Date: Sun, 17 Oct 2004 06:50:34 GMT From: "Matt Emmerton" <matt@gsicomp.on.ca> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/58293: vi replace with CR (ASCII 13) doesn't work Message-ID: <200410170650.i9H6oY8h030071@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/58293; it has been noted by GNATS.
From: "Matt Emmerton" <matt@gsicomp.on.ca>
To: <freebsd-gnats-submit@FreeBSD.org>, <mjanosi@uakron.edu>
Cc:
Subject: Re: bin/58293: vi replace with CR (ASCII 13) doesn't work
Date: Sun, 17 Oct 2004 02:44:21 -0400
Based on my (very limited) knowledge of the ex/vi code, "higher" levels of
the replacement algorithm are supposed to have already handled escaped
characters (such as things like \007 and ^H.) The assumption in these
higher layers is that CR/LF hold special significance -- mainly because of
multi-line replacement patterns which requires special handling.
The real action is in the re_sub() routine, where everything except special
sequences (see comment) are handled via OUTCH. The OUTCH macro treats CR/LF
in a special way to handle multi-line patterns and passes them through
NEEDNEWLINE. This ends up replacing CR with NL and ignores the fact that
the CR in the pattern was escaped. This is why :s/X/\^M/ (escaped) acts the
same as :s/X/^M/ (unescaped).
My solution is to handle an escaped CR in the same block of code that
handles the special sequences. Since the CR is escaped, it is not
significant wrt multi-line patterns, and just needs to flow through.
DISCLAIMER: This patch has been tested to solve the problem presented in the
PR, no testing of complex situations (ie multi-line patterns, etc) has been
performed.
Patch against FreeBSD 4.10 sources follows:
*** ex_subst.c.orig Sun Oct 17 02:33:28 2004
--- ex_subst.c Sun Oct 17 03:05:34 2004
***************
*** 1443,1448 ****
--- 1443,1451 ----
case 'U':
++rp;
conv = C_UPPER;
+ continue;
+ case '\r':
+ OUTCH(ch, 0);
continue;
default:
++rp;
--
Matt Emmerton
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200410170650.i9H6oY8h030071>
