6. Block Find (fblk)

<<available_commands>>=
fprintf(stderr, "fblk: looks up block given name\n");
<<function_declarations>>=
static int get_fblk(int argc, char *argv[]);
<<functions>>=
static int get_fblk(int argc, char *argv[])
{
    wmp_core core;
    int rc;
    wmp_block blk;
    int err;
    int prog;

    err = 0;
    if (argc < 3) {
        fprintf(stderr, "Usage: %s NAME prog\n", argv[0]);
        return 1;
    }
    rc = wmp_core_open(&core, wmp_filename_get());
    if (!rc) return 0;
    wmp_block_init(&blk);

    prog = atoi(argv[2]);
    rc = wmp_lookup_block(&core, argv[1], &blk, prog);

    if(!rc) {
        fprintf(stderr,
                "Could not find block name '%s'\n",
                argv[1]);
        err = 1;
    } else {
        print_block(&blk);
    }
    wmp_block_free(&blk);
    wmp_core_close(&core);
    return err;
}
<<command_parsing>>=
else if (match(argv[1], len, "fblk", 4)) {
    argv++;
    argc--;
    get_fblk(argc, argv);
}



prev | home | next