NetBSD Problem Report #8169

Received: (qmail 11990 invoked from network); 7 Aug 1999 22:06:54 -0000
Message-Id: <v04210102b3d25c540af1@[216.58.99.177]>
Date: Sat, 7 Aug 1999 18:04:48 -0400
From: Kevin Schoedel <schoedel@kw.igs.net>
To: gnats-bugs@gnats.netbsd.org
Subject: nvi: write doesn't set remembered command

>Number:         8169
>Category:       bin
>Synopsis:       nvi: write doesn't set remembered command
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Aug 07 15:20:02 +0000 1999
>Closed-Date:    Sat Oct 31 14:31:56 +0000 2009
>Last-Modified:  Sat Oct 31 14:35:01 +0000 2009
>Originator:     Kevin Schoedel
>Release:        1.4
>Organization:
>Environment:

System: NetBSD lithium.local.domain 1.4 NetBSD 1.4 (3MIN) #4: Sun May 16
17:58:52 EDT 1999
kevin@lithium.local.domain:/usr/src/sys/arch/pmax/compile/3MIN pmax

nvi: Version 1.66 (5/18/96) The CSRG, University of California, Berkeley.

>Description:

When writing to a shell command (e.g.. ":w !foo") the "remembered command"
is not set. Consequently, attempting to use "!" in a subsequent shell
command either fails entirely or uses the otherwise-previous command.

(BTW, is there any good reason for using this relatively old nvi? This
particular bug exists in the current version 1.79 as well, but presumably
others don't. Assuming there are changes from the original 1.66 to
NetBSD's current 1.66, if I were to merge the 1.66 -> 1.79 changes
into NetBSD's vi, is there someone willing to review and check in
the changes?)

>How-To-Repeat:

Observe that no two people use the same subset of vi ;-)

Script started on Thu Aug  5 22:29:08 1999
$ ex
/tmp/vi.09531b: new file: line 1
:w !echo write
write
!
:!!
No previous command to replace "!"
:r !echo read
!
read
:!!
!echo read
File modified since last write.
read
!
:w !echo write again
write again
!
:!!
!echo read
File modified since last write.
read
!
:q!
$ ^D

Script done on Thu Aug  5 22:29:43 1999

>Fix:

I am not an nvi expert. This patch simply replicates the relevant code
from ex_read() into exwr(). This patch applies to /usr/src/usr.bin/vi
in NetBSD 1.4.  Further below is the equivalent patch for nvi 1.79.

*** ex/ex_write.c.orig	Fri Jan  9 03:08:12 1998
--- ex/ex_write.c	Sat Aug  7 15:13:44 1999
***************
*** 141,146 ****
--- 141,147 ----
  	MARK rm;
  	int flags;
  	char *name, *p;
+ 	EX_PRIVATE *exp;

  	NEEDFILE(sp, cmdp);

***************
*** 161,174 ****
  			return (1);
  		}

! 		for (++p; *p && isblank(*p); ++p);
! 		if (*p == '\0') {
! 			ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
! 			return (1);
! 		}
! 		/* Expand the argument. */
! 		if (argv_exp1(sp, cmdp, p, strlen(p), 1))
! 			return (1);

  		/*
  		 * !!!
--- 162,183 ----
  			return (1);
  		}

!  		/*
!  		 * File name and bang expand the user's argument.  If
!  		 * we don't get an additional argument, it's illegal.
!  		 */
!  		++p;
!  		if (argv_exp1(sp, cmdp, p, strlen(p) + 1, 1))
!   			return (1);
!
!  		/* Set the last bang command. */
!  		exp = EXP(sp);
!  		if (exp->lastbcomm != NULL)
!  			free(exp->lastbcomm);
!  		if ((exp->lastbcomm = strdup(p)) == NULL) {
!  			msgq(sp, M_SYSERR, NULL);
!   			return (1);
!  		}

  		/*
  		 * !!!


Here is the equivalent patch for nvi 1.79.

*** ex/ex_write.c.orig	Fri Jul 12 20:55:27 1996
--- ex/ex_write.c	Tue Jun 29 14:52:08 1999
***************
*** 139,144 ****
--- 139,145 ----
  	MARK rm;
  	int flags;
  	char *name, *p;
+ 	EX_PRIVATE *exp;

  	NEEDFILE(sp, cmdp);

***************
*** 159,172 ****
  			return (1);
  		}

! 		/* Expand the argument. */
! 		for (++p; *p && isblank(*p); ++p);
! 		if (*p == '\0') {
! 			ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
  			return (1);
! 		}
! 		if (argv_exp1(sp, cmdp, p, strlen(p), 1))
  			return (1);

  		/*
  		 * Historically, vi waited after a write filter even if there
--- 160,181 ----
  			return (1);
  		}

! 		/*
! 		 * File name and bang expand the user's argument.  If
! 		 * we don't get an additional argument, it's illegal.
! 		 */
! 		++p;
! 		if (argv_exp1(sp, cmdp, p, strlen(p) + 1, 1))
  			return (1);
!
! 		/* Set the last bang command. */
! 		exp = EXP(sp);
! 		if (exp->lastbcomm != NULL)
! 			free(exp->lastbcomm);
! 		if ((exp->lastbcomm = strdup(p)) == NULL) {
! 			msgq(sp, M_SYSERR, NULL);
  			return (1);
+ 		}

  		/*
  		 * Historically, vi waited after a write filter even if there

-- 
Kevin Schoedel
schoedel@kw.igs.net
>Release-Note:
>Audit-Trail:

From: schoedel@kw.igs.net (Kevin Schoedel)
To: gnats-bugs@netbsd.org
Cc:  Subject: bin/8169
Date: Wed, 19 Jan 2000 12:44 EST

 Correction to the previously-supplied patch:

 <		if ((exp->lastbcomm = strdup(p)) == NULL) {                     
 ---
 >		if ((exp->lastbcomm = strdup(cmdp->argv[1]->bp)) == NULL) {

State-Changed-From-To: open->closed
State-Changed-By: dsl@NetBSD.org
State-Changed-When: Sat, 31 Oct 2009 14:31:56 +0000
State-Changed-Why:
Fix similar to that suggested applied.


From: David Laight <dsl@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/8169 CVS commit: src/dist/nvi/ex
Date: Sat, 31 Oct 2009 14:30:55 +0000

 Module Name:	src
 Committed By:	dsl
 Date:		Sat Oct 31 14:30:55 UTC 2009

 Modified Files:
 	src/dist/nvi/ex: ex_write.c

 Log Message:
 Save command in :w !<command> for later :w !!
 Fixes PR/8169


 To generate a diff of this commit:
 cvs rdiff -u -r1.2 -r1.3 src/dist/nvi/ex/ex_write.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.