FloatImg/tools/cumulfimgs.c
2019-07-16 00:19:59 +02:00

90 lines
1.8 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../floatimg.h"
int verbosity;
int g_width, g_height;
/* --------------------------------------------------------------------- */
int testfile(char *path)
{
int foo, numbers[3];
foo = fimg_fileinfos(path, numbers);
if (foo) {
#if DEBUG_LEVEL
fprintf(stderr, "%s -> err %d\n", path, foo);
#endif
return foo;
}
fprintf(stderr, "\t\t%d x %d\n",numbers[0], numbers[1]);
if (3 != numbers[2]) {
fprintf(stderr, "file %s, %d : bad type\n", path, numbers[2]);
return -7;
}
return foo;
}
/* --------------------------------------------------------------------- */
void help(int v)
{
puts("options :");
puts("\t-v\tincrease verbosity");
puts("\t-o\tname of output file");
puts("\t-s\tname of source file");
if (verbosity) { puts(""); fimg_print_version(1); }
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo, idx;
int opt;
char *output_file = "noname.fimg";
char *source_file = "noname.fimg";
g_width = g_height = 0;
while ((opt = getopt(argc, argv, "ho:s:v")) != -1) {
switch(opt) {
case 'h': help(0); break;
case 'o': output_file = optarg; break;
case 's': source_file = optarg; break;
case 'v': verbosity++; break;
}
}
#if DEBUG_LEVEL
fprintf(stderr, "argc = %d, optind = %d\n", argc, optind);
#endif
foo = testfile(source_file);
fprintf(stderr, "Source %s -> %d\n", source_file, foo);
foo = testfile(output_file);
fprintf(stderr, "Output %s -> %d\n", output_file, foo);
for (idx=optind; idx<argc; idx++) {
fprintf(stderr, "%5d %s\n", idx, argv[idx]);
foo = testfile(argv[idx]);
fprintf(stderr, "testfile %s -> %d\n", argv[idx],foo);
}
return 0;
}
/* --------------------------------------------------------------------- */