From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 500F21F462 for ; Thu, 20 Jun 2019 13:19:38 +0000 (UTC) Received: from localhost ([::1]:47690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdwyW-0004OB-CM for normalperson@yhbt.net; Thu, 20 Jun 2019 09:19:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51184) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdwxY-0002kz-Ll for bug-gnulib@gnu.org; Thu, 20 Jun 2019 09:18:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdwlu-00013M-R1 for bug-gnulib@gnu.org; Thu, 20 Jun 2019 09:08:23 -0400 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::5]:21820) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdwlt-00012m-RV for bug-gnulib@gnu.org; Thu, 20 Jun 2019 09:06:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1561035990; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=mTpNOthFd5E4ZVCtqooR0Sm2QSOLZLOmSxA++59xzV8=; b=LIdsUBA9JcDDOaRYQ/7H4XZrx1/wrOWENP2EOALKLfRvF9QWIJGBrmtznH0rUq3dHc D7vlYNIgEGD7xx+t1s8rpNs2mDW7pBsADibCpm5iNWFwDnQNhWu54Xbhm9karv/28Lei sj42pcJFx9zoX+jHHuGRbDRvSgzfegke/AZfpaGyOLxvlSAkYedoAc/tAjO/70c8he4g MuWcazsHvuVmroCnbLo7G4RhQozyLdfL58l/bNV/rsDprnCrujn4jcMd+bOHZuL0XHWQ XEe+LphbLKBj6B74M3zkJ+OxL1VCVMiYInkTTW4ls5rLFHSC/WKV21IeraMN2ycd7HGU 0lvA== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOGaf0y5RW" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 44.24 DYNA|AUTH) with ESMTPSA id J01134v5KD6QEOM (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Thu, 20 Jun 2019 15:06:26 +0200 (CEST) From: Bruno Haible To: Akim Demaille Subject: Re: argmatch: accept perfect matches in documented arglists Date: Thu, 20 Jun 2019 15:06:26 +0200 Message-ID: <11405045.c7khPThjkt@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-145-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: References: <4443393.gEGGKB8KqV@omega> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:238:20a:202:5300::5 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Eggert , bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" Hi Akim, Sorry for the delay. > Here is my proposal. It looks really good now. My comments below are only nitpicking. I like the addition of documentation. It makes the module a lot easier to use. > +2019-05-23 Akim Demaille > + > + argmatch: add support to generate the usage message. > + * lib/argmatch.c: Move some #includes and gettext support to... > + * lib/argmatch.h: here. > + (ARGMATCH_DEFINE_GROUP): New macro. > + * tests/test-argmatch.c (argmatch_backup_docs, argmatch_backup_args) > + (argmatch_backup_group): New. > + (CHECK): New. > + (main): Check argmatch_backup_value, argmatch_backup_xvalue, > + argmatch_backup_argument and argmatch_backup_usage. > + * doc/argmatch.texi (Recognizing Option Arguments): New. The ChangeLog entry should mention that you modify doc/gnulib.texi. > +@example > +const argmatch_backup_group_type argmatch_backup_group = > +@{ > + N_("\ > +The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.\n\ > +The version control method may be selected via the --backup option or through\n\ > +the VERSION_CONTROL environment variable. Here are the values:\n"), > + NULL, > + argmatch_backup_docs, > + argmatch_backup_args > +@}; > +@end example Why does not args element come last and the doc strings come first? - It'd be more natural for a programmer to put the args element first. - It at some point in the future, you need to add more doc strings, it would be easy to add them in a backward-compatible way at the end of the string (since a struct initializer implicitly initializes trailing members with NULL or 0 values). > +ptrdiff_t i = argmatch_backup_value ("--backup", "none"); > +// argmatch_backup_group.args[i].arg is "none", so its value > +// is argmatch_backup_group.args[i].val. > +// Return -1 on invalid argument, and -2 on ambiguity. > + > +enum backup_type val = *argmatch_backup_xvalue ("--backup", "none"); > +// Returns a pointer to the value, and exit on errors. > +// So argmatch_backup_group.args[i].val == val. The naming of the functions is a bit odd. argmatch_backup_xvalue returns a value, and argmatch_backup_value return not a value but a choice (an index or -1 or -2). How about renaming these functions: argmatch_backup_value -> argmatch_backup_choice argmatch_backup_xvalue -> argmatch_backup_value > + /* If nonnegative, the indice I of ARG in ARGS, i.e, \ "the indice" is not valid English. https://www.merriam-webster.com/dictionary/indice The singular of 'indices' is 'index'. > + void \ > + argmatch_##Name##_usage (FILE *out) \ > + { \ > + ... > + if (g->doc_pre) \ > + fprintf (out, "%s\n", _(g->doc_pre)); \ > + int doc_col = argmatch_##Name##_doc_col (); \ Local variable declarations after statements in the same block are a C99 feature. Can you change it to use C99 syntax? Or, if you can't, add 'c99' to the module dependencies. Bruno