diff options
| author | Karel Klic <kklic@redhat.com> | 2011-05-05 13:51:03 +0200 |
|---|---|---|
| committer | Karel Klic <kklic@redhat.com> | 2011-05-05 13:51:03 +0200 |
| commit | cb09f7742092950787283e6cbb4ac7af9e8d00fd (patch) | |
| tree | 6199412f207fbb6a262b77e33b61de70aa550d20 /src/lib/parse_options.c | |
| parent | d01e3b4c482bd243a0265b6292f1f919f3750fef (diff) | |
| parent | 13e0fc50583209894d699def95ecd2e23feac558 (diff) | |
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'src/lib/parse_options.c')
| -rw-r--r-- | src/lib/parse_options.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/src/lib/parse_options.c b/src/lib/parse_options.c index d9ce8a2f..4e4a3e08 100644 --- a/src/lib/parse_options.c +++ b/src/lib/parse_options.c @@ -24,12 +24,55 @@ #define USAGE_OPTS_WIDTH 24 #define USAGE_GAP 2 -void show_usage_and_die(const char *usage, const struct options *opt) +const char *g_progname; + +const char *abrt_init(char **argv) { - fprintf(stderr, _("Usage: %s\n"), usage); + char *env_verbose = getenv("ABRT_VERBOSE"); + if (env_verbose) + g_verbose = atoi(env_verbose); + + g_progname = strrchr(argv[0], '/'); + if (g_progname) + g_progname++; + else + g_progname = argv[0]; + + char *pfx = getenv("ABRT_PROG_PREFIX"); + if (pfx && string_to_bool(pfx)) + msg_prefix = g_progname; + + return g_progname; +} - if (opt->type != OPTION_GROUP) - fputc('\n', stderr); +void export_abrt_envvars(int pfx) +{ + putenv(xasprintf("ABRT_VERBOSE=%u", g_verbose)); + if (pfx) + { + putenv((char*)"ABRT_PROG_PREFIX=1"); + msg_prefix = g_progname; + } +} + +void show_usage_and_die(const char *usage, const struct options *opt) +{ + fputs(_("Usage: "), stderr); + while (*usage) + { + int len = strchrnul(usage, '\b') - usage; + if (len > 0) + { + fprintf(stderr, "%.*s", len, usage); + usage += len; + } + if (*usage == '\b') + { + fputs(g_progname, stderr); + usage++; + } + } + fputs("\n\n", stderr); for (; opt->type != OPTION_END; opt++) { |
