tiff2ps: sue EXIT_FAILURE / EXIT_SUCCESS

see #17
This commit is contained in:
Thomas Bernard 2020-03-07 13:17:42 +01:00
parent ff18e43223
commit 05993b6408
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -40,6 +40,13 @@
#include "tiffio.h" #include "tiffio.h"
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif
/* /*
* Revision history * Revision history
* 2013-Jan-21 * 2013-Jan-21
@ -332,7 +339,7 @@ main(int argc, char* argv[])
case '9': diroff = (uint32) strtoul(optarg, NULL, 0); case '9': diroff = (uint32) strtoul(optarg, NULL, 0);
break; break;
default: TIFFError ("-o", "Offset must be a numeric value."); default: TIFFError ("-o", "Offset must be a numeric value.");
exit (1); exit (EXIT_FAILURE);
} }
break; break;
case 'O': /* XXX too bad -o is already taken */ case 'O': /* XXX too bad -o is already taken */
@ -341,21 +348,21 @@ main(int argc, char* argv[])
fprintf(stderr, fprintf(stderr,
"%s: %s: Cannot open output file.\n", "%s: %s: Cannot open output file.\n",
argv[0], optarg); argv[0], optarg);
exit(-2); exit (EXIT_FAILURE);
} }
break; break;
case 'P': case 'P':
switch (optarg[0]) switch (optarg[0])
{ {
case 'l': case 'l':
case 'L': strcpy (pageOrientation, "Landscape"); case 'L': strcpy (pageOrientation, "Landscape");
break; break;
case 'p': case 'p':
case 'P': strcpy (pageOrientation, "Portrait"); case 'P': strcpy (pageOrientation, "Portrait");
break; break;
default: TIFFError ("-P", "Page orientation must be Landscape or Portrait"); default: TIFFError ("-P", "Page orientation must be Landscape or Portrait");
exit (-1); exit (EXIT_FAILURE);
} }
break; break;
case 'l': case 'l':
leftmargin = atof(optarg); leftmargin = atof(optarg);
@ -386,7 +393,7 @@ main(int argc, char* argv[])
break; break;
default: default:
fprintf (stderr, "Rotation angle must be 90, 180, 270 (degrees ccw) or auto\n"); fprintf (stderr, "Rotation angle must be 90, 180, 270 (degrees ccw) or auto\n");
exit (-1); exit (EXIT_FAILURE);
} }
break; break;
case 's': case 's':
@ -424,7 +431,7 @@ main(int argc, char* argv[])
res_unit = RESUNIT_INCH; res_unit = RESUNIT_INCH;
break; break;
case '?': case '?':
usage(-1); usage(EXIT_FAILURE);
} }
if (useImagemask == TRUE) if (useImagemask == TRUE)
@ -432,14 +439,14 @@ main(int argc, char* argv[])
if ((level2 == FALSE) && (level3 == FALSE)) if ((level2 == FALSE) && (level3 == FALSE))
{ {
TIFFError ("-m "," imagemask operator requres Postscript Level2 or Level3"); TIFFError ("-m "," imagemask operator requres Postscript Level2 or Level3");
exit (1); exit (EXIT_FAILURE);
} }
} }
if (pageWidth && (maxPageWidth > pageWidth)) if (pageWidth && (maxPageWidth > pageWidth))
{ {
TIFFError ("-W", "Max viewport width cannot exceed page width"); TIFFError ("-W", "Max viewport width cannot exceed page width");
exit (1); exit (EXIT_FAILURE);
} }
/* auto rotate requires a specified page width and height */ /* auto rotate requires a specified page width and height */
@ -452,13 +459,13 @@ main(int argc, char* argv[])
if ((maxPageWidth > 0) || (maxPageHeight > 0)) if ((maxPageWidth > 0) || (maxPageHeight > 0))
{ {
TIFFError ("-r auto", " is incompatible with maximum page width/height specified by -H or -W"); TIFFError ("-r auto", " is incompatible with maximum page width/height specified by -H or -W");
exit (1); exit (EXIT_FAILURE);
} }
} }
if ((maxPageWidth > 0) && (maxPageHeight > 0)) if ((maxPageWidth > 0) && (maxPageHeight > 0))
{ {
TIFFError ("-H and -W", " Use only one of -H or -W to define a viewport"); TIFFError ("-H and -W", " Use only one of -H or -W to define a viewport");
exit (1); exit (EXIT_FAILURE);
} }
if ((generateEPSF == TRUE) && (printAll == TRUE)) if ((generateEPSF == TRUE) && (printAll == TRUE))
@ -489,13 +496,13 @@ main(int argc, char* argv[])
&& !TIFFSetDirectory(tif, (tdir_t)dirnum)) && !TIFFSetDirectory(tif, (tdir_t)dirnum))
{ {
TIFFClose(tif); TIFFClose(tif);
return (-1); return (EXIT_FAILURE);
} }
else if (diroff != 0 && else if (diroff != 0 &&
!TIFFSetSubDirectory(tif, diroff)) !TIFFSetSubDirectory(tif, diroff))
{ {
TIFFClose(tif); TIFFClose(tif);
return (-1); return (EXIT_FAILURE);
} }
np = TIFF2PS(output, tif, pageWidth, pageHeight, np = TIFF2PS(output, tif, pageWidth, pageHeight,
leftmargin, bottommargin, centered); leftmargin, bottommargin, centered);
@ -509,10 +516,10 @@ main(int argc, char* argv[])
if (np) if (np)
PSTail(output, np); PSTail(output, np);
else else
usage(-1); usage(EXIT_FAILURE);
if (output != stdout) if (output != stdout)
fclose(output); fclose(output);
return (0); return (EXIT_SUCCESS);
} }
static uint16 samplesperpixel; static uint16 samplesperpixel;
@ -3080,7 +3087,7 @@ tsize_t Ascii85EncodeBlock( uint8 * ascii85_p, unsigned f_eod, const uint8 * raw
#endif /* EXP_ASCII85ENCODER */ #endif /* EXP_ASCII85ENCODER */
char* stuff[] = { const char* stuff[] = {
"usage: tiff2ps [options] input.tif ...", "usage: tiff2ps [options] input.tif ...",
"where options are:", "where options are:",
" -1 generate PostScript Level 1 (default)", " -1 generate PostScript Level 1 (default)",
@ -3120,13 +3127,12 @@ NULL
static void static void
usage(int code) 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(code); exit(code);
} }