[net.sources] Window sources #1 [of 0-7]: Terminal drivers

chris@umcp-cs.UUCP (07/01/83)

: Run this shell script with "sh" not "csh"
PATH=:/bin:/usr/bin:/usr/ucb
export PATH
all=FALSE
if [ $1x = -ax ]; then
	all=TRUE
fi
/bin/echo 'Extracting TrmAmb.c'
sed 's/^X//' <<'//go.sysin dd *' >TrmAmb.c
X/* Copyright (c) 1983 University of Maryland Computer Science Department */
X/* terminal control module for Ann Arbor Ambassadors */
X
X/* ACT 16-Oct-1982: Combined Gosling's version and mine to write this one */
X
X/* ACT 10-Nov-1982 modified for windows */
X
X#include <stdio.h>
X#include "Trm.h"
X
Xstatic
Xint	curX, curY, Baud, CurModes, DesModes, Tcap;
X
Xstatic
Xfloat	BaudFactor;
X
Xstatic
Xenum IDmode { m_insert = 1, m_overwrite = 0} DesiredMode;
X
Xstatic
XINSmode (new)
Xenum IDmode new; {
X	DesiredMode = new;
X}
X
Xstatic
Xmodes (des) {
X	DesModes = des;
X}
X
Xstatic
XSetmodes (OverRide) {
X	register Des = OverRide ? 0 : DesModes;
X	static char *mds[16] = { "0", "0;1", "0;4", "0;1;4", "0;5",
X		"0;1;5", "0;4;5", "0;1;4;5", "0;7", "0;1;7", "0;4;7",
X		"0;1;4;7", "0;5;7", "0;1;5;7", "0;4;5;7", "1;4;5;7" };
X
X	if (Des == CurModes)
X		return;
X	printf ("\033[%sm", mds[Des]);
X	CurModes = Des;
X}
X
Xstatic
Xinslines (n) {
X    Setmodes (1);
X    printf (n <= 1 ? "\033[L" : "\033[%dL", n);
X    pad (60-curY, 0.80);
X}
X
Xstatic
Xdellines (n) {
X    Setmodes (1);
X    printf (n <= 1 ? "\033[M" : "\033[%dM", n);
X    pad (60-curY, 0.80);
X    if (W_tt.t_length == 60)
X	return;
X    if (Baud < 4800) {		/* yeesh! */
X	topos (W_tt.t_length-n+1, 1);
X	printf ("\033[J");
X	pad (60-curY, 8.00);
X    }
X    else {
X	register i;
X	for (i=W_tt.t_length-n+1; i<=W_tt.t_length; i++) {
X	    topos (i, 1);
X	    wipeline ();
X	}
X    }
X}
X
Xstatic
Xwritechars (start, end)
Xregister char *start, *end; {
X    register char *p;
X    register runlen;
X
X    Setmodes (0);
X    if (DesiredMode == m_insert) {
X	printf ("\033[%d@", end - start + 1);
X	pad (80-curX, 0.16);
X    }
X    while (start <= end) {
X	if (start+5 < end && *start == start[1]) {
X	    runlen = 0;
X	    p = start;
X	    do runlen++; while (*++start == *p && start <= end);
X	    if (runlen > 5) {
X		putchar (*p);
X		printf ("\033[%db", runlen - 1);
X		pad (runlen-1, 1.00);
X		curX += runlen;
X	    }
X	    else {
X		start = p;
X		goto normal;
X	    }
X	}
X	else {
Xnormal:
X	    putchar (*start++);
X	    curX++;
X	}
X    }
X}
X
Xstatic
Xblanks (n) register n; {
X    if (n > 0) {
X	Setmodes (0);
X	curX += n;
X	if (DesiredMode == m_insert) {
X	    printf ("\033[%d@", n);
X	    pad (80-curX, 0.16);
X	}
X	if (n > 5) {
X	    printf (" \033[%db", n-1);
X	    pad (n-1, 1.00);
X	}
X	else while (--n >= 0) putchar (' ');
X    }
X}
X
Xstatic
Xpad (n, f)
Xfloat f; {
X    register	k = n * f * BaudFactor;
X    while (--k >= 0)
X	putchar (0);
X}
X
Xstatic
Xtopos (row, column) register row, column; {
X    if (curY == row) {
X	if (curX == column)
X	    return;
X	if (curX == column + 1) {
X	    putchar (010);
X	    goto done;
X	}
X	printf ("\033[%d`", column);
X	goto done;
X    }
X    if (curY+1 == row && (column == 1 || column == curX)) {
X	if (column != curX) putchar (015);
X	putchar (012);
X	goto done;
X    }
X    if (row == 1 && column == 1) {
X	printf ("\033[f");
X	goto done;
X    }
X    if (column == 1) {
X	printf ("\033[%df", row);
X	goto done;
X    }
X    if (row == 1) {
X	printf ("\033[;%df", column);
X	goto done;
X    }
X    printf ("\033[%d;%df", row, column);
Xdone:
X    curX = column;
X    curY = row;
X    pad (1, 1.00);
X}
X
Xstatic
Xinit (BaudRate) {
X    BaudFactor = BaudRate / 10000.;
X    Baud = BaudRate;
X    return 0;
X}
X
Xstatic
Xreset () {
X    printf ("\033[>30;33;37;38;39l\033[>52h");	/* RM(ZDBM,ZWFM,ZAXM,ZAPM,
X						      ZSSM) */
X		    				/* SM(ZMKM) */
X    if (!Tcap)
X	printf ("\033[60;0;0;%dp", W_tt.t_length);/* ZSDP */
X    printf ("\033[1Q\033[m");			/* SEE, SGR */
X    printf ("\033[f\033[2J");			/* HVP, ED */
X    curX = curY = 1;
X    CurModes = 0;
X    DesiredMode = m_overwrite;
X    pad (1, 250.00);
X}
X
Xstatic
Xcleanup () {
X    Setmodes (1);
X    topos (W_tt.t_length, 1);
X    printf ("\033[J");
X    pad (1, 150.);
X    printf ("\033[>33;37h\033[>52l");		/* SM(ZWFM,ZAXM) RM(ZMKM) */
X}
X
Xstatic
Xwipeline () {
X    Setmodes (1);
X    printf ("\033[K");
X    pad (80-curX, 0.14);
X}
X
Xstatic
Xwipescreen () {
X    Setmodes (1);
X    printf ("\033[2J");
X    pad (1, 200.);
X}
X
Xstatic
Xdelchars (n) {
X    if (n <= 0) return;
X    Setmodes (1);
X    printf (n == 1 ? "\033[P" : "\033[%dP", n);
X    pad (80-curX, 0.20);
X}
X
XTrmAmb () {
X	static int ppl[]={18,20,22,24,26,28,30,36,40,48,60,0};
X	int pl, i;		/* get preferred page length from */
X	char *p = (char *) getenv ("PL");/* environment - DCL */
X
X	W_tt.t_length = 60;
X	Tcap = 0;
X	if (p == 0) {
X	    static char tbuf[1024];
X	    if (tgetent (tbuf, getenv ("TERM")) > 0) {
X		W_tt.t_length = tgetnum ("li");
X		++Tcap;
X	    }
X	}
X	if (Tcap == 0) {
X		pl = p == 0 ? 60 : atoi (p);
X		for (i=0; ppl[i]; i++)
X			if (pl==ppl[i]) { W_tt.t_length = pl; break; }
X	}
X	W_tt.t_INSmode = INSmode;
X	W_tt.t_modes = modes;
X	W_tt.t_inslines = inslines;
X	W_tt.t_dellines = dellines;
X	W_tt.t_blanks = blanks;
X	W_tt.t_init = init;
X	W_tt.t_cleanup = cleanup;
X	W_tt.t_wipeline = wipeline;
X	W_tt.t_wipescreen = wipescreen;
X	W_tt.t_topos = topos;
X	W_tt.t_reset = reset;
X	W_tt.t_delchars = delchars;
X	W_tt.t_writechars = writechars;
X	W_tt.t_window = 0;
X	W_tt.t_ILmf = 0;
X	W_tt.t_ILov = 4;
X	W_tt.t_ICmf = 1;
X	W_tt.t_ICov = 4;
X	W_tt.t_DCmf = 0;
X	W_tt.t_DCov = 5;
X	W_tt.t_width = 80;
X	return 0;
X}
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
	/bin/chmod 644 TrmAmb.c
	/bin/echo -n '	'; /bin/ls -ld TrmAmb.c
fi
/bin/echo 'Extracting TrmBitG.c'
sed 's/^X//' <<'//go.sysin dd *' >TrmBitG.c
X/* Copyright (c) 1983 University of Maryland Computer Science Department */
X/* terminal control module for BBN BitGraph
X *
X * ACT 24-Jul-1982 Modified from Ann Arbor Ambassador driver
X * The thing needs padding only at 19200 baud.
X */
X
X#include <stdio.h>
X#include "Trm.h"
X
Xstatic
Xint	curX, curY;
X
Xstatic int   Baud;
X
Xstatic CurGraph;
X
Xstatic
Xenum IDmode { m_insert = 1, m_overwrite = 0}
X	DesiredMode;
X
X#define	PAD(n,f)	if(Baud>9600)pad(n,f)
X
Xstatic
XINSmode (new)
Xenum IDmode new; {
X	DesiredMode = new;
X};
X
Xstatic
XCurmodes, Desmodes;
X
Xstatic
Xmodes (new) {
X	Desmodes = new;
X}
X
Xstatic
XSetmodes (OverRide) {
X	register LDes = OverRide ? 0 : Desmodes;
X	static char *mds[16] = { "0", "0;1", "0;4", "0;1;4", "0;5",
X		"0;1;5", "0;4;5", "0;1;4;5", "0;7", "0;1;7", "0;4;7",
X		"0;1;4;7", "0;5;7", "0;1;5;7", "0;4;5;7", "1;4;5;7" };
X
X	if (LDes == Curmodes)
X		return;
X	printf ("\033[%sm", mds[LDes]);
X	Curmodes = LDes;
X}
X
Xstatic
Xinslines (n) {
X	Setmodes (1);
X	printf (n <= 1 ? "\033[L" : "\033[%dL", n);
X	PAD (64-curY-n, 3.0);
X};
X
Xstatic
Xdellines (n) {
X	Setmodes (1);
X	printf (n <= 1 ? "\033[M" : "\033[%dM", n);
X	PAD (64-curY, 3.0);
X};
X
Xstatic
Xwritechars (start, end)
Xregister char *start,
X	      *end; {
X	register p = end-start+1;
X	Setmodes (0);
X	if (DesiredMode == m_insert) {
X		printf ("\033[%d@", p);
X		PAD (1, 3.0);
X	}
X	curX += p;
X	while (start <= end) {
X		if (*start & 0x80) {
X			if (CurGraph == 0) {
X				printf ("\033(0");
X				CurGraph++;
X			}
X			putchar (*start++ & 0x7f);
X		}
X		else {
X			if (CurGraph) {
X				printf ("\033(B");
X				CurGraph = 0;
X			}
X			putchar (*start++);
X		}
X	}
X	PAD (p, .6);
X};
X
Xstatic
Xblanks (n) {
X	if (n > 0) {
X		Setmodes (0);
X		if (DesiredMode == m_insert) {
X			printf ("\033[%d@", n);
X			PAD (1, 3.0);
X		}
X		curX += n;
X		while (--n >= 0) putchar (' ');
X	}
X	PAD (n, .6);
X};
X
Xstatic float BaudFactor;
X
Xstatic pad(n,f)
Xfloat   f; {
X	register k;
X
X	k = n * f * BaudFactor;
X	while (--k >= 0)
X	putchar (0);
X};
X
Xstatic
Xtopos (row, column) {
X	if (curY == row) {
X		if (curX == column)
X			return;
X		if (curX == column + 1) {
X			putchar ('\b');
X			goto done;
X		}
X	}
X	if (curY+1 == row && (column == 1 || column == curX)) {
X		if (column != curX) putchar (015);
X		putchar (012);
X		goto done;
X	}
X	if (curY == row+1 && column == curX) {
X		printf ("\033M");
X		goto done;
X	}
X	if (row == 1 && column == 1) {
X		printf ("\033[H");
X		goto done;
X	}
X	if (column == 1) {
X		printf ("\033[%dH", row);
X		goto done;
X	}
X	printf ("\033[%d;%dH", row, column);
Xdone: 
X	curX = column;
X	curY = row;
X};
X
Xstatic
Xinit (BaudRate) {
X	Baud = BaudRate;
X	BaudFactor = ((float) BaudRate) / 10000.;
X	return 0;
X};
X
Xstatic
Xreset () {
X	printf ("\033[?50l");		/* Turn off auto XON XOFF */
X	printf ("\033[H\033[2J\033[0m");/* Home, clear, no modes */
X	printf ("\017\033(B");		/* Funny graphics off */
X	curX = curY = 1;
X	Curmodes = 0;
X	CurGraph = 0;
X	DesiredMode = m_overwrite;
X};
X
Xstatic
Xcleanup () {
X	Setmodes (1);
X	if (CurGraph) {
X		printf ("\033(B");
X		CurGraph = 0;
X	}
X	topos (64, 1);
X	printf("\033[?50h");		/* Turn auto XON XOFF back on */
X};
X
Xstatic
Xwipeline () {
X	Setmodes (1);
X	printf ("\033[K");
X	PAD (1, 6.0);
X};
X
Xstatic
Xwipescreen () {
X	Setmodes (1);
X	printf("\033[2J");
X	PAD (1, 10.0);
X};
X
Xstatic
Xdelchars (n) {
X	if (n<=0) return;
X	Setmodes (1);
X	printf(n == 1 ? "\033[P" : "\033[%dP", n);
X	PAD (1, 3.0);
X};
X
Xstatic
Xflash () {
X	printf ("\033[?5%c", InverseVideo ? 'h' : 'l');
X	pad (1, 100.0);
X
X/* (ACT) This one's more fun, but takes too long: */
X/*	printf ("\033:0;0;13;2000;0;0;0;0;0;0;31;7;16;16;16;0;64;0P");*/
X
X	printf ("\033[?5%c", InverseVideo ? 'l' : 'h');
X	pad (1, 100.0);		/* this is REALLY slow!! */
X}
X
X/* Turn off graphics mode */
Xstatic donerefresh () {
X    if (CurGraph) {
X	printf ("\033(B");
X	CurGraph = 0;
X    }
X}
X
XTrmBitG () {
X	register char *t;
X	int f_height, f_width;
X	char *getenv();
X
X	t = getenv ("FONTHEIGHT");
X	f_height = t && *t ? atoi (t) : 16;
X	t = getenv ("FONTWIDTH");
X	f_width = t && *t ? atoi (t) : 9;
X
X	W_tt.t_length = 1024 / f_height;
X	W_tt.t_width = 768 / f_width;
X
X	W_tt.t_INSmode = INSmode;
X	W_tt.t_modes = modes;
X	W_tt.t_inslines = inslines;
X	W_tt.t_dellines = dellines;
X	W_tt.t_blanks = blanks;
X	W_tt.t_init = init;
X	W_tt.t_cleanup = cleanup;
X	W_tt.t_wipeline = wipeline;
X	W_tt.t_wipescreen = wipescreen;
X	W_tt.t_topos = topos;
X	W_tt.t_reset = reset;
X	W_tt.t_delchars = delchars;
X	W_tt.t_writechars = writechars;
X	W_tt.t_flash = flash;
X	W_tt.t_donerefresh = donerefresh;
X	W_tt.t_window = 0;
X	W_tt.t_ILmf = 0;		/* well, only below 19200 */
X	W_tt.t_ILov = 5;
X	W_tt.t_ICmf = 0;		/* same */
X	W_tt.t_ICov = 5;
X	W_tt.t_DCmf = 0;		/* ditto */
X	W_tt.t_DCov = 5;
X	W_tt.t_frames[0] = 'l' | 0x80;	/* ulc */
X	W_tt.t_frames[1] =
X	W_tt.t_frames[6] = 'q' | 0x80;	/* top, bottom */
X	W_tt.t_frames[2] = 'k' | 0x80;	/* urc */
X	W_tt.t_frames[3] =
X	W_tt.t_frames[4] = 'x' | 0x80;	/* left, right sides */
X	W_tt.t_frames[5] = 'm' | 0x80;	/* llc */
X	W_tt.t_frames[7] = 'j' | 0x80;	/* lrc */
X	return 0;
X};
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
	/bin/chmod 644 TrmBitG.c
	/bin/echo -n '	'; /bin/ls -ld TrmBitG.c
fi
/bin/echo 'Extracting TrmTEK4025.c'
sed 's/^X//' <<'//go.sysin dd *' >TrmTEK4025.c
X/* Copyright (c) 1983 University of Maryland Computer Science Department */
X/* Terminal control module for Tektronix 4025 */
X
X/*	Tektronix makes great scopes, but their terminals are another thing */
X/*	entirely.  This was written so no one else will have to waste their */
X/*	time on it.	-- TVR/Feb81					    */
X/*	Rewritten from Concept-100 driver (which was copyright 1981,1980 by */
X/*	James Gosling)							    */
X/* Modified: 26 Feb 81 (JCMogul) - defines null HLmode rather than as zero */
X/* Major bug fixes sometime 1982 Chris Torek */
X
X#include <stdio.h>
X#include "Trm.h"
X
Xstatic
Xint	curX, curY;
X
Xstatic
Xchar	tekesc;
X
Xstatic
Xenum IDmode { m_insert = 1, m_overwrite = 0 }
X	CurMode;
X
Xstatic
XINSmode (new)
Xenum IDmode new; {
X	CurMode = new;
X};
X
Xstatic
Xinslines (n) register n; {
X    /* Stupid TEK4025 does insert AFTER cursor.  Can't insert at line 1!!! */
X    /* We compensate by putting line 1 offscreen. Sigh...  See 'topos'     */
X    /* Worse yet: the cursor is left on the LAST of the inserted lines! ACT*/
X    putchar (013);
X    tek ("ILI", n);
X    if (curY == 1) printf ("%cRUP\r", tekesc);
X    curY += n-1;
X};
X
Xstatic
Xdellines (n) register n; {
X    tek ("DLI", n);
X/* ACT Now must clear any display that might have come up from below */
X    topos (35 - n, 1);
X    tek ("DLI", 50);
X};
X
Xstatic
Xwritechars (start, end)
Xregister char	*start,
X		*end; {
X    if (CurMode == m_insert) {
X	printf ("%cICH\r",tekesc);
X    }
X    while (start <= end) {
X	putchar (*start++);
X	curX++;
X    }
X    if (CurMode == m_insert) {
X	printf("%cICH\r",tekesc);
X    }
X};
X
Xstatic
Xblanks (n) {
X    /* See 'writechars' for remarks about insert mode. */
X    if (CurMode == m_insert) {
X	printf ("%cICH\r",tekesc);
X    }
X    while (--n >=0) {
X	putchar (' ');
X	curX++;
X    }
X    if (CurMode == m_insert) {
X	printf("%cICH\r", tekesc);
X    }
X};
X
Xstatic
Xtopos (row, column) register row, column; {
X    /* CAUTION: Because Insert Line won't work on the top line, display is */
X    /*		used with screen rolled up one line, so logical line 1 is  */
X    /*		the terminal's line 2.  But either due to a firmware bug   */
X    /*		(or brain damage in the microprogrammer), it can't do abs. */
X    /*		cursor positioning anyway.  However, it can go move the    */
X    /*		cursor by a numeric amount.				   */
X    if (curX > 80) {
X	curX = curX - 80;
X	curY++;
X    }
X    if (curY == row && curX == column) return;
X
X    /* I couldn't get LF to do the right thing, although i'm not sure	*/
X    /* why.  Maybe you know more than i.  TVR/Feb81			*/
X    if (row < curY) {
X	if (row < curY - 7) tek ("UP", curY-row);
X	else while (row < curY) putchar (013), --curY;
X    }
X    if (row > curY) tek ("DOW", row-curY);
X
X    if (column > curX) tek ("RIG", column-curX);
X    else if (column == 1) putchar ('\r');
X    else if (column < curX - 7) tek ("LEF", curX-column);
X    else while (column < curX) putchar(010), curX--;
X    curX = column;
X    curY = row;
X};
X
Xstatic
Xinit () {
X    return 0;
X};
X
Xstatic
Xreset () {
X	if (tekesc != 28) {
X		tekesc = 28;
X		printf("\033COM 28\r");	/* Init cmd char */
X	}
X	printf(
X"\34LEA P7 26\34LEA P8 16\34LEA P4 2\34LEA P6 6\34LEA P1 27 90\34LEA P2 14\r"
X	);			/* Teach it some pad keys */
X	wipescreen();
X	CurMode = m_overwrite;
X};
X
Xstatic
Xcleanup () {
X    if (tekesc == 28) {
X	tekesc = 27;
X	printf("\34COM 27\r");	/* Restore cmd char -ACT */
X	printf("\33LEA P7\33LEA P8\33LEA P4\33LEA P6\33LEA P1\33LEA P2\r");
X    }
X};
X
Xstatic
Xwipeline (i,j) register j; {
X    register cnt = j - curX + 1;
X    if (cnt < 1) return;
X    if (curX == 1) {
X	tek ("DLI", 1);
X	inslines (1);
X    }
X    else {
X	register oldcol = curX;
X        while (--cnt >= 0) { putchar(' '); ++curX; };
X        topos (curY, oldcol);
X    }
X};
X
Xstatic
Xwipescreen () {
X    printf ("%cERA%cDOW 35%cUP 34\r",tekesc,tekesc,tekesc);
X    curX = curY = 1;
X};
X
Xstatic
Xdelchars (n) {
X    tek ("DCH", n);
X};
X
Xstatic
Xtek (str, cnt) char *str; {
X    printf ("%c%s", tekesc, str);
X    if (cnt != 1) printf (" %d", cnt);
X    putchar ('\r');
X};
X
XTrmTEK4025 () {
X    W_tt.t_INSmode = INSmode;
X    W_tt.t_modes = NoOperation;
X    W_tt.t_inslines = inslines;
X    W_tt.t_dellines = dellines;
X    W_tt.t_blanks = blanks;
X    W_tt.t_init = init;
X    W_tt.t_cleanup = cleanup;
X    W_tt.t_wipeline = wipeline;
X    W_tt.t_wipescreen = wipescreen;
X    W_tt.t_topos = topos;
X    W_tt.t_reset = reset;
X    W_tt.t_delchars = delchars;
X    W_tt.t_writechars = writechars;
X    W_tt.t_window = 0;
X    W_tt.t_ILmf = 1;
X    W_tt.t_ILov = 9;
X    W_tt.t_ICmf = 1;
X    W_tt.t_ICov = 4;
X    W_tt.t_DCmf = 2;
X    W_tt.t_DCov = 0;
X    W_tt.t_length = 34;
X    W_tt.t_width = 80;
X    return 0;
X};
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
	/bin/chmod 644 TrmTEK4025.c
	/bin/echo -n '	'; /bin/ls -ld TrmTEK4025.c
fi
/bin/echo 'Extracting TrmVT100.c'
sed 's/^X//' <<'//go.sysin dd *' >TrmVT100.c
X/* Copyright (c) 1983 University of Maryland Computer Science Department */
X/* terminal control module for DEC VT100's */
X
X/* Modified version of Gosling's C100 driver -- jpershing@bbn */
X
X/* This is a somewhat primitive driver for the DEC VT100 terminal.  The
X   terminal is driven in so-called "ansi" mode, using jump scroll.  It is
X   assumed to have the Control-S misfeature disabled (although this
X   shouldn't get in the way -- it does anyway).  Specific optimization left
X   to be done are (1) deferral of setting the window until necessary (as
X   the escape sequence to do this is expensive) and (2) being more clever
X   about optimizing motion (as the direct-cursor-motion sequence is also
X   quite verbose).  Also, something needs to be done about putting the
X   terminal back into slow-scroll mode if that's the luser's preference (or
X   perhaps having EMACS itself use slow-scroll mode [lose, lose]).
X*/
X
X#include <stdio.h>
X#include "Trm.h"
X
Xstatic
Xint	curX, curY;
Xstatic
Xint	WindowSize;
X
Xstatic curmodes, CurGraph;
Xstatic
Xmodes (m) register m; {
X    static char *mds[16] = { "0", "0;1", "0;4", "0;1;4", "0;5",
X	"0;1;5", "0;4;5", "0;1;4;5", "0;7", "0;1;7", "0;4;7",
X	"0;1;4;7", "0;5;7", "0;1;5;7", "0;4;5;7", "1;4;5;7" };
X
X    if (curmodes == m)
X	return;
X    printf ("\033[%sm", mds[m]);
X    curmodes = m;
X}
X
Xstatic
Xinslines (n) register n; {
X    printf ("\033[%d;%dr\033[%dH", curY, WindowSize, curY);
X    curX = 1;
X    while (--n >= 0) {
X	printf ("\033M");
X	pad (1, 20.);		/* DEC sez pad=30, but what do they know? */
X    }
X    printf ("\033[r");
X    pad (1, 2.);		/* ACT */
X    curX = curY = 1;
X};
X
Xstatic
Xdellines (n) register n; {
X    printf ("\033[%d;%dr\033[%dH", curY, WindowSize, WindowSize);
X    curX = 1;
X    curY = WindowSize;
X    while (--n >= 0) {
X	printf ("\033E");
X	pad (1, 20.);		/* [see above comment] */
X    }
X    printf ("\033[r");
X    pad (1, 2.);		/* ACT */
X    curX = curY = 1;
X};
X
Xstatic	Baud;
X
Xstatic
Xwritechars (start, end)
Xregister char	*start,
X		*end; {
X    register count = 0;
X    while (start <= end) {
X	if (*start & 0x80) {
X	    if (CurGraph == 0) {
X		printf ("\033(0");
X		CurGraph++;
X	    }
X	    putchar (*start++ & 0x7f);
X	}
X	else {
X	    if (CurGraph && *start != ' ') {
X		printf ("\033(B");
X		CurGraph = 0;
X	    }
X	    putchar (*start++);
X	}
X	curX++;
X	if (count++ > 15 && Baud > 9600) count = 0, pad (1, 2.5);/* ACT */
X    }
X};
X
Xstatic
Xblanks (n) register n; {
X    while (--n >= 0) {
X	putchar (' ');
X	curX++;
X    }
X};
X
Xstatic float BaudFactor;
X
Xstatic pad(n,f)
Xregister n;
Xregister float f; {
X    register    k = n * f * BaudFactor;
X    while (--k >= 0)
X 	putchar (0);
X};
X
Xstatic				/* This routine needs lots of work */
Xtopos (row, column) register row, column; {
X    register k;
X    if (curY == row) {
X	k = curX - column;
X	if (k) {
X	    if (k > 0 && k < 4) {
X		while (k--) putchar(010);
X		goto done;
X	    }
X	}
X	else return;
X    }
X    if (curY + 1 == row && (column == 1 || column==curX)) {
X	if(column!=curX) putchar (015);
X	putchar (012);
X	goto done;
X    }
X    if (row == 1 && column == 1) {
X	printf ("\033[H");
X	pad (1, 5.);		/* ACT */
X	goto done;
X    }
X    printf ("\033[%d;%dH", row, column );
X    pad (1, 5.);		/* ACT */
Xdone:
X    curX = column;
X    curY = row;
X};
X
Xstatic
Xinit (BaudRate) {
X    static inited = 0;
X    if (!inited) {
X	char *getenv();
X	static char tbuf[1024];		/* ACT Try for termcap's co# */
X	register char *t = getenv ("COL");
X	W_tt.t_width = t ? atoi (t)
X	: ((t = getenv ("TERM")) && tgetent (tbuf,t)>0) ? tgetnum ("co") : 80;
X    }
X    Baud = BaudRate;
X    BaudFactor = BaudRate/10000.;
X    W_tt.t_ILmf = 0.0;
X    W_tt.t_ILov = 15 + 2+BaudFactor*20.;
X    return 0;
X};
X
Xstatic
Xreset () {
X    printf ("\033<\033[r\033[m\033[?4;6l\033[2J\033(B\017");/* Whew! */
X    if (InverseVideo) printf ("\033[?5h");/* Use inverse video */
X    pad (1, 55.);
X    WindowSize = 24;
X    curmodes = 0;
X    CurGraph = 0;
X    curX = curY = 1;
X};
X
Xstatic
Xcleanup () {
X    modes (0);
X    if (CurGraph) {
X	printf ("\033(B");
X	CurGraph = 0;
X    }
X    window (0);
X    topos (WindowSize, 1);
X    wipeline ();
X};
X
Xstatic
Xwipeline () {
X    printf("\033[K");
X    pad (1, 2.);
X};
X
Xstatic
Xwipescreen () {
X    printf("\033[2J");
X    pad (1, 60.);		/* ACT was 45. */
X};
X
Xstatic
Xwindow (n) register n; {
X    if (n <= 0 || n > 24)
X	n = 24;
X    WindowSize = n;
X}
X
X/* Visible Bell for DT80/1 -ACT */
Xstatic
Xflash () {
X    printf (InverseVideo ? "\033[?5l" : "\033[?5h");
X    pad (1, 40.);
X    printf (InverseVideo ? "\033[?5h" : "\033[?5l");
X}
X
X/* Turn off graphics mode */
Xstatic donerefresh () {
X    if (CurGraph) {
X	printf ("\033(B");
X	CurGraph = 0;
X    }
X}
X
XTrmVT100 () {
X	W_tt.t_INSmode = NoOperation;
X	W_tt.t_modes = modes;
X	W_tt.t_inslines = inslines;
X	W_tt.t_dellines = dellines;
X	W_tt.t_blanks = blanks;
X	W_tt.t_init = init;
X	W_tt.t_cleanup = cleanup;
X	W_tt.t_wipeline = wipeline;
X	W_tt.t_wipescreen = wipescreen;
X	W_tt.t_topos = topos;
X	W_tt.t_reset = reset;
X	W_tt.t_delchars = 0;
X	W_tt.t_writechars = writechars;
X	W_tt.t_window = window;
X	W_tt.t_flash = flash;
X	W_tt.t_donerefresh = donerefresh;
X	W_tt.t_ILmf = 0;
X	W_tt.t_ILov = 0;
X	W_tt.t_ICmf = MissingFeature;
X	W_tt.t_ICov = MissingFeature;
X	W_tt.t_DCmf = MissingFeature;
X	W_tt.t_DCov = MissingFeature;
X	W_tt.t_length = 24;
X	W_tt.t_width = 80;
X	W_tt.t_frames[0] = 'l' | 0x80;	/* ulc */
X	W_tt.t_frames[1] =
X	W_tt.t_frames[6] = 'q' | 0x80;	/* top, bottom */
X	W_tt.t_frames[2] = 'k' | 0x80;	/* urc */
X	W_tt.t_frames[3] =
X	W_tt.t_frames[4] = 'x' | 0x80;	/* left, right sides */
X	W_tt.t_frames[5] = 'm' | 0x80;	/* llc */
X	W_tt.t_frames[7] = 'j' | 0x80;	/* lrc */
X	return 0;
X};
//go.sysin dd *
made=TRUE
if [ $made = TRUE ]; then
	/bin/chmod 644 TrmVT100.c
	/bin/echo -n '	'; /bin/ls -ld TrmVT100.c
fi
-- 
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs
ARPA:	chris.umcp-cs@UDel-Relay