tiffinfo: print usage on stdout when -h is used

also use EXIT_FAILURE / EXIT_SUCCESS
see #17
This commit is contained in:
Thomas Bernard 2020-03-07 16:15:12 +01:00
parent 46c8624972
commit 1c614e2686
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -42,15 +42,22 @@
#include "tiffiop.h"
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif
static TIFFErrorHandler old_error_handler = 0;
static int status = 0; /* exit status */
static int status = EXIT_SUCCESS; /* exit status */
static int showdata = 0; /* show data */
static int rawdata = 0; /* show raw/decoded data */
static int showwords = 0; /* show data as bytes/words */
static int readdata = 0; /* read data in file */
static int stoponerr = 1; /* stop on first read error */
static void usage(void);
static void usage(int);
static void tiffinfo(TIFF*, uint16, long, int);
static void
@ -58,7 +65,7 @@ PrivateErrorHandler(const char* module, const char* fmt, va_list ap)
{
if (old_error_handler)
(*old_error_handler)(module,fmt,ap);
status = 1;
status = EXIT_FAILURE;
}
int
@ -75,7 +82,7 @@ main(int argc, char* argv[])
uint64 diroff = 0;
int chopstrips = 0; /* disable strip chopping */
while ((c = getopt(argc, argv, "f:o:cdDSjilmrsvwz0123456789")) != -1)
while ((c = getopt(argc, argv, "f:o:cdDSjilmrsvwz0123456789h")) != -1)
switch (c) {
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
@ -97,7 +104,7 @@ main(int argc, char* argv[])
else if (streq(optarg, "msb2lsb"))
order = FILLORDER_MSB2LSB;
else
usage();
usage(EXIT_FAILURE);
break;
case 'i':
stoponerr = 0;
@ -122,12 +129,15 @@ main(int argc, char* argv[])
case 'z':
chopstrips = 1;
break;
case 'h':
usage(EXIT_SUCCESS);
/*NOTREACHED*/
case '?':
usage();
usage(EXIT_FAILURE);
/*NOTREACHED*/
}
if (optind >= argc)
usage();
usage(EXIT_FAILURE);
old_error_handler = TIFFSetErrorHandler(PrivateErrorHandler);
@ -162,7 +172,7 @@ main(int argc, char* argv[])
return (status);
}
char* stuff[] = {
static const char* stuff[] = {
"usage: tiffinfo [options] input...",
"where options are:",
" -D read data",
@ -182,16 +192,15 @@ NULL
};
static void
usage(void)
usage(int code)
{
char buf[BUFSIZ];
int i;
FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
setbuf(stderr, buf);
fprintf(stderr, "%s\n\n", TIFFGetVersion());
fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
fprintf(stderr, "%s\n", stuff[i]);
exit(-1);
fprintf(out, "%s\n", stuff[i]);
exit(code);
}
static void