📄 setupterm.c
字号:
cur_term->_strs = cur_strs; cur_term->_strtab = strtab; cur_term->sgr_mode = cur_term->sgr_faked = A_NORMAL; if (filenum == 1 && !isatty(filenum)) filenum = 2; /* Allow output redirect */ cur_term->Filedes = filenum; _blast_keys(cur_term); cur_term->_iwait = cur_term->fl_typeahdok = cur_term->_chars_on_queue = cur_term->_fl_rawmode = cur_term->_ungotten = 0; cur_term->_cursorstate = 1; cur_term->_delay = cur_term->_inputfd = cur_term->_check_fd = -1; (void) memset((char*)cur_term->_regs, 0, 26 * sizeof(short));#ifndef DUMPTI def_shell_mode(); /* This is a useful default for PROGTTY, too */ PROGTTY = SHELLTTY;#endif /* DUMPTI */ /* Skip names of terminals */ (void) memcpy((char *) cp, (char *) ip, (int) (snames * sizeof(*cp))); ip += snames; /* * Pull out the booleans. * The for loop below takes care of a new curses with an old tic * file and visa-versa. nbools says how many bools the tic file has. * So, we only loop for as long as there are bools to read. * However, if this is an old curses that doesn't have all the * bools that this new tic has dumped, then the extra if * "if (cp < fp)" says that if we are going to read into our structure * passed its size don't do it but we still need to keep bumping * up the pointer of what we read in from the terminfo file. */ { char *fp = &cur_bools->Sentinel; register char s;#ifdef DUMPTI register int tempindex = 0;#endif /* DUMPTI */ cp = &cur_bools->_auto_left_margin; while (nbools--) { s = *ip++;#ifdef DUMPTI printf("Bool %s [%s] (%s) = %d.\n", boolfnames[tempindex], boolnames[tempindex], boolcodes[tempindex], s); tempindex++;#endif /* DUMPTI */ if (cp < fp) *cp++ = s & 01; } if (cp < fp) (void) memset(cp, 0, (int) ((fp - cp) * sizeof(bool))); } /* Force proper alignment */ if (((unsigned int) ip) & 1) ip++; /* * Pull out the numbers. */ { register short *sp = &cur_nums->_columns; short *fp = &cur_nums->Sentinel; register int s;#ifdef DUMPTI register int tempindex = 0;#endif /* DUMPTI */ while (nints--) { s = _Getshi();#ifdef DUMPTI Vr2val = _Vr2getshi(); printf("Num %s [%s] (%s) = %d [%d].\n", numfnames[tempindex], numnames[tempindex], numcodes[tempindex], s, Vr2val); tempindex++;#endif /* DUMPTI */ if (sp < fp) if (s < 0) *sp++ = -1; else *sp++ = s; } if (sp < fp) (void) memset((char *) sp, '\377', (int) ((fp - sp) * sizeof(short))); }#ifdef TIOCGWINSZ /* * ioctls for 4.3BSD and other systems that have adopted TIOCGWINSZ. */ { struct winsize w; if (ioctl(filenum, TIOCGWINSZ, &w) != -1 && w.ws_row != 0 && w.ws_col != 0) { cur_nums->_lines = (unsigned char) w.ws_row; cur_nums->_columns = (unsigned char) w.ws_col;#ifdef DUMPTI printf("ioctl TIOCGWINSZ override: (lines, columns)=(%d, %d)\n", w.ws_row, w.ws_col);#endif /* DUMPTI */ } }#else /* TIOCGWINSZ */# ifdef JWINSIZE /* * ioctls for Blit - you may need to #include <jioctl.h> * This ioctl defines the window size and overrides what * it says in terminfo. */ { struct jwinsize w; if (ioctl(filenum, JWINSIZE, &w) != -1 && w.bytesy != 0 && w.bytesx != 0) { cur_nums->_lines = (unsigned char) w.bytesy; cur_nums->_columns = (unsigned char) w.bytesx;# ifdef DUMPTI printf("ioctl JWINSIZE override: (lines, columns)=(%d, %d)\n", w.bytesy, w.bytesx);# endif /* DUMPTI */ } }# endif /* JWINSIZE */# ifdef TIOCGSIZE /* * ioctls for Sun. */ { struct ttysize w; if (ioctl(filenum, TIOCGSIZE, &w) != -1 && w.ts_lines > 0 && w.ts_cols > 0) { cur_nums->_lines = w.ts_lines; cur_nums->_columns = w.ts_cols;# ifdef DUMPTI printf("ioctl TIOCGSIZE override: (lines, columns)=(%d, %d)\n", w.ts_lines, w.ts_cols);# endif /* DUMPTI */ } }# endif /* TIOCGSIZE */#endif /* TIOCGWINSZ */ /* * Check $LINES and $COLUMNS. */ { int ilines = 0, icolumns = 0; lcp = getenv("LINES"); ccp = getenv("COLUMNS"); if (lcp) if ((ilines = atoi(lcp)) > 0) { cur_nums->_lines = ilines;#ifdef DUMPTI printf("$LINES override: lines=%d\n", ilines);#endif /* DUMPTI */ } if (ccp) if ((icolumns = atoi(ccp)) > 0) { cur_nums->_columns = icolumns;#ifdef DUMPTI printf("$COLUMNS override: columns=%d\n", icolumns);#endif /* DUMPTI */ } } /* Pull out the strings. */ { register char **pp = &cur_strs->strs._back_tab; char **fp = &cur_strs->strs3.Sentinel;#ifdef DUMPTI register int tempindex = 0; register char *startstr = ip + sizeof(short) * nstrs; printf("string table = '"); _Mprint(sstrtab, startstr); printf("'\n");#endif /* DUMPTI */ while (nstrs--) { n = _Getshi();#ifdef DUMPTI Vr2val = _Vr2getshi(); printf("String %s [%s] (%s) offset = %d [%d]", strfnames[tempindex], strnames[tempindex], strcodes[tempindex], n, Vr2val); tempindex++;#endif /* DUMPTI */ if (pp < fp) {#ifdef DUMPTI _Sprint(n, startstr+n);#endif /* DUMPTI */ if (n < 0) *pp++ = NULL; else *pp++ = strtab + n; }#ifdef DUMPTI else _Sprint(-1, (char *) 0);#endif /* DUMPTI */ } if (pp < fp) (void) memset((char *) pp, 0, (int) ((fp - pp) * sizeof(charptr))); } (void) memcpy(strtab, ip, sstrtab);#ifndef DUMPTI /* * If tabs are being expanded in software, turn this off * so output won't get messed up. Also, don't use tab * or backtab, even if the terminal has them, since the * user might not have hardware tabs set right. */#ifdef SYSV if ((PROGTTY.c_oflag & TABDLY) == TAB3) { PROGTTY.c_oflag &= ~TABDLY; if (PROGTTY.c_oflag == OPOST) PROGTTY.c_oflag = 0; reset_prog_mode(); goto next; }#else /* SYSV */ if ((PROGTTY.sg_flags & XTABS) == XTABS) { PROGTTY.sg_flags &= ~XTABS; reset_prog_mode(); goto next; }#endif /* SYSV */ if (dest_tabs_magic_smso) {next: cur_strs->strs2._tab = cur_strs->strs._back_tab = NULL; }#ifdef LTILDE ioctl(cur_term -> Filedes, TIOCLGET, &n);#endif /* LTILDE */#endif /* DUMPTI */#ifdef _VR2_COMPAT_CODE (void) memcpy(&cur_term->_b1, &cur_bools->_auto_left_margin, (char *) &cur_term->_c1 - (char *) &cur_term->_b1); (void) memcpy((char *) &cur_term->_c1, (char *) &cur_nums->_columns, (char *) &cur_term->_Vr2_Astrs._s1 - (char *) &cur_term->_c1); (void) memcpy((char *) &cur_term->_Vr2_Astrs._s1, (char *) &cur_strs->strs._back_tab, (char *) &cur_term->Filedes - (char *) &cur_term->_Vr2_Astrs._s1);#endif /* _VR2_COMPAT_CODE */ on_sequences = cur_term->turn_on_seq; str_array = (char **) cur_strs; { static char offsets[] = { 35, /* enter_standout_mode, */ 36, /* enter_underline_mode, */ 25, /* enter_alt_charset_mode, */ 34, /* enter_reverse_mode, */ 26, /* enter_blink_mode, */ 30, /* enter_dim_mode, */ 27, /* enter_bold_mode, */ 32, /* enter_secure_mode, */ 33, /* enter_protected_mode, */ }; for (n = 0; n < NUM_ATTRIBUTES; n++) { if (on_sequences[n] = str_array[offsets[n]]) cur_term->bit_vector |= bit_attributes[n]; } } if (!(set_attributes)) { static char faked_attrs[] = { 1, 3, 4, 6 }, offsets[] = { 43, /* exit_standout_mode, */ 44, /* exit_underline_mode, */ 38, /* exit_alt_charset_mode, */ }; char **off_sequences = cur_term->turn_off_seq; int i; if ((max_attributes == -1) && (ceol_standout_glitch || (magic_cookie_glitch >= 0))) max_attributes = 1; /* Figure out what attributes need to be faked. See vidupdate.c */ for (n = 0; n < sizeof(faked_attrs); n++) { if ((!on_sequences[i = faked_attrs[n]]) || (stringsneq(on_sequences[i], on_sequences[0]) == 0)) { cur_term->sgr_faked |= bit_attributes[i]; } } cur_term->check_turn_off = A_STANDOUT | A_UNDERLINE | A_ALTCHARSET; for (n = 0; n < sizeof(offsets); n++) { if ((!(off_sequences[n] = str_array[offsets[n]])) || ((n > 0) && (stringsneq(off_sequences[n], off_sequences[0]) == 0)) || ((n == 2) && (stringsneq(exit_attribute_mode, off_sequences[n]) == 0))) { cur_term->check_turn_off &= ~bit_attributes[n]; } } } cur_term->cursor_seq[0] = cursor_invisible; cur_term->cursor_seq[1] = cursor_normal; cur_term->cursor_seq[2] = cursor_visible; return (OK);}void_blast_keys(terminal)TERMINAL *terminal;{ terminal->_keys = NULL; terminal->internal_keys = NULL; terminal->_ksz = terminal->_first_macro = 0; terminal->_lastkey_ordered = terminal->_lastmacro_ordered = -1; (void) memset((char*)terminal->funckeystarter, 0, 0400 * sizeof(bool));}static intstringsneq(str1, str2)char *str1, *str2;{ if (str1 == NULL) return (str2 != NULL); if (str2 == NULL) return (1); return (strcmp(str1, str2));}#ifndef DUMPTIreset_prog_mode(){ if (_BR(PROGTTY))#ifdef SYSV (void) ioctl(cur_term -> Filedes, TCSETAW, &PROGTTY);#else /* SYSV */ (void) ioctl(cur_term -> Filedes, TIOCSETN, &PROGTTY);#endif /* SYSV */#ifdef LTILDE ioctl(cur_term -> Filedes, TIOCLGET, &cur_term -> oldlmode); cur_term -> newlmode = cur_term -> oldlmode & ~LTILDE; if (cur_term -> newlmode != cur_term -> oldlmode) ioctl(cur_term -> Filedes, TIOCLSET, &cur_term -> newlmode);#endif /* LTILDE */#ifdef DIOCSETT if (cur_term -> old.st_termt == 0) ioctl(cur_term->Filedes, DIOCGETT, &cur_term -> old); cur_term -> new = cur_term -> old; cur_term -> new.st_termt = 0; cur_term -> new.st_flgs |= TM_SET; ioctl(cur_term->Filedes, DIOCSETT, &cur_term -> new);#endif /* DIOCSETT */ return (OK);}def_shell_mode(){#ifdef SYSV (void) ioctl(cur_term -> Filedes, TCGETA, &SHELLTTY);#else /* SYSV */ (void) ioctl(cur_term -> Filedes, TIOCGETP, &SHELLTTY);#endif /* SYSV */ return (OK);}#endif /* DUMPTI */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -