[comp.bugs.4bsd] vi eats control-Ds in sourced files

chris@mimsy.UUCP (Chris Torek) (03/27/88)

Index:	ucb/ex/ex_get.c 4.3BSD Fix

Description:
	When vi (ex) reads .exrc files or other sourced files, it
	discards control-D.  This makes it difficult to map something
	to a string that includes a control-D, or to remap ^D itself.

Repeat-By:
	Create a .exrc file with the line

		map! ^D foo

	(that is, map control-D anything).  Run vi; note `missing rhs'
	error.

Fix:
	This seems to be what is required.  In any case it accounts
	for the fact that newline-to-control-D mapping is done only
	when `intty' is set.

RCS file: RCS/ex_get.c,v
retrieving revision 1.1
diff -c2 -r1.1 ex_get.c
*** /tmp/,RCSt1003257	Sat Mar 26 22:51:12 1988
--- ex_get.c	Sat Mar 26 22:50:55 1988
***************
*** 31,35 ****
  	do
  		c = getcd();
! 	while (!globp && c == CTRL(d));
  	return (c);
  }
--- 31,35 ----
  	do
  		c = getcd();
! 	while (!globp && intty && c == CTRL(d));
  	return (c);
  }
***************
*** 45,49 ****
  	c &= TRIM;
  	if (!inopen)
! 		if (!globp && c == CTRL(d))
  			setlastchar('\n');
  		else if (junk(c)) {
--- 45,49 ----
  	c &= TRIM;
  	if (!inopen)
! 		if (!globp && intty && c == CTRL(d))
  			setlastchar('\n');
  		else if (junk(c)) {
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

wk@hpirs.HP.COM (Wayne Krone) (03/29/88)

> Index:	ucb/ex/ex_get.c 4.3BSD Fix
> 
> Description:
> 	When vi (ex) reads .exrc files or other sourced files, it
> 	discards control-D.  This makes it difficult to map something
> 	to a string that includes a control-D, or to remap ^D itself.
> 
> Repeat-By:
> 	Create a .exrc file with the line
> 
> 		map! ^D foo
> 
> 	(that is, map control-D anything).  Run vi; note `missing rhs'
> 	error.

Is this really a problem that needs fixing?  Quote the ctrl-D with a
ctrl-V and it works without the fix.  The following line entered either
interactively or via a .exrc file will accomplish the desired result:

		map! ^V^D foo

Wayne Krone
Hewlett-Packard

chris@mimsy.UUCP (Chris Torek) (03/30/88)

>In article <10817@mimsy.UUCP> I wrote
>>Index:	ucb/ex/ex_get.c 4.3BSD Fix
>>Description:
>>	When vi (ex) reads .exrc files or other sourced files, it
>> 	discards control-D.

In article <3900001@hpirs.HP.COM> wk@hpirs.HP.COM (Wayne Krone) writes:
>Is this really a problem that needs fixing?

Yes.

>Quote the ctrl-D with a ctrl-V and it works without the fix.

Not in 4.3BSD (see `Index:' above).  A 4.3BSD .exrc containing
the `map!' command with the following sequence of characters:

	control-V control-D space f o o

Running vi produces a `missing rhs' error and ^D has not been
map!'ed.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

wk@hpirs.HP.COM (Wayne Krone) (04/02/88)

Re, my earlier comment:

> Is this really a problem that needs fixing?  Quote the ctrl-D with a
> ctrl-V and it works without the fix.  The following line entered either
> interactively or via a .exrc file will accomplish the desired result:
> 
> 		map! ^V^D foo

My apologies.  I fixed HP's implementation some months ago and only
remembered how it works, not that I had modified it, when I made the
above posting.

I have a different fix from Chris because I wanted to keep the .exrc
input the same as the interactive input (i.e., to map ctrl-D from
within vi you must precede the ctrl-D with ctrl-V so I reasoned input
from the .exrc file should also have a ctrl-V preceding the ctrl-D).
Is this line of reasoning incorrect?

Alternate fix:  In the routine mapcmd() in ex_cmdsub.c the following
appears twice:

	if (c == CTRL(v)) {
		c = getchar();

The fix is to change "getchar" to be "getcd" in both places.

Again, I apologize for my forgetfulness.

Wayne Krone
Hewlett-Packard

chris@mimsy.UUCP (Chris Torek) (04/03/88)

In article <3900002@hpirs.HP.COM> wk@hpirs.HP.COM (Wayne Krone) writes:
>I have a different fix from Chris because I wanted to keep the .exrc
>input the same as the interactive input (i.e., to map ctrl-D from
>within vi you must precede the ctrl-D with ctrl-V so I reasoned input
>from the .exrc file should also have a ctrl-V preceding the ctrl-D).
>Is this line of reasoning incorrect?

I would say that the reason for typing ^V^D interactively is that vi
tries to emulate the Berkeley tty driver (with some notable
exceptions).  Since files are simpler than ttys, the file contents
should be interpreted in the simplest possible manner, i.e., all the
funny translations done for user input should be skipped.  (After all,
you got the data into the file by working through or around all those
<expletive> translations in the first place.)

On the other hand, your fix makes `map' commands from `ex' mode work,
(I would guess; I have not tried it) as long as one types ^V^D and not
just ^D.  Perhaps, then, both changes should be applied.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris