tiff2pdf: print usage on stdout when -h is used

see #17
This commit is contained in:
Thomas Bernard 2020-03-07 16:06:40 +01:00
parent 2c6e8805ba
commit ee6cf2f59d
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -263,7 +263,7 @@ typedef struct {
/* These functions are called by main. */ /* These functions are called by main. */
void tiff2pdf_usage(void); static void tiff2pdf_usage(int);
int tiff2pdf_match_paper_size(float*, float*, char*); int tiff2pdf_match_paper_size(float*, float*, char*);
/* These functions are used to generate a PDF from a TIFF. */ /* These functions are used to generate a PDF from a TIFF. */
@ -754,11 +754,12 @@ int main(int argc, char** argv){
case 'b': case 'b':
t2p->pdf_image_interpolate = 1; t2p->pdf_image_interpolate = 1;
break; break;
case 'h': case 'h':
case '?': tiff2pdf_usage(EXIT_SUCCESS);
tiff2pdf_usage();
goto success; goto success;
break; case '?':
tiff2pdf_usage(EXIT_FAILURE);
goto fail;
} }
} }
@ -775,14 +776,14 @@ int main(int argc, char** argv){
} }
} else { } else {
TIFFError(TIFF2PDF_MODULE, "No input file specified"); TIFFError(TIFF2PDF_MODULE, "No input file specified");
tiff2pdf_usage(); tiff2pdf_usage(EXIT_FAILURE);
goto fail; goto fail;
} }
if(argc > optind) { if(argc > optind) {
TIFFError(TIFF2PDF_MODULE, TIFFError(TIFF2PDF_MODULE,
"No support for multiple input files"); "No support for multiple input files");
tiff2pdf_usage(); tiff2pdf_usage(EXIT_FAILURE);
goto fail; goto fail;
} }
@ -844,8 +845,8 @@ success:
} }
void tiff2pdf_usage(){ static void tiff2pdf_usage(int code) {
char* lines[]={ static const char* lines[]={
"usage: tiff2pdf [options] input.tiff", "usage: tiff2pdf [options] input.tiff",
"options:", "options:",
" -o: output to file name", " -o: output to file name",
@ -866,7 +867,7 @@ void tiff2pdf_usage(){
" -l: length in units", " -l: length in units",
" -r: 'd' for resolution default, 'o' for resolution override", " -r: 'd' for resolution default, 'o' for resolution override",
" -p: paper size, eg \"letter\", \"legal\", \"A4\"", " -p: paper size, eg \"letter\", \"legal\", \"A4\"",
" -F: make the tiff fill the PDF page", " -F: make the tiff fill the PDF page",
" -f: set PDF \"Fit Window\" user preference", " -f: set PDF \"Fit Window\" user preference",
" -e: date, overrides image or current date/time default, YYYYMMDDHHMMSS", " -e: date, overrides image or current date/time default, YYYYMMDDHHMMSS",
" -c: sets document creator, overrides image software default", " -c: sets document creator, overrides image software default",
@ -880,10 +881,11 @@ void tiff2pdf_usage(){
NULL NULL
}; };
int i=0; int i=0;
FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
fprintf(stderr, "%s\n\n", TIFFGetVersion()); fprintf(out, "%s\n\n", TIFFGetVersion());
for (i=0;lines[i]!=NULL;i++){ for (i=0;lines[i]!=NULL;i++){
fprintf(stderr, "%s\n", lines[i]); fprintf(out, "%s\n", lines[i]);
} }
return; return;