summaryrefslogtreecommitdiffstats
path: root/src/cli
diff options
context:
space:
mode:
authorMiroslav Lichvar <mlichvar@redhat.com>2011-04-15 17:30:31 +0200
committerMiroslav Lichvar <mlichvar@redhat.com>2011-05-05 17:16:00 +0200
commitfb0cd889c011a128a8d03ebeb52f43cd44f5b40e (patch)
treefad3addb2dcb3d467da7a7ece994dd9eb1422e28 /src/cli
parentc2095ab91d0b2047c2340309b939f05f184b7a8b (diff)
downloadabrt-fb0cd889c011a128a8d03ebeb52f43cd44f5b40e.tar.gz
abrt-fb0cd889c011a128a8d03ebeb52f43cd44f5b40e.tar.xz
abrt-fb0cd889c011a128a8d03ebeb52f43cd44f5b40e.zip
abrt-cli: select reporters by numbers (trac#194)
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/report.c58
1 files changed, 43 insertions, 15 deletions
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");