X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/828bb999c53f7e78046255aab61b55d7805a6229..4e95a413c2909c807226e5efc09da4c8ba24740e:/terminal.c diff --git a/terminal.c b/terminal.c index 36f59c3b..432ed936 100644 --- a/terminal.c +++ b/terminal.c @@ -133,14 +133,13 @@ static void unlineptr(termline *line) freeline(line); } +#ifdef TERM_CC_DIAGS /* * Diagnostic function: verify that a termline has a correct * combining character structure. * - * XXX-REMOVE-BEFORE-RELEASE: This is a performance-intensive - * check. Although it's currently really useful for getting all the - * bugs out of the new cc stuff, it will want to be absent when we - * make a proper release. + * This is a performance-intensive check, so it's no longer enabled + * by default. */ static void cc_check(termline *line) { @@ -185,6 +184,7 @@ static void cc_check(termline *line) sfree(flags); } +#endif /* * Add a combining character to a character cell. @@ -231,7 +231,9 @@ static void add_cc(termline *line, int col, unsigned long chr) line->chars[newcc].chr = chr; line->chars[col].cc_next = newcc - col; - cc_check(line); /* XXX-REMOVE-BEFORE-RELEASE */ +#ifdef TERM_CC_DIAGS + cc_check(line); +#endif } /* @@ -257,7 +259,9 @@ static void clear_cc(termline *line, int col) line->chars[origcol].cc_next = 0; - cc_check(line); /* XXX-REMOVE-BEFORE-RELEASE */ +#ifdef TERM_CC_DIAGS + cc_check(line); +#endif } /* @@ -305,7 +309,9 @@ static void copy_termchar(termline *destline, int x, termchar *src) add_cc(destline, x, src->chr); } - cc_check(destline); /* XXX-REMOVE-BEFORE-RELEASE */ +#ifdef TERM_CC_DIAGS + cc_check(destline); +#endif } /* @@ -324,7 +330,9 @@ static void move_termchar(termline *line, termchar *dest, termchar *src) /* Ensure the original cell doesn't have a cc list. */ src->cc_next = 0; - cc_check(line); /* XXX-REMOVE-BEFORE-RELEASE */ +#ifdef TERM_CC_DIAGS + cc_check(line); +#endif } /* @@ -669,9 +677,9 @@ static unsigned char *compressline(termline *ldata) * Diagnostics: ensure that the compressed data really does * decompress to the right thing. * - * XXX-REMOVE-BEFORE-RELEASE: This is a bit performance-heavy - * to be leaving in production code. + * This is a bit performance-heavy for production code. */ +#ifdef TERM_CC_DIAGS #ifndef CHECK_SB_COMPRESSION { int dused; @@ -701,6 +709,7 @@ static unsigned char *compressline(termline *ldata) freeline(dcl); } #endif +#endif /* TERM_CC_DIAGS */ /* * Trim the allocated memory so we don't waste any, and return. @@ -960,7 +969,9 @@ static void resizeline(Terminal *term, termline *line, int cols) for (i = oldcols; i < cols; i++) line->chars[i] = term->basic_erase_char; - cc_check(line); /* XXX-REMOVE-BEFORE-RELEASE */ +#ifdef TERM_CC_DIAGS + cc_check(line); +#endif } } @@ -1017,6 +1028,21 @@ static termline *lineptr(Terminal *term, int y, int lineno, int screen) } /* We assume that we don't screw up and retrieve something out of range. */ + if (line == NULL) { + fatalbox("line==NULL in terminal.c\n" + "lineno=%d y=%d w=%d h=%d\n" + "count(scrollback=%p)=%d\n" + "count(screen=%p)=%d\n" + "count(alt=%p)=%d alt_sblines=%d\n" + "whichtree=%p treeindex=%d\n\n" + "Please contact " + "and pass on the above information.", + lineno, y, term->cols, term->rows, + term->scrollback, count234(term->scrollback), + term->screen, count234(term->screen), + term->alt_screen, count234(term->alt_screen), term->alt_sblines, + whichtree, treeindex); + } assert(line != NULL); resizeline(term, line, term->cols); @@ -1820,7 +1846,9 @@ static void scroll(Terminal *term, int topline, int botline, int lines, int sb) } else { while (lines > 0) { line = delpos234(term->screen, topline); - cc_check(line); /* XXX-REMOVE-BEFORE-RELEASE */ +#ifdef TERM_CC_DIAGS + cc_check(line); +#endif if (sb && term->savelines > 0) { int sblen = count234(term->scrollback); /* @@ -2608,12 +2636,19 @@ static void term_out(Terminal *term) } } - /* How about C1 controls ? */ + /* + * How about C1 controls? + * Explicitly ignore SCI (0x9a), which we don't translate to DECID. + */ if ((c & -32) == 0x80 && term->termstate < DO_CTRLS && !term->vt52_mode && has_compat(VT220)) { - term->termstate = SEEN_ESC; - term->esc_query = FALSE; - c = '@' + (c & 0x1F); + if (c == 0x9a) + c = 0; + else { + term->termstate = SEEN_ESC; + term->esc_query = FALSE; + c = '@' + (c & 0x1F); + } } /* Or the GL control. */ @@ -2633,32 +2668,25 @@ static void term_out(Terminal *term) if ((c & ~0x1F) == 0 && term->termstate < DO_CTRLS) { switch (c) { case '\005': /* ENQ: terminal type query */ - /* Strictly speaking this is VT100 but a VT100 defaults to + /* + * Strictly speaking this is VT100 but a VT100 defaults to * no response. Other terminals respond at their option. * * Don't put a CR in the default string as this tends to * upset some weird software. - * - * An xterm returns "xterm" (5 characters) */ compatibility(ANSIMIN); if (term->ldisc) { - char abuf[256], *s, *d; - int state = 0; - for (s = term->cfg.answerback, d = abuf; *s; s++) { - if (state) { - if (*s >= 'a' && *s <= 'z') - *d++ = (*s - ('a' - 1)); - else if ((*s >= '@' && *s <= '_') || - *s == '?' || (*s & 0x80)) - *d++ = ('@' ^ *s); - else if (*s == '~') - *d++ = '^'; - state = 0; - } else if (*s == '^') { - state = 1; - } else - *d++ = *s; + char abuf[lenof(term->cfg.answerback)], *s, *d; + for (s = term->cfg.answerback, d = abuf; *s;) { + char *n; + char c = ctrlparse(s, &n); + if (n) { + *d++ = c; + s = n; + } else { + *d++ = *s++; + } } lpage_send(term->ldisc, DEFAULT_CODEPAGE, abuf, d - abuf, 0); @@ -2824,7 +2852,9 @@ static void term_out(Terminal *term) if (DIRECT_CHAR(c)) width = 1; if (!width) - width = wcwidth((wchar_t) c); + width = (term->cfg.cjk_ambig_wide ? + mk_wcwidth_cjk((wchar_t) c) : + mk_wcwidth((wchar_t) c)); if (term->wrapnext && term->wrap && width > 0) { cline->lattr |= LATTR_WRAPPED; @@ -3510,7 +3540,7 @@ static void term_out(Terminal *term) case 95: case 96: case 97: - /* xterm-style bright foreground */ + /* aixterm-style bright foreground */ term->curr_attr &= ~ATTR_FGMASK; term->curr_attr |= ((term->esc_args[i] - 90 + 8) @@ -3541,7 +3571,7 @@ static void term_out(Terminal *term) case 105: case 106: case 107: - /* xterm-style bright background */ + /* aixterm-style bright background */ term->curr_attr &= ~ATTR_BGMASK; term->curr_attr |= ((term->esc_args[i] - 100 + 8) @@ -3798,7 +3828,7 @@ static void term_out(Terminal *term) } } break; - case 'Z': /* CBT: BackTab for xterm */ + case 'Z': /* CBT */ compatibility(OTHER); { int i = def(term->esc_args[0], 1); @@ -6210,13 +6240,13 @@ int term_data(Terminal *term, int is_stderr, const char *data, int len) * the remote side needing to wait until term_out() has cleared * a backlog. * - * This is a slightly suboptimal way to deal with SSH2 - in + * This is a slightly suboptimal way to deal with SSH-2 - in * principle, the window mechanism would allow us to continue * to accept data on forwarded ports and X connections even * while the terminal processing was going slowly - but we * can't do the 100% right thing without moving the terminal * processing into a separate thread, and that might hurt - * portability. So we manage stdout buffering the old SSH1 way: + * portability. So we manage stdout buffering the old SSH-1 way: * if the terminal processing goes slowly, the whole SSH * connection stops accepting data until it's ready. * @@ -6235,3 +6265,17 @@ void term_set_focus(Terminal *term, int has_focus) term->has_focus = has_focus; term_schedule_cblink(term); } + +/* + * Provide "auto" settings for remote tty modes, suitable for an + * application with a terminal window. + */ +char *term_get_ttymode(Terminal *term, const char *mode) +{ + char *val = NULL; + if (strcmp(mode, "ERASE") == 0) { + val = term->cfg.bksp_is_delete ? "^?" : "^H"; + } + /* FIXME: perhaps we should set ONLCR based on cfg.lfhascr as well? */ + return dupstr(val); +}