2005-05-31 11:50:56 -04:00
|
|
|
/* ANSI.C
|
|
|
|
*
|
|
|
|
* The routines in this file provide support for ANSI style terminals
|
|
|
|
* over a serial line. The serial I/O services are provided by routines in
|
|
|
|
* "termio.c". It compiles into nothing if not an ANSI device.
|
|
|
|
*
|
|
|
|
* modified by Petri Kutvonen
|
|
|
|
*/
|
|
|
|
|
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"
|
2013-10-10 00:33:13 -04:00
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if ANSI
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
#define NROW 25 /* Screen size. */
|
|
|
|
#define NCOL 80 /* Edit if you want to. */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if PKCODE
|
|
|
|
#define MROW 64
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
#define NPAUSE 100 /* # times thru update to pause */
|
|
|
|
#define MARGIN 8 /* size of minimim margin and */
|
|
|
|
#define SCRSIZ 64 /* scroll size for extended lines */
|
|
|
|
#define BEL 0x07 /* BEL character. */
|
|
|
|
#define ESC 0x1B /* ESC character. */
|
|
|
|
|
|
|
|
extern int ttopen(); /* Forward references. */
|
|
|
|
extern int ttgetc();
|
|
|
|
extern int ttputc();
|
|
|
|
extern int ttflush();
|
|
|
|
extern int ttclose();
|
|
|
|
extern int ansimove();
|
|
|
|
extern int ansieeol();
|
|
|
|
extern int ansieeop();
|
|
|
|
extern int ansibeep();
|
|
|
|
extern int ansiopen();
|
|
|
|
extern int ansirev();
|
|
|
|
extern int ansiclose();
|
|
|
|
extern int ansikopen();
|
|
|
|
extern int ansikclose();
|
|
|
|
extern int ansicres();
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if COLOR
|
2005-09-30 18:26:09 -04:00
|
|
|
extern int ansifcol();
|
|
|
|
extern int ansibcol();
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
int cfcolor = -1; /* current forground color */
|
|
|
|
int cbcolor = -1; /* current background color */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Standard terminal interface dispatch table. Most of the fields point into
|
|
|
|
* "termio" code.
|
|
|
|
*/
|
2010-07-11 13:54:48 -04:00
|
|
|
struct terminal term = {
|
2005-05-31 11:50:56 -04:00
|
|
|
#if PKCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
MROW - 1,
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
NROW - 1,
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
NROW - 1,
|
|
|
|
NCOL,
|
|
|
|
NCOL,
|
2005-05-31 11:50:56 -04:00
|
|
|
MARGIN,
|
|
|
|
SCRSIZ,
|
|
|
|
NPAUSE,
|
2005-09-30 18:26:09 -04:00
|
|
|
ansiopen,
|
|
|
|
ansiclose,
|
2005-05-31 11:50:56 -04:00
|
|
|
ansikopen,
|
|
|
|
ansikclose,
|
2005-09-30 18:26:09 -04:00
|
|
|
ttgetc,
|
|
|
|
ttputc,
|
|
|
|
ttflush,
|
|
|
|
ansimove,
|
|
|
|
ansieeol,
|
|
|
|
ansieeop,
|
|
|
|
ansibeep,
|
2005-05-31 11:50:56 -04:00
|
|
|
ansirev,
|
|
|
|
ansicres
|
|
|
|
#if COLOR
|
2005-09-30 18:26:09 -04:00
|
|
|
, ansifcol,
|
2005-05-31 11:50:56 -04:00
|
|
|
ansibcol
|
|
|
|
#endif
|
|
|
|
#if SCROLLCODE
|
2005-09-30 18:26:09 -04:00
|
|
|
, NULL
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#if COLOR
|
2005-09-30 18:26:09 -04:00
|
|
|
ansifcol(color)
|
|
|
|
/* set the current output color */
|
|
|
|
int color; /* color to set */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
if (color == cfcolor)
|
|
|
|
return;
|
|
|
|
ttputc(ESC);
|
|
|
|
ttputc('[');
|
2005-09-30 18:26:09 -04:00
|
|
|
ansiparm(color + 30);
|
2005-05-31 11:50:56 -04:00
|
|
|
ttputc('m');
|
|
|
|
cfcolor = color;
|
|
|
|
}
|
|
|
|
|
2010-06-28 21:32:20 -04:00
|
|
|
/* Set the current background color.
|
|
|
|
* color: color to set.
|
|
|
|
*/
|
|
|
|
void ansibcol(int color)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
if (color == cbcolor)
|
|
|
|
return;
|
|
|
|
ttputc(ESC);
|
|
|
|
ttputc('[');
|
2005-09-30 18:26:09 -04:00
|
|
|
ansiparm(color + 40);
|
2005-05-31 11:50:56 -04:00
|
|
|
ttputc('m');
|
2005-09-30 18:26:09 -04:00
|
|
|
cbcolor = color;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ansimove(row, col)
|
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
ttputc(ESC);
|
|
|
|
ttputc('[');
|
|
|
|
ansiparm(row + 1);
|
|
|
|
ttputc(';');
|
|
|
|
ansiparm(col + 1);
|
|
|
|
ttputc('H');
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2010-06-28 21:32:20 -04:00
|
|
|
void ansieeol(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
ttputc(ESC);
|
|
|
|
ttputc('[');
|
|
|
|
ttputc('K');
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2010-06-28 21:32:20 -04:00
|
|
|
void ansieeop(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
#if COLOR
|
|
|
|
ansifcol(gfcolor);
|
|
|
|
ansibcol(gbcolor);
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
ttputc(ESC);
|
|
|
|
ttputc('[');
|
|
|
|
ttputc('J');
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2010-06-28 21:32:20 -04:00
|
|
|
/* Change reverse video state.
|
|
|
|
* state: TRUE = reverse, FALSE = normal
|
|
|
|
*/
|
|
|
|
void ansirev(int state)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
#if COLOR
|
|
|
|
int ftmp, btmp; /* temporaries for colors */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ttputc(ESC);
|
|
|
|
ttputc('[');
|
2005-09-30 18:26:09 -04:00
|
|
|
ttputc(state ? '7' : '0');
|
2005-05-31 11:50:56 -04:00
|
|
|
ttputc('m');
|
|
|
|
#if COLOR
|
|
|
|
if (state == FALSE) {
|
|
|
|
ftmp = cfcolor;
|
|
|
|
btmp = cbcolor;
|
|
|
|
cfcolor = -1;
|
|
|
|
cbcolor = -1;
|
|
|
|
ansifcol(ftmp);
|
|
|
|
ansibcol(btmp);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-06-28 21:32:20 -04:00
|
|
|
/* Change screen resolution. */
|
|
|
|
int ansicres()
|
|
|
|
{
|
2010-08-29 06:03:55 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2010-06-28 21:32:20 -04:00
|
|
|
void ansibeep(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
ttputc(BEL);
|
|
|
|
ttflush();
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2010-06-28 21:32:20 -04:00
|
|
|
void ansiparm(int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
int q, r;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
q = n / 10;
|
|
|
|
if (q != 0) {
|
|
|
|
r = q / 10;
|
2005-05-31 11:50:56 -04:00
|
|
|
if (r != 0) {
|
2005-09-30 18:26:09 -04:00
|
|
|
ttputc((r % 10) + '0');
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
ttputc((q % 10) + '0');
|
|
|
|
}
|
|
|
|
ttputc((n % 10) + '0');
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2010-06-28 21:32:20 -04:00
|
|
|
void ansiopen(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
#if V7 | USG | BSD
|
2010-02-27 05:38:22 -05:00
|
|
|
char *cp;
|
2005-09-30 18:26:09 -04:00
|
|
|
|
|
|
|
if ((cp = getenv("TERM")) == NULL) {
|
|
|
|
puts("Shell variable TERM not defined!");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (strcmp(cp, "vt100") != 0) {
|
|
|
|
puts("Terminal type not 'vt100'!");
|
|
|
|
exit(1);
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
strcpy(sres, "NORMAL");
|
|
|
|
revexist = TRUE;
|
2005-09-30 18:26:09 -04:00
|
|
|
ttopen();
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2010-06-28 21:32:20 -04:00
|
|
|
void ansiclose(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
#if COLOR
|
|
|
|
ansifcol(7);
|
|
|
|
ansibcol(0);
|
|
|
|
#endif
|
|
|
|
ttclose();
|
|
|
|
}
|
|
|
|
|
2010-06-28 21:32:20 -04:00
|
|
|
/* Open the keyboard (a noop here). */
|
|
|
|
void ansikopen(void)
|
|
|
|
{
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2010-06-28 21:32:20 -04:00
|
|
|
/* Close the keyboard (a noop here). */
|
|
|
|
void ansikclose(void)
|
|
|
|
{
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|