On Tue, 07 Feb 2023 21:12:58 +0100, =?UTF-8?Q?Tom=C3=A1=C5=A1_Rippl_?= wrote:
> System: OpenBSD 7.2
> Architecture: OpenBSD.amd64
> Machine: amd64
>
> Description
>
> There is a bug in ex's 's' command.
>
> With the 'number' option OFF, and when using the 'c' flag, ex correctly "unde
> rlines" the part of the text to be replaced with carets. For instance, when i
> ssuing :s/men/MEN/c for:
>
> Five women came to the party.
> ^^^[ynq]
>
> However, with the 'number' option ON, the caret underline is incorrectly offs
> et by the number of characters that matches the indent used when numbering is
> ON.
>
> Five women came to the party.
> ^^^[ynq]
> Perhaps, on the contrary, the error lies in the fact that the displayed line
> does not respect the NUMBER option enabled (as it is displayed without the li
> ne number) so the line is positioned incorrectly and the underlining is posit
> ioned 'correctly'.
Yes, the bug is that the number is not displayed. The following
diff fixes that but there is still a bug because the resulting line
also lacks a line number. In other words, instead of:
:s/men/MEN/c
1 Five women came to the party.
^^^[ynq]y
Five woMEN came to the party.
it should look like this:
:s/men/MEN/c
1 Five women came to the party.
^^^[ynq]y
1 Five woMEN came to the party.
- todd
Index: ex/ex_subst.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/ex/ex_subst.c,v
retrieving revision 1.30
diff -u -p -u -r1.30 ex_subst.c
--- ex/ex_subst.c 18 Apr 2017 01:45:35 -0000 1.30
+++ ex/ex_subst.c 8 Feb 2023 00:06:18 -0000
@@ -633,7 +633,10 @@ nextmatch: match[0].rm_so = offset;
goto lquit;
}
} else {
- if (ex_print(sp, cmdp, &from, &to, 0) ||
+ int iflags = 0;
+ if (O_ISSET(sp, O_NUMBER))
+ iflags = E_C_HASH;
+ if (ex_print(sp, cmdp, &from, &to, iflags) ||
ex_scprint(sp, &from, &to))
goto lquit;
if (ex_txt(sp, &tiq, 0, TXT_CR))