.
Last update: 1997-05-20
9945-2-119 _____________________________________________________________________________ Topic: ed global commands Relevant Sections: 4.20.7.3.7, 4.20.7.3.8, 4.20.7.3.25, 4.20.7.3.26 Defect Report: ----------------------- From: [email protected] (Scott Sutter) Date: Thu, 27 Apr 1995 14:05:12 -0500 (CDT) From: [email protected] (Bob Clark) Date: Apr 10, 1995 Dear Standards Board, I would like to request an official interpretation from WG15 concerning the following point in ISO/IEC 9945-2:1993 (POSIX.2). The indicated sections of the ed utility description do not indicate whether any given line in the buffer may be modified more than once during a single global command invocation. (A global command refers to any of the g, G, v, or V commands.) Lines 3758-3760 of section 4.20.7.3.7 describe the basic premise of the global commands: In the global command, the first step shall be to mark every line that matches the given BRE. Then, for every such line, the given command list shall be executed with the current line number set to the address of that line. Lines 3781-3783 of section 4.20.7.3.8 indicate that the commands list of the G command can modify any part of the buffer (this is also true for the other global commands): The commands read as part of the execution of the G command can address and affect any lines in the buffer. What comes into question is whether ed should allow a commands list to modify any one line in the buffer on more than one iteration of a global command. Historically, the global commands do not execute the given command list on any marked line which has already been modified (via a substitute or move command in the command list), during the current global command invocation. For example, assume the following input file: ab bc ac ab And the following ed command: g/b/ 1,$s/$/./ Every ed command I have found gives the following output: ab. bc. ac. ab. If the substitute command had been applied to the whole buffer (due to the 1,$ address range) for each of the three /b/ matches found by the g command, the resulting file would be: ab... bc... ac... ab... This facet of the historical implementation prevents the extraordinary consequences possible if lines may be modified more than once from within any one global command. The following problematic examples assume an ed command that allows these multiple modifications. (The input file is the same as in the example above.) 1) g/b/ .,$s/b/x/g This substitution would fail after the first iteration since the string to be substituted (/b/) has been removed. 2) g/b/ $s/a/aaaaaaaaaa/g This substitution would cause the last line to grow in length at an exponential rate. A similar case could split lines and make the file length grow exponentially. 3) g/b/ +1m0 Here, the global search marked line 2 for later action, but on the first iteration, it was moved to the top of the file. Should the second iteration set dot to line 1 or line 4 before executing the command list? It is my opinion that the historical implementation of the global commands is safer and is at least more straight forward than the possible interpretation described above and should be clarified in the relevant sections of POSIX.2. Thank you for your attention to this matter. Bob Clark Interpretation response ------------------------ The standard states the behavior for ed global commands and conforming implementations must conform to this. However, concerns have been raised concerning historical practice which are being referred to the sponsor. Rationale ------------- None. Forwarded to Interpretations group: May 04 1995 Proposed resolution forwarded: Aug 11 1995 Finalized: Sept 12 1995