working on a new tool

This commit is contained in:
phyto 2019-07-16 00:19:59 +02:00
parent ecf952d881
commit bcf57f8764
4 changed files with 82 additions and 9 deletions

View File

@ -29,7 +29,7 @@ fimg_describe(&dst, "created fimg from dump");
foo = fimg_load_from_pnm(srcname, &src, 0); foo = fimg_load_from_pnm(srcname, &src, 0);
if (foo) fprintf(stderr, "create src fimg from '%s' -> %d\n", dstname, foo); if (foo) fprintf(stderr, "create src fimg from '%s' -> %d\n", dstname, foo);
#if DEBUG_LEVEL #if DEBUG_LEVEL
fimg_describe(&qrc, "created fimg from PNM"); fimg_describe(&src, "created fimg from PNM");
#endif #endif
// fprintf(stderr, "src is %dx%d\n", src.width, src.height); // fprintf(stderr, "src is %dx%d\n", src.width, src.height);

View File

@ -5,30 +5,85 @@
#include "../floatimg.h" #include "../floatimg.h"
int verbosity; 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) void help(int v)
{ {
puts("options :"); puts("options :");
puts("\t-v\tincrease verbosity"); puts("\t-v\tincrease verbosity");
puts("\t-o\tname of output file"); puts("\t-o\tname of output file");
puts("\t-s\tname of source file");
if (verbosity) { puts(""); fimg_print_version(1); } if (verbosity) { puts(""); fimg_print_version(1); }
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo; int foo, idx;
int opt; int opt;
char *output_file = "noname.fimg"; char *output_file = "noname.fimg";
char *source_file = "noname.fimg";
while ((opt = getopt(argc, argv, "ho:v")) != -1) {
g_width = g_height = 0;
while ((opt = getopt(argc, argv, "ho:s:v")) != -1) {
switch(opt) { switch(opt) {
case 'h': help(0); break; case 'h': help(0); break;
case 'o': output_file = optarg; break; case 'o': output_file = optarg; break;
case 's': source_file = optarg; break;
case 'v': verbosity++; 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; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */

View File

@ -85,7 +85,9 @@ if (argc == 1) {
} }
foo = various_numbers_from_file(argv[optind], 0); foo = various_numbers_from_file(argv[optind], 0);
if (foo) {
fprintf(stderr, "got a %d ?\n", foo);
}
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */

View File

@ -4,22 +4,38 @@
#include "../floatimg.h" #include "../floatimg.h"
/* --------------------------------------------------------------------- */ int verbosity;
/* --------------------------------------------------------------------- */
void help(int lj)
{
fimg_print_version(1);
exit(0);
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo; int foo, opt;
int width, height; int width, height;
char *fname; char *fname;
FloatImg fimg; FloatImg fimg;
while ((opt = getopt(argc, argv, "ho:v")) != -1) {
switch(opt) {
case 'h': help(0); break;
case 'v': verbosity++; break;
}
}
if (4 != argc) { if (4 != argc) {
fimg_print_version(1); fimg_print_version(1);
fprintf(stderr, "Usage:\n\t%s quux.fimg width height\n", argv[0]); fprintf(stderr, "Usage:\n\t%s quux.fimg width height\n", argv[0]);
exit(1); exit(1);
} }
fname = argv[1];
width = atoi(argv[2]); height = atoi(argv[3]); fname = argv[optind];
width = atoi(argv[optind+1]); height = atoi(argv[optind+2]);
fprintf(stderr, "making '%s' %d x %d\n", fname, width, height); fprintf(stderr, "making '%s' %d x %d\n", fname, width, height);
foo = fimg_create(&fimg, width, height, 3); foo = fimg_create(&fimg, width, height, 3);
@ -31,7 +47,7 @@ fimg_clear(&fimg);
foo = fimg_dump_to_file(&fimg, fname, 0); foo = fimg_dump_to_file(&fimg, fname, 0);
if (foo) { if (foo) {
fprintf(stderr, "dump floatimg -> %d\n", foo); fprintf(stderr, "dump fimg -> %d\n", foo);
exit(1); exit(1);
} }