From patchwork Mon Dec 15 08:46:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 421038 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 3E0DE140082 for ; Mon, 15 Dec 2014 20:28:15 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id C782B28C22E; Mon, 15 Dec 2014 10:24:09 +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=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 18E7B28B402 for ; Mon, 15 Dec 2014 10:23:29 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .gmail. - helo: .mail-pd0-f181.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -8.5 Received: from mail-pd0-f181.google.com (mail-pd0-f181.google.com [209.85.192.181]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Mon, 15 Dec 2014 10:23:25 +0100 (CET) Received: by mail-pd0-f181.google.com with SMTP id v10so11161769pde.26 for ; Mon, 15 Dec 2014 01:25:12 -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=ScRVCZcIfxsq8K/R3KFZYJ0oLrhpnPYZHYYrnzswt8E=; b=NRYGOyWLsBc2kn0LHBtGrUnQtQXDhXaEeH+f5CSzVdVpxxTBYr2cq4Kfc0zSZyh/hO RfhjJuAOa479R1TDa+pEyM7LdR0oigkpKjpu3uMtrLUkNB0CrZxZsxU2m2uBLb0CCfdG GMRqEcoXXOhPR0k5Dwj3+PS+9KLVUwPJEiYlzg9tC3FIM9bbenUlCheWmO70ZqsKGY0p 2tNjfKjIBLnQC2l9yjZ1oOSGTUwZeAg3rIV3n55n5PlyjvnfTkYAJtwLcn1WhFWXuopq fKyx1BXIHp/W+WY1G/7ApbsMcv4rU5q+E6tai6rZOaeI3vqVkE0HLjYAr92fwcn/maPD 5vkA== X-Received: by 10.68.225.7 with SMTP id rg7mr50207702pbc.24.1418635512688; Mon, 15 Dec 2014 01:25:12 -0800 (PST) Received: from debian.lan ([103.29.140.56]) by mx.google.com with ESMTPSA id rh11sm8631536pdb.66.2014.12.15.01.25.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Dec 2014 01:25:11 -0800 (PST) From: Yousong Zhou To: nbd@openwrt.org Date: Mon, 15 Dec 2014 16:46:50 +0800 Message-Id: <1418633213-50491-10-git-send-email-yszhou4tech@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1418633213-50491-1-git-send-email-yszhou4tech@gmail.com> References: <1418633213-50491-1-git-send-email-yszhou4tech@gmail.com> Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH 09/12] 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 | 9 +++------ 2 files changed, 17 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 63ca919..177cee6 100644 --- a/file.c +++ b/file.c @@ -278,15 +278,12 @@ 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? */ *result = next_arg(ctx, false, false); + *str = pctx_cur_str(ctx->pctx); return 0; }