[comp.emacs] Terminfo/curses for microemacs 3.8i

greg@xios.XIOS.UUCP (Greg Franks) (08/05/87)

*** Curses/termlib stuff for uemacs 3.8i running on SYS V machines ***

Here are my changes to enable the keypad using the terminfo database
found on SYS V machines.  Note the changes to estruct.h!  The major
change is the tinfo driver.  Curses attends to all of the details of
handling the VT100 escape sequences.  They are mapped to the FN keys. 
for example, the down arrow will become FN^B.  Curses will magically
pass <ESC> back to uemacs if <ESC> is pressed by itself (the wonders of
alarm clock calls).   As an added bonus, the tinfo driver will allow the
use of the meta key on terminals like wyse-85's.

Be sure that your terminfo entries have all of the stuff needed to map
the function keys.  To determine the key bindings, type 

   CTRL-X function-key 

then bind away.  You may want to hard-wire some entries into ebind.h.

If I have forgotten something - send hate mail :-)  ...enjoy

-----cut----- -----cut----- -----cut----- -----cut----- -----cut----- 
#! /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:
#	Makefile
#	tinfo.c
#	estruct.diff
#	spawn.diff
# This archive created: Wed Aug  5 08:52:25 1987
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'Makefile'
then
	echo shar: "will not over-write existing file 'Makefile'"
else
cat << \SHAR_EOF > 'Makefile'
CFLAGS=		-O

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 \
		lock.o main.o random.o region.o search.o spawn.o \
		st520.o tcap.o termio.o tinfo.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 \
		hp110.c hp150.c ibmpc.c input.c isearch.c line.c \
		lock.c main.c random.c region.c search.c spawn.c \
		st520.c tcap.c termio.c tinfo.c tipc.c vmsvt.c vt52.c \
		window.c word.c z309.c

HFILES=		estruct.h edef.h efunc.h epath.h ebind.h evar.h

emacs:		$(OFILES)
		$(CC) $(CFLAGS) $(OFILES) -lcurses -lc -o emacs

$(OFILES):	$(HFILES)
SHAR_EOF
fi
if test -f 'tinfo.c'
then
	echo shar: "will not over-write existing file 'tinfo.c'"
else
cat << \SHAR_EOF > 'tinfo.c'
/*	tinfo:	Unix SysV terminfo video driver
		for MicroEMACS
*/

#define	termdef	1			/* don't define "term" external */
#define CTRL_S	0			/* Control S is for search */

#include <stdio.h>
#include	"estruct.h"
#include        "edef.h"

#if TERMINFO

/* Can't include curses.h because of symbol clash WINDOW.  *sigh*	*/

#define A_REVERSE	0001000		/* From curses.h		*/

#define	MARGIN	8
#define	SCRSIZ	64
#define	NPAUSE	10			/* # times thru update to pause */

extern int      wgetch();		/* From curses */
extern int	waddch();		/* From curses */
extern int      wrefresh();		/* from curses */
extern int      endwin();		/* from curses */
extern int      wclrtoeol();		/* from curses */
extern int      wclrtobot();		/* from curses */
extern int      beep();			/* from curses */
extern int	wattrset();		/* from curses */
extern int	tinforev();
extern int      tinfoopen();
extern int	tinfoclose();
extern int      tinfokopen();
extern int	tinfokclose();
extern int	tinfogetc();
extern int	tinfoputc();
extern int	tinfoflush();
extern int	tinfomove();
extern int	tinfoeeol();
extern int	tinfoeeop();
extern int	tinfores();
extern int      wmove();		/* from curses */
#if	COLOR
extern	int	tinfofcol();
extern	int	tinfobcol();
#endif

TERM term = {
	NULL,		/* these two values are set dynamically at open time */
	NULL,
	NULL,
	NULL,
	MARGIN,
	SCRSIZ,
	NPAUSE,
        tinfoopen,
        tinfoclose,
        tinfokopen,
        tinfokclose,
        tinfogetc,
        tinfoputc,
        tinfoflush,
        tinfomove,
        tinfoeeol,
        tinfoeeop,
        beep,
        tinforev,
        tinfores
#if	COLOR
	, tinfofcol,
	tinfobcol
#endif
};

extern struct _win_st {
	short	_cury, _curx;
	short	_maxy, _maxx;
	short	_begy, _begx;
} *stdscr;		/* From curses			*/

/*
 * We are going to let terminfo do all of the work for us....
 */
tinfoopen()
{
	initscr();		/* read terminfo database */
	nonl();			/* Don't process newlines */
	raw();			/* Give me chars as they come */
	noecho();		/* But don't echo em! */
	keypad( stdscr, TRUE );	/* Activate keypad. */
	meta( stdscr, TRUE );	/* Allow meta key */
	idlok( stdscr, TRUE );	/* enable fancy scroll logic */

	term.t_nrow = stdscr->_maxy - 1;
	term.t_ncol = stdscr->_maxx - 1;
	term.t_mrow = term.t_nrow;
	term.t_mcol = term.t_ncol;
}

tinfoclose()
{
        endwin();
}

tinfokopen()

{
	strcpy(sres, "NORMAL");
}

tinfokclose()

{
}

tinforev(state)		/* change reverse video status */

int state;		/* FALSE = normal video, TRUE = reverse video */

{
	wattrset( stdscr, state ? A_REVERSE : 0 );
}

tinfogetc()
{
	register int c;

	c = wgetch( stdscr );
	if ( 0x0080 <= c && c <  0x0100 ) {
		c &= 0x7f;		/* Mask off crap	*/
		c = toupper( c );
		if ( 0x00 <= c  && c <= 0x1f )
			c |= CTRL | 0x0040;

		c |= META;		/* note meta prefix	*/

	} else if ( 0x0101 <= c && c <= 0x0FFF ) {
		c &= 0x7f;		/* Mask off crap.	*/
		
		/* Curses has returned a special function key.	*/
		/* Zap off the high bit and or in SPECIAL	*/
		/* designation.	 Control characters are have 	*/
		/* both the SPECIAL and CONTROL designators set	*/

		if ( 0x00 <= c  && c <= 0x1f )
			c |= CTRL | 0x0040;

		c |= SPEC;
	}
		
	return( c );
}

tinfoputc( c )
char c;
{
	waddch( stdscr, c );
}

tinfoflush()
{
	wrefresh( stdscr );
}

tinfomove( row, col )
register int row, col;
{
	wmove( stdscr, row, col );
}


tinfoeeol()
{
	wclrtoeol( stdscr );
}

tinfoeeop()
{
	wclrtobot( stdscr );
	wrefresh( stdscr );
}

tinfores()	/* change screen resolution */

{
	return(TRUE);
}

spal(dummy)	/* change palette string */

{
	/*	Does nothing here	*/
}

#if	COLOR
tinfofcol()	/* no colors here, ignore this */
{
}

tinfobcol()	/* no colors here, ignore this */
{
}
#endif

#else

hello()
{
}

#endif TERMINFO
SHAR_EOF
fi
if test -f 'estruct.diff'
then
	echo shar: "will not over-write existing file 'estruct.diff'"
else
cat << \SHAR_EOF > 'estruct.diff'
*** 3.8i/estruct.h	Wed Aug  5 08:44:33 1987
--- mine/estruct.h	Wed Aug  5 08:44:02 1987
***************
*** 68,74
  #define VT52    0                       /* VT52 terminal (Zenith).      */
  #define VT100   0                       /* Handle VT100 style keypad.   */
  #define RAINBOW 0                       /* Use Rainbow fast video.      */
! #define TERMCAP 1                       /* 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	*/

--- 68,75 -----
  #define VT52    0                       /* VT52 terminal (Zenith).      */
  #define VT100   0                       /* Handle VT100 style keypad.   */
  #define RAINBOW 0                       /* Use Rainbow fast video.      */
! #define TERMCAP 0                       /* Use TERMCAP                  */
! #define TERMINFO 1                      /* Use TERMINFO                 */
  #define	IBMPC	0			/* IBM-PC CGA/MONO/EGA driver	*/
  #define	DG10	0			/* Data General system/10	*/
  #define	TIPC	0			/* TI Profesional PC driver	*/
***************
*** 81,87
  #define CVMVAS  1	/* arguments to page forward/back in pages	*/
  #define	NFWORD	1	/* forward word jumps to beginning of word	*/
  #define	CLRMSG	0	/* space clears the message line with no insert	*/
! #define	ACMODE	0	/* auto CMODE on .C and .H files		*/
  #define	CFENCE	1	/* fench matching in CMODE			*/
  #define	TYPEAH	1	/* type ahead causes update to be skipped	*/
  #define DEBUGM	1	/* $debug triggers macro debugging		*/

--- 82,88 -----
  #define CVMVAS  1	/* arguments to page forward/back in pages	*/
  #define	NFWORD	1	/* forward word jumps to beginning of word	*/
  #define	CLRMSG	0	/* space clears the message line with no insert	*/
! #define	ACMODE	1	/* auto CMODE on .C and .H files		*/
  #define	CFENCE	1	/* fench matching in CMODE			*/
  #define	TYPEAH	1	/* type ahead causes update to be skipped	*/
  #define DEBUGM	1	/* $debug triggers macro debugging		*/
***************
*** 566,569
  	} u;
  } MC;
  #endif
  

--- 567,572 -----
  	} u;
  } MC;
  #endif
+ 
+ #define filter dosfilter	/* rename for curses	*/
  
SHAR_EOF
fi
if test -f 'spawn.diff'
then
	echo shar: "will not over-write existing file 'spawn.diff'"
else
cat << \SHAR_EOF > 'spawn.diff'
*** 3.8i/spawn.c	Wed Aug  5 08:43:23 1987
--- mine/spawn.c	Wed Aug  5 08:43:02 1987
***************
*** 278,283
          TTflush();
          TTclose();                              /* stty to old modes    */
          system(line);
          TTopen();
          mlputs("[End]");                        /* Pause.               */
          TTflush();

--- 278,286 -----
          TTflush();
          TTclose();                              /* stty to old modes    */
          system(line);
+ 	fprintf( stderr, "Press RETURN to continue" );			/*rgf*/
+         while ((s = getchar()) != '\r' && s != ' ' && s != '\n' )	/*rgf*/
+                 ;							/*rgf*/
          TTopen();
          TTflush();
          sgarbf = TRUE;
***************
*** 279,285
          TTclose();                              /* stty to old modes    */
          system(line);
          TTopen();
-         mlputs("[End]");                        /* Pause.               */
          TTflush();
          while ((s = tgetc()) != '\r' && s != ' ')
                  ;

--- 282,287 -----
          while ((s = getchar()) != '\r' && s != ' ' && s != '\n' )	/*rgf*/
                  ;							/*rgf*/
          TTopen();
          TTflush();
          sgarbf = TRUE;
          return (TRUE);
***************
*** 281,288
          TTopen();
          mlputs("[End]");                        /* Pause.               */
          TTflush();
-         while ((s = tgetc()) != '\r' && s != ' ')
-                 ;
          sgarbf = TRUE;
          return (TRUE);
  #endif

--- 283,288 -----
                  ;							/*rgf*/
          TTopen();
          TTflush();
          sgarbf = TRUE;
          return (TRUE);
  #endif
***************
*** 384,389
          TTclose();                              /* stty to old modes    */
  	strcat(line,">");
  	strcat(line,filnam);
          system(line);
          TTopen();
          TTflush();

--- 384,390 -----
          TTclose();                              /* stty to old modes    */
  	strcat(line,">");
  	strcat(line,filnam);
+ 	strcat(line, " 2>&1");		/* Capture stderr.	*/	/*rgf*/
          system(line);
          TTopen();
          TTflush();
SHAR_EOF
fi
exit 0
#	End of shell archive
-- 
Greg Franks             XIOS Systems Corporation, 1600 Carling Avenue,
(613) 725-5411          Ottawa, Ontario, Canada, K1Z 8R8
seismo!mnetor!dciem!nrcaer!xios!greg        "Vermont ain't flat!"