Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 90522431FBC for ; Mon, 3 Dec 2012 14:30:38 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N-LqrKjawMIW for ; Mon, 3 Dec 2012 14:30:34 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id EFF8D431FAE for ; Mon, 3 Dec 2012 14:30:33 -0800 (PST) Received: by mail-lb0-f181.google.com with SMTP id ge1so2953535lbb.26 for ; Mon, 03 Dec 2012 14:30:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:in-reply-to:references:user-agent:date:message-id :mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=rB/XGdWpozeprmXmqdSHIq2s+Vjg8p0qfI/w7FSSJjU=; b=MXGoGuuukJV+4XJLXvSTGNR6DrJBGkSKao98A/SUmZehfgdgefOnQnvGb4Dhe3kTM5 WzvhP9s+jngptdBvgzXKQNd2QLZjOsPOtnRdloSVzUxTy2DFj7dkz67xTiaJO7kgEKSB +sVDaOs6eYMUVMledtvxw7lTOHgjoWlxiz034kuIbODSJPTbwrK0N/NwCXXni+Ha3GkX 6ZHBuedaGOEuYwUMRO7io0007nO44WxkqOAxluEITHTyx+EB6HvuQPRtPM+hXP3KYN8I MD2eJZuepr/8plhFpUMffIIkgMHEYx/aCxnuqp+4e2WfEKZLxJYJ3X1uKdeHzL/ugYqt R2bA== Received: by 10.112.23.2 with SMTP id i2mr5114898lbf.24.1354573832325; Mon, 03 Dec 2012 14:30:32 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id pw17sm5891143lab.5.2012.12.03.14.30.30 (version=SSLv3 cipher=OTHER); Mon, 03 Dec 2012 14:30:31 -0800 (PST) From: Jani Nikula To: Michal Nazarewicz , notmuch@notmuchmail.org Subject: Re: [PATCH 1/2] cli: fix notmuch top level argument parsing In-Reply-To: <874nk2aigq.fsf@nikula.org> References: <874nk2aigq.fsf@nikula.org> User-Agent: Notmuch/0.14+137~g9203c35 (http://notmuchmail.org) Emacs/23.4.1 (i686-pc-linux-gnu) Date: Tue, 04 Dec 2012 00:30:29 +0200 Message-ID: <871uf6ahve.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQlcq0a9O9noX0rHilcPNqJQMHF+K4u0BuZdJGjFMAH0hwyEC8hzs6hCiAoB4Xfk1RmHb3jT X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Dec 2012 22:30:38 -0000 On Tue, 04 Dec 2012, Jani Nikula wrote: > On Mon, 03 Dec 2012, Michal Nazarewicz wrote: >> On Mon, Dec 03 2012, Jani Nikula wrote: >>> Use strcmp instead of STRNCMP_LITERAL, which matches the prefix >>> instead of the whole argument. >> >> Perhaps add and use this instead: >> >> #define STRCMP_LITERAL(var, literal) \ >> strncmp ((var), (literal), sizeof (literal)) > > That's broken the same way STRNCMP_LITERAL is broken in this use case: > it matches if literal is a prefix of var. Err, that's bollocks. Missed the missing -1 there. ;) >> Than again, it's argument parsing so hardly a performance critical path, >> so maybe readability is more important. I'll go with this. And I'm not even sure strncmp is faster than strcmp, as it has to keep track of count. BR, Jani. >> >>> --- >>> notmuch.c | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/notmuch.c b/notmuch.c >>> index 477a09c..4ff66e3 100644 >>> --- a/notmuch.c >>> +++ b/notmuch.c >>> @@ -245,10 +245,10 @@ main (int argc, char *argv[]) >>> if (argc =3D=3D 1) >>> return notmuch (local); >>>=20=20 >>> - if (STRNCMP_LITERAL (argv[1], "--help") =3D=3D 0) >>> + if (strcmp (argv[1], "--help") =3D=3D 0) >>> return notmuch_help_command (NULL, argc - 1, &argv[1]); >>>=20=20 >>> - if (STRNCMP_LITERAL (argv[1], "--version") =3D=3D 0) { >>> + if (strcmp (argv[1], "--version") =3D=3D 0) { >>> printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n"); >>> return 0; >>> } >> >> --=20 >> Best regards, _ _ >> .o. | Liege of Serenely Enlightened Majesty of o' \,=3D./ `o >> ..o | Computer Science, Micha=C5=82 =E2=80=9Cmina86=E2=80=9D Nazarewicz= (o o) >> ooo +------------------ooO--(_)--Ooo--