summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-01-19 00:31:04 +0000
committerMiles Bader <miles@gnu.org>1996-01-19 00:31:04 +0000
commiteb5616108ddc7fed7da94c9caf935c06b1106f2f (patch)
tree86f9de7abaec5ee9087cda9ed3c4c7f755445fd4
parent9dce711573e27cd3b01eb119347c33a3863c5895 (diff)
(argp_default_options, argp_default_parser):
Add --program-name (hidden) option. (OPT_PROGNAME): New macro.
-rw-r--r--libshouldbeinlibc/argp-parse.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/libshouldbeinlibc/argp-parse.c b/libshouldbeinlibc/argp-parse.c
index c52bc1f1..9690ea22 100644
--- a/libshouldbeinlibc/argp-parse.c
+++ b/libshouldbeinlibc/argp-parse.c
@@ -40,10 +40,12 @@
/* ---------------------------------------------------------------- */
#define OPT_HELP -1
+#define OPT_PROGNAME -2
static struct argp_option argp_default_options[] =
{
- {"help", OPT_HELP, 0, 0, "Give this help list", -1},
+ {"help", OPT_HELP, 0, 0, "Give this help list", -1},
+ {"program-name",OPT_PROGNAME,"NAME", OPTION_HIDDEN, "Set the program name"},
{0, 0}
};
@@ -57,10 +59,26 @@ argp_default_parser (int key, char *arg, struct argp_state *state)
if (state->flags & ARGP_NO_EXIT)
usage_flags &= ~ARGP_HELP_EXIT;
argp_help (state->argp, stdout, usage_flags);
- return 0;
+ break;
+
+ case OPT_PROGNAME: /* Set the program name. */
+ program_invocation_name = arg;
+ program_invocation_short_name = rindex (arg, '/');
+ if (program_invocation_short_name)
+ program_invocation_short_name++;
+ else
+ program_invocation_short_name = program_invocation_name;
+
+ if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
+ == (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
+ state->argv[0] = arg; /* Update what getopt uses too. */
+
+ break;
+
default:
return EINVAL;
}
+ return 0;
}
static struct argp argp_default_argp =