tiffgt: output usage on stdout with -h

also use EXIT_SUCCESS / EXIT_FAILURE
This commit is contained in:
Thomas Bernard 2020-03-07 15:59:35 +01:00
parent eb6806dd64
commit 2c6e8805ba
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -48,6 +48,13 @@
#include "tiffio.h" #include "tiffio.h"
#include "tiffiop.h" #include "tiffiop.h"
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif
#ifndef HAVE_GETOPT #ifndef HAVE_GETOPT
extern int getopt(int argc, char * const argv[], const char *optstring); extern int getopt(int argc, char * const argv[], const char *optstring);
#endif #endif
@ -68,12 +75,12 @@ static int filenum;
static TIFFErrorHandler oerror; static TIFFErrorHandler oerror;
static TIFFErrorHandler owarning; static TIFFErrorHandler owarning;
static void cleanup_and_exit(void); static void cleanup_and_exit(int);
static int initImage(void); static int initImage(void);
static int prevImage(void); static int prevImage(void);
static int nextImage(void); static int nextImage(void);
static void setWindowSize(void); static void setWindowSize(void);
static void usage(void); static void usage(int);
static uint16 photoArg(const char*); static uint16 photoArg(const char*);
static void raster_draw(void); static void raster_draw(void);
static void raster_reshape(int, int); static void raster_reshape(int, int);
@ -102,7 +109,7 @@ main(int argc, char* argv[])
oerror = TIFFSetErrorHandler(NULL); oerror = TIFFSetErrorHandler(NULL);
owarning = TIFFSetWarningHandler(NULL); owarning = TIFFSetWarningHandler(NULL);
while ((c = getopt(argc, argv, "d:o:p:eflmsvw?")) != -1) while ((c = getopt(argc, argv, "d:o:p:eflmsvwh")) != -1)
switch (c) { switch (c) {
case 'd': case 'd':
dirnum = atoi(optarg); dirnum = atoi(optarg);
@ -131,13 +138,16 @@ main(int argc, char* argv[])
case 'v': case 'v':
verbose = 1; verbose = 1;
break; break;
case 'h':
usage(EXIT_SUCCESS);
/*NOTREACHED*/
case '?': case '?':
usage(); usage(EXIT_FAILURE);
/*NOTREACHED*/ /*NOTREACHED*/
} }
filenum = argc - optind; filenum = argc - optind;
if ( filenum < 1) if ( filenum < 1)
usage(); usage(EXIT_FAILURE);
glutInit(&argc, argv); glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
@ -157,13 +167,13 @@ main(int argc, char* argv[])
filelist = (char **) _TIFFmalloc(filenum * sizeof(char*)); filelist = (char **) _TIFFmalloc(filenum * sizeof(char*));
if (!filelist) { if (!filelist) {
TIFFError(argv[0], "Can not allocate space for the file list."); TIFFError(argv[0], "Can not allocate space for the file list.");
return 1; return EXIT_FAILURE;
} }
_TIFFmemcpy(filelist, argv + optind, filenum * sizeof(char*)); _TIFFmemcpy(filelist, argv + optind, filenum * sizeof(char*));
fileindex = -1; fileindex = -1;
if (nextImage() < 0) { if (nextImage() < 0) {
_TIFFfree(filelist); _TIFFfree(filelist);
return 2; return EXIT_FAILURE;
} }
/* /*
* Set initial directory if user-specified * Set initial directory if user-specified
@ -177,7 +187,7 @@ main(int argc, char* argv[])
photo = photo0; photo = photo0;
if (initImage() < 0){ if (initImage() < 0){
_TIFFfree(filelist); _TIFFfree(filelist);
return 3; return EXIT_FAILURE;
} }
/* /*
* Create a new window or reconfigure an existing * Create a new window or reconfigure an existing
@ -193,12 +203,12 @@ main(int argc, char* argv[])
glutSpecialFunc(raster_special); glutSpecialFunc(raster_special);
glutMainLoop(); glutMainLoop();
cleanup_and_exit(); cleanup_and_exit(EXIT_SUCCESS);
return 0; return EXIT_SUCCESS;
} }
static void static void
cleanup_and_exit(void) cleanup_and_exit(int code)
{ {
TIFFRGBAImageEnd(&img); TIFFRGBAImageEnd(&img);
if (filelist != NULL) if (filelist != NULL)
@ -207,7 +217,7 @@ cleanup_and_exit(void)
_TIFFfree(raster); _TIFFfree(raster);
if (tif != NULL) if (tif != NULL)
TIFFClose(tif); TIFFClose(tif);
exit(0); exit(code);
} }
static int static int
@ -250,7 +260,7 @@ initImage(void)
if (raster == NULL) { if (raster == NULL) {
width = height = 0; width = height = 0;
TIFFError(filelist[fileindex], "No space for raster buffer"); TIFFError(filelist[fileindex], "No space for raster buffer");
cleanup_and_exit(); cleanup_and_exit(EXIT_FAILURE);
} }
width = w; width = w;
height = h; height = h;
@ -361,7 +371,7 @@ raster_keys(unsigned char key, int x, int y)
break; break;
case 'q': /* exit */ case 'q': /* exit */
case '\033': case '\033':
cleanup_and_exit(); cleanup_and_exit(EXIT_SUCCESS);
} }
glutPostRedisplay(); glutPostRedisplay();
} }
@ -422,7 +432,7 @@ raster_special(int key, int x, int y)
# pragma GCC diagnostic pop # pragma GCC diagnostic pop
# endif # endif
char* stuff[] = { static const char* stuff[] = {
"usage: tiffgt [options] file.tif", "usage: tiffgt [options] file.tif",
"where options are:", "where options are:",
" -c use colormap visual", " -c use colormap visual",
@ -440,16 +450,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(-1); exit(code);
} }
static uint16 static uint16