diff options
author | Werner Koch <[email protected]> | 2007-08-29 16:59:20 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2007-08-29 16:59:20 +0000 |
commit | 8464627bf444de523c05c44a5a174e4d3736549c (patch) | |
tree | 3b4b5ed8df2106cb8afa1e429acaa5a315d3bcbc /jnlib/argparse.c | |
parent | New command --check-programs for gpgconf. (diff) | |
download | gnupg-8464627bf444de523c05c44a5a174e4d3736549c.tar.gz gnupg-8464627bf444de523c05c44a5a174e4d3736549c.zip |
Extended the --check-program output: Error messages are now inlcued in an
easy parsable format.
Diffstat (limited to 'jnlib/argparse.c')
-rw-r--r-- | jnlib/argparse.c | 112 |
1 files changed, 59 insertions, 53 deletions
diff --git a/jnlib/argparse.c b/jnlib/argparse.c index 2d46884f0..3104db40e 100644 --- a/jnlib/argparse.c +++ b/jnlib/argparse.c @@ -149,65 +149,71 @@ static void show_version(void); static void initialize( ARGPARSE_ARGS *arg, const char *filename, unsigned *lineno ) { - if( !(arg->flags & (1<<15)) ) { /* initialize this instance */ - arg->internal.idx = 0; - arg->internal.last = NULL; - arg->internal.inarg = 0; - arg->internal.stopped = 0; - arg->internal.aliases = NULL; - arg->internal.cur_alias = NULL; - arg->err = 0; - arg->flags |= 1<<15; /* mark initialized */ - if( *arg->argc < 0 ) - jnlib_log_bug("Invalid argument for ArgParse\n"); + if( !(arg->flags & (1<<15)) ) + { + /* Initialize this instance. */ + arg->internal.idx = 0; + arg->internal.last = NULL; + arg->internal.inarg = 0; + arg->internal.stopped = 0; + arg->internal.aliases = NULL; + arg->internal.cur_alias = NULL; + arg->err = 0; + arg->flags |= 1<<15; /* Mark as initialized. */ + if ( *arg->argc < 0 ) + jnlib_log_bug ("invalid argument for arg_parsee\n"); } - - - if( arg->err ) { /* last option was erroneous */ - const char *s; - - if( filename ) { - if( arg->r_opt == -6 ) - s = "argument not expected\n"; - else if( arg->r_opt == -5 ) - s = "read error\n"; - else if( arg->r_opt == -4 ) - s = "keyword too long\n"; - else if( arg->r_opt == -3 ) - s = "missing argument\n"; - else if( arg->r_opt == -7 ) - s = "invalid command\n"; - else if( arg->r_opt == -10 ) - s = "invalid alias definition\n"; - else - s = "invalid option\n"; - jnlib_log_error("%s:%u: %s\n", filename, *lineno, s); + + + if (arg->err) + { + /* Last option was erroneous. */ + const char *s; + + if (filename) + { + if ( arg->r_opt == -6 ) + s = _("argument not expected"); + else if ( arg->r_opt == -5 ) + s = _("read error"); + else if ( arg->r_opt == -4 ) + s = _("keyword too long"); + else if ( arg->r_opt == -3 ) + s = _("missing argument"); + else if ( arg->r_opt == -7 ) + s = _("invalid command"); + else if ( arg->r_opt == -10 ) + s = _("invalid alias definition"); + else + s = _("invalid option"); + jnlib_log_error ("%s:%u: %s\n", filename, *lineno, s); } - else { - s = arg->internal.last? arg->internal.last:"[??]"; + else + { + s = arg->internal.last? arg->internal.last:"[??]"; - if( arg->r_opt == -3 ) - jnlib_log_error ("Missing argument for option \"%.50s\"\n", s); - else if( arg->r_opt == -6 ) - jnlib_log_error ("Option \"%.50s\" does not expect an argument\n", - s ); - else if( arg->r_opt == -7 ) - jnlib_log_error ("Invalid command \"%.50s\"\n", s); - else if( arg->r_opt == -8 ) - jnlib_log_error ("Option \"%.50s\" is ambiguous\n", s); - else if( arg->r_opt == -9 ) - jnlib_log_error ("Command \"%.50s\" is ambiguous\n",s ); - else - jnlib_log_error ("Invalid option \"%.50s\"\n", s); + if ( arg->r_opt == -3 ) + jnlib_log_error (_("missing argument for option \"%.50s\"\n"), s); + else if ( arg->r_opt == -6 ) + jnlib_log_error (_("option \"%.50s\" does not expect an " + "argument\n"), s ); + else if ( arg->r_opt == -7 ) + jnlib_log_error (_("invalid command \"%.50s\"\n"), s); + else if ( arg->r_opt == -8 ) + jnlib_log_error (_("option \"%.50s\" is ambiguous\n"), s); + else if ( arg->r_opt == -9 ) + jnlib_log_error (_("command \"%.50s\" is ambiguous\n"),s ); + else + jnlib_log_error (_("invalid option \"%.50s\"\n"), s); } - if( arg->err != 1 ) - exit(2); - arg->err = 0; + if ( arg->err != 1 ) + exit (2); + arg->err = 0; } - /* clearout the return value union */ - arg->r.ret_str = NULL; - arg->r.ret_long= 0; + /* Zero out the return value union. */ + arg->r.ret_str = NULL; + arg->r.ret_long = 0; } |