Hello.

I have noticed that  ed -p ''  errors with the following error.

    $ ed -p '' foo.txt
    ed: option requires an argument -- 'p'
    Try 'ed --help' for more information.
    $ ed -p ''
    ed: option requires an argument -- 'p'
    Try 'ed --help' for more information.

As if I had run  ed -p  without an argument.

That seems incorrect; there does not seem to be anything in the
POSIX Issue 7 specification for ed that allows unspecified behaviour
when the prompt string is empty or requires that the prompt string
specified by -p shall not be the empty string.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html

I think GNU ed is supposed to not error, and let the command run in this
case, and set the prompt string to  ''  and enable prompting by default;
i.e. pretty much like not specifying  -p ''  at all except that now the
P  command should effectively do nothing instead of toggling on/off a
'*' prompt.

The cause of this problem seems to be that the Arg_parser library that
ed is using, in the parse_short_option function, at line 209 of
carg_parser.c, checks  !arg || !arg[0]  as error condition for short
options that require an argument instead of checking only  !arg
incorrectly likening empty string to a missing argument.

    207     else if( options[index].has_arg == ap_yes )
    208       {
    209       if( !arg || !arg[0] )
    210         {
    211         add_error( ap, "option requires an argument -- '" );
    212         add_error( ap, code_str ); add_error( ap, "'" );
    213         return 1;
    214         }

A similar problem occurs for long options ( --prompt '' ), and
long= options ( --prompt= ) because, at line 157 of the same file, in
the parse_long_option function, the same check is done instead of  !arg
for long options that require an argument:

    $ ed --prompt= foo.txt
    ed: option '--prompt' requires an argument
    Try 'ed --help' for more information.
    $ ed --prompt '' foo.txt
    ed: option '--prompt' requires an argument
    Try 'ed --help' for more information.

    155   if( options[index].has_arg == ap_yes )
    156     {
    157     if( !arg || !arg[0] )
    158       {
    159       add_error( ap, "option '--" ); add_error( ap, 
options[index].long_name );
    160       add_error( ap, "' requires an argument" );
    161       return 1;
    162       }

I think that at least the behaviour of  ed -p ''  should be changed to
make it not unexpectedly error.

o/
 emanuele6

Reply via email to