diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | examples/renderdemo.c | 49 | ||||
-rw-r--r-- | pango/querymodules.c | 40 |
3 files changed, 82 insertions, 14 deletions
@@ -1,3 +1,10 @@ +2006-02-15 Behdad Esfahbod <behdad@gnome.org> + + Bug 331038 – pango-querymodules --help and --version + Patch from Antoine Dopffer. + + * examples/renderdemo.c, pango/querymodules.c: Add --version option. + 2006-02-13 Behdad Esfahbod <behdad@gnome.org> * configure.in: Pass gnits instead of gnu to automake. diff --git a/examples/renderdemo.c b/examples/renderdemo.c index 42bde875..76cea9a8 100644 --- a/examples/renderdemo.c +++ b/examples/renderdemo.c @@ -27,6 +27,7 @@ #include <string.h> #include <glib.h> +#include <glib/gprintf.h> #include <pango/pango.h> #include "renderdemo.h" @@ -366,8 +367,11 @@ parse_ellipsis (const char *name, opt_ellipsize = value->value; else { - fail ("--ellipsize option must be one of none/start/middle/end"); - ret = FALSE; + g_set_error(error, + G_OPTION_ERROR, + G_OPTION_ERROR_BAD_VALUE, + "Argument for --ellipsize must be one of none/start/middle/end"); + ret = FALSE; } return ret; @@ -393,10 +397,13 @@ parse_hinting (const char *name, opt_hinting = HINT_FULL; else { - fail ("--hinting option must be one of none/auto/full"); + g_set_error(error, + G_OPTION_ERROR, + G_OPTION_ERROR_BAD_VALUE, + "Argument for --hinting must be one of none/auto/full"); ret = FALSE; } - + return ret; } @@ -421,7 +428,10 @@ parse_wrap (const char *name, } else { - fail ("--wrap option must be one of word/char/word-char"); + g_set_error(error, + G_OPTION_ERROR, + G_OPTION_ERROR_BAD_VALUE, + "Argument for --wrap must be one of word/char/word-char"); ret = FALSE; } @@ -496,7 +506,11 @@ parse_backend (const char *name, { gchar *backends = backends_to_string (); - fail ("available --backend options are: %s", backends); + g_set_error(error, + G_OPTION_ERROR, + G_OPTION_ERROR_BAD_VALUE, + "Available --backend options are: %s", + backends); g_free(backends); ret = FALSE; } @@ -505,6 +519,17 @@ parse_backend (const char *name, } +static gboolean +show_version(const char *name, + const char *arg, + gpointer data, + GError **error) +{ + g_printf("%s (%s) %s\n", prog_name, PACKAGE_NAME, PACKAGE_VERSION); + g_printf("module interface version: %s\n", MODULE_VERSION); + exit(0); +} + void parse_options (int argc, char *argv[]) { @@ -547,6 +572,8 @@ parse_options (int argc, char *argv[]) "Run Pango layout engine this many times", "integer"}, {"text", 't', 0, G_OPTION_ARG_STRING, &opt_text, "Text to display (instead of a file)", "string"}, + {"version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, &show_version, + "Show version numbers", NULL}, {"waterfall", 0, 0, G_OPTION_ARG_NONE, &opt_waterfall, "Create a waterfall display", NULL}, {"width", 'w', 0, G_OPTION_ARG_INT, &opt_width, @@ -567,13 +594,9 @@ parse_options (int argc, char *argv[]) if (!g_option_context_parse (context, &argc, &argv, &parse_error)) { if (parse_error != NULL) - { - fail("Parse option error : %s\n", parse_error->message); - } + fail("%s", parse_error->message); else - { - fail("Parse option error\n"); - } + fail("Option parse error"); exit(1); } g_option_context_free(context); @@ -615,7 +638,7 @@ parse_options (int argc, char *argv[]) if (!g_file_get_contents (argv[1], &text, &len, &error)) fail ("%s\n", error->message); if (!g_utf8_validate (text, len, NULL)) - fail ("Text is not valid UTF-8"); + fail ("Input text is not valid UTF-8"); } /* Strip trailing whitespace diff --git a/pango/querymodules.c b/pango/querymodules.c index 65a91b89..72dd2183 100644 --- a/pango/querymodules.c +++ b/pango/querymodules.c @@ -19,6 +19,7 @@ * Boston, MA 02111-1307, USA. */ +#include <stdlib.h> #include <config.h> #include <glib.h> @@ -181,13 +182,50 @@ query_module (const char *dir, const char *name) g_module_close (module); } +static gboolean +show_version(const char *name, + const char *arg, + gpointer data, + GError **error) +{ + g_printf("pango-querymodules (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION); + g_printf("module interface version: %s\n", MODULE_VERSION); + exit(0); +} + int main (int argc, char **argv) { char *cwd; int i; char *path; - + GOptionContext *context; + GError *parse_error = NULL; + GOptionEntry entries[] = + { + {"version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, &show_version, + "Show version numbers", NULL}, + {NULL} + }; + + context = g_option_context_new ("- [MODULE]..."); + g_option_context_add_main_entries (context, entries, NULL); + + if (!g_option_context_parse (context, &argc, &argv, &parse_error)) + { + if (parse_error != NULL) + { + g_printerr("Parse option error: %s\n", parse_error->message); + } + else + { + g_printerr("Parse option error\n"); + } + exit(1); + } + + g_option_context_free(context); + g_type_init (); g_printf ("# Pango Modules file\n" |