better args parsing in mkfimg

This commit is contained in:
tth
2021-05-04 10:29:02 +02:00
parent 65eaca26cc
commit c59eedd33c
2 changed files with 25 additions and 10 deletions

View File

@@ -63,7 +63,7 @@ int foo;
puts("Usage:\tmkfimg [options] quux.fimg width height");
puts("\t-k N.N\tgive a float parameter");
fputs("\t-t bla\thowto make the pic\n\t\t", stdout);
fputs("\t-t bla\thowto make the pic :\n\t\t", stdout);
for (foo=0; types[foo].code; foo++) {
printf("%s ", types[foo].name);
}
@@ -79,7 +79,7 @@ exit(0);
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo, opt;
int foo, opt, nbargs;
int width, height;
char *fname;
float fvalue = 1.0;
@@ -103,21 +103,33 @@ for (foo=0; foo<argc; foo++)
fprintf(stderr, "%3d %s\n", foo, argv[foo]);
#endif
if (3 != argc-optind) {
fprintf(stderr, "%s need filename, width & height\n", argv[0]);
exit(1);
}
if (type < 0) {
fprintf(stderr, "type '%s' is unknow\n", tname);
exit(2);
}
nbargs = argc-optind;
switch (nbargs) {
case 2:
if (2!=parse_WxH(argv[optind+1], &width, &height)) {
fprintf(stderr, "%s: parse error on '%s'\n",
argv[0], argv[optind+1]);
exit(1);
}
break;
case 3:
width = atoi(argv[optind+1]);
height = atoi(argv[optind+2]);
break;
default:
fprintf(stderr, "%s need filename, width & height\n", argv[0]);
exit(1);
}
fname = argv[optind];
width = atoi(argv[optind+1]); height = atoi(argv[optind+2]);
if (verbosity>1) fprintf(stderr, "*** mkfimg *** %s %s\n", __DATE__, __TIME__);
if (verbosity) fprintf(stderr, "making '%s' %d x %d, type %d\n",
if (verbosity) fprintf(stderr, "making '%s' %dx%d, type %d\n",
fname, width, height, type);
srand48(getpid() ^ time(NULL));