7. File

The file command will return information of a particular file.

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

    err = 0;
    prog = 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_file_init(&file);
    id = atoi(argv[1]);
    rc = wmp_find_file(&core, id, &file, prog);

    if(!rc) {
        fprintf(stderr,
                "Could not find file with id %d\n",
                id);
        err = 1;
    } else {
        printf("id = %d\n", file.id);
        printf("filename = %s\n", file.filename);
        printf("top = %d\n", file.top);
        printf("next_file = %d\n", file.next_file);
    }
    wmp_file_free(&file);
    wmp_core_close(&core);
    return err;
}
<<command_parsing>>=
else if (match(argv[1], len, "file", 4)) {
    argv++;
    argc--;
    get_file(argc, argv);
}



prev | home | next