Hi hackers, While on IRC, Beuc suggested that the pdf-filter utility returns an error when using 1) no filter or 2) a non-implemented filter. I thought it was a good idea, so I attach a patch for that feature here.
## # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: [email protected] # target_branch: file:///home/gerel/PROJECTS/libgnupdf/trunk/ # testament_sha1: 68781c0a97a54921c9da416a27a16548df5d22b8 # timestamp: 2009-02-01 18:55:00 -0300 # base_revision_id: [email protected] # # Begin patch === modified file 'ChangeLog' --- ChangeLog 2009-01-27 23:46:47 +0000 +++ ChangeLog 2009-02-01 21:54:46 +0000 @@ -1,3 +1,7 @@ +2009-02-01 Gerardo E. Gidoni <[email protected]> + + * utils/pdf-filter.c: added implemented filter's check. + 2009-01-28 Jose E. Marchesi <[email protected]> * doc/gnupdf-hg.texi (Opaque Pointers): Opaque pointers documented === modified file 'utils/pdf-filter.c' --- utils/pdf-filter.c 2009-01-27 20:59:40 +0000 +++ utils/pdf-filter.c 2009-02-01 21:54:46 +0000 @@ -1,4 +1,4 @@ -/* -*- mode: C -*- Time-stamp: "09/01/27 21:58:32 jemarch" +/* -*- mode: C -*- Time-stamp: "2009-02-01 18:53:26 gerel" * * File: pdf-filter.c * Date: Tue Jul 10 18:42:07 2007 @@ -143,11 +143,12 @@ static pdf_stm_t create_stream (int argc, char* argv[], pdf_bool_t* mode, pdf_status_t* last_ret, - pdf_bool_t * read_pdf_fsys, pdf_bool_t * write_pdf_fsys, - pdf_stm_t * fsys_stm); + int *optidx, pdf_bool_t * read_pdf_fsys, + pdf_bool_t * write_pdf_fsys, pdf_stm_t * fsys_stm); -static void -install_filters (int argc, char* argv[], pdf_stm_t stm, pdf_status_t ret); +static pdf_bool_t +install_filters (int argc, char* argv[], pdf_stm_t stm, pdf_status_t ret, + int * optidx); static void process_stream (pdf_stm_t, pdf_bool_t mode, pdf_bool_t read_pdf_fsys, @@ -160,14 +161,20 @@ int main (int argc, char *argv[]) { + int optidx; pdf_stm_t stm,fsys_stm; pdf_bool_t read_mode,read_pdf_fsys,write_pdf_fsys; pdf_status_t last_ret; pdf_status_t destroy_ret; - stm = create_stream (argc, argv, &read_mode, &last_ret, &read_pdf_fsys, + stm = create_stream (argc, argv, &read_mode,&last_ret,&optidx, &read_pdf_fsys, &write_pdf_fsys, &fsys_stm); - install_filters (argc, argv, stm, last_ret); + if (!install_filters (argc, argv, stm, last_ret, &optidx)) + { + fprintf (stderr, + "Error: At least one implemented filter must be specified.\n"); + exit(1); + } process_stream (stm, read_mode, read_pdf_fsys,write_pdf_fsys, fsys_stm); destroy_ret = pdf_stm_destroy (stm); if ((destroy_ret != PDF_OK) && (destroy_ret != PDF_EEOF)) @@ -270,7 +277,7 @@ static pdf_stm_t create_stream (int argc, char* argv[], pdf_bool_t* read_mode, - pdf_status_t* last_ret, pdf_bool_t * read_pdf_fsys, + pdf_status_t* last_ret, int *optidx, pdf_bool_t * read_pdf_fsys, pdf_bool_t * write_pdf_fsys, pdf_stm_t * fsys_stm) { char c; @@ -290,7 +297,7 @@ argv, "i:o:", GNU_longOptions, - NULL)) != -1) + optidx)) != -1) { c = ret; switch (c) @@ -428,9 +435,12 @@ return stm; } -static void -install_filters (int argc, char* argv[], pdf_stm_t stm, pdf_status_t ret) +static pdf_bool_t +install_filters (int argc, char* argv[], pdf_stm_t stm, pdf_status_t ret, + int * opt_index) { + char not_impl_format[] = "warning: --%s not implemented.\n"; + pdf_bool_t has_filters = PDF_FALSE; char c; pdf_hash_t filter_params; FILE *file; @@ -470,7 +480,7 @@ pdf_error (status, stderr, "while installing the null filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } case ASCIIHEXDEC_FILTER_ARG: @@ -490,7 +500,7 @@ pdf_error (status, stderr, "while installing the ASCII hex decoder filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } case ASCIIHEXENC_FILTER_ARG: @@ -510,23 +520,27 @@ pdf_error (status, stderr, "while installing the ASCII hex encoder filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } case ASCII85DEC_FILTER_ARG: { + fprintf (stderr, not_impl_format, GNU_longOptions[*opt_index].name); break; } case ASCII85ENC_FILTER_ARG: { + fprintf (stderr, not_impl_format, GNU_longOptions[*opt_index].name); break; } case LZWENC_FILTER_ARG: { + fprintf (stderr, not_impl_format, GNU_longOptions[*opt_index].name); break; } case LZWDEC_FILTER_ARG: { + fprintf (stderr, not_impl_format, GNU_longOptions[*opt_index].name); break; } #ifdef HAVE_LIBZ @@ -547,7 +561,7 @@ pdf_error (status, stderr, "while installing the flate decoder filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } case FLATEENC_FILTER_ARG: @@ -567,7 +581,7 @@ pdf_error (status, stderr, "while installing the flate encoder filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } #endif /* HAVE_LIBZ */ @@ -589,7 +603,7 @@ pdf_error (status, stderr, "while installing the RunLength decoder filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } case RUNLENGTHENC_FILTER_ARG: @@ -610,11 +624,12 @@ pdf_error (status, stderr, "while installing the RunLength encoder filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } case CCITTFAXDEC_FILTER_ARG: { + fprintf (stderr, not_impl_format, GNU_longOptions[*opt_index].name); break; } #ifdef HAVE_LIBJBIG2DEC @@ -643,6 +658,7 @@ } fclose (file); + has_filters |= PDF_TRUE; break; } case JBIG2DEC_FILTER_ARG: @@ -675,16 +691,18 @@ stream */ jbig2dec_global_segments = NULL; jbig2dec_global_segments_size = 0; - + has_filters |= PDF_TRUE; break; } #endif /* HAVE_LIBJBIG2DEC */ case DCTDEC_FILTER_ARG: { + fprintf (stderr, not_impl_format, GNU_longOptions[*opt_index].name); break; } case JXPDEC_FILTER_ARG: { + fprintf (stderr, not_impl_format, GNU_longOptions[*opt_index].name); break; } case PREDENC_FILTER_ARG: @@ -695,6 +713,7 @@ args.pred_colors, args.pred_bpc, args.pred_columns); */ + fprintf (stderr, not_impl_format, GNU_longOptions[*opt_index].name); break; } case PREDDEC_FILTER_ARG: @@ -705,6 +724,7 @@ args.pred_colors, args.pred_bpc, args.pred_columns); */ + fprintf (stderr, not_impl_format, GNU_longOptions[*opt_index].name); break; } case MD5ENC_FILTER_ARG: @@ -725,7 +745,7 @@ pdf_error (status, stderr, "while installing the MD5 encoder filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } case KEY_ARG: @@ -737,6 +757,7 @@ } key = strdup (optarg); + has_filters |= PDF_TRUE; break; } case AESENC_FILTER_ARG: @@ -769,7 +790,7 @@ pdf_error (status, stderr, "while installing the AESV2 encoder filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } case AESDEC_FILTER_ARG: @@ -802,7 +823,7 @@ pdf_error (status, stderr, "while installing the AESV2 decoder filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } case V2ENC_FILTER_ARG: @@ -835,7 +856,7 @@ pdf_error (status, stderr, "while installing the V2 encoder filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } case V2DEC_FILTER_ARG: @@ -868,7 +889,7 @@ pdf_error (status, stderr, "while installing the V2 decoder filter"); exit (1); } - + has_filters |= PDF_TRUE; break; } /* FILTER OPTIONS: */ @@ -887,8 +908,9 @@ argv, "", GNU_longOptions, - NULL)) != -1); + opt_index)) != -1); + return has_filters; } static # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWX06nvAABGDfgHh6c/f//3+F 3g6////+YAePn3x7vSmgdA69AGNhIB4SJIpjUNDU21NqeoxT9FNMIMCDCeoAYIwmg0KMm1U/U9Gq MgZNABpoaBgTEAGgGgDjI0yYmgyZMJpkDIaA0Bpk0MAJoDDVPyQTKmgHqPU9EAAAAAAAAAARVMlN Myg9IANGgDTQAAADQGjTIAkkAQE00EaNJgTApP1PSPQptTQxBj1R6mnqb1S4klaLQM1k8tMpXZrF T5OkkpmhtIP3i56H57LLls/eYCt52TUfFlO5OTLFrLrawihIgdPVGqIN0kEzWOlJz3IaU+q91Y3M 9pfMayhtQCUjaMMyEvKnAaCxZ9cdte1xqREoA4Nqa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