From patchwork Tue Dec 16 07:00:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 422466 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3E84B1400B7 for ; Thu, 18 Dec 2014 13:58:10 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id ED0F028C117; Thu, 18 Dec 2014 03:52:57 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, DATE_IN_PAST_24_48, FREEMAIL_FROM,T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id BA5F028C007 for ; Thu, 18 Dec 2014 03:52:14 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-pd0-f171.google.com (mail-pd0-f171.google.com [209.85.192.171]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 18 Dec 2014 03:52:13 +0100 (CET) Received: by mail-pd0-f171.google.com with SMTP id y13so436259pdi.2 for ; Wed, 17 Dec 2014 18:54:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n7w4mBNCD1RNxAVlTrE87Ehh6UZd7HCPOHdFixVJ8KA=; b=QZcfcvaxjhtC6XkBb+612/0JZOZG1r9vJeWoLSEvtkO39vj+xCUIvzQkbcB5jPj2lZ l6adNoq3wZ/qwevbYMFCnPe/qpfZfC6xax01yUPmRCtJaKniv01B2IHZZD1pjiAWf5S7 mbRHlw+kfmkpj/gjoi9ntvGOVz9RvUrwtuUEpT50I3IZtdkgn0uEQK3BKQRXBeHZA+0H wBT8tstYwmpDMJcF+aAL1ju2VPs8n9sW2VdjeRhFxCoLrYtn4YUDUwUlYiiPEueFMI/2 iAW598HXnzZvW3yiFPL5miWAHqC50eNHR+dIdg/0YpXyfoLwM+9ZiELjWHH+w9umRLdP mMcw== X-Received: by 10.70.46.201 with SMTP id x9mr76114771pdm.154.1418871242678; Wed, 17 Dec 2014 18:54:02 -0800 (PST) Received: from debian.lan ([103.29.140.56]) by mx.google.com with ESMTPSA id oy7sm5104495pbc.88.2014.12.17.18.53.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Dec 2014 18:54:01 -0800 (PST) From: Yousong Zhou To: nbd@openwrt.org Date: Tue, 16 Dec 2014 15:00:15 +0800 Message-Id: <1418713218-16300-14-git-send-email-yszhou4tech@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1418713218-16300-1-git-send-email-yszhou4tech@gmail.com> References: <1418713218-16300-1-git-send-email-yszhou4tech@gmail.com> Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH v2 13/16] delta: preprocess delta line with uci_parse_argument(). X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Signed-off-by: Yousong Zhou --- delta.c | 25 ++++++++++++++----------- file.c | 7 +------ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/delta.c b/delta.c index b56df5b..2eb2ae7 100644 --- a/delta.c +++ b/delta.c @@ -95,11 +95,14 @@ int uci_add_delta_path(struct uci_context *ctx, const char *dir) return 0; } -static inline int uci_parse_delta_tuple(struct uci_context *ctx, char **buf, struct uci_ptr *ptr) +static inline int uci_parse_delta_tuple(struct uci_context *ctx, struct uci_ptr *ptr) { + struct uci_parse_context *pctx = ctx->pctx; + char *str = pctx_cur_str(pctx), *arg; int c = UCI_CMD_CHANGE; - switch(**buf) { + UCI_INTERNAL(uci_parse_argument, ctx, ctx->pctx->file, &str, &arg); + switch(*arg) { case '^': c = UCI_CMD_REORDER; break; @@ -122,9 +125,9 @@ static inline int uci_parse_delta_tuple(struct uci_context *ctx, char **buf, str } if (c != UCI_CMD_CHANGE) - *buf += 1; + arg += 1; - UCI_INTERNAL(uci_parse_ptr, ctx, ptr, *buf); + UCI_INTERNAL(uci_parse_ptr, ctx, ptr, arg); if (!ptr->section) goto error; @@ -155,13 +158,13 @@ error: return 0; } -static void uci_parse_delta_line(struct uci_context *ctx, struct uci_package *p, char *buf) +static void uci_parse_delta_line(struct uci_context *ctx, struct uci_package *p) { struct uci_element *e = NULL; struct uci_ptr ptr; int cmd; - cmd = uci_parse_delta_tuple(ctx, &buf, &ptr); + cmd = uci_parse_delta_tuple(ctx, &ptr); if (strcmp(ptr.package, p->e.name) != 0) goto error; @@ -214,6 +217,7 @@ static int uci_parse_delta(struct uci_context *ctx, FILE *stream, struct uci_pac pctx->file = stream; while (!feof(pctx->file)) { + pctx->pos = 0; uci_getln(ctx, 0); if (!pctx->buf[0]) continue; @@ -223,7 +227,7 @@ static int uci_parse_delta(struct uci_context *ctx, FILE *stream, struct uci_pac * delta as possible */ UCI_TRAP_SAVE(ctx, error); - uci_parse_delta_line(ctx, p, pctx->buf); + uci_parse_delta_line(ctx, p); UCI_TRAP_RESTORE(ctx); changes++; error: @@ -311,11 +315,10 @@ static void uci_filter_delta(struct uci_context *ctx, const char *name, const ch pctx->file = f; while (!feof(f)) { struct uci_element *e; - char *buf; + pctx->pos = 0; uci_getln(ctx, 0); - buf = pctx->buf; - if (!buf[0]) + if (!pctx->buf[0]) continue; /* NB: need to allocate the element before the call to @@ -324,7 +327,7 @@ static void uci_filter_delta(struct uci_context *ctx, const char *name, const ch e = uci_alloc_generic(ctx, UCI_TYPE_DELTA, pctx->buf, sizeof(struct uci_element)); uci_list_add(&list, &e->list); - uci_parse_delta_tuple(ctx, &buf, &ptr); + uci_parse_delta_tuple(ctx, &ptr); if (section) { if (!ptr.section || (strcmp(section, ptr.section) != 0)) continue; diff --git a/file.c b/file.c index 0fc68a6..5be2e66 100644 --- a/file.c +++ b/file.c @@ -278,13 +278,8 @@ int uci_parse_argument(struct uci_context *ctx, FILE *stream, char **str, char * uci_alloc_parse_context(ctx); ctx->pctx->file = stream; - - if (!*str) { + if (!*str) uci_getln(ctx, 0); - *str = ctx->pctx->buf; - } else { - UCI_ASSERT(ctx, ctx->pctx->pos == *str - ctx->pctx->buf); - } /*FIXME do we need to skip empty lines? */ ofs_result = next_arg(ctx, false, false);