/*
* termcap.c
*
* SFUN: termcap capabilities
*
* Taken from VikingMUD.
* Modified by Frank Schmidt.
*
*/
/*
* W A R N I N G ! ! ! !
*
* You should NOT view this file from within the mud or in an editor
* you are not sure if will quote escape characters (emacs works).
* This file is so full of escape characters that your terminal will
* most probably be seriously messed up from viewing it.
*
* The following blank lines are for your protection only.
*/
#ifdef __AUTO
/* inside auto object */
/* path to object holding termcap variables and functions */
#define TERMCAP_OB SIMUL_EFUN
#if 0
/* standardize simple termcaps through functions: */
static varargs string blink(string str, object who) {
return ESC + "BLINK" + ESC + str + ESC + "END" + ESC;
}
static varargs string bold(string str, object who) {
return ESC + "BOLD" + ESC + str + ESC + "END" + ESC;
}
static varargs string clear_screen(object who) {
return ESC + "CLS" + ESC;
}
static varargs string inverse(string str, object who) {
return ESC + "INVERSE" + ESC + str + ESC + "END" + ESC;
}
static varargs string underline(string str, object who) {
return ESC + "UNDERLINE" + ESC + str + ESC + "END" + ESC;
}
/* return a string always ended properly, leaving no garbage */
static string termcap_string(string str) {
return str + ESC + "END" + ESC;
}
#endif
/* return capability information */
static varargs mixed query_termcap(string term, string cap) {
if (term) {
if (cap)
return TERMCAP_OB->query_termcap_capability(term, cap);
else
return TERMCAP_OB->query_termcap_term(term);
}
else
return TERMCAP_OB->query_all_termcap_entries();
}
/* return real stringlength of a termcap string */
static int termcap_strlen(string str) {
int i, sz, l;
string *tstr;
for (sz=a_sizeof(tstr = explode(str, ESC)); i < sz; i += 2)
l += strlen(tstr[i]);
return l;
}
/* return formatted line of termcap code converted to term code */
static string termcap_format_line(string str, string term) {
return TERMCAP_OB->termcap_format_line(str, term);
}
#undef TERMCAP_OB
#else /* __AUTO */
/* outside of auto object: the termcap object */
/* how to init us */
#define INIT_TERMCAP() init_termcap()
/* internal variables */
private static mapping termcap_entries;
/* return termcap information */
mapping query_all_termcap_entries() {
return termcap_entries;
}
/* return capability information */
mapping query_termcap_term(string what) {
return termcap_entries[what];
}
/* return code for a capability for a specific term */
mixed query_termcap_capability(string term, string capability) {
mapping t;
if (t=termcap_entries[term])
return t[capability];
return 0;
}
/* return formatted line of termcap code converted to term code */
string termcap_format_line(string str, string term) {
mapping temp;
if (temp=termcap_entries[term]) {
int i, sz;
string *tstr, code;
if (sz=a_sizeof(tstr = explode(str, ESC))) {
str = tstr[0];
for (i=1; i < sz; ++i) {
if (code=temp[tstr[i]])
str += code;
if (++i >= sz) break;
str += tstr[i];
}
}
}
return str;
}
/* initialize data */
static void init_termcap() {
/* mapping over what terms and capabilities we got totally */
termcap_entries =
([
"dumb": ([ ]), /* Dumb terminal */
"vt100":
([
"BELL":"", /* audible signal (bell) */
"CLS":"[;H[2J", /* clear screen and home cursor */
"BOLD":"[1m", /* turn on bold (extra bright) attribute */
"INVERSE":"[7m", /* turn on reverse-video attribute */
"BLINK":"[5m", /* turn on blinking attribute */
"END":"[m", /* turn off all attributes */
"TAB":" ", /* move cursor to next hardware tab stop */
"UNDERLINE":"[4m", /* underline character overstrikes */
#if 0
"ESC":ESC, /* Our escape character (so we can quote it) */
#endif
]),
"ansi" :
([
"CLS":"[;H[2J", /* clear screen and home cursor */
"BOLD":"[1m", /* turn on bold (extra bright) attribute */
"INVERSE":"[7m", /* turn on reverse-video attribute */
"BLINK":"[5m", /* turn on blinking attribute */
"END":"[m", /* turn off all attributes */
"TAB":" ", /* move cursor to next hardware tab stop */
"UNDERLINE":"[4m", /* underline character overstrikes */
"BLACK":"[30m",
"RED":"[31m",
"GREEN":"[32m",
"YELLOW":"[33m",
"BLUE":"[34m",
"MAGENTA":"[35m",
"CYAN":"[36m",
"GREY":"[37m",
"WHITE":"[37m",
"L_RED":"[1;31m",
"L_GREEN":"[1;32m",
"L_YELLOW":"[1;33m",
"L_BLUE":"[1;34m",
"L_MAGENTA":"[1;35m",
"L_CYAN":"[1;36m",
"B_BLACK":"[40m",
"B_RED":"[41m",
"B_GREEN":"[42m",
"B_YELLOW":"[43m",
"B_BLUE":"[44m",
"B_MAGENTA":"[45m",
"B_CYAN":"[46m",
"B_GREY":"[47m",
"B_WHITE":"[47m",
#if 0
"ESC":ESC, /* Our escape character (so we can quote it) */
#endif
]),
"debug" :
([
"BOLD":"[BOLD]", /* turn on bold (extra bright) attribute */
"INVERSE":"[INVERSE]", /* turn on reverse-video attribute */
"BLINK":"[BLINK]", /* turn on blinking attribute */
"END":"[END]", /* turn off all attributes */
"TAB":"[TAB]", /* move cursor to next hardware tab stop */
"UNDERLINE":"[UNDERLINE]", /* underline character overstrikes */
"BLACK":"[BLACK]",
"RED":"[RED]",
"GREEN":"[GREEN]",
"YELLOW":"[YELLOW]",
"BLUE":"[BLUE]",
"MAGENTA":"[MAGENTA]",
"CYAN":"[CYAN]",
"GREY":"[GREY]",
"WHITE":"[WHITE]",
"L_RED":"[L_RED]",
"L_GREEN":"[L_GREEN]",
"L_YELLOW":"[L_YELLOW]",
"L_BLUE":"L_BLUE]",
"L_MAGENTA":"[L_MAGENTA]",
"L_CYAN":"[L_CYAN]",
"B_BLACK":"[B_BLACK]",
"B_RED":"[B_RED]",
"B_GREEN":"[B_GREEN]",
"B_YELLOW":"[B_YELLOW]",
"B_BLUE":"[B_BLUE]",
"B_MAGENTA":"[B_MAGENTA]",
"B_CYAN":"[B_CYAN]",
"B_GREY":"[B_GREY]",
"B_WHITE":"[B_WHITE]",
#if 0
"ESC":"[ESC]",
#endif
]),
"xterm":
([
"BELL":"", /* audible signal (bell) */
"CLS":"[;H[2J", /* clear screen and home cursor */
#if 0
"COLUMNS":80, /* number of columns in a line */
#endif
"HOME":"[H", /* home cursor */
#if 0
"LINES":24, /* number of lines on screen or page */
#endif
"BOLD":"[1m", /* turn on bold (extra bright) attribute */
"INVERSE":"[7m", /* turn on reverse-video attribute */
"BLINK":"[5m", /* turn on blinking attribute */
"END":"[m", /* turn off all attributes */
"TAB":" ", /* move cursor to next hardware tab stop */
"UNDERLINE":"[4m", /* underline character overstrikes */
#if 0
"ESC":ESC, /* Our escape character (so we can quote it) */
#endif
]),
"atari":
([
"CLS":"E",
"sr":"I",
"up":"A",
"ku":"A",
"kd":"B",
"kr":"C",
"kl":"D",
"kb":"",
"BOLD":"p",
"se":"q",
"sc":"j",
"rc":"k",
"al":"L",
"dl":"M",
"vi":"f",
"ve":"e",
"is":"vq",
"rs":"vEq",
"BG":"c%c",
"FG":"b%c",
#if 0
"ESC":ESC, /* Our escape character (so we can quote it) */
#endif
]),
"adm3a":
([
"CLS":"",
#if 0
"ESC":ESC, /* Our escape character (so we can quote it) */
#endif
]),
"colxterm":
([
"BELL":"", /* audible signal (bell) */
"CLS":"[;H[2J", /* clear screen and home cursor */
#if 0
"MOVE":"![%i%d;%dH", /* screen-relative cursor motion to row m col n */
"COLUMNS":80, /* number of columns in a line */
"HOME":"[H", /* home cursor */
"INITTERM":"[1;24r[24;1H", /* terminal initialization string */
"LINES":24, /* number of lines on screen or page */
#endif
"BOLD":"[1m", /* turn on bold (extra bright) attribute */
"INVERSE":"[7m", /* turn on reverse-video attribute */
"BLINK":"[5m", /* turn on blinking attribute */
"END":"[m", /* turn off all attributes */
"TAB":" ", /* move cursor to next hardware tab stop */
"UNDERLINE":"[4m", /* underline character overstrikes */
"BLACK":"[30m",
"RED":"[31m",
"GREEN":"[32m",
"YELLOW":"[33m",
"BLUE":"[34m",
"MAGENTA":"[35m",
"CYAN":"[36m",
"GREY":"[37m",
"WHITE":"[37m",
"L_RED":"[1;31m",
"L_GREEN":"[1;32m",
"L_YELLOW":"[1;33m",
"L_BLUE":"[1;34m",
"L_MAGENTA":"[1;35m",
"L_CYAN":"[1;36m",
"B_BLACK":"[40m",
"B_RED":"[41m",
"B_GREEN":"[42m",
"B_YELLOW":"[43m",
"B_BLUE":"[44m",
"B_MAGENTA":"[45m",
"B_CYAN":"[46m",
"B_GREY":"[47m",
"B_WHITE":"[47m",
#if 0
"ESC":ESC, /* Our escape character (so we can quote it) */
#endif
]),
]);
}
#endif /* __AUTO */