/* * Stop open, restoring tty modes. */ void ostop(struct termios f) { pfast = (f.c_oflag & ONLCR) == 0; termreset(), fgoto(), flusho(); normal(f); tostop(); }
void setterm(char *type) { register int unknown; char ltcbuf[TCBUFSIZE]; if (type[0] == 0) type = "xx"; unknown = 0; putpad(TE); if (tgetent(ltcbuf, type) != 1) { unknown++; CP(ltcbuf, "xx|dumb:"); } gettmode(); /* must call gettmode() before setsize(). GR */ setsize(); aoftspace = tspace; zap(); /* * Initialize keypad arrow keys. */ addmac1(KU, "k", "up", arrows, 1); addmac1(KD, "j", "down", arrows, 1); addmac1(KL, "h", "left", arrows, 1); addmac1(KR, "l", "right", arrows, 1); addmac1(KH, "H", "home", arrows, 1); /* * Handle funny termcap capabilities */ if (xCS && SC && RC) { if (AL==NULL) AL=""; if (DL==NULL) DL=""; } if (AL_PARM && AL==NULL) AL=""; if (DL_PARM && DL==NULL) DL=""; if (IC && IM==NULL) IM=""; if (IC && EI==NULL) EI=""; if (!GT) BT=NULL; /* If we can't tab, we can't backtab either */ #ifdef TIOCLGET #define HAS_JOB_CONTROL #endif #ifdef _SC_JOB_CONTROL #define HAS_JOB_CONTROL #endif #ifdef HAS_JOB_CONTROL /* * Now map users susp char to ^Z, being careful that the susp * overrides any arrow key, but only for hackers (=new tty driver). */ { static char sc[2]; int i /* , fnd */; if (sysconf(_SC_JOB_CONTROL) != -1) { /* * If a system supports job control but no job * control shell is used, only one method of * detection remains: Our session id equals our * process group id. Any job control shell would * have created at least one new process group. * But as the VSUSP key may be active, we have * to override arrow keys either. */ #ifndef _CRAY /* getsid() is a bad syscall on UNICOS */ if (getsid(0) != getpgid(0)) #endif /* !_CRAY */ ldisc = 2; /* value of NTTYDISC */ sc[0] = tty.c_cc[VSUSP]; sc[1] = 0; if (tty.c_cc[VSUSP] == CTRL('z')) { for (i=0; i<=4; i++) if (arrows[i].cap && arrows[i].cap[0] == CTRL('z')) addmac(sc, NULL, NULL, arrows); } else if (sc[0] #ifdef _PC_VDISABLE && sc[0] != fpathconf(1, _PC_VDISABLE) #endif ) addmac(sc, "\32", "susp", arrows); } } #endif /* HAS_JOB_CONTROL */ if (CM != 0) { if (tgoto(CM, 2, 2)[0] == 'O') /* OOPS */ CA = 0, CM = 0; else CA = 1, costCM = cost(tgoto(CM, 8, 10)); } else { CA = 0, CM = 0; } costSR = cost(SR); costAL = cost(AL); costDP = cost(tgoto(DOWN_PARM, 10, 10)); costLP = cost(tgoto(LEFT_PARM, 10, 10)); costRP = cost(tgoto(RIGHT_PARM, 10, 10)); PC = xPC ? xPC[0] : 0; aoftspace = tspace; safecp(ttylongname, gettlongname(ltcbuf, type), sizeof ttylongname, "Terminal name too long"); /* proper strings to change tty type */ termreset(); gettmode(); value(REDRAW) = AL && DL; value(OPTIMIZE) = !CA && !GT; if (ospeed == B1200 && !value(REDRAW)) value(SLOWOPEN) = 1; /* see also gettmode above */ if (unknown) serror(catgets(catd, 1, 191, "%s: Unknown terminal type"), type); }
/* * Do a z operation. * Code here is rather long, and very uninteresting. */ void vzop(int hadcnt, int cnt, register int c) { register line *addr; if (state != VISUAL) { /* * Z from open; always like a z=. * This code is a mess and should be cleaned up. */ vmoveitup(1, 1); vgoto(outline, 0); ostop(normf); setoutt(); addr2 = dot; vclear(); destline = WECHO; zop2(Xhadcnt ? Xcnt : value(WINDOW) - 1, '='); if (state == CRTOPEN) putnl(); putNFL(); termreset(); Outchar = vputchar; ignore(ostart()); vcnt = 0; outline = destline = 0; vjumpto(dot, cursor, 0); return; } if (hadcnt) { addr = zero + cnt; if (addr < one) addr = one; if (addr > dol) addr = dol; markit(addr); } else switch (c) { case '+': addr = dot + vcnt - vcline; break; case '^': addr = dot - vcline - 1; forbid (addr < one); c = '-'; break; default: addr = dot; break; } switch (c) { case '.': case '-': break; case '^': forbid (addr <= one); break; case '+': forbid (addr >= dol); /* fall into ... */ case CR: case NL: c = CR; break; default: beep(); return; } vmoving = 0; vjumpto(addr, NOSTR, c); }
void setterm(char *type) { int tgetent(char *bp, const char *name); register int unknown, i; register int l; char ltcbuf[TCBUFSIZE]; struct winsize win; char *s; if (type[0] == 0) type = "xx"; unknown = 0; putpad(TE); if (tgetent(ltcbuf, type) != 1) { unknown++; CP(ltcbuf, "xx|dumb:"); } gettmode(); if (ioctl(0, TIOCGWINSZ, &win) < 0) { i = EX_LINES = tgetnum("li"); COLUMNS = tgetnum("co"); } else { if ((EX_LINES = win.ws_row) == 0) EX_LINES = tgetnum("li"); i = EX_LINES; if ((COLUMNS = win.ws_col) == 0) COLUMNS = tgetnum("co"); } if (EX_LINES <= 5) EX_LINES = 24; if (EX_LINES > TUBELINES) EX_LINES = TUBELINES; l = EX_LINES; if (ex_ospeed < B1200) l = 9; /* including the message line at the bottom */ else if (ex_ospeed < B2400) l = 17; if (l > EX_LINES) l = EX_LINES; aoftspace = tspace; zap(); /* * Initialize keypad arrow keys. */ arrows[0].cap = KU; arrows[0].mapto = "k"; arrows[0].descr = "up"; arrows[1].cap = KD; arrows[1].mapto = "j"; arrows[1].descr = "down"; arrows[2].cap = KL; arrows[2].mapto = "h"; arrows[2].descr = "left"; arrows[3].cap = KR; arrows[3].mapto = "l"; arrows[3].descr = "right"; arrows[4].cap = KH; arrows[4].mapto = "H"; arrows[4].descr = "home"; /* * Handle funny termcap capabilities */ if (CS && SC && RC) AL=DL=""; if (AL_PARM && AL==NULL) AL=""; if (DL_PARM && DL==NULL) DL=""; if (IC && IM==NULL) IM=""; if (IC && EI==NULL) EI=""; if (!GT) BT=NULL; /* If we can't tab, we can't backtab either */ #ifdef SIGTSTP /* * Now map users susp char to ^Z, being careful that the susp * overrides any arrow key, but only for hackers (=new tty driver). */ if (dosusp) { static char sc[2]; int i; sc[0] = tty.c_cc[VSUSP]; sc[1] = 0; if (*sc == CTRL('z')) { for (i=0; i<=4; i++) if (arrows[i].cap && arrows[i].cap[0] == CTRL('z')) addmac(sc, NULL, NULL, arrows); } else addmac(sc, "\32", "susp", arrows); } #endif options[WINDOW].ovalue = options[WINDOW].odefault = l - 1; if (defwind) options[WINDOW].ovalue = defwind; options[SCROLL].ovalue = options[SCROLL].odefault = HC ? 11 : ((l-1) / 2); if (COLUMNS <= 4) COLUMNS = 1000; if (!(s = tgoto(CM, 2, 2)) || *s == 'O') /* OOPS */ CA = 0, CM = 0; else CA = 1, costCM = cost(tgoto(CM, 8, 10)); costSR = cost(SR); costAL = cost(AL); costDP = cost(tgoto(DOWN_PARM, 10, 10)); costLP = cost(tgoto(LEFT_PARM, 10, 10)); costRP = cost(tgoto(RIGHT_PARM, 10, 10)); PC = xPC ? xPC[0] : 0; aoftspace = tspace; CP(ex_ttytype, longname(ltcbuf, type)); if (i <= 0) EX_LINES = 2; /* proper strings to change tty type */ termreset(); value(REDRAW) = AL && DL; value(OPTIMIZE) = !CA && !GT; if (ex_ospeed == B1200 && !value(REDRAW)) value(SLOWOPEN) = 1; /* see also gettmode above */ if (unknown) serror("%s: Unknown terminal type", type); }