From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29531 invoked from network); 8 Jul 2022 07:47:30 -0000 Received: from minnie.tuhs.org (50.116.15.146) by inbox.vuxu.org with ESMTPUTF8; 8 Jul 2022 07:47:30 -0000 Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id 640764011E; Fri, 8 Jul 2022 17:47:07 +1000 (AEST) Received: from marmaro.de (marmaro.de [176.28.23.198]) by minnie.tuhs.org (Postfix) with ESMTP id 41CA440116 for ; Fri, 8 Jul 2022 17:47:03 +1000 (AEST) Received: by marmaro.de (masqmail 0.3.6-dev, from userid 1000) id 1o9ihZ-3C2-00 for ; Fri, 08 Jul 2022 09:47:01 +0200 To: tuhs@tuhs.org User-Agent: meillo's mail handler (mmh) X-License: CC0 (http://marmaro.de/rights) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12277.1657266421.1@marmaro.de> Content-Transfer-Encoding: quoted-printable Date: Fri, 08 Jul 2022 09:47:01 +0200 From: markus schnalke Message-ID: <1o9ihZ-3C2-00@marmaro.de> Message-ID-Hash: CWYWXB7NCRHK7SCCJIOB7N5JZZG646PX X-Message-ID-Hash: CWYWXB7NCRHK7SCCJIOB7N5JZZG646PX X-MailFrom: meillo@marmaro.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-tuhs.tuhs.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [TUHS] ed: multiple addresses (with semicolons) List-Id: The Unix Heritage Society mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Hoi, via a recent message from Chris Pinnock to the list I became aware of the book ``Ed Mastery'' by Michael W. Lucas. At once I bought and read it. Although it is not on the mastery level it claims and I would have liked it to be, it still was fun to read. This brought me back to my ed interest. I like ed a lot and despite my young age, I've actually programmed with ed for fun and have prepared the troff slides for a talk on early Unix tools (like ed) with ed alone. I use the Heirloom version of ed. Anyways, I wondered about the possibility to give multiple addresses ... more than two for relative address searches. For example, to print the context of the first occurance of `argv' within the main function, you can use: /^main(/;/\/-2;+4n = For the last occurance it's even one level more: /^main(/;/^}/;?\?-2;+4n (The semicolons mean that the next search or relative addressing starts at the result of the previous one. I.e. in this case: We go to the `main' function, from there go to the function end, then backwards to `argv' minus two lines and print (with line numbers) this line and four lines more.) The manpage of 6th Edition mentiones this possibility to give more than two addresses: Commands may require zero, one, or two addresses. Commands which require no addresses regard the presence of an address as an error. Commands which accept one or two addresses assume default addresses when insufficient are given. If more addresses are given than such a command requires, the last one or two (depending on what is accepted) are used. http://man.cat-v.org/unix-6th/1/ed You can see it in the sources as well: https://www.tuhs.org/cgi-bin/utree.pl?file=3DV6/usr/source/s1/ed.c (Search for ';' to find the line. There's a loop processing the addresses.) V5 ed(1) is in assembler, however, which I cannot read. Thus there must have been a complete rewrite, maybe introducing this feature at that point. (I don't know where to find v5 manpage to check that as well.) I wonder how using multiple addresses for setting starting points for relative searches came to be. When was it implemented and what use cases drove this features back in the days? Or was it more an accident that was introduced by the implementation, which turned out to be useful? Or maybe it existed already in earlier versions of ed, althoug maybe undocumented. For reference, POSIX writes: Commands accept zero, one, or two addresses. If more than the required number of addresses are provided to a command that requires zero addresses, it shall be an error. Otherwise, if more than the required number of addresses are provided to a command, the addresses specified first shall be evaluated and then discarded until the maximum number of valid addresses remain, for the specified command. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html Here more explanation rom the rationale section: Any number of addresses can be provided to commands taking addresses; for example, "1,2,3,4,5p" prints lines 4 and 5, because two is the greatest valid number of addresses accepted by the print command. This, in combination with the delimiter, permits users to create commands based on ordered patterns in the file. For example, the command "3;/foo/;+2p" will display the first line after line 3 that contains the pattern foo, plus the next two lines. Note that the address "3;" must still be evaluated before being discarded, because the search origin for the "/foo/" command depends on this. As far as I can see, multiple addresses make only sense with the semicolon separator, because the comma separator does not change the state, thus previous addresses can have no effect on later addresses. The implementation just does not forbid them, for simplicity reasons. meillo