[comp.unix.microport] porting information for MicroEmacs 3.9

hedrick@athos.rutgers.edu (Charles Hedrick) (02/22/88)

The following information may be of some help for those of you
who are interested in bringing up MicroEmacs on Microport SV/AT.
See the README for more information on MicroEmacs.  You will
want to extract this archive somewhere that has a subdirectory
called diffs.  Similar information on JOVE will follow shortly,
after I've had more time to test it.  (JOVE had a few more
portability problems, all of which as far as I can tell are bugs
in the original.  However JOVE is definitely a more friendly
editor, if your files don't contain nulls and don't have long
lines.)

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	diffs/README
#	diffs/ansi.c.pch
#	diffs/display.c.pch
#	diffs/epath.h.pch
#	diffs/estruct.h.pch
#	diffs/file.c.pch
#	diffs/fileio.c.pch
#	diffs/input.c.pch
#	diffs/line.c.pch
#	diffs/lock.c.pch
#	diffs/makefile.pch
#	diffs/termio.c.pch
# This archive created: Sun Feb 21 16:53:35 1988
export PATH; PATH=/bin:$PATH
if test -f 'diffs/README'
then
	echo shar: will not over-write existing file "'diffs/README'"
else
cat << \SHAR_EOF > 'diffs/README'
Here are diffs for MicroEMACS 3.9e as I'm using it on the Microport. 
Note that almost none of these are really necessary to get it to run.  I
think if you set up the conditionals in estruct.h and the compile
options in Makefile, it would work as is, except for one thing: the
patch in termio seems to be necessary, or when you exit from the
program, your terminal is left in wierd states.  Note that I use only
the ansi driver, since I use this only from the console.  Presumably
termcap would work fine as well.  (I've used the termcap mode in
JOVE and microGnu without any problems.)  More detailed comments are
included with each file.

Of all the "small" Emacses I prefer JOVE's user interface.  However
MicroEmacs 3.9e is now a reasonably complete Emacs, and has the large
advantage of being able to handle files with very long lines and (with
the patches herein) with nulls in them.  You can just about edit binary
files with this, except that it will tack a newline on the end.  About
all MicroEmacs is missing compared to JOVE is filename and command name
completion.  (However this is one of the more friendly features of
Emacs.) Also, MicroEmacs is somewhat smaller than JOVE.  It will run
under the small model, which JOVE will not, though I don't recommend
using the small model unless you like to restrict yourself to tiny
files. 

An older version, MicroEMACS 3.8b is available from the various
comp.sources.unix archive sites in volume 9 as v09i033 through 047.  It
is also available on SIMTEL20.ARPA as pd2:<unix.editors>.  On
j.cc.purdue.edu, one of the archive sites, there is a file
pub/microemacs.tar.Z, which has about the right creation date to be the
new version, though I'm not about to FTP 300Kb just to check it.  (Both
Simtel and j.cc.purdue.edu allow anonymous FTP.) I'm not sure where we
got 3.9e, but here is access information from the readme file. 

	MicroEMACS 3.9 is availible in a couple of different ways. 
First, it is availible via my bulletin board system..... 

	The Programmer's Room
	FIDO 201/2
	(317) 742-5533
	24 hours  300/1200 baud

	Also it should be online on the following BBS's:

	The Starship Trooper	Fido 201/1	(317) 423-2281	2400

	[These following two are open from 10pm till 5pm
				and only while Purdue is in session]
	The NightStaff		Fido 201/4	(317) 495-4270	1200
	The Access Violation	Fido 201/5	(317) 495-4270	9600

	There it is arranged as three MSDOS .ARC files, EMACSDOC.ARC
which contains the documentation and command files, EMACSSRC.ARC which
contains the sources and the UNIX Makefile, and EMACSEXE.EXE which
contains the MSDOS executables.  Also all the various executables are
available individually.


ANSI.C:  I tend to use ansi-24, so I have decreased the screen size to 24.
Originally ANSI mode only worked with terminal type vt100.  I now allow
it also for any terminal type beginning with "ansi", since that is the
normal default for the Uport console.

DISPLAY.C: A bunch of random hacks: Implement direct memory-mapped
screen I/O, in case you like to have the ultimate in speed.  The Uport
ansi driver is actually fairly fast, so you may not want to do this. 
This feature is controlled by MEMMAP in estruct.h.  If you use this, you
had better arrange for your system startup to run shmcreate, so that the
program has access to the screen map.  /etc/rc.d/shm.rc as distributed
by Uport has an appropriate line in it commented "ega low res".  I think
this code will work with either the monochrome adapter or the EGA
adapter.  The patch at line 175/184 is from posted patches to make the
large model work.  I suspect that is really for a bug in the Microsoft
compiler and would be unnecessary for Uport.
  
FILE.C: Changed the calling convention for ffgetline to make it return
the line size.  This means we don't have to call strlen.  This both
speeds up reading files and allows them to contain nulls.  Replacing
the lputc loop with bcopy is strictly for performance, and is probably
not necessary. (I was trying to fix a slowdown that later turned out
to be due to a bad system malloc.)  Added code to keep the previous
version of a file as foo.BAK.

FILEIO.C: Change to ffgetline argument needed by patch above.  Also
more supposed speedups that are probalby not really needed.  Turning
strncpy into bcopy is needed to allow nulls to be read.
  
INPUT.C:  In the keyboard input routing, add special code that
turns the ALT key into a meta key, and allows you to define the
special function keys in .emacsrc as FNx

LINE.C: The first looks like a typo.  The second is another patch
to make the large model work that is probably only necessary for
the Microsoft MS-DOS compiler.
  
LOCK.C: I don't use lock.  I think these changes were added at Rutgers
to make the locking convention compatible with Gnu Emacs's.  I don't
recommend adding this.

TERMIO.C: This is a critical one.  It is necessary to prevent
leaving the terminal in a wierd state when you exit.

EPATH.H: Where you put files is up to you.

ESTRUCT.H: Various configuration options.  You don't have to use the
same ones I do, but at least this shows you one configuration that
works.

MAKEFILE: Note by the way that the optimizer blows up on one of the
modules (I think it's region.c, but I'm not sure.  cc just coredumps.
Obviously that module gets recompiled without -O.  I have
removed the modules for other machines, e.g. dg10, tipc, etc.  This
speeds up linking slightly.  However if you decide to use termcap
you'll need to put back the appropriate module.  I don't understand
why the original had -lc in the final load command.  libc is
searched automatically.  This just slows down loading.  Note that
I include -lxmalloc.  This is my tuned malloc, which was just
posted.
SHAR_EOF
fi # end of overwriting check
if test -f 'diffs/ansi.c.pch'
then
	echo shar: will not over-write existing file "'diffs/ansi.c.pch'"
else
cat << \SHAR_EOF > 'diffs/ansi.c.pch'
*** ../original/ansi.c	Sun Feb  7 02:59:58 1988
--- ansi.c	Sun Feb  7 22:16:58 1988
***************
*** 16,22
  #define NROW    23                      /* Screen size.                 */
  #define NCOL    77                      /* Edit if you want to.         */
  #else
! #define NROW    25                      /* Screen size.                 */
  #define NCOL    80                      /* Edit if you want to.         */
  #endif
  #define	NPAUSE	100			/* # times thru update to pause */

--- 16,22 -----
  #define NROW    23                      /* Screen size.                 */
  #define NCOL    77                      /* Edit if you want to.         */
  #else
! #define NROW    24                      /* Screen size.                 */
  #define NCOL    80                      /* Edit if you want to.         */
  #endif
  #define	NPAUSE	100			/* # times thru update to pause */
***************
*** 224,230
                  puts("Shell variable TERM not defined!");
                  exit(1);
          }
!         if (strcmp(cp, "vt100") != 0) {
                  puts("Terminal type not 'vt100'!");
                  exit(1);
          }

--- 224,230 -----
                  puts("Shell variable TERM not defined!");
                  exit(1);
          }
!         if (strcmp(cp, "vt100") != 0 && strncmp(cp, "ansi", 4) != 0) {
                  puts("Terminal type not 'vt100'!");
                  exit(1);
          }
SHAR_EOF
fi # end of overwriting check
if test -f 'diffs/display.c.pch'
then
	echo shar: will not over-write existing file "'diffs/display.c.pch'"
else
cat << \SHAR_EOF > 'diffs/display.c.pch'
*** ../original/display.c	Sun Feb  7 03:00:31 1988
--- display.c	Sun Feb 21 13:08:48 1988
***************
*** 31,36
  #if	MEMMAP == 0
  VIDEO   **pscreen;                      /* Physical screen. */
  #endif
  
  /*
   * Initialize the data structures used by the display code. The edge vectors

--- 31,39 -----
  #if	MEMMAP == 0
  VIDEO   **pscreen;                      /* Physical screen. */
  #endif
+ #if MEMMAP && UPORT
+ char *shmaddr;
+ #endif
  
  /*
   * Initialize the data structures used by the display code. The edge vectors
***************
*** 44,49
      register int i;
      register VIDEO *vp;
      char *malloc();
  
      TTopen();		/* open the screen */
      TTkopen();		/* open the keyboard */

--- 47,55 -----
      register int i;
      register VIDEO *vp;
      char *malloc();
+ #if MEMMAP && UPORT
+     extern char *shmat();
+     int shmid = shmget(0xb0000, 32768, 0);
  
      shmaddr = shmat (shmid, (char *)0);
  #endif
***************
*** 45,50
      register VIDEO *vp;
      char *malloc();
  
      TTopen();		/* open the screen */
      TTkopen();		/* open the keyboard */
      TTrev(FALSE);

--- 51,59 -----
      extern char *shmat();
      int shmid = shmget(0xb0000, 32768, 0);
  
+     shmaddr = shmat (shmid, (char *)0);
+ #endif
+ 
      TTopen();		/* open the screen */
      TTkopen();		/* open the keyboard */
      TTrev(FALSE);
***************
*** 172,179
      register VIDEO      *vp;
  
      vp = vscreen[vtrow];
!     while (vtcol < term.t_ncol)
!         vp->v_text[vtcol++] = ' ';
  }
  
  /* upscreen:	user routine to force a screen update

--- 181,188 -----
      register VIDEO      *vp;
  
      vp = vscreen[vtrow];
! 	for (;vtcol < term.t_ncol; vtcol++)
!         vp->v_text[vtcol] = ' ';
  }
  
  /* upscreen:	user routine to force a screen update
***************
*** 579,584
  	vp1->v_flag &= ~(VFCHG | VFCOL);	/* flag this line as changed */
  
  }
  
  #else
  

--- 588,617 -----
  	vp1->v_flag &= ~(VFCHG | VFCOL);	/* flag this line as changed */
  
  }
+ 
+ #if UPORT
+ /*
+  * There is no special module for Microport SysV, as this is the only
+  * system-dependent code for it.
+  */
+ 
+ scwrite(row, cp1, fg, bg)
+   int row, fg, bg;
+   register char *cp1;
+ {
+     register char *cp2;
+     register int nch;
+ 
+     cp2 = shmaddr + (160 * row);
+     for (nch = 0; nch < term.t_ncol; nch++) {
+ 	*cp2 = *cp1;
+ 	cp2++;
+ 	cp1++;
+ 	*cp2 = bg << 4 | fg;
+ 	cp2++;
+     }	
+ }
+ #endif
  
  #else
  
SHAR_EOF
fi # end of overwriting check
if test -f 'diffs/epath.h.pch'
then
	echo shar: will not over-write existing file "'diffs/epath.h.pch'"
else
cat << \SHAR_EOF > 'diffs/epath.h.pch'
*** ../original/epath.h	Sun Feb  7 03:01:30 1988
--- epath.h	Sun Feb  7 13:53:09 1988
***************
*** 57,63
  #if	V7 | BSD | USG
  {
  	".emacsrc",
! 	"emacs.hlp",
  	"/usr/local/",
  	"/usr/lib/",
  	""

--- 57,63 -----
  #if	V7 | BSD | USG
  {
  	".emacsrc",
! 	"/usr/local/lib/emacs.hlp",
  	"/usr/local/",
  	"/usr/lib/",
  	""
SHAR_EOF
fi # end of overwriting check
if test -f 'diffs/estruct.h.pch'
then
	echo shar: will not over-write existing file "'diffs/estruct.h.pch'"
else
cat << \SHAR_EOF > 'diffs/estruct.h.pch'
*** ../original/estruct.h	Sun Feb  7 03:00:54 1988
--- estruct.h	Sun Feb 21 12:40:38 1988
***************
*** 40,46
  
  #define AMIGA   0                       /* AmigaDOS			*/
  #define ST520   0                       /* ST520, TOS                   */
! #define MSDOS   1                       /* MS-DOS                       */
  #define V7      0                       /* V7 UNIX or Coherent or BSD4.2*/
  #define	BSD	0			/* UNIX BSD 4.2	and ULTRIX	*/
  #define	USG	0			/* UNIX system V		*/

--- 40,46 -----
  
  #define AMIGA   0                       /* AmigaDOS			*/
  #define ST520   0                       /* ST520, TOS                   */
! #define MSDOS   0                       /* MS-DOS                       */
  #define V7      0                       /* V7 UNIX or Coherent or BSD4.2*/
  #define	BSD	0			/* UNIX BSD 4.2	and ULTRIX	*/
  #define	USG	1			/* UNIX system V		*/
***************
*** 43,49
  #define MSDOS   1                       /* MS-DOS                       */
  #define V7      0                       /* V7 UNIX or Coherent or BSD4.2*/
  #define	BSD	0			/* UNIX BSD 4.2	and ULTRIX	*/
! #define	USG	0			/* UNIX system V		*/
  #define VMS     0                       /* VAX/VMS                      */
  #define CPM     0                       /* CP/M-86                      */
  #define	FINDER	0			/* Macintosh OS			*/

--- 43,49 -----
  #define MSDOS   0                       /* MS-DOS                       */
  #define V7      0                       /* V7 UNIX or Coherent or BSD4.2*/
  #define	BSD	0			/* UNIX BSD 4.2	and ULTRIX	*/
! #define	USG	1			/* UNIX system V		*/
  #define VMS     0                       /* VAX/VMS                      */
  #define CPM     0                       /* CP/M-86                      */
  #define	FINDER	0			/* Macintosh OS			*/
***************
*** 47,52
  #define VMS     0                       /* VAX/VMS                      */
  #define CPM     0                       /* CP/M-86                      */
  #define	FINDER	0			/* Macintosh OS			*/
  
  /*	Compiler definitions			*/
  #define	UNIX	0	/* a random UNIX compiler */

--- 47,53 -----
  #define VMS     0                       /* VAX/VMS                      */
  #define CPM     0                       /* CP/M-86                      */
  #define	FINDER	0			/* Macintosh OS			*/
+ #define UPORT	1			/* Microport SV/AT screen & kybd*/
  
  /*	Compiler definitions			*/
  #define	UNIX	1	/* a random UNIX compiler */
***************
*** 49,55
  #define	FINDER	0			/* Macintosh OS			*/
  
  /*	Compiler definitions			*/
! #define	UNIX	0	/* a random UNIX compiler */
  #define MWC	0	/* Marc Williams C */
  #define	LATTICE	0	/* Lattice 2.14 thruough 3.0 compilers */
  #define	AZTEC	1	/* Aztec C 3.20e */

--- 50,56 -----
  #define UPORT	1			/* Microport SV/AT screen & kybd*/
  
  /*	Compiler definitions			*/
! #define	UNIX	1	/* a random UNIX compiler */
  #define MWC	0	/* Marc Williams C */
  #define	LATTICE	0	/* Lattice 2.14 thruough 3.0 compilers */
  #define	AZTEC	0	/* Aztec C 3.20e */
***************
*** 52,58
  #define	UNIX	0	/* a random UNIX compiler */
  #define MWC	0	/* Marc Williams C */
  #define	LATTICE	0	/* Lattice 2.14 thruough 3.0 compilers */
! #define	AZTEC	1	/* Aztec C 3.20e */
  #define	MSC	0	/* MicroSoft C compile version 3 & 4 */
  #define	TURBO	0	/* Turbo C/MSDOS */
  

--- 53,59 -----
  #define	UNIX	1	/* a random UNIX compiler */
  #define MWC	0	/* Marc Williams C */
  #define	LATTICE	0	/* Lattice 2.14 thruough 3.0 compilers */
! #define	AZTEC	0	/* Aztec C 3.20e */
  #define	MSC	0	/* MicroSoft C compile version 3 & 4 */
  #define	TURBO	0	/* Turbo C/MSDOS */
  
***************
*** 67,73
  
  /*	Terminal Output definitions		*/
  
! #define ANSI    0			/* ANSI escape sequences	*/
  #define	HP150	0			/* HP150 screen driver		*/
  #define	HP110	0			/* HP110 screen driver		*/
  #define	VMSVT	0			/* various VMS terminal entries	*/

--- 68,74 -----
  
  /*	Terminal Output definitions		*/
  
! #define ANSI    1			/* ANSI escape sequences	*/
  #define	HP150	0			/* HP150 screen driver		*/
  #define	HP110	0			/* HP110 screen driver		*/
  #define	VMSVT	0			/* various VMS terminal entries	*/
***************
*** 74,80
  #define VT52    0                       /* VT52 terminal (Zenith).      */
  #define RAINBOW 0                       /* Use Rainbow fast video.      */
  #define TERMCAP 0                       /* Use TERMCAP                  */
! #define	IBMPC	1			/* IBM-PC CGA/MONO/EGA driver	*/
  #define	DG10	0			/* Data General system/10	*/
  #define	TIPC	0			/* TI Profesional PC driver	*/
  #define	Z309	0			/* Zenith 100 PC family	driver	*/

--- 75,81 -----
  #define VT52    0                       /* VT52 terminal (Zenith).      */
  #define RAINBOW 0                       /* Use Rainbow fast video.      */
  #define TERMCAP 0                       /* Use TERMCAP                  */
! #define	IBMPC	0			/* IBM-PC CGA/MONO/EGA driver	*/
  #define	DG10	0			/* Data General system/10	*/
  #define	TIPC	0			/* TI Profesional PC driver	*/
  #define	Z309	0			/* Zenith 100 PC family	driver	*/
***************
*** 84,90
  /*	Configuration options	*/
  
  #define CVMVAS  1	/* arguments to page forward/back in pages	*/
! #define	CLRMSG	0	/* space clears the message line with no insert	*/
  #define	CFENCE	1	/* fench matching in CMODE			*/
  #define	TYPEAH	1	/* type ahead causes update to be skipped	*/
  #define DEBUGM	1	/* $debug triggers macro debugging		*/

--- 85,91 -----
  /*	Configuration options	*/
  
  #define CVMVAS  1	/* arguments to page forward/back in pages	*/
! #define	CLRMSG	1	/* space clears the message line with no insert	*/
  #define	CFENCE	1	/* fench matching in CMODE			*/
  #define	TYPEAH	1	/* type ahead causes update to be skipped	*/
  #define DEBUGM	1	/* $debug triggers macro debugging		*/
***************
*** 105,111
  #define MAGIC	1	/* include regular expression matching?		*/
  #define	AEDIT	1	/* advanced editing options: en/detabbing	*/
  #define	PROC	1	/* named procedures				*/
! #define	CLEAN	0	/* de-alloc memory on exit			*/
  #define	CALLED	0	/* is emacs a called subroutine? or stand alone */
  
  #define ASCII	1	/* always using ASCII char sequences for now	*/

--- 106,112 -----
  #define MAGIC	1	/* include regular expression matching?		*/
  #define	AEDIT	1	/* advanced editing options: en/detabbing	*/
  #define	PROC	1	/* named procedures				*/
! #define	CLEAN	1	/* de-alloc memory on exit			*/
  #define	CALLED	0	/* is emacs a called subroutine? or stand alone */
  
  #define ASCII	1	/* always using ASCII char sequences for now	*/
***************
*** 205,211
  
  /*	define some ability flags */
  
! #if	IBMPC | Z309
  #define	MEMMAP	1
  #else
  #define	MEMMAP	0

--- 206,212 -----
  
  /*	define some ability flags */
  
! #if	IBMPC | Z309 | (UPORT & ANSI)
  #define	MEMMAP	1
  #else
  #define	MEMMAP	0
***************
*** 429,434
  #define BFINVS  0x01                    /* Internal invisable buffer    */
  #define BFCHG   0x02                    /* Changed since last write     */
  #define	BFTRUNC	0x04			/* buffer was truncated when read */
  
  /*	mode flags	*/
  #define	NUMMODES	9		/* # of defined modes		*/

--- 430,436 -----
  #define BFINVS  0x01                    /* Internal invisable buffer    */
  #define BFCHG   0x02                    /* Changed since last write     */
  #define	BFTRUNC	0x04			/* buffer was truncated when read */
+ #define BFSAVED1 0x08			/* buffer has been saved once */
  
  /*	mode flags	*/
  #define	NUMMODES	9		/* # of defined modes		*/
SHAR_EOF
fi # end of overwriting check
if test -f 'diffs/file.c.pch'
then
	echo shar: will not over-write existing file "'diffs/file.c.pch'"
else
cat << \SHAR_EOF > 'diffs/file.c.pch'
*** ../original/file.c	Sun Feb  7 03:00:38 1988
--- file.c	Sun Feb 21 13:11:36 1988
***************
*** 9,14
  #include        <stdio.h>
  #include	"estruct.h"
  #include        "edef.h"
  
  /*
   * Read a file into the current

--- 9,15 -----
  #include        <stdio.h>
  #include	"estruct.h"
  #include        "edef.h"
+ #include	<errno.h>
  
  /*
   * Read a file into the current
***************
*** 243,250
          mlwrite("[Reading file]");
          nline = 0;
  	lflag = FALSE;
!         while ((s=ffgetline()) == FIOSUC) {
!                 nbytes = strlen(fline);
                  if ((lp1=lalloc(nbytes)) == NULL) {
                          s = FIOMEM;             /* Keep message on the  */
                          break;                  /* display.             */

--- 244,250 -----
          mlwrite("[Reading file]");
          nline = 0;
  	lflag = FALSE;
!         while ((s=ffgetline(&nbytes)) == FIOSUC) {
                  if ((lp1=lalloc(nbytes)) == NULL) {
                          s = FIOMEM;             /* Keep message on the  */
                          break;                  /* display.             */
***************
*** 254,261
                  lp1->l_fp = curbp->b_linep;
                  lp1->l_bp = lp2;
                  curbp->b_linep->l_bp = lp1;
!                 for (i=0; i<nbytes; ++i)
!                         lputc(lp1, i, fline[i]);
                  ++nline;
          }
          ffclose();                              /* Ignore errors.       */

--- 254,264 -----
                  lp1->l_fp = curbp->b_linep;
                  lp1->l_bp = lp2;
                  curbp->b_linep->l_bp = lp1;
! /*
!  *               for (i=0; i<nbytes; ++i)
!  *                       lputc(lp1, i, fline[i]);
!  */
! 		bcopy (fline, lp1->l_text, nbytes);
                  ++nline;
          }
          ffclose();                              /* Ignore errors.       */
***************
*** 291,296
          return (TRUE);
  }
  
  /*
   * Take a file name, and from it
   * fabricate a buffer name. This routine knows

--- 294,308 -----
          return (TRUE);
  }
  
+ bcopy(from,to,count)
+ register char *from;
+ register char *to;
+ register int count;
+ {
+ while (count-- > 0)
+   *to++ = *from++;
+ }
+ 
  /*
   * Take a file name, and from it
   * fabricate a buffer name. This routine knows
***************
*** 459,464
  	if (s != TRUE)
  		return(s);
  #endif
  	/* turn off ALL keyboard translation in case we get a dos error */
  	TTkclose();
  

--- 471,536 -----
  	if (s != TRUE)
  		return(s);
  #endif
+ /*
+  * This code could certainly be made to work on other systems, but
+  * it would need slight generalization and testing.  So for the
+  * moment it is on SYS V only.
+  */
+ #if	USG
+         if ((curbp->b_flag&BFSAVED1) == 0) {        /* Return, no changes.  */
+ 		char *strrchr();
+ 		char newname[256];
+ 		char *cp1;
+ 
+ 	        curbp->b_flag |= BFSAVED1;  /* we have now saved it once */
+ 	        /* make name foo.BAK.  dratted SysV has max name size of 14 */
+ 		strcpy(newname,fn);
+ 
+ 		/* first get last component of name into cp1 */
+ 		cp1 = strrchr(newname,'/');		
+ 		if (cp1)
+ 			cp1++;
+ 		else
+ 			cp1 = newname;
+ 		if (strlen(cp1) <= (14 - 4))  /* short, can append */
+ 			strcat(cp1, ".BAK");
+ 		else if (strlen(cp1) <= (14 - 2))
+ 			strcat(cp1, ".B");  /* sort of ugly, but it works */
+ 		else 
+ 			strcpy(cp1+12, ".B");  /* have to truncate */
+ 
+ 		/* now rename the original to the backup name */
+ 		if (link (fn, newname) != 0) {
+ 		  if (errno == ENOENT)  /* no original file ??? */
+ 		    goto nobackup;
+ 		  if (errno == EEXIST) { /* backup already exists */
+ 		    if (unlink(newname) != 0) {
+ 		      if (mlyesno("Unable to remove old backup..continue") == FALSE) {
+ 			mlwrite("[Aborted]");
+ 			return(FALSE);
+ 		      }
+ 		      goto nobackup;
+ 		    }
+ 		    else if (link (fn, newname) == 0)  /* rid of old: again? */
+ 		      errno = 0;  /* OK */
+ 		  }
+ 		  if (errno) { /* any other serious error */
+ 		    if (mlyesno("Unable to make backup..continue") == FALSE) {
+ 		      mlwrite("[Aborted]");
+ 		      return(FALSE);
+ 		    }
+ 		    goto nobackup;
+ 		  }
+ 		}
+ 		if (unlink (fn) != 0)
+ 		  if (mlyesno("Unable to make backup..continue") == FALSE) {
+ 		    mlwrite("[Aborted]");
+ 		    return(FALSE);
+ 		  }
+ 	nobackup: ;
+ 	}
+ #endif
+ 
  	/* turn off ALL keyboard translation in case we get a dos error */
  	TTkclose();
  
***************
*** 567,574
  
          nline = 0;
  	lflag = FALSE;
!         while ((s=ffgetline()) == FIOSUC) {
!                 nbytes = strlen(fline);
                  if ((lp1=lalloc(nbytes)) == NULL) {
                          s = FIOMEM;             /* Keep message on the  */
                          break;                  /* display.             */

--- 639,645 -----
  
          nline = 0;
  	lflag = FALSE;
!         while ((s=ffgetline(&nbytes)) == FIOSUC) {
                  if ((lp1=lalloc(nbytes)) == NULL) {
                          s = FIOMEM;             /* Keep message on the  */
                          break;                  /* display.             */
SHAR_EOF
fi # end of overwriting check
if test -f 'diffs/fileio.c.pch'
then
	echo shar: will not over-write existing file "'diffs/fileio.c.pch'"
else
cat << \SHAR_EOF > 'diffs/fileio.c.pch'
*** ../original/fileio.c	Sun Feb  7 03:00:38 1988
--- fileio.c	Sat Feb 13 01:22:32 1988
***************
*** 115,122
   * at the end of the file that don't have a newline present. Check for I/O
   * errors too. Return status.
   */
! ffgetline()
! 
  {
          register int c;		/* current character read */
          register int i;		/* current index into fline */

--- 115,122 -----
   * at the end of the file that don't have a newline present. Check for I/O
   * errors too. Return status.
   */
! ffgetline(retsize)
! int *retsize;
  {
          register int c;		/* current character read */
          register int i;		/* current index into fline */
***************
*** 127,137
  		return(FIOEOF);
  
  	/* dump fline if it ended up too big */
! 	if (flen > NSTRING) {
! 		free(fline);
! 		fline = NULL;
! 	}
! 
  	/* if we don't have an fline, allocate one */
  	if (fline == NULL)
  		if ((fline = malloc(flen = NSTRING)) == NULL)

--- 127,141 -----
  		return(FIOEOF);
  
  	/* dump fline if it ended up too big */
! /* This is sort of questionable.  If we have a file with one long
!  * line, we want to dump the buffer the next time, but if it has
!  * many long lines, this will lose big.
!  *
!  *	if (flen > NSTRING) {
!  *		free(fline);
!  *		fline = NULL;
!  *	}
!  */
  	/* if we don't have an fline, allocate one */
  	if (fline == NULL)
  		if ((fline = malloc(flen = NSTRING)) == NULL)
***************
*** 139,145
  
  	/* read the line in */
          i = 0;
!         while ((c = fgetc(ffp)) != EOF && c != '\n') {
                  fline[i++] = c;
  		/* if it's longer, get more room */
                  if (i >= flen) {

--- 143,149 -----
  
  	/* read the line in */
          i = 0;
!         while ((c = getc(ffp)) != EOF && c != '\n') {
                  fline[i++] = c;
  		/* if it's longer, get more room */
                  if (i >= flen) {
***************
*** 145,151
                  if (i >= flen) {
                  	if ((tmpline = malloc(flen+NSTRING)) == NULL)
                  		return(FIOMEM);
!                 	strncpy(tmpline, fline, flen);
                  	flen += NSTRING;
                  	free(fline);
                  	fline = tmpline;

--- 149,155 -----
                  if (i >= flen) {
                  	if ((tmpline = malloc(flen+NSTRING)) == NULL)
                  		return(FIOMEM);
!                 	bcopy(fline, tmpline, flen);
                  	flen += NSTRING;
                  	free(fline);
                  	fline = tmpline;
***************
*** 176,181
  	if (cryptflag)
  		crypt(fline, strlen(fline));
  #endif
          return(FIOSUC);
  }
  

--- 180,186 -----
  	if (cryptflag)
  		crypt(fline, strlen(fline));
  #endif
+ 	*retsize = i;
          return(FIOSUC);
  }
  
SHAR_EOF
fi # end of overwriting check
if test -f 'diffs/input.c.pch'
then
	echo shar: will not over-write existing file "'diffs/input.c.pch'"
else
cat << \SHAR_EOF > 'diffs/input.c.pch'
*** ../original/input.c	Sun Feb  7 03:00:41 1988
--- input.c	Sun Feb 21 12:36:59 1988
***************
*** 357,362
  	if (c == metac) {
  #endif
  		c = get1key();
  	        if (islower(c))		/* Force to upper */
          	        c ^= DIFCASE;
  	        if (c>=0x00 && c<=0x1F)		/* control key */

--- 357,370 -----
  	if (c == metac) {
  #endif
  		c = get1key();
+ #if	UPORT
+ 		if (c == 'N')   /* ALT key makes ESC N thing */
+ 			c = get1key();
+ 		else if (c == '[' || c == 'O') {
+ 			c = get1key();
+ 			return(SPEC | c);
+ 		}
+ #endif
  	        if (islower(c))		/* Force to upper */
          	        c ^= DIFCASE;
  	        if (c>=0x00 && c<=0x1F)		/* control key */
SHAR_EOF
fi # end of overwriting check
if test -f 'diffs/line.c.pch'
then
	echo shar: will not over-write existing file "'diffs/line.c.pch'"
else
cat << \SHAR_EOF > 'diffs/line.c.pch'
*** ../original/line.c	Sun Feb  7 03:00:45 1988
--- line.c	Sun Feb  7 21:16:19 1988
***************
*** 30,36
  
  {
  	register LINE	*lp;
! 	register int	size;
  	char *malloc();
  
  	size = (used+NBLOCK-1) & ~(NBLOCK-1);

--- 30,36 -----
  
  {
  	register LINE	*lp;
! 	register int size;
  	char *malloc();
  
  	size = (used+NBLOCK-1) & ~(NBLOCK-1);
***************
*** 596,602
  	}
  
  	/* and now insert the character */
! 	kbufp->d_chunk[kused++] = c;
  	return(TRUE);
  }
  

--- 596,603 -----
  	}
  
  	/* and now insert the character */
! 	kbufp->d_chunk[kused] = c;
! 	kused++;
  	return(TRUE);
  }
  
SHAR_EOF
fi # end of overwriting check
if test -f 'diffs/lock.c.pch'
then
	echo shar: will not over-write existing file "'diffs/lock.c.pch'"
else
cat << \SHAR_EOF > 'diffs/lock.c.pch'
*** ../original/lock.c	Sun Feb  7 03:01:29 1988
--- lock.c	Fri Feb 12 03:03:55 1988
***************
*** 3,8
  								*/
  
  #include <stdio.h>
  #include "estruct.h"
  #include "edef.h"
  

--- 3,12 -----
  								*/
  
  #include <stdio.h>
+ #include <sys/types.h>
+ #include <sys/file.h>
+ #include <sys/stat.h>
+ #include <pwd.h>
  #include "estruct.h"
  #include "edef.h"
  #define LOCK_DIR "/usr/local/gnuemacs/lock"
***************
*** 5,10
  #include <stdio.h>
  #include "estruct.h"
  #include "edef.h"
  
  #if	FILOCK
  #if	BSD

--- 9,15 -----
  #include <pwd.h>
  #include "estruct.h"
  #include "edef.h"
+ #define LOCK_DIR "/usr/local/gnuemacs/lock"
  
  #if	FILOCK
  #if	BSD
***************
*** 27,32
  	register int i;		/* loop indexes */
  	register int status;	/* return status */
  	char *undolock();
  
  	/* check to see if that file is already locked here */
  	if (numlocks > 0)

--- 32,38 -----
  	register int i;		/* loop indexes */
  	register int status;	/* return status */
  	char *undolock();
+ 	char *f,*stuff,*stuff2,*getwd(),*oname,*keepname;
  
  	/* check to see if that file is already locked here */
         stuff=malloc(200);
***************
*** 29,34
  	char *undolock();
  
  	/* check to see if that file is already locked here */
  	if (numlocks > 0)
  		for (i=0; i < numlocks; ++i)
  			if (strcmp(fname, lname[i]) == 0)

--- 35,72 -----
  	char *f,*stuff,*stuff2,*getwd(),*oname,*keepname;
  
  	/* check to see if that file is already locked here */
+        stuff=malloc(200);
+        stuff2=malloc(200);
+        stuff2=getwd(stuff);
+ again:
+   if(index(fname,'/') != 0)
+ 	  { if (strncmp(fname,"./",2)==0)
+ 		{ fname=fname + 2;
+ 		  goto again;
+ 		}
+ 	    else 
+ 	      {
+ 	    if (strncmp(fname,"../",3)==0)
+ 	      {
+ 		fname= fname + 3;
+ 		stuff2=rindex(stuff,'/');
+ 		if(strlen(stuff) >= 2) {
+ 		  for(;*stuff2 !=0;stuff2++)
+ 		    *stuff2=0;
+ 		}
+ 		stuff2=rindex(stuff,'/');
+ 		if(strlen(stuff) == 0)
+ 		  strcpy(stuff,"/");
+ 		goto again;
+ 	      }
+ 	  }
+ 	  }
+ 	if(strlen(stuff) >= 2)
+ 	  strcat(stuff,"/");
+        strcat(stuff,fname);
+        fname=stuff;
+ 	keepname=malloc(strlen(fname));
+ 	strcpy(keepname,fname);
  	if (numlocks > 0)
  		for (i=0; i < numlocks; ++i)
  			if (strcmp(fname, lname[i]) == 0)
***************
*** 42,47
  
  	/* next, try to lock it */
  	status = lock(fname);
  	if (status == ABORT)	/* file is locked, no override */
  		return(ABORT);
  	if (status == FALSE)	/* locked, overriden, dont add to table */

--- 80,86 -----
  
  	/* next, try to lock it */
  	status = lock(fname);
+ 	strcpy(fname,keepname);
  	if (status == ABORT)	/* file is locked, no override */
  		return(ABORT);
  	if (status == FALSE)	/* locked, overriden, dont add to table */
***************
*** 96,101
  	register int status;	/* return status */
  	char msg[NSTRING];	/* message string */
  	char *dolock();
  
  	/* attempt to lock the file */
  	locker = dolock(fname);

--- 135,141 -----
  	register int status;	/* return status */
  	char msg[NSTRING];	/* message string */
  	char *dolock();
+ 	char *f,*stuff,*stuff2,*getwd(),*oname,*keepname;
  
  	/* attempt to lock the file */
  	locker = dolock(fname);
***************
*** 141,146
  	return(FALSE);
  }
  
  lckerror(errstr)	/* report a lock error */
  
  char *errstr;		/* lock error string to print out */

--- 181,272 -----
  	return(FALSE);
  }
  
+ char *
+ dolock(fname)
+ char *fname;
+ {
+   int ffpint,rstat,ipid,i,luid;
+   char *pid,*f,*stuff,*stuff2,*getwd(),*oname,*name;
+   FILE *lockffp;
+   struct stat *buf;
+   struct passwd *passwordent;
+   	 oname=fname;
+ 	 for (;*fname;*fname++)
+ 	   {
+ 	     if (*fname == '/')
+ 	       *fname = '!';
+ 	   }
+ f=(char *)malloc(strlen(oname)+26);
+ strcpy(f,LOCK_DIR);
+ strcat(f,"/");
+ strcat(f,oname);
+ if(access(f,F_OK) == 0)
+     { ffpint=open(f,O_RDONLY);
+       if (ffpint<0)
+ 	{ mlwrite("open: %s",perror("open"));
+ 	  sleep(2);
+ 	  quit();
+ 	}
+       pid=malloc(10);
+       rstat=read(ffpint,pid,10);
+       if (rstat<0)
+ 	{ mlwrite("read: %s",perror("read"));
+ 	  sleep(2);
+ 	  quit();
+ 	}
+       ipid=atoi(pid);
+       if (!( kill ( ipid , 0 ) < 0 && errno == ESRCH))
+ 	{
+ 	  buf=malloc(500); 
+ 	  rstat=stat(f,buf);
+ 	  if (rstat <0 )
+ 	    { mlwrite("stat: %s",perror("stat"));
+ 	      sleep(2);
+ 	      return("LOCK"); }
+ 	  else
+ 	    { luid=(int) buf->st_uid;
+ 	      passwordent=getpwuid(luid);
+ 	    return(passwordent->pw_name);
+ 	    } 
+ 	}
+     }
+   ffpint=open(f,O_WRONLY | O_CREAT,0666);
+   if (ffpint<0)
+       { mlwrite("open: %s",perror("open"));
+ 	quit();
+       }
+   ipid=getpid();
+   pid=malloc(10);
+   sprintf(pid,"%d ",ipid);
+   fchmod(ffpint, 0666);
+   write(ffpint,pid,strlen(pid));
+   close(ffpint);
+   return(NULL);
+ }
+ 
+ char *
+ undolock(fname)
+ char *fname;
+ {
+   int result;
+   char *f,*oname,*errno;
+   oname=fname;
+ 	 for (;*fname;*fname++)
+ 	   {
+ 	     if (*fname == '/')
+ 	       *fname = '!';
+ 	   }
+ f=(char *)malloc(strlen(oname)+26);
+ strcpy(f,LOCK_DIR);
+ strcat(f,"/");
+ strcat(f,oname);
+ result=unlink(f);
+   if (result < 0)
+     {
+       return("unlink: ");
+     }
+   return(NULL);
+ }
  lckerror(errstr)	/* report a lock error */
  
  char *errstr;		/* lock error string to print out */
SHAR_EOF
fi # end of overwriting check
if test -f 'diffs/makefile.pch'
then
	echo shar: will not over-write existing file "'diffs/makefile.pch'"
else
cat << \SHAR_EOF > 'diffs/makefile.pch'
*** ../original/makefile	Sun Feb  7 03:32:03 1988
--- makefile	Tue Feb 16 00:48:05 1988
***************
*** 1,4
! CFLAGS=
  
  OFILES=		ansi.o basic.o bind.o buffer.o crypt.o dg10.o \
  		display.o eval.o exec.o file.o fileio.o \

--- 1,4 -----
! CFLAGS=  -Ml -O
  
  OFILES=		ansi.o basic.o bind.o buffer.o crypt.o \
  		display.o eval.o exec.o file.o fileio.o \
***************
*** 1,6
  CFLAGS=
  
! OFILES=		ansi.o basic.o bind.o buffer.o crypt.o dg10.o \
  		display.o eval.o exec.o file.o fileio.o \
  		hp110.o hp150.o ibmpc.o input.o isearch.o line.o \
  		main.o random.o region.o search.o spawn.o \

--- 1,6 -----
  CFLAGS=  -Ml -O
  
! OFILES=		ansi.o basic.o bind.o buffer.o crypt.o \
  		display.o eval.o exec.o file.o fileio.o \
  		input.o isearch.o line.o \
  		main.o random.o region.o search.o spawn.o \
***************
*** 2,8
  
  OFILES=		ansi.o basic.o bind.o buffer.o crypt.o dg10.o \
  		display.o eval.o exec.o file.o fileio.o \
! 		hp110.o hp150.o ibmpc.o input.o isearch.o line.o \
  		main.o random.o region.o search.o spawn.o \
  		st520.o tcap.o termio.o tipc.o vmsvt.o vt52.o \
  		window.o word.o z309.o

--- 2,8 -----
  
  OFILES=		ansi.o basic.o bind.o buffer.o crypt.o \
  		display.o eval.o exec.o file.o fileio.o \
! 		input.o isearch.o line.o \
  		main.o random.o region.o search.o spawn.o \
  		termio.o \
  		window.o word.o
***************
*** 4,11
  		display.o eval.o exec.o file.o fileio.o \
  		hp110.o hp150.o ibmpc.o input.o isearch.o line.o \
  		main.o random.o region.o search.o spawn.o \
! 		st520.o tcap.o termio.o tipc.o vmsvt.o vt52.o \
! 		window.o word.o z309.o
  
  CFILES=		ansi.c basic.c bind.c buffer.c crypt.c dg10.c \
  		display.c eval.c exec.c file.c fileio.c \

--- 4,11 -----
  		display.o eval.o exec.o file.o fileio.o \
  		input.o isearch.o line.o \
  		main.o random.o region.o search.o spawn.o \
! 		termio.o \
! 		window.o word.o
  
  CFILES=		ansi.c basic.c bind.c buffer.c crypt.c dg10.c \
  		display.c eval.c exec.c file.c fileio.c \
***************
*** 17,23
  HFILES=		estruct.h edef.h efunc.h epath.h ebind.h evar.h
  
  emacs:		$(OFILES)
! 		$(CC) $(CFLAGS) $(OFILES) -lc -o emacs
  
  $(OFILES):	$(HFILES)
  

--- 17,23 -----
  HFILES=		estruct.h edef.h efunc.h epath.h ebind.h evar.h
  
  emacs:		$(OFILES)
! 		$(CC) $(CFLAGS) $(OFILES) -lxmalloc -o emacs
  
  $(OFILES):	$(HFILES)
  
SHAR_EOF
fi # end of overwriting check
if test -f 'diffs/termio.c.pch'
then
	echo shar: will not over-write existing file "'diffs/termio.c.pch'"
else
cat << \SHAR_EOF > 'diffs/termio.c.pch'
*** ../original/termio.c	Sun Feb  7 05:12:20 1988
--- termio.c	Sun Feb 21 13:12:54 1988
***************
*** 162,167
  
  #if	USG
  	ioctl(0, TCGETA, &otermio);	/* save old settings */
  	ntermio.c_iflag = 0;		/* setup new settings */
  	ntermio.c_oflag = 0;
  	ntermio.c_cflag = otermio.c_cflag;

--- 162,168 -----
  
  #if	USG
  	ioctl(0, TCGETA, &otermio);	/* save old settings */
+ 	ntermio = otermio;
  	ntermio.c_iflag = 0;		/* setup new settings */
  	ntermio.c_oflag = 0;
  	ntermio.c_cflag = otermio.c_cflag;
SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0