/* actions associated with putting the terminal in open mode */ void tostart(void) { putpad(VS); putpad(KS); if (!value(MESG)) { if (ttynbuf[0] == 0) { register char *tn; if ((tn=ttyname(2)) == NULL && (tn=ttyname(1)) == NULL && (tn=ttyname(0)) == NULL) ttynbuf[0] = 1; else safecp(ttynbuf, tn, sizeof ttynbuf, "%s too long", tn); } if (ttynbuf[0] != 1) { struct stat sbuf; stat(ttynbuf, &sbuf); ttymesg = sbuf.st_mode & 0777; chmod(ttynbuf, #ifdef UCBV7 /* * This applies to the UCB V7 Pdp-11 system with the * -u write option only. */ 0611 /* 11 = urgent only allowed */ #else 0600 #endif ); } } }
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); }