From patchwork Wed Oct 31 14:11:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 195884 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 8268B2C00B9 for ; Thu, 1 Nov 2012 01:11:39 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TTZ18-0005ic-8Q; Wed, 31 Oct 2012 14:11:38 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TTZ0y-0005hZ-2W for fwts-devel@lists.ubuntu.com; Wed, 31 Oct 2012 14:11:28 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginmedia.com ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1TTZ0x-00019F-V9 for fwts-devel@lists.ubuntu.com; Wed, 31 Oct 2012 14:11:28 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 4/4] lib: klog: tidy up the code a little Date: Wed, 31 Oct 2012 14:11:24 +0000 Message-Id: <1351692684-15611-5-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1351692684-15611-1-git-send-email-colin.king@canonical.com> References: <1351692684-15611-1-git-send-email-colin.king@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King The klog code needs a little bit of a tidy up, mostly using bools where possible and some re-formatting of the source - cosmetic changes. Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Keng-Yu Lin --- src/lib/src/fwts_klog.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c index 445ae4b..c611247 100644 --- a/src/lib/src/fwts_klog.c +++ b/src/lib/src/fwts_klog.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -35,7 +36,6 @@ */ #define KLOG_DATA_JSON_FILE "klog.json" - /* * fwts_klog_free() * free kernel log list @@ -100,23 +100,24 @@ char *fwts_klog_remove_timestamp(char *text) } int fwts_klog_scan(fwts_framework *fw, - fwts_list *klog, - fwts_klog_scan_func scan_func, - fwts_klog_progress_func progress_func, - void *private, - int *match) + fwts_list *klog, + fwts_klog_scan_func scan_func, + fwts_klog_progress_func progress_func, + void *private, + int *match) { typedef struct { char *line; int repeated; } klog_reduced_item; - *match= 0; char *prev; fwts_list_link *item; fwts_list *klog_reduced; int i; + *match = 0; + if (!klog) return FWTS_ERROR; @@ -132,7 +133,7 @@ int fwts_klog_scan(fwts_framework *fw, if (progress_func && ((i % 25) == 0)) progress_func(fw, 50 * i / fwts_list_len(klog)); if (*newline) { - int matched = 0; + bool matched = false; fwts_list_link *l; fwts_list_foreach(l, klog_reduced) { char *line; @@ -141,7 +142,7 @@ int fwts_klog_scan(fwts_framework *fw, line = fwts_klog_remove_timestamp(reduced->line); if (strcmp(newline, line) == 0) { reduced->repeated++; - matched = 1; + matched = true; break; } } @@ -191,16 +192,19 @@ static char *fwts_klog_unique_label(const char *str) const char *src = str; char *dst; int count = 0; - int forceupper = 1; + bool forceupper = true; strcpy(buffer, "Klog"); dst = buffer + 4; - while ((dst < (buffer+sizeof(buffer)-1)) && (count < 4) && (*src)) { - if ((*src == '|') || (*src == '/') || (*src == ' ')) { + while ((dst < (buffer + sizeof(buffer) - 1)) && + (count < 4) && (*src)) { + if ((*src == '|') || + (*src == '/') || + (*src == ' ')) { src++; count++; - forceupper = 1; + forceupper = true; continue; } if (!isalnum(*src)) { @@ -210,7 +214,7 @@ static char *fwts_klog_unique_label(const char *str) *dst++ = forceupper ? toupper(*src) : *src; src++; - forceupper = 0; + forceupper = false; } *dst = '\0'; return buffer; @@ -232,7 +236,7 @@ void fwts_klog_scan_patterns(fwts_framework *fw, FWTS_UNUSED(prevline); while (pattern->pattern != NULL) { - int matched = 0; + bool matched = false; switch (pattern->compare_mode) { case FWTS_COMPARE_REGEX: if (pattern->re) @@ -249,7 +253,9 @@ void fwts_klog_scan_patterns(fwts_framework *fw, fwts_log_info(fw, "Kernel message: %s", line); else { fwts_tag_failed(fw, pattern->tag); - fwts_failed(fw, pattern->level, fwts_klog_unique_label(pattern->pattern), "%s Kernel message: %s", fwts_log_level_to_str(pattern->level), line); + fwts_failed(fw, pattern->level, + fwts_klog_unique_label(pattern->pattern), + "%s Kernel message: %s", fwts_log_level_to_str(pattern->level), line); (*errors)++; } if (repeated) @@ -352,7 +358,7 @@ static int fwts_klog_check(fwts_framework *fw, } /* Now fetch json objects and compile regex */ - for (i=0; i