one more step : display metadata

This commit is contained in:
tth 2022-04-17 04:00:12 +02:00
parent ddfadf9a67
commit 8a663a95ee
1 changed files with 62 additions and 8 deletions

View File

@ -13,29 +13,83 @@
int verbosity;
/* --------------------------------------------------------------------- */
enum comId { C_timestamp, C_count, C_fval, C_cpid, C_origin, C_all };
typedef struct {
char *name;
int id;
} Cmd;
Cmd Cmd_list[] = {
{ "timestamp", C_timestamp },
{ "cpid", C_cpid },
{ "count", C_count },
{ "fval", C_fval },
{ "origin", C_origin },
{ "all", C_all },
{ NULL, 0, }
};
/* --------------------------------------------------------------------- */
int lookup_cmd(char *txt)
{
Cmd *cmd;
int n;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, txt);
#endif
for (n=0, cmd=Cmd_list; cmd->name; cmd++, n++) {
#if DEBUG_LEVEL > 1
fprintf(stderr, " try %-12s %3d\n", cmd->name, n);
#endif
if (!strcmp(cmd->name, txt)) {
// fprintf(stderr, "found '%s' at %d\n", txt, n);
return cmd->id;
}
}
return -1; /* NOT FOUND */
}
/* --------------------------------------------------------------------- */
int get_print_metadata(char *fname, char *command)
{
int foo;
int foo, action;
FimgMetaData metadata;
// #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %s )\n", __func__, fname, command);
// #endif
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, fname, command);
#endif
foo = fimg_get_metadata_from_file(fname, &metadata);
if (foo) return foo;
/* switch on command here, please */
/* switch on command here */
action = lookup_cmd(command);
// fprintf(stderr, " command '%s' -> %d\n", command, action);
fimg_show_metadata(&metadata, fname, 0);
switch(action) {
case C_timestamp:
printf("ts %ld\n", metadata.timestamp.tv_sec); break;
case C_count:
printf("count %d\n", metadata.count); break;
case C_fval:
printf("fval %f\n", metadata.fval); break;
case C_cpid:
printf("cpid %ld\n", metadata.cpid); break;
case C_all:
fimg_show_metadata(&metadata, fname, 0); break;
default:
fprintf(stderr, "WTF?\n"); exit(1);
}
return 0;
}
/* --------------------------------------------------------------------- */
void help(void)
{
fprintf(stderr, "*** fimgmetadata (%s, %s)\n", __DATE__, __TIME__);
fprintf(stderr, "*** Fimg Metadata Reader (%s, %s)\n", __DATE__, __TIME__);
fimg_print_version(1);
exit(0);
}
@ -60,7 +114,7 @@ if (2 != nbargs) {
exit(1);
}
foo = get_print_metadata(argv[optind], argv[optind+1]);
foo = get_print_metadata(argv[optind+1], argv[optind]);
if (foo) fprintf(stderr, "got a %d from job\n", foo);
return 0;