Example 3–4: Extension That Uses Arrays: file.c (cont.)
quit(1);
}
if (first_file) {
sprintf(buf, "[Process ID: %d]", fields_pid[0].data);
print(buf);
first_file = False;
}
if(!prfile(fil))
fprintf(stderr, "Continuing with next file address.\n");
}
} /* for loop */
return(True);
} /* end */
Example 3–5: Extension That Uses Global Symbols: sum.c
#include <stdio.h>
#include <kdbx.h>
static char *help_string =
"sum - print a summary of the system \\\n\
Usage : sum \\\n\
";
static void read_var(name, type, val)
char *name;
int type;
long *val;
{
char *error;
long n;
if(!read_sym_val(name, type, &n, &error)){
fprintf(stderr, "Reading %s:\n", name);
fprintf(stderr, "%s\n", error);
quit(1);
}
*val = n;
}
main(argc, argv)
int argc;
char **argv;
{
DataStruct utsname, cpup, time;
char buf[256], *error, *resp, *sysname, *release, *version, *machine;
long avail, secs, tmp;
check_args(argc, argv, help_string);
read_var("utsname.nodename", STRING, &resp);
sprintf(buf, "Hostname : %s", resp);
print(buf);
free(resp);
read_var("ncpus", NUMBER, &avail);
/*
3–34 Writing Extensions to the kdbx Debugger