From patchwork Mon Jun 27 15:27:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Fergeau X-Patchwork-Id: 102218 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EB629B6F6B for ; Tue, 28 Jun 2011 02:32:10 +1000 (EST) Received: from localhost ([::1]:35976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QbEjG-0005oI-3z for incoming@patchwork.ozlabs.org; Mon, 27 Jun 2011 12:32:06 -0400 Received: from eggs.gnu.org ([140.186.70.92]:47923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QbDj4-0005yE-2W for qemu-devel@nongnu.org; Mon, 27 Jun 2011 11:27:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QbDiz-0006E1-JE for qemu-devel@nongnu.org; Mon, 27 Jun 2011 11:27:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64848) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QbDiy-0006DS-Rd for qemu-devel@nongnu.org; Mon, 27 Jun 2011 11:27:45 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5RFRia9027478 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 27 Jun 2011 11:27:44 -0400 Received: from localhost.localdomain (teriyaki.cdg.redhat.com [10.32.192.15]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p5RFRd6b012361 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 27 Jun 2011 11:27:43 -0400 From: Christophe Fergeau To: qemu-devel@nongnu.org Date: Mon, 27 Jun 2011 17:27:38 +0200 Message-Id: <1309188459-806-4-git-send-email-cfergeau@redhat.com> In-Reply-To: <1309188459-806-1-git-send-email-cfergeau@redhat.com> References: <1308926260-11995-1-git-send-email-cfergeau@redhat.com> <1309188459-806-1-git-send-email-cfergeau@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCHv2 3/4] libcacard: introduce NEXT_TOKEN macro X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org vcard_emul_options now has repetitive code to read the current token and advance to the next. After the previous changes, this repetitive code can be moved in a NEXT_TOKEN macro to avoid having this code duplicated. Signed-off-by: Christophe Fergeau --- libcacard/vcard_emul_nss.c | 71 +++++++++++++++----------------------------- 1 files changed, 24 insertions(+), 47 deletions(-) diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c index 9271f58..2a20bd6 100644 --- a/libcacard/vcard_emul_nss.c +++ b/libcacard/vcard_emul_nss.c @@ -975,6 +975,26 @@ find_blank(const char *str) static VCardEmulOptions options; #define READER_STEP 4 +/* Expects "args" to be at the beginning of a token (ie right after the ',' + * ending the previous token), and puts the next token start in "token", + * and its length in "token_length". "token" will not be nul-terminated. + * After calling the macro, "args" will be advanced to the beginning of + * the next token. + * This macro may call continue or break. + */ +#define NEXT_TOKEN(token) \ + (token) = args; \ + args = strpbrk(args, ",)"); \ + if (*args == 0) { \ + break; \ + } \ + if (*args == ')') { \ + args++; \ + continue; \ + } \ + (token##_length) = args - (token); \ + args = strip(args+1); + VCardEmulOptions * vcard_emul_options(const char *args) { @@ -1010,58 +1030,15 @@ vcard_emul_options(const char *args) } args = strip(args+1); - name = args; - args = strpbrk(args, ",)"); - if (*args == 0) { - break; - } - if (*args == ')') { - args++; - continue; - } - name_length = args - name; - args = strip(args+1); - - vname = args; - args = strpbrk(args, ",)"); - if (*args == 0) { - break; - } - if (*args == ')') { - args++; - continue; - } - vname_length = args - vname; - args = strip(args+1); - - type_params = args; - args = strpbrk(args, ",)"); - if (*args == 0) { - break; - } - if (*args == ')') { - args++; - continue; - } - type_params_length = args - type_params; - args = strip(args+1); - + NEXT_TOKEN(name) + NEXT_TOKEN(vname) + NEXT_TOKEN(type_params) type_params_length = MIN(type_params_length, sizeof(type_str)-1); strncpy(type_str, type_params, type_params_length); type_str[type_params_length] = 0; type = vcard_emul_type_from_string(type_str); - type_params = args; - args = strpbrk(args, ",)"); - if (*args == 0) { - break; - } - if (*args == ')') { - args++; - continue; - } - type_params_length = args - type_params; - args = strip(args+1); + NEXT_TOKEN(type_params) if (*args == 0) { break;