MudOSa4DGD/
MudOSa4DGD/bin/
MudOSa4DGD/data/
MudOSa4DGD/doc/
MudOSa4DGD/doc/driver/
MudOSa4DGD/doc/efun/bitstrings/
MudOSa4DGD/doc/efun/command/
MudOSa4DGD/doc/efun/communication/
MudOSa4DGD/doc/efun/heart_beat/
MudOSa4DGD/doc/efun/interactive/
MudOSa4DGD/doc/efun/inventory/
MudOSa4DGD/doc/efun/living/
MudOSa4DGD/doc/efun/mappings/
MudOSa4DGD/doc/efun/strings/
MudOSa4DGD/doc/efun/uid/
MudOSa4DGD/doc/funs/
MudOSa4DGD/doc/language/
MudOSa4DGD/mudlib/dgd/doc/
MudOSa4DGD/mudlib/dgd/lib/include/dgd/
MudOSa4DGD/mudlib/dgd/lib/std/
MudOSa4DGD/mudlib/dgd/lib/sys/
MudOSa4DGD/mudlib/dgd/log/
MudOSa4DGD/mudlib/log/
MudOSa4DGD/mudlib/std/include/
MudOSa4DGD/mudlib/std/obj/
/*
 * 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.
 */













































/* how to init us */
#define INIT_TERMCAP() init_termcap()



#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 */


/* 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 */
void init_termcap() {
  /* mapping over what terms and capabilities we got totally */
  termcap_entries =
    ([
      "dumb": ([ ]),		        /* Dumb terminal */
      "vt100":
      ([
	"BELL":"",		        /* audible signal (bell) */
	"CLS":"",		/* clear screen and home cursor */
	"BOLD":"",		        /* turn on bold (extra bright) attribute */
	"INVERSE":"",		/* turn on reverse-video attribute */
	"BLINK":"",		/* turn on blinking attribute */
	"END":"",		        /* turn off all attributes */
	"TAB":"	",		        /* move cursor to next hardware tab stop */
	"UNDERLINE":"",	        /* underline character overstrikes */
#if 0
	"ESC":ESC,		        /* Our escape character (so we can quote it) */
#endif
	]),
      "ansi" :
      ([
	"CLS":"",		/* clear screen and home cursor */
	"BOLD":"",		        /* turn on bold (extra bright) attribute */
	"INVERSE":"",		/* turn on reverse-video attribute */
	"BLINK":"",		/* turn on blinking attribute */
	"END":"",		        /* turn off all attributes */
	"TAB":"	",		        /* move cursor to next hardware tab stop */
	"UNDERLINE":"",	        /* underline character overstrikes */

	"BLACK":"",
	"RED":"",
	"GREEN":"",
	"YELLOW":"",
	"BLUE":"",
	"MAGENTA":"",
	"CYAN":"",
	"GREY":"",
	"WHITE":"",
	
	"L_RED":"",
	"L_GREEN":"",
	"L_YELLOW":"",
	"L_BLUE":"",
	"L_MAGENTA":"",
	"L_CYAN":"",
	
	"B_BLACK":"",
	"B_RED":"",
	"B_GREEN":"",
	"B_YELLOW":"",
	"B_BLUE":"",
	"B_MAGENTA":"",
	"B_CYAN":"",
	"B_GREY":"",
	"B_WHITE":"",
#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":"",		/* clear screen and home cursor */
#if 0
	"COLUMNS":80,		        /* number of columns in a line */
#endif
	"HOME":"",		        /* home cursor */
#if 0
	"LINES":24,			/* number of lines on screen or page */
#endif
	"BOLD":"",		        /* turn on bold (extra bright) attribute */
	"INVERSE":"",		/* turn on reverse-video attribute */
	"BLINK":"",		/* turn on blinking attribute */
	"END":"",		        /* turn off all attributes */
	"TAB":"	",		        /* move cursor to next hardware tab stop */
	"UNDERLINE":"",	        /* 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":"",		/* 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":"",		        /* home cursor */
	"INITTERM":"",  /* terminal initialization string */
	"LINES":24,			/* number of lines on screen or page */
#endif
	"BOLD":"",		        /* turn on bold (extra bright) attribute */
	"INVERSE":"",		/* turn on reverse-video attribute */
	"BLINK":"",		/* turn on blinking attribute */
	"END":"",		        /* turn off all attributes */
	"TAB":"	",		        /* move cursor to next hardware tab stop */
	"UNDERLINE":"",	        /* underline character overstrikes */

	"BLACK":"",
	"RED":"",
	"GREEN":"",
	"YELLOW":"",
	"BLUE":"",
	"MAGENTA":"",
	"CYAN":"",
	"GREY":"",
	"WHITE":"",
	
	"L_RED":"",
	"L_GREEN":"",
	"L_YELLOW":"",
	"L_BLUE":"",
	"L_MAGENTA":"",
	"L_CYAN":"",
	
	"B_BLACK":"",
	"B_RED":"",
	"B_GREEN":"",
	"B_YELLOW":"",
	"B_BLUE":"",
	"B_MAGENTA":"",
	"B_CYAN":"",
	"B_GREY":"",
	"B_WHITE":"",
#if 0
	"ESC":ESC,		         /* Our escape character (so we can quote it) */
#endif
	]),
      ]);
}


#endif /* __AUTO */