--- console-2.3.51.c 2000/03/11 07:01:07 1.1 +++ console-2.3.51.c 2000/03/11 17:17:54 1.5 @@ -66,6 +66,11 @@ * * Resurrected character buffers in videoram plus lots of other trickery * by Martin Mares , July 1998 + * + * ECMA-35 (ISO 2022), ECMA-48 (ISO 6429) and missing DEC VT-series functions + * by Dominik Kubla , February 1999 + * Adapted for 2.3.51 and changes conditionalized according to VTE_VERSION + * by Eric S. Raymond , March 2000. */ #include @@ -143,8 +148,8 @@ unsigned int cols, int do_clear); static void blank_screen(void); static void gotoxy(int currcons, int new_x, int new_y); -static void save_cur(int currcons); -static void reset_terminal(int currcons, int do_clear); +static void vte_decsc(int currcons); +static void vte_ris(int currcons, int do_clear); static void con_flush_chars(struct tty_struct *tty); static void set_vesa_blanking(unsigned long arg); static void set_cursor(int currcons); @@ -238,7 +243,7 @@ unsigned short *d, *s; if (t+nr >= b) - nr = b - t - 1; + nr = b - t; if (b > video_num_lines || t >= b || nr < 1) return; if (IS_VISIBLE && sw->con_scroll(vc_cons[currcons].d, t, b, SM_UP, nr)) @@ -256,7 +261,7 @@ unsigned int step; if (t+nr >= b) - nr = b - t - 1; + nr = b - t; if (b > video_num_lines || t >= b || nr < 1) return; if (IS_VISIBLE && sw->con_scroll(vc_cons[currcons].d, t, b, SM_DOWN, nr)) @@ -369,7 +374,7 @@ static void update_attr(int currcons) { attr = build_attr(currcons, color, intensity, blink, underline, reverse ^ decscnm); - video_erase_char = (build_attr(currcons, color, 1, 0, 0, decscnm) << 8) | ' '; + video_erase_char = (build_attr(currcons, color, intensity, 0, 0, decscnm) << 8) | ' '; } /* Note: inverting the screen twice should revert to the original state */ @@ -750,11 +755,11 @@ screenbuf_size = ss; set_origin(currcons); - /* do part of a reset_terminal() */ + /* do part of a vte_ris() */ top = 0; bottom = video_num_lines; gotoxy(currcons, x, y); - save_cur(currcons); + vte_decsc(currcons); if (console_table[currcons]) { struct winsize ws, *cws = &console_table[currcons]->winsize; @@ -789,7 +794,13 @@ /* * VT102 emulator + * + * VTE_VERSION selects the version of the emulation + * + * 20x is bug-fixes only (for the 2.3.x series). + * 21x improves VT100 and ECMA-48 conformance. */ +#define VTE_VERSION 210 #define set_kbd(x) set_vc_kbd_mode(kbd_table+currcons,x) #define clr_kbd(x) clr_vc_kbd_mode(kbd_table+currcons,x) @@ -874,7 +885,10 @@ scrolldelta(lines); } -static void lf(int currcons) +/* + * LINE FEED (LF) + */ +static void vte_lf(int currcons) { /* don't scroll if above bottom of scrolling region, or * if below scrolling region @@ -888,9 +902,12 @@ need_wrap = 0; } -static void ri(int currcons) +/* + * REVERSE LINE FEED (RI) + */ +static void vte_ri(int currcons) { - /* don't scroll if below top of scrolling region, or + /* don't scroll if below top of scrolling region, or * if above scrolling region */ if (y == top) @@ -902,13 +919,19 @@ need_wrap = 0; } -static inline void cr(int currcons) +/* + * CARRIAGE RETURN (CR) + */ +static inline void vte_cr(int currcons) { pos -= x<<1; need_wrap = x = 0; } -static inline void bs(int currcons) +/* + * BACK SPACE (BS) + */ +static inline void vte_bs(int currcons) { if (x) { pos -= 2; @@ -917,12 +940,64 @@ } } -static inline void del(int currcons) +#if VTE_VERSION >= 210 +/* + * CURSOR LINE TABULATION (CVT) + * + * NOTE: + * In accordance with our interpretation of VT as LF we will treat CVT as + * (par[0] * LF). Not very creative, but at least consequent. + */ +static void vte_cvt(int currcons, int vpar) { - /* ignored */ + int i; + + for (i = 0; i < vpar; i++) { + vte_lf(currcons); + } } -static void csi_J(int currcons, int vpar) +/* + * CURSOR BACKWARD TABULATION (CBT) + */ +static void vte_cbt(int currcons, int vpar) +{ + int i; + + for (i = 0; i < vpar; i++) { + pos -= (x << 1); + while (x > 0) { + x--; + if (tab_stop[x >> 5] & (1 << (x & 31))) + break; + } + pos += (x << 1); + } +} + +/* + * CURSOR FORWARD TABULATION (CHT) + */ +static void vte_cht(int currcons, int vpar) +{ + int i; + + for (i = 0; i < vpar; i++) { + pos -= (x << 1); + while (x < video_num_columns - 1) { + x++; + if (tab_stop[x >> 5] & (1 << (x & 31))) + break; + } + pos += (x << 1); + } +} +#endif /* VTE_VERSION >= 210 */ + +/* + * ERASE IN PAGE (ED) + */ +static void vte_ed(int currcons, int vpar) { unsigned int count; unsigned short * start; @@ -966,7 +1041,10 @@ need_wrap = 0; } -static void csi_K(int currcons, int vpar) +/* + * ERASE IN LINE (EL) + */ +static void vte_el(int currcons, int vpar) { unsigned int count; unsigned short * start; @@ -1000,8 +1078,13 @@ need_wrap = 0; } -static void csi_X(int currcons, int vpar) /* erase the following vpar positions */ -{ /* not vt100? */ +/* + * Erase character (ECH) + * + * NOTE: This function is not available in DEC VT1xx terminals. + */ +static void vte_ech(int currcons, int vpar) +{ int count; if (!vpar) @@ -1023,7 +1106,12 @@ color = def_color; } -static void csi_m(int currcons) +/* + * SELECT GRAPHIC RENDITION (SGR) + * + * NOTE: The DEC vt1xx series only implements attribute values 0,1,4,5 and 7. + */ +static void vte_sgr(int currcons) { int i; @@ -1032,78 +1120,65 @@ case 0: /* all attributes off */ default_attr(currcons); break; - case 1: + case 1: /* bold or increased intensity */ intensity = 2; break; - case 2: + case 2: /* faint or decreased intensity */ intensity = 0; break; - case 4: + case 4: /* singly underlined. */ underline = 1; break; - case 5: + case 5: /* slowly blinking (< 2.5 Hz) */ +#if VTE_VERSION >= 210 + case 6: /* rapidly blinking (>= 2.5 Hz) */ +#endif /* VTE_VERSION >= 210 */ blink = 1; break; - case 7: + case 7: /* negative image */ reverse = 1; break; - case 10: /* ANSI X3.64-1979 (SCO-ish?) - * Select primary font, don't display - * control chars if defined, don't set - * bit 8 on output. - */ + case 10: /* primary (default) font */ translate = set_translate(charset == 0 ? G0_charset : G1_charset,currcons); disp_ctrl = 0; toggle_meta = 0; break; - case 11: /* ANSI X3.64-1979 (SCO-ish?) - * Select first alternate font, lets - * chars < 32 be displayed as ROM chars. - */ + case 11: /* first alternative font */ translate = set_translate(IBMPC_MAP,currcons); disp_ctrl = 1; toggle_meta = 0; break; - case 12: /* ANSI X3.64-1979 (SCO-ish?) - * Select second alternate font, toggle - * high bit before displaying as ROM char. - */ + case 12: /* second alternative font */ translate = set_translate(IBMPC_MAP,currcons); disp_ctrl = 1; toggle_meta = 1; break; - case 21: - case 22: +#if VTE_VERSION < 199 + case 21: /* normal intensity */ +#endif /* VTE_VERSION < 199 */ + case 22: /* normal intensity */ intensity = 1; break; - case 24: + case 24: /* not underlined (neither singly nor doubly) */ underline = 0; break; - case 25: + case 25: /* steady (not blinking) */ blink = 0; break; - case 27: + case 27: /* positive image */ reverse = 0; break; - case 38: /* ANSI X3.64-1979 (SCO-ish?) - * Enables underscore, white foreground - * with white underscore (Linux - use - * default foreground). - */ + case 38: /* foreground color (ISO 8613-6/ITU T.416) */ color = (def_color & 0x0f) | background; underline = 1; break; - case 39: /* ANSI X3.64-1979 (SCO-ish?) - * Disable underline option. - * Reset colour to default? It did this - * before... - */ + case 39: /* default display color */ color = (def_color & 0x0f) | background; underline = 0; break; - case 49: + case 49: /* default background color */ color = (def_color & 0xf0) | foreground; break; default: @@ -1127,24 +1202,82 @@ con_schedule_flip(tty); } -static void cursor_report(int currcons, struct tty_struct * tty) +#if VTE_VERSION >= 210 +/* + * Fake a DEC DSR for non-implemented features + */ +static void vte_fake_dec_dsr(struct tty_struct *tty, char *reply) +{ + char buf[40]; + sprintf(buf, "\033[?%sn", reply); + respond_string(buf, tty); +} +#endif /* VTE_VERSION >= 210 */ + +/* + * CURSOR POSITION REPORT (CPR) + * DEC EXTENDED CURSOR POSITION REPORT (DECXCPR) + */ +static void vte_cpr(int currcons, struct tty_struct *tty, int ext) { char buf[40]; - sprintf(buf, "\033[%d;%dR", y + (decom ? top+1 : 1), x+1); +#if VTE_VERSION >= 210 + if (ext) { + /* + * NOTE: + * Since we don't implement any form of page memory, we will + * always return the cursor position in page 1. + */ + sprintf(buf, "\033[?%d;%d;1R", y + (decom ? top + 1 : 1), x+1); + } else +#endif /* VTE_VERSION >= 210 */ + sprintf(buf, "\033[%d;%dR", y + (decom ? top + 1 : 1), x+1); respond_string(buf, tty); } -static inline void status_report(struct tty_struct * tty) +/* + * DEVICE STATUS REPORT (DSR) + */ +static inline void vte_dsr(struct tty_struct * tty) { - respond_string("\033[0n", tty); /* Terminal ok */ + respond_string("\033[0n", tty); /* Terminal ok */ } -static inline void respond_ID(struct tty_struct * tty) +/* + * ANSWERBACK MESSAGE + */ +static inline void vte_answerback(struct tty_struct *tty) +{ + respond_string("l i n u x", tty); +} + +/* + * DEVICE ATTRIBUTE (DA) + */ +static inline void vte_da(struct tty_struct *tty) { respond_string(VT102ID, tty); } +#if VTE_VERSION >= 210 +/* + * DEC REPORT TERMINAL PARAMETERS (DECREPTPARM) + * + * NOTE: This function is _only_ available on DEV VT1xx terminals. + * + * XXX Fixme! Report should reflect actual parameters instead of being hard + * coded. -dbk + */ +static void vte_decreptparm(int currcons, struct tty_struct *tty) +{ + char buf[40]; + + sprintf(buf, "\033[%d;1;1;120;120;1;0x", par[0] + 2); + respond_string(buf, tty); +} +#endif /* VTE_VERSION >= 210 */ + void mouse_report(struct tty_struct * tty, int butt, int mrx, int mry) { char buf[8]; @@ -1162,6 +1295,10 @@ return report_mouse; } +/* + * Set mode (SM / DECSM) + * Reset mode (RM / DECRM) + */ static void set_mode(int currcons, int on_off) { int i; @@ -1294,7 +1431,12 @@ need_wrap = 0; } -static void csi_at(int currcons, unsigned int nr) +/* + * INSERT CHARACTER (ICH) + * + * NOTE: This function is not available in DEC VT1xx terminals. + */ +static void vte_ich(int currcons, unsigned int nr) { if (nr > video_num_columns - x) nr = video_num_columns - x; @@ -1303,7 +1445,10 @@ insert_char(currcons, nr); } -static void csi_L(int currcons, unsigned int nr) +/* + * INSERT LINE (IL) + */ +static void vte_il(int currcons, unsigned int nr) { if (nr > video_num_lines - y) nr = video_num_lines - y; @@ -1312,7 +1457,10 @@ insert_line(currcons, nr); } -static void csi_P(int currcons, unsigned int nr) +/* + * DELETE CHARACTER (DCH) + */ +static void vte_dch(int currcons, unsigned int nr) { if (nr > video_num_columns - x) nr = video_num_columns - x; @@ -1321,7 +1469,10 @@ delete_char(currcons, nr); } -static void csi_M(int currcons, unsigned int nr) +/* + * DELETE LINE (DL) + */ +static void vte_dl(int currcons, unsigned int nr) { if (nr > video_num_lines - y) nr = video_num_lines - y; @@ -1330,7 +1481,18 @@ delete_line(currcons, nr); } -static void save_cur(int currcons) +/* + * SAVE CURSOR (DECSC) + * + * This saves the following states: + * - cursor position + * - graphic rendition + * - character set shift state + * - state of wrap flag + * - state of origin mode + * - state of selective erase (not implemented) + */ +static void vte_decsc(int currcons) { saved_x = x; saved_y = y; @@ -1344,7 +1506,10 @@ saved_G1 = G1_charset; } -static void restore_cur(int currcons) +/* + * RESTORE CURSOR (DECRC) + */ +static void vte_decrc(int currcons) { gotoxy(currcons,saved_x,saved_y); intensity = s_intensity; @@ -1360,15 +1525,31 @@ need_wrap = 0; } -enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey, - EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd, - ESpalette }; +enum { ESinit, ESesc, EScsi, ESgetpars, ESgotpars, ESfunckey, + ESacs, ESscf, ESgzd4, ESg1d4, ESdocs, ESignore, ESosc, + ESpalette +}; -static void reset_terminal(int currcons, int do_clear) +/* + * RESET TO INITIAL STATE (RIS) + * + * On DEC terminals this causes the following: + * - all set-up parameters are replaced by power-up defaults + * - all communications lines are disconnected (should we send SIGHUP to + * controlling process?) + * - all user-defined keys are cleared (not implemented) + * - the screen is cleared + * - cursor is place to upper-left corner + * - SGR state is set to normal + * - selective erase attribute write state is set to "non-selective erase" + * (not implemented) + * - all character sets are set to default (not implemented) + */ +static void vte_ris(int currcons, int do_clear) { top = 0; bottom = video_num_lines; - vc_state = ESnormal; + vc_state = ESinit; ques = 0; translate = set_translate(LAT1_MAP,currcons); G0_charset = LAT1_MAP; @@ -1414,28 +1595,78 @@ bell_duration = DEFAULT_BELL_DURATION; gotoxy(currcons,0,0); - save_cur(currcons); + vte_decsc(currcons); if (do_clear) - csi_J(currcons,2); + vte_ed(currcons,2); +} + +/* + * TABULATION CLEAR (TBC) + * + * NOTE: + * In case of parameters 0 and 2 the number of lines affected depends on the + * setting of the Tabulation Stop Mode (TSM). Since we don't implement TSM, + * this is silently ignored. + * + * Parameters 1 and 4 are similiar to 0 and 3, but affect only line tabulation + * stops, which are not implemented. + * + * Parameter 2 may only be interpreted, when we implement a tabulation stop map + * per display line. + */ +static void vte_tbc(int currcons, int vpar) +{ + + switch (vpar) { + case 0: + /* + * The character tabulation stop at the active + * presentation position is cleared. + */ + tab_stop[x >> 5] &= ~(1 << (x & 31)); + return; +#if 0 + case 2: + /* + * All character tabulation stops in the active + * line are cleared. + */ +#endif + case 3: + /* + * All character tabulation stops are cleared. + */ + case 5: + /* + * All tabulation stops are cleared. + */ + tab_stop[0] = tab_stop[1] = tab_stop[2] = tab_stop[3] = + tab_stop[4] = 0; + } } static void do_con_trol(struct tty_struct *tty, unsigned int currcons, int c) { /* - * Control characters can be used in the _middle_ - * of an escape sequence. + * C0 CONTROL CHARACTERS + * + * NOTE: Control characters can be used in the _middle_ + * of an escape sequence. */ switch (c) { - case 0: + case 0x00: /* NUL - Null */ + return; + case 0x05: /* ENQ - Inquiry */ + vte_answerback(tty); return; - case 7: + case 0x07: /* BEL - Bell */ if (bell_duration) kd_mksound(bell_pitch, bell_duration); return; - case 8: - bs(currcons); + case 0x08: /* BS - Back space */ + vte_bs(currcons); return; - case 9: + case 0x09: /* HT - Character tabulation */ pos -= (x << 1); while (x < video_num_columns - 1) { x++; @@ -1444,104 +1675,185 @@ } pos += (x << 1); return; - case 10: case 11: case 12: - lf(currcons); + case 0x0a: /* LF - Line feed */ + case 0x0b: /* VT - Line tabulation */ + /* + * Since line tabulation is not implemented in the DEC VT + * series (except VT131 ?), the DEC VT series treats any + * VT as LF. + */ + case 0x0c: /* FF - Form feed */ + /* + * DEC VT series processes FF as LF. + */ + vte_lf(currcons); if (!is_kbd(lnm)) return; - case 13: - cr(currcons); + case 0x0d: /* CR - Carriage return */ + vte_cr(currcons); return; - case 14: + case 0x0e: /* SO - Shift out / LS1 - Locking shift 1 */ charset = 1; translate = set_translate(G1_charset,currcons); disp_ctrl = 1; return; - case 15: + case 0x0f: /* SI - Shift in / LS0 - Locking shift 0 */ charset = 0; translate = set_translate(G0_charset,currcons); disp_ctrl = 0; return; - case 24: case 26: - vc_state = ESnormal; + case 0x18: /* CAN - Cancel */ + case 0x1a: /* SUB - Substitute */ + vc_state = ESinit; return; - case 27: + case 0x1b: /* ESC - Escape */ vc_state = ESesc; return; - case 127: - del(currcons); + case 0x7f: /* DEL - Delete */ + /* + * This character is ignored, unless a 96-set has been mapped, + * but this is not supported at the moment. + */ + return; +#if VTE_VERSION >= 210 + /* + * C1 control functions (8-bit mode). + * + * XXX Fixme! Should only be interpreted if 8-bit controls are enabled. + * XXX Fixme! Should have all C1 controls implemented (acc. to ECMA). + */ + case 0x84: /* IND - Line feed (DEC only, dropped by ECMA/ISO) */ + vte_lf(currcons); + return; + case 0x85: /* NEL - Next line */ + vte_lf(currcons); + vte_cr(currcons); + return; + case 0x88: /* HTS - Character tabulation set */ + tab_stop[x >> 5] |= (1 << (x & 31)); + return; + case 0x8d: /* RI - Reverse line feed */ + vte_ri(currcons); return; - case 128+27: - vc_state = ESsquare; + case 0x9b: /* CSI - Control sequence introducer */ + vc_state = EScsi; return; +#endif /* VTE_VERSION >= 210 */ } + switch(vc_state) { case ESesc: - vc_state = ESnormal; + vc_state = ESinit; switch (c) { - case '[': - vc_state = ESsquare; + +#if 0 + case ' ': /* ACS - Announce code structure */ + vc_state = ESacs; return; - case ']': - vc_state = ESnonstd; +#endif + case '#': /* SCF - Single control functions */ + vc_state = ESscf; return; - case '%': - vc_state = ESpercent; + case '%': /* DOCS - Designate other coding system */ + vc_state = ESdocs; return; - case 'E': - cr(currcons); - lf(currcons); + case '(': /* GZD4 - G0-designate 94-set */ + vc_state = ESgzd4; return; - case 'M': - ri(currcons); + case ')': /* G1D4 - G1-designate 94-set */ + vc_state = ESg1d4; return; - case 'D': - lf(currcons); + + /* ===== Private control functions ===== */ + + case '7': /* DECSC - Save cursor */ + vte_decsc(currcons); return; - case 'H': - tab_stop[x >> 5] |= (1 << (x & 31)); + case '8': /* DECRC - Restore cursor */ + vte_decrc(currcons); return; - case 'Z': - respond_ID(tty); + case '=': /* DECKPAM - Keypad application mode */ + set_kbd(kbdapplic); return; - case '7': - save_cur(currcons); + case '>': /* DECKPNM - Keypad numeric mode */ + clr_kbd(kbdapplic); return; - case '8': - restore_cur(currcons); + + /* ===== C1 control functions ===== */ + + case 'D': /* IND - Line feed (DEC only, dropped by ECMA/ISO) */ + vte_lf(currcons); return; - case '(': - vc_state = ESsetG0; + case 'E': /* NEL - Next line */ + vte_cr(currcons); + vte_lf(currcons); return; - case ')': - vc_state = ESsetG1; + case 'H': /* HTS - Character tabulation set */ + tab_stop[x >> 5] |= (1 << (x & 31)); return; - case '#': - vc_state = EShash; + case 'M': /* RI - Reverse line feed */ + vte_ri(currcons); return; - case 'c': - reset_terminal(currcons,1); + case 'Z': /* DECID - Identify terminal */ + /* XXX: This clashes with ISO 6429! */ + vte_da(tty); return; - case '>': /* Numeric keypad */ - clr_kbd(kbdapplic); + case '[': /* CSI - Control sequence introducer */ + vc_state = EScsi; return; - case '=': /* Appl. keypad */ - set_kbd(kbdapplic); + case ']': /* OSC - Operating system command */ + /* XXX: Fixme! Wrong sequence and format! */ + vc_state = ESosc; + return; + + /* ===== Single control functions ===== */ + + case '`': /* DMI - Disable manual input */ + case 'b': /* EMI - Enable manual input */ + /* XXX: Implement this together with KAM */ + return; + case 'c': /* RIS - Reset ti initial state */ + vte_ris(currcons,1); return; } return; - case ESnonstd: - if (c=='P') { /* palette escape sequence */ - for (npar=0; npar='0'&&c<='9') || (c>='A'&&c<='F') || (c>='a'&&c<='f') ) { par[npar++] = (c>'9' ? (c&0xDF)-'A'+10 : c-'0') ; @@ -1554,12 +1866,12 @@ palette[i] = 16*par[j++]; palette[i] += par[j]; set_palette(currcons); - vc_state = ESnormal; + vc_state = ESinit; } } else - vc_state = ESnormal; + vc_state = ESinit; return; - case ESsquare: + case EScsi: for(npar = 0 ; npar < NPAR ; npar++) par[npar] = 0; npar = 0; @@ -1581,20 +1893,26 @@ return; } else vc_state=ESgotpars; case ESgotpars: - vc_state = ESnormal; + vc_state = ESinit; switch(c) { - case 'h': + case 'h': /* SM / DECSM - set mode */ set_mode(currcons,1); return; - case 'l': + case 'l': /* RM / DECRM - reset mode */ set_mode(currcons,0); return; case 'c': + /* + * XXX Fixme! Need to use final byte reserved for + * private sequences instead of flag designating + * private parameters! + */ if (ques) { if (par[0]) cursor_type = par[0] | (par[1]<<8) | (par[2]<<16); else cursor_type = CUR_DEFAULT; + ques = 0; return; } break; @@ -1605,16 +1923,41 @@ complement_mask = par[0]<<8 | par[1]; else complement_mask = s_complement_mask; + ques = 0; return; } break; case 'n': - if (!ques) { - if (par[0] == 5) - status_report(tty); - else if (par[0] == 6) - cursor_report(currcons,tty); - } +#if VTE_VERSION >= 210 + if (ques) { + switch (par[0]) { + case 6: /* DECXCPR - Extended CPR */ + vte_cpr(currcons, tty, 1); + break; + case 15: /* DEC printer status */ + vte_fake_dec_dsr(tty, "13"); + break; + case 25: /* DEC UDK status */ + vte_fake_dec_dsr(tty, "21"); + break; + case 26: /* DEC keyboard status */ + vte_fake_dec_dsr(tty, "27;1;0;1"); + break; + case 75: /* DEC data integrity */ + vte_fake_dec_dsr(tty, "70"); + break; + } + } else +#endif /* VTE_VERSION >= 210 */ + switch (par[0]) { + case 5: /* DSR - Device status report */ + vte_dsr(tty); + break; + case 6: /* CPR - Cursor position report */ + vte_cpr(currcons,tty,0); + break; + } + ques = 0; return; } if (ques) { @@ -1622,83 +1965,151 @@ return; } switch(c) { - case 'G': case '`': - if (par[0]) par[0]--; - gotoxy(currcons,par[0],y); + + /* ===== Control functions w/ intermediate byte ===== */ + +#if 0 + case ' ': /* Intermediate byte: SP (ISO 6429) */ + vc_state = EScsi_space; + return; +#endif + + /* ===== Control functions w/o intermediate byte ===== */ + + case '@': /* ICH - Insert character */ + vte_ich(currcons,par[0]); return; - case 'A': + case 'A': /* CUU - Cursor up */ +#if VTE_VERSION >= 210 + case 'k': /* VPB - Line position backward */ +#endif /* VTE_VERSION >= 210 */ if (!par[0]) par[0]++; gotoxy(currcons,x,y-par[0]); return; - case 'B': case 'e': + case 'B': /* CUD - Cursor down */ + case 'e': /* VPR - Line position forward */ if (!par[0]) par[0]++; gotoxy(currcons,x,y+par[0]); return; - case 'C': case 'a': + case 'C': /* CUF - Cursor right */ + case 'a': /* HPR - Character position forward */ if (!par[0]) par[0]++; gotoxy(currcons,x+par[0],y); return; - case 'D': + case 'D': /* CUB - Cursor left */ +#if VTE_VERSION >= 210 + case 'j': /* HPB - Character position backward */ +#endif /* VTE_VERSION >= 210 */ if (!par[0]) par[0]++; gotoxy(currcons,x-par[0],y); return; - case 'E': + case 'E': /* CNL - Cursor next line */ if (!par[0]) par[0]++; gotoxy(currcons,0,y+par[0]); return; - case 'F': + case 'F': /* CPL - Cursor preceeding line */ if (!par[0]) par[0]++; gotoxy(currcons,0,y-par[0]); return; - case 'd': + case 'G': /* CHA - Cursor character absolute */ + case '`': /* HPA - Character position absolute */ if (par[0]) par[0]--; - gotoxay(currcons,x,par[0]); + gotoxy(currcons,par[0],y); return; - case 'H': case 'f': + case 'H': /* CUP - Cursor position */ + case 'f': /* HVP - Horizontal and vertical position */ if (par[0]) par[0]--; if (par[1]) par[1]--; gotoxay(currcons,par[1],par[0]); return; - case 'J': - csi_J(currcons,par[0]); +#if VTE_VERSION >= 210 + case 'I': /* CHT - Cursor forward tabulation */ + if (!par[0]) + par[0]++; + vte_cht(currcons, par[0]); + return; +#endif /* VTE_VERSION >= 210 */ + case 'J': /* ED - Erase in page */ + vte_ed(currcons,par[0]); + return; + case 'K': /* EL - Erase in line */ + vte_el(currcons,par[0]); + return; + case 'L': /* IL - Insert line */ + vte_il(currcons,par[0]); + return; + case 'M': /* DL - Delete line */ + vte_dl(currcons,par[0]); + return; + case 'P': /* DCH - Delete character */ + vte_dch(currcons,par[0]); + return; +#if VTE_VERSION >= 210 + case 'W': /* CTC - Cursor tabulation control */ + switch (par[0]) { + case 0: /* Set character tab stop at current position */ + tab_stop[x >> 5] |= (1 << (x & 31)); + return; + case 2: /* Clear character tab stop at curr. position */ + vte_tbc(currcons, 0); + return; + case 5: /* All character tab stops are cleared. */ + vte_tbc(currcons, 5); + return; + } return; - case 'K': - csi_K(currcons,par[0]); +#endif /* VTE_VERSION >= 210 */ + case 'X': /* ECH - Erase character */ + vte_ech(currcons, par[0]); return; - case 'L': - csi_L(currcons,par[0]); +#if VTE_VERSION >= 210 + case 'Y': /* CVT - Cursor line tabulation */ + if (!par[0]) + par[0]++; + vte_cvt(currcons, par[0]); return; - case 'M': - csi_M(currcons,par[0]); + case 'Z': /* CBT - Cursor backward tabulation */ + vte_cbt(currcons, par[0]); return; - case 'P': - csi_P(currcons,par[0]); +#endif /* VTE_VERSION >= 210 */ + case ']': /* setterm functions */ + /* XXX Fixme! This collides with ISO 6429 */ + setterm_command(currcons); return; - case 'c': + case 'c': /* DA - Device attribute */ if (!par[0]) - respond_ID(tty); + vte_da(tty); return; - case 'g': - if (!par[0]) - tab_stop[x >> 5] &= ~(1 << (x & 31)); - else if (par[0] == 3) { - tab_stop[0] = - tab_stop[1] = - tab_stop[2] = - tab_stop[3] = - tab_stop[4] = 0; - } + case 'd': /* VPA - Line position absolute */ + if (par[0]) par[0]--; + gotoxay(currcons,x,par[0]); return; - case 'm': - csi_m(currcons); + case 'g': /* TBC - Tabulation clear */ + vte_tbc(currcons, par[0]); return; + case 'm': /* SGR - Select graphics rendition */ + vte_sgr(currcons); + return; + + /* ===== Private control sequences ===== */ + case 'q': /* DECLL - but only 3 leds */ - /* map 0,1,2,3 to 0,1,2,4 */ +#if 0 + switch (par[0]) { + case 0: /* all LEDs off */ + case 1: /* LED 1 on */ + case 2: /* LED 2 on */ + case 3: /* LED 3 on */ + case 4: /* LED 4 on */ + } +#else + /* map 0,1,2,3 to 0,1,2,4 */ /* huh? */ if (par[0] < 4) setledstate(kbd_table + currcons, (par[0] < 3) ? par[0] : 4); +#endif return; - case 'r': + case 'r': /* DECSTBM - Set top and bottom margin */ if (!par[0]) par[0]++; if (!par[1]) @@ -1711,25 +2122,23 @@ gotoxay(currcons,0,0); } return; - case 's': - save_cur(currcons); +#if VTE_VERSION < 199 + case 's': /* DECSC - Save cursor */ + vte_decsc(currcons); return; - case 'u': - restore_cur(currcons); + case 'u': /* DECRC - Restore cursor */ + vte_decrc(currcons); return; - case 'X': - csi_X(currcons, par[0]); - return; - case '@': - csi_at(currcons,par[0]); - return; - case ']': /* setterm functions */ - setterm_command(currcons); +#endif /* VTE_VERSION < 199 */ +#if VTE_VERSION >= 210 + case 'x': /* DECREQTPARM - Request terminal parameters */ + vte_decreptparm(currcons, tty); return; +#endif /* VTE_VERSION >= 210 */ } return; - case ESpercent: - vc_state = ESnormal; + case ESdocs: + vc_state = ESinit; switch (c) { case '@': /* defined in ISO 2022 */ utf = 0; @@ -1741,48 +2150,86 @@ } return; case ESfunckey: - vc_state = ESnormal; + vc_state = ESinit; return; - case EShash: - vc_state = ESnormal; + case ESscf: + vc_state = ESinit; if (c == '8') { /* DEC screen alignment test. kludge :-) */ video_erase_char = (video_erase_char & 0xff00) | 'E'; - csi_J(currcons, 2); + vte_ed(currcons, 2); video_erase_char = (video_erase_char & 0xff00) | ' '; do_update_region(currcons, origin, screenbuf_size/2); } return; - case ESsetG0: - if (c == '0') + case ESgzd4: + switch (c) { + case '0': /* DEC Special graphics */ G0_charset = GRAF_MAP; - else if (c == 'B') + break; +#if 0 + case '>': /* DEC Technical */ + G0_charset = DEC_TECH_MAP; + break; + case 'A': /* ISO Latin-1 supplemental */ + G0_charset = ISO_LAT1_MAP; + break; +#endif + case 'B': /* ASCII */ G0_charset = LAT1_MAP; - else if (c == 'U') + break; + case 'U': G0_charset = IBMPC_MAP; - else if (c == 'K') + break; + case 'K': + /* + * XXX FIXME! + * This is German NRCS on DEC VT! User-preferred + * supplemental map is '<'! + */ G0_charset = USER_MAP; + break; + } if (charset == 0) translate = set_translate(G0_charset,currcons); - vc_state = ESnormal; + vc_state = ESinit; return; - case ESsetG1: - if (c == '0') + case ESg1d4: + switch (c) { + case '0': /* DEC Special graphics */ G1_charset = GRAF_MAP; - else if (c == 'B') + break; +#if 0 + case '>': /* DEC Technical */ + G1_charset = DEC_TECH_MAP; + break; + case 'A': /* ISO Latin-1 supplemental */ + G1_charset = ISO_LAT1_MAP; + break; +#endif + case 'B': /* ASCII */ G1_charset = LAT1_MAP; - else if (c == 'U') + break; + case 'U': G1_charset = IBMPC_MAP; - else if (c == 'K') + break; + case 'K': + /* + * XXX FIXME! + * This is German NRCS on DEC VT! User-preferred + * supplemental map is '<'! + */ G1_charset = USER_MAP; + break; + } if (charset == 1) translate = set_translate(G1_charset,currcons); - vc_state = ESnormal; + vc_state = ESinit; return; default: - vc_state = ESnormal; + vc_state = ESinit; } } @@ -1923,7 +2370,7 @@ && (c != 127 || disp_ctrl) && (c != 128+27); - if (vc_state == ESnormal && ok) { + if (vc_state == ESinit && ok) { /* Now try to find out how to display it */ tc = conv_uni_to_pc(vc_cons[currcons].d, tc); if ( tc == -4 ) { @@ -1946,8 +2393,8 @@ if (need_wrap || decim) FLUSH if (need_wrap) { - cr(currcons); - lf(currcons); + vte_cr(currcons); + vte_lf(currcons); } if (decim) insert_char(currcons, 1); @@ -2098,14 +2545,14 @@ cnt = 0; } if (c == 8) { /* backspace */ - bs(currcons); + vte_bs(currcons); start = (ushort *)pos; myx = x; continue; } if (c != 13) - lf(currcons); - cr(currcons); + vte_lf(currcons); + vte_cr(currcons); start = (ushort *)pos; myx = x; if (c == 10 || c == 13) @@ -2354,7 +2801,7 @@ ulcolor = 0x0f; /* bold white */ halfcolor = 0x08; /* grey */ init_waitqueue_head(&vt_cons[currcons]->paste_wait); - reset_terminal(currcons, do_clear); + vte_ris(currcons, do_clear); } /* @@ -2449,7 +2896,7 @@ set_origin(currcons); save_screen(currcons); gotoxy(currcons,x,y); - csi_J(currcons, 0); + vte_ed(currcons, 0); update_screen(fg_console); printk("Console: %s %s %dx%d", can_do_color ? "colour" : "mono",