tiff2rgba: output usage to stdout when using -h
also uses std C EXIT_FAILURE / EXIT_SUCCESS see #17
This commit is contained in:
parent
05993b6408
commit
02875964eb
@ -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)
|
||||
@ -68,7 +75,7 @@ main(int argc, char* argv[])
|
||||
extern char *optarg;
|
||||
#endif
|
||||
|
||||
while ((c = getopt(argc, argv, "c:r:t:bn8")) != -1)
|
||||
while ((c = getopt(argc, argv, "c:r:t:bn8h")) != -1)
|
||||
switch (c) {
|
||||
case 'b':
|
||||
process_by_block = 1;
|
||||
@ -86,7 +93,7 @@ main(int argc, char* argv[])
|
||||
else if (streq(optarg, "zip"))
|
||||
compression = COMPRESSION_DEFLATE;
|
||||
else
|
||||
usage(-1);
|
||||
usage(EXIT_FAILURE);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
@ -105,17 +112,20 @@ main(int argc, char* argv[])
|
||||
bigtiff_output = 1;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
usage(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
case '?':
|
||||
usage(0);
|
||||
usage(EXIT_FAILURE);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
if (argc - optind < 2)
|
||||
usage(-1);
|
||||
usage(EXIT_FAILURE);
|
||||
|
||||
out = TIFFOpen(argv[argc-1], bigtiff_output?"w8":"w");
|
||||
if (out == NULL)
|
||||
return (-2);
|
||||
return (EXIT_FAILURE);
|
||||
|
||||
for (; optind < argc-1; optind++) {
|
||||
in = TIFFOpen(argv[optind], "r");
|
||||
@ -132,7 +142,7 @@ main(int argc, char* argv[])
|
||||
}
|
||||
}
|
||||
(void) TIFFClose(out);
|
||||
return (0);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -166,7 +176,7 @@ cvt_by_tile( TIFF *in, TIFF *out )
|
||||
if (tile_width != (rastersize / tile_height) / sizeof( uint32))
|
||||
{
|
||||
TIFFError(TIFFFileName(in), "Integer overflow when calculating raster buffer");
|
||||
exit(-1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
raster = (uint32*)_TIFFmalloc(rastersize);
|
||||
if (raster == 0) {
|
||||
@ -182,7 +192,7 @@ cvt_by_tile( TIFF *in, TIFF *out )
|
||||
if (tile_width != wrk_linesize / sizeof (uint32))
|
||||
{
|
||||
TIFFError(TIFFFileName(in), "Integer overflow when calculating wrk_line buffer");
|
||||
exit(-1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
wrk_line = (uint32*)_TIFFmalloc(wrk_linesize);
|
||||
if (!wrk_line) {
|
||||
@ -279,7 +289,7 @@ cvt_by_strip( TIFF *in, TIFF *out )
|
||||
if (width != (rastersize / rowsperstrip) / sizeof( uint32))
|
||||
{
|
||||
TIFFError(TIFFFileName(in), "Integer overflow when calculating raster buffer");
|
||||
exit(-1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
raster = (uint32*)_TIFFmalloc(rastersize);
|
||||
if (raster == 0) {
|
||||
@ -295,7 +305,7 @@ cvt_by_strip( TIFF *in, TIFF *out )
|
||||
if (width != wrk_linesize / sizeof (uint32))
|
||||
{
|
||||
TIFFError(TIFFFileName(in), "Integer overflow when calculating wrk_line buffer");
|
||||
exit(-1);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
wrk_line = (uint32*)_TIFFmalloc(wrk_linesize);
|
||||
if (!wrk_line) {
|
||||
@ -528,7 +538,7 @@ tiffcvt(TIFF* in, TIFF* out)
|
||||
return( cvt_whole_image( in, out ) );
|
||||
}
|
||||
|
||||
static char* stuff[] = {
|
||||
const static char* stuff[] = {
|
||||
"usage: tiff2rgba [-c comp] [-r rows] [-b] [-n] [-8] input... output",
|
||||
"where comp is one of the following compression algorithms:",
|
||||
" jpeg\t\tJPEG encoding",
|
||||
@ -547,13 +557,12 @@ static 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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user