From patchwork Sun Mar 8 03:31:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 5961101 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2FBA3BF440 for ; Sun, 8 Mar 2015 04:39:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 369C02025B for ; Sun, 8 Mar 2015 04:39:37 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE279203B0 for ; Sun, 8 Mar 2015 04:39:35 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t284aeob022383; Sat, 7 Mar 2015 23:36:40 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t284ZgAU009437 for ; Sat, 7 Mar 2015 23:35:42 -0500 Received: from redhat.com (ask-08.lab.msp.redhat.com [10.15.85.8]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t284ZeCC015877; Sat, 7 Mar 2015 23:35:40 -0500 Received: by redhat.com (sSMTP sendmail emulation); Sat, 07 Mar 2015 21:32:07 -0600 From: "Benjamin Marzinski" To: device-mapper development Date: Sat, 7 Mar 2015 21:31:43 -0600 Message-Id: <1425785506-20419-13-git-send-email-bmarzins@redhat.com> In-Reply-To: <1425785506-20419-1-git-send-email-bmarzins@redhat.com> References: <1425785506-20419-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH 12/15] libmultipath: cleanup parser code X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP read_value_block() and alloc_value_block() are completely unused, and can go away. Also, all of the config file parsing is done it parse.c, so there's no reason to make "stream" a global variable. Signed-off-by: Benjamin Marzinski --- libmultipath/parser.c | 101 ++++---------------------------------------------- libmultipath/parser.h | 6 --- 2 files changed, 8 insertions(+), 99 deletions(-) diff --git a/libmultipath/parser.c b/libmultipath/parser.c index d351ab2..e4296ee 100644 --- a/libmultipath/parser.c +++ b/libmultipath/parser.c @@ -280,8 +280,8 @@ out: return NULL; } -int -read_line(char *buf, int size) +static int +read_line(FILE *stream, char *buf, int size) { char *p; @@ -291,93 +291,6 @@ read_line(char *buf, int size) return 1; } -vector -read_value_block(void) -{ - char *buf; - int i; - char *str = NULL; - char *dup; - vector vec = NULL; - vector elements = vector_alloc(); - - if (!elements) - return NULL; - - buf = (char *) MALLOC(MAXBUF); - - if (!buf) { - vector_free(elements); - return NULL; - } - - while (read_line(buf, MAXBUF)) { - vec = alloc_strvec(buf); - if (vec) { - str = VECTOR_SLOT(vec, 0); - if (!strcmp(str, EOB)) { - free_strvec(vec); - break; - } - - for (i = 0; i < VECTOR_SIZE(vec); i++) { - str = VECTOR_SLOT(vec, i); - dup = (char *) MALLOC(strlen(str) + 1); - if (!dup) - goto out; - memcpy(dup, str, strlen(str)); - - if (!vector_alloc_slot(elements)) { - free_strvec(vec); - goto out1; - } - - vector_set_slot(elements, dup); - } - free_strvec(vec); - } - } - FREE(buf); - return elements; -out1: - FREE(dup); -out: - FREE(buf); - vector_free(elements); - return NULL; -} - -int -alloc_value_block(vector strvec, void (*alloc_func) (vector)) -{ - char *buf; - char *str = NULL; - vector vec = NULL; - - buf = (char *) MALLOC(MAXBUF); - - if (!buf) - return 1; - - while (read_line(buf, MAXBUF)) { - vec = alloc_strvec(buf); - if (vec) { - str = VECTOR_SLOT(vec, 0); - if (!strcmp(str, EOB)) { - free_strvec(vec); - break; - } - - if (VECTOR_SIZE(vec)) - (*alloc_func) (vec); - - free_strvec(vec); - } - } - FREE(buf); - return 0; -} - void * set_value(vector strvec) { @@ -553,7 +466,7 @@ validate_config_strvec(vector strvec, char *file) } static int -process_stream(vector keywords, char *file) +process_stream(FILE *stream, vector keywords, char *file) { int i; int r = 0, t; @@ -574,7 +487,7 @@ process_stream(vector keywords, char *file) return 1; } - while (read_line(buf, MAXBUF)) { + while (read_line(stream, buf, MAXBUF)) { line_nr++; strvec = alloc_strvec(buf); if (!strvec) @@ -616,7 +529,8 @@ process_stream(vector keywords, char *file) if (keyword->sub) { kw_level++; - r += process_stream(keyword->sub, file); + r += process_stream(stream, + keyword->sub, file); kw_level--; } break; @@ -651,6 +565,7 @@ int process_file(char *file) { int r; + FILE *stream; if (!keywords) { condlog(0, "No keywords alocated"); @@ -665,7 +580,7 @@ process_file(char *file) /* Stream handling */ line_nr = 0; - r = process_stream(keywords, file); + r = process_stream(stream, keywords, file); fclose(stream); //free_keywords(keywords); diff --git a/libmultipath/parser.h b/libmultipath/parser.h index bfbb3ae..ba6859e 100644 --- a/libmultipath/parser.h +++ b/libmultipath/parser.h @@ -47,9 +47,6 @@ struct keyword { int unique; }; -/* global var exported */ -FILE *stream; - /* Reloading helpers */ #define SET_RELOAD (reload = 1) #define UNSET_RELOAD (reload = 0) @@ -72,9 +69,6 @@ extern int _install_keyword(char *string, int (*handler) (vector), extern void dump_keywords(vector keydump, int level); extern void free_keywords(vector keywords); extern vector alloc_strvec(char *string); -extern int read_line(char *buf, int size); -extern vector read_value_block(void); -extern int alloc_value_block(vector strvec, void (*alloc_func) (vector)); extern void *set_value(vector strvec); extern int alloc_keywords(void); extern int process_file(char *conf_file);