fax2tiff.c: print usage on stdout when using -h option

see #17
This commit is contained in:
Thomas Bernard 2020-03-07 12:38:05 +01:00
parent 0aed3363cf
commit 04e7c51f4e
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -68,7 +68,7 @@ uint16 badfaxrun;
uint32 badfaxlines; uint32 badfaxlines;
int copyFaxFile(TIFF* tifin, TIFF* tifout); int copyFaxFile(TIFF* tifin, TIFF* tifout);
static void usage(void); static void usage(int code);
/* /*
Struct to carry client data. Note that it does not appear that the client Struct to carry client data. Note that it does not appear that the client
@ -110,7 +110,7 @@ main(int argc, char* argv[])
extern char* optarg; extern char* optarg;
#endif #endif
while ((c = getopt(argc, argv, "R:X:o:r:1234ABLMPUW5678abcflmprsuvwz?")) != -1) while ((c = getopt(argc, argv, "R:X:o:r:1234ABLMPUW5678abcflmprsuvwzh")) != -1)
switch (c) { switch (c) {
/* input-related options */ /* input-related options */
case '3': /* input is g3-encoded */ case '3': /* input is g3-encoded */
@ -216,13 +216,15 @@ main(int argc, char* argv[])
case 'v': /* -v for info */ case 'v': /* -v for info */
verbose++; verbose++;
break; break;
case 'h':
usage(EXIT_SUCCESS);
case '?': case '?':
usage(); usage(EXIT_FAILURE);
/*NOTREACHED*/ /*NOTREACHED*/
} }
npages = argc - optind; npages = argc - optind;
if (npages < 1) if (npages < 1)
usage(); usage(EXIT_FAILURE);
rowbuf = _TIFFmalloc(TIFFhowmany8(xsize)); rowbuf = _TIFFmalloc(TIFFhowmany8(xsize));
refbuf = _TIFFmalloc(TIFFhowmany8(xsize)); refbuf = _TIFFmalloc(TIFFhowmany8(xsize));
@ -426,7 +428,7 @@ copyFaxFile(TIFF* tifin, TIFF* tifout)
return (row); return (row);
} }
char* stuff[] = { const char* stuff[] = {
"usage: fax2tiff [options] input.raw...", "usage: fax2tiff [options] input.raw...",
"where options are:", "where options are:",
" -3 input data is G3-encoded [default]", " -3 input data is G3-encoded [default]",
@ -463,16 +465,15 @@ NULL
}; };
static void static void
usage(void) usage(int code)
{ {
char buf[BUFSIZ];
int i; int i;
FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
setbuf(stderr, buf); fprintf(out, "%s\n\n", TIFFGetVersion());
fprintf(stderr, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++) for (i = 0; stuff[i] != NULL; i++)
fprintf(stderr, "%s\n", stuff[i]); fprintf(out, "%s\n", stuff[i]);
exit(EXIT_FAILURE); exit(code);
} }
/* vim: set ts=8 sts=8 sw=8 noet: */ /* vim: set ts=8 sts=8 sw=8 noet: */