5. segment

The segement command will return information of a particular segment, given it's UUID.

<<available_commands>>=
fprintf(stderr,
        "seg: prints segment info given UUID\n");
<<function_declarations>>=
static int get_seg(int argc, char *argv[]);
<<functions>>=
static int get_seg(int argc, char *argv[])
{
    wmp_core core;
    int rc;
    wmp_segment seg;
    unsigned int id;
    int err;
    int prog;

    prog = 0; /* TODO: make parameter */
    err = 0;
    if (argc < 2) {
        fprintf(stderr, "Usage: %s UUID\n", argv[0]);
        return 1;
    }
    rc = wmp_core_open(&core, wmp_filename_get());
    if (!rc) return 0;
    wmp_segment_init(&seg);
    id = atoi(argv[1]);
    rc = wmp_find_segment(&core, id, &seg, prog);

    if(!rc) {
        fprintf(stderr,
                "Could not find segment with id %d\n",
                id);
        err = 1;
    } else {
        printf("id = %d\n", seg.id);
        printf("type = %d\n", seg.type);
        printf("str = \"\"\"\n%s\n\"\"\"\n", seg.str);
        printf("linum = %d\n", seg.linum);
        printf("file = \"%s\"\n", seg.filename);
        printf("next_segment = %d\n", seg.nxtseg);
    }
    wmp_segment_free(&seg);
    wmp_core_close(&core);
    return err;
}
<<command_parsing>>=
else if (match(argv[1], len, "seg", 3)) {
    argv++;
    argc--;
    get_seg(argc, argv);
}



prev | home | next