thumbnail: use EXIT_FAILURE / EXIT_SUCCESS
the -h option was already used so it cannot be used for help/usage see #17
This commit is contained in:
parent
aa4409eda5
commit
da2995eecf
@ -39,6 +39,13 @@
|
|||||||
|
|
||||||
#include "tiffio.h"
|
#include "tiffio.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
|
||||||
@ -67,7 +74,7 @@ static uint8* thumbnail;
|
|||||||
static int cpIFD(TIFF*, TIFF*);
|
static int cpIFD(TIFF*, TIFF*);
|
||||||
static int generateThumbnail(TIFF*, TIFF*);
|
static int generateThumbnail(TIFF*, TIFF*);
|
||||||
static void initScale();
|
static void initScale();
|
||||||
static void usage(void);
|
static void usage(int code);
|
||||||
|
|
||||||
#if !HAVE_DECL_OPTARG
|
#if !HAVE_DECL_OPTARG
|
||||||
extern char* optarg;
|
extern char* optarg;
|
||||||
@ -94,11 +101,11 @@ main(int argc, char* argv[])
|
|||||||
streq(optarg, "linear")? LINEAR :
|
streq(optarg, "linear")? LINEAR :
|
||||||
EXP;
|
EXP;
|
||||||
break;
|
break;
|
||||||
default: usage();
|
default: usage(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (argc-optind != 2)
|
if (argc-optind != 2)
|
||||||
usage();
|
usage(EXIT_FAILURE);
|
||||||
|
|
||||||
out = TIFFOpen(argv[optind+1], "w");
|
out = TIFFOpen(argv[optind+1], "w");
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
@ -111,7 +118,7 @@ main(int argc, char* argv[])
|
|||||||
if (!thumbnail) {
|
if (!thumbnail) {
|
||||||
TIFFError(TIFFFileName(in),
|
TIFFError(TIFFFileName(in),
|
||||||
"Can't allocate space for thumbnail buffer.");
|
"Can't allocate space for thumbnail buffer.");
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in != NULL) {
|
if (in != NULL) {
|
||||||
@ -125,10 +132,10 @@ main(int argc, char* argv[])
|
|||||||
(void) TIFFClose(in);
|
(void) TIFFClose(in);
|
||||||
}
|
}
|
||||||
(void) TIFFClose(out);
|
(void) TIFFClose(out);
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
bad:
|
bad:
|
||||||
(void) TIFFClose(out);
|
(void) TIFFClose(out);
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CopyField(tag, v) \
|
#define CopyField(tag, v) \
|
||||||
@ -650,7 +657,7 @@ generateThumbnail(TIFF* in, TIFF* out)
|
|||||||
TIFFWriteDirectory(out) != -1);
|
TIFFWriteDirectory(out) != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* stuff[] = {
|
const char* stuff[] = {
|
||||||
"usage: thumbnail [options] input.tif output.tif",
|
"usage: thumbnail [options] input.tif output.tif",
|
||||||
"where options are:",
|
"where options are:",
|
||||||
" -h # specify thumbnail image height (default is 274)",
|
" -h # specify thumbnail image height (default is 274)",
|
||||||
@ -667,16 +674,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set ts=8 sts=8 sw=8 noet: */
|
/* vim: set ts=8 sts=8 sw=8 noet: */
|
||||||
|
Loading…
Reference in New Issue
Block a user