On 03/29/2011 10:44 AM, Nikola Pajkovsky wrote:
Signed-off-by: Nikola Pajkovsky<npajkovs(a)redhat.com>
---
src/cli/cli.c | 31 ++++++++++-
src/cli/report.cpp | 135 ++++++++++++++++++++++++++++++++++++++++-------
src/cli/report.h | 4 +-
src/plugins/Makefile.am | 4 +-
4 files changed, 148 insertions(+), 26 deletions(-)
diff --git a/src/cli/cli.c b/src/cli/cli.c
index 0c895a7..4e0042f 100644
--- a/src/cli/cli.c
+++ b/src/cli/cli.c
@@ -360,6 +360,9 @@ int main(int argc, char** argv)
print_usage_and_die(argv[0]);
}
+ /* Get settings */
+ load_event_config_data();
+
/* Do the selected operation. */
int exitcode = 0;
switch (op)
@@ -409,15 +412,37 @@ int main(int argc, char** argv)
}
case OPT_INFO:
{
- if (run_analyze_event(dump_dir_name) != 0)
- return 1;
-
/* Load crash_data from (possibly updated by analyze) dump dir */
struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
if (!dd)
return -1;
+
+ char *analyze_events_as_lines = list_possible_events(dd, NULL,
"analyze");
+ dd_close(dd);
+
+ if (analyze_events_as_lines&& *analyze_events_as_lines)
+ {
+ GList *list_analyze_events = str_to_glist(analyze_events_as_lines,
'\n');
+ free(analyze_events_as_lines);
+
+ char *event = select_event_option(list_analyze_events);
+ list_free_with_free(list_analyze_events);
+
+ int analyzer_result = run_analyze_event(dump_dir_name, event);
+ free(event);
+
+ if (analyzer_result != 0)
+ return 1;
+ }
+
+ /* Load crash_data from (possibly updated by analyze) dump dir */
+ dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
+ if (!dd)
+ return -1;
+
crash_data_t *crash_data = create_crash_data_from_dump_dir(dd);
dd_close(dd);
+
add_to_crash_data_ext(crash_data, CD_DUMPDIR, dump_dir_name,
CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE);
diff --git a/src/cli/report.cpp b/src/cli/report.cpp
index da37bea..ef101b8 100644
--- a/src/cli/report.cpp
+++ b/src/cli/report.cpp
@@ -15,9 +15,9 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "report.h"
-#include "run-command.h"
#include "abrtlib.h"
+#include "run-command.h"
+#include "report.h"
/* Field separator for the crash report file that is edited by user. */
#define FIELD_SEP "%----"
@@ -553,7 +553,8 @@ static int run_events(const char *dump_dir_name,
int r = run_event_on_dir_name(run_state, dump_dir_name, event.c_str());
if (r == 0&& run_state->children_count == 0)
{
- l_state.last_line = xasprintf("Error: no processing is specified for
event '%s'", event.c_str());
+ l_state.last_line = xasprintf("Error: no processing is specified for
event '%s'",
+ event.c_str());
r = -1;
}
if (r == 0)
@@ -585,31 +586,128 @@ static char *do_log(char *log_line, void *param)
log("%s", log_line);
return log_line;
}
-int run_analyze_event(const char *dump_dir_name)
+
+int run_analyze_event(const char *dump_dir_name, const char *analyzer)
{
VERB2 log("run_analyze_event('%s')", dump_dir_name);
struct run_event_state *run_state = new_run_event_state();
run_state->logging_callback = do_log;
- int res = run_event_on_dir_name(run_state, dump_dir_name,
"analyze_LocalGDB");
+ int res = run_event_on_dir_name(run_state, dump_dir_name, analyzer);
free_run_event_state(run_state);
return res;
}
+/* show even description? */
+char *select_event_option(GList *list_options)
+{
+ if (!list_options)
+ return NULL;
+
+ unsigned count = g_list_length(list_options) - 1;
+ if (!count)
+ return NULL;
+
+ int pos = -1;
+ fprintf(stdout, "Select how you would like to analyze the problem:\n");
- all (non-debugging) strings ^^^^^^^^^^^^^^^^^^^^ need to be translatable
+ for (GList *li = list_options; li; li = li->next)
+ {
+ char *opt = (char*)li->data;
+ event_config_t *config = get_event_config(opt);
+ if (config)
+ {
+ ++pos;
+ printf(" %i) %s\n", pos, config->screen_name);
+ }
+ }
+
+ unsigned picked;
+ unsigned ii;
+ for (ii = 0; ii< 3; ++ii)
+ {
+ fprintf(stdout, "Choose option [0 - %u]: ", count);
- make this
translatable: ^^^^^^^^^^^^^^^^
+ fflush(NULL);
+
+ char answer[16];
+ if (!fgets(answer, sizeof(answer), stdin))
+ continue;
+
+ answer[strlen(answer) - 1] = '\0';
+ if (!*answer)
+ continue;
+
+ picked = xatou(answer);
+ if (picked> count)
+ {
+ log(_("You have chosen number out of range"));
- do you
really want to log() this? isn't printf() enough?
+ continue;
+ }
+
+ break;
+ }
+
+ if (ii == 3)
+ error_msg_and_die(_("Invalid input, porgram exiting..."));
-
typo: "porgram"
+
+ GList *choosen = g_list_nth(list_options, picked);
- how about:
gpointer* data = g_list_nth_data()
if (data != NULL)
return xstrdup((char*)data);
- but maybe I'm just too paranoid with the "if" ?
+ return xstrdup((char*)choosen->data);
+}
+
+GList *str_to_glist(char *str, int delim)
+{
+ GList *list = NULL;
+ while (*str)
+ {
+ char *end = strchrnul(str, delim);
+ char *tmp = xstrndup(str, end - str);
+ if (*tmp)
+ list = g_list_append(list, tmp);
+
+ str = end;
+ if (!*str)
+ break;
+ str++;
+ }
+
+ if (!list&& !g_list_length(list))
+ return NULL;
+
+ return list;
+}
/* Report the crash */
int report(const char *dump_dir_name, int flags)
{
- if (run_analyze_event(dump_dir_name) != 0)
- return 1;
-
/* Load crash_data from (possibly updated by analyze) dump dir */
struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0);
if (!dd)
return -1;
+ char *analyze_events_as_lines = list_possible_events(dd, NULL,
"analyze");
+ dd_close(dd);
+
+ if (analyze_events_as_lines&& *analyze_events_as_lines)
- please add
a space before &&
+ {
+ GList *list_analyze_events = str_to_glist(analyze_events_as_lines,
'\n');
+ free(analyze_events_as_lines);
+
+ char *event = select_event_option(list_analyze_events);
+ list_free_with_free(list_analyze_events);
+
+ int analyzer_result = run_analyze_event(dump_dir_name, event);
+ free(event);
+
+ if (analyzer_result != 0)
+ return 1;
- how about just: return analyzer_result; (ommiting the
if())
+ }
+
The rest seems ok.
Jirka