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 | |
| parent | d01e3b4c482bd243a0265b6292f1f919f3750fef (diff) | |
| parent | 13e0fc50583209894d699def95ecd2e23feac558 (diff) | |
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/parse_options.c | 51 | ||||
| -rw-r--r-- | src/lib/parse_options.h | 17 |
2 files changed, 59 insertions, 9 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++) { diff --git a/src/lib/parse_options.h b/src/lib/parse_options.h index 8c784b96..d86662e2 100644 --- a/src/lib/parse_options.h +++ b/src/lib/parse_options.h @@ -23,6 +23,13 @@ extern "C" { #endif +const char *abrt_init(char **argv); +#define export_abrt_envvars abrt_export_abrt_envvars +void export_abrt_envvars(int pfx); +#define g_progname abrt_g_progname +extern const char *g_progname; + + enum parse_opt_type { OPTION_BOOL, OPTION_GROUP, @@ -50,12 +57,12 @@ struct options { * h - help */ #define OPT_END() { OPTION_END } -#define OPT_BOOL(s, l, v, h) { OPTION_BOOL, (s), (l), (v), NULL, (h) } #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) } -#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), "NUM", (h) } -#define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v), (a), (h) } -#define OPT_OPTSTRING(s, l, v, a, h) { OPTION_OPTSTRING, (s), (l), (v), (a), (h) } -#define OPT_LIST(s, l, v, a, h) { OPTION_LIST, (s), (l), (v), (a), (h) } +#define OPT_BOOL( s, l, v, h) { OPTION_BOOL , (s), (l), (v), NULL , (h) } +#define OPT_INTEGER( s, l, v, h) { OPTION_INTEGER , (s), (l), (v), "NUM", (h) } +#define OPT_STRING( s, l, v, a, h) { OPTION_STRING , (s), (l), (v), (a) , (h) } +#define OPT_OPTSTRING(s, l, v, a, h) { OPTION_OPTSTRING, (s), (l), (v), (a) , (h) } +#define OPT_LIST( s, l, v, a, h) { OPTION_LIST , (s), (l), (v), (a) , (h) } #define OPT__VERBOSE(v) OPT_BOOL('v', "verbose", (v), _("Be verbose")) |
