From 4811a811d8eb224e0204305088e2f4c4524b5c53 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Sun, 7 Jan 2007 13:31:37 +0000 Subject: Some dynamically allocated elements are not considered of vital importance for the vt100 emulation to work well enough for most cases (i.e. alternate character set tables, non-default tab settings, etc). However, code did not always check if these elements had been successfully allocated before trying to use them, or worse, would explicitely panic in DIAGNOSTIC kernels. Change this to work in a degraded mode (by ignoring related escape sequences) instead. --- sys/dev/wscons/wsemul_vt100.c | 217 +++++++++++++++-------------- sys/dev/wscons/wsemul_vt100_chars.c | 38 +++-- sys/dev/wscons/wsemul_vt100_subr.c | 270 ++++++++++++++++++------------------ sys/dev/wscons/wsemul_vt100var.h | 4 +- 4 files changed, 274 insertions(+), 255 deletions(-) (limited to 'sys') diff --git a/sys/dev/wscons/wsemul_vt100.c b/sys/dev/wscons/wsemul_vt100.c index bab482e2a96..67834bca41d 100644 --- a/sys/dev/wscons/wsemul_vt100.c +++ b/sys/dev/wscons/wsemul_vt100.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsemul_vt100.c,v 1.16 2007/01/07 13:28:50 miod Exp $ */ +/* $OpenBSD: wsemul_vt100.c,v 1.17 2007/01/07 13:31:36 miod Exp $ */ /* $NetBSD: wsemul_vt100.c,v 1.13 2000/04/28 21:56:16 mycroft Exp $ */ /* @@ -176,12 +176,12 @@ wsemul_vt100_cnattach(type, cookie, ccol, crow, defattr) if (res) edp->kernattr = defattr; - edp->tabs = 0; - edp->dblwid = 0; + edp->tabs = NULL; + edp->dblwid = NULL; edp->dw = 0; edp->dcsarg = 0; - edp->isolatin1tab = edp->decgraphtab = edp->dectechtab = 0; - edp->nrctab = 0; + edp->isolatin1tab = edp->decgraphtab = edp->dectechtab = NULL; + edp->nrctab = NULL; wsemul_vt100_reset(edp); return (edp); } @@ -215,7 +215,8 @@ wsemul_vt100_attach(console, type, cookie, ccol, crow, cbcookie, defattr) edp->tabs = malloc(edp->ncols, M_DEVBUF, M_NOWAIT); edp->dblwid = malloc(edp->nrows, M_DEVBUF, M_NOWAIT); - memset(edp->dblwid, 0, edp->nrows); + if (edp->dblwid != NULL) + memset(edp->dblwid, 0, edp->nrows); edp->dw = 0; edp->dcsarg = malloc(DCS_MAXLEN, M_DEVBUF, M_NOWAIT); edp->isolatin1tab = malloc(128 * sizeof(int), M_DEVBUF, M_NOWAIT); @@ -236,7 +237,7 @@ wsemul_vt100_detach(cookie, crowp, ccolp) *crowp = edp->crow; *ccolp = edp->ccol; -#define f(ptr) if (ptr) {free(ptr, M_DEVBUF); ptr = 0;} +#define f(ptr) if (ptr) {free(ptr, M_DEVBUF); ptr = NULL;} f(edp->tabs) f(edp->dblwid) f(edp->dcsarg) @@ -295,7 +296,7 @@ wsemul_vt100_reset(edp) } edp->dcspos = 0; edp->dcstype = 0; - edp->chartab_G[0] = 0; + edp->chartab_G[0] = NULL; edp->chartab_G[1] = edp->nrctab; /* ??? */ edp->chartab_G[2] = edp->isolatin1tab; edp->chartab_G[3] = edp->isolatin1tab; @@ -376,24 +377,24 @@ wsemul_vt100_output_c0c1(edp, c, kernel) u_int n; switch (c) { - case ASCII_NUL: - default: + case ASCII_NUL: + default: /* ignore */ break; - case ASCII_BEL: + case ASCII_BEL: wsdisplay_emulbell(edp->cbcookie); break; - case ASCII_BS: + case ASCII_BS: if (edp->ccol > 0) { edp->ccol--; edp->flags &= ~VTFL_LASTCHAR; } break; - case ASCII_CR: + case ASCII_CR: edp->ccol = 0; edp->flags &= ~VTFL_LASTCHAR; break; - case ASCII_HT: + case ASCII_HT: if (edp->tabs) { if (!COLS_LEFT) break; @@ -405,13 +406,13 @@ wsemul_vt100_output_c0c1(edp, c, kernel) } edp->ccol = n; break; - case ASCII_SO: /* LS1 */ + case ASCII_SO: /* LS1 */ edp->chartab0 = 1; break; - case ASCII_SI: /* LS0 */ + case ASCII_SI: /* LS0 */ edp->chartab0 = 0; break; - case ASCII_ESC: + case ASCII_ESC: if (kernel) { printf("wsemul_vt100_output_c0c1: ESC in kernel " "output ignored\n"); @@ -427,27 +428,27 @@ wsemul_vt100_output_c0c1(edp, c, kernel) } break; #if 0 - case CSI: /* 8-bit */ + case CSI: /* 8-bit */ /* XXX cancel current escape sequence */ edp->nargs = 0; memset(edp->args, 0, sizeof (edp->args)); edp->modif1 = edp->modif2 = '\0'; edp->state = VT100_EMUL_STATE_CSI; break; - case DCS: /* 8-bit */ + case DCS: /* 8-bit */ /* XXX cancel current escape sequence */ edp->nargs = 0; memset(edp->args, 0, sizeof (edp->args)); edp->state = VT100_EMUL_STATE_DCS; break; - case ST: /* string end 8-bit */ + case ST: /* string end 8-bit */ /* XXX only in VT100_EMUL_STATE_STRING */ wsemul_vt100_handle_dcs(edp); return (VT100_EMUL_STATE_NORMAL); #endif - case ASCII_LF: - case ASCII_VT: - case ASCII_FF: + case ASCII_LF: + case ASCII_VT: + case ASCII_FF: wsemul_vt100_nextline(edp); break; } @@ -462,13 +463,13 @@ wsemul_vt100_output_esc(edp, c) int i; switch (c) { - case '[': /* CSI */ + case '[': /* CSI */ edp->nargs = 0; memset(edp->args, 0, sizeof (edp->args)); edp->modif1 = edp->modif2 = '\0'; newstate = VT100_EMUL_STATE_CSI; break; - case '7': /* DECSC */ + case '7': /* DECSC */ edp->flags |= VTFL_SAVEDCURS; edp->savedcursor_row = edp->crow; edp->savedcursor_col = edp->ccol; @@ -482,7 +483,7 @@ wsemul_vt100_output_esc(edp, c) edp->savedchartab0 = edp->chartab0; edp->savedchartab1 = edp->chartab1; break; - case '8': /* DECRC */ + case '8': /* DECRC */ if ((edp->flags & VTFL_SAVEDCURS) == 0) break; edp->crow = edp->savedcursor_row; @@ -497,44 +498,44 @@ wsemul_vt100_output_esc(edp, c) edp->chartab0 = edp->savedchartab0; edp->chartab1 = edp->savedchartab1; break; - case '=': /* DECKPAM application mode */ + case '=': /* DECKPAM application mode */ edp->flags |= VTFL_APPLKEYPAD; break; - case '>': /* DECKPNM numeric mode */ + case '>': /* DECKPNM numeric mode */ edp->flags &= ~VTFL_APPLKEYPAD; break; - case 'E': /* NEL */ + case 'E': /* NEL */ edp->ccol = 0; /* FALLTHRU */ - case 'D': /* IND */ + case 'D': /* IND */ wsemul_vt100_nextline(edp); break; - case 'H': /* HTS */ - KASSERT(edp->tabs != 0); - edp->tabs[edp->ccol] = 1; + case 'H': /* HTS */ + if (edp->tabs != NULL) + edp->tabs[edp->ccol] = 1; break; - case '~': /* LS1R */ + case '~': /* LS1R */ edp->chartab1 = 1; break; - case 'n': /* LS2 */ + case 'n': /* LS2 */ edp->chartab0 = 2; break; - case '}': /* LS2R */ + case '}': /* LS2R */ edp->chartab1 = 2; break; - case 'o': /* LS3 */ + case 'o': /* LS3 */ edp->chartab0 = 3; break; - case '|': /* LS3R */ + case '|': /* LS3R */ edp->chartab1 = 3; break; - case 'N': /* SS2 */ + case 'N': /* SS2 */ edp->sschartab = 2; break; - case 'O': /* SS3 */ + case 'O': /* SS3 */ edp->sschartab = 3; break; - case 'M': /* RI */ + case 'M': /* RI */ if (ROWS_ABOVE > 0) { edp->crow--; CHECK_DW; @@ -542,37 +543,37 @@ wsemul_vt100_output_esc(edp, c) } wsemul_vt100_scrolldown(edp, 1); break; - case 'P': /* DCS */ + case 'P': /* DCS */ edp->nargs = 0; memset(edp->args, 0, sizeof (edp->args)); newstate = VT100_EMUL_STATE_DCS; break; - case 'c': /* RIS */ + case 'c': /* RIS */ wsemul_vt100_reset(edp); wsemul_vt100_ed(edp, 2); edp->ccol = edp->crow = 0; break; - case '(': case ')': case '*': case '+': /* SCS */ + case '(': case ')': case '*': case '+': /* SCS */ edp->designating = c - '('; newstate = VT100_EMUL_STATE_SCS94; break; - case '-': case '.': case '/': /* SCS */ + case '-': case '.': case '/': /* SCS */ edp->designating = c - '-' + 1; newstate = VT100_EMUL_STATE_SCS96; break; - case '#': + case '#': newstate = VT100_EMUL_STATE_ESC_HASH; break; - case ' ': /* 7/8 bit */ + case ' ': /* 7/8 bit */ newstate = VT100_EMUL_STATE_ESC_SPC; break; - case ']': /* OSC operating system command */ - case '^': /* PM privacy message */ - case '_': /* APC application program command */ + case ']': /* OSC operating system command */ + case '^': /* PM privacy message */ + case '_': /* APC application program command */ /* ignored */ newstate = VT100_EMUL_STATE_STRING; break; - case '<': /* exit VT52 mode - ignored */ + case '<': /* exit VT52 mode - ignored */ break; default: #ifdef VT100_PRINTUNKNOWN @@ -592,23 +593,23 @@ wsemul_vt100_output_scs94(edp, c) u_int newstate = VT100_EMUL_STATE_NORMAL; switch (c) { - case '%': /* probably DEC supplemental graphic */ + case '%': /* probably DEC supplemental graphic */ newstate = VT100_EMUL_STATE_SCS94_PERCENT; break; - case 'A': /* british / national */ + case 'A': /* british / national */ edp->chartab_G[edp->designating] = edp->nrctab; break; - case 'B': /* ASCII */ + case 'B': /* ASCII */ edp->chartab_G[edp->designating] = 0; break; - case '<': /* user preferred supplemental */ + case '<': /* user preferred supplemental */ /* XXX not really "user" preferred */ edp->chartab_G[edp->designating] = edp->isolatin1tab; break; - case '0': /* DEC special graphic */ + case '0': /* DEC special graphic */ edp->chartab_G[edp->designating] = edp->decgraphtab; break; - case '>': /* DEC tech */ + case '>': /* DEC tech */ edp->chartab_G[edp->designating] = edp->dectechtab; break; default: @@ -626,7 +627,7 @@ wsemul_vt100_output_scs94_percent(edp, c) u_char c; { switch (c) { - case '5': /* DEC supplemental graphic */ + case '5': /* DEC supplemental graphic */ /* XXX there are differences */ edp->chartab_G[edp->designating] = edp->isolatin1tab; break; @@ -648,44 +649,45 @@ wsemul_vt100_output_scs96(edp, c) int nrc; switch (c) { - case '%': /* probably portugese */ + case '%': /* probably portugese */ newstate = VT100_EMUL_STATE_SCS96_PERCENT; break; - case 'A': /* ISO-latin-1 supplemental */ + case 'A': /* ISO-latin-1 supplemental */ edp->chartab_G[edp->designating] = edp->isolatin1tab; break; - case '4': /* dutch */ + case '4': /* dutch */ nrc = 1; goto setnrc; - case '5': case 'C': /* finnish */ + case '5': case 'C': /* finnish */ nrc = 2; goto setnrc; - case 'R': /* french */ + case 'R': /* french */ nrc = 3; goto setnrc; - case 'Q': /* french canadian */ + case 'Q': /* french canadian */ nrc = 4; goto setnrc; - case 'K': /* german */ + case 'K': /* german */ nrc = 5; goto setnrc; - case 'Y': /* italian */ + case 'Y': /* italian */ nrc = 6; goto setnrc; - case 'E': case '6': /* norwegian / danish */ + case 'E': case '6': /* norwegian / danish */ nrc = 7; goto setnrc; - case 'Z': /* spanish */ + case 'Z': /* spanish */ nrc = 9; goto setnrc; - case '7': case 'H': /* swedish */ + case '7': case 'H': /* swedish */ nrc = 10; goto setnrc; - case '=': /* swiss */ + case '=': /* swiss */ nrc = 11; setnrc: - vt100_setnrc(edp, nrc); /* what table ??? */ - break; + if (vt100_setnrc(edp, nrc) == 0) /* what table ??? */ + break; + /* else FALLTHROUGH */ default: #ifdef VT100_PRINTUNKNOWN printf("ESC%c%c unknown\n", edp->designating + '-' - 1, c); @@ -701,12 +703,13 @@ wsemul_vt100_output_scs96_percent(edp, c) u_char c; { switch (c) { - case '6': /* portugese */ - vt100_setnrc(edp, 8); - break; + case '6': /* portugese */ + if (vt100_setnrc(edp, 8) == 0) + break; + /* else FALLTHROUGH */ default: #ifdef VT100_PRINTUNKNOWN - printf("ESC%c%%%c unknown\n", edp->designating + '-', c); + printf("ESC%c%%%c unknown\n", edp->designating + '-' - 1, c); #endif break; } @@ -719,8 +722,8 @@ wsemul_vt100_output_esc_spc(edp, c) u_char c; { switch (c) { - case 'F': /* 7-bit controls */ - case 'G': /* 8-bit controls */ + case 'F': /* 7-bit controls */ + case 'G': /* 8-bit controls */ #ifdef VT100_PRINTNOTIMPL printf("ESC%c ignored\n", c); #endif @@ -764,15 +767,15 @@ wsemul_vt100_output_dcs(edp, c) u_int newstate = VT100_EMUL_STATE_DCS; switch (c) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': /* argument digit */ if (edp->nargs > VT100_EMUL_NARGS - 1) break; edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) + (c - '0'); break; - case ';': /* argument terminator */ + case ';': /* argument terminator */ edp->nargs++; break; default: @@ -785,13 +788,13 @@ wsemul_vt100_output_dcs(edp, c) } newstate = VT100_EMUL_STATE_STRING; switch (c) { - case '$': + case '$': newstate = VT100_EMUL_STATE_DCS_DOLLAR; break; - case '{': /* DECDLD soft charset */ - case '!': /* DECRQUPSS user preferred supplemental set */ + case '{': /* DECDLD soft charset */ + case '!': /* DECRQUPSS user preferred supplemental set */ /* 'u' must follow - need another state */ - case '|': /* DECUDK program F6..F20 */ + case '|': /* DECUDK program F6..F20 */ #ifdef VT100_PRINTNOTIMPL printf("DCS%c ignored\n", c); #endif @@ -813,22 +816,22 @@ wsemul_vt100_output_dcs_dollar(edp, c) u_char c; { switch (c) { - case 'p': /* DECRSTS terminal state restore */ - case 'q': /* DECRQSS control function request */ + case 'p': /* DECRSTS terminal state restore */ + case 'q': /* DECRQSS control function request */ #ifdef VT100_PRINTNOTIMPL printf("DCS$%c ignored\n", c); #endif break; - case 't': /* DECRSPS restore presentation state */ + case 't': /* DECRSPS restore presentation state */ switch (ARG(0)) { - case 0: /* error */ + case 0: /* error */ break; - case 1: /* cursor information restore */ + case 1: /* cursor information restore */ #ifdef VT100_PRINTNOTIMPL printf("DCS1$t ignored\n"); #endif break; - case 2: /* tab stop restore */ + case 2: /* tab stop restore */ edp->dcspos = 0; edp->dcstype = DCSTYPE_TABRESTORE; break; @@ -856,8 +859,8 @@ wsemul_vt100_output_esc_hash(edp, c) int i; switch (c) { - case '5': /* DECSWL single width, single height */ - if (edp->dw) { + case '5': /* DECSWL single width, single height */ + if (edp->dblwid != NULL && edp->dw != 0) { for (i = 0; i < edp->ncols / 2; i++) (*edp->emulops->copycols)(edp->emulcookie, edp->crow, @@ -869,10 +872,10 @@ wsemul_vt100_output_esc_hash(edp, c) edp->dw = 0; } break; - case '6': /* DECDWL double width, single height */ - case '3': /* DECDHL double width, double height, top half */ - case '4': /* DECDHL double width, double height, bottom half */ - if (!edp->dw) { + case '6': /* DECDWL double width, single height */ + case '3': /* DECDHL double width, double height, top half */ + case '4': /* DECDHL double width, double height, bottom half */ + if (edp->dblwid != NULL && edp->dw == 0) { for (i = edp->ncols / 2 - 1; i >= 0; i--) (*edp->emulops->copycols)(edp->emulcookie, edp->crow, @@ -888,7 +891,7 @@ wsemul_vt100_output_esc_hash(edp, c) edp->ccol = (edp->ncols >> 1) - 1; } break; - case '8': { /* DECALN */ + case '8': { /* DECALN */ int i, j; for (i = 0; i < edp->nrows; i++) for (j = 0; j < edp->ncols; j++) @@ -915,25 +918,25 @@ wsemul_vt100_output_csi(edp, c) u_int newstate = VT100_EMUL_STATE_CSI; switch (c) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': /* argument digit */ if (edp->nargs > VT100_EMUL_NARGS - 1) break; edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) + (c - '0'); break; - case ';': /* argument terminator */ + case ';': /* argument terminator */ edp->nargs++; break; - case '?': /* DEC specific */ - case '>': /* DA query */ + case '?': /* DEC specific */ + case '>': /* DA query */ edp->modif1 = c; break; - case '!': - case '"': - case '$': - case '&': + case '!': + case '"': + case '$': + case '&': edp->modif2 = c; break; default: /* end of escape sequence */ diff --git a/sys/dev/wscons/wsemul_vt100_chars.c b/sys/dev/wscons/wsemul_vt100_chars.c index f76185b83df..f62e24b49de 100644 --- a/sys/dev/wscons/wsemul_vt100_chars.c +++ b/sys/dev/wscons/wsemul_vt100_chars.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsemul_vt100_chars.c,v 1.4 2004/04/02 04:39:51 deraadt Exp $ */ +/* $OpenBSD: wsemul_vt100_chars.c,v 1.5 2007/01/07 13:31:36 miod Exp $ */ /* $NetBSD: wsemul_vt100_chars.c,v 1.4 1999/02/20 18:20:02 drochner Exp $ */ /* @@ -80,15 +80,21 @@ vt100_initchartables(edp) { int i; - for (i = 0; i < 128; i++) - (*edp->emulops->mapchar)(edp->emulcookie, 128 + i, - &edp->isolatin1tab[i]); - for (i = 0; i < 128; i++) - (*edp->emulops->mapchar)(edp->emulcookie, decspcgr2uni[i], - &edp->decgraphtab[i]); - for (i = 0; i < 128; i++) - (*edp->emulops->mapchar)(edp->emulcookie, dectech2uni[i], - &edp->dectechtab[i]); + if (edp->isolatin1tab != NULL) + for (i = 0; i < 128; i++) + (*edp->emulops->mapchar)(edp->emulcookie, 128 + i, + &edp->isolatin1tab[i]); + + if (edp->decgraphtab != NULL) + for (i = 0; i < 128; i++) + (*edp->emulops->mapchar)(edp->emulcookie, + decspcgr2uni[i], &edp->decgraphtab[i]); + + if (edp->dectechtab != NULL) + for (i = 0; i < 128; i++) + (*edp->emulops->mapchar)(edp->emulcookie, + dectech2uni[i], &edp->dectechtab[i]); + vt100_setnrc(edp, 0); } @@ -137,18 +143,24 @@ static const struct { 0x00e8, 0x00f4, 0x00e4, 0x00f6, 0x00fc, 0x00fb}}, }; -void +int vt100_setnrc(edp, nrc) struct wsemul_vt100_emuldata *edp; int nrc; { int i; - KASSERT(nrc < sizeof(nrctable) / sizeof(nrctable[0])); + if (edp->nrctab == NULL) + return (0); + + if (nrc < 0 || nrc >= sizeof(nrctable) / sizeof(nrctable[0])) + return (ERANGE); for (i = 0; i < 128; i++) (*edp->emulops->mapchar)(edp->emulcookie, i, &edp->nrctab[i]); for (i = 0; i < 12; i++) (*edp->emulops->mapchar)(edp->emulcookie, nrctable[nrc].c[i], - &edp->nrctab[nrcovlpos[i]]); + &edp->nrctab[nrcovlpos[i]]); + + return (0); } diff --git a/sys/dev/wscons/wsemul_vt100_subr.c b/sys/dev/wscons/wsemul_vt100_subr.c index 76a0b2041aa..c67c0389592 100644 --- a/sys/dev/wscons/wsemul_vt100_subr.c +++ b/sys/dev/wscons/wsemul_vt100_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsemul_vt100_subr.c,v 1.13 2005/04/21 00:26:29 deraadt Exp $ */ +/* $OpenBSD: wsemul_vt100_subr.c,v 1.14 2007/01/07 13:31:36 miod Exp $ */ /* $NetBSD: wsemul_vt100_subr.c,v 1.7 2000/04/28 21:56:16 mycroft Exp $ */ /* @@ -197,53 +197,53 @@ wsemul_vt100_handle_csi(edp, c) #define A3(a, b, c) (((a) << 16) | ((b) << 8) | (c)) switch (A3(edp->modif1, edp->modif2, c)) { - case A3('>', '\0', 'c'): /* DA secondary */ + case A3('>', '\0', 'c'): /* DA secondary */ wsdisplay_emulinput(edp->cbcookie, WSEMUL_VT_ID2, sizeof(WSEMUL_VT_ID2)); break; - case A3('\0', '\0', 'J'): /* ED selective erase in display */ - case A3('?', '\0', 'J'): /* DECSED selective erase in display */ + case A3('\0', '\0', 'J'): /* ED selective erase in display */ + case A3('?', '\0', 'J'): /* DECSED selective erase in display */ wsemul_vt100_ed(edp, ARG(0)); break; - case A3('\0', '\0', 'K'): /* EL selective erase in line */ - case A3('?', '\0', 'K'): /* DECSEL selective erase in line */ + case A3('\0', '\0', 'K'): /* EL selective erase in line */ + case A3('?', '\0', 'K'): /* DECSEL selective erase in line */ wsemul_vt100_el(edp, ARG(0)); break; - case A3('\0', '\0', 'h'): /* SM */ + case A3('\0', '\0', 'h'): /* SM */ for (n = 0; n < edp->nargs; n++) vt100_ansimode(edp, ARG(n), VTMODE_SET); break; - case A3('?', '\0', 'h'): /* DECSM */ + case A3('?', '\0', 'h'): /* DECSM */ for (n = 0; n < edp->nargs; n++) vt100_decmode(edp, ARG(n), VTMODE_SET); break; - case A3('\0', '\0', 'l'): /* RM */ + case A3('\0', '\0', 'l'): /* RM */ for (n = 0; n < edp->nargs; n++) vt100_ansimode(edp, ARG(n), VTMODE_RESET); break; - case A3('?', '\0', 'l'): /* DECRM */ + case A3('?', '\0', 'l'): /* DECRM */ for (n = 0; n < edp->nargs; n++) vt100_decmode(edp, ARG(n), VTMODE_RESET); break; - case A3('\0', '$', 'p'): /* DECRQM request mode ANSI */ + case A3('\0', '$', 'p'): /* DECRQM request mode ANSI */ vt100_ansimode(edp, ARG(0), VTMODE_REPORT); break; - case A3('?', '$', 'p'): /* DECRQM request mode DEC */ + case A3('?', '$', 'p'): /* DECRQM request mode DEC */ vt100_decmode(edp, ARG(0), VTMODE_REPORT); break; - case A3('\0', '\0', 'i'): /* MC printer controller mode */ - case A3('?', '\0', 'i'): /* MC printer controller mode */ + case A3('\0', '\0', 'i'): /* MC printer controller mode */ + case A3('?', '\0', 'i'): /* MC printer controller mode */ switch (ARG(0)) { - case 0: /* print screen */ - case 1: /* print cursor line */ - case 4: /* off */ - case 5: /* on */ + case 0: /* print screen */ + case 1: /* print cursor line */ + case 4: /* off */ + case 5: /* on */ #ifdef VT100_PRINTNOTIMPL printf("CSI%di ignored\n", ARG(0)); #endif break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%di unknown\n", ARG(0)); #endif @@ -252,50 +252,50 @@ wsemul_vt100_handle_csi(edp, c) break; #define A2(a, b) (((a) << 8) | (b)) - case A2('!', 'p'): /* DECSTR soft reset VT300 only */ + case A2('!', 'p'): /* DECSTR soft reset VT300 only */ wsemul_vt100_reset(edp); break; - case A2('"', 'p'): /* DECSCL */ + case A2('"', 'p'): /* DECSCL */ switch (ARG(0)) { - case 61: /* VT100 mode (no further arguments!) */ + case 61: /* VT100 mode (no further arguments!) */ break; - case 62: - case 63: /* VT300 mode */ + case 62: + case 63: /* VT300 mode */ break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%d\"p unknown\n", ARG(0)); #endif break; } switch (ARG(1)) { - case 0: - case 2: /* 8-bit controls */ + case 0: + case 2: /* 8-bit controls */ #ifdef VT100_PRINTNOTIMPL printf("CSI%d;%d\"p ignored\n", ARG(0), ARG(1)); #endif break; - case 1: /* 7-bit controls */ + case 1: /* 7-bit controls */ break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%d;%d\"p unknown\n", ARG(0), ARG(1)); #endif break; } break; - case A2('"', 'q'): /* DECSCA select character attribute VT300 */ + case A2('"', 'q'): /* DECSCA select character attribute VT300 */ switch (ARG(0)) { - case 0: - case 1: /* erasable */ + case 0: + case 1: /* erasable */ break; - case 2: /* not erasable */ + case 2: /* not erasable */ #ifdef VT100_PRINTNOTIMPL printf("CSI2\"q ignored\n"); #endif break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%d\"q unknown\n", ARG(0)); #endif @@ -303,39 +303,40 @@ wsemul_vt100_handle_csi(edp, c) } break; - case A2('$', 'u'): /* DECRQTSR request terminal status report */ + case A2('$', 'u'): /* DECRQTSR request terminal status report */ switch (ARG(0)) { - case 0: /* ignored */ + case 0: /* ignored */ break; - case 1: /* terminal state report */ + case 1: /* terminal state report */ #ifdef VT100_PRINTNOTIMPL printf("CSI1$u ignored\n"); #endif break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%d$u unknown\n", ARG(0)); #endif break; } break; - case A2('$', 'w'): /* DECRQPSR request presentation status report + case A2('$', 'w'): /* DECRQPSR request presentation status report (VT300 only) */ switch (ARG(0)) { - case 0: /* error */ + case 0: /* error */ break; - case 1: /* cursor information report */ + case 1: /* cursor information report */ #ifdef VT100_PRINTNOTIMPL printf("CSI1$w ignored\n"); #endif break; - case 2: /* tab stop report */ - { + case 2: /* tab stop report */ + { int i, n, ps = 0; char buf[20]; - KASSERT(edp->tabs != 0); + wsdisplay_emulinput(edp->cbcookie, "\033P2$u", 5); - for (i = 0; i < edp->ncols; i++) + if (edp->tabs != NULL) + for (i = 0; i < edp->ncols; i++) if (edp->tabs[i]) { n = snprintf(buf, sizeof buf, "%s%d", (ps ? "/" : ""), i + 1); @@ -347,41 +348,41 @@ wsemul_vt100_handle_csi(edp, c) buf, n); ps = 1; } - } + } wsdisplay_emulinput(edp->cbcookie, "\033\\", 2); break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%d$w unknown\n", ARG(0)); #endif break; } break; - case A2('$', '}'): /* DECSASD select active status display */ + case A2('$', '}'): /* DECSASD select active status display */ switch (ARG(0)) { - case 0: /* main display */ - case 1: /* status line */ + case 0: /* main display */ + case 1: /* status line */ #ifdef VT100_PRINTNOTIMPL printf("CSI%d$} ignored\n", ARG(0)); #endif break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%d$} unknown\n", ARG(0)); #endif break; } break; - case A2('$', '~'): /* DECSSDD select status line type */ + case A2('$', '~'): /* DECSSDD select status line type */ switch (ARG(0)) { - case 0: /* none */ - case 1: /* indicator */ - case 2: /* host-writable */ + case 0: /* none */ + case 1: /* indicator */ + case 2: /* host-writable */ #ifdef VT100_PRINTNOTIMPL printf("CSI%d$~ ignored\n", ARG(0)); #endif break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%d$~ unknown\n", ARG(0)); #endif @@ -389,35 +390,35 @@ wsemul_vt100_handle_csi(edp, c) } break; - case A2('&', 'u'): /* DECRQUPSS request user preferred + case A2('&', 'u'): /* DECRQUPSS request user preferred supplemental set */ wsdisplay_emulinput(edp->cbcookie, "\033P0!u%5\033\\", 9); break; - case '@': /* ICH insert character VT300 only */ + case '@': /* ICH insert character VT300 only */ n = min(DEF1_ARG(0), COLS_LEFT + 1); help = NCOLS - (edp->ccol + n); if (help > 0) COPYCOLS(edp->ccol, edp->ccol + n, help); ERASECOLS(edp->ccol, n, edp->bkgdattr); break; - case 'A': /* CUU */ + case 'A': /* CUU */ edp->crow -= min(DEF1_ARG(0), ROWS_ABOVE); CHECK_DW; break; - case 'B': /* CUD */ + case 'B': /* CUD */ edp->crow += min(DEF1_ARG(0), ROWS_BELOW); CHECK_DW; break; - case 'C': /* CUF */ + case 'C': /* CUF */ edp->ccol += min(DEF1_ARG(0), COLS_LEFT); break; - case 'D': /* CUB */ + case 'D': /* CUB */ edp->ccol -= min(DEF1_ARG(0), edp->ccol); edp->flags &= ~VTFL_LASTCHAR; break; - case 'H': /* CUP */ - case 'f': /* HVP */ + case 'H': /* CUP */ + case 'f': /* HVP */ if (edp->flags & VTFL_DECOM) edp->crow = edp->scrreg_startrow + min(DEF1_ARG(0), edp->scrreg_nrows) - 1; @@ -427,8 +428,8 @@ wsemul_vt100_handle_csi(edp, c) edp->ccol = min(DEF1_ARG(1), NCOLS) - 1; edp->flags &= ~VTFL_LASTCHAR; break; - case 'L': /* IL insert line */ - case 'M': /* DL delete line */ + case 'L': /* IL insert line */ + case 'M': /* DL delete line */ n = min(DEF1_ARG(0), ROWS_BELOW + 1); { int savscrstartrow, savscrnrows; @@ -444,45 +445,45 @@ wsemul_vt100_handle_csi(edp, c) edp->scrreg_nrows = savscrnrows; } break; - case 'P': /* DCH delete character */ + case 'P': /* DCH delete character */ n = min(DEF1_ARG(0), COLS_LEFT + 1); help = NCOLS - (edp->ccol + n); if (help > 0) COPYCOLS(edp->ccol + n, edp->ccol, help); ERASECOLS(NCOLS - n, n, edp->bkgdattr); break; - case 'X': /* ECH erase character */ + case 'X': /* ECH erase character */ n = min(DEF1_ARG(0), COLS_LEFT + 1); ERASECOLS(edp->ccol, n, edp->bkgdattr); break; - case 'c': /* DA primary */ + case 'c': /* DA primary */ if (ARG(0) == 0) wsdisplay_emulinput(edp->cbcookie, WSEMUL_VT_ID1, sizeof(WSEMUL_VT_ID1)); break; - case 'g': /* TBC */ - KASSERT(edp->tabs != 0); - switch (ARG(0)) { - case 0: - edp->tabs[edp->ccol] = 0; - break; - case 3: - memset(edp->tabs, 0, edp->ncols); - break; - default: + case 'g': /* TBC */ + if (edp->tabs != NULL) + switch (ARG(0)) { + case 0: + edp->tabs[edp->ccol] = 0; + break; + case 3: + memset(edp->tabs, 0, edp->ncols); + break; + default: #ifdef VT100_PRINTUNKNOWN - printf("CSI%dg unknown\n", ARG(0)); + printf("CSI%dg unknown\n", ARG(0)); #endif - break; - } + break; + } break; - case 'm': /* SGR select graphic rendition */ + case 'm': /* SGR select graphic rendition */ flags = edp->attrflags; fgcol = edp->fgcol; bgcol = edp->bgcol; for (n = 0; n < edp->nargs; n++) { switch (ARG(n)) { - case 0: /* reset */ + case 0: /* reset */ if (n == edp->nargs - 1) { edp->bkgdattr = edp->curattr = edp->defattr; edp->attrflags = 0; @@ -494,43 +495,43 @@ wsemul_vt100_handle_csi(edp, c) fgcol = WSCOL_WHITE; bgcol = WSCOL_BLACK; break; - case 1: /* bold */ + case 1: /* bold */ flags |= WSATTR_HILIT; break; - case 4: /* underline */ + case 4: /* underline */ flags |= WSATTR_UNDERLINE; break; - case 5: /* blink */ + case 5: /* blink */ flags |= WSATTR_BLINK; break; - case 7: /* reverse */ + case 7: /* reverse */ flags |= WSATTR_REVERSE; break; - case 22: /* ~bold VT300 only */ + case 22: /* ~bold VT300 only */ flags &= ~WSATTR_HILIT; break; - case 24: /* ~underline VT300 only */ + case 24: /* ~underline VT300 only */ flags &= ~WSATTR_UNDERLINE; break; - case 25: /* ~blink VT300 only */ + case 25: /* ~blink VT300 only */ flags &= ~WSATTR_BLINK; break; - case 27: /* ~reverse VT300 only */ + case 27: /* ~reverse VT300 only */ flags &= ~WSATTR_REVERSE; break; - case 30: case 31: case 32: case 33: - case 34: case 35: case 36: case 37: + case 30: case 31: case 32: case 33: + case 34: case 35: case 36: case 37: /* fg color */ flags |= WSATTR_WSCOLORS; fgcol = ARG(n) - 30; break; - case 40: case 41: case 42: case 43: - case 44: case 45: case 46: case 47: + case 40: case 41: case 42: case 43: + case 44: case 45: case 46: case 47: /* bg color */ flags |= WSATTR_WSCOLORS; bgcol = ARG(n) - 40; break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%dm unknown\n", ARG(n)); #endif @@ -551,13 +552,14 @@ wsemul_vt100_handle_csi(edp, c) edp->bgcol = bgcol; } break; - case 'n': /* reports */ + case 'n': /* reports */ switch (ARG(0)) { - case 5: /* DSR operating status */ + case 5: /* DSR operating status */ /* 0 = OK, 3 = malfunction */ wsdisplay_emulinput(edp->cbcookie, "\033[0n", 4); break; - case 6: { /* DSR cursor position report */ + case 6: /* DSR cursor position report */ + { char buf[20]; int row; if (edp->flags & VTFL_DECOM) @@ -571,28 +573,28 @@ wsemul_vt100_handle_csi(edp, c) else if (n >= sizeof buf) n = sizeof buf - 1; wsdisplay_emulinput(edp->cbcookie, buf, n); - } + } break; - case 15: /* DSR printer status */ + case 15: /* DSR printer status */ /* 13 = no printer, 10 = ready, 11 = not ready */ wsdisplay_emulinput(edp->cbcookie, "\033[?13n", 6); break; - case 25: /* UDK status - VT300 only */ + case 25: /* UDK status - VT300 only */ /* 20 = locked, 21 = unlocked */ wsdisplay_emulinput(edp->cbcookie, "\033[?21n", 6); break; - case 26: /* keyboard dialect */ + case 26: /* keyboard dialect */ /* 1 = north american , 7 = german */ wsdisplay_emulinput(edp->cbcookie, "\033[?27;1n", 8); break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%dn unknown\n", ARG(0)); #endif break; } break; - case 'r': /* DECSTBM set top/bottom margins */ + case 'r': /* DECSTBM set top/bottom margins */ help = min(DEF1_ARG(0), edp->nrows) - 1; n = min(DEFx_ARG(1, edp->nrows), edp->nrows) - help; if (n < 2) { @@ -606,19 +608,19 @@ wsemul_vt100_handle_csi(edp, c) edp->scrreg_startrow : 0); edp->ccol = 0; break; - case 'y': + case 'y': switch (ARG(0)) { - case 4: /* DECTST invoke confidence test */ + case 4: /* DECTST invoke confidence test */ /* ignore */ break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%dy unknown\n", ARG(0)); #endif break; } break; - default: + default: #ifdef VT100_PRINTUNKNOWN printf("CSI%c (%d, %d) unknown\n", c, ARG(0), ARG(1)); #endif @@ -717,35 +719,37 @@ wsemul_vt100_handle_dcs(edp) int i, pos; switch (edp->dcstype) { - case 0: /* not handled */ + case 0: /* not handled */ return; - case DCSTYPE_TABRESTORE: - KASSERT(edp->tabs != 0); - memset(edp->tabs, 0, edp->ncols); - pos = 0; - for (i = 0; i < edp->dcspos; i++) { - char c = edp->dcsarg[i]; - switch (c) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - pos = pos * 10 + (edp->dcsarg[i] - '0'); - break; - case '/': - if (pos > 0) - edp->tabs[pos - 1] = 1; - pos = 0; - break; - default: + case DCSTYPE_TABRESTORE: + if (edp->tabs != NULL) { + memset(edp->tabs, 0, edp->ncols); + pos = 0; + for (i = 0; i < edp->dcspos; i++) { + char c = edp->dcsarg[i]; + switch (c) { + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + case '8': case '9': + pos = pos * 10 + (edp->dcsarg[i] - '0'); + break; + case '/': + if (pos > 0) + edp->tabs[pos - 1] = 1; + pos = 0; + break; + default: #ifdef VT100_PRINTUNKNOWN - printf("unknown char %c in DCS\n", c); + printf("unknown char %c in DCS\n", c); #endif - break; + break; + } } + if (pos > 0) + edp->tabs[pos - 1] = 1; } - if (pos > 0) - edp->tabs[pos - 1] = 1; break; - default: + default: panic("wsemul_vt100_handle_dcs: bad type %d", edp->dcstype); } edp->dcstype = 0; diff --git a/sys/dev/wscons/wsemul_vt100var.h b/sys/dev/wscons/wsemul_vt100var.h index 1c9eb66c81b..69b921b4132 100644 --- a/sys/dev/wscons/wsemul_vt100var.h +++ b/sys/dev/wscons/wsemul_vt100var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsemul_vt100var.h,v 1.5 2004/12/23 21:47:47 miod Exp $ */ +/* $OpenBSD: wsemul_vt100var.h,v 1.6 2007/01/07 13:31:36 miod Exp $ */ /* $NetBSD: wsemul_vt100var.h,v 1.5 2000/04/28 21:56:17 mycroft Exp $ */ /* @@ -138,4 +138,4 @@ void wsemul_vt100_handle_dcs(struct wsemul_vt100_emuldata *); int wsemul_vt100_translate(void *cookie, keysym_t, char **); void vt100_initchartables(struct wsemul_vt100_emuldata *); -void vt100_setnrc(struct wsemul_vt100_emuldata *, int); +int vt100_setnrc(struct wsemul_vt100_emuldata *, int); -- cgit v1.2.3