The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] ed: multiple addresses (with semicolons)
@ 2022-07-08 13:23 Douglas McIlroy
  2022-07-08 16:01 ` [TUHS] " Ken Thompson
  2022-07-10  9:25 ` Angelo Papenhoff
  0 siblings, 2 replies; 13+ messages in thread
From: Douglas McIlroy @ 2022-07-08 13:23 UTC (permalink / raw)
  To: TUHS main list

The interpretation of a string of addresses separated by commas and/or
semicolons was already defined in the v1 man page for ed.

Ed was essentially a stripped-down version of Multics qed. The latter
was originally
written by Ken. Unfortunately the "Multics Condensed Guide" online at
multicians.org describes how strings of addresses were interpreted
only by canonical examples for the various editing requests.

I  have no specific memory of semicolons in qed. I have a vague
recollection that semicolons originated in ed, however you should put
no trust in this. Maybe Ken remembers.

Doug

^ permalink raw reply	[flat|nested] 13+ messages in thread
* [TUHS] Re: ed: multiple addresses (with semicolons)
@ 2022-07-11 17:30 Douglas McIlroy
  2022-07-18 10:52 ` markus schnalke
  0 siblings, 1 reply; 13+ messages in thread
From: Douglas McIlroy @ 2022-07-11 17:30 UTC (permalink / raw)
  To: TUHS main list

> More was I curious about the documentation of address chains in books.

It was even discussed in Lomutu and Lomuto, "A Unix Primer", a pleasant
book whose level is accurately described in the title.

Doug

^ permalink raw reply	[flat|nested] 13+ messages in thread
* [TUHS] Re: ed: multiple addresses (with semicolons)
@ 2022-07-08 21:36 Douglas McIlroy
  2022-07-11 14:40 ` markus schnalke
  0 siblings, 1 reply; 13+ messages in thread
From: Douglas McIlroy @ 2022-07-08 21:36 UTC (permalink / raw)
  To: meillo, TUHS main list

> I wasn't able to find the ``Multics Condensed Guide'' on multicians.org

multicians.org  points to
http://www.bitsavers.org/pdf/honeywell/multics/swenson/6906.multics-condensed-guide.pdf

It also has
https://www.multicians.org/mspm/bx-9-06.681115.qed-editor.pdf

Amusingly, the "condensed guide" is many pages longer than the
MSPM (Multics system programmer's manual--the gospel)
Neither tells about extra address fields or semicolons

> In ex(1) the " comment command reappeared.

And in sed the y command reappeared.

Doug

^ permalink raw reply	[flat|nested] 13+ messages in thread
* [TUHS] ed: multiple addresses (with semicolons)
@ 2022-07-08  7:47 markus schnalke
  2022-07-08  8:09 ` [TUHS] " markus schnalke
  0 siblings, 1 reply; 13+ messages in thread
From: markus schnalke @ 2022-07-08  7:47 UTC (permalink / raw)
  To: tuhs

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(/;/\<argv\>/-2;+4n 

For the last occurance it's even one level more:

	/^main(/;/^}/;?\<argv\>?-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=V6/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 <semicolon> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-07-18 10:52 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-08 13:23 [TUHS] ed: multiple addresses (with semicolons) Douglas McIlroy
2022-07-08 16:01 ` [TUHS] " Ken Thompson
2022-07-08 19:13   ` markus schnalke
2022-07-09  8:10     ` steve jenkin
2022-07-09  8:22       ` Rob Pike
2022-07-10  3:50         ` Jon Forrest
2022-07-10  9:25 ` Angelo Papenhoff
2022-07-10  9:59   ` Ralph Corderoy
  -- strict thread matches above, loose matches on Subject: below --
2022-07-11 17:30 Douglas McIlroy
2022-07-18 10:52 ` markus schnalke
2022-07-08 21:36 Douglas McIlroy
2022-07-11 14:40 ` markus schnalke
2022-07-08  7:47 [TUHS] " markus schnalke
2022-07-08  8:09 ` [TUHS] " markus schnalke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).