From patchwork Thu May 31 08:24:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: lib: fwts_framework: set log name suffix when using --log-type option Date: Wed, 30 May 2012 22:24:25 -0000 From: Colin King X-Patchwork-Id: 162115 Message-Id: <1338452665-3903-1-git-send-email-colin.king@canonical.com> To: fwts-devel@lists.ubuntu.com From: Colin Ian King Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Ivan Hu Tested-by: Chris Van Hoof --- src/lib/src/fwts_framework.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c index 721f4de..a43d31b 100644 --- a/src/lib/src/fwts_framework.c +++ b/src/lib/src/fwts_framework.c @@ -96,6 +96,34 @@ static const char *fwts_copyright[] = { }; /* + * fwts_framework_log_suffix() + * set the log name suffix + */ +static void fwts_framework_log_suffix(fwts_framework *fw, const char *suffix) +{ + char *ptr; + char *new; + size_t len; + + /* Locate old suffix and kill it */ + ptr = rindex(fw->results_logname, '.'); + if (ptr != NULL) + *ptr = '\0'; + + /* Space for old log name sans old suffix + new suffix + '.' + '\0' */ + len = strlen(fw->results_logname) + strlen(suffix) + 2; + + if ((new = calloc(len, 1)) == NULL) { + fprintf(stderr, "Cannot allocate log name.\n"); + exit(EXIT_FAILURE); + } + + snprintf(new, len, "%s.%s", fw->results_logname, suffix); + free(fw->results_logname); + fw->results_logname = new; +} + +/* * fwts_framework_compare_priority() * used to register tests sorted on run priority */ @@ -943,15 +971,19 @@ int fwts_framework_options_handler(fwts_framework *fw, int argc, char * const ar fwts_iasl_disassemble_all_to_file(fw); return FWTS_COMPLETE; case 32: /* --log-type */ - if (!strcmp(optarg, "plaintext")) + if (!strcmp(optarg, "plaintext")) { fw->log_type = LOG_TYPE_PLAINTEXT; - else if (!strcmp(optarg, "json")) + fwts_framework_log_suffix(fw, "log"); + } else if (!strcmp(optarg, "json")) { fw->log_type = LOG_TYPE_JSON; - else if (!strcmp(optarg, "xml")) + fwts_framework_log_suffix(fw, "json"); + } else if (!strcmp(optarg, "xml")) { fw->log_type = LOG_TYPE_XML; - else if (!strcmp(optarg, "html")) + fwts_framework_log_suffix(fw, "xml"); + } else if (!strcmp(optarg, "html")) { fw->log_type = LOG_TYPE_HTML; - else { + fwts_framework_log_suffix(fw, "html"); + } else { fprintf(stderr, "--log-type can be either plaintext, xml, html or json.\n"); return FWTS_ERROR; }