15. Content

Gets content information, given an id.

<<available_commands>>=
fprintf(stderr, "content: prints content info given UUID\n");
<<utils>>=
static void print_content(wmp_content *c)
{
    printf("prog = %d\n", c->prog);
    printf("id = %d\n", c->id);
    printf("section = %s\n", c->section);
    printf("filename = %s\n", c->filename);
    printf("linum = %d\n", c->linum);
    printf("content = @@\n%s\n@@\n", c->content);
    printf("next = %d\n", c->next);
}
<<function_declarations>>=
static int get_content(int argc, char *argv[]);
<<functions>>=
static int get_content(int argc, char *argv[])
{
    wmp_core core;
    int rc;
    wmp_content c;
    unsigned int id;
    int err;
    int prog;

    prog = 0;
    err = 0;

    if (argc < 2) {
        fprintf(stderr, "Usage: %s UUID [prog]\n", argv[0]);
        return 1;
    }

    rc = wmp_core_open(&core, wmp_filename_get());

    if (!rc) return 0;

    wmp_content_init(&c);
    id = atoi(argv[1]);

    if (argc > 2) prog = atoi(argv[2]);

    rc = wmp_content_find(&core, id, &c, prog);

    if (!rc) {
        fprintf(stderr,
                "Could not find block in program %d "
                "with id %d\n",
                prog,
                id);
        err = 1;
    } else {
        print_content(&c);
    }

    wmp_content_free(&c);
    wmp_core_close(&core);
    return err;
}
<<command_parsing>>=
else if (match(argv[1], len, "content", 7)) {
    argv++;
    argc--;
    get_content(argc, argv);
}



prev | home | next