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.5 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RDNS_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: (qmail 2298 invoked from network); 12 Mar 2020 12:58:41 -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 12:58:41 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 74F969BCDB; Thu, 12 Mar 2020 22:58:35 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id DA07C9BB47; Thu, 12 Mar 2020 22:57:25 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vTPpSTvN"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id 6AB289BB47; Thu, 12 Mar 2020 22:57:23 +1000 (AEST) Received: from mail-vs1-f47.google.com (mail-vs1-f47.google.com [209.85.217.47]) by minnie.tuhs.org (Postfix) with ESMTPS id D1BF79BB46 for ; Thu, 12 Mar 2020 22:57:22 +1000 (AEST) Received: by mail-vs1-f47.google.com with SMTP id p7so1366239vso.6 for ; Thu, 12 Mar 2020 05:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pnefIQzL6rsneTq4xQYVgtiFNZKU48FQE22oL5LUnwM=; b=vTPpSTvNbyYJeOpD41Ng+XysraR+n3Qc4KToGffD8MvUyqvuzbvLqfxtg6S1j6S31t Qptrz0/+Myw+K/ljx/pZuc0MoZ+fVV9iAMUcjVOhxwXY9OzU+hahI4Ic78TTrq2kOc5F nx9DS93YrTZDkuKzoyzB+TyzZ1qMUL6oLoci/Q7eZ5bI8htcTAZet2m1ctGNw2spw/VG M9deM2SF6KQ7x53qsU7WxYplAsIm1qDQG215ke692f93Nole9hu//HuTnLcUZbI7JTeg KAEx+rNKRPKuOKFU5ovOknkwlvdgdv1r6YuFG8e1hbqDVn8UYAbI6/uzsOb4FB62pOII azFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pnefIQzL6rsneTq4xQYVgtiFNZKU48FQE22oL5LUnwM=; b=Y6jyVmKVO5C4zKfH6uFjvGNlXHUarbpYSeBMxZ0s0W10X3cdtDeQThc8uYbu+iaedZ 9kSoxI4IT+j11ZhTe8qYXP4So04xUAzWv1X8WHJkbBuFWrnALyHXUTRIC31UKTgKRape GxJ/wRHvjpUPnWujAxcbhn9GH1EaO7LvvzBJ3afoCzdzFKbgwp/clZ9vIx2PwJHfT2uV LJmHoietwGztAgcWY3Gl5u7quvM02915vyA2BDBM6PBj1p+ISXOcxf8azJs1Nbv2L2NI L6tmmaErwKuOWjm6oMQ2j1Fb11QvSvhOxTkb9nff+gHIg5e9tjU65Mly90vqQlyrNoVX xqAg== X-Gm-Message-State: ANhLgQ32a3hfQhLIjuPgO9Xw9iqVAK+4wpti7sdF/oVLiNxwc8B3PnqG BMLmC0kE0JhjwjqLCm3kmJcyCQkqYnhcXEBRV9o= X-Google-Smtp-Source: ADFU+vtzLLpmpPDJFTEuixYdwELpDAPTrhOeY4pwXUelOIzump4+Rrpd/vqzlZk/qjmF+pSFyWQaUvqPkwWrDsFB9Kc= X-Received: by 2002:a67:2ecf:: with SMTP id u198mr5155514vsu.29.1584017841767; Thu, 12 Mar 2020 05:57:21 -0700 (PDT) MIME-Version: 1.0 References: <20200305020517.GA13872@wopr> <20200308052632.GD20478@eureka.lemis.com> <202003080532.0285WcWn1544496@darkstar.fourwinds.com> <20200309212257.GB39634@wopr> In-Reply-To: From: "John P. Linderman" Date: Thu, 12 Mar 2020 08:57:09 -0400 Message-ID: To: Warner Losh Content-Type: multipart/alternative; boundary="000000000000c6c71605a0a7e4aa" 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" --000000000000c6c71605a0a7e4aa Content-Type: text/plain; charset="UTF-8" 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? On Wed, Mar 11, 2020 at 5:29 PM Warner Losh wrote: > > > On Wed, Mar 11, 2020 at 11:43 AM John P. Linderman > wrote: > >> This is *great*, Kurt. The source in src/runtime/hrs/src for rsort.c is >> their version of my external sort, modified to be a subroutine. There's >> some lessons to be learned about "software hygiene". I was cavalier about >> freeing what I allocated dynamically. As a result, their version leaks like >> a sieve if the subroutine is called repeatedly. Apropos of which, they came >> to me having noted that only the first call was acting as expected. There's >> a wonderful irony (I'm big on irony). I had replaced my do-it-yourself >> argument processing with getopt. The code has the following comment >> >> ** Use getopt() for portability. >> >> A few lines later, you see >> >> optind = 1; /* reset after use in Hancock program * >> while ((c = getopt(argc, argv, "cCiIjmrsSuvb:f:D:o:p:T:x:y:z:")) != >> EOF) { >> >> optind??? Seems getopt has an undocumented global flag to prevent >> reprocessing the arguments. How portable:-) >> > > It's documented: > > The variables opterr and optind are both initialized to 1. The optind > variable may be set to another value before a set of calls to > getopt() in > order to skip over more or less argv entries. > > is what the FreeBSD man page has to say about it. So this just resets any > scanning that had happened before this... > > Warner > --000000000000c6c71605a0a7e4aa Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
My = error. I was looking at getopt(1) rather than getopt(3). Of course optind i= s 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 com= mand. Perhaps something to do with the software release process?

On We= d, Mar 11, 2020 at 5:29 PM Warner Losh <imp@bsdimp.com> wrote:


On Wed, Mar 11, 2020= at 11:43 AM John P. Linderman <jpl.jpl@gmail.com> wrote:
This is great, Kurt. The source in=C2=A0src/runtime/hrs/src fo= r rsort.c is their version of my external sort, modified to be a subroutine= . There's some lessons to be learned about "software hygiene"= . I was cavalier about freeing what I allocated dynamically. As a result, t= heir version leaks like a sieve if the subroutine is called repeatedly. Apr= opos of which, they came to me having noted that only the first call was ac= ting as expected. There's a wonderful irony (I'm big on irony). I h= ad replaced my do-it-yourself argument processing with getopt. The code has= the following comment

** Use getopt() for porta= bility.

A few lines later, you see

=C2= =A0 =C2=A0 optind =3D 1; =C2=A0/* reset after use in Hancock program *
=C2=A0 =C2= =A0=C2=A0while ((c =3D getopt(argc, argv, "cCiIjmrsSuvb:f:D:o:p:T:x:y:= z:")) !=3D EOF) {
=C2=A0 =C2=A0=C2=A0
optind??? Seems getopt has an undocumented global flag to prevent repro= cessing the arguments. How portable:-)

It's documented:

=C2=A0 =C2=A0 =C2=A0T= he variables opterr and optind are both initialized to 1.=C2=A0 The optind<= br>=C2=A0 =C2=A0 =C2=A0variable may be set to another value before a set of= calls to getopt() in
=C2=A0 =C2=A0 =C2=A0order to skip over more or les= s argv entries.

is what the FreeBSD man page h= as to say about it. So this just resets any scanning that had happened befo= re this...

Warner
--000000000000c6c71605a0a7e4aa--