diff -cbr src-orig/basic.c src/basic.c
*** src-orig/basic.c	Mon Dec 16 11:42:16 1991
--- src/basic.c	Sun Dec 22 16:19:00 1991
***************
*** 164,169 ****
--- 164,207 ----
          return(TRUE);
  }
  
+ #if   KEEPPOS
+ 
+ /*
+  * Move to the top of the screen.  The standsrd screen code does most of the
+  * hard parts of update.
+  *
+  */
+ PASCAL NEAR gotobos(f, n)
+ int f, n;
+ {
+         curwp->w_dotp  = curwp->w_linep;
+         curwp->w_doto  = 0;
+         curwp->w_flag |= WFHARD;
+         return(TRUE);
+ } /* gotobos */
+ 
+ 
+ /*
+  * Goto the end of the screen.
+  */
+ PASCAL NEAR gotoeos(f, n)
+ int f, n;
+ {
+ register LINE   *lp;
+ int   currow;
+ 
+       lp = curwp->w_linep;
+       currow = curwp->w_ntrows - 1;
+         while (currow-- && lp!=curbp->b_linep) lp = lforw(lp);
+         curwp->w_dotp  = lp;
+         curwp->w_doto  = 0;
+         curwp->w_flag |= WFHARD;
+         return(TRUE);
+ } /* gotoeos */
+ 
+ #endif
+ 
+ 
  /*
   * Move forward by full lines. If the number of lines to move is less than
   * zero, call the backward line function to actually do it. The last command
***************
*** 440,445 ****
--- 478,488 ----
  {
          register LINE   *lp;
  
+ #if   KEEPPOS
+         int     currow;
+         register LINE   *lp1;
+ #endif
+ 
          if (f == FALSE) {
                  n = curwp->w_ntrows - 2;        /* Default scroll.      */
                  if (n <= 0)                     /* Forget the overlap   */
***************
*** 447,457 ****
          } else if (n < 0)
                  return(backpage(f, -n));
          lp = curwp->w_linep;
          while (n-- && lp!=curbp->b_linep)
                  lp = lforw(lp);
          curwp->w_linep = lp;
!         curwp->w_dotp  = lp;
          curwp->w_doto  = 0;
          curwp->w_flag |= WFHARD;
          return(TRUE);
  }
--- 490,521 ----
          } else if (n < 0)
                  return(backpage(f, -n));
          lp = curwp->w_linep;
+ 
+ #if   KEEPPOS
+         if ((lastflag&CFCPCN) == 0)
+                 curgoal = getccol(FALSE);
+         /* flag this command as a line move */
+         thisflag |= CFCPCN;
+         lp1 = lp;
+         currow = 0;
+         while (lp1 != curwp->w_dotp ) {
+               currow++;
+               lp1 = lforw(lp1);
+         }
+ #endif
+ 
          while (n-- && lp!=curbp->b_linep)
                  lp = lforw(lp);
          curwp->w_linep = lp;
! 
! #if   KEEPPOS
!         while (currow-- && lp!=curbp->b_linep) lp = lforw(lp);
!         curwp->w_doto = getgoal(lp);
! #else
          curwp->w_doto  = 0;
+ #endif
+ 
+         curwp->w_dotp  = lp;
          curwp->w_flag |= WFHARD;
          return(TRUE);
  }
***************
*** 470,475 ****
--- 534,544 ----
  {
          register LINE   *lp;
  
+ #if   KEEPPOS
+         int     currow;
+         register LINE   *lp1;
+ #endif
+ 
          if (f == FALSE) {
                  n = curwp->w_ntrows - 2;        /* Default scroll.      */
                  if (n <= 0)                     /* Don't blow up if the */
***************
*** 477,487 ****
          } else if (n < 0)
                  return(forwpage(f, -n));
          lp = curwp->w_linep;
          while (n-- && lback(lp)!=curbp->b_linep)
                  lp = lback(lp);
          curwp->w_linep = lp;
!         curwp->w_dotp  = lp;
          curwp->w_doto  = 0;
          curwp->w_flag |= WFHARD;
          return(TRUE);
  }
--- 546,577 ----
          } else if (n < 0)
                  return(forwpage(f, -n));
          lp = curwp->w_linep;
+ 
+ #if   KEEPPOS
+         if ((lastflag&CFCPCN) == 0)
+                 curgoal = getccol(FALSE);
+         /* flag this command as a line move */
+         thisflag |= CFCPCN;
+         lp1 = lp;
+         currow = 0;
+         while (lp1 != curwp->w_dotp ) {
+               currow++;
+               lp1 = lforw(lp1);
+         }
+ #endif
+ 
          while (n-- && lback(lp)!=curbp->b_linep)
                  lp = lback(lp);
          curwp->w_linep = lp;
! 
! #if   KEEPPOS
!         while (currow-- && lp!=curbp->b_linep) lp = lforw(lp);
!         curwp->w_doto = getgoal(lp);
! #else
          curwp->w_doto  = 0;
+ #endif
+ 
+         curwp->w_dotp  = lp;
          curwp->w_flag |= WFHARD;
          return(TRUE);
  }
diff -cbr src-orig/bind.c src/bind.c
*** src-orig/bind.c	Mon Dec 16 11:42:16 1991
--- src/bind.c	Sun Dec 22 16:19:00 1991
***************
*** 772,777 ****
--- 772,782 ----
  
  	c = c & 255;	/* strip the prefixes */
  
+         if ((c & 255) == 127) {
+                 *ptr++ = '^';
+                 c = '?';
+         }
+ 
  	/* and output the final sequence */
  
  	*ptr++ = c;
***************
*** 938,944 ****
  	if (*keyname == '^' && *(keyname+1) != 0) {
  		c |= CTRL;
  		++keyname;
! 		uppercase(keyname);
  	}
  
  	/* A literal control character? (Boo, hiss) */
--- 943,949 ----
  	if (*keyname == '^' && *(keyname+1) != 0) {
  		c |= CTRL;
  		++keyname;
! 		/* uppercase(keyname); */
  	}
  
  	/* A literal control character? (Boo, hiss) */
diff -cbr src-orig/char.c src/char.c
*** src-orig/char.c	Mon Dec 16 11:42:16 1991
--- src/char.c	Sun Dec 22 16:19:00 1991
***************
*** 139,145 ****
  		upcase[index ^ DIFCASE] = index;
  	}
  
! #if	MSDOS
  	/* setup various extended IBM-PC characters */
  	upcase[0x80]  = 0x87;	/* C with a cedilla */
  	lowcase[0x81] = 0x9a;	/* U with an umlaut */
--- 139,145 ----
  		upcase[index ^ DIFCASE] = index;
  	}
  
! #if     MSDOS | OS2
  	/* setup various extended IBM-PC characters */
  	upcase[0x80]  = 0x87;	/* C with a cedilla */
  	lowcase[0x81] = 0x9a;	/* U with an umlaut */
diff -cbr src-orig/display.c src/display.c
*** src-orig/display.c	Mon Dec 16 11:42:16 1991
--- src/display.c	Sun Dec 22 16:19:02 1991
***************
*** 885,891 ****
--- 885,897 ----
  	    || req || rev
  #endif
  			) {
+ #if     OS2NPM
+         	ttrow = row;  /* special optimization */
+                 ttcol = 0;
+                 os2vmove(row, 0);       /* Go to start of line. */
+ #else
  		movecursor(row, 0);	/* Go to start of line. */
+ #endif
  		/* set rev video if needed */
  		if (rev != req)
  			(*term.t_rev)(req);
***************
*** 979,985 ****
--- 985,997 ----
  	}
  
  	/* move to the begining of the text to update */
+ #if     OS2NPM
+         ttrow = row;  /* special optimization */
+         ttcol = upcol;
+         os2vmove(row, upcol);       /* Go to start of line. */
+ #else
  	movecursor(row, upcol);
+ #endif
  
  #if	REVSTA
  	if (rev)
diff -cbr src-orig/dolock.c src/dolock.c
*** src-orig/dolock.c	Mon Dec 16 11:42:16 1991
--- src/dolock.c	Sun Dec 22 16:19:02 1991
***************
*** 71,79 ****
--- 71,81 ----
  #if	ZTC
  extern volatile int errno;
  #else
+ #if     MSC == 0
  extern int errno;
  #endif
  #endif
+ #endif
  
  #define LOCKDIR "_xlk"
  #define LOCKMSG "LOCK ERROR -- "
diff -cbr src-orig/edef.h src/edef.h
*** src-orig/edef.h	Mon Dec 16 11:44:30 1991
--- src/edef.h	Sun Dec 22 16:19:22 1991
***************
*** 27,33 ****
  NOSHARE int DNEAR eolexist = TRUE;	/* does clear to EOL exist?	*/
  NOSHARE int DNEAR revexist = FALSE;	/* does reverse video exist?	*/
  NOSHARE int DNEAR exec_error = FALSE;	/* macro execution error pending? */
! NOSHARE int DNEAR flickcode = TRUE;	/* do flicker supression?	*/
  CONST char *modename[] = { 		/* name of modes		*/
  	"WRAP", "CMODE", "SPELL", "EXACT", "VIEW", "OVER",
  	"MAGIC", "CRYPT", "ASAVE", "REP"};
--- 27,33 ----
  NOSHARE int DNEAR eolexist = TRUE;	/* does clear to EOL exist?	*/
  NOSHARE int DNEAR revexist = FALSE;	/* does reverse video exist?	*/
  NOSHARE int DNEAR exec_error = FALSE;	/* macro execution error pending? */
! NOSHARE int DNEAR flickcode = FALSE;	/* do flicker supression?	*/
  CONST char *modename[] = { 		/* name of modes		*/
  	"WRAP", "CMODE", "SPELL", "EXACT", "VIEW", "OVER",
  	"MAGIC", "CRYPT", "ASAVE", "REP"};
***************
*** 93,98 ****
--- 93,101 ----
  NOSHARE int DNEAR kbdmode = STOP;	/* current keyboard macro mode	*/
  NOSHARE int DNEAR kbdrep = 0;		/* number of repetitions	*/
  NOSHARE int DNEAR restflag = FALSE;	/* restricted use?		*/
+ #ifdef	BACKUP
+ NOSHARE	int DNEAR bakfile = TRUE;	/* save the bakfile		*/
+ #endif
  NOSHARE int DNEAR lastkey = 0;		/* last keystoke		*/
  NOSHARE int DNEAR seed = 0;		/* random number seed		*/
  NOSHARE long envram = 0l;		/* # of bytes current in use by malloc */
***************
*** 277,282 ****
--- 280,288 ----
  NOSHARE extern int kbdmode;		/* current keyboard macro mode	*/
  NOSHARE extern int kbdrep;		/* number of repetitions	*/
  NOSHARE extern int restflag;		/* restricted use?		*/
+ #ifdef	BACKUP
+ NOSHARE	extern	int bakfile;		/* save the bakfile		*/
+ #endif
  NOSHARE extern int lastkey;		/* last keystoke		*/
  NOSHARE extern int seed;		/* random number seed		*/
  NOSHARE extern long envram;		/* # of bytes current in use by malloc */
diff -cbr src-orig/efunc.h src/efunc.h
*** src-orig/efunc.h	Mon Dec 16 11:44:30 1991
--- src/efunc.h	Sun Dec 22 16:19:22 1991
***************
*** 27,32 ****
--- 27,35 ----
  	{"begin-macro",			ctlxlp},
  	{"beginning-of-file",		gotobob},
  	{"beginning-of-line",		gotobol},
+ #if	KEEPPOS
+ 	{"beginning-of-screen",		gotobos},
+ #endif
  	{"bind-to-key",			bindtokey},
  	{"buffer-position",		showcpos},
  	{"case-region-lower",		lowerregion},
***************
*** 39,44 ****
--- 42,50 ----
  	{"change-screen-row",		new_row_org},
  	{"change-screen-size",		newsize},
  	{"change-screen-width",		newwidth},
+ #if	CHDIR
+ 	{"change-working-directory",    changedir},
+ #endif
  	{"clear-and-redraw",		refresh},
  	{"clear-message-line",		clrmes},
  	{"copy-region",			copyregion},
***************
*** 48,53 ****
--- 54,60 ----
  	{"delete-blank-lines",		deblank},
  	{"delete-buffer",		killbuffer},
  	{"delete-global-mode",		delgmode},
+ 	{"delete-line",			delline},
  	{"delete-mode",			delmode},
  	{"delete-next-character",	forwdel},
  	{"delete-next-word",		delfword},
***************
*** 72,77 ****
--- 79,87 ----
  	{"end-macro",			ctlxrp},
  	{"end-of-file",			gotoeob},
  	{"end-of-line",			gotoeol},
+ #ifdef	KEEPPOS
+ 	{"end-of-screen",		gotoeos},
+ #endif
  	{"end-of-word",			endword},
  	{"entab-line",			entab},
  	{"entab-region",		entab},
***************
*** 227,232 ****
--- 237,243 ----
  #if	CTAGS
  	{"tag-word",			tagword},
  #endif
+ 	{"toggle-over-mode",		toggleovermode},
  	{"transpose-characters",	twiddle},
  	{"trim-line",			trim},
  	{"trim-region",			trim},
diff -cbr src-orig/epath.h src/epath.h
*** src-orig/epath.h	Mon Dec 16 11:44:30 1991
--- src/epath.h	Sun Dec 22 16:19:24 1991
***************
*** 44,54 ****
  
  #if	MSDOS
  {
! 	"emacs.rc",
! 	"emacs.hlp",
! 	"\\sys\\public\\",
! 	"\\usr\\bin\\",
! 	"\\bin\\",
  	"\\",
  	""
  };
--- 44,54 ----
  
  #if	MSDOS
  {
! 	"me.rc",
! 	"me.hlp",
!  	"c:\\bin\\",
!         "c:\\etc\\",
! 	"c:\\",
  	"\\",
  	""
  };
***************
*** 56,67 ****
  
  #if OS2
  {
!         "emacs.rc",
!         "emacs.hlp",
!         "C:\\OS2\\SYSTEM\\",
!         "C:\\OS2\\DLL\\",
!         "C:\\OS2\\BIN\\",
!         "C:\\OS2\\",
          "\\",
          ""
  };
--- 56,67 ----
  
  #if OS2
  {
!         "me.rc",
!         "me.hlp",
!  	"c:\\bin\\",
!         "c:\\etc\\",
!         "c:\\os2\\",
! 	"c:\\",
          "\\",
          ""
  };
***************
*** 71,78 ****
  {
  	".emacsrc",
  	"emacs.hlp",
- 	"/usr/local/",
  	"/usr/lib/",
  	""
  };
  #endif
--- 71,80 ----
  {
  	".emacsrc",
  	"emacs.hlp",
  	"/usr/lib/",
+ 	"/usr/local/",
+ 	"/usr/local/lib/",
+ 	"/usr/local/lib/emacs/",
  	""
  };
  #endif
diff -cbr src-orig/eproto.h src/eproto.h
*** src-orig/eproto.h	Mon Dec 16 11:44:30 1991
--- src/eproto.h	Sun Dec 22 16:19:26 1991
***************
*** 284,289 ****
--- 284,290 ----
  extern PASCAL NEAR forwpage(int f, int n);
  extern PASCAL NEAR forwword(int f, int n);
  extern PASCAL NEAR freewhile(WHBLOCK *wp);
+ extern PASCAL NEAR getbackupname(char *backup, char *file);
  extern PASCAL NEAR getccol(int bflg);
  extern PASCAL NEAR getcmd(void);
  extern PASCAL NEAR getfence(int f, int n);
***************
*** 336,341 ****
--- 337,343 ----
  extern PASCAL NEAR lowrite(char c);
  extern PASCAL NEAR macarg(char *tok);
  extern PASCAL NEAR macrotokey(int f, int n);
+ extern PASCAL NEAR makebackup(char *filename);
  extern PASCAL NEAR makelist(int iflag);
  extern PASCAL NEAR mouse_screen(void);
  extern PASCAL NEAR screenlist(int iflag);
***************
*** 488,501 ****
  extern int PASCAL NEAR backtagword(int f, int n); /* return from tagged word */
  #endif
  
  /* some library redefinitions */
  
  char *strcat(char *, char *);
  char *strcpy(char *, char *);
  #if RAMSIZE == 0
! char *malloc(int);
  #endif
! char *realloc(char *block, int siz);
  
  #else
  
--- 490,515 ----
  extern int PASCAL NEAR backtagword(int f, int n); /* return from tagged word */
  #endif
  
+ extern PASCAL	NEAR	toggleovermode(int f, int n);
+ extern PASCAL	NEAR	delline(int f, int n);
+   
+ #if	KEEPPOS
+ extern PASCAL NEAR	gotobos(int f, int n);	/* goto beginning of screen */
+ extern PASCAL NEAR	gotoeos(int f, int n);	/* goto end of screen */
+ #endif
+ 
+ #if	CHDIR
+ extern PASCAL NEAR changedir(int f, int n);
+ #endif
+ 
  /* some library redefinitions */
  
  char *strcat(char *, char *);
  char *strcpy(char *, char *);
  #if RAMSIZE == 0
! void *malloc(size_t);
  #endif
! void *realloc(void *block, size_t siz);
  
  #else
  
***************
*** 766,771 ****
--- 780,786 ----
  extern PASCAL NEAR forwpage();
  extern PASCAL NEAR forwword();
  extern PASCAL NEAR freewhile();
+ extern PASCAL NEAR getbackupname();
  extern PASCAL NEAR getccol();
  extern PASCAL NEAR getcmd();
  extern PASCAL NEAR getfence();
***************
*** 819,824 ****
--- 834,840 ----
  extern PASCAL NEAR lowrite();
  extern PASCAL NEAR macarg();
  extern PASCAL NEAR macrotokey();
+ extern PASCAL NEAR makebackup();
  extern PASCAL NEAR makelist();
  extern PASCAL NEAR mouse_screen();
  extern PASCAL NEAR screenlist();
***************
*** 969,974 ****
--- 985,1002 ----
  extern int PASCAL NEAR tagword();	/* vi-like tagging */
  extern int PASCAL NEAR retagword();	/* Try again (if redefined) */
  extern int PASCAL NEAR backtagword();	/* return from tagged word */
+ #endif
+ 
+ extern PASCAL	NEAR	toggleovermode();
+ extern PASCAL	NEAR	delline();
+   
+ #if	KEEPPOS
+ extern PASCAL NEAR	gotobos();		/* goto beginning of screen */
+ extern PASCAL NEAR	gotoeos();		/* goto end of screen */
+ #endif
+ 
+ #if	CHDIR
+ extern PASCAL NEAR changedir();
  #endif
  
  /* some library redefinitions */
diff -cbr src-orig/estruct.h src/estruct.h
*** src-orig/estruct.h	Mon Dec 16 11:44:32 1991
--- src/estruct.h	Sun Dec 22 14:42:36 1991
***************
*** 146,162 ****
  #define REVSTA	1	/* Status line appears in reverse video 	*/
  #define	COLOR	1	/* color commands and windows			*/
  
! #define FILOCK	1	/* file locking under unix BSD 4.2		*/
  #define	ISRCH	1	/* Incremental searches like ITS EMACS		*/
! #define	FLABEL	1	/* function key label code [HP150]		*/
  #define	CRYPT	1	/* file encryption enabled?			*/
  #define MAGIC	1	/* include regular expression matching?		*/
  #define MOUSE	1 	/* Include routines for mouse actions		*/
  #define	NOISY	1	/* Use a fancy BELL if it exists		*/
! #define CTAGS	0	/* include vi-like tagging?			*/
  #define	SPEECH	0	/* spoken EMACS, for the sight impared [not ready] */
  #define	VARARG	1	/* use varargs.h for mlwrite()			*/
  
  /*	Character set options		*/
  /*	[Set one of these!!]		*/
  #define ASCII	1	/* always using ASCII char sequences for now	*/
--- 146,167 ----
  #define REVSTA	1	/* Status line appears in reverse video 	*/
  #define	COLOR	1	/* color commands and windows			*/
  
! #define FILOCK	0	/* file locking under unix BSD 4.2		*/
  #define	ISRCH	1	/* Incremental searches like ITS EMACS		*/
! #define	FLABEL	0	/* function key label code [HP150]		*/
  #define	CRYPT	1	/* file encryption enabled?			*/
  #define MAGIC	1	/* include regular expression matching?		*/
  #define MOUSE	1 	/* Include routines for mouse actions		*/
  #define	NOISY	1	/* Use a fancy BELL if it exists		*/
! #define CTAGS	1	/* include vi-like tagging?			*/
  #define	SPEECH	0	/* spoken EMACS, for the sight impared [not ready] */
  #define	VARARG	1	/* use varargs.h for mlwrite()			*/
  
+ #define BACKUP	0	/* retain original file as backup (MSDOS, UNIX) */
+ #define	SOFTAB	1	/* in OVER mode, are tabs and returns soft?	*/
+ #define	KEEPPOS	1	/* Maintain cursor position when paging		*/
+ #define CHDIR   1	/* code for changing working directory		*/
+ 
  /*	Character set options		*/
  /*	[Set one of these!!]		*/
  #define ASCII	1	/* always using ASCII char sequences for now	*/
***************
*** 222,228 ****
  #if MSDOS & (TURBO | MSC | TIPC)
  #define	NEAR
  #define	DNEAR
! #define	PASCAL pascal
  #define	CDECL cdecl
  #else
  #if MSDOS & ZTC
--- 227,233 ----
  #if MSDOS & (TURBO | MSC | TIPC)
  #define	NEAR
  #define	DNEAR
! #define	PASCAL /* pascal */
  #define	CDECL cdecl
  #else
  #if MSDOS & ZTC
***************
*** 397,403 ****
  /*	internal constants	*/
  
  #define NBINDS	300			/* max # of bound keys		*/
! #if	AOSVS | VMS
  #define	NFILEN	256
  #else
  #define NFILEN	80			/* # of bytes, file name	*/
--- 402,408 ----
  /*	internal constants	*/
  
  #define NBINDS	300			/* max # of bound keys		*/
! #if	AOSVS | VMS | OS2
  #define	NFILEN	256
  #else
  #define NFILEN	80			/* # of bytes, file name	*/
***************
*** 655,660 ****
--- 660,668 ----
  	char	b_bname[NBUFN]; 	/* Buffer name			*/
  #if	CRYPT
  	char   b_key[NPAT];	       /* current encrypted key        */
+ #endif
+ #if	BACKUP							   /* -- ZU */
+ 	short	b_bupflg;		/* true if file was backed up	*/
  #endif
  }	BUFFER;
  
diff -cbr src-orig/file.c src/file.c
*** src-orig/file.c	Mon Dec 16 11:42:18 1991
--- src/file.c	Sun Dec 22 16:37:44 1991
***************
*** 11,18 ****
  #include	"eproto.h"
  #include	"edef.h"
  #include	"elang.h"
! #if	BSD | SUN | V7
  #include	<sys/types.h>
  #include	<sys/stat.h>
  #endif
  
--- 11,19 ----
  #include	"eproto.h"
  #include	"edef.h"
  #include	"elang.h"
! #if     V7 | USG | HPUX | BSD | SUN | XENIX | MSDOS | OS2
  #include	<sys/types.h>
+ #undef CDECL
  #include	<sys/stat.h>
  #endif
  
***************
*** 176,182 ****
  	register int cmark;	/* current mark */
  	char bname[NBUFN];	/* buffer name to put file */
  
! #if	MSDOS | OS2 | AOSVS | VMS | TOS
  	mklower(fname); 	       /* msdos isn't case sensitive */
  #endif
  	for (bp=bheadp; bp!=NULL; bp=bp->b_bufp) {
--- 177,183 ----
  	register int cmark;	/* current mark */
  	char bname[NBUFN];	/* buffer name to put file */
  
! #if	MSDOS | _OS2 | AOSVS | VMS | TOS
  	mklower(fname); 	       /* msdos isn't case sensitive */
  #endif
  	for (bp=bheadp; bp!=NULL; bp=bp->b_bufp) {
***************
*** 262,267 ****
--- 263,271 ----
  	if ((s=bclear(bp)) != TRUE)		/* Might be old.	*/
  		return(s);
  	bp->b_flag &= ~(BFINVS|BFCHG);
+ #if	BACKUP
+ 	curbp->b_bupflg = FALSE;		/* no backup file yet	*/
+ #endif
  	strcpy(bp->b_fname, fname);
  
  	/* let a user macro get hold of things...if he wants */
***************
*** 465,470 ****
--- 469,477 ----
  	if ((s=writeout(fname, "w")) == TRUE) {
  		strcpy(curbp->b_fname, fname);
  		curbp->b_flag &= ~BFCHG;
+ #if	BACKUP
+ 		curbp->b_bupflg = TRUE;
+ #endif
  		/* Update mode lines.	*/
  		upmode();
  	}
***************
*** 486,491 ****
--- 493,501 ----
  		return(s);
  	if ((s=writeout(fname, "a")) == TRUE) {
  		curbp->b_flag &= ~BFCHG;
+ #if	BACKUP
+ 		curbp->b_bupflg = TRUE;
+ #endif
  		/* Update mode lines.	*/
  		upmode();
  	}
***************
*** 549,555 ****
   * This function performs the details of file writing. It uses
   * the file management routines in the "fileio.c" package. The
   * number of lines written is displayed. Several errors are
!  * posible, and cause writeout to return a FALSE result. When
   * $ssave is TRUE,  the buffer is written out to a temporary
   * file, and then the old file is unlinked and the temporary
   * renamed to the original name.  Before the file is written,
--- 559,565 ----
   * This function performs the details of file writing. It uses
   * the file management routines in the "fileio.c" package. The
   * number of lines written is displayed. Several errors are
!  * possible, and cause writeout to return a FALSE result. When
   * $ssave is TRUE,  the buffer is written out to a temporary
   * file, and then the old file is unlinked and the temporary
   * renamed to the original name.  Before the file is written,
***************
*** 654,662 ****
  #endif
  			/* erase original file */
  			/* rename temporary file to original name */
  			if (unlink(fn) == 0 && rename(tname, fn) == 0) {
! #if	BSD | SUN | V7
! 				chmod(fn, (int)st.st_uid, (int)st.st_gid);
  				chmod(fn, (int)st.st_mode);
  #else
  				;
--- 664,676 ----
  #endif
  			/* erase original file */
  			/* rename temporary file to original name */
+ #if	BACKUP
+ 			if (makebackup(fn) == TRUE && rename(tname, fn) == 0) {
+ #else
  			if (unlink(fn) == 0 && rename(tname, fn) == 0) {
! #endif
! #if	V7 | USG | HPUX | BSD | SUN | XENIX
! 				chown(fn, (int)st.st_uid, (int)st.st_gid);
  				chmod(fn, (int)st.st_mode);
  #else
  				;
***************
*** 870,872 ****
--- 884,1018 ----
  	return(TRUE);
  }
  
+ 								   /* -- ZU */
+ /* Make a backup file.
+  * This is done by renaming the original file to a new name.
+  * The name of the backup file is defined as follows:
+  *
+  * MSDOS: The base file name remains untouched, the extension has a tilde (~)
+  *	  as its first character and the other characters moved one place
+  *	  to the right.
+  * UNIX:  The first character is a '#'. The rest of the name is moved one
+  *	  place to the right. The length of the filename may not exceed 14
+  *	  characters (for BSD the limit is 255).
+  *
+  * No other operating system supported by now.
+  */
+ #if	BACKUP
+ 
+ PASCAL NEAR makebackup( filename )
+ char	*filename;
+ {
+ 	char	backupname[NFILEN];
+ #if     MSDOS | OS2 | V7 | USG | HPUX | BSD | SUN | XENIX
+ 	if ( curbp->b_bupflg ||			/* already backed up  */
+ 	     !bakfile				/* no backup file wanted */
+ 				) {
+ 		if( unlink( filename ) == 0 )
+ 			return( TRUE );
+ 		else
+ 			return( FALSE );
+ 	}
+ 
+ 	getbackupname( backupname, filename );
+ 
+ 	if( !fexist( filename ))		/* no original file - */
+ 		return( TRUE );			/* nothing to backup  */
+ 
+ 	if( fexist( backupname ))
+ 		if( unlink( backupname ))	/* file is readonly */
+ 			return( FALSE );
+ 
+ 	if( rename( filename, backupname ) != 0 )
+ 		return( FALSE );
+ 
+ 	return( TRUE );
+ #else			/* for all other operating systems return fail */
+ 	return( FALSE );
+ #endif	/* MSDOS | V7 | USG | HPUX | BSD | SUN | XENIX */
+ }
+ 
+ /* Make the name of the backup file according to the original file name
+  * This routines knows about the filename possibilities of the different
+  * operating systems.
+  */
+ PASCAL NEAR getbackupname( backup, file )
+ char	*backup;
+ char	*file;
+ {
+ 	char	temp[NFILEN];
+ 	int	index;
+ 	char	*dotpos;
+ 
+ 	strcpy( backup, file );
+ #if     MSDOS | OS2
+ 	for( index = strlen( backup ) -1; index >= 0 && backup[index] != '.';
+ 								index-- )
+ 		;
+ 	if( index < 0 )
+ 		strcat( backup, ".~" );
+ 	else {
+ 		strcpy( temp, &backup[index +1] );
+ 		backup[index +1] = '~';	/* first char of new extension	*/
+ 		temp[2] = '\0';		/* extension is at most 3 chars	*/
+ 		strcpy( &backup[index +2], temp );
+ 	}
+ #endif	/* MSDOS */
+ 
+ #if	V7 | USG | HPUX | BSD | SUN | XENIX
+ /*	strcpy( temp, "#" ); */
+ 	*temp = 0;
+ 	for( index = strlen( backup ) -1; index >= 0 && backup[index] != '/';
+ 								index-- )
+ 		;
+ 	if( index >= 0 )
+ 	    	strcat( temp, &backup[index +1] );
+ 	else
+ 		strncat( temp, backup, NFILEN -1 );
+ 
+ #if	BSD	/* BSD allows filenames	up to 255 characters	*/
+ #if	NFILEN < 255
+ 	if( strlen( temp ) > NFILEN )
+ 		temp[NFILEN] = '\0';
+ #else
+ 	if( strlen( temp ) > 254 )
+ 		temp[255] = '\0';
+ #endif
+ #else		/* other Unixes allow only 14 characters	*/
+ 	if( strlen( temp ) > 12 )
+ 		temp[ 13] = '\0';
+ #endif
+ 	strcat(temp,"-");
+ 	if( index >= 0 )
+ 		strncpy( &backup[index +1], temp, NFILEN - strlen( backup ) -1 );
+ 	else
+ 		strncpy( backup, temp, NFILEN - strlen( backup ) -1 );
+ #endif	/* V7 | USG | HPUX | BSD | SUN | XENIX */
+ }
+ 
+ #endif	/* BACKUP */
+ 
+ #if	CHDIR
+ /*
+  * Change current working directory
+  */
+ PASCAL NEAR changedir(f, n)
+ int f, n;
+ {
+ 	char buf[NSTRING + 32];	/* message buffer */
+ 	char *fname;	/* file user wishes to find */	/* file name */
+ 	register int s;		/* status return */
+ 
+ 	if (restflag)		/* don't allow this command if restricted */
+ 		return(resterr());
+ 
+ 	if ((fname = gtfilename("New directory")) != NULL)
+ 		changecwd(fname);
+ 
+ 	strcpy(buf, "Current directory = ");
+ 	getcwd(buf + 20, NSTRING);
+ 	mlwrite(buf);
+ 
+ 	return(TRUE);
+ }
+ #endif
diff -cbr src-orig/ibmpc.c src/ibmpc.c
*** src-orig/ibmpc.c	Mon Dec 16 11:42:18 1991
--- src/ibmpc.c	Sun Dec 22 16:19:06 1991
***************
*** 14,21 ****
  #include	"elang.h"
  
  #if     IBMPC
! #define NROW	50			/* Max Screen size.		*/
! #define NCOL    80                      /* Edit if you want to.         */
  #define	MARGIN	8			/* size of minimim margin and	*/
  #define	SCRSIZ	64			/* scroll size for extended lines */
  #define	NPAUSE	200			/* # times thru update to pause */
--- 14,21 ----
  #include	"elang.h"
  
  #if     IBMPC
! #define NROW    80                      /* Max Screen size.             */
! #define NCOL    140                     /* Edit if you want to.         */
  #define	MARGIN	8			/* size of minimim margin and	*/
  #define	SCRSIZ	64			/* scroll size for extended lines */
  #define	NPAUSE	200			/* # times thru update to pause */
***************
*** 419,432 ****
--- 419,442 ----
  	ttclose();
  }
  
+ static CtrlC_State;						   /* -- ZU */
  PASCAL NEAR ibmkopen()	/* open the keyboard */
  
  {
+ 	rg.x.ax = 0x3300;					   /* -- ZU */
+ 	intdos( &rg, &rg );					   /*     . */
+ 	CtrlC_State = rg.h.dl;					   /* -- UZ */
+   	rg.x.ax = 0x3301;
+   	rg.h.dl = 0x00;
+   	intdos(&rg, &rg);
  }
  
  PASCAL NEAR ibmkclose() /* close the keyboard */
  
  {
+ 	rg.x.ax = 0x3301;					   /* -- ZU */
+ 	rg.h.dl = CtrlC_State;					   /*     . */
+ 	intdos(&rg, &rg);					   /* -- UZ */
  }
  
  PASCAL NEAR scinit(type) /* initialize the screen head pointers */
diff -cbr src-orig/input.c src/input.c
*** src-orig/input.c	Mon Dec 16 11:42:20 1991
--- src/input.c	Sun Dec 22 17:05:42 1991
***************
*** 46,51 ****
--- 46,60 ----
  #include	"edef.h"
  #include	"elang.h"
  
+ #if USG | BSD | V7
+ #include	<sys/types.h>
+ #include	<pwd.h>
+ extern	struct passwd *getpwnam();
+ #if USG
+ #define	index	strchr
+ #endif
+ #endif
+ 
  /*
   * Ask a yes or no question in the message line. Return either TRUE, FALSE, or
   * ABORT. The ABORT status is returned if the user bumps out of the question
***************
*** 218,223 ****
--- 227,236 ----
  	register int ec;	/* extended input character */
  	int cpos;		/* current column on screen output */
  	static char buf[NSTRING];/* buffer to hold tentative name */
+ #if USG | BSD | V7 | XENIX
+ 	char *home;
+ 	struct passwd *pwd;
+ #endif
  
  	/* if we are executing a command line get the next arg and match it */
  	if (clexec) {
***************
*** 296,303 ****
  			TTflush();
  			if (buf[cpos - 1] == 0)
  				return(buf);
  		} else {
! 			if (cpos < maxlen && c > ' ') {
  				buf[cpos++] = c;
  				mlout(c);
  				++ttcol;
--- 309,383 ----
  			TTflush();
  			if (buf[cpos - 1] == 0)
  				return(buf);
+ #if USG | BSD | V7 | XENIX
+ 		} else if (c == '/' && type == CMP_FILENAME && buf[0] == '~') {
+ 			int i;
+ 			if (cpos == 1) {
+ 				if (home = (char *)getenv("HOME")) {
+ 					mlout('\b');	/* backup over ~ */
+ 					mlout(' ');
+ 					mlout('\b');
+ 					ttcol--;
+ 					TTflush();
+ 					strcpy(buf, home);
+ 					cpos = strlen(buf);
+ 					if (buf[cpos-1] != '/')
+ 						buf[cpos++] = '/';
+ 					for (i = 0; i < cpos; i++) {
+ 						mlout(buf[i]);
+ 						ttcol++;
+ 					}
+ 					TTflush();
+ 				} else
+ 					goto nextc;
+ 			} else {
+ 				buf[cpos] = '\0';
+ 				if (pwd = getpwnam(&buf[1])) {
+ 					while (cpos != 0) {	/* kill	*/
+ 						mlout('\b');	/* line	*/
+ 						mlout(' ');
+ 						mlout('\b');
+ 						--cpos;
+ 						--ttcol;
+ 					}
+ 					TTflush();
+ 					strcpy(buf, pwd->pw_dir);
+ 					cpos = strlen(buf);
+ 					if (buf[cpos-1] != '/')
+ 						buf[cpos++] = '/';
+ 					for (i = 0; i < cpos; i++) {
+ 						mlout(buf[i]);
+ 						ttcol++;
+ 					}
+ 					TTflush();
+ 				} else
+ 					goto nextc;
+ 			}
+ 		} else if (c == '/' && type == CMP_FILENAME && buf[0] == '$') {
+ 			int i;
+ 			buf[cpos] = '\0';
+ 			if (home = (char *)getenv(&buf[1])) {
+ 				while (cpos != 0) {	/* kill	*/
+ 					mlout('\b');	/* line	*/
+ 					mlout(' ');
+ 					mlout('\b');
+ 					--cpos;
+ 					--ttcol;
+ 				}
+ 				TTflush();
+ 				strcpy(buf, home);
+ 				cpos = strlen(buf);
+ 				buf[cpos++] = '/';
+ 				for (i = 0; i < cpos; i++) {
+ 					mlout(buf[i]);
+ 					ttcol++;
+ 				}
+ 				TTflush();
+ 			} else
+ 				goto nextc;
+ #endif
  		} else {
! nextc:			if (cpos < maxlen && c > ' ') {
  				buf[cpos++] = c;
  				mlout(c);
  				++ttcol;
***************
*** 482,488 ****
--- 562,572 ----
  	while (fname) {
  
  		/* is this a match? */
+ #if	OS2
+ 		if (strnicmp(name,fname,*cpos) == 0) {
+ #else
  		if (strncmp(name,fname,*cpos) == 0) {
+ #endif
  
  			/* count the number of matches */
  			matches++;
***************
*** 515,524 ****
--- 599,615 ----
  		return;
  	}
  
+ 	while (*cpos != 0) {
+ 		mlout('\b');    /* clear the old prefix out, just in case */
+ 		(*cpos)--;      /* the case of the name has changed (OS/2) */
+ 		ttcol--;
+ 	}
+ 
  	/* the longestmatch array contains the longest match so copy and print it */
  	for ( ; (*cpos < (NSTRING-1)) && (*cpos < longestlen); (*cpos)++) {
  		name[*cpos] = longestmatch[*cpos];
  		TTputc(name[*cpos]);
+                 ttcol++;
  	}
  
  	name[*cpos] = 0;
diff -cbr src-orig/keyboard.c src/keyboard.c
*** src-orig/keyboard.c	Mon Dec 16 11:42:20 1991
--- src/keyboard.c	Sun Dec 22 16:19:06 1991
***************
*** 74,81 ****
--- 74,85 ----
  	/* some others as well */
  	switch (c) {
  
+ case 1:         return(ALTD | CTRL | '[');
  case 3:		return(0);			/* null */
+ 
  case 0x0F:	return(SHFT | CTRL | 'I');	/* backtab */
+ case 0x94:      return(SPEC | CTRL | 'I');      /* ctrl tab */
+ case 0xA5:      return(ALTD | CTRL | 'I');      /* alt tab */
  
  case 0x10:	return(ALTD | 'Q');
  case 0x11:	return(ALTD | 'W');
diff -cbr src-orig/line.c src/line.c
*** src-orig/line.c	Mon Dec 16 11:42:20 1991
--- src/line.c	Sun Dec 22 16:19:08 1991
***************
*** 838,843 ****
--- 838,882 ----
  	return(TRUE);
  }
  
+ 
+ /*
+  * Delete the line the cursor is on
+  */
+ PASCAL	NEAR	delline(f, n)
+ int f, n;
+ {
+ 
+ /*		Use the lines associated with  i  in order to keep the
+ 		cursor in the same column when deleting a line.  If you
+ 		comment these lines out then the cursor will revert to
+ 		the first column.					*/
+ 
+  int	i,i1;
+ 
+ 	i1 = lastflag;
+         i = getccol(FALSE);
+ 	gotobol(f,n);
+ 
+ 	lastflag = thisflag;
+ 	thisflag = 0;
+ 	setmark(f,n);
+ 
+ 	lastflag = thisflag;
+ 	thisflag = 0;
+ 	forwline(f,n);
+ 
+ 	lastflag = i1;		/* This so if several lines are killed at the */
+ 	thisflag = 0;		/* same time, they will all go into the same  */
+ 	killregion(f, n);	/* kill buffer				      */
+ 
+ 	curgoal = i;
+ 	curwp->w_doto = getgoal(curwp->w_dotp);
+ 
+ 	lastflag = i1;
+ 	return(TRUE);
+ }
+ 
+ 
  /*
   * Delete all of the text saved in the kill buffer. Called by commands when a
   * new kill context is being created. The kill buffer array is released, just
diff -cbr src-orig/main.c src/main.c
*** src-orig/main.c	Mon Dec 16 11:42:20 1991
--- src/main.c	Sun Dec 22 16:19:08 1991
***************
*** 218,227 ****
  #if WMCS
  		if (argv[carg][0] == ':') {
  #else
! 		if (argv[carg][0] == '-') {
  #endif
  			switch (argv[carg][1]) {
  				/* Process Startup macroes */
  				case 'c':	/* -c for changable file */
  				case 'C':
  					viewflag = FALSE;
--- 218,242 ----
  #if WMCS
  		if (argv[carg][0] == ':') {
  #else
! 		if (argv[carg][0] == '-' || argv[carg][0] == '+') {
! 			/*		 ^^^^^^^^^^^^^^^^^^^^^^^   */
! 			/*		 added by J.Bayer to allow */
! 			/*		compatability with vi	   */
  #endif
+ /* J.Bayer, 9/22/88 */
+ 			if  (argv[carg][0] == '+') {	/* + to emulate vi */
+ 					gotoflag = TRUE;
+ 					gline = asc_int(&argv[carg][1]);
+ 			} else
  			switch (argv[carg][1]) {
  				/* Process Startup macroes */
+ #ifdef	BACKUP
+ 						/* J. Bayer	9/22/88 */
+ 				case 'b':	/* -b for no bakfile creation */
+ 				case 'B':
+ 					bakfile = FALSE;
+ 					break;
+ #endif
  				case 'c':	/* -c for changable file */
  				case 'C':
  					viewflag = FALSE;
***************
*** 881,886 ****
--- 896,902 ----
  	prefix |= META;
  	prenum = n;
  	predef = f;
+ 	thisflag = lastflag; /* jbayer */
  	return(TRUE);
  }
  
***************
*** 892,897 ****
--- 908,914 ----
  	prefix |= CTLX;
  	prenum = n;
  	predef = f;
+ 	thisflag = lastflag; /* jbayer */
  	return(TRUE);
  }
  
diff -cbr src-orig/mouse.c src/mouse.c
*** src-orig/mouse.c	Mon Dec 16 11:42:20 1991
--- src/mouse.c	Sun Dec 22 16:19:10 1991
***************
*** 600,605 ****
--- 600,607 ----
  int row;
  
  {
+ 	if (wp==NULL)
+ 		return(FALSE);
  	if (row == wp->w_toprow+wp->w_ntrows && modeflag)
  		return(TRUE);
  	return(FALSE);
diff -cbr src-orig/msdos.c src/msdos.c
*** src-orig/msdos.c	Mon Dec 16 11:42:20 1991
--- src/msdos.c	Sun Dec 22 16:19:12 1991
***************
*** 27,32 ****
--- 27,33 ----
  struct ffblk fileblock;	/* structure for directory searches */
  #endif
  #if	MSC | ZTC
+ #include <direct.h>
  #include <dos.h>
  
  struct find_t fileblock;	/* structure for directory searches */
***************
*** 42,47 ****
--- 43,55 ----
  #include	<process.h>
  #endif
  
+ #if     MSC
+ #ifdef SWAPLIB
+ #include <swaplib.h>
+ #define spawnl(m, n1, n2, a, x)  swap_spawnlp(n1, n2, a, x)
+ #endif
+ #endif
+ 
  /*	Some global variable	*/
  #define INBUFSIZ	40
  static int mexist;	/* is the mouse driver installed? */
***************
*** 114,120 ****
  #if	MSC | TURBO | DTL | LATTICE | MWC
  	int86x(0x21, &rg, &rg, &segreg);
  	miaddr = (((long)segreg.es) << 16) + (long)rg.x.bx;
! 	if (miaddr == 0 || *(char * far)miaddr == 0xcf) {
  #endif
  #if	ZTC
  	int86x(0x21, &rg, &rg, &segreg);
--- 122,128 ----
  #if	MSC | TURBO | DTL | LATTICE | MWC
  	int86x(0x21, &rg, &rg, &segreg);
  	miaddr = (((long)segreg.es) << 16) + (long)rg.x.bx;
! 	if (miaddr == 0 || *(char far *) miaddr == 0xcf) {
  #endif
  #if	ZTC
  	int86x(0x21, &rg, &rg, &segreg);
***************
*** 440,449 ****
--- 448,459 ----
          movecursor(term.t_nrow, 0);             /* Seek to last line.   */
          TTflush();
  	TTkclose();
+ 	TTclose();						   /* -- ZU */
  	shellprog("");
  #if	WINDOW_TEXT
  	refresh_screen(first_screen);
  #endif
+ 	TTopen();						   /* -- ZU */
  	TTkopen();
          sgarbf = TRUE;
          return(TRUE);
***************
*** 470,476 ****
--- 480,488 ----
                  return(s);
  	movecursor(term.t_nrow - 1, 0);
  	TTkclose();
+ 	TTclose();
          shellprog(line);
+ 	TTopen();
  	TTkopen();
  
  	/* if we are interactive, pause here */
***************
*** 493,499 ****
   */
  
  PASCAL NEAR execprg(f, n)
! 
  {
          register int s;
          char line[NLINE];
--- 505,511 ----
   */
  
  PASCAL NEAR execprg(f, n)
! int f, n;
  {
          register int s;
          char line[NLINE];
***************
*** 506,515 ****
--- 518,529 ----
                  return(s);
  	movecursor(term.t_nrow - 1, 0);
  	TTkclose();
+ 	TTclose();						   /* -- ZU */
          execprog(line);
  #if	WINDOW_TEXT
  	refresh_screen(first_screen);
  #endif
+ 	TTopen();						   /* -- ZU */
  	TTkopen();
  	/* if we are interactive, pause here */
  	if (clexec == FALSE) {
***************
*** 579,588 ****
--- 593,604 ----
  
  	/* execute the command */
  	TTkclose();
+ 	TTclose();
          shellprog(line);
  #if	WINDOW_TEXT
  	refresh_screen(first_screen);
  #endif
+ 	TTopen();
  	TTkopen();
          sgarbf = TRUE;
  
***************
*** 657,666 ****
--- 673,684 ----
  	strcat(line," <fltinp >fltout");
  	movecursor(term.t_nrow - 1, 0);
  	TTkclose();
+ 	TTclose();
          shellprog(line);
  #if	WINDOW_TEXT
  	refresh_screen(first_screen);
  #endif
+ 	TTopen();
  	TTkopen();
          sgarbf = TRUE;
  	s = TRUE;
***************
*** 711,720 ****
--- 729,742 ----
  	char *getenv();
  
  	/*  detect current switch character and set us up to use it */
+ #if 0
  	regs.h.ah = 0x37;	/*  get setting data  */
  	regs.h.al = 0x00;	/*  get switch character  */
  	intdos(&regs, &regs);
  	swchar = (char)regs.h.dl;
+ #else
+ 	swchar = '/';
+ #endif
  
  	/*  get name of system shell  */
  	if ((shell = getenv("COMSPEC")) == NULL) {
***************
*** 754,764 ****
  char *cmd;	/*  Incoming command line to execute  */
  
  {
! 	char *sp;		/* temporary string pointer */
  	char f1[38];		/* FCB1 area (not initialized */
  	char f2[38];		/* FCB2 area (not initialized */
- 	char prog[NSTRING];	/* program filespec */
- 	char tail[NSTRING];	/* command tail with length byte */
  	union REGS regs;	/* parameters for dos call  */
  #if	MWC == 0
  	struct SREGS segreg;	/* segment registers for dis call */
--- 776,784 ----
  char *cmd;	/*  Incoming command line to execute  */
  
  {
! #ifndef NEWSPAWN
  	char f1[38];		/* FCB1 area (not initialized */
  	char f2[38];		/* FCB2 area (not initialized */
  	union REGS regs;	/* parameters for dos call  */
  #if	MWC == 0
  	struct SREGS segreg;	/* segment registers for dis call */
***************
*** 769,774 ****
--- 789,799 ----
  		char *fcb1;	/* 4 byte pointer to FCB at PSP+5Ch */
  		char *fcb2;	/* 4 byte pointer to FCB at PSP+6Ch */
  	} pblock;
+ #endif
+ 	char *sp;		/* temporary string pointer */
+ 	char prog[NSTRING];	/* program filespec */
+ 	char tail[NSTRING];	/* command tail with length byte */
+ 	char curdir[NFILEN];	/* current directory save space */
  
  	/* parse the command name from the command line */
  	sp = prog;
***************
*** 776,781 ****
--- 801,807 ----
  		*sp++ = *cmd++;
  	*sp = 0;
  
+ #ifndef NEWSPAWN
  	/* and parse out the command tail */
  	while (*cmd && ((*cmd == ' ') || (*cmd == '\t')))
  		++cmd;
***************
*** 782,787 ****
--- 808,814 ----
  	*tail = (char)(strlen(cmd)); /* record the byte length */
  	strcpy(&tail[1], cmd);
  	strcat(&tail[1], "\r");
+ #endif
  
  	/* look up the program on the path trying various extentions */
  	if ((sp = flook(prog, TRUE)) == NULL)
***************
*** 792,797 ****
--- 819,827 ----
  		}
  	strcpy(prog, sp);
  
+ 	getcwd(curdir, sizeof(curdir));		/* save current directory */
+ 
+ #ifndef NEWSPAWN
  #if	MWC == 0
  	/* get a pointer to this PSPs environment segment number */
  	segread(&segreg);
***************
*** 858,863 ****
--- 888,897 ----
  	} else
  		rval = -_doserrno;	/* failed child call */
  #endif
+ #else
+         rval = spawnl(P_WAIT, prog, prog, cmd, NULL);
+ #endif
+ 	chdir( curdir );		/* restore current directory */
  	return((rval < 0) ? FALSE : TRUE);
  }
  
***************
*** 1052,1054 ****
--- 1086,1105 ----
  #endif
  #endif
  #endif
+ 
+ #if	CHDIR
+ changecwd(dir)
+ char *dir;
+ {
+ 	char drive[5];
+ 	unsigned total;
+ 
+ 	_splitpath(dir, drive, NULL, NULL, NULL);
+ 
+ 	if ( drive[0] != 0 )
+ 		_dos_setdrive(toupper(drive[0]) - '@', &total);
+ 
+ 	chdir(dir);
+ }
+ #endif
+ 
diff -cbr src-orig/os2.c src/os2.c
*** src-orig/os2.c	Mon Dec 16 11:42:20 1991
--- src/os2.c	Sun Dec 22 16:42:30 1991
***************
*** 11,16 ****
--- 11,18 ----
  
  */
  
+ #define INCL_BASE
+ #define INCL_NOPM
  #define INCL_DOS
  #include "os2.h"
  
***************
*** 19,35 ****
  #undef	PASCAL
  #undef	NEAR
  #undef	HIBYTE
  
  #include	"estruct.h"
  #include	"eproto.h"
  
  #if	OS2
- #define INCL_BASE
  
  #include "elang.h"
  #include "edef.h"
  
  
  /*
   * Create a subjob with a copy of the command intrepreter in it. When the
   * command interpreter exits, mark the screen as garbage so that you do a full
--- 21,39 ----
  #undef	PASCAL
  #undef	NEAR
  #undef	HIBYTE
+ #undef	COLOR
  
  #include	"estruct.h"
  #include	"eproto.h"
  
  #if	OS2
  
  #include "elang.h"
  #include "edef.h"
  
+ #include <process.h>
  
+ 
  /*
   * Create a subjob with a copy of the command intrepreter in it. When the
   * command interpreter exits, mark the screen as garbage so that you do a full
***************
*** 37,42 ****
--- 41,47 ----
   * Under some (unknown) condition, you don't get one free when DCL starts up.
   */
  spawncli(f, n)
+ int f, n;
  {
  	/* don't allow this command if restricted */
  	if (restflag)
***************
*** 58,63 ****
--- 63,69 ----
   * done. Bound to "C-X !".
   */
  spawn(f, n)
+ int f, n;
  {
          register int s;
          char line[NLINE];
***************
*** 90,95 ****
--- 96,102 ----
   */
  
  execprg(f, n)
+ int f, n;
  {
          register int s;
          char line[NLINE];
***************
*** 121,126 ****
--- 128,134 ----
   * MicroEMACS don't try to use the same file.
   */
  pipecmd(f, n)
+ int f, n;
  {
  	register WINDOW *wp;	/* pointer to new window */
  	register BUFFER *bp;	/* pointer to buffer to zot */
***************
*** 211,217 ****
   * MicroEMACS don't try to use the same file.
   */
  filter(f, n)
! 
  {
  	register int    s;	/* return status from CLI */
  	register BUFFER *bp;	/* pointer to buffer to zot */
--- 219,225 ----
   * MicroEMACS don't try to use the same file.
   */
  filter(f, n)
! int f, n;
  {
  	register int    s;	/* return status from CLI */
  	register BUFFER *bp;	/* pointer to buffer to zot */
***************
*** 308,318 ****
  		return(FALSE);		/*  No shell located  */
  	}
  
! 	/*
! 	 * We are actually setting up a shell inside a shell here.
! 	 * Is there a better way?
! 	 */
! 	return(system(shell));
  }
  
  
--- 316,322 ----
  		return(FALSE);		/*  No shell located  */
  	}
  
! 	return(spawnl(P_WAIT, shell, shell, NULL));
  }
  
  
***************
*** 324,330 ****
  	char		 failName[NFILEN];
  	char		 prog[NSTRING];		/* name of program */
  	USHORT		 i;
! 	PRESULTCODES	 results;
  	
  
  	/*
--- 328,334 ----
  	char		 failName[NFILEN];
  	char		 prog[NSTRING];		/* name of program */
  	USHORT		 i;
!         RESULTCODES      results;
  	
  
  	/*
***************
*** 352,360 ****
--- 356,367 ----
  	if ((sp = flook(prog, TRUE)) == NULL)
  		if ((sp = flook(strcat(prog, ".exe"), TRUE)) == NULL) {
  			strcpy(&prog[strlen(prog)-4], ".com");
+ 			if ((sp = flook(prog, TRUE)) == NULL) {
+ 			        strcpy(&prog[strlen(prog)-4], ".cmd");
  			if ((sp = flook(prog, TRUE)) == NULL)
  				return(FALSE);
  		}
+ 		}
  	strcpy(prog, sp);
  
  	/*
***************
*** 361,374 ****
  	 * Execute the program synchronously.  We wait for child
  	 * to return.
  	 */
! 	return (0 == DosExecPgm( failName, NFILEN, EXEC_SYNC,
! 					 args, 0, results, prog));
  }
  
  	
  /*	FILE Directory routines		*/
  
! FILEFINDBUF pBuf;	/* buffer to hold file information */
  HDIR hDir;		/* directory handle */
  int num_found;		/* number of directory entries found/to find */
  
--- 368,381 ----
  	 * Execute the program synchronously.  We wait for child
  	 * to return.
  	 */
!         return (0 == DosExecPgm(failName, sizeof(failName), EXEC_SYNC,
! 			  	args, 0, &results, prog));
  }
  
  	
  /*	FILE Directory routines		*/
  
! FILEFINDBUF fbuf;	/* buffer to hold file information */
  HDIR hDir;		/* directory handle */
  int num_found;		/* number of directory entries found/to find */
  
***************
*** 415,430 ****
  
  	/* and call for the first file */
  	num_found = 1;
! 	hDir = HDIR_CREATE;
  	if (DosFindFirst(fname, &hDir, FILE_NORMAL|FILE_DIRECTORY,
! 			  &pBuf, sizeof(pBuf), &num_found, 0L) != 0)
  		return(NULL);
  
  	/* return the first file name! */
  	strcpy(rbuf, path);
! 	strcat(rbuf, pBuf.achName);
! 	mklower(rbuf);
! 	if (pBuf.attrFile == FILE_DIRECTORY)
  		strcat(rbuf, DIRSEPSTR);
  	return(rbuf);
  }
--- 422,437 ----
  
  	/* and call for the first file */
  	num_found = 1;
! 	hDir = HDIR_SYSTEM;
  	if (DosFindFirst(fname, &hDir, FILE_NORMAL|FILE_DIRECTORY,
! 			  &fbuf, sizeof(fbuf), &num_found, 0L) != 0)
  		return(NULL);
  
  	/* return the first file name! */
  	strcpy(rbuf, path);
! 	strcat(rbuf, fbuf.achName);
! 	/* mklower(rbuf); */
! 	if (fbuf.attrFile == FILE_DIRECTORY)
  		strcat(rbuf, DIRSEPSTR);
  	return(rbuf);
  }
***************
*** 438,451 ****
  	char fname[NFILEN];		/* file/path for DOS call */
  
  	/* and call for the next file */
! 	if (DosFindNext(hDir, (void *)&pBuf, sizeof(pBuf), &num_found) != 0)
  		return(NULL);
  
  	/* return the first file name! */
  	strcpy(rbuf, path);
! 	strcat(rbuf, pBuf.achName);
! 	mklower(rbuf);
! 	if (pBuf.attrFile == FILE_DIRECTORY)
  		strcat(rbuf, DIRSEPSTR);
  	return(rbuf);
  }
--- 445,458 ----
  	char fname[NFILEN];		/* file/path for DOS call */
  
  	/* and call for the next file */
! 	if (DosFindNext(hDir, (void *)&fbuf, sizeof(fbuf), &num_found) != 0)
  		return(NULL);
  
  	/* return the first file name! */
  	strcpy(rbuf, path);
! 	strcat(rbuf, fbuf.achName);
! 	/* mklower(rbuf); */
! 	if (fbuf.attrFile == FILE_DIRECTORY)
  		strcat(rbuf, DIRSEPSTR);
  	return(rbuf);
  }
***************
*** 465,567 ****
  	return(sp);
  }
  
! #if	OBSOLETE
! /*	extcode:	resolve MSDOS extended character codes
! 			encoding the proper sequences into emacs
! 			printable character specifications
! */
! 
! int extcode(
! 	unsigned c	/* byte following a zero extended char byte */
! )
! 
! {
! 	/* function keys 1 through 9 */
! 	if (c >= 59 && c < 68)
! 		return(SPEC | c - 58 + '0');
! 
! 	/* function key 10 */
! 	if (c == 68)
! 		return(SPEC | '0');
! 
! 	/* shifted function keys */
! 	if (c >= 84 && c < 93)
! 		return(SPEC | SHFT | c - 83 + '0');
! 	if (c == 93)
! 		return(SPEC | SHFT | '0');
! 
! 	/* control function keys */
! 	if (c >= 94 && c < 103)
! 		return(SPEC | CTRL | c - 93 + '0');
! 	if (c == 103)
! 		return(SPEC | CTRL | '0');
! 
! 	/* ALTed function keys */
! 	if (c >= 104 && c < 113)
! 		return(SPEC | ALTD | c - 103 + '0');
! 	if (c == 113)
! 		return(SPEC | ALTD | '0');
! 
! 	/* ALTed number keys */
! 	if (c >= 120 && c < 129)
! 		return(ALTD | c - 119 + '0');
! 	if (c == 130)
! 		return(ALTD | '0');
! 
! 	/* some others as well */
! 	switch (c) {
! 		case 3:		return(0);		/* null */
! 		case 15:	return(SHFT | CTRL | 'I');	/* backtab */
! 
! 		case 16:	return(ALTD | 'Q');
! 		case 17:	return(ALTD | 'W');
! 		case 18:	return(ALTD | 'E');
! 		case 19:	return(ALTD | 'R');
! 		case 20:	return(ALTD | 'T');
! 		case 21:	return(ALTD | 'Y');
! 		case 22:	return(ALTD | 'U');
! 		case 23:	return(ALTD | 'I');
! 		case 24:	return(ALTD | 'O');
! 		case 25:	return(ALTD | 'P');
! 
! 		case 30:	return(ALTD | 'A');
! 		case 31:	return(ALTD | 'S');
! 		case 32:	return(ALTD | 'D');
! 		case 33:	return(ALTD | 'F');
! 		case 34:	return(ALTD | 'G');
! 		case 35:	return(ALTD | 'H');
! 		case 36:	return(ALTD | 'J');
! 		case 37:	return(ALTD | 'K');
! 		case 38:	return(ALTD | 'L');
! 
! 		case 44:	return(ALTD | 'Z');
! 		case 45:	return(ALTD | 'X');
! 		case 46:	return(ALTD | 'C');
! 		case 47:	return(ALTD | 'V');
! 		case 48:	return(ALTD | 'B');
! 		case 49:	return(ALTD | 'N');
! 		case 50:	return(ALTD | 'M');
! 
! 		case 71:	return(SPEC | '<');	/* HOME */
! 		case 72:	return(SPEC | 'P');	/* cursor up */
! 		case 73:	return(SPEC | 'Z');	/* page up */
! 		case 75:	return(SPEC | 'B');	/* cursor left */
! 		case 77:	return(SPEC | 'F');	/* cursor right */
! 		case 79:	return(SPEC | '>');	/* end */
! 		case 80:	return(SPEC | 'N');	/* cursor down */
! 		case 81:	return(SPEC | 'V');	/* page down */
! 		case 82:	return(SPEC | 'C');	/* insert */
! 		case 83:	return(SPEC | 'D');	/* delete */
! 		case 115:	return(SPEC | CTRL | 'B');	/* control left */
! 		case 116:	return(SPEC | CTRL | 'F');	/* control right */
! 		case 117:	return(SPEC | CTRL | '>');	/* control END */
! 		case 118:	return(SPEC | CTRL | 'V');	/* control page down */
! 		case 119:	return(SPEC | CTRL | '<');	/* control HOME */
! 		case 132:	return(SPEC | CTRL | 'Z');	/* control page up */
! 	}
  
! 	return(ALTD | c);
  }
! #endif	/* obsolete */
  #endif
  
--- 472,492 ----
  	return(sp);
  }
  
! 
! #if	CHDIR
! changecwd(dir)
! char *dir;
! {
! 	char drive[5];
  
! 	_splitpath(dir, drive, NULL, NULL, NULL);
! 
! 	if ( drive[0] != 0 )
!                 DosSelectDisk(toupper(drive[0]) - '@');
! 
! 	chdir(dir);
  }
! #endif
! 
  #endif
  
diff -cbr src-orig/os2npm.c src/os2npm.c
*** src-orig/os2npm.c	Mon Dec 16 11:42:20 1991
--- src/os2npm.c	Sun Dec 22 16:19:16 1991
***************
*** 12,17 ****
--- 12,18 ----
   */
  
  #define INCL_BASE
+ #define INCL_NOPM
  #include	<os2.h>
  
  #define	termdef	1			/* don't define "term" external */
***************
*** 18,23 ****
--- 19,25 ----
  
  #include	<stdio.h>
  
+ #undef  COLOR
  #undef	PASCAL
  #undef	NEAR
  #undef	HIBYTE
***************
*** 33,41 ****
   * We need COLOR as defined in estruct.h, so edit it out of os2def.h.
   */
  #include	<conio.h>
  
! #define	NROW    50		/* Screen size.                 */
! #define	NCOL    80		/* Edit if you want to.         */
  #define	MARGIN	8		/* size of minimim margin and	*/
  #define	SCRSIZ	64		/* scroll size for extended lines */
  #define	NPAUSE	100		/* # times thru update to pause */
--- 35,44 ----
   * We need COLOR as defined in estruct.h, so edit it out of os2def.h.
   */
  #include	<conio.h>
+ #include <stdlib.h>
  
! #define	NROW    128		/* Screen size.                 */
! #define	NCOL    140		/* Edit if you want to.         */
  #define	MARGIN	8		/* size of minimim margin and	*/
  #define	SCRSIZ	64		/* scroll size for extended lines */
  #define	NPAUSE	100		/* # times thru update to pause */
***************
*** 47,56 ****
  
  #define NDRIVE	4		/* number of video modes	*/
  
! int dtype = -1;				/* current video mode	*/
! char drvname[][8] = {			/* names of video modes	*/
! 	"CGA", "MONO", "EGA", "VGA"
! };
  
  /* Forward references.          */
  
--- 50,57 ----
  
  #define NDRIVE	4		/* number of video modes	*/
  
! int mono = 0;
! 
  
  /* Forward references.          */
  
***************
*** 84,91 ****
  } os2rcell = {0, 0x07};
  
  static struct {				/* initial states		*/
- 	USHORT		ansiState;	/* ANSI translation		*/
- 	VIOCONFIGINFO	vioConfigInfo;	/* video configuration		*/
  	VIOMODEINFO	vioModeInfo;	/* video mode			*/
  	KBDINFO		kbdInfo;	/* keyboard info		*/
  } initial;
--- 85,90 ----
***************
*** 153,159 ****
  PASCAL NEAR os2fcol(
  	int color)			/* color to set */
  {
! 	if (dtype != CDMONO)
  		cfcolor = ctrans[color];
  	else
  		cfcolor = 7;
--- 152,158 ----
  PASCAL NEAR os2fcol(
  	int color)			/* color to set */
  {
! 	if (!mono)
  		cfcolor = ctrans[color];
  	else
  		cfcolor = 7;
***************
*** 175,181 ****
  PASCAL NEAR os2bcol(
  	int color)		/* color to set */
  {
! 	if (dtype != CDMONO)
  		cbcolor = ctrans[color];
  	else
  		cbcolor = 0;
--- 174,180 ----
  PASCAL NEAR os2bcol(
  	int color)		/* color to set */
  {
! 	if (!mono)
  		cbcolor = ctrans[color];
  	else
  		cbcolor = 0;
***************
*** 202,208 ****
--- 201,225 ----
  {
  	os2row = row;
  	os2col = col;
+         if ( _osmode == OS2_MODE )
  	VioSetCurPos(os2row, os2col, 0);
+         else
+           _asm
+           {
+             mov ah,2
+             mov bh,0
+             mov dh,byte ptr os2row
+             mov dl,byte ptr os2col
+             int 0x10
+           }
+ }
+ 
+ os2vmove(                    /* speedup for special case in updateline */
+ 	int row,
+ 	int col)
+ {
+ 	os2row = row;
+ 	os2col = col;
  }
  
  
***************
*** 215,221 ****
  {
  	if (lvbMin <= lvbMax) {		/* did anything change?	*/
  		VioShowBuf(lvbMin * 2, (lvbMax - lvbMin + 1) * 2, 0);
! 		VioSetCurPos(os2row, os2col, 0);
  	}
  	lvbMin = lvbLen;
  	lvbMax = 0;
--- 232,238 ----
  {
  	if (lvbMin <= lvbMax) {		/* did anything change?	*/
  		VioShowBuf(lvbMin * 2, (lvbMax - lvbMin + 1) * 2, 0);
! 		os2move(os2row, os2col);
  	}
  	lvbMin = lvbLen;
  	lvbMax = 0;
***************
*** 256,262 ****
  
  	/* Function, edit or alt- key?	*/
  	if (keyInfo.chChar == 0  ||  keyInfo.chChar == 0xE0) {
! 		nextc = extcode(keyInfo.chScan); /* hold on to scan code */
  		return(0);
  	}
  	return(keyInfo.chChar & 255);
--- 273,280 ----
  
  	/* Function, edit or alt- key?	*/
  	if (keyInfo.chChar == 0  ||  keyInfo.chChar == 0xE0) {
! 		nextc = extcode(keyInfo.chScan | (keyInfo.chChar << 8));
! 		/* hold on to scan code */
  		return(0);
  	}
  	return(keyInfo.chChar & 255);
***************
*** 294,300 ****
  	USHORT	i;
  
  	if (c == '\n' || c == '\r') {		/* returns and linefeeds */
! 		return;
  	}
  	if (c == '\b') {			/* backspace		*/
  		cell = ' ' | (revflag ? *(USHORT *)&os2rcell : *(USHORT *)&os2cell);
--- 312,318 ----
  	USHORT	i;
  
  	if (c == '\n' || c == '\r') {		/* returns and linefeeds */
! 		return 0;
  	}
  	if (c == '\b') {			/* backspace		*/
  		cell = ' ' | (revflag ? *(USHORT *)&os2rcell : *(USHORT *)&os2cell);
***************
*** 347,353 ****
  	USHORT  i;
  
  #if COLOR
! 	if (dtype != CDMONO)
  		cell |= (ctrans[gbcolor] << 4 | ctrans[gfcolor]) << 8;
  	else
  		cell |= 0x0700;
--- 365,371 ----
  	USHORT  i;
  
  #if COLOR
! 	if (!mono)
  		cell |= (ctrans[gbcolor] << 4 | ctrans[gfcolor]) << 8;
  	else
  		cell |= 0x0700;
***************
*** 382,425 ****
  /* Change the screen resolution.					*/
  /*----------------------------------------------------------------------*/
  
  PASCAL NEAR os2cres(char *res)		/* name of desired video mode	*/
  {
! 	USHORT	err;
! 	int	type;			/* video mode type	*/
  	VIOMODEINFO vioModeInfo;
  
  	vioModeInfo = initial.vioModeInfo;
  	
! 	/* From the name, find the type of video mode.	*/
! 	for (type = 0; type < NDRIVE; type++) {
! 		if (strcmp(res, drvname[type]) == 0)
! 			break;
! 	}
! 	if (type == NDRIVE)
! 		return(FALSE);	/* not a mode we know about	*/
! 
! 		
! 	switch (type) {
! 		case CDMONO:
! 		case CDCGA:
! 			vioModeInfo.row = 25;
! 			break;
! 		case CDEGA:
! 			vioModeInfo.row = 43;
! 			break;
! 		case CDVGA:
! 			vioModeInfo.row = 50;
! 			break;
! 	}
  	
! 	if (VioSetMode(&vioModeInfo, 0))	/* change modes 	*/
! 		return(FALSE);			/* couldn't do it	*/
  
  	newsize(TRUE, vioModeInfo.row);
  
  	/* reset the $sres environment variable */
! 	strcpy(sres, drvname[type]);
! 	dtype = type;				/* set the current mode	*/
  	
  	return TRUE;
  }
--- 400,461 ----
  /* Change the screen resolution.					*/
  /*----------------------------------------------------------------------*/
  
+ static int checkmode(VIOMODEINFO *vmi, int scans, int lines, int font)
+ {
+         int diff = scans - lines * font;
+ 
+         if ( (0 <= diff) && (diff < font) )
+         {
+                 vmi -> vres = scans;
+                 vmi -> row = lines;
+                 return(TRUE);
+         }
+         else
+                 return(FALSE);
+ 
+ }
+ 
  PASCAL NEAR os2cres(char *res)		/* name of desired video mode	*/
  {
! 	USHORT	lines;
  	VIOMODEINFO vioModeInfo;
  
+         if ( ((lines = atoi(res)) < 16) || (lines >= NROW) )
+           return(FALSE);
+ 
  	vioModeInfo = initial.vioModeInfo;
+         vioModeInfo.vres = vioModeInfo.vres / vioModeInfo.row * lines;
+         vioModeInfo.row = lines;
  	
! 	if (VioSetMode(&vioModeInfo, 0))
!         {
!                 /* only 350, 400 or 480 scan lines allowed ? */
!                 /* (i.e. full screen) */
!  	        vioModeInfo = initial.vioModeInfo;
! 
!                 if ( !(checkmode(&vioModeInfo, 480, lines, 16) ||
!                        checkmode(&vioModeInfo, 480, lines, 14) ||
!                        checkmode(&vioModeInfo, 480, lines,  8) ||
!                        checkmode(&vioModeInfo, 400, lines, 16) ||
!                        checkmode(&vioModeInfo, 400, lines, 14) ||
!                        checkmode(&vioModeInfo, 400, lines,  8) ||
!                        checkmode(&vioModeInfo, 350, lines, 16) ||
!                        checkmode(&vioModeInfo, 350, lines, 14) ||
!                        checkmode(&vioModeInfo, 350, lines,  8))   )
!                         return(FALSE);
  	
!                 vioModeInfo.hres = (vioModeInfo.vres == 350) ? 640 : 720;
  
+ 	        if (VioSetMode(&vioModeInfo, 0))
+                         return(FALSE);
+         }
+ 
+ 	VioGetMode(&vioModeInfo, 0);
+         term.t_ncol = vioModeInfo.col;
  	newsize(TRUE, vioModeInfo.row);
  
  	/* reset the $sres environment variable */
! 	itoa(vioModeInfo.row, sres, 10);
  	
  	return TRUE;
  }
***************
*** 454,486 ****
  
  PASCAL NEAR os2open()
  {
! 	initial.vioConfigInfo.cb = 0x0A;
! 	VioGetConfig(0, &initial.vioConfigInfo, 0);
! 	switch (initial.vioConfigInfo.adapter) {
! 		case 3:
! 			dtype = CDVGA;
! 			break;
! 		case 2:
! 			dtype = CDEGA;
! 			break;
! 		case 1:
! 			dtype = CDCGA;
! 			break;
! 		case 0:
! 		default:
! 			dtype = CDMONO;
! 	}
! 	strcpy(sres, drvname[dtype]);
  
! 	initial.vioModeInfo.cb = 0x0E;
  	VioGetMode(&initial.vioModeInfo, 0);
! 	newsize(TRUE, initial.vioModeInfo.row);
  			
! 	VioGetAnsi(&initial.ansiState, 0);
  	VioGetBuf((PULONG)&lvb, &lvbLen, 0);
  	lvbMin = lvbLen;
  	lvbMax = 0;
  
  	revexist = TRUE;
  	revflag = FALSE;
  }
--- 490,531 ----
  
  PASCAL NEAR os2open()
  {
! 	VIOINTENSITY vi;
! 	PFNSIGHANDLER oldhandler;
! 	USHORT oldact;
  
! 	initial.vioModeInfo.cb = sizeof(initial.vioModeInfo);
  	VioGetMode(&initial.vioModeInfo, 0);
!         mono = (initial.vioModeInfo.color == COLORS_2);
! 
!         if ( _osmode == OS2_MODE )
!         {
!           term.t_ncol = initial.vioModeInfo.col;
!           term.t_nrow = initial.vioModeInfo.row;
!         }
!         else
!         {
!           term.t_ncol = *((char *) 0x0040004AL);
!           term.t_nrow = *((char *) 0x00400084L) + 1;
!         }
! 
! 	newsize(TRUE, term.t_nrow);
! 	itoa(term.t_nrow + 1, sres, 10);
  			
!         vi.cb = sizeof(vi);
!         vi.type = 2;
!         vi.fs = 1;
!         VioSetState(&vi, 0);
! 
  	VioGetBuf((PULONG)&lvb, &lvbLen, 0);
  	lvbMin = lvbLen;
  	lvbMax = 0;
  
+ 	DosSetSigHandler((PFNSIGHANDLER) NULL, &oldhandler, &oldact,
+ 	                 SIGA_IGNORE, SIG_CTRLBREAK);
+ 	DosSetSigHandler((PFNSIGHANDLER) NULL, &oldhandler, &oldact,
+ 	                 SIGA_IGNORE, SIG_CTRLC);
+ 
  	revexist = TRUE;
  	revflag = FALSE;
  }
***************
*** 493,502 ****
  
  PASCAL NEAR os2close()
  {
! 	VioSetAnsi(initial.ansiState, 0);
  	VioSetMode(&initial.vioModeInfo, 0);
  	VioSetCurPos(initial.vioModeInfo.row - 1,
  			 initial.vioModeInfo.col - 1, 0);
  }
  
  /*----------------------------------------------------------------------*/
--- 538,551 ----
  
  PASCAL NEAR os2close()
  {
!         if ( _osmode == OS2_MODE )
!         {
  	VioSetMode(&initial.vioModeInfo, 0);
  	VioSetCurPos(initial.vioModeInfo.row - 1,
  			 initial.vioModeInfo.col - 1, 0);
+         }
+         else
+           os2move(term.t_nrow - 1, term.t_ncol - 1);
  }
  
  /*----------------------------------------------------------------------*/
***************
*** 508,514 ****
  {
  	KBDINFO	kbdInfo;
  
! 	initial.kbdInfo.cb = 0x000A;
  	KbdGetStatus(&initial.kbdInfo, 0);	
  	kbdInfo = initial.kbdInfo;
  	kbdInfo.fsMask &= ~0x0001;		/* not echo on		*/
--- 557,563 ----
  {
  	KBDINFO	kbdInfo;
  
! 	initial.kbdInfo.cb = sizeof(initial.kbdInfo);
  	KbdGetStatus(&initial.kbdInfo, 0);	
  	kbdInfo = initial.kbdInfo;
  	kbdInfo.fsMask &= ~0x0001;		/* not echo on		*/
diff -cbr src-orig/random.c src/random.c
*** src-orig/random.c	Mon Dec 16 11:42:22 1991
--- src/random.c	Sun Dec 22 16:19:18 1991
***************
*** 265,270 ****
--- 265,289 ----
                  stabsize = n;
                  return(TRUE);
          }
+ 
+ #if	SOFTAB
+ 
+ 	if (curwp->w_bufp->b_mode & MDOVER)  {
+ 		if (! tabsize) {
+            		curgoal = getccol(FALSE) | 0x07;
+ 	   		curgoal++;
+ 	   	}
+ 	   	else {
+ 		   	curgoal = tabsize - (getccol(FALSE) % tabsize) + getccol(FALSE);
+ 		}
+ 
+ 		curwp->w_doto =  getgoal(curwp->w_dotp);
+    		return(TRUE);
+ 	}
+ 
+ #endif
+ 
+ 
          if (!stabsize)
                  return(linsert(1, '\t'));
          return(linsert(stabsize - (getccol(FALSE) % stabsize), ' '));
***************
*** 451,456 ****
--- 470,497 ----
          return(s);
  }
  
+ 
+ /*
+  * Toggle overwrite mode.  Bound to the ins key.
+  */
+ PASCAL	NEAR	toggleovermode(f, n)	/* toggle overwrite mode */
+ 
+ int	f, n;		/* default and argument */
+ 
+ {
+ 	if (curwp->w_bufp->b_mode & MDOVER)
+ 	{
+ 		curwp->w_bufp->b_mode &= ~MDOVER;
+ 		curwp->w_bufp->b_mode |= MDREPL;
+ 	}
+ 	else if (curwp->w_bufp->b_mode & MDREPL)
+ 		curwp->w_bufp->b_mode &= ~MDREPL;
+         else
+ 		curwp->w_bufp->b_mode |= MDOVER;
+ 	upmode();
+ }
+ 
+ 
  /*
   * Insert a newline. Bound to "C-M". If we are in CMODE, do automatic
   * indentation as specified.
***************
*** 462,467 ****
--- 503,517 ----
  {
  	register int    s;
  
+ #if	SOFTAB
+ 
+ 	if (curwp->w_bufp->b_mode & MDOVER)  {
+ 		gotobol(f,1);
+ 		thisflag = 0;
+ 		return(forwline(f,1));
+ 	}
+ #endif
+ 
  	if (curbp->b_mode&MDVIEW)	/* don't allow this command if	*/
  		return(rdonly());	/* we are in read only mode	*/
  	if (n < 0)
***************
*** 868,876 ****
  	register char *scan;		/* scanning pointer to convert prompt */
  	register int i;			/* loop index */
  	register int status;		/* error return on input */
- #if	COLOR
  	register int uflag;		/* was modename uppercase?	*/
- #endif
  	char prompt[50];	/* string to prompt user with */
  	char cbuf[NPAT];		/* buffer to recieve mode name into */
  
--- 918,924 ----
***************
*** 898,906 ****
  	/* make it uppercase */
  
  	scan = cbuf;
- #if	COLOR
  	uflag = (*scan >= 'A' && *scan <= 'Z');
- #endif
  	while (*scan)
  		uppercase(scan++);
  
--- 946,952 ----
diff -cbr src-orig/unix.c src/unix.c
*** src-orig/unix.c	Mon Dec 16 11:42:24 1991
--- src/unix.c	Sun Dec 22 17:12:10 1991
***************
*** 802,807 ****
--- 802,810 ----
  	int status;
  	struct capbind * cb;
  	struct keybind * kp;
+ #ifdef TIOCGWINSZ
+ 	struct winsize win;
+ #endif
  
  	char * getenv(), * tgetstr();
  #if HPUX
***************
*** 831,840 ****
  		exit(1);
  	}
  
  	/* Get size from termcap */
  	term.t_nrow = tgetnum("li") - 1;
  	term.t_ncol = tgetnum("co");
! 	if (term.t_nrow < 3 || term.t_ncol < 3) {
  		puts("Screen size is too small!");
  		exit(1);
  	}
--- 834,861 ----
  		exit(1);
  	}
  
+ 	term.t_nrow = -1;
+ 	term.t_ncol = -1;
+ 
+ #ifdef TIOCGWINSZ
+ 	if (ioctl (0, TIOCGWINSZ, &win) == 0) {
+ 		if (win.ws_col)
+ 			term.t_ncol = win.ws_col;
+ 		else
+ 			term.t_ncol = -1;
+ 		if (win.ws_row)
+ 			term.t_nrow = win.ws_row - 1;
+ 		else
+ 			term.t_nrow = -1;
+ 	}
+ #endif /* TIOCGWINSZ */
+ 
  	/* Get size from termcap */
+         if ( term.t_nrow == -1 )
  	term.t_nrow = tgetnum("li") - 1;
+         if ( term.t_ncol == -1 )
  	term.t_ncol = tgetnum("co");
! 	if (term.t_nrow < 15 || term.t_ncol < 64) {
  		puts("Screen size is too small!");
  		exit(1);
  	}
***************
*** 1537,1542 ****
--- 1558,1571 ----
  	/* Return the next file name! */
  	return(rbuf);
  }
+ 
+ #if	CHDIR
+ changecwd(dir)
+ char *dir;
+ {
+ 	chdir(dir);
+ }
+ #endif
  
  #if FLABEL
  int fnclabel(f, n)	/* label a function key */
diff -cbr src-orig/window.c src/window.c
*** src-orig/window.c	Mon Dec 16 11:42:24 1991
--- src/window.c	Sun Dec 22 16:19:20 1991
***************
*** 37,43 ****
--- 37,46 ----
  
  {
      if (f == FALSE)
+         {
  	sgarbf = TRUE;
+         thisflag = lastflag; /* jbayer */
+         }
      else
  	{
  	curwp->w_force = 0;		/* Center dot. */
