10. Blocklist

Given a block name, print underlying blocks associated with it.

<<available_commands>>=
fprintf(stderr, "blklst: prints sub-blocks\n");
<<function_declarations>>=
static int get_blklst(int argc, char *argv[]);
<<functions>>=
static int get_blklst(int argc, char *argv[])
{
    wmp_core core;
    int rc;
    wmp_segment s;
    wmp_block b;
    int next;
    int prog;

    prog = 0; /* TODO: make parameter */
    if (argc < 2) {
        fprintf(stderr, "Usage: %s NAME\n", argv[0]);
        return 1;
    }

    rc = wmp_core_open(&core, wmp_filename_get());
    if (!rc) return 0;
    wmp_block_init(&b);
    rc = wmp_lookup_block(&core, argv[1], &b, prog);
    if (!rc) {
        fprintf(stderr,
                "Could not find block '%s'",
                argv[1]);
        return 1;
    }
    wmp_segment_init(&s);
    wmp_find_segment(&core, b.head_segment, &s, prog);

    while (1) {
        next = s.nxtseg;
        if (s.id == next || s.id <= 0) {
            wmp_segment_free(&s);
            break;
        }

        if (s.type == 1) {
            printf("%s\n", s.str);
        }

        wmp_segment_free(&s);
        wmp_segment_init(&s);
        wmp_find_segment(&core, next, &s, prog);
    }
    wmp_block_free(&b);
    wmp_core_close(&core);
    return 0;
}
<<command_parsing>>=
else if (match(argv[1], len, "blklst", 6)) {
    argv++;
    argc--;
    get_blklst(argc, argv);
}



prev | home | next