teken_subr.h revision 186798
1186681Sed/*- 2186681Sed * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org> 3186681Sed * All rights reserved. 4186681Sed * 5186681Sed * Redistribution and use in source and binary forms, with or without 6186681Sed * modification, are permitted provided that the following conditions 7186681Sed * are met: 8186681Sed * 1. Redistributions of source code must retain the above copyright 9186681Sed * notice, this list of conditions and the following disclaimer. 10186681Sed * 2. Redistributions in binary form must reproduce the above copyright 11186681Sed * notice, this list of conditions and the following disclaimer in the 12186681Sed * documentation and/or other materials provided with the distribution. 13186681Sed * 14186681Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15186681Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16186681Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17186681Sed * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18186681Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19186681Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20186681Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21186681Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22186681Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23186681Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24186681Sed * SUCH DAMAGE. 25186681Sed * 26186681Sed * $FreeBSD: head/sys/dev/syscons/teken/teken_subr.h 186798 2009-01-05 22:09:46Z ed $ 27186681Sed */ 28186681Sed 29186681Sedstatic void teken_subr_cursor_up(teken_t *, unsigned int); 30186681Sedstatic void teken_subr_erase_line(teken_t *, unsigned int); 31186681Sedstatic void teken_subr_regular_character(teken_t *, teken_char_t); 32186681Sedstatic void teken_subr_reset_to_initial_state(teken_t *); 33186681Sed 34186681Sedstatic inline int 35186681Sedteken_tab_isset(teken_t *t, unsigned int col) 36186681Sed{ 37186681Sed unsigned int b, o; 38186681Sed 39186681Sed teken_assert(col <= T_NUMCOL); 40186681Sed 41186681Sed b = col / (sizeof(unsigned int) * 8); 42186681Sed o = col % (sizeof(unsigned int) * 8); 43186681Sed 44186681Sed return (t->t_tabstops[b] & (1 << o)); 45186681Sed} 46186681Sed 47186681Sedstatic inline void 48186681Sedteken_tab_clear(teken_t *t, unsigned int col) 49186681Sed{ 50186681Sed unsigned int b, o; 51186681Sed 52186681Sed teken_assert(col <= T_NUMCOL); 53186681Sed 54186681Sed b = col / (sizeof(unsigned int) * 8); 55186681Sed o = col % (sizeof(unsigned int) * 8); 56186681Sed 57186681Sed t->t_tabstops[b] &= ~(1 << o); 58186681Sed} 59186681Sed 60186681Sedstatic inline void 61186681Sedteken_tab_set(teken_t *t, unsigned int col) 62186681Sed{ 63186681Sed unsigned int b, o; 64186681Sed 65186681Sed teken_assert(col <= T_NUMCOL); 66186681Sed 67186681Sed b = col / (sizeof(unsigned int) * 8); 68186681Sed o = col % (sizeof(unsigned int) * 8); 69186681Sed 70186681Sed t->t_tabstops[b] |= 1 << o; 71186681Sed} 72186681Sed 73186681Sedstatic void 74186681Sedteken_tab_default(teken_t *t) 75186681Sed{ 76186681Sed unsigned int i; 77186681Sed 78186681Sed memset(&t->t_tabstops, 0, T_NUMCOL / 8); 79186681Sed 80186681Sed for (i = 8; i < T_NUMCOL; i += 8) 81186681Sed teken_tab_set(t, i); 82186681Sed} 83186681Sed 84186681Sedstatic void 85186681Sedteken_subr_do_scroll(teken_t *t, int amount) 86186681Sed{ 87186681Sed teken_rect_t tr; 88186681Sed teken_pos_t tp; 89186681Sed 90186681Sed teken_assert(t->t_cursor.tp_row <= t->t_winsize.tp_row); 91186681Sed teken_assert(t->t_scrollreg.ts_end <= t->t_winsize.tp_row); 92186681Sed teken_assert(amount != 0); 93186681Sed 94186681Sed /* Copy existing data 1 line up. */ 95186681Sed if (amount > 0) { 96186681Sed /* Scroll down. */ 97186681Sed 98186681Sed /* Copy existing data up. */ 99186681Sed if (t->t_scrollreg.ts_begin + amount < t->t_scrollreg.ts_end) { 100186681Sed tr.tr_begin.tp_row = t->t_scrollreg.ts_begin + amount; 101186681Sed tr.tr_begin.tp_col = 0; 102186681Sed tr.tr_end.tp_row = t->t_scrollreg.ts_end; 103186681Sed tr.tr_end.tp_col = t->t_winsize.tp_col; 104186681Sed tp.tp_row = t->t_scrollreg.ts_begin; 105186681Sed tp.tp_col = 0; 106186681Sed teken_funcs_copy(t, &tr, &tp); 107186681Sed 108186681Sed tr.tr_begin.tp_row = t->t_scrollreg.ts_end - amount; 109186681Sed } else { 110186681Sed tr.tr_begin.tp_row = t->t_scrollreg.ts_begin; 111186681Sed } 112186681Sed 113186681Sed /* Clear the last lines. */ 114186681Sed tr.tr_begin.tp_col = 0; 115186681Sed tr.tr_end.tp_row = t->t_scrollreg.ts_end; 116186681Sed tr.tr_end.tp_col = t->t_winsize.tp_col; 117186681Sed teken_funcs_fill(t, &tr, BLANK, &t->t_curattr); 118186681Sed } else { 119186681Sed /* Scroll up. */ 120186681Sed amount = -amount; 121186681Sed 122186681Sed /* Copy existing data down. */ 123186681Sed if (t->t_scrollreg.ts_begin + amount < t->t_scrollreg.ts_end) { 124186681Sed tr.tr_begin.tp_row = t->t_scrollreg.ts_begin; 125186681Sed tr.tr_begin.tp_col = 0; 126186681Sed tr.tr_end.tp_row = t->t_scrollreg.ts_end - amount; 127186681Sed tr.tr_end.tp_col = t->t_winsize.tp_col; 128186681Sed tp.tp_row = t->t_scrollreg.ts_begin + amount; 129186681Sed tp.tp_col = 0; 130186681Sed teken_funcs_copy(t, &tr, &tp); 131186681Sed 132186681Sed tr.tr_end.tp_row = t->t_scrollreg.ts_begin + amount; 133186681Sed } else { 134186681Sed tr.tr_end.tp_row = t->t_scrollreg.ts_end; 135186681Sed } 136186681Sed 137186681Sed /* Clear the first lines. */ 138186681Sed tr.tr_begin.tp_row = t->t_scrollreg.ts_begin; 139186681Sed tr.tr_begin.tp_col = 0; 140186681Sed tr.tr_end.tp_col = t->t_winsize.tp_col; 141186681Sed teken_funcs_fill(t, &tr, BLANK, &t->t_curattr); 142186681Sed } 143186681Sed} 144186681Sed 145186681Sedstatic ssize_t 146186681Sedteken_subr_do_cpr(teken_t *t, unsigned int cmd, char response[16]) 147186681Sed{ 148186681Sed 149186681Sed switch (cmd) { 150186681Sed case 5: /* Operating status. */ 151186681Sed strcpy(response, "0n"); 152186681Sed return (2); 153186681Sed case 6: { /* Cursor position. */ 154186681Sed int len; 155186681Sed 156186681Sed len = snprintf(response, 16, "%u;%uR", 157186681Sed (t->t_cursor.tp_row - t->t_originreg.ts_begin) + 1, 158186681Sed t->t_cursor.tp_col + 1); 159186681Sed 160186681Sed if (len >= 16) 161186681Sed return (-1); 162186681Sed return (len); 163186681Sed } 164186681Sed case 15: /* Printer status. */ 165186681Sed strcpy(response, "13n"); 166186681Sed return (3); 167186681Sed case 25: /* UDK status. */ 168186681Sed strcpy(response, "20n"); 169186681Sed return (3); 170186681Sed case 26: /* Keyboard status. */ 171186681Sed strcpy(response, "27;1n"); 172186681Sed return (5); 173186681Sed default: 174186681Sed teken_printf("Unknown DSR\n"); 175186681Sed return (-1); 176186681Sed } 177186681Sed} 178186681Sed 179186681Sedstatic void 180186681Sedteken_subr_alignment_test(teken_t *t) 181186681Sed{ 182186681Sed teken_rect_t tr; 183186681Sed 184186681Sed t->t_scrollreg.ts_begin = 0; 185186681Sed t->t_scrollreg.ts_end = t->t_winsize.tp_row; 186186681Sed 187186681Sed t->t_cursor.tp_row = t->t_cursor.tp_col = 0; 188186681Sed t->t_stateflags &= ~TS_WRAPPED; 189186681Sed teken_funcs_cursor(t); 190186681Sed 191186681Sed tr.tr_begin.tp_row = 0; 192186681Sed tr.tr_begin.tp_col = 0; 193186681Sed tr.tr_end = t->t_winsize; 194186681Sed teken_funcs_fill(t, &tr, 'E', &t->t_defattr); 195186681Sed} 196186681Sed 197186681Sedstatic void 198186681Sedteken_subr_backspace(teken_t *t) 199186681Sed{ 200186681Sed 201186753Sed#ifdef TEKEN_CONS25 202186753Sed if (t->t_cursor.tp_col == 0) { 203186753Sed if (t->t_cursor.tp_row == t->t_originreg.ts_begin) 204186753Sed return; 205186753Sed t->t_cursor.tp_row--; 206186753Sed t->t_cursor.tp_col = t->t_winsize.tp_col - 1; 207186753Sed } else { 208186753Sed t->t_cursor.tp_col--; 209186753Sed } 210186753Sed#else /* !TEKEN_CONS25 */ 211186681Sed if (t->t_cursor.tp_col == 0) 212186681Sed return; 213186681Sed 214186681Sed t->t_cursor.tp_col--; 215186681Sed t->t_stateflags &= ~TS_WRAPPED; 216186753Sed#endif /* TEKEN_CONS25 */ 217186681Sed 218186681Sed teken_funcs_cursor(t); 219186681Sed} 220186681Sed 221186681Sedstatic void 222186681Sedteken_subr_bell(teken_t *t) 223186681Sed{ 224186681Sed 225186681Sed teken_funcs_bell(t); 226186681Sed} 227186681Sed 228186681Sedstatic void 229186681Sedteken_subr_carriage_return(teken_t *t) 230186681Sed{ 231186681Sed 232186681Sed t->t_cursor.tp_col = 0; 233186681Sed t->t_stateflags &= ~TS_WRAPPED; 234186681Sed teken_funcs_cursor(t); 235186681Sed} 236186681Sed 237186681Sedstatic void 238186681Sedteken_subr_cursor_backward(teken_t *t, unsigned int ncols) 239186681Sed{ 240186681Sed 241186681Sed if (ncols > t->t_cursor.tp_col) 242186681Sed t->t_cursor.tp_col = 0; 243186681Sed else 244186681Sed t->t_cursor.tp_col -= ncols; 245186681Sed t->t_stateflags &= ~TS_WRAPPED; 246186681Sed teken_funcs_cursor(t); 247186681Sed} 248186681Sed 249186681Sedstatic void 250186681Sedteken_subr_cursor_backward_tabulation(teken_t *t, unsigned int ntabs) 251186681Sed{ 252186681Sed 253186681Sed do { 254186681Sed /* Stop when we've reached the beginning of the line. */ 255186681Sed if (t->t_cursor.tp_col == 0) 256186681Sed break; 257186681Sed 258186681Sed t->t_cursor.tp_col--; 259186681Sed 260186681Sed /* Tab marker set. */ 261186681Sed if (teken_tab_isset(t, t->t_cursor.tp_col)) 262186681Sed ntabs--; 263186681Sed } while (ntabs > 0); 264186729Sed 265186729Sed teken_funcs_cursor(t); 266186681Sed} 267186681Sed 268186681Sedstatic void 269186681Sedteken_subr_cursor_down(teken_t *t, unsigned int nrows) 270186681Sed{ 271186681Sed 272186681Sed if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end) 273186681Sed t->t_cursor.tp_row = t->t_scrollreg.ts_end - 1; 274186681Sed else 275186681Sed t->t_cursor.tp_row += nrows; 276186681Sed t->t_stateflags &= ~TS_WRAPPED; 277186681Sed teken_funcs_cursor(t); 278186681Sed} 279186681Sed 280186681Sedstatic void 281186681Sedteken_subr_cursor_forward(teken_t *t, unsigned int ncols) 282186681Sed{ 283186681Sed 284186681Sed if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col) 285186681Sed t->t_cursor.tp_col = t->t_winsize.tp_col - 1; 286186681Sed else 287186681Sed t->t_cursor.tp_col += ncols; 288186681Sed t->t_stateflags &= ~TS_WRAPPED; 289186681Sed teken_funcs_cursor(t); 290186681Sed} 291186681Sed 292186681Sedstatic void 293186681Sedteken_subr_cursor_forward_tabulation(teken_t *t, unsigned int ntabs) 294186681Sed{ 295186681Sed 296186681Sed do { 297186681Sed /* Stop when we've reached the end of the line. */ 298186681Sed if (t->t_cursor.tp_col == t->t_winsize.tp_col - 1) 299186681Sed break; 300186681Sed 301186681Sed t->t_cursor.tp_col++; 302186681Sed 303186681Sed /* Tab marker set. */ 304186681Sed if (teken_tab_isset(t, t->t_cursor.tp_col)) 305186681Sed ntabs--; 306186681Sed } while (ntabs > 0); 307186729Sed 308186729Sed teken_funcs_cursor(t); 309186681Sed} 310186681Sed 311186681Sedstatic void 312186681Sedteken_subr_cursor_next_line(teken_t *t, unsigned int ncols) 313186681Sed{ 314186681Sed 315186681Sed t->t_cursor.tp_col = 0; 316186681Sed teken_subr_cursor_down(t, ncols); 317186681Sed} 318186681Sed 319186681Sedstatic void 320186681Sedteken_subr_cursor_position(teken_t *t, unsigned int row, unsigned int col) 321186681Sed{ 322186681Sed 323186681Sed t->t_cursor.tp_row = t->t_originreg.ts_begin + row - 1; 324186681Sed if (row >= t->t_originreg.ts_end) 325186681Sed t->t_cursor.tp_row = t->t_originreg.ts_end - 1; 326186681Sed 327186681Sed t->t_cursor.tp_col = col - 1; 328186681Sed if (t->t_cursor.tp_col >= t->t_winsize.tp_col) 329186681Sed t->t_cursor.tp_col = t->t_winsize.tp_col - 1; 330186681Sed 331186681Sed t->t_stateflags &= ~TS_WRAPPED; 332186681Sed teken_funcs_cursor(t); 333186681Sed} 334186681Sed 335186681Sedstatic void 336186681Sedteken_subr_cursor_position_report(teken_t *t, unsigned int cmd) 337186681Sed{ 338186681Sed char response[18] = "\x1B["; 339186681Sed ssize_t len; 340186681Sed 341186681Sed len = teken_subr_do_cpr(t, cmd, response + 2); 342186681Sed if (len < 0) 343186681Sed return; 344186681Sed 345186681Sed teken_funcs_respond(t, response, len + 2); 346186681Sed} 347186681Sed 348186681Sedstatic void 349186681Sedteken_subr_cursor_previous_line(teken_t *t, unsigned int ncols) 350186681Sed{ 351186681Sed 352186681Sed t->t_cursor.tp_col = 0; 353186681Sed teken_subr_cursor_up(t, ncols); 354186681Sed} 355186681Sed 356186681Sedstatic void 357186681Sedteken_subr_cursor_up(teken_t *t, unsigned int nrows) 358186681Sed{ 359186681Sed 360186681Sed if (t->t_scrollreg.ts_begin + nrows >= t->t_cursor.tp_row) 361186681Sed t->t_cursor.tp_row = t->t_scrollreg.ts_begin; 362186681Sed else 363186681Sed t->t_cursor.tp_row -= nrows; 364186681Sed t->t_stateflags &= ~TS_WRAPPED; 365186681Sed teken_funcs_cursor(t); 366186681Sed} 367186681Sed 368186681Sedstatic void 369186681Sedteken_subr_delete_character(teken_t *t, unsigned int ncols) 370186681Sed{ 371186681Sed teken_rect_t tr; 372186681Sed 373186681Sed tr.tr_begin.tp_row = t->t_cursor.tp_row; 374186681Sed tr.tr_end.tp_row = t->t_cursor.tp_row + 1; 375186681Sed tr.tr_end.tp_col = t->t_winsize.tp_col; 376186681Sed 377186681Sed if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col) { 378186681Sed tr.tr_begin.tp_col = t->t_cursor.tp_col; 379186681Sed } else { 380186681Sed /* Copy characters to the left. */ 381186681Sed tr.tr_begin.tp_col = t->t_cursor.tp_col + ncols; 382186681Sed teken_funcs_copy(t, &tr, &t->t_cursor); 383186681Sed 384186681Sed tr.tr_begin.tp_col = t->t_winsize.tp_col - ncols; 385186681Sed } 386186681Sed 387186681Sed /* Blank trailing columns. */ 388186681Sed teken_funcs_fill(t, &tr, BLANK, &t->t_curattr); 389186681Sed} 390186681Sed 391186681Sedstatic void 392186681Sedteken_subr_delete_line(teken_t *t, unsigned int nrows) 393186681Sed{ 394186681Sed teken_rect_t tr; 395186681Sed 396186681Sed tr.tr_begin.tp_col = 0; 397186681Sed tr.tr_end.tp_row = t->t_scrollreg.ts_end; 398186681Sed tr.tr_end.tp_col = t->t_winsize.tp_col; 399186681Sed 400186681Sed if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end) { 401186681Sed tr.tr_begin.tp_row = t->t_cursor.tp_row; 402186681Sed } else { 403186681Sed teken_pos_t tp; 404186681Sed 405186681Sed /* Copy rows up. */ 406186681Sed tr.tr_begin.tp_row = t->t_cursor.tp_row + nrows; 407186681Sed tp.tp_row = t->t_cursor.tp_row; 408186681Sed tp.tp_col = 0; 409186681Sed teken_funcs_copy(t, &tr, &tp); 410186681Sed 411186681Sed tr.tr_begin.tp_row = t->t_scrollreg.ts_end - nrows; 412186681Sed } 413186681Sed 414186681Sed /* Blank trailing rows. */ 415186681Sed teken_funcs_fill(t, &tr, BLANK, &t->t_curattr); 416186681Sed} 417186681Sed 418186681Sedstatic void 419186681Sedteken_subr_device_control_string(teken_t *t __unused) 420186681Sed{ 421186681Sed 422186681Sed teken_printf("device control string???\n"); 423186681Sed} 424186681Sed 425186681Sedstatic void 426186681Sedteken_subr_device_status_report(teken_t *t, unsigned int cmd) 427186681Sed{ 428186681Sed char response[19] = "\x1B[?"; 429186681Sed ssize_t len; 430186681Sed 431186681Sed len = teken_subr_do_cpr(t, cmd, response + 3); 432186681Sed if (len < 0) 433186681Sed return; 434186681Sed 435186681Sed teken_funcs_respond(t, response, len + 3); 436186681Sed} 437186681Sed 438186681Sedstatic void 439186681Sedteken_subr_double_height_double_width_line_top(teken_t *t __unused) 440186681Sed{ 441186681Sed 442186681Sed teken_printf("double height double width top\n"); 443186681Sed} 444186681Sed 445186681Sedstatic void 446186681Sedteken_subr_double_height_double_width_line_bottom(teken_t *t __unused) 447186681Sed{ 448186681Sed 449186681Sed teken_printf("double height double width bottom\n"); 450186681Sed} 451186681Sed 452186681Sedstatic void 453186681Sedteken_subr_erase_character(teken_t *t, unsigned int ncols) 454186681Sed{ 455186681Sed teken_rect_t tr; 456186681Sed 457186681Sed tr.tr_begin = t->t_cursor; 458186681Sed tr.tr_end.tp_row = t->t_cursor.tp_row + 1; 459186681Sed 460186681Sed if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col) 461186681Sed tr.tr_end.tp_col = t->t_winsize.tp_col; 462186681Sed else 463186681Sed tr.tr_end.tp_col = t->t_cursor.tp_col + ncols; 464186681Sed 465186681Sed teken_funcs_fill(t, &tr, BLANK, &t->t_curattr); 466186681Sed} 467186681Sed 468186681Sedstatic void 469186681Sedteken_subr_erase_display(teken_t *t, unsigned int mode) 470186681Sed{ 471186681Sed teken_rect_t r; 472186681Sed 473186681Sed r.tr_begin.tp_col = 0; 474186681Sed r.tr_end.tp_col = t->t_winsize.tp_col; 475186681Sed 476186681Sed switch (mode) { 477186681Sed case 1: /* Erase from the top to the cursor. */ 478186681Sed teken_subr_erase_line(t, 1); 479186681Sed 480186681Sed /* Erase lines above. */ 481186681Sed if (t->t_cursor.tp_row == 0) 482186681Sed return; 483186681Sed r.tr_begin.tp_row = 0; 484186681Sed r.tr_end.tp_row = t->t_cursor.tp_row; 485186681Sed break; 486186681Sed case 2: /* Erase entire display. */ 487186681Sed r.tr_begin.tp_row = 0; 488186681Sed r.tr_end.tp_row = t->t_winsize.tp_row; 489186681Sed break; 490186681Sed default: /* Erase from cursor to the bottom. */ 491186681Sed teken_subr_erase_line(t, 0); 492186681Sed 493186681Sed /* Erase lines below. */ 494186681Sed if (t->t_cursor.tp_row == t->t_winsize.tp_row - 1) 495186681Sed return; 496186681Sed r.tr_begin.tp_row = t->t_cursor.tp_row + 1; 497186681Sed r.tr_end.tp_row = t->t_winsize.tp_row; 498186681Sed break; 499186681Sed } 500186681Sed 501186681Sed teken_funcs_fill(t, &r, BLANK, &t->t_curattr); 502186681Sed} 503186681Sed 504186681Sedstatic void 505186681Sedteken_subr_erase_line(teken_t *t, unsigned int mode) 506186681Sed{ 507186681Sed teken_rect_t r; 508186681Sed 509186681Sed r.tr_begin.tp_row = t->t_cursor.tp_row; 510186681Sed r.tr_end.tp_row = t->t_cursor.tp_row + 1; 511186681Sed 512186681Sed switch (mode) { 513186681Sed case 1: /* Erase from the beginning of the line to the cursor. */ 514186681Sed r.tr_begin.tp_col = 0; 515186681Sed r.tr_end.tp_col = t->t_cursor.tp_col + 1; 516186681Sed break; 517186681Sed case 2: /* Erase entire line. */ 518186681Sed r.tr_begin.tp_col = 0; 519186681Sed r.tr_end.tp_col = t->t_winsize.tp_col; 520186681Sed break; 521186681Sed default: /* Erase from cursor to the end of the line. */ 522186681Sed r.tr_begin.tp_col = t->t_cursor.tp_col; 523186681Sed r.tr_end.tp_col = t->t_winsize.tp_col; 524186681Sed break; 525186681Sed } 526186681Sed 527186681Sed teken_funcs_fill(t, &r, BLANK, &t->t_curattr); 528186681Sed} 529186681Sed 530186681Sedstatic void 531186681Sedteken_subr_horizontal_position_absolute(teken_t *t, unsigned int col) 532186681Sed{ 533186681Sed 534186681Sed t->t_cursor.tp_col = col - 1; 535186681Sed if (t->t_cursor.tp_col >= t->t_winsize.tp_col) 536186681Sed t->t_cursor.tp_col = t->t_winsize.tp_col - 1; 537186681Sed 538186681Sed t->t_stateflags &= ~TS_WRAPPED; 539186681Sed teken_funcs_cursor(t); 540186681Sed} 541186681Sed 542186681Sedstatic void 543186681Sedteken_subr_horizontal_tab(teken_t *t) 544186681Sed{ 545186729Sed#ifdef TEKEN_CONS25 546186729Sed 547186729Sed teken_subr_cursor_forward_tabulation(t, 1); 548186729Sed#else /* !TEKEN_CONS25 */ 549186681Sed teken_rect_t tr; 550186681Sed 551186681Sed tr.tr_begin = t->t_cursor; 552186681Sed teken_subr_cursor_forward_tabulation(t, 1); 553186681Sed tr.tr_end.tp_row = tr.tr_begin.tp_row + 1; 554186681Sed tr.tr_end.tp_col = t->t_cursor.tp_col; 555186681Sed 556186681Sed /* Blank region that we skipped. */ 557186681Sed if (tr.tr_end.tp_col > tr.tr_begin.tp_col) 558186681Sed teken_funcs_fill(t, &tr, BLANK, &t->t_curattr); 559186729Sed#endif /* TEKEN_CONS25 */ 560186681Sed} 561186681Sed 562186681Sedstatic void 563186681Sedteken_subr_horizontal_tab_set(teken_t *t) 564186681Sed{ 565186681Sed 566186681Sed teken_tab_set(t, t->t_cursor.tp_col); 567186681Sed} 568186681Sed 569186681Sedstatic void 570186681Sedteken_subr_index(teken_t *t) 571186681Sed{ 572186681Sed 573186681Sed if (t->t_cursor.tp_row < t->t_scrollreg.ts_end - 1) { 574186681Sed t->t_cursor.tp_row++; 575186681Sed t->t_stateflags &= ~TS_WRAPPED; 576186681Sed teken_funcs_cursor(t); 577186681Sed } else { 578186681Sed teken_subr_do_scroll(t, 1); 579186681Sed } 580186681Sed} 581186681Sed 582186681Sedstatic void 583186681Sedteken_subr_insert_character(teken_t *t, unsigned int ncols) 584186681Sed{ 585186681Sed teken_rect_t tr; 586186681Sed 587186681Sed tr.tr_begin = t->t_cursor; 588186681Sed tr.tr_end.tp_row = t->t_cursor.tp_row + 1; 589186681Sed 590186681Sed if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col) { 591186681Sed tr.tr_end.tp_col = t->t_winsize.tp_col; 592186681Sed } else { 593186681Sed teken_pos_t tp; 594186681Sed 595186681Sed /* Copy characters to the right. */ 596186681Sed tr.tr_end.tp_col = t->t_winsize.tp_col - ncols; 597186681Sed tp.tp_row = t->t_cursor.tp_row; 598186681Sed tp.tp_col = t->t_cursor.tp_col + ncols; 599186681Sed teken_funcs_copy(t, &tr, &tp); 600186681Sed 601186681Sed tr.tr_end.tp_col = t->t_cursor.tp_col + ncols; 602186681Sed } 603186681Sed 604186681Sed /* Blank current location. */ 605186681Sed teken_funcs_fill(t, &tr, BLANK, &t->t_curattr); 606186681Sed} 607186681Sed 608186681Sedstatic void 609186681Sedteken_subr_insert_line(teken_t *t, unsigned int nrows) 610186681Sed{ 611186681Sed teken_rect_t tr; 612186681Sed 613186681Sed tr.tr_begin.tp_row = t->t_cursor.tp_row; 614186681Sed tr.tr_begin.tp_col = 0; 615186681Sed tr.tr_end.tp_col = t->t_winsize.tp_col; 616186681Sed 617186681Sed if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end) { 618186681Sed tr.tr_end.tp_row = t->t_scrollreg.ts_end; 619186681Sed } else { 620186681Sed teken_pos_t tp; 621186681Sed 622186681Sed /* Copy lines down. */ 623186681Sed tr.tr_end.tp_row = t->t_scrollreg.ts_end - nrows; 624186681Sed tp.tp_row = t->t_cursor.tp_row + nrows; 625186681Sed tp.tp_col = 0; 626186681Sed teken_funcs_copy(t, &tr, &tp); 627186681Sed 628186681Sed tr.tr_end.tp_row = t->t_cursor.tp_row + nrows; 629186681Sed } 630186681Sed 631186681Sed /* Blank current location. */ 632186681Sed teken_funcs_fill(t, &tr, BLANK, &t->t_curattr); 633186681Sed} 634186681Sed 635186681Sedstatic void 636186681Sedteken_subr_keypad_application_mode(teken_t *t) 637186681Sed{ 638186681Sed 639186681Sed teken_funcs_param(t, TP_KEYPADAPP, 1); 640186681Sed} 641186681Sed 642186681Sedstatic void 643186681Sedteken_subr_keypad_numeric_mode(teken_t *t) 644186681Sed{ 645186681Sed 646186681Sed teken_funcs_param(t, TP_KEYPADAPP, 0); 647186681Sed} 648186681Sed 649186681Sedstatic void 650186681Sedteken_subr_newline(teken_t *t) 651186681Sed{ 652186681Sed 653186681Sed t->t_cursor.tp_row++; 654186681Sed 655186681Sed if (t->t_cursor.tp_row >= t->t_scrollreg.ts_end) { 656186681Sed teken_subr_do_scroll(t, 1); 657186681Sed t->t_cursor.tp_row = t->t_scrollreg.ts_end - 1; 658186681Sed } 659186681Sed 660186681Sed t->t_stateflags &= ~TS_WRAPPED; 661186681Sed teken_funcs_cursor(t); 662186681Sed} 663186681Sed 664186681Sedstatic void 665186798Sedteken_subr_newpage(teken_t *t) 666186798Sed{ 667186798Sed#ifdef TEKEN_CONS25 668186798Sed teken_rect_t tr; 669186798Sed 670186798Sed tr.tr_begin.tp_row = tr.tr_begin.tp_col = 0; 671186798Sed tr.tr_end = t->t_winsize; 672186798Sed teken_funcs_fill(t, &tr, BLANK, &t->t_curattr); 673186798Sed 674186798Sed t->t_cursor.tp_row = t->t_cursor.tp_col = 0; 675186798Sed teken_funcs_cursor(t); 676186798Sed#else /* !TEKEN_CONS25 */ 677186798Sed 678186798Sed teken_subr_newline(t); 679186798Sed#endif /* TEKEN_CONS25 */ 680186798Sed} 681186798Sed 682186798Sedstatic void 683186681Sedteken_subr_next_line(teken_t *t) 684186681Sed{ 685186681Sed 686186681Sed t->t_cursor.tp_col = 0; 687186681Sed teken_subr_newline(t); 688186681Sed} 689186681Sed 690186681Sedstatic void 691186681Sedteken_subr_pan_down(teken_t *t, unsigned int nrows) 692186681Sed{ 693186681Sed 694186681Sed teken_subr_do_scroll(t, (int)nrows); 695186681Sed} 696186681Sed 697186681Sedstatic void 698186681Sedteken_subr_pan_up(teken_t *t, unsigned int nrows) 699186681Sed{ 700186681Sed 701186681Sed teken_subr_do_scroll(t, -(int)nrows); 702186681Sed} 703186681Sed 704186681Sedstatic void 705186681Sedteken_subr_primary_device_attributes(teken_t *t, unsigned int request) 706186681Sed{ 707186681Sed 708186681Sed if (request == 0) { 709186681Sed const char response[] = "\x1B[?1;2c"; 710186681Sed 711186681Sed teken_funcs_respond(t, response, sizeof response - 1); 712186681Sed } else { 713186681Sed teken_printf("Unknown DA1\n"); 714186681Sed } 715186681Sed} 716186681Sed 717186681Sedstatic void 718186681Sedteken_subr_do_putchar(teken_t *t, const teken_pos_t *tp, teken_char_t c, 719186681Sed int width) 720186681Sed{ 721186681Sed 722186681Sed if (t->t_stateflags & TS_INSERT && 723186681Sed tp->tp_col < t->t_winsize.tp_col - width) { 724186681Sed teken_rect_t ctr; 725186681Sed teken_pos_t ctp; 726186681Sed 727186681Sed /* Insert mode. Move existing characters to the right. */ 728186681Sed ctr.tr_begin = *tp; 729186681Sed ctr.tr_end.tp_row = tp->tp_row + 1; 730186681Sed ctr.tr_end.tp_col = t->t_winsize.tp_col - width; 731186681Sed ctp.tp_row = tp->tp_row; 732186681Sed ctp.tp_col = tp->tp_col + width; 733186681Sed teken_funcs_copy(t, &ctr, &ctp); 734186681Sed } 735186681Sed 736186681Sed teken_funcs_putchar(t, tp, c, &t->t_curattr); 737186681Sed} 738186681Sed 739186681Sedstatic void 740186681Sedteken_subr_regular_character(teken_t *t, teken_char_t c) 741186681Sed{ 742186681Sed int width; 743186681Sed 744186681Sed /* XXX: Don't process zero-width characters yet. */ 745186681Sed width = teken_wcwidth(c); 746186681Sed if (width <= 0) 747186681Sed return; 748186681Sed 749186729Sed#ifdef TEKEN_CONS25 750186729Sed teken_subr_do_putchar(t, &t->t_cursor, c, width); 751186729Sed t->t_cursor.tp_col += width; 752186729Sed 753186729Sed if (t->t_cursor.tp_col >= t->t_winsize.tp_col) { 754186729Sed if (t->t_cursor.tp_row == t->t_scrollreg.ts_end - 1) { 755186729Sed /* Perform scrolling. */ 756186729Sed teken_subr_do_scroll(t, 1); 757186729Sed } else { 758186729Sed /* No scrolling needed. */ 759186729Sed if (t->t_cursor.tp_row < t->t_winsize.tp_row - 1) 760186729Sed t->t_cursor.tp_row++; 761186729Sed } 762186729Sed t->t_cursor.tp_col = 0; 763186729Sed } 764186729Sed#else /* !TEKEN_CONS25 */ 765186681Sed if (t->t_cursor.tp_col == t->t_winsize.tp_col - 1 && 766186681Sed (t->t_stateflags & (TS_WRAPPED|TS_AUTOWRAP)) == 767186681Sed (TS_WRAPPED|TS_AUTOWRAP)) { 768186681Sed teken_pos_t tp; 769186681Sed 770186681Sed /* Perform line wrapping. */ 771186681Sed 772186681Sed if (t->t_cursor.tp_row == t->t_scrollreg.ts_end - 1) { 773186681Sed /* Perform scrolling. */ 774186681Sed teken_subr_do_scroll(t, 1); 775186681Sed tp.tp_row = t->t_scrollreg.ts_end - 1; 776186681Sed } else { 777186681Sed /* No scrolling needed. */ 778186681Sed tp.tp_row = t->t_cursor.tp_row + 1; 779186681Sed if (tp.tp_row == t->t_winsize.tp_row) { 780186681Sed /* 781186681Sed * Corner case: regular character 782186681Sed * outside scrolling region, but at the 783186681Sed * bottom of the screen. 784186681Sed */ 785186681Sed teken_subr_do_putchar(t, &t->t_cursor, 786186681Sed c, width); 787186681Sed return; 788186681Sed } 789186681Sed } 790186681Sed 791186681Sed tp.tp_col = 0; 792186681Sed teken_subr_do_putchar(t, &tp, c, width); 793186681Sed 794186681Sed t->t_cursor.tp_row = tp.tp_row; 795186681Sed t->t_cursor.tp_col = width; 796186681Sed t->t_stateflags &= ~TS_WRAPPED; 797186681Sed } else { 798186681Sed /* No line wrapping needed. */ 799186681Sed teken_subr_do_putchar(t, &t->t_cursor, c, width); 800186681Sed t->t_cursor.tp_col += width; 801186681Sed 802186681Sed if (t->t_cursor.tp_col >= t->t_winsize.tp_col) { 803186681Sed t->t_stateflags |= TS_WRAPPED; 804186681Sed t->t_cursor.tp_col = t->t_winsize.tp_col - 1; 805186681Sed } else { 806186681Sed t->t_stateflags &= ~TS_WRAPPED; 807186681Sed } 808186681Sed } 809186729Sed#endif /* TEKEN_CONS25 */ 810186681Sed 811186681Sed teken_funcs_cursor(t); 812186681Sed} 813186681Sed 814186681Sedstatic void 815186681Sedteken_subr_reset_dec_mode(teken_t *t, unsigned int cmd) 816186681Sed{ 817186681Sed 818186681Sed switch (cmd) { 819186681Sed case 1: /* Cursor keys mode. */ 820186681Sed teken_funcs_param(t, TP_CURSORKEYS, 0); 821186681Sed break; 822186681Sed case 2: /* DECANM: ANSI/VT52 mode. */ 823186681Sed teken_printf("DECRST VT52\n"); 824186681Sed break; 825186681Sed case 3: /* 132 column mode. */ 826186681Sed teken_funcs_param(t, TP_132COLS, 0); 827186681Sed teken_subr_reset_to_initial_state(t); 828186681Sed break; 829186681Sed case 5: /* Inverse video. */ 830186681Sed teken_printf("DECRST inverse video\n"); 831186681Sed break; 832186681Sed case 6: /* Origin mode. */ 833186681Sed t->t_stateflags &= ~TS_ORIGIN; 834186681Sed t->t_originreg.ts_begin = 0; 835186681Sed t->t_originreg.ts_end = t->t_winsize.tp_row; 836186681Sed t->t_cursor.tp_row = t->t_cursor.tp_col = 0; 837186681Sed t->t_stateflags &= ~TS_WRAPPED; 838186681Sed teken_funcs_cursor(t); 839186681Sed break; 840186681Sed case 7: /* Autowrap mode. */ 841186681Sed t->t_stateflags &= ~TS_AUTOWRAP; 842186681Sed break; 843186681Sed case 8: /* Autorepeat mode. */ 844186681Sed teken_funcs_param(t, TP_AUTOREPEAT, 0); 845186681Sed break; 846186681Sed case 25: /* Hide cursor. */ 847186681Sed teken_funcs_param(t, TP_SHOWCURSOR, 0); 848186681Sed break; 849186681Sed case 40: /* Disallow 132 columns. */ 850186681Sed teken_printf("DECRST allow 132\n"); 851186681Sed break; 852186681Sed case 45: /* Disable reverse wraparound. */ 853186681Sed teken_printf("DECRST reverse wraparound\n"); 854186681Sed break; 855186681Sed case 47: /* Switch to alternate buffer. */ 856186681Sed teken_printf("Switch to alternate buffer\n"); 857186681Sed break; 858186681Sed default: 859186681Sed teken_printf("Unknown DECRST: %u\n", cmd); 860186681Sed } 861186681Sed} 862186681Sed 863186681Sedstatic void 864186681Sedteken_subr_reset_mode(teken_t *t, unsigned int cmd) 865186681Sed{ 866186681Sed 867186681Sed switch (cmd) { 868186681Sed case 4: 869186681Sed t->t_stateflags &= ~TS_INSERT; 870186681Sed break; 871186681Sed default: 872186681Sed teken_printf("Unknown reset mode: %u\n", cmd); 873186681Sed } 874186681Sed} 875186681Sed 876186681Sedstatic void 877186681Sedteken_subr_do_reset(teken_t *t) 878186681Sed{ 879186681Sed 880186681Sed t->t_curattr = t->t_saved_curattr = t->t_defattr; 881186681Sed t->t_cursor.tp_row = t->t_cursor.tp_col = 0; 882186681Sed t->t_saved_cursor = t->t_cursor; 883186681Sed t->t_stateflags = TS_AUTOWRAP; 884186681Sed 885186681Sed teken_tab_default(t); 886186681Sed} 887186681Sed 888186681Sedstatic void 889186681Sedteken_subr_reset_to_initial_state(teken_t *t) 890186681Sed{ 891186681Sed 892186681Sed teken_subr_do_reset(t); 893186681Sed teken_subr_erase_display(t, 2); 894186753Sed teken_funcs_param(t, TP_SHOWCURSOR, 1); 895186681Sed teken_funcs_cursor(t); 896186681Sed} 897186681Sed 898186681Sedstatic void 899186681Sedteken_subr_restore_cursor(teken_t *t) 900186681Sed{ 901186681Sed 902186681Sed t->t_cursor = t->t_saved_cursor; 903186681Sed t->t_curattr = t->t_saved_curattr; 904186681Sed t->t_stateflags &= ~TS_WRAPPED; 905186681Sed teken_funcs_cursor(t); 906186681Sed} 907186681Sed 908186681Sedstatic void 909186681Sedteken_subr_reverse_index(teken_t *t) 910186681Sed{ 911186681Sed 912186681Sed if (t->t_cursor.tp_row > t->t_scrollreg.ts_begin) { 913186681Sed t->t_cursor.tp_row--; 914186681Sed t->t_stateflags &= ~TS_WRAPPED; 915186681Sed teken_funcs_cursor(t); 916186681Sed } else { 917186681Sed teken_subr_do_scroll(t, -1); 918186681Sed } 919186681Sed} 920186681Sed 921186681Sedstatic void 922186681Sedteken_subr_save_cursor(teken_t *t) 923186681Sed{ 924186681Sed 925186681Sed t->t_saved_cursor = t->t_cursor; 926186681Sed t->t_saved_curattr = t->t_curattr; 927186681Sed} 928186681Sed 929186681Sedstatic void 930186681Sedteken_subr_scs(teken_t *t __unused) 931186681Sed{ 932186681Sed 933186681Sed teken_printf("scs???\n"); 934186681Sed} 935186681Sed 936186681Sedstatic void 937186681Sedteken_subr_secondary_device_attributes(teken_t *t, unsigned int request) 938186681Sed{ 939186681Sed 940186681Sed if (request == 0) { 941186681Sed const char response[] = "\x1B[>0;10;0c"; 942186681Sed teken_funcs_respond(t, response, sizeof response - 1); 943186681Sed } else { 944186681Sed teken_printf("Unknown DA2\n"); 945186681Sed } 946186681Sed} 947186681Sed 948186681Sedstatic void 949186681Sedteken_subr_set_dec_mode(teken_t *t, unsigned int cmd) 950186681Sed{ 951186681Sed 952186681Sed switch (cmd) { 953186681Sed case 1: /* Cursor keys mode. */ 954186681Sed teken_funcs_param(t, TP_CURSORKEYS, 1); 955186681Sed break; 956186681Sed case 2: /* DECANM: ANSI/VT52 mode. */ 957186681Sed teken_printf("DECSET VT52\n"); 958186681Sed break; 959186681Sed case 3: /* 132 column mode. */ 960186681Sed teken_funcs_param(t, TP_132COLS, 1); 961186681Sed teken_subr_reset_to_initial_state(t); 962186681Sed break; 963186681Sed case 5: /* Inverse video. */ 964186681Sed teken_printf("DECSET inverse video\n"); 965186681Sed break; 966186681Sed case 6: /* Origin mode. */ 967186681Sed t->t_stateflags |= TS_ORIGIN; 968186681Sed t->t_originreg = t->t_scrollreg; 969186681Sed t->t_cursor.tp_row = t->t_scrollreg.ts_begin; 970186681Sed t->t_cursor.tp_col = 0; 971186681Sed t->t_stateflags &= ~TS_WRAPPED; 972186681Sed teken_funcs_cursor(t); 973186681Sed break; 974186681Sed case 7: /* Autowrap mode. */ 975186681Sed t->t_stateflags |= TS_AUTOWRAP; 976186681Sed break; 977186681Sed case 8: /* Autorepeat mode. */ 978186681Sed teken_funcs_param(t, TP_AUTOREPEAT, 1); 979186681Sed break; 980186681Sed case 25: /* Display cursor. */ 981186681Sed teken_funcs_param(t, TP_SHOWCURSOR, 1); 982186681Sed break; 983186681Sed case 40: /* Allow 132 columns. */ 984186681Sed teken_printf("DECSET allow 132\n"); 985186681Sed break; 986186681Sed case 45: /* Enable reverse wraparound. */ 987186681Sed teken_printf("DECSET reverse wraparound\n"); 988186681Sed break; 989186681Sed case 47: /* Switch to alternate buffer. */ 990186681Sed teken_printf("Switch away from alternate buffer\n"); 991186681Sed break; 992186681Sed default: 993186681Sed teken_printf("Unknown DECSET: %u\n", cmd); 994186681Sed } 995186681Sed} 996186681Sed 997186681Sedstatic void 998186681Sedteken_subr_set_mode(teken_t *t, unsigned int cmd) 999186681Sed{ 1000186681Sed 1001186681Sed switch (cmd) { 1002186681Sed case 4: 1003186681Sed teken_printf("Insert mode\n"); 1004186681Sed t->t_stateflags |= TS_INSERT; 1005186681Sed break; 1006186681Sed default: 1007186681Sed teken_printf("Unknown set mode: %u\n", cmd); 1008186681Sed } 1009186681Sed} 1010186681Sed 1011186681Sedstatic void 1012186681Sedteken_subr_set_graphic_rendition(teken_t *t, unsigned int ncmds, 1013186681Sed unsigned int cmds[]) 1014186681Sed{ 1015186681Sed unsigned int i, n; 1016186681Sed 1017186681Sed /* No attributes means reset. */ 1018186681Sed if (ncmds == 0) { 1019186681Sed t->t_curattr = t->t_defattr; 1020186681Sed return; 1021186681Sed } 1022186681Sed 1023186681Sed for (i = 0; i < ncmds; i++) { 1024186681Sed n = cmds[i]; 1025186681Sed 1026186681Sed switch (n) { 1027186681Sed case 0: /* Reset. */ 1028186681Sed t->t_curattr = t->t_defattr; 1029186681Sed break; 1030186681Sed case 1: /* Bold. */ 1031186681Sed t->t_curattr.ta_format |= TF_BOLD; 1032186681Sed break; 1033186681Sed case 4: /* Underline. */ 1034186681Sed t->t_curattr.ta_format |= TF_UNDERLINE; 1035186681Sed break; 1036186681Sed case 5: /* Blink. */ 1037186681Sed t->t_curattr.ta_format |= TF_BLINK; 1038186681Sed break; 1039186681Sed case 7: /* Reverse. */ 1040186681Sed t->t_curattr.ta_format |= TF_REVERSE; 1041186681Sed break; 1042186681Sed case 22: /* Remove bold. */ 1043186681Sed t->t_curattr.ta_format &= ~TF_BOLD; 1044186681Sed break; 1045186681Sed case 24: /* Remove underline. */ 1046186681Sed t->t_curattr.ta_format &= ~TF_UNDERLINE; 1047186681Sed break; 1048186681Sed case 25: /* Remove blink. */ 1049186681Sed t->t_curattr.ta_format &= ~TF_BLINK; 1050186681Sed break; 1051186681Sed case 27: /* Remove reverse. */ 1052186681Sed t->t_curattr.ta_format &= ~TF_REVERSE; 1053186681Sed break; 1054186681Sed case 30: /* Set foreground color: black */ 1055186681Sed case 31: /* Set foreground color: red */ 1056186681Sed case 32: /* Set foreground color: green */ 1057186681Sed case 33: /* Set foreground color: brown */ 1058186681Sed case 34: /* Set foreground color: blue */ 1059186681Sed case 35: /* Set foreground color: magenta */ 1060186681Sed case 36: /* Set foreground color: cyan */ 1061186681Sed case 37: /* Set foreground color: white */ 1062186681Sed t->t_curattr.ta_fgcolor = n - 30; 1063186681Sed break; 1064186681Sed case 39: /* Set default foreground color. */ 1065186681Sed t->t_curattr.ta_fgcolor = t->t_defattr.ta_fgcolor; 1066186681Sed break; 1067186681Sed case 40: /* Set background color: black */ 1068186681Sed case 41: /* Set background color: red */ 1069186681Sed case 42: /* Set background color: green */ 1070186681Sed case 43: /* Set background color: brown */ 1071186681Sed case 44: /* Set background color: blue */ 1072186681Sed case 45: /* Set background color: magenta */ 1073186681Sed case 46: /* Set background color: cyan */ 1074186681Sed case 47: /* Set background color: white */ 1075186681Sed t->t_curattr.ta_bgcolor = n - 40; 1076186681Sed break; 1077186681Sed case 49: /* Set default background color. */ 1078186681Sed t->t_curattr.ta_bgcolor = t->t_defattr.ta_bgcolor; 1079186681Sed break; 1080186681Sed default: 1081186681Sed teken_printf("unsupported attribute %u\n", n); 1082186681Sed } 1083186681Sed } 1084186681Sed} 1085186681Sed 1086186681Sedstatic void 1087186681Sedteken_subr_set_top_and_bottom_margins(teken_t *t, unsigned int top, 1088186681Sed unsigned int bottom) 1089186681Sed{ 1090186681Sed 1091186681Sed /* Adjust top row number. */ 1092186681Sed if (top > 0) 1093186681Sed top--; 1094186681Sed /* Adjust bottom row number. */ 1095186681Sed if (bottom == 0 || bottom > t->t_winsize.tp_row) 1096186681Sed bottom = t->t_winsize.tp_row; 1097186681Sed 1098186681Sed /* Invalid arguments. */ 1099186681Sed if (top >= bottom - 1) { 1100186681Sed top = 0; 1101186681Sed bottom = t->t_winsize.tp_row; 1102186681Sed } 1103186681Sed 1104186681Sed t->t_scrollreg.ts_begin = top; 1105186681Sed t->t_scrollreg.ts_end = bottom; 1106186681Sed if (t->t_stateflags & TS_ORIGIN) { 1107186681Sed /* XXX: home cursor? */ 1108186681Sed t->t_originreg = t->t_scrollreg; 1109186681Sed t->t_cursor.tp_row = t->t_originreg.ts_begin; 1110186681Sed t->t_cursor.tp_col = 0; 1111186681Sed t->t_stateflags &= ~TS_WRAPPED; 1112186681Sed teken_funcs_cursor(t); 1113186681Sed } 1114186681Sed} 1115186681Sed 1116186681Sedstatic void 1117186681Sedteken_subr_single_height_double_width_line(teken_t *t __unused) 1118186681Sed{ 1119186681Sed 1120186681Sed teken_printf("single height double width???\n"); 1121186681Sed} 1122186681Sed 1123186681Sedstatic void 1124186681Sedteken_subr_single_height_single_width_line(teken_t *t __unused) 1125186681Sed{ 1126186681Sed 1127186681Sed teken_printf("single height single width???\n"); 1128186681Sed} 1129186681Sed 1130186681Sedstatic void 1131186681Sedteken_subr_string_terminator(teken_t *t __unused) 1132186681Sed{ 1133186681Sed 1134186681Sed teken_printf("string terminator???\n"); 1135186681Sed} 1136186681Sed 1137186681Sedstatic void 1138186681Sedteken_subr_tab_clear(teken_t *t, unsigned int cmd) 1139186681Sed{ 1140186681Sed 1141186681Sed switch (cmd) { 1142186681Sed case 0: 1143186681Sed teken_tab_clear(t, t->t_cursor.tp_col); 1144186681Sed break; 1145186681Sed case 3: 1146186681Sed memset(&t->t_tabstops, 0, T_NUMCOL / 8); 1147186681Sed break; 1148186681Sed } 1149186681Sed} 1150186681Sed 1151186681Sedstatic void 1152186681Sedteken_subr_vertical_position_absolute(teken_t *t, unsigned int row) 1153186681Sed{ 1154186681Sed 1155186681Sed t->t_cursor.tp_row = t->t_originreg.ts_begin + row - 1; 1156186681Sed if (row >= t->t_originreg.ts_end) 1157186681Sed t->t_cursor.tp_row = t->t_originreg.ts_end - 1; 1158186681Sed 1159186681Sed 1160186681Sed t->t_stateflags &= ~TS_WRAPPED; 1161186681Sed teken_funcs_cursor(t); 1162186681Sed} 1163