diff options
-rw-r--r-- | hardinfo/util.c | 10 | ||||
-rw-r--r-- | includes/report.h | 2 | ||||
-rw-r--r-- | shell/report.c | 70 |
3 files changed, 78 insertions, 4 deletions
diff --git a/hardinfo/util.c b/hardinfo/util.c index 81b7e743..c58e2e1a 100644 --- a/hardinfo/util.c +++ b/hardinfo/util.c @@ -407,7 +407,7 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param) .short_name = 'f', .arg = G_OPTION_ARG_STRING, .arg_data = &report_format, - .description = N_("chooses a report format (text, html)")}, + .description = N_("chooses a report format ([text], html)")}, { .long_name = "run-benchmark", .short_name = 'b', @@ -496,8 +496,12 @@ void parameters_init(int *argc, char ***argv, ProgramParameters * param) param->force_all_details = force_all_details; param->argv0 = *(argv)[0]; - if (report_format && g_str_equal(report_format, "html")) - param->report_format = REPORT_FORMAT_HTML; + if (report_format) { + if (g_str_equal(report_format, "html")) + param->report_format = REPORT_FORMAT_HTML; + if (g_str_equal(report_format, "shell")) + param->report_format = REPORT_FORMAT_SHELL; + } /* html ok? * gui: yes diff --git a/includes/report.h b/includes/report.h index 931a536e..1c1bd420 100644 --- a/includes/report.h +++ b/includes/report.h @@ -24,6 +24,7 @@ typedef enum { REPORT_FORMAT_HTML, REPORT_FORMAT_TEXT, + REPORT_FORMAT_SHELL, N_REPORT_FORMAT } ReportFormat; @@ -81,6 +82,7 @@ void report_dialog_show(); ReportContext *report_context_html_new(); ReportContext *report_context_text_new(); +ReportContext *report_context_shell_new(); void report_header (ReportContext *ctx); void report_footer (ReportContext *ctx); diff --git a/shell/report.c b/shell/report.c index 8a8f8c6b..924f2ec4 100644 --- a/shell/report.c +++ b/shell/report.c @@ -31,6 +31,7 @@ static void set_all_active(ReportDialog * rd, gboolean setting); static FileTypes file_types[] = { {"HTML (*.html)", "text/html", ".html", report_context_html_new}, {"Plain Text (*.txt)", "text/plain", ".txt", report_context_text_new}, + {"Shell Dump (*.txt)", "text/plain", ".txt", report_context_shell_new}, {NULL, NULL, NULL, NULL} }; @@ -237,12 +238,56 @@ void report_details(ReportContext *ctx, gchar *key, gchar *value, gboolean highl report_details_end(ctx); } +static void report_table_shell_dump(ReportContext *ctx, gchar *key_file_str, int level) +{ + gchar *text, *p, *next_nl, *eq, *indent; + gchar *key, *value; + + indent = g_strnfill(level * 4, ' '); + + if (key_file_str) { + p = text = g_strdup(key_file_str); + while(next_nl = strchr(p, '\n')) { + *next_nl = 0; + eq = strchr(p, '='); + if (*p != '[' && eq) { + *eq = 0; + key = p; value = eq + 1; + + ctx->output = h_strdup_cprintf("%s%s=%s\n", ctx->output, indent, key, value); + if (key_wants_details(key) || params.force_all_details) { + gchar *mi_tag = key_mi_tag(key); + gchar *mi_data = ctx->entry->morefunc(mi_tag); /*const*/ + + if (mi_data) + report_table_shell_dump(ctx, mi_data, level + 1); + + g_free(mi_tag); + } + + } else + ctx->output = h_strdup_cprintf("%s%s\n", ctx->output, indent, p); + p = next_nl + 1; + } + } + g_free(text); + g_free(indent); + return; +} + void report_table(ReportContext * ctx, gchar * text) { - GKeyFile *key_file = g_key_file_new(); + GKeyFile *key_file = NULL; gchar **groups; gint i; + if (ctx->format == REPORT_FORMAT_SHELL) { + report_table_shell_dump(ctx, text, 0); + return; + } + + key_file = g_key_file_new(); + /* make only "Value" column visible ("Key" column is always visible) */ ctx->columns = REPORT_COL_VALUE; ctx->show_column_headers = FALSE; @@ -683,6 +728,29 @@ ReportContext *report_context_text_new() return ctx; } +ReportContext *report_context_shell_new() +{ + ReportContext *ctx; + + ctx = g_new0(ReportContext, 1); + ctx->header = report_text_header; + ctx->footer = report_text_footer; + + ctx->title = report_text_title; + ctx->subtitle = report_text_subtitle; + /* special format handled in report_table(), + * doesn't need the others. */ + + ctx->output = g_strdup(""); + ctx->format = REPORT_FORMAT_SHELL; + + ctx->column_titles = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, g_free); + ctx->first_table = TRUE; + + return ctx; +} + void report_context_free(ReportContext * ctx) { g_hash_table_destroy(ctx->column_titles); |