From mjanosi@uakron.edu  Mon Oct 20 11:55:05 2003
Return-Path: <mjanosi@uakron.edu>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 3821B16A4B3
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 20 Oct 2003 11:55:05 -0700 (PDT)
Received: from correntosa.uakron.edu (correntosa.uakron.edu [130.101.81.44])
	by mx1.FreeBSD.org (Postfix) with ESMTP id D043243F3F
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 20 Oct 2003 11:55:01 -0700 (PDT)
	(envelope-from mjanosi@uakron.edu)
Received: from mulder.uakron.edu (mulder.cc.uakron.edu [130.101.5.50])
	by correntosa.uakron.edu (8.12.10/8.12.2) with ESMTP id h9KIskCD023186
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 20 Oct 2003 14:54:46 -0400
Received: from uakron.edu (webteam3.cc.uakron.edu [130.101.181.56])
	by mulder.uakron.edu (8.12.10/8.11.6) with ESMTP id h9KIsjME006249
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 20 Oct 2003 14:54:45 -0400 (EDT)
Message-Id: <3F942F90.4C5A86D1@uakron.edu>
Date: Mon, 20 Oct 2003 14:55:12 -0400
From: Miklos Janosi <mjanosi@uakron.edu>
Sender: mjanosi@mulder.cc.uakron.edu
Reply-To: mjanosi@uakron.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject: vi replace with CR (ASCII 13) doesn't work

>Number:         58293
>Category:       bin
>Synopsis:       vi(1) replace with CR (ASCII 13) doesn't work
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 20 12:00:30 PDT 2003
>Closed-Date:    
>Last-Modified:  Mon Dec  9 18:50:01 UTC 2013
>Originator:     Miklos Janosi
>Release:        FreeBSD 4.7-RELEASE i386
>Organization:
University of Akron
>Environment:
System: FreeBSD webteam3.cc.uakron.edu 4.7-RELEASE FreeBSD 4.7-RELEASE
#1: Wed Feb 26 09:29:28 EST 2003
mjanosi@webteam5.cc.uakron.edu:/usr/src/sys/compile/MIKI i386

>Description:
The vi command :s/X/\^M/ behaves just like :s/X/^M/
>How-To-Repeat:
Edit a file that contains just 1 char, an "X" with vi. Enter the
following
command :s/X/\^M/ and keep in mind ^M is the key combination of ctrl-v
and
<enter>. It should replace the "X" with a carriage return (ASCII 13),
but
it replaces it with a newline (ASCII 10).
>Fix:
>Release-Note:
>Audit-Trail:

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
 

From: Zhihao Yuan <zhihao.yuan@rackspace.com>
To: bug-followup@FreeBSD.org, mjanosi@uakron.edu
Cc:  
Subject: Re: bin/58293: vi(1) replace with CR (ASCII 13) doesn&#39;t work
Date: Mon, 9 Dec 2013 13:49:03 -0500

 Fixed in -CURRENT.
 
 -- 
 Zhihao Yuan <zhihao.yuan@rackspace.com>
 The best way to predict the future is to invent it.
 ___________________________________________________
 4BSD -- http://4bsd.biz/
>Unformatted:
 X-send-pr-version: 3.113
 X-GNATS-Notify:
 
 
