From fb0cd889c011a128a8d03ebeb52f43cd44f5b40e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 15 Apr 2011 17:30:31 +0200 Subject: abrt-cli: select reporters by numbers (trac#194) --- src/cli/report.c | 58 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 15 deletions(-) (limited to 'src/cli/report.c') diff --git a/src/cli/report.c b/src/cli/report.c index 96bf0062..72e9c4a6 100644 --- a/src/cli/report.c +++ b/src/cli/report.c @@ -422,6 +422,31 @@ static bool set_echo(bool enable) return true; } +/* Returns true if the string contains the specified number. */ +static bool is_number_in_string(unsigned number, const char *str) +{ + const char *c; + char numstr[sizeof(int) * 3 + 2]; + int len; + + len = snprintf(numstr, sizeof(numstr), "%u", number); + for (c = str; *c; c++) + { + c = strstr(c, numstr); + if (!c) + /* no such number exists in the string */ + return false; + if ((c == str || !isalnum(c[-1])) && !isalnum(c[len])) + /* found */ + return true; + + /* found, but it's part of another number. Continue + * from the next position. */ + } + + return false; +} + /** * Asks user for missing information */ @@ -744,30 +769,33 @@ int report(const char *dump_dir_name, int flags) else { const char *rating_str = get_problem_item_content_or_NULL(problem_data, FILENAME_RATING); - unsigned rating = rating_str ? xatou(rating_str) : 4; + unsigned i, rating = rating_str ? xatou(rating_str) : 4; + GList *li; + char wanted_reporters[255]; - /* For every reporter, ask if user really wants to report using it. */ - for (GList *li = report_events; li; li = li->next) + puts(_("How would you like to report the problem?")); + /* Print list of reporters and ask the user which should be used. */ + for (li = report_events, i = 1; li; li = li->next, i++) { char *reporter_name = (char *) li->data; event_config_t *config = get_event_config(reporter_name); - char question[255]; - char *show_reporter_name; - if (config) - show_reporter_name = (config->screen_name) ? config->screen_name : reporter_name; - else - show_reporter_name = reporter_name; - snprintf(question, sizeof(question), _("Report using %s?"), show_reporter_name); + printf(" %d) %s\n", i, (config && config->screen_name) ? config->screen_name : reporter_name); + } + + read_from_stdin(_("Select reporter(s): "), wanted_reporters, sizeof(wanted_reporters)); + + for (li = report_events, i = 1; li; li = li->next, i++) + { + char *reporter_name = (char *) li->data; + event_config_t *config = get_event_config(reporter_name); if (!config) VERB1 log("No configuration file found for '%s' reporter", reporter_name); - - if (!ask_yesno(question)) - { - puts(_("Skipping...")); + + /* Was this reporter requested? */ + if (!is_number_in_string(i, wanted_reporters)) continue; - } /* TODO: npajkovs; not implemented yet */ //const char *rating_required = get_map_string_item_or_NULL(single_plugin_settings, "RatingRequired"); -- cgit