Fix a bug in ex's 's' command with the 'c' flag when 'number' is off.
authormillert <millert@openbsd.org>
Fri, 23 Jun 2023 15:06:45 +0000 (15:06 +0000)
committermillert <millert@openbsd.org>
Fri, 23 Jun 2023 15:06:45 +0000 (15:06 +0000)
The underlining was positioned in the wrong place.  This fixes
the problem and matches historic ex behavior.  OK op@

usr.bin/vi/ex/ex.c
usr.bin/vi/ex/ex_subst.c

index 357aa86..9aa31ad 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ex.c,v 1.22 2022/02/20 19:45:51 tb Exp $      */
+/*     $OpenBSD: ex.c,v 1.23 2023/06/23 15:06:45 millert Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -1454,8 +1454,14 @@ addr_verify:
                LF_INIT(FL_ISSET(ecp->iflags, E_C_HASH | E_C_LIST | E_C_PRINT));
                if (!LF_ISSET(E_C_HASH | E_C_LIST | E_C_PRINT | E_NOAUTO) &&
                    !F_ISSET(sp, SC_EX_GLOBAL) &&
-                   O_ISSET(sp, O_AUTOPRINT) && F_ISSET(ecp, E_AUTOPRINT))
-                       LF_INIT(E_C_PRINT);
+                   O_ISSET(sp, O_AUTOPRINT) && F_ISSET(ecp, E_AUTOPRINT)) {
+
+                       /* Honor the number option if autoprint is set. */
+                       if (F_ISSET(ecp, E_OPTNUM))
+                               LF_INIT(E_C_HASH);
+                       else
+                               LF_INIT(E_C_PRINT);
+               }
 
                if (LF_ISSET(E_C_HASH | E_C_LIST | E_C_PRINT)) {
                        cur.lno = sp->lno;
index 64afb91..e58bf1e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ex_subst.c,v 1.30 2017/04/18 01:45:35 deraadt Exp $   */
+/*     $OpenBSD: ex_subst.c,v 1.31 2023/06/23 15:06:45 millert Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -633,7 +633,9 @@ nextmatch:  match[0].rm_so = offset;
                                        goto lquit;
                                }
                        } else {
-                               if (ex_print(sp, cmdp, &from, &to, 0) ||
+                               const int flags =
+                                   O_ISSET(sp, O_NUMBER) ? E_C_HASH : 0;
+                               if (ex_print(sp, cmdp, &from, &to, flags) ||
                                    ex_scprint(sp, &from, &to))
                                        goto lquit;
                                if (ex_txt(sp, &tiq, 0, TXT_CR))