[net.bugs.4bsd] vi bug?

ado@elsie.UUCP (Arthur David Olson) (03/06/85)

Index:		ucb/ex/ex_vops.c

Description:
	<1798@sdcrdcf.UUCP>--
    > . ..I have a file whose contents is:
    > 12345
    > 67890
    > 
    > The cursor is on the 1, and I type the following sequence of commands:
    > ma
    > f5
    > y`a
    > <cr>
    > P
    > 
    > Now, I think the P should insert 12345 before the 6 on the second line.
    > Instead, it DELETES the 6789. . .

Repeat-By:
	See above.

Fix:
	The file to be fixed is known as "/usr/src/cmd/ex/ex_vops.c" in 4.1bsd.
	The trade secret status of the code precludes a clearer posting.

 ed /usr/src/cmd/ex/ex_vops.c
 /dot > wdot/c
 #ifdef OLDVERSION
 	if (dot > wdot) {
 #else
 	if (dot > wdot || (dot == wdot && wcursor != 0 && cursor > wcursor)) {
 #endif
 .
 w
 q
--
UNIX and EX are AT&T Bell Laboratories and Elizabeth Taylor trademarks.
--
	UUCP: ..decvax!seismo!elsie!ado    ARPA: elsie!ado@seismo.ARPA
	DEC, VAX and Elsie are Digital Equipment and Borden trademarks

levy@ttrdc.UUCP (Daniel R. Levy) (09/05/86)

I have found what I _think_ is a bug in several different versions of vi
(on a VAX running BSD4.1, on a 3B2/400 running SysVR2, on a 3B20S running
SysVR2, but not on a PDP 11/70 running the UNIX 4.0 system).

The trouble seems to be that vi will intercept certain ASCII sequences in
the input file on lines beginning with 'ex:' and will interpret them as if
they were commands.

For example, a file containing the two lines

ex::
ex:3:

will, when read into some versions of vi, produce the diagnostic
"Not that many lines in buffer."

This problem arose when using vi to edit ASCII database files structured into
newline-separated records with the fields separated by colons (a la
/etc/passwd) and where 'ex' was one possible entry in the first field of
a record.

Would someone who is in the know please tell me whether this behavior is
a bug or a "feature"?  I certainly cannot find any mention of it in what
little documentation I have about vi (the SysV and BSD man pages on ex and
vi, and a document called "An Introduction to Display Editing using Vi").
Thank you in advance.
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
	   go for it!  			allegra,ulysses,vax135}!ttrdc!levy

jrw@hropus.UUCP (Jim Webb) (09/06/86)

> I have found what I _think_ is a bug in several different versions of vi
  ....
> The trouble seems to be that vi will intercept certain ASCII sequences in
> the input file on lines beginning with 'ex:' and will interpret them as if
> they were commands.
> 
> Would someone who is in the know please tell me whether this behavior is
> a bug or a "feature"?  I certainly cannot find any mention of it in what
> little documentation I have about vi (the SysV and BSD man pages on ex and
> vi, and a document called "An Introduction to Display Editing using Vi").
> Thank you in advance.

This is an semi-documented feature:  

	Mode lines are now supported.  Put a line containing
		ex: xxx :
	in the first or last 5 lines of the file, where xxx is any ex
	command you want executed when that file is read in.  To make
	other programs happy, it should probably be inside a comment. ----+
	You can use vi: as well as ex:.  (Note: no space allowed          |
	between the "ex" and ":".  The spaces around xxx are considered   |
	part of the command, and so are optional.)                        |
                                                                          |
                                              eg /* ex: autoindent : */ <-+

It was added in version 3.7 (October 16, 1981).  This and other goodies
are found in a file ex.news which comes with the vi src.  On my machine,
it was in /usr/src/cmd/vi/vax/ex.news which is a vax running SVR2.  I don't
know whether or not it is considered proprietary, otherwise I would have
posted it in its entirety.
-- 
Jim Webb             "Out of phase--get help"          ...!ihnp4!hropus!jrw

levy@ttrdc.UUCP (Daniel R. Levy) (09/08/86)

Thanks to the several people who wrote or posted to say that yes, this
(intercepting ex: or vi: [or ei: or vx: -- yuck] in the first or last few
lines of a file being read in) is an old, old "feature" allowing for auto-
configuration of vi, and that, yawn, it had been hashed over many many
times before on the net.  (Guess I have to get a copy of the compleat net
archives, then, so I won't appear stupid to the oldtimers.  Postpone those
backups, Joe, gotta mount a few dozen magtapes to grep for something :-). )

I sure would have preferred that this behavior wasn't the default, requiring
a command line option or environment variable to turn it on, or at the least
that it could be turned off by a command line option or something in the
$HOME/.exrc file.  In certain contexts, e.g. editing ASCII database files,
it stinks.  I particularly liked the message from the fellow who said that his
version of the vi source code deleted this "feature" by #ifdef SUICIDE
preprocessor directives.  (I have now found it, in the routine checkmodeline()
in ex_io.c.  Not the #ifdef SUICIDE directive, but rather the suicidal code.)

Dan

-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
	   go for it!  			allegra,ulysses,vax135}!ttrdc!levy