From owner-freebsd-bugs@FreeBSD.ORG Sun Oct 17 06:50:34 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9E6A016A4CE for ; Sun, 17 Oct 2004 06:50:34 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8D4CC43D2F for ; Sun, 17 Oct 2004 06:50:34 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i9H6oYWk030072 for ; Sun, 17 Oct 2004 06:50:34 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i9H6oY8h030071; Sun, 17 Oct 2004 06:50:34 GMT (envelope-from gnats) Date: Sun, 17 Oct 2004 06:50:34 GMT Message-Id: <200410170650.i9H6oY8h030071@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: "Matt Emmerton" Subject: Re: bin/58293: vi replace with CR (ASCII 13) doesn't work X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Matt Emmerton List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Oct 2004 06:50:34 -0000 The following reply was made to PR bin/58293; it has been noted by GNATS. From: "Matt Emmerton" To: , 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