/* * init_mouse - check for xterm and initialize mouse tracking if present... */ int init_mouse(void) { if(mexist) return(TRUE); if(getenv("DISPLAY")){ mouseon(); kpinsert("\033[M", KEY_XTERM_MOUSE, 1); return(mexist = TRUE); } else return(FALSE); }
/* * Add default keypad sequences to the trie. */ static void setup_dflt_esc_seq(void) { /* * this is sort of a hack, but it allows us to use * the function keys on pc's running telnet */ /* * UW-NDC/UCS vt10[02] application mode. */ kpinsert("\033OP", F1, 1); kpinsert("\033OQ", F2, 1); kpinsert("\033OR", F3, 1); kpinsert("\033OS", F4, 1); kpinsert("\033Op", F5, 1); kpinsert("\033Oq", F6, 1); kpinsert("\033Or", F7, 1); kpinsert("\033Os", F8, 1); kpinsert("\033Ot", F9, 1); kpinsert("\033Ou", F10, 1); kpinsert("\033Ov", F11, 1); kpinsert("\033Ow", F12, 1); /* * DEC vt100, ANSI and cursor key mode. */ kpinsert("\033OA", KEY_UP, 1); kpinsert("\033OB", KEY_DOWN, 1); kpinsert("\033OC", KEY_RIGHT, 1); kpinsert("\033OD", KEY_LEFT, 1); /* * special keypad functions */ kpinsert("\033[4J", KEY_PGUP, 1); kpinsert("\033[3J", KEY_PGDN, 1); kpinsert("\033[2J", KEY_HOME, 1); kpinsert("\033[N", KEY_END, 1); /* * vt220? */ kpinsert("\033[5~", KEY_PGUP, 1); kpinsert("\033[6~", KEY_PGDN, 1); kpinsert("\033[1~", KEY_HOME, 1); kpinsert("\033[4~", KEY_END, 1); /* * konsole, XTerm (XFree 4.x.x) keyboard setting */ kpinsert("\033[H", KEY_HOME, 1); kpinsert("\033[F", KEY_END, 1); /* * gnome-terminal 2.6.0, don't know why it * changed from 2.2.1 */ kpinsert("\033OH", KEY_HOME, 1); kpinsert("\033OF", KEY_END, 1); /* * "\033[2~" was common for KEY_HOME in a quick survey * of terminals (though typically the Insert key). * Teraterm 2.33 sends the following escape sequences, * which is quite incompatible with everything * else: * Home: "\033[2~" End: "\033[5~" PgUp: "\033[3~" * PgDn: "\033[6~" * The best thing to do would be to fix TeraTerm * keymappings or to tweak terminfo. */ /* * ANSI mode. */ kpinsert("\033[=a", F1, 1); kpinsert("\033[=b", F2, 1); kpinsert("\033[=c", F3, 1); kpinsert("\033[=d", F4, 1); kpinsert("\033[=e", F5, 1); kpinsert("\033[=f", F6, 1); kpinsert("\033[=g", F7, 1); kpinsert("\033[=h", F8, 1); kpinsert("\033[=i", F9, 1); kpinsert("\033[=j", F10, 1); kpinsert("\033[=k", F11, 1); kpinsert("\033[=l", F12, 1); /* * DEC vt100, ANSI and cursor key mode reset. */ kpinsert("\033[A", KEY_UP, 1); kpinsert("\033[B", KEY_DOWN, 1); kpinsert("\033[C", KEY_RIGHT, 1); kpinsert("\033[D", KEY_LEFT, 1); /* * DEC vt52 mode. */ kpinsert("\033A", KEY_UP, 1); kpinsert("\033B", KEY_DOWN, 1); kpinsert("\033C", KEY_RIGHT, 1); kpinsert("\033D", KEY_LEFT, 1); /* * DEC vt52 application keys, and some Zenith 19. */ kpinsert("\033?r", KEY_DOWN, 1); kpinsert("\033?t", KEY_LEFT, 1); kpinsert("\033?v", KEY_RIGHT, 1); kpinsert("\033?x", KEY_UP, 1); /* * Some Ctrl-Arrow keys */ kpinsert("\033[5A", CTRL_KEY_UP, 1); kpinsert("\033[5B", CTRL_KEY_DOWN, 1); kpinsert("\033[5C", CTRL_KEY_RIGHT, 1); kpinsert("\033[5D", CTRL_KEY_LEFT, 1); kpinsert("\033[1;5A", CTRL_KEY_UP, 1); kpinsert("\033[1;5B", CTRL_KEY_DOWN, 1); kpinsert("\033[1;5C", CTRL_KEY_RIGHT, 1); kpinsert("\033[1;5D", CTRL_KEY_LEFT, 1); /* * Map some shift+up/down/left/right to their shiftless counterparts */ kpinsert("\033[1;2A", KEY_UP, 1); kpinsert("\033[1;2B", KEY_DOWN, 1); kpinsert("\033[1;2C", KEY_RIGHT, 1); kpinsert("\033[1;2D", KEY_LEFT, 1); kpinsert("\033[a", KEY_UP, 1); kpinsert("\033[b", KEY_DOWN, 1); kpinsert("\033[c", KEY_RIGHT, 1); kpinsert("\033[d", KEY_LEFT, 1); /* * Sun Console sequences. */ kpinsert("\033[1", KEY_SWALLOW_Z, 1); kpinsert("\033[215", KEY_SWAL_UP, 1); kpinsert("\033[217", KEY_SWAL_LEFT, 1); kpinsert("\033[219", KEY_SWAL_RIGHT, 1); kpinsert("\033[221", KEY_SWAL_DOWN, 1); /* * Kermit App Prog Cmd, gobble until ESC \ (kermit should intercept this) */ kpinsert("\033_", KEY_KERMIT, 1); /* * Fake a control character. */ kpinsert("\033\033", KEY_DOUBLE_ESC, 1); }
static int tinfoterminalinfo(int termcap_wins) { char *_ku, *_kd, *_kl, *_kr, *_kppu, *_kppd, *_kphome, *_kpend, *_kpdel, *_kf1, *_kf2, *_kf3, *_kf4, *_kf5, *_kf6, *_kf7, *_kf8, *_kf9, *_kf10, *_kf11, *_kf12; char *ttnm; if (Pmaster) { /* * setupterm() automatically retrieves the value * of the TERM variable. */ int err; ttnm = getenv("TERM"); if(!ttnm) return(-1); strncpy(term_name, ttnm, sizeof(term_name)); term_name[sizeof(term_name)-1] = '\0'; setupterm ((char *) 0, 1, &err); if (err != 1) return(err-2); } else { /* * setupterm() issues a message and exits, if the * terminfo data base is gone or the term type is * unknown, if arg2 is 0. */ setupterm ((char *) 0, 1, (int *) 0); } _clearscreen = tigetstr("clear"); _moveto = tigetstr("cup"); _up = tigetstr("cuu1"); _down = tigetstr("cud1"); _right = tigetstr("cuf1"); _left = tigetstr("cub1"); _setinverse = tigetstr("smso"); _clearinverse = tigetstr("rmso"); _setunderline = tigetstr("smul"); _clearunderline = tigetstr("rmul"); _setbold = tigetstr("bold"); _clearallattr = tigetstr("sgr0"); _cleartoeoln = tigetstr("el"); _cleartoeos = tigetstr("ed"); _deletechar = tigetstr("dch1"); _insertchar = tigetstr("ich1"); _startinsert = tigetstr("smir"); _endinsert = tigetstr("rmir"); _deleteline = tigetstr("dl1"); _insertline = tigetstr("il1"); _scrollregion = tigetstr("csr"); _scrolldown = tigetstr("ind"); _scrollup = tigetstr("ri"); _termcap_init = tigetstr("smcup"); _termcap_end = tigetstr("rmcup"); _startdelete = tigetstr("smdc"); _enddelete = tigetstr("rmdc"); _ku = tigetstr("kcuu1"); _kd = tigetstr("kcud1"); _kl = tigetstr("kcub1"); _kr = tigetstr("kcuf1"); _kppu = tigetstr("kpp"); _kppd = tigetstr("knp"); _kphome = tigetstr("khome"); _kpend = tigetstr("kend"); _kpdel = tigetstr("kdch1"); _kf1 = tigetstr("kf1"); _kf2 = tigetstr("kf2"); _kf3 = tigetstr("kf3"); _kf4 = tigetstr("kf4"); _kf5 = tigetstr("kf5"); _kf6 = tigetstr("kf6"); _kf7 = tigetstr("kf7"); _kf8 = tigetstr("kf8"); _kf9 = tigetstr("kf9"); _kf10 = tigetstr("kf10"); _kf11 = tigetstr("kf11"); _kf12 = tigetstr("kf12"); _colors = tigetnum("colors"); _pairs = tigetnum("pairs"); _setaf = tigetstr("setaf"); _setab = tigetstr("setab"); _setf = tigetstr("setf"); _setb = tigetstr("setb"); _scp = tigetstr("scp"); _op = tigetstr("op"); _oc = tigetstr("oc"); _bce = tigetflag("bce"); _tlines = tigetnum("lines"); if(_tlines == -1){ char *er; int rr; /* tigetnum failed, try $LINES */ er = getenv("LINES"); if(er && (rr = atoi(er)) > 0) _tlines = rr; } _tcolumns = tigetnum("cols"); if(_tcolumns == -1){ char *ec; int cc; /* tigetnum failed, try $COLUMNS */ ec = getenv("COLUMNS"); if(ec && (cc = atoi(ec)) > 0) _tcolumns = cc; } /* * Add default keypad sequences to the trie. * Since these come first, they will override any conflicting termcap * or terminfo escape sequences defined below. An escape sequence is * considered conflicting if one is a prefix of the other. * So, without TERMCAP_WINS, there will likely be some termcap/terminfo * escape sequences that don't work, because they conflict with default * sequences defined here. */ if(!termcap_wins) setup_dflt_esc_seq(); /* * add termcap/info escape sequences to the trie... */ if(_ku != NULL && _kd != NULL && _kl != NULL && _kr != NULL){ kpinsert(_ku, KEY_UP, termcap_wins); kpinsert(_kd, KEY_DOWN, termcap_wins); kpinsert(_kl, KEY_LEFT, termcap_wins); kpinsert(_kr, KEY_RIGHT, termcap_wins); } if(_kppu != NULL && _kppd != NULL){ kpinsert(_kppu, KEY_PGUP, termcap_wins); kpinsert(_kppd, KEY_PGDN, termcap_wins); } kpinsert(_kphome, KEY_HOME, termcap_wins); kpinsert(_kpend, KEY_END, termcap_wins); kpinsert(_kpdel, KEY_DEL, termcap_wins); kpinsert(_kf1, F1, termcap_wins); kpinsert(_kf2, F2, termcap_wins); kpinsert(_kf3, F3, termcap_wins); kpinsert(_kf4, F4, termcap_wins); kpinsert(_kf5, F5, termcap_wins); kpinsert(_kf6, F6, termcap_wins); kpinsert(_kf7, F7, termcap_wins); kpinsert(_kf8, F8, termcap_wins); kpinsert(_kf9, F9, termcap_wins); kpinsert(_kf10, F10, termcap_wins); kpinsert(_kf11, F11, termcap_wins); kpinsert(_kf12, F12, termcap_wins); /* * Add default keypad sequences to the trie. * Since these come after the termcap/terminfo escape sequences above, * the termcap/info sequences will override any conflicting default * escape sequences defined here. * So, with TERMCAP_WINS, some of the default sequences will be missing. * This means that you'd better get all of your termcap/terminfo entries * correct if you define TERMCAP_WINS. */ if(termcap_wins) setup_dflt_esc_seq(); if(Pmaster) return(0); else return(TRUE); }
/* * Read termcap and set some global variables. Initialize input trie to * decode escape sequences. */ static int tcapterminalinfo(int termcap_wins) { char *p, *tgetstr(); char tcbuf[2*1024]; char *tv_stype; char err_str[72]; int err; char *_ku, *_kd, *_kl, *_kr, *_kppu, *_kppd, *_kphome, *_kpend, *_kpdel, *_kf1, *_kf2, *_kf3, *_kf4, *_kf5, *_kf6, *_kf7, *_kf8, *_kf9, *_kf10, *_kf11, *_kf12; if (!(tv_stype = getenv("TERM")) || !strncpy(term_name, tv_stype, sizeof(term_name))){ if(Pmaster){ return(-1); } else{ puts("Environment variable TERM not defined!"); exit(1); } } term_name[sizeof(term_name)-1] = '\0'; if((err = tgetent(tcbuf, tv_stype)) != 1){ if(Pmaster){ return(err - 2); } else{ snprintf(err_str, sizeof(err_str), "Unknown terminal type %s!", tv_stype); puts(err_str); exit(1); } } p = tcapbuf; _clearscreen = tgetstr("cl", &p); _moveto = tgetstr("cm", &p); _up = tgetstr("up", &p); _down = tgetstr("do", &p); _right = tgetstr("nd", &p); _left = tgetstr("bs", &p); _setinverse = tgetstr("so", &p); _clearinverse = tgetstr("se", &p); _setunderline = tgetstr("us", &p); _clearunderline = tgetstr("ue", &p); _setbold = tgetstr("md", &p); _clearallattr = tgetstr("me", &p); _cleartoeoln = tgetstr("ce", &p); _cleartoeos = tgetstr("cd", &p); _deletechar = tgetstr("dc", &p); _insertchar = tgetstr("ic", &p); _startinsert = tgetstr("im", &p); _endinsert = tgetstr("ei", &p); _deleteline = tgetstr("dl", &p); _insertline = tgetstr("al", &p); _scrollregion = tgetstr("cs", &p); _scrolldown = tgetstr("sf", &p); _scrollup = tgetstr("sr", &p); _termcap_init = tgetstr("ti", &p); _termcap_end = tgetstr("te", &p); _startdelete = tgetstr("dm", &p); _enddelete = tgetstr("ed", &p); _ku = tgetstr("ku", &p); _kd = tgetstr("kd", &p); _kl = tgetstr("kl", &p); _kr = tgetstr("kr", &p); _kppu = tgetstr("kP", &p); _kppd = tgetstr("kN", &p); _kphome = tgetstr("kh", &p); _kpend = tgetstr("kH", &p); _kpdel = tgetstr("kD", &p); _kf1 = tgetstr("k1", &p); _kf2 = tgetstr("k2", &p); _kf3 = tgetstr("k3", &p); _kf4 = tgetstr("k4", &p); _kf5 = tgetstr("k5", &p); _kf6 = tgetstr("k6", &p); _kf7 = tgetstr("k7", &p); _kf8 = tgetstr("k8", &p); _kf9 = tgetstr("k9", &p); if((_kf10 = tgetstr("k;", &p)) == NULL) _kf10 = tgetstr("k0", &p); _kf11 = tgetstr("F1", &p); _kf12 = tgetstr("F2", &p); _colors = tgetnum("Co"); _pairs = tgetnum("pa"); _setaf = tgetstr("AF", &p); _setab = tgetstr("AB", &p); _setf = tgetstr("Sf", &p); _setb = tgetstr("Sb", &p); _scp = tgetstr("sp", &p); _op = tgetstr("op", &p); _oc = tgetstr("oc", &p); _bce = tgetflag("ut"); if (p >= &tcapbuf[TCAPSLEN]){ puts("Terminal description too big!\n"); if(Pmaster) return(-3); else exit(1); } _tlines = tgetnum("li"); if(_tlines == -1){ char *er; int rr; /* tgetnum failed, try $LINES */ er = getenv("LINES"); if(er && (rr = atoi(er)) > 0) _tlines = rr; } _tcolumns = tgetnum("co"); if(_tcolumns == -1){ char *ec; int cc; /* tgetnum failed, try $COLUMNS */ ec = getenv("COLUMNS"); if(ec && (cc = atoi(ec)) > 0) _tcolumns = cc; } /* * Add default keypad sequences to the trie. * Since these come first, they will override any conflicting termcap * or terminfo escape sequences defined below. An escape sequence is * considered conflicting if one is a prefix of the other. * So, without TERMCAP_WINS, there will likely be some termcap/terminfo * escape sequences that don't work, because they conflict with default * sequences defined here. */ if(!termcap_wins) setup_dflt_esc_seq(); /* * add termcap/info escape sequences to the trie... */ if(_ku != NULL && _kd != NULL && _kl != NULL && _kr != NULL){ kpinsert(_ku, KEY_UP, termcap_wins); kpinsert(_kd, KEY_DOWN, termcap_wins); kpinsert(_kl, KEY_LEFT, termcap_wins); kpinsert(_kr, KEY_RIGHT, termcap_wins); } if(_kppu != NULL && _kppd != NULL){ kpinsert(_kppu, KEY_PGUP, termcap_wins); kpinsert(_kppd, KEY_PGDN, termcap_wins); } kpinsert(_kphome, KEY_HOME, termcap_wins); kpinsert(_kpend, KEY_END, termcap_wins); kpinsert(_kpdel, KEY_DEL, termcap_wins); kpinsert(_kf1, F1, termcap_wins); kpinsert(_kf2, F2, termcap_wins); kpinsert(_kf3, F3, termcap_wins); kpinsert(_kf4, F4, termcap_wins); kpinsert(_kf5, F5, termcap_wins); kpinsert(_kf6, F6, termcap_wins); kpinsert(_kf7, F7, termcap_wins); kpinsert(_kf8, F8, termcap_wins); kpinsert(_kf9, F9, termcap_wins); kpinsert(_kf10, F10, termcap_wins); kpinsert(_kf11, F11, termcap_wins); kpinsert(_kf12, F12, termcap_wins); /* * Add default keypad sequences to the trie. * Since these come after the termcap/terminfo escape sequences above, * the termcap/info sequences will override any conflicting default * escape sequences defined here. * So, with TERMCAP_WINS, some of the default sequences will be missing. * This means that you'd better get all of your termcap/terminfo entries * correct if you define TERMCAP_WINS. */ if(termcap_wins) setup_dflt_esc_seq(); if(Pmaster) return(0); else return(TRUE); }