From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,RDNS_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: (qmail 19226 invoked from network); 12 Mar 2020 19:25:50 -0000 Received-SPF: pass (minnie.tuhs.org: domain of minnie.tuhs.org designates 45.79.103.53 as permitted sender) receiver=inbox.vuxu.org; client-ip=45.79.103.53 envelope-from= Received: from unknown (HELO minnie.tuhs.org) (45.79.103.53) by inbox.vuxu.org with ESMTP; 12 Mar 2020 19:25:50 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 841919CD93; Fri, 13 Mar 2020 05:25:46 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 90E039CD60; Fri, 13 Mar 2020 05:24:45 +1000 (AEST) Received: by minnie.tuhs.org (Postfix, from userid 112) id 452EB9CD60; Fri, 13 Mar 2020 05:24:42 +1000 (AEST) Received: from sdaoden.eu (sdaoden.eu [217.144.132.164]) by minnie.tuhs.org (Postfix) with ESMTPS id 6D11C9CD5F for ; Fri, 13 Mar 2020 05:24:41 +1000 (AEST) Received: by sdaoden.eu (Postfix, from userid 1000) id 4D5C116054; Thu, 12 Mar 2020 20:24:39 +0100 (CET) Date: Thu, 12 Mar 2020 20:24:38 +0100 From: Steffen Nurpmeso To: "John P. Linderman" Message-ID: <20200312192438.q9Q4k%steffen@sdaoden.eu> In-Reply-To: References: <20200305020517.GA13872@wopr> <20200308052632.GD20478@eureka.lemis.com> <202003080532.0285WcWn1544496@darkstar.fourwinds.com> <20200309212257.GB39634@wopr> Mail-Followup-To: "John P. Linderman" , Warner Losh , The Unix Heritage Society User-Agent: s-nail v14.9.17-52-g56288e6a OpenPGP: id=EE19E1C1F2F7054F8D3954D8308964B51883A0DD; url=https://ftp.sdaoden.eu/steffen.asc; preference=signencrypt BlahBlahBlah: Any stupid boy can crush a beetle. But all the professors in the world can make no bugs. Subject: Re: [TUHS] Command line options and complexity X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: The Unix Heritage Society Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" John P. Linderman wrote in : |My error. I was looking at getopt(1) rather than getopt(3). Of course \ |optind is documented, it's the way to find non-flag arguments. |I don't know why the Hancock authors chose to make rsort into a subroutine \ |rather than just piping into the command. Perhaps something to do with \ |the software release process? I really like a lot of such old code, and reading it. One can only learn from it. Even though i discovered all this in (Free)BSD land, after coming over from Linux, I loved reading those "old-hand" comment blocks, it was inspiration and kindled something here. For the few pieces of code that i am prowd of aka that i thought were worth it i followed their example. This rsort.c is however more verbose and spiritful than anything i ever wrote. I keep it in my box of precious things. getopt(3) on the other hand is portable but terrible. Just on the 10th i resorted a small SCSI MMC-3 cdda access tool (~50 KB C source are necessary for that in 2020, missing Solaris and MacOS, but including CD-TEXT and all that!!) to it because people are used to option and/or argument joining etc, but it lost long option support. Not worth commenting a lot, but here is an option parser of 6359 bytes when development verification code and dump_doc() are not counted, but is uses a carrier struct, supports long options, and documentation strings as part of long option strings (one .RODATA entry). FreeBSD's standard compatible and thus naked lib/libc/stdlib/getopt.c is 4312 bytes. And GNU's getopt_long is huge and even permutates arguments. At least getopt(3) is predictable once a user gets it. Things are different for sed(1)s -i and some sccs commands i have forgotten. I think it has even be tried to standardize optional arguments in that respect, but i would argue this is not a good direction to go, consider for example "sed -ie". Isn't this asking for troubles without accompanying comments. * static char const a_sopts[] = "A:h#"; * static char const * const a_lopts[] = { * "account:;A;" N_("execute an `account' command"), .. * "long-help;\201;" N_("this listing"), * NIL * }; .. * struct su_avopt avo; .. * su_avopt_setup(&avo, --argc, C(char const*const*,++argv), * a_sopts, a_lopts); * while((i = su_avopt_parse(&avo)) != su_AVOPT_STATE_DONE){ * switch(i){ * case 'A': * "account_name" = avo.avo_current_arg; * break; * case 'h': * case S(char,S(u8,'\201')): * a_main_usage(n_stdout); * if(i != 'h'){ * fprintf(n_stdout, "\nLong options:\n"); * su_avopt_dump_doc(&avo, &a_main_dump_doc, S(up,n_stdout)); * } * exit(0); .. * argc = avo.avo_argc; * argv = C(char**,avo.avo_argv); --steffen | |Der Kragenbaer, The moon bear, |der holt sich munter he cheerfully and one by one |einen nach dem anderen runter wa.ks himself off |(By Robert Gernhardt)