On Mon, Aug 15, 2016 at 06:26:44PM +0200, Theo Buehler wrote:
> On Mon, Aug 15, 2016 at 03:33:38PM +0200, Jérôme FRGACIC wrote:
> > Hello tech,
> > 
> > I recently use ed(1) to transmit some input lines to another command.
> > However, I remark that after the 'w' command, I can exit ed without any
> > warnings even if the data were not saved into a file.
> > 
> > Here is an example :
> > 
> > $ ed
> > P
> > *a
> > A simple line.
> > .
> > *w !sed 's/^/#/'
> > #A simple line.
> > 15
> > *q
> > $ # No warning before exit
> > 
> > This behaviour seems not conform to the Open Group Base Specifications
> > Issue 6 (IEEE Std 1003.1, 2004 Edition). I would suggest this diff to
> > solve this problem.
> 
> POSIX says the following about the quit command:
> 
>        The q command shall cause ed to exit. If the buffer has changed since
>        the last time the entire buffer was written, the user shall be warned,
>        as described previously.
> 
> where 'previously' means:
> 
>        If changes have been made in the buffer since the last w command that
>        wrote the entire buffer, ed shall warn the user if an attempt is made
>        to destroy the editor buffer via the e or q commands.
>        [...]
> 
> You did write the entire buffer, namely to the stdin of the sed command,
> and afterwards you didn't change the buffer anymore, so I think this is
> compliant with what is quoted above.
> 
> FWIW, the GNU ed port (ged) behaves in exactly the same way.
> 
> Could you please be more specific what part of the standard you have in
> mind?

Oh, there's this in the description of the w command, sorry:

       If file begins with '!', the rest of the line shall be taken to be a
       shell command line whose standard input shall be the addressed lines.
       Such a shell command line shall not be remembered as the current
       pathname. This usage of the write command with '!'  shall not be
       considered as a ``last w command that wrote the entire buffer'', as
       described previously; thus, this alone shall not prevent the warning to
       the user if an attempt is made to destroy the editor buffer via the e
       or q commands.

Please ignore my previous objection.

> > 
> > Index: main.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ed/main.c,v
> > retrieving revision 1.57
> > diff -r1.57 main.c
> > 862c862
> > <           else if (addr == addr_last)
> > ---
> > >           else if (addr == addr_last && *fnp != '!')
> > 
> > 
> > PS : I haven't subcribe to the tech mailing list, so please add me as
> > recipient if you reply.
> > 
> > 
> > Kind regards,
> > 
> > 
> > Jérôme FRGACIC
> > 
> 

Reply via email to