[comp.os.minix] Very good news for vi fans

rtregn@faui44.informatik.uni-erlangen.de (Robert Regn) (09/23/88)

In  <350@ucrmath.UUCP>  pascal@ucrmath.UUCP (Freeman Pascal) writes:

>While attempting to port stevie to MINIX /usr/lib/opt have me a very
>strange error...
>
>        /usr/lib/opt:  error on line 205(%*s): redefined symbole .0
>
>It occured when I was compiling search.c.  Anyone have any ideas what
>this means and how to fix it???  How do you even track down this error?


Stevie was posted in comp.sources.unix on june.   (It is a good subset of vi,
only tricky visual commands and many 'ex' commands are missed)

Meantime i have splitted search.c many times and found the problem.
It was a 'internal static declaration of a procedure'
Above this fix is listed and other bugfixes   
Stevie uses system V ioctl, which is also modified for minix (Ver. 7)
Some changes are included by ifdef so you must define MINIX.

If you see the changing in search.c at line 92, you could think i have
improved efficiency. That's not the reason for it. If i call strsave
unconditionally, then -!- the string received by strsave is NOT the
same as the string given in the call of strsave !! The first two chars are
changed. So the 'n' command wasn't working. I think, this is a bug in
the minix compiler.

Remaining problems are:
   scrolling (because minix tty don't support all ansi escapes)
	slow - for ^E the full screen is updated
	probably stevie can improved to clever use the existing features
	( ESC M  for ^U )
   search with '^' (don't know why)
   cursor keys don't work - they generate three chars beginning with ESC
	- stevie expect one char  (keymap.h)
   the u  (undo) works only after a r command - Tony Andrews is asked to
	improve that.
   dW works as dw
   editing an empty file hangs stevie (don't know why)
   the possible file size is limited
	(about 24700 Bytes, a little more than mined).
   editing an empty file hangs stevie

If Stevie writes the file back, it renames the existing to .bak and creates
it new. After successfully writing the .bak is deleted.
Fatal consequence: A write protected file will overwritten if you have
w-permission on directory.
Because of this i have suppressed the renaming if there is no write
acess for the file. Also the [Read only] message is displayed.
Permissions are restored on the new file and (if possible,) the owner.

For the :e  command i have added handling of %, but only one % is expanded.

Stevie can work with a tag file!! But knows anyone a PD ctags program?
For linking you must increase the stack of asld (45000).
My system for the test was 1.3a.


------------------------------------------ cut ------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  cmdline.c.diff fileio.c.diff keymap.h.diff search.c.diff
#   term.h.diff unix.c.diff
# Wrapped by rtregn@faui32 on Fri Sep 23 15:32:08 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'cmdline.c.diff' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cmdline.c.diff'\"
else
echo shar: Extracting \"'cmdline.c.diff'\" \(1137 characters\)
sed "s/^X//" >'cmdline.c.diff' <<'END_OF_FILE'
X4a5
X>  * further   modifications by:  Robert Regn	   rtregn@faui32.uucp
X158d158
X< 				UNCHANGED;
X273c273
X< 	if ( strcmp(cmd,"set")==0 ) {
X---
X> 	if ( strncmp(cmd,"set", 2)==0 ) {
X480a481,483
X> 		if (altfile)
X> 			free(altfile);
X> 		altfile = strsave(arg);
X503a507,523
X> 		} else
X> 		  if (strchr(arg, '%')) {
X> 			char *s, *buf=alloc(strlen(arg)+strlen(Filename));
X> 			if (Filename == NULL) {
X> 				emsg("No filename");
X> 				return FALSE;
X> 			}
X> 			s = strchr(arg, '%');
X> 			*s = 0;
X> 			strcpy (buf, arg);
X> 			strcat (buf, Filename);
X> 			strcat (buf, s+1);
X> 			if (altfile)		/* I'm not shure if it is ok */
X> 				free(altfile);
X> 			altfile = Filename;
X> 			altline = cntllines(Filemem, Curschar);
X> 			Filename = buf;
X504a525,526
X> 			if (altfile)		/* I'm not shure if it is ok */
X> 				free(altfile);
X530a553
X> #ifndef MINIX
X548a572
X> #endif
X555d578
X< 	int n;
X608c631
X< 	} while (c != '\r' && c != '\n');
X---
X> 	} while (c != '\r' && c != '\n' && c != ' ' && c != ':');
X610c633,638
X< 	screenclear();
X---
X> 	if ( c == ':') {				/* this can vi too  */
X> 		outstr("\n");
X> 		readcmdline(c, NULL);
X> 	}
X> 	else
X> 		screenclear();
END_OF_FILE
if test 1137 -ne `wc -c <'cmdline.c.diff'`; then
    echo shar: \"'cmdline.c.diff'\" unpacked with wrong size!
fi
# end of 'cmdline.c.diff'
fi
if test -f 'fileio.c.diff' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'fileio.c.diff'\"
else
echo shar: Extracting \"'fileio.c.diff'\" \(1423 characters\)
sed "s/^X//" >'fileio.c.diff' <<'END_OF_FILE'
X4a5
X>  * further   modifications by:  Robert Regn	   rtregn@faui32.uucp
X8a10
X> #include <stat.h>
X31a34
X> static char rdonly=0;
X57c60,62
X< 	filemess("");
X---
X> 	rdonly = (access(fname, 2) != 0);
X> 	filemess( rdonly ? "[Read only]" : "");
X> 	outstr("rdonly : ");
X82c87,89
X< 				exit(1);
X---
X> 				{outstr("\n\r");
X> 				windexit(1);
X> 				}
X118c125
X< 		p="\"%s\" %d lines, %ld characters (%d un-printable))";
X---
X> 		p="\"%s\" %s %d lines, %ld characters (%d un-printable))";
X120c127
X< 		p="\"%s\" %d lines, %ld characters";
X---
X> 		p="\"%s\" %s %d lines, %ld characters";
X122c129
X< 	sprintf(buff, p, fname, linecnt, nchars, unprint);
X---
X> 	sprintf(buff, p, fname, rdonly ? "[Read only]" : "", linecnt, nchars, unprint);
X146a154,155
X> 	struct stat sbuf;
X> 	char newfile=1;
X149a159,160
X> 	if (stat(fname, &sbuf)!= 0)	/* save mode of file for creating */
X> 		newfile = 1;
X166c177,178
X< 	rename(fname, backup);
X---
X> 	/* skipping rename avoids overwriting  R/O files by creating a new */
X> 	/* also save link structure 			R. Regn*/
X167a180,181
X> 	if (!rdonly && sbuf.st_nlink == 1)
X> 		rename(fname, backup);
X168a183
X> 
X172c187,189
X< 		emsg("Can't open file for writing!");
X---
X> 		if (rdonly)
X> 			emsg("File is Read only");
X> 		else 	emsg("Permission denied");
X175a193,196
X> 	if (!rdonly && !newfile)	/* restore mode (and owner) properly */
X> 		{chmod(fname, sbuf.st_mode&04777);
X> 		 chown (sbuf.st_uid, sbuf.st_gid);
X> 		}
END_OF_FILE
if test 1423 -ne `wc -c <'fileio.c.diff'`; then
    echo shar: \"'fileio.c.diff'\" unpacked with wrong size!
fi
# end of 'fileio.c.diff'
fi
if test -f 'keymap.h.diff' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'keymap.h.diff'\"
else
echo shar: Extracting \"'keymap.h.diff'\" \(111 characters\)
sed "s/^X//" >'keymap.h.diff' <<'END_OF_FILE'
X23c23
X< #define	K_CGRAVE	0x88	/* control grave accent */
X---
X> #define	K_CGRAVE	036	/* control grave accent */
END_OF_FILE
if test 111 -ne `wc -c <'keymap.h.diff'`; then
    echo shar: \"'keymap.h.diff'\" unpacked with wrong size!
fi
# end of 'keymap.h.diff'
fi
if test -f 'search.c.diff' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'search.c.diff'\"
else
echo shar: Extracting \"'search.c.diff'\" \(333 characters\)
sed "s/^X//" >'search.c.diff' <<'END_OF_FILE'
X87c87,88
X< 	static LPTR *bcksearch(), *fwdsearch();
X---
X> 	/*static verursachte opt error */
X> 	LPTR *bcksearch(), *fwdsearch();
X90,92c91,95
X< 	if ( laststr != NULL )
X< 		free(laststr);
X< 	laststr = strsave(str);
X---
X> 	if (strcmp (laststr, str) != 0)
X> 	{	if ( laststr != NULL )
X> 			free(laststr);
X> 		laststr = strsave(str);
X> 	}
END_OF_FILE
if test 333 -ne `wc -c <'search.c.diff'`; then
    echo shar: \"'search.c.diff'\" unpacked with wrong size!
fi
# end of 'search.c.diff'
fi
if test -f 'term.h.diff' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'term.h.diff'\"
else
echo shar: Extracting \"'term.h.diff'\" \(694 characters\)
sed "s/^X//" >'term.h.diff' <<'END_OF_FILE'
X44,49c44,49
X< #define	T_EL	"\033[2K"	/* erase the entire current line */
X< #define	T_IL	"\033[L"	/* insert one line */
X< #define	T_DL	"\033[M"	/* delete one line */
X< #define	T_ED	"\033[2J"	/* erase display (may optionally home cursor) */
X< #define	T_SC	"\0337"		/* save the cursor position */
X< #define	T_RC	"\0338"		/* restore the cursor position */
X---
X> #define	T_EL	"\t\t\t\t\t\t\t\t\t\t\r"	/* erase the entire current line */
X> #define	T_IL	""	/* insert one line */
X> #define	T_DL	""	/* delete one line */
X> #define	T_ED	"\033[H\033[J"	/* erase display (may optionally home cursor) */
X> #define	T_SC	""		/* save the cursor position */
X> #define	T_RC	""		/* restore the cursor position */
END_OF_FILE
if test 694 -ne `wc -c <'term.h.diff'`; then
    echo shar: \"'term.h.diff'\" unpacked with wrong size!
fi
# end of 'term.h.diff'
fi
if test -f 'unix.c.diff' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'unix.c.diff'\"
else
echo shar: Extracting \"'unix.c.diff'\" \(1504 characters\)
sed "s/^X//" >'unix.c.diff' <<'END_OF_FILE'
X2a3
X>  * modifications by:  Robert Regn	   rtregn@faui32.uucp
X5a7,21
X> #ifdef MINIX
X> #include <sgtty.h>
X> 
X> char *strchr(s, c)
X> register char *s;
X> {
X> 	while (*s) {
X> 		if (*s == c)
X> 			return s;
X> 		s++;
X> 	}
X> 	return 0;
X> }
X> 
X> #else
X6a23
X> #endif
X94a112,114
X> #ifdef MINIX
X> static	struct	sgttyb	ostate;
X> #else
X95a116
X> #endif
X101a123,141
X> #ifdef MINIX
X> 	struct	sgttyb	nstate;
X> 
X> 	if ((term = getenv("TERM")) == NULL || strcmp(term, "minix") != 0) {
X> 		fprintf(stderr, "Invalid terminal type '%s'\n", term);
X> 		exit(1);
X> 	}
X> 	Columns = 80;
X> 	P(P_LI) = Rows = 24;
X> 
X> 	/*
X> 	 * Go into cbreak mode
X> 	 */
X> 	 ioctl(0, TIOCGETP, &ostate);
X> 	 nstate = ostate;
X> 	 nstate.sg_flags |= CBREAK;
X> 	 nstate.sg_flags &= ~ECHO;
X> 	 ioctl(0, TIOCSETP, &nstate);
X> #else
X119a160
X> #endif
X128a170,173
X> 	flushbuf();
X> #ifdef MINIX
X> 	ioctl(0, TIOCSETP, &ostate);
X> #else
X129a175
X> #endif
X132a179,211
X> 
X> #ifdef MINIX
X> void
X> doshell()
X> {
X> 	char	*sh, *getenv();
X> 	struct	sgttyb	nstate;
X> 
X> 	if ((sh = getenv("SHELL")) == NULL) {
X> 		sh = "/bin/sh";
X> 	}
X> 	gotocmd(TRUE, FALSE, 0);
X> 
X> 	switch (fork() ) {
X> 		case	0:	ioctl(0, TIOCSETP, &ostate);
X> 				write(1,"\n", 1);
X> 				execl(sh, "sh", "-i", 0);
X> 				write(1,"Exec failed", 11);
X> 				exit(1);
X> 
X> 		case	-1:	emsg("fork failed");
X> 				break;
X> 
X> 		default:	wait(0);
X> 				nstate = ostate;
X> 				nstate.sg_flags |= CBREAK;
X> 				nstate.sg_flags &= ~ECHO;
X> 				ioctl(0, TIOCSETP, &nstate);
X> 	}
X> 
X> 	wait_return();
X> }
X> #endif
END_OF_FILE
if test 1504 -ne `wc -c <'unix.c.diff'`; then
    echo shar: \"'unix.c.diff'\" unpacked with wrong size!
fi
# end of 'unix.c.diff'
fi
echo shar: End of shell archive.
exit 0



						Robert Regn
						rtregn.faui32.uucp

frank@morgan.com (Frank Wortner) (10/04/88)

Robert Regn <rtregn@faui44.informatik.uni-erlangen.de> writes:

>Stevie can work with a tag file!! But knows anyone a PD ctags program?

The GNU Emacs support program "etags" probably can do the job.  It can
emulate "ctags" quite well.  The only possible problem with etags is the
usual one:  it might not fit into 64K of memory.  It's worth a try, though.

					Frank

alan@oetl.UUCP (Alan Strassberg) (10/05/88)

In article <4376@louie.udel.EDU> frank@morgan.com (Frank Wortner) writes:
>
>>Stevie can work with a tag file!! But knows anyone a PD ctags program?

	comp.sources.unix archives: Vol_3/ctags is there to use.

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Alan Strassberg		UUCP: ..!{pyramid,leadsv}!oetl!alan
work (408) 425-6126		alan@oetl   (alan@leadsv)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-