From b0c2f3dee12b4051bd210a143d195089ec7afe8f Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sun, 30 Dec 2007 14:36:00 +0000 Subject: [PATCH] use G_OPTION_REMAINING to access the filenames passed as command-line 2007-12-30 Sven Neumann * plug-ins/jpeg/jpegqual.c: use G_OPTION_REMAINING to access the filenames passed as command-line arguments. svn path=/trunk/; revision=24477 --- ChangeLog | 5 +++ plug-ins/jpeg/jpegqual.c | 91 ++++++++++++++++++++++++++++------------ 2 files changed, 69 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c8f49ae8a..ca3af178f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-12-30 Sven Neumann + + * plug-ins/jpeg/jpegqual.c: use G_OPTION_REMAINING to access the + filenames passed as command-line arguments. + 2007-12-30 Sven Neumann * plug-ins/script-fu/scripts/chip-away.scm: applied another patch diff --git a/plug-ins/jpeg/jpegqual.c b/plug-ins/jpeg/jpegqual.c index e0d690ef9e..848ff5f1e7 100644 --- a/plug-ins/jpeg/jpegqual.c +++ b/plug-ins/jpeg/jpegqual.c @@ -40,8 +40,10 @@ */ #include +#include #include #include + #include #include @@ -50,26 +52,44 @@ #include "jpeg-quality.h" /* command-line options */ -static gboolean option_summary = FALSE; -static gboolean option_ctable = FALSE; -static gboolean option_table_2cols = FALSE; -static gboolean option_unknown = FALSE; -static gboolean option_ignore_err = FALSE; +static gboolean option_summary = FALSE; +static gboolean option_ctable = FALSE; +static gboolean option_table_2cols = FALSE; +static gboolean option_unknown = FALSE; +static gboolean option_ignore_err = FALSE; +static gchar **filenames = NULL; -static GOptionEntry option_entries[] = +static const GOptionEntry option_entries[] = { - { "ignore-errors", 'i', 0, G_OPTION_ARG_NONE, &option_ignore_err, - "Continue processing other files after a JPEG error", NULL }, - { "summary", 's', 0, G_OPTION_ARG_NONE, &option_summary, - "Print summary information and closest IJG quality", NULL }, - { "tables", 't', 0, G_OPTION_ARG_NONE, &option_table_2cols, - "Dump quantization tables", NULL }, - { "c-tables", 'c', 0, G_OPTION_ARG_NONE, &option_ctable, - "Dump quantization tables as C code", NULL }, - { "ctables", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &option_ctable, - NULL, NULL }, - { "unknown", 'u', 0, G_OPTION_ARG_NONE, &option_unknown, - "Only print information about files with unknown tables", NULL }, + { + "ignore-errors", 'i', 0, G_OPTION_ARG_NONE, &option_ignore_err, + "Continue processing other files after a JPEG error", NULL + }, + { + "summary", 's', 0, G_OPTION_ARG_NONE, &option_summary, + "Print summary information and closest IJG quality", NULL + }, + { + "tables", 't', 0, G_OPTION_ARG_NONE, &option_table_2cols, + "Dump quantization tables", NULL + }, + { + "c-tables", 'c', 0, G_OPTION_ARG_NONE, &option_ctable, + "Dump quantization tables as C code", NULL + }, + { + "ctables", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &option_ctable, + NULL, NULL + }, + { + "unknown", 'u', 0, G_OPTION_ARG_NONE, &option_unknown, + "Only print information about files with unknown tables", NULL + }, + { + G_OPTION_REMAINING, 0, 0, + G_OPTION_ARG_FILENAME_ARRAY, &filenames, + NULL, NULL + }, { NULL } }; @@ -535,13 +555,16 @@ add_unknown_table (struct jpeg_decompress_struct *cinfo, table_data->hashval = hashval; table_data->subsmp_h = cinfo->comp_info[0].h_samp_factor; table_data->subsmp_v = cinfo->comp_info[0].v_samp_factor; + num_quant_tables = 0; for (t = 0; t < 4; t++) if (cinfo->quant_tbl_ptrs[t]) num_quant_tables++; + table_data->num_quant_tables = num_quant_tables; table_data->ijg_qual = jpeg_detect_quality (cinfo); table_data->files = g_slist_prepend (NULL, filename); + if (cinfo->quant_tbl_ptrs[0]) { for (i = 0; i < DCTSIZE2; i++) @@ -552,6 +575,7 @@ add_unknown_table (struct jpeg_decompress_struct *cinfo, for (i = 0; i < DCTSIZE2; i++) table_data->luminance[i] = 0; } + if (cinfo->quant_tbl_ptrs[1]) { for (i = 0; i < DCTSIZE2; i++) @@ -562,6 +586,7 @@ add_unknown_table (struct jpeg_decompress_struct *cinfo, for (i = 0; i < DCTSIZE2; i++) table_data->chrominance[i] = 0; } + found_tables = g_slist_prepend (found_tables, table_data); } @@ -1013,34 +1038,46 @@ int main (int argc, char *argv[]) { - GError *error = NULL; GOptionContext *context; + GError *error = NULL; + gint i; g_set_prgname ("jpegqual"); - context = g_option_context_new ("FILE [...] - analyzes JPEG quantization tables"); + context = + g_option_context_new ("FILE [...] - analyzes JPEG quantization tables"); g_option_context_add_main_entries (context, option_entries, NULL /* skip i18n? */); - g_option_context_parse (context, &argc, &argv, &error); - if (argc <= 1) + + if (! g_option_context_parse (context, &argc, &argv, &error)) + { + g_printerr ("%s\n", error->message); + g_error_free (error); + return EXIT_FAILURE; + } + + if (! filenames) { g_printerr ("Missing file name. Try the option --help for help\n"); - return 1; + return EXIT_FAILURE; } + if (!option_summary && !option_ctable && !option_table_2cols) { g_printerr ("Missing output option. Assuming that you wanted --summary.\n"); option_summary = TRUE; } - for (argv++, argc--; *argv; argv++, argc--) + for (i = 0; filenames[i]; i++) { - if (! analyze_file (*argv) && ! option_ignore_err) - return 1; + if (! analyze_file (filenames[i]) && ! option_ignore_err) + return EXIT_FAILURE; } + if (option_unknown && found_tables) { print_unknown_tables (); } - return 0; + + return EXIT_SUCCESS; }