2005-05-31 11:50:56 -04:00
|
|
|
/* TCAP.C
|
|
|
|
*
|
|
|
|
* Unix V7 SysV and BS4 Termcap video driver
|
|
|
|
*
|
|
|
|
* modified by Petri Kutvonen
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* defining this to 1 breaks tcapopen() - it doesn't check if the
|
|
|
|
* sceen size has changed.
|
|
|
|
* -lbt
|
|
|
|
*/
|
|
|
|
#define USE_BROKEN_OPTIMIZATION 0
|
2005-09-30 18:26:09 -04:00
|
|
|
#define termdef 1 /* don't define "term" external */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "estruct.h"
|
|
|
|
#include "edef.h"
|
|
|
|
|
|
|
|
#if TERMCAP
|
|
|
|
|
|
|
|
#if UNIX
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MARGIN 8
|
|
|
|
#define SCRSIZ 64
|
2005-09-30 18:26:09 -04:00
|
|
|
#define NPAUSE 10 /* # times thru update to pause */
|
2005-05-31 11:50:56 -04:00
|
|
|
#define BEL 0x07
|
|
|
|
#define ESC 0x1B
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
extern int ttopen();
|
|
|
|
extern int ttgetc();
|
|
|
|
extern int ttputc();
|
|
|
|
extern int tgetnum();
|
|
|
|
extern int ttflush();
|
|
|
|
extern int ttclose();
|
|
|
|
extern int tcapkopen();
|
|
|
|
extern int tcapkclose();
|
|
|
|
extern int tcapmove();
|
|
|
|
extern int tcapeeol();
|
|
|
|
extern int tcapeeop();
|
|
|
|
extern int tcapbeep();
|
|
|
|
extern int tcaprev();
|
|
|
|
extern int tcapcres();
|
|
|
|
extern int tcapopen();
|
2005-05-31 11:50:56 -04:00
|
|
|
#if PKCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
extern int tcapclose();
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
extern int tput();
|
|
|
|
extern char *tgoto();
|
2005-05-31 11:50:56 -04:00
|
|
|
#if COLOR
|
2005-09-30 18:26:09 -04:00
|
|
|
extern int tcapfcol();
|
|
|
|
extern int tcapbcol();
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
extern int tcapscroll_reg();
|
|
|
|
extern int tcapscroll_delins();
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define TCAPSLEN 315
|
|
|
|
char tcapbuf[TCAPSLEN];
|
|
|
|
char *UP, PC, *CM, *CE, *CL, *SO, *SE;
|
|
|
|
|
|
|
|
#if PKCODE
|
|
|
|
char *TI, *TE;
|
|
|
|
int term_init_ok = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SCROLLCODE
|
|
|
|
char *CS, *DL, *AL, *SF, *SR;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
TERM term = {
|
2005-09-30 18:26:09 -04:00
|
|
|
0, /* these four values are set dynamically at open time */
|
2005-05-31 11:50:56 -04:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
MARGIN,
|
|
|
|
SCRSIZ,
|
|
|
|
NPAUSE,
|
2005-09-30 18:26:09 -04:00
|
|
|
tcapopen,
|
2005-05-31 11:50:56 -04:00
|
|
|
#if PKCODE
|
|
|
|
tcapclose,
|
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
ttclose,
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
tcapkopen,
|
|
|
|
tcapkclose,
|
|
|
|
ttgetc,
|
|
|
|
ttputc,
|
|
|
|
ttflush,
|
|
|
|
tcapmove,
|
|
|
|
tcapeeol,
|
|
|
|
tcapeeop,
|
|
|
|
tcapbeep,
|
|
|
|
tcaprev,
|
|
|
|
tcapcres
|
2005-05-31 11:50:56 -04:00
|
|
|
#if COLOR
|
2005-09-30 18:26:09 -04:00
|
|
|
, tcapfcol,
|
2005-05-31 11:50:56 -04:00
|
|
|
tcapbcol
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
#if SCROLLCODE
|
|
|
|
, NULL /* set dynamically at open time */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
tcapopen()
|
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
char *getenv();
|
|
|
|
char *t, *p, *tgetstr();
|
|
|
|
char tcbuf[1024];
|
|
|
|
char *tv_stype;
|
|
|
|
char err_str[72];
|
|
|
|
int int_col, int_row;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if PKCODE && USE_BROKEN_OPTIMIZATION
|
2005-09-30 18:26:09 -04:00
|
|
|
if (!term_init_ok) {
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((tv_stype = getenv("TERM")) == NULL) {
|
|
|
|
puts("Environment variable TERM not defined!");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((tgetent(tcbuf, tv_stype)) != 1) {
|
|
|
|
sprintf(err_str, "Unknown terminal type %s!",
|
|
|
|
tv_stype);
|
|
|
|
puts(err_str);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get screen size from system, or else from termcap. */
|
|
|
|
getscreensize(&int_col, &int_row);
|
|
|
|
term.t_nrow = int_row - 1;
|
|
|
|
term.t_ncol = int_col;
|
|
|
|
|
|
|
|
if ((term.t_nrow <= 0)
|
|
|
|
&& (term.t_nrow = (short) tgetnum("li") - 1) == -1) {
|
|
|
|
puts("termcap entry incomplete (lines)");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((term.t_ncol <= 0)
|
|
|
|
&& (term.t_ncol = (short) tgetnum("co")) == -1) {
|
|
|
|
puts("Termcap entry incomplete (columns)");
|
|
|
|
exit(1);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#ifdef SIGWINCH
|
2005-09-30 18:26:09 -04:00
|
|
|
term.t_mrow = MAXROW;
|
|
|
|
term.t_mcol = MAXCOL;
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
term.t_mrow = term.t_nrow > MAXROW ? MAXROW : term.t_nrow;
|
|
|
|
term.t_mcol = term.t_ncol > MAXCOL ? MAXCOL : term.t_ncol;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
p = tcapbuf;
|
|
|
|
t = tgetstr("pc", &p);
|
|
|
|
if (t)
|
|
|
|
PC = *t;
|
|
|
|
else
|
|
|
|
PC = 0;
|
|
|
|
|
|
|
|
CL = tgetstr("cl", &p);
|
|
|
|
CM = tgetstr("cm", &p);
|
|
|
|
CE = tgetstr("ce", &p);
|
|
|
|
UP = tgetstr("up", &p);
|
|
|
|
SE = tgetstr("se", &p);
|
|
|
|
SO = tgetstr("so", &p);
|
|
|
|
if (SO != NULL)
|
|
|
|
revexist = TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if PKCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
if (tgetnum("sg") > 0) { /* can reverse be used? P.K. */
|
|
|
|
revexist = FALSE;
|
|
|
|
SE = NULL;
|
|
|
|
SO = NULL;
|
|
|
|
}
|
|
|
|
TI = tgetstr("ti", &p); /* terminal init and exit */
|
|
|
|
TE = tgetstr("te", &p);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (CL == NULL || CM == NULL || UP == NULL) {
|
|
|
|
puts("Incomplete termcap entry\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CE == NULL) /* will we be able to use clear to EOL? */
|
|
|
|
eolexist = FALSE;
|
|
|
|
#if SCROLLCODE
|
|
|
|
CS = tgetstr("cs", &p);
|
|
|
|
SF = tgetstr("sf", &p);
|
|
|
|
SR = tgetstr("sr", &p);
|
|
|
|
DL = tgetstr("dl", &p);
|
|
|
|
AL = tgetstr("al", &p);
|
|
|
|
|
|
|
|
if (CS && SR) {
|
|
|
|
if (SF == NULL) /* assume '\n' scrolls forward */
|
|
|
|
SF = "\n";
|
|
|
|
term.t_scroll = tcapscroll_reg;
|
|
|
|
} else if (DL && AL) {
|
|
|
|
term.t_scroll = tcapscroll_delins;
|
|
|
|
} else {
|
|
|
|
term.t_scroll = NULL;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
|
|
|
|
if (p >= &tcapbuf[TCAPSLEN]) {
|
|
|
|
puts("Terminal description too big!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#if PKCODE && USE_BROKEN_OPTIMIZATION
|
2005-09-30 18:26:09 -04:00
|
|
|
term_init_ok = 1;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
ttopen();
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if PKCODE
|
|
|
|
|
|
|
|
tcapclose()
|
|
|
|
{
|
|
|
|
putpad(tgoto(CM, 0, term.t_nrow));
|
|
|
|
putpad(TE);
|
|
|
|
ttflush();
|
|
|
|
ttclose();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tcapkopen()
|
|
|
|
{
|
|
|
|
#if PKCODE
|
|
|
|
putpad(TI);
|
|
|
|
ttflush();
|
|
|
|
#endif
|
|
|
|
strcpy(sres, "NORMAL");
|
|
|
|
}
|
|
|
|
|
|
|
|
tcapkclose()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
tcapmove(row, col)
|
|
|
|
register int row, col;
|
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
putpad(tgoto(CM, col, row));
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
tcapeeol()
|
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
putpad(CE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
tcapeeop()
|
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
putpad(CL);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
tcaprev(state)
|
|
|
|
/* change reverse video status */
|
|
|
|
int state; /* FALSE = normal video, TRUE = reverse video */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
static int revstate = FALSE;
|
|
|
|
if (state) {
|
|
|
|
if (SO != NULL)
|
|
|
|
putpad(SO);
|
2005-09-30 18:26:09 -04:00
|
|
|
} else if (SE != NULL)
|
|
|
|
putpad(SE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
tcapcres()
|
|
|
|
{ /* change screen resolution */
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
#if SCROLLCODE
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/* move howmanylines lines starting at from to to */
|
2005-09-30 18:26:09 -04:00
|
|
|
tcapscroll_reg(from, to, howmanylines)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (to == from)
|
|
|
|
return;
|
|
|
|
if (to < from) {
|
|
|
|
tcapscrollregion(to, from + howmanylines - 1);
|
|
|
|
tcapmove(from + howmanylines - 1, 0);
|
|
|
|
for (i = from - to; i > 0; i--)
|
|
|
|
putpad(SF);
|
|
|
|
} else { /* from < to */
|
|
|
|
tcapscrollregion(from, to + howmanylines - 1);
|
|
|
|
tcapmove(from, 0);
|
|
|
|
for (i = to - from; i > 0; i--)
|
|
|
|
putpad(SR);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
tcapscrollregion(0, term.t_nrow);
|
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/* move howmanylines lines starting at from to to */
|
2005-09-30 18:26:09 -04:00
|
|
|
tcapscroll_delins(from, to, howmanylines)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
int i;
|
|
|
|
if (to == from)
|
|
|
|
return;
|
|
|
|
if (to < from) {
|
|
|
|
tcapmove(to, 0);
|
|
|
|
for (i = from - to; i > 0; i--)
|
|
|
|
putpad(DL);
|
|
|
|
tcapmove(to + howmanylines, 0);
|
|
|
|
for (i = from - to; i > 0; i--)
|
|
|
|
putpad(AL);
|
|
|
|
} else {
|
|
|
|
tcapmove(from + howmanylines, 0);
|
|
|
|
for (i = to - from; i > 0; i--)
|
|
|
|
putpad(DL);
|
|
|
|
tcapmove(from, 0);
|
|
|
|
for (i = to - from; i > 0; i--)
|
|
|
|
putpad(AL);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/* cs is set up just like cm, so we use tgoto... */
|
2005-09-30 18:26:09 -04:00
|
|
|
tcapscrollregion(top, bot)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
ttputc(PC);
|
2005-09-30 18:26:09 -04:00
|
|
|
putpad(tgoto(CS, bot, top));
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
#endif
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
spal(dummy)
|
|
|
|
{ /* change palette string */
|
|
|
|
/* Does nothing here */
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if COLOR
|
2005-09-30 18:26:09 -04:00
|
|
|
tcapfcol()
|
|
|
|
{ /* no colors here, ignore this */
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
tcapbcol()
|
|
|
|
{ /* no colors here, ignore this */
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
tcapbeep()
|
|
|
|
{
|
|
|
|
ttputc(BEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
putpad(str)
|
2005-09-30 18:26:09 -04:00
|
|
|
char *str;
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
tputs(str, 1, ttputc);
|
|
|
|
}
|
|
|
|
|
|
|
|
putnpad(str, n)
|
2005-09-30 18:26:09 -04:00
|
|
|
char *str;
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
tputs(str, n, ttputc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if FNLABEL
|
2005-09-30 18:26:09 -04:00
|
|
|
fnclabel(f, n)
|
|
|
|
/* label a function key */
|
|
|
|
int f, n; /* default flag, numeric argument [unused] */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
/* on machines with no function keys...don't bother */
|
2005-09-30 18:26:09 -04:00
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
|
|
|
|
hello()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|