On Thu, Jun 18, 2015 at 02:16:08PM +0100, Jason McIntyre wrote:
> On Thu, Jun 18, 2015 at 12:33:58PM +0200, Theo Buehler wrote:
> > Here's a silly ed(1) session:
> > 
> > $ ed -p ":> "
> > :> P
> > P
> > *q
> > $
> > 
> > Notice how the prompt string changed from the custom prompt ":> " to
> > the default prompt "*".
> > 
> > This behavior seems to contradict both the man page and POSIX:
> > 
> > >From ed(1):
> >      -p string  Specifies a command prompt.  This may be toggled on and off
> >                 with the P command.
> > 
> > >From POSIX:
> >        The P command shall cause ed to prompt with an <asterisk> ('*') (or
> >        string, if -p is specified) for all subsequent commands. The P 
> > command
> >        alternatively shall turn this mode on and off; it shall be initially 
> > on
> >        if the -p option is specified; otherwise, off.
> > 
> > With the patch below, the above session becomes
> > 
> > $ ed -p ":> "
> > :> P 
> > P
> > :> q 
> > $
> > 
> > which, I believe, is closer to both the documentation and POSIX.
> > 
> > This also matches the behavior of GNU Ed 1.10.
> > 
> 
> it does seem odd, yes.
> 
> still, i'd like to know how netbsd and freebsd behave: all 3 manuals use
> the same (ambiguous) text.  it could be that we want to document it as a
> difference to posix rather than change the behaviour (i'm not the guy to
> judge whether a change in behaviour is warranted).
> 
> note also:
> 
> - posix isn;t explicit (surprise, surprise)
> - posix also documents "bsd" systems as (simultaneously!) not supporting
>   "P" and supporting "P" as a synonym for "p"
> 
> jmc

>From looking at the source code, I'm quite sure that the other BSD's
behavior is the same as the current behavior in OpenBSD.

I agree that the formulations in the manpages and POSIX aren't explicit,
let alone unambiguous, as to what exactly is supposed to happen when
pressing "P".

However, what POSIX claims about "P" being a synonym of "p" is bogus:

*  BSD does not support the P command; moreover, in BSD it is
   synonymous with the p command.

Compare this with the following session:

$ ed
p
?
P
*p
?
*P
q
$

The source code in FreeBSD and NetBSD shows that the "print command p"
and the "prompt command P" are treated completely differently there as
well.

> 
> > Index: bin/ed/main.c
> > ===================================================================
> > RCS file: /cvs/src/bin/ed/main.c,v
> > retrieving revision 1.43
> > diff -u -p -r1.43 main.c
> > --- bin/ed/main.c   16 Jan 2015 06:39:32 -0000      1.43
> > +++ bin/ed/main.c   18 Jun 2015 10:33:21 -0000
> > @@ -110,7 +110,7 @@ top:
> >     while ((c = getopt(argc, argv, "p:sx")) != -1)
> >             switch (c) {
> >             case 'p':                               /* set prompt */
> > -                   prompt = optarg;
> > +                   dps = prompt = optarg;
> >                     break;
> >             case 's':                               /* run script */
> >                     scripted = 1;
> > 
> 

Reply via email to