[gnu.emacs.bug] More fixes and goodies for Microport boxes

eric@UUNET.UU.NET (10/28/88)

Things contained in this patch:

	1. A corrected s- file for System V Release 3.0

	2. A rewrite of build-install in (portable!) Bourne shell

	3. Additions to your exclusion-suffix list

	4. Additions to keypad.el to fully support AT-style keyboards

	5. An AT386.el terminal package suitable for use on a 386 box
	   running Microport UNIX.

Here they are:

1. A slight glitch discovered while bringing up gnumacs on an 80386 under
Microport V/386: the s-usg5-3.h file defines HAVE_SOCKETS, HAVE_PTYS and
SYSTEMV_PTYS. These are not present in the Microport 3.0e, or, I think, in
other 5.3.0 releases. I made a new s-usg5-3-0.h file which follows:

---CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE--------
/* Definitions file for GNU Emacs running on AT&T's System V Release 3.0
   Copyright (C) 1987 Free Software Foundation, Inc.

This file is part of GNU Emacs.

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.  No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing.  Refer to the GNU Emacs General Public
License for full details.

Everyone is granted permission to copy, modify and redistribute
GNU Emacs, but only under the conditions described in the
GNU Emacs General Public License.   A copy of this license is
supposed to have been given to you along with GNU Emacs so you
can know your rights and responsibilities.  It should be in a
file named COPYING.  Among other things, the copyright notice
and this notice must be preserved on all copies.  */


/*
 *	Define symbols to identify the version of Unix this is.
 *	Define all the symbols that apply correctly.
 */

#define USG				/* System III, System V, etc */

#define USG5

/* SYSTEM_TYPE should indicate the kind of system you are using.
 It sets the Lisp variable system-type.  */

#define SYSTEM_TYPE "usg-unix-v"

/* nomultiplejobs should be defined if your system's shell
 does not have "job control" (the ability to stop a program,
 run some other program, then continue the first one).  */

#define NOMULTIPLEJOBS

/* Default is to set interrupt_input to 0: don't do input buffering within Emacs */

/* #define INTERRUPT_INPUT */

/* Letter to use in finding device name of first pty,
  if system supports pty's.  'p' means it is /dev/ptyp0  */

#define FIRST_PTY_LETTER 'p'

/*
 *	Define HAVE_TERMIO if the system provides sysV-style ioctls
 *	for terminal control.
 */

#define HAVE_TERMIO

/*
 *	Define HAVE_TIMEVAL if the system supports the BSD style clock values.
 *	Look in <sys/time.h> for a timeval structure.
 */

/* #define HAVE_TIMEVAL */
 
/*
 *	Define HAVE_SELECT if the system supports the `select' system call.
 */

/* #define HAVE_SELECT */

/*
 *	Define HAVE_PTYS if the system supports pty devices.
 */

/* #define HAVE_PTYS */
/* #define SYSV_PTYS */

/* Define HAVE_SOCKETS if system supports 4.2-compatible sockets.  */

/* #define HAVE_SOCKETS */

/*
 *	Define NONSYSTEM_DIR_LIBRARY to make Emacs emulate
 *      The 4.2 opendir, etc., library functions.
 */

/* #define NONSYSTEM_DIR_LIBRARY */

/*
 * 	Define SYSV_SYSTEM_DIR to use the V.3 getdents/readir
 *	library functions.  Almost, but not quite the same as
 *	the 4.2 functions
 */
#define SYSV_SYSTEM_DIR

/* Define this symbol if your system has the functions bcopy, etc. */

/* #define BSTRING */

/* subprocesses should be defined if you want to
 have code for asynchronous subprocesses
 (as used in M-x compile and M-x shell).
 This is supposed to work now on system V release 2.  */

#define subprocesses

/* If your system uses COFF (Common Object File Format) then define the
   preprocessor symbol "COFF". */

#define COFF

/* define MAIL_USE_FLOCK if the mailer uses flock
   to interlock access to /usr/spool/mail/$USER.
   The alternative is that a lock file named
   /usr/spool/mail/$USER.lock.  */

/* #define MAIL_USE_FLOCK */

/* Define CLASH_DETECTION if you want lock files to be written
   so that Emacs can tell instantly when you try to modify
   a file that someone else has modified in his Emacs.  */

/* #define CLASH_DETECTION */

/* Define SHORTNAMES if the C compiler can distinguish only
   short names.  It means that the stuff in ../shortnames
   must be run to convert the long names to short ones.  */

/* #define SHORTNAMES */

/* We use the Berkeley (and usg5.2.2) interface to nlist.  */

#define NLIST_STRUCT

/* The file containing the kernel's symbol table is called /unix.  */

#define KERNEL_FILE "/unix"

/* The symbol in the kernel where the load average is found
   is named avenrun.  */

#define LDAV_SYMBOL "avenrun"

/* Special hacks needed to make Emacs run on this system.  */

/*
 *	Make the sigsetmask function go away.  Don't know what the
 *	ramifications of this are, but doesn't seem possible to
 *	emulate it properly anyway at this point.
 */

#define sigsetmask(mask)	/* Null expansion */

/* setjmp and longjmp can safely replace _setjmp and _longjmp,
   but they will run slower.  */

#define _setjmp setjmp
#define _longjmp longjmp

/* On USG systems the system calls are interruptable by signals
 that the user program has elected to catch.  Thus the system call
 must be retried in these cases.  To handle this without massive
 changes in the source code, we remap the standard system call names
 to names for our own functions in sysdep.c that do the system call
 with retries. */

#define read sys_read
#define write sys_write
#define open sys_open
#define close sys_close

#define INTERRUPTABLE_OPEN
#define INTERRUPTABLE_CLOSE
#define INTERRUPTABLE_IO

/* On USG systems these have different names */

#define index strchr
#define rindex strrchr

/* USG systems tend to put everything declared static
   into the initialized data area, which becomes pure after dumping Emacs.
   Foil this.  Emacs carefully avoids static vars inside functions.  */

#define static

/* Compiler bug bites on many systems when default ADDR_CORRECT is used.  */

#define ADDR_CORRECT(x) (x)

/* Prevent -lg from being used for debugging.  Not implemented?  */

#define LIBS_DEBUG

/* Use terminfo instead of termcap.  */

#define TERMINFO
---CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE--------

2. Also I rewrote build-install in Bourne shell, which is much more portable:

---CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE--------
: Shell script for building and installing Emacs.
set -x

EMACS=/u/src/emacs
BIN=/usr/local/bin

/bin/sed "s;/usr/local/emacs;$EMACS;" < src/paths.h-dist > src/paths.h

(cd etc; make) || exit 1
(cd src; make) || exit 1

if [ `pwd` != `(cd $EMACS; pwd)` ] then
  mv `pwd` $EMACS
  if [ $status != '0' ] then
    mkdir $EMACS
    echo mv `pwd` to $EMACS failed--using tar to copy.
    tar cf - . | (cd $EMACS; umask 0; tar xf -)
    if [ $status != '0' ] then
      echo tar-copying `pwd` to $EMACS failed.
      exit 1
    fi
  fi
fi

cp $EMACS/etc/[ce]tags $BIN
mv $EMACS/src/xemacs $BIN/emacs
rm $EMACS/src/temacs
chmod 777 $BIN/ctags $BIN/emacs
---CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE--------

3. Also, you should add ".a" and ".ln" to your list of extensions ignored
when looking for files to complete a name on. Who wants to find object
archives or compiled lint information in a file-completion search?

4. The keypad.el 'abstract keymap' needs only two trivial changes to be
able to span all the AT-style keyboards out there. Here they are:

---CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE--------
60a61
> ;; + -- keypad key labelled '+'
76c77
< ;; H -- home-down
---
> ;; H -- home-down (or 'end') key
---CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE--------

5. And here's the terminal package, suitable for use on a 386 box running
   Microport UNIX, that goes with the above changes.

---CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE--------
;; Map AT386 function key escape sequences
;; into the standard slots in function-keymap.
;;
;; by: Eric S. Raymond == {ihnp4,rutgers,seismo}!cbmvax!snark!eric

(require 'keypad)

;; First, map as many keys as possible to terminal-independent keycaps

(defvar META-RB-map nil
  "The META-RB-map maps the ESC-[ function keys on the AT386 keyboard.")

(if (not META-RB-map)
    (progn
     (setq META-RB-map (lookup-key global-map "\e["))
     (if (not (keymapp META-RB-map))
	 (setq META-RB-map (make-sparse-keymap)))  ;; <ESC>[ commands

     (setup-terminal-keymap META-RB-map
	    '(("A" . ?u)	; up arrow
	      ("B" . ?d)	; down-arrow
	      ("C" . ?r)	; right-arrow
	      ("D" . ?l)	; left-arrow
	      ("U" . ?N)	; 'Page Down' -> next page
	      ("V" . ?P)	; 'Page Up' -> prev page
	      ("H" . ?H)	; 'Home' -> home-key
	      ("I" . ?I)	; 'Insert' -> insert-character
	      ("Y" . ?E)	; 'End' -> unmapped
	      ("G" . ?C)	; 'Keypad center' -> clear screen
	      ("S" . ?-)	; 'Keypad -' -> unmapped
	      ("T" . ?+)	; 'Keypad +' -> unmapped
	))))

(defun enable-arrow-keys ()
  "Enable the use of the AT386 arrow keys for cursor motion.
Because of the nature of the AT386, this unavoidably breaks
the standard Emacs command ESC [; therefore, it is not done by default,
but only if you give this command in your .emacs."
  (global-set-key "\e[" META-RB-map))

(defvar META-O-map nil
  "META-O-map maps the META-O function keys on the AT386 keyboard.")

(if (not META-O-map)
    (progn

     (setq META-O-map (lookup-key global-map "\eO"))
     (if (not (keymapp META-O-map))
	 (setq META-O-map (make-sparse-keymap)))  ;; <ESC>O commands
     (setup-terminal-keymap META-O-map '(
		("P" . ?\C-a)	; 'F1' -> function key 1
		("Q" . ?\C-b)	; 'F2' -> function key 2
		("R" . ?\C-c)	; 'F3' -> function key 3
		("S" . ?\C-d)	; 'F4' -> function key 4
		("T" . ?\C-e)	; 'F5' -> function key 5
		("U" . ?\C-f)	; 'F6' -> function key 6
		("V" . ?\C-g)	; 'F7' -> function key 7
		("W" . ?\C-h)	; 'F8' -> function key 8
		("X" . ?\C-i)	; 'F9' -> function key 9
		("Y" . ?\C-j)	; 'F10' -> function key 10
		;("Z" . ?\C-k)	; 'F11' -> function key 11
		;("O" . ?\C-@)	; 'F12' -> function key 12
	))

     (define-key global-map "\eO" META-O-map)))

(defvar META-n-map nil
  "META-n-map maps the ALT-modified ASCII keys on the AT386 keyboard.")

(if (not META-n-map)
    (progn

     (setq META-n-map (lookup-key global-map "\eP"))
     (if (not (keymapp META-n-map))
	 (setq META-n-map (make-sparse-keymap)))  ;; <ESC>P commands
     (setup-terminal-keymap META-n-map '(
		("1" . ?1)	; Ctrl-1 -> keypad 1
		("2" . ?2)	; Ctrl-2 -> keypad 2
		("3" . ?3)	; Ctrl-3 -> keypad 3
		("4" . ?4)	; Ctrl-4 -> keypad 4
		("5" . ?5)	; Ctrl-5 -> keypad 5
		("6" . ?6)	; Ctrl-6 -> keypad 6
		("7" . ?7)	; Ctrl-7 -> keypad 7
		("8" . ?8)	; Ctrl-8 -> keypad 8
		("9" . ?9)	; Ctrl-9 -> keypad 9
		("0" . ?0)	; Ctrl-0 -> keypad 0
		("-" . ?-)	; Ctrl-- -> keypad -
	))
     (define-key global-map "\en" META-n-map)))

---CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE-------CUT-HERE--------

Expect more 386 hackery from me from now on. My 3B1 is retired, I've moved
to a Microport environment, and have a good inside track with the Microport
guys. One thing I'm thinking about is using their nice powerful set of
keyboard-translation ioctls to enable some emacsy things like a working
ALT key and a real keypad mapped differently from the Insert-Delete-Home-
End-PageUp-PageDown groups. Whence my question:

Where in the source should I put machine-specific initialization code?

eric@snark.uu.net = eric%snark@uunet.uu.net     -->     Eric S. Raymond