Re: [dev] [vis][RFC][PATCH 1/2] Replace first '/' of substitute command with \0

From: Marc André Tanner <mat_AT_brain-dump.org>
Date: Wed, 6 May 2015 21:03:29 +0200

On Tue, May 05, 2015 at 06:25:29PM +0200, Silvan Jegen wrote:
> Replacing the first '/' allows the 's' command name to be correctly
> identified even though it is part of its own argument.

Special casing '/' seems wrong, an arbitrary delimiter can be used

 :s,foo,bar

is perfectly valid. The end of the command name should probably be
detected by isalpha(3) or similar. Hence instead of doing a strdup(...)
we should probably do a malloc(strlen(...)+2) in combination with
a strcpy/memcpy and then memmove(...) the arguments one position to
the right and NUL-terminate the name.

> This is hacky because afterwards we will add the '/' back in before
> calling the 'sed' program.

Relying on the fact that cmd_set was called with (i.e. that argv[0]
was set to) ':s/' is wrong, it could also be ':substitute/'.

With the strategy outlined above argv[1] would contain the argument
(= search pattern) which could be prefixed by 's'. Furthermore if
the pattern doesn't contain the delimiter at the end, it should
be appended.

Please send an updated patch if you think this makes sense ...

-- 
 Marc André Tanner >< http://www.brain-dump.org/ >< GPG key: CF7D56C0
Received on Wed May 06 2015 - 21:03:29 CEST

This archive was generated by hypermail 2.3.0 : Wed May 06 2015 - 21:12:07 CEST