8. File Find (ffile)
<<available_commands>>=
fprintf(stderr, "ffind: looks up file given name\n");
<<function_declarations>>=
static int get_ffile(int argc, char *argv[]);
<<functions>>=
static int get_ffile(int argc, char *argv[])
{
wmp_core core;
int rc;
wmp_file file;
int err;
err = 0;
if (argc < 2) {
fprintf(stderr, "Usage: %s NAME [prog]\n", argv[0]);
return 1;
}
rc = wmp_core_open(&core, wmp_filename_get());
if (!rc) return 0;
wmp_file_init(&file);
rc = wmp_lookup_file(&core, argv[1], &file);
if (!rc) {
fprintf(stderr,
"Could not find file '%s'\n",
argv[1]);
err = 1;
} else {
wmp_block top;
printf("id = %d\n", file.id);
printf("filename = %s\n", file.filename);
wmp_block_init(&top);
rc = wmp_find_block(&core, file.top, &top, file.prog);
if (rc) {
printf("top = %d (%s)\n", file.top, top.name);
} else {
printf("top = %d\n", file.top);
}
printf("next_file = %d\n", file.next_file);
printf("program id = %d\n", file.prog);
wmp_block_free(&top);
}
wmp_file_free(&file);
wmp_core_close(&core);
return err;
}
<<command_parsing>>=
else if (match(argv[1], len, "ffile", 5)) {
argv++;
argc--;
get_ffile(argc, argv);
}
prev | home | next