From aa4409eda521fd2834d696c7e75ab15957083ad0 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 7 Mar 2020 12:58:33 +0100 Subject: [PATCH] rgb2ycbcr: use EXIT_FAILURE / EXIT_SUCCESS the -h option was already used so it cannot be used for help/usage see #17 --- tools/rgb2ycbcr.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/tools/rgb2ycbcr.c b/tools/rgb2ycbcr.c index cb94d458..482cc5b4 100644 --- a/tools/rgb2ycbcr.c +++ b/tools/rgb2ycbcr.c @@ -39,6 +39,13 @@ #include "tiffiop.h" #include "tiffio.h" +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#ifndef EXIT_FAILURE +#define EXIT_FAILURE 1 +#endif + #define streq(a,b) (strcmp(a,b) == 0) #define CopyField(tag, v) \ if (TIFFGetField(in, tag, &v)) TIFFSetField(out, tag, v) @@ -89,17 +96,17 @@ main(int argc, char* argv[]) else if (streq(optarg, "zip")) compression = COMPRESSION_ADOBE_DEFLATE; else - usage(-1); + usage(EXIT_FAILURE); break; case 'h': horizSubSampling = atoi(optarg); if( horizSubSampling != 1 && horizSubSampling != 2 && horizSubSampling != 4 ) - usage(-1); + usage(EXIT_FAILURE); break; case 'v': vertSubSampling = atoi(optarg); if( vertSubSampling != 1 && vertSubSampling != 2 && vertSubSampling != 4 ) - usage(-1); + usage(EXIT_FAILURE); break; case 'r': rowsperstrip = atoi(optarg); @@ -113,14 +120,14 @@ main(int argc, char* argv[]) refBlackWhite[5] = 240.; break; case '?': - usage(0); + usage(EXIT_FAILURE); /*NOTREACHED*/ } if (argc - optind < 2) - usage(-1); + usage(EXIT_FAILURE); out = TIFFOpen(argv[argc-1], "w"); if (out == NULL) - return (-2); + return (EXIT_FAILURE); setupLumaTables(); for (; optind < argc-1; optind++) { in = TIFFOpen(argv[optind], "r"); @@ -137,7 +144,7 @@ main(int argc, char* argv[]) } } (void) TIFFClose(out); - return (0); + return (EXIT_SUCCESS); } float *lumaRed; @@ -357,7 +364,7 @@ tiffcvt(TIFF* in, TIFF* out) return result; } -char* stuff[] = { +const char* stuff[] = { "usage: rgb2ycbcr [-c comp] [-r rows] [-h N] [-v N] input... output\n", "where comp is one of the following compression algorithms:\n", " jpeg\t\tJPEG encoding\n", @@ -375,14 +382,12 @@ char* stuff[] = { static 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]); + fprintf(out, "%s\n", stuff[i]); exit(code); }