summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bernard <miniupnp@free.fr>2020-03-07 12:32:28 +0100
committerThomas Bernard <miniupnp@free.fr>2020-04-26 22:11:34 +0200
commit0aed3363cf061b7db6b59357dfedc4ca257166ae (patch)
treeadd7fa6a1b32177fa1d8c0e7755205ae1c877358
parentb683c3752430a25940cde0d380929c0f79ba6d03 (diff)
downloadlibtiff-git-0aed3363cf061b7db6b59357dfedc4ca257166ae.tar.gz
fax2ps: output usage to stdout when using -h option
also use EXIT_SUCCESS, EXIT_FAILURE from C standard
-rw-r--r--tools/fax2ps.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/tools/fax2ps.c b/tools/fax2ps.c
index 274b29e4..f59f4921 100644
--- a/tools/fax2ps.c
+++ b/tools/fax2ps.c
@@ -48,6 +48,13 @@
#include "tiffiop.h"
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
float defxres = 204.; /* default x resolution (pixels/inch) */
float defyres = 98.; /* default y resolution (lines/inch) */
const float half = 0.5;
@@ -330,7 +337,7 @@ main(int argc, char** argv)
int c, dowarnings = 0; /* if 1, enable library warnings */
TIFF* tif;
- while ((c = getopt(argc, argv, "l:p:x:y:W:H:wS")) != -1)
+ while ((c = getopt(argc, argv, "l:p:x:y:W:H:wSh")) != -1)
switch (c) {
case 'H': /* page height */
pageHeight = (float)atof(optarg);
@@ -350,7 +357,7 @@ main(int argc, char** argv)
if( pages == NULL )
{
fprintf(stderr, "Out of memory\n");
- exit(-1);
+ exit(EXIT_FAILURE);
}
pages[npages++] = pageNumber;
break;
@@ -366,8 +373,10 @@ main(int argc, char** argv)
case 'l':
maxline = atoi(optarg);
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
case '?':
- usage(-1);
+ usage(EXIT_FAILURE);
}
if (npages > 0)
qsort(pages, npages, sizeof(uint16), pcompar);
@@ -391,7 +400,7 @@ main(int argc, char** argv)
fd = tmpfile();
if (fd == NULL) {
fprintf(stderr, "Could not obtain temporary file.\n");
- exit(-2);
+ exit(EXIT_FAILURE);
}
#if defined(HAVE_SETMODE) && defined(O_BINARY)
setmode(fileno(stdin), O_BINARY);
@@ -401,7 +410,7 @@ main(int argc, char** argv)
fclose(fd);
fprintf(stderr,
"Could not copy stdin to temporary file.\n");
- exit(-2);
+ exit(EXIT_FAILURE);
}
}
_TIFF_lseek_f(fileno(fd), 0, SEEK_SET);
@@ -421,10 +430,10 @@ main(int argc, char** argv)
printf("%%%%Pages: %u\n", totalPages);
printf("%%%%EOF\n");
- return (0);
+ return (EXIT_SUCCESS);
}
-char* stuff[] = {
+const char* stuff[] = {
"usage: fax2ps [options] [input.tif ...]",
"where options are:",
" -w suppress warning messages",
@@ -441,13 +450,12 @@ NULL
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);
}