bin/58293: vi replace with CR (ASCII 13) doesn't work

Matt Emmerton matt at gsicomp.on.ca
Sat Oct 16 23:50:34 PDT 2004


The following reply was made to PR bin/58293; it has been noted by GNATS.

From: "Matt Emmerton" <matt at gsicomp.on.ca>
To: <freebsd-gnats-submit at FreeBSD.org>, <mjanosi at 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
 


More information about the freebsd-bugs mailing list