teken_subr.h revision 186729
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 186729 2009-01-03 22:51:54Z 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
201186681Sed	if (t->t_cursor.tp_col == 0)
202186681Sed		return;
203186681Sed
204186681Sed	t->t_cursor.tp_col--;
205186681Sed	t->t_stateflags &= ~TS_WRAPPED;
206186681Sed
207186681Sed	teken_funcs_cursor(t);
208186681Sed}
209186681Sed
210186681Sedstatic void
211186681Sedteken_subr_bell(teken_t *t)
212186681Sed{
213186681Sed
214186681Sed	teken_funcs_bell(t);
215186681Sed}
216186681Sed
217186681Sedstatic void
218186681Sedteken_subr_carriage_return(teken_t *t)
219186681Sed{
220186681Sed
221186681Sed	t->t_cursor.tp_col = 0;
222186681Sed	t->t_stateflags &= ~TS_WRAPPED;
223186681Sed	teken_funcs_cursor(t);
224186681Sed}
225186681Sed
226186681Sedstatic void
227186681Sedteken_subr_cursor_backward(teken_t *t, unsigned int ncols)
228186681Sed{
229186681Sed
230186681Sed	if (ncols > t->t_cursor.tp_col)
231186681Sed		t->t_cursor.tp_col = 0;
232186681Sed	else
233186681Sed		t->t_cursor.tp_col -= ncols;
234186681Sed	t->t_stateflags &= ~TS_WRAPPED;
235186681Sed	teken_funcs_cursor(t);
236186681Sed}
237186681Sed
238186681Sedstatic void
239186681Sedteken_subr_cursor_backward_tabulation(teken_t *t, unsigned int ntabs)
240186681Sed{
241186681Sed
242186681Sed	do {
243186681Sed		/* Stop when we've reached the beginning of the line. */
244186681Sed		if (t->t_cursor.tp_col == 0)
245186681Sed			break;
246186681Sed
247186681Sed		t->t_cursor.tp_col--;
248186681Sed
249186681Sed		/* Tab marker set. */
250186681Sed		if (teken_tab_isset(t, t->t_cursor.tp_col))
251186681Sed			ntabs--;
252186681Sed	} while (ntabs > 0);
253186729Sed
254186729Sed	teken_funcs_cursor(t);
255186681Sed}
256186681Sed
257186681Sedstatic void
258186681Sedteken_subr_cursor_down(teken_t *t, unsigned int nrows)
259186681Sed{
260186681Sed
261186681Sed	if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end)
262186681Sed		t->t_cursor.tp_row = t->t_scrollreg.ts_end - 1;
263186681Sed	else
264186681Sed		t->t_cursor.tp_row += nrows;
265186681Sed	t->t_stateflags &= ~TS_WRAPPED;
266186681Sed	teken_funcs_cursor(t);
267186681Sed}
268186681Sed
269186681Sedstatic void
270186681Sedteken_subr_cursor_forward(teken_t *t, unsigned int ncols)
271186681Sed{
272186681Sed
273186681Sed	if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col)
274186681Sed		t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
275186681Sed	else
276186681Sed		t->t_cursor.tp_col += ncols;
277186681Sed	t->t_stateflags &= ~TS_WRAPPED;
278186681Sed	teken_funcs_cursor(t);
279186681Sed}
280186681Sed
281186681Sedstatic void
282186681Sedteken_subr_cursor_forward_tabulation(teken_t *t, unsigned int ntabs)
283186681Sed{
284186681Sed
285186681Sed	do {
286186681Sed		/* Stop when we've reached the end of the line. */
287186681Sed		if (t->t_cursor.tp_col == t->t_winsize.tp_col - 1)
288186681Sed			break;
289186681Sed
290186681Sed		t->t_cursor.tp_col++;
291186681Sed
292186681Sed		/* Tab marker set. */
293186681Sed		if (teken_tab_isset(t, t->t_cursor.tp_col))
294186681Sed			ntabs--;
295186681Sed	} while (ntabs > 0);
296186729Sed
297186729Sed	teken_funcs_cursor(t);
298186681Sed}
299186681Sed
300186681Sedstatic void
301186681Sedteken_subr_cursor_next_line(teken_t *t, unsigned int ncols)
302186681Sed{
303186681Sed
304186681Sed	t->t_cursor.tp_col = 0;
305186681Sed	teken_subr_cursor_down(t, ncols);
306186681Sed}
307186681Sed
308186681Sedstatic void
309186681Sedteken_subr_cursor_position(teken_t *t, unsigned int row, unsigned int col)
310186681Sed{
311186681Sed
312186681Sed	t->t_cursor.tp_row = t->t_originreg.ts_begin + row - 1;
313186681Sed	if (row >= t->t_originreg.ts_end)
314186681Sed		t->t_cursor.tp_row = t->t_originreg.ts_end - 1;
315186681Sed
316186681Sed	t->t_cursor.tp_col = col - 1;
317186681Sed	if (t->t_cursor.tp_col >= t->t_winsize.tp_col)
318186681Sed		t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
319186681Sed
320186681Sed	t->t_stateflags &= ~TS_WRAPPED;
321186681Sed	teken_funcs_cursor(t);
322186681Sed}
323186681Sed
324186681Sedstatic void
325186681Sedteken_subr_cursor_position_report(teken_t *t, unsigned int cmd)
326186681Sed{
327186681Sed	char response[18] = "\x1B[";
328186681Sed	ssize_t len;
329186681Sed
330186681Sed	len = teken_subr_do_cpr(t, cmd, response + 2);
331186681Sed	if (len < 0)
332186681Sed		return;
333186681Sed
334186681Sed	teken_funcs_respond(t, response, len + 2);
335186681Sed}
336186681Sed
337186681Sedstatic void
338186681Sedteken_subr_cursor_previous_line(teken_t *t, unsigned int ncols)
339186681Sed{
340186681Sed
341186681Sed	t->t_cursor.tp_col = 0;
342186681Sed	teken_subr_cursor_up(t, ncols);
343186681Sed}
344186681Sed
345186681Sedstatic void
346186681Sedteken_subr_cursor_up(teken_t *t, unsigned int nrows)
347186681Sed{
348186681Sed
349186681Sed	if (t->t_scrollreg.ts_begin + nrows >= t->t_cursor.tp_row)
350186681Sed		t->t_cursor.tp_row = t->t_scrollreg.ts_begin;
351186681Sed	else
352186681Sed		t->t_cursor.tp_row -= nrows;
353186681Sed	t->t_stateflags &= ~TS_WRAPPED;
354186681Sed	teken_funcs_cursor(t);
355186681Sed}
356186681Sed
357186681Sedstatic void
358186681Sedteken_subr_delete_character(teken_t *t, unsigned int ncols)
359186681Sed{
360186681Sed	teken_rect_t tr;
361186681Sed
362186681Sed	tr.tr_begin.tp_row = t->t_cursor.tp_row;
363186681Sed	tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
364186681Sed	tr.tr_end.tp_col = t->t_winsize.tp_col;
365186681Sed
366186681Sed	if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col) {
367186681Sed		tr.tr_begin.tp_col = t->t_cursor.tp_col;
368186681Sed	} else {
369186681Sed		/* Copy characters to the left. */
370186681Sed		tr.tr_begin.tp_col = t->t_cursor.tp_col + ncols;
371186681Sed		teken_funcs_copy(t, &tr, &t->t_cursor);
372186681Sed
373186681Sed		tr.tr_begin.tp_col = t->t_winsize.tp_col - ncols;
374186681Sed	}
375186681Sed
376186681Sed	/* Blank trailing columns. */
377186681Sed	teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
378186681Sed}
379186681Sed
380186681Sedstatic void
381186681Sedteken_subr_delete_line(teken_t *t, unsigned int nrows)
382186681Sed{
383186681Sed	teken_rect_t tr;
384186681Sed
385186681Sed	tr.tr_begin.tp_col = 0;
386186681Sed	tr.tr_end.tp_row = t->t_scrollreg.ts_end;
387186681Sed	tr.tr_end.tp_col = t->t_winsize.tp_col;
388186681Sed
389186681Sed	if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end) {
390186681Sed		tr.tr_begin.tp_row = t->t_cursor.tp_row;
391186681Sed	} else {
392186681Sed		teken_pos_t tp;
393186681Sed
394186681Sed		/* Copy rows up. */
395186681Sed		tr.tr_begin.tp_row = t->t_cursor.tp_row + nrows;
396186681Sed		tp.tp_row = t->t_cursor.tp_row;
397186681Sed		tp.tp_col = 0;
398186681Sed		teken_funcs_copy(t, &tr, &tp);
399186681Sed
400186681Sed		tr.tr_begin.tp_row = t->t_scrollreg.ts_end - nrows;
401186681Sed	}
402186681Sed
403186681Sed	/* Blank trailing rows. */
404186681Sed	teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
405186681Sed}
406186681Sed
407186681Sedstatic void
408186681Sedteken_subr_device_control_string(teken_t *t __unused)
409186681Sed{
410186681Sed
411186681Sed	teken_printf("device control string???\n");
412186681Sed}
413186681Sed
414186681Sedstatic void
415186681Sedteken_subr_device_status_report(teken_t *t, unsigned int cmd)
416186681Sed{
417186681Sed	char response[19] = "\x1B[?";
418186681Sed	ssize_t len;
419186681Sed
420186681Sed	len = teken_subr_do_cpr(t, cmd, response + 3);
421186681Sed	if (len < 0)
422186681Sed		return;
423186681Sed
424186681Sed	teken_funcs_respond(t, response, len + 3);
425186681Sed}
426186681Sed
427186681Sedstatic void
428186681Sedteken_subr_double_height_double_width_line_top(teken_t *t __unused)
429186681Sed{
430186681Sed
431186681Sed	teken_printf("double height double width top\n");
432186681Sed}
433186681Sed
434186681Sedstatic void
435186681Sedteken_subr_double_height_double_width_line_bottom(teken_t *t __unused)
436186681Sed{
437186681Sed
438186681Sed	teken_printf("double height double width bottom\n");
439186681Sed}
440186681Sed
441186681Sedstatic void
442186681Sedteken_subr_erase_character(teken_t *t, unsigned int ncols)
443186681Sed{
444186681Sed	teken_rect_t tr;
445186681Sed
446186681Sed	tr.tr_begin = t->t_cursor;
447186681Sed	tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
448186681Sed
449186681Sed	if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col)
450186681Sed		tr.tr_end.tp_col = t->t_winsize.tp_col;
451186681Sed	else
452186681Sed		tr.tr_end.tp_col = t->t_cursor.tp_col + ncols;
453186681Sed
454186681Sed	teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
455186681Sed}
456186681Sed
457186681Sedstatic void
458186681Sedteken_subr_erase_display(teken_t *t, unsigned int mode)
459186681Sed{
460186681Sed	teken_rect_t r;
461186681Sed
462186681Sed	r.tr_begin.tp_col = 0;
463186681Sed	r.tr_end.tp_col = t->t_winsize.tp_col;
464186681Sed
465186681Sed	switch (mode) {
466186681Sed	case 1: /* Erase from the top to the cursor. */
467186681Sed		teken_subr_erase_line(t, 1);
468186681Sed
469186681Sed		/* Erase lines above. */
470186681Sed		if (t->t_cursor.tp_row == 0)
471186681Sed			return;
472186681Sed		r.tr_begin.tp_row = 0;
473186681Sed		r.tr_end.tp_row = t->t_cursor.tp_row;
474186681Sed		break;
475186681Sed	case 2: /* Erase entire display. */
476186681Sed		r.tr_begin.tp_row = 0;
477186681Sed		r.tr_end.tp_row = t->t_winsize.tp_row;
478186681Sed		break;
479186681Sed	default: /* Erase from cursor to the bottom. */
480186681Sed		teken_subr_erase_line(t, 0);
481186681Sed
482186681Sed		/* Erase lines below. */
483186681Sed		if (t->t_cursor.tp_row == t->t_winsize.tp_row - 1)
484186681Sed			return;
485186681Sed		r.tr_begin.tp_row = t->t_cursor.tp_row + 1;
486186681Sed		r.tr_end.tp_row = t->t_winsize.tp_row;
487186681Sed		break;
488186681Sed	}
489186681Sed
490186681Sed	teken_funcs_fill(t, &r, BLANK, &t->t_curattr);
491186681Sed}
492186681Sed
493186681Sedstatic void
494186681Sedteken_subr_erase_line(teken_t *t, unsigned int mode)
495186681Sed{
496186681Sed	teken_rect_t r;
497186681Sed
498186681Sed	r.tr_begin.tp_row = t->t_cursor.tp_row;
499186681Sed	r.tr_end.tp_row = t->t_cursor.tp_row + 1;
500186681Sed
501186681Sed	switch (mode) {
502186681Sed	case 1: /* Erase from the beginning of the line to the cursor. */
503186681Sed		r.tr_begin.tp_col = 0;
504186681Sed		r.tr_end.tp_col = t->t_cursor.tp_col + 1;
505186681Sed		break;
506186681Sed	case 2: /* Erase entire line. */
507186681Sed		r.tr_begin.tp_col = 0;
508186681Sed		r.tr_end.tp_col = t->t_winsize.tp_col;
509186681Sed		break;
510186681Sed	default: /* Erase from cursor to the end of the line. */
511186681Sed		r.tr_begin.tp_col = t->t_cursor.tp_col;
512186681Sed		r.tr_end.tp_col = t->t_winsize.tp_col;
513186681Sed		break;
514186681Sed	}
515186681Sed
516186681Sed	teken_funcs_fill(t, &r, BLANK, &t->t_curattr);
517186681Sed}
518186681Sed
519186681Sedstatic void
520186681Sedteken_subr_horizontal_position_absolute(teken_t *t, unsigned int col)
521186681Sed{
522186681Sed
523186681Sed	t->t_cursor.tp_col = col - 1;
524186681Sed	if (t->t_cursor.tp_col >= t->t_winsize.tp_col)
525186681Sed		t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
526186681Sed
527186681Sed	t->t_stateflags &= ~TS_WRAPPED;
528186681Sed	teken_funcs_cursor(t);
529186681Sed}
530186681Sed
531186681Sedstatic void
532186681Sedteken_subr_horizontal_tab(teken_t *t)
533186681Sed{
534186729Sed#ifdef TEKEN_CONS25
535186729Sed
536186729Sed	teken_subr_cursor_forward_tabulation(t, 1);
537186729Sed#else /* !TEKEN_CONS25 */
538186681Sed	teken_rect_t tr;
539186681Sed
540186681Sed	tr.tr_begin = t->t_cursor;
541186681Sed	teken_subr_cursor_forward_tabulation(t, 1);
542186681Sed	tr.tr_end.tp_row = tr.tr_begin.tp_row + 1;
543186681Sed	tr.tr_end.tp_col = t->t_cursor.tp_col;
544186681Sed
545186681Sed	/* Blank region that we skipped. */
546186681Sed	if (tr.tr_end.tp_col > tr.tr_begin.tp_col)
547186681Sed		teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
548186729Sed#endif /* TEKEN_CONS25 */
549186681Sed}
550186681Sed
551186681Sedstatic void
552186681Sedteken_subr_horizontal_tab_set(teken_t *t)
553186681Sed{
554186681Sed
555186681Sed	teken_tab_set(t, t->t_cursor.tp_col);
556186681Sed}
557186681Sed
558186681Sedstatic void
559186681Sedteken_subr_index(teken_t *t)
560186681Sed{
561186681Sed
562186681Sed	if (t->t_cursor.tp_row < t->t_scrollreg.ts_end - 1) {
563186681Sed		t->t_cursor.tp_row++;
564186681Sed		t->t_stateflags &= ~TS_WRAPPED;
565186681Sed		teken_funcs_cursor(t);
566186681Sed	} else {
567186681Sed		teken_subr_do_scroll(t, 1);
568186681Sed	}
569186681Sed}
570186681Sed
571186681Sedstatic void
572186681Sedteken_subr_insert_character(teken_t *t, unsigned int ncols)
573186681Sed{
574186681Sed	teken_rect_t tr;
575186681Sed
576186681Sed	tr.tr_begin = t->t_cursor;
577186681Sed	tr.tr_end.tp_row = t->t_cursor.tp_row + 1;
578186681Sed
579186681Sed	if (t->t_cursor.tp_col + ncols >= t->t_winsize.tp_col) {
580186681Sed		tr.tr_end.tp_col = t->t_winsize.tp_col;
581186681Sed	} else {
582186681Sed		teken_pos_t tp;
583186681Sed
584186681Sed		/* Copy characters to the right. */
585186681Sed		tr.tr_end.tp_col = t->t_winsize.tp_col - ncols;
586186681Sed		tp.tp_row = t->t_cursor.tp_row;
587186681Sed		tp.tp_col = t->t_cursor.tp_col + ncols;
588186681Sed		teken_funcs_copy(t, &tr, &tp);
589186681Sed
590186681Sed		tr.tr_end.tp_col = t->t_cursor.tp_col + ncols;
591186681Sed	}
592186681Sed
593186681Sed	/* Blank current location. */
594186681Sed	teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
595186681Sed}
596186681Sed
597186681Sedstatic void
598186681Sedteken_subr_insert_line(teken_t *t, unsigned int nrows)
599186681Sed{
600186681Sed	teken_rect_t tr;
601186681Sed
602186681Sed	tr.tr_begin.tp_row = t->t_cursor.tp_row;
603186681Sed	tr.tr_begin.tp_col = 0;
604186681Sed	tr.tr_end.tp_col = t->t_winsize.tp_col;
605186681Sed
606186681Sed	if (t->t_cursor.tp_row + nrows >= t->t_scrollreg.ts_end) {
607186681Sed		tr.tr_end.tp_row = t->t_scrollreg.ts_end;
608186681Sed	} else {
609186681Sed		teken_pos_t tp;
610186681Sed
611186681Sed		/* Copy lines down. */
612186681Sed		tr.tr_end.tp_row = t->t_scrollreg.ts_end - nrows;
613186681Sed		tp.tp_row = t->t_cursor.tp_row + nrows;
614186681Sed		tp.tp_col = 0;
615186681Sed		teken_funcs_copy(t, &tr, &tp);
616186681Sed
617186681Sed		tr.tr_end.tp_row = t->t_cursor.tp_row + nrows;
618186681Sed	}
619186681Sed
620186681Sed	/* Blank current location. */
621186681Sed	teken_funcs_fill(t, &tr, BLANK, &t->t_curattr);
622186681Sed}
623186681Sed
624186681Sedstatic void
625186681Sedteken_subr_keypad_application_mode(teken_t *t)
626186681Sed{
627186681Sed
628186681Sed	teken_funcs_param(t, TP_KEYPADAPP, 1);
629186681Sed}
630186681Sed
631186681Sedstatic void
632186681Sedteken_subr_keypad_numeric_mode(teken_t *t)
633186681Sed{
634186681Sed
635186681Sed	teken_funcs_param(t, TP_KEYPADAPP, 0);
636186681Sed}
637186681Sed
638186681Sedstatic void
639186681Sedteken_subr_newline(teken_t *t)
640186681Sed{
641186681Sed
642186681Sed	t->t_cursor.tp_row++;
643186681Sed
644186681Sed	if (t->t_cursor.tp_row >= t->t_scrollreg.ts_end) {
645186681Sed		teken_subr_do_scroll(t, 1);
646186681Sed		t->t_cursor.tp_row = t->t_scrollreg.ts_end - 1;
647186681Sed	}
648186681Sed
649186681Sed	t->t_stateflags &= ~TS_WRAPPED;
650186681Sed	teken_funcs_cursor(t);
651186681Sed}
652186681Sed
653186681Sedstatic void
654186681Sedteken_subr_next_line(teken_t *t)
655186681Sed{
656186681Sed
657186681Sed	t->t_cursor.tp_col = 0;
658186681Sed	teken_subr_newline(t);
659186681Sed}
660186681Sed
661186681Sedstatic void
662186681Sedteken_subr_pan_down(teken_t *t, unsigned int nrows)
663186681Sed{
664186681Sed
665186681Sed	teken_subr_do_scroll(t, (int)nrows);
666186681Sed}
667186681Sed
668186681Sedstatic void
669186681Sedteken_subr_pan_up(teken_t *t, unsigned int nrows)
670186681Sed{
671186681Sed
672186681Sed	teken_subr_do_scroll(t, -(int)nrows);
673186681Sed}
674186681Sed
675186681Sedstatic void
676186681Sedteken_subr_primary_device_attributes(teken_t *t, unsigned int request)
677186681Sed{
678186681Sed
679186681Sed	if (request == 0) {
680186681Sed		const char response[] = "\x1B[?1;2c";
681186681Sed
682186681Sed		teken_funcs_respond(t, response, sizeof response - 1);
683186681Sed	} else {
684186681Sed		teken_printf("Unknown DA1\n");
685186681Sed	}
686186681Sed}
687186681Sed
688186681Sedstatic void
689186681Sedteken_subr_do_putchar(teken_t *t, const teken_pos_t *tp, teken_char_t c,
690186681Sed    int width)
691186681Sed{
692186681Sed
693186681Sed	if (t->t_stateflags & TS_INSERT &&
694186681Sed	    tp->tp_col < t->t_winsize.tp_col - width) {
695186681Sed		teken_rect_t ctr;
696186681Sed		teken_pos_t ctp;
697186681Sed
698186681Sed		/* Insert mode. Move existing characters to the right. */
699186681Sed		ctr.tr_begin = *tp;
700186681Sed		ctr.tr_end.tp_row = tp->tp_row + 1;
701186681Sed		ctr.tr_end.tp_col = t->t_winsize.tp_col - width;
702186681Sed		ctp.tp_row = tp->tp_row;
703186681Sed		ctp.tp_col = tp->tp_col + width;
704186681Sed		teken_funcs_copy(t, &ctr, &ctp);
705186681Sed	}
706186681Sed
707186681Sed	teken_funcs_putchar(t, tp, c, &t->t_curattr);
708186681Sed}
709186681Sed
710186681Sedstatic void
711186681Sedteken_subr_regular_character(teken_t *t, teken_char_t c)
712186681Sed{
713186681Sed	int width;
714186681Sed
715186681Sed	/* XXX: Don't process zero-width characters yet. */
716186681Sed	width = teken_wcwidth(c);
717186681Sed	if (width <= 0)
718186681Sed		return;
719186681Sed
720186729Sed#ifdef TEKEN_CONS25
721186729Sed	teken_subr_do_putchar(t, &t->t_cursor, c, width);
722186729Sed	t->t_cursor.tp_col += width;
723186729Sed
724186729Sed	if (t->t_cursor.tp_col >= t->t_winsize.tp_col) {
725186729Sed		if (t->t_cursor.tp_row == t->t_scrollreg.ts_end - 1) {
726186729Sed			/* Perform scrolling. */
727186729Sed			teken_subr_do_scroll(t, 1);
728186729Sed		} else {
729186729Sed			/* No scrolling needed. */
730186729Sed			if (t->t_cursor.tp_row < t->t_winsize.tp_row - 1)
731186729Sed				t->t_cursor.tp_row++;
732186729Sed		}
733186729Sed		t->t_cursor.tp_col = 0;
734186729Sed	}
735186729Sed#else /* !TEKEN_CONS25 */
736186681Sed	if (t->t_cursor.tp_col == t->t_winsize.tp_col - 1 &&
737186681Sed	    (t->t_stateflags & (TS_WRAPPED|TS_AUTOWRAP)) ==
738186681Sed	    (TS_WRAPPED|TS_AUTOWRAP)) {
739186681Sed		teken_pos_t tp;
740186681Sed
741186681Sed		/* Perform line wrapping. */
742186681Sed
743186681Sed		if (t->t_cursor.tp_row == t->t_scrollreg.ts_end - 1) {
744186681Sed			/* Perform scrolling. */
745186681Sed			teken_subr_do_scroll(t, 1);
746186681Sed			tp.tp_row = t->t_scrollreg.ts_end - 1;
747186681Sed		} else {
748186681Sed			/* No scrolling needed. */
749186681Sed			tp.tp_row = t->t_cursor.tp_row + 1;
750186681Sed			if (tp.tp_row == t->t_winsize.tp_row) {
751186681Sed				/*
752186681Sed				 * Corner case: regular character
753186681Sed				 * outside scrolling region, but at the
754186681Sed				 * bottom of the screen.
755186681Sed				 */
756186681Sed				teken_subr_do_putchar(t, &t->t_cursor,
757186681Sed				    c, width);
758186681Sed				return;
759186681Sed			}
760186681Sed		}
761186681Sed
762186681Sed		tp.tp_col = 0;
763186681Sed		teken_subr_do_putchar(t, &tp, c, width);
764186681Sed
765186681Sed		t->t_cursor.tp_row = tp.tp_row;
766186681Sed		t->t_cursor.tp_col = width;
767186681Sed		t->t_stateflags &= ~TS_WRAPPED;
768186681Sed	} else {
769186681Sed		/* No line wrapping needed. */
770186681Sed		teken_subr_do_putchar(t, &t->t_cursor, c, width);
771186681Sed		t->t_cursor.tp_col += width;
772186681Sed
773186681Sed		if (t->t_cursor.tp_col >= t->t_winsize.tp_col) {
774186681Sed			t->t_stateflags |= TS_WRAPPED;
775186681Sed			t->t_cursor.tp_col = t->t_winsize.tp_col - 1;
776186681Sed		} else {
777186681Sed			t->t_stateflags &= ~TS_WRAPPED;
778186681Sed		}
779186681Sed	}
780186729Sed#endif /* TEKEN_CONS25 */
781186681Sed
782186681Sed	teken_funcs_cursor(t);
783186681Sed}
784186681Sed
785186681Sedstatic void
786186681Sedteken_subr_reset_dec_mode(teken_t *t, unsigned int cmd)
787186681Sed{
788186681Sed
789186681Sed	switch (cmd) {
790186681Sed	case 1: /* Cursor keys mode. */
791186681Sed		teken_funcs_param(t, TP_CURSORKEYS, 0);
792186681Sed		break;
793186681Sed	case 2: /* DECANM: ANSI/VT52 mode. */
794186681Sed		teken_printf("DECRST VT52\n");
795186681Sed		break;
796186681Sed	case 3: /* 132 column mode. */
797186681Sed		teken_funcs_param(t, TP_132COLS, 0);
798186681Sed		teken_subr_reset_to_initial_state(t);
799186681Sed		break;
800186681Sed	case 5: /* Inverse video. */
801186681Sed		teken_printf("DECRST inverse video\n");
802186681Sed		break;
803186681Sed	case 6: /* Origin mode. */
804186681Sed		t->t_stateflags &= ~TS_ORIGIN;
805186681Sed		t->t_originreg.ts_begin = 0;
806186681Sed		t->t_originreg.ts_end = t->t_winsize.tp_row;
807186681Sed		t->t_cursor.tp_row = t->t_cursor.tp_col = 0;
808186681Sed		t->t_stateflags &= ~TS_WRAPPED;
809186681Sed		teken_funcs_cursor(t);
810186681Sed		break;
811186681Sed	case 7: /* Autowrap mode. */
812186681Sed		t->t_stateflags &= ~TS_AUTOWRAP;
813186681Sed		break;
814186681Sed	case 8: /* Autorepeat mode. */
815186681Sed		teken_funcs_param(t, TP_AUTOREPEAT, 0);
816186681Sed		break;
817186681Sed	case 25: /* Hide cursor. */
818186681Sed		teken_funcs_param(t, TP_SHOWCURSOR, 0);
819186681Sed		break;
820186681Sed	case 40: /* Disallow 132 columns. */
821186681Sed		teken_printf("DECRST allow 132\n");
822186681Sed		break;
823186681Sed	case 45: /* Disable reverse wraparound. */
824186681Sed		teken_printf("DECRST reverse wraparound\n");
825186681Sed		break;
826186681Sed	case 47: /* Switch to alternate buffer. */
827186681Sed		teken_printf("Switch to alternate buffer\n");
828186681Sed		break;
829186681Sed	default:
830186681Sed		teken_printf("Unknown DECRST: %u\n", cmd);
831186681Sed	}
832186681Sed}
833186681Sed
834186681Sedstatic void
835186681Sedteken_subr_reset_mode(teken_t *t, unsigned int cmd)
836186681Sed{
837186681Sed
838186681Sed	switch (cmd) {
839186681Sed	case 4:
840186681Sed		t->t_stateflags &= ~TS_INSERT;
841186681Sed		break;
842186681Sed	default:
843186681Sed		teken_printf("Unknown reset mode: %u\n", cmd);
844186681Sed	}
845186681Sed}
846186681Sed
847186681Sedstatic void
848186681Sedteken_subr_do_reset(teken_t *t)
849186681Sed{
850186681Sed
851186681Sed	t->t_curattr = t->t_saved_curattr = t->t_defattr;
852186681Sed	t->t_cursor.tp_row = t->t_cursor.tp_col = 0;
853186681Sed	t->t_saved_cursor = t->t_cursor;
854186681Sed	t->t_stateflags = TS_AUTOWRAP;
855186681Sed
856186681Sed	teken_tab_default(t);
857186681Sed}
858186681Sed
859186681Sedstatic void
860186681Sedteken_subr_reset_to_initial_state(teken_t *t)
861186681Sed{
862186681Sed
863186681Sed	teken_subr_do_reset(t);
864186681Sed	teken_subr_erase_display(t, 2);
865186681Sed	teken_funcs_cursor(t);
866186681Sed}
867186681Sed
868186681Sedstatic void
869186681Sedteken_subr_restore_cursor(teken_t *t)
870186681Sed{
871186681Sed
872186681Sed	t->t_cursor = t->t_saved_cursor;
873186681Sed	t->t_curattr = t->t_saved_curattr;
874186681Sed	t->t_stateflags &= ~TS_WRAPPED;
875186681Sed	teken_funcs_cursor(t);
876186681Sed}
877186681Sed
878186681Sedstatic void
879186681Sedteken_subr_reverse_index(teken_t *t)
880186681Sed{
881186681Sed
882186681Sed	if (t->t_cursor.tp_row > t->t_scrollreg.ts_begin) {
883186681Sed		t->t_cursor.tp_row--;
884186681Sed		t->t_stateflags &= ~TS_WRAPPED;
885186681Sed		teken_funcs_cursor(t);
886186681Sed	} else {
887186681Sed		teken_subr_do_scroll(t, -1);
888186681Sed	}
889186681Sed}
890186681Sed
891186681Sedstatic void
892186681Sedteken_subr_save_cursor(teken_t *t)
893186681Sed{
894186681Sed
895186681Sed	t->t_saved_cursor = t->t_cursor;
896186681Sed	t->t_saved_curattr = t->t_curattr;
897186681Sed}
898186681Sed
899186681Sedstatic void
900186681Sedteken_subr_scs(teken_t *t __unused)
901186681Sed{
902186681Sed
903186681Sed	teken_printf("scs???\n");
904186681Sed}
905186681Sed
906186681Sedstatic void
907186681Sedteken_subr_secondary_device_attributes(teken_t *t, unsigned int request)
908186681Sed{
909186681Sed
910186681Sed	if (request == 0) {
911186681Sed		const char response[] = "\x1B[>0;10;0c";
912186681Sed		teken_funcs_respond(t, response, sizeof response - 1);
913186681Sed	} else {
914186681Sed		teken_printf("Unknown DA2\n");
915186681Sed	}
916186681Sed}
917186681Sed
918186681Sedstatic void
919186681Sedteken_subr_set_dec_mode(teken_t *t, unsigned int cmd)
920186681Sed{
921186681Sed
922186681Sed	switch (cmd) {
923186681Sed	case 1: /* Cursor keys mode. */
924186681Sed		teken_funcs_param(t, TP_CURSORKEYS, 1);
925186681Sed		break;
926186681Sed	case 2: /* DECANM: ANSI/VT52 mode. */
927186681Sed		teken_printf("DECSET VT52\n");
928186681Sed		break;
929186681Sed	case 3: /* 132 column mode. */
930186681Sed		teken_funcs_param(t, TP_132COLS, 1);
931186681Sed		teken_subr_reset_to_initial_state(t);
932186681Sed		break;
933186681Sed	case 5: /* Inverse video. */
934186681Sed		teken_printf("DECSET inverse video\n");
935186681Sed		break;
936186681Sed	case 6: /* Origin mode. */
937186681Sed		t->t_stateflags |= TS_ORIGIN;
938186681Sed		t->t_originreg = t->t_scrollreg;
939186681Sed		t->t_cursor.tp_row = t->t_scrollreg.ts_begin;
940186681Sed		t->t_cursor.tp_col = 0;
941186681Sed		t->t_stateflags &= ~TS_WRAPPED;
942186681Sed		teken_funcs_cursor(t);
943186681Sed		break;
944186681Sed	case 7: /* Autowrap mode. */
945186681Sed		t->t_stateflags |= TS_AUTOWRAP;
946186681Sed		break;
947186681Sed	case 8: /* Autorepeat mode. */
948186681Sed		teken_funcs_param(t, TP_AUTOREPEAT, 1);
949186681Sed		break;
950186681Sed	case 25: /* Display cursor. */
951186681Sed		teken_funcs_param(t, TP_SHOWCURSOR, 1);
952186681Sed		break;
953186681Sed	case 40: /* Allow 132 columns. */
954186681Sed		teken_printf("DECSET allow 132\n");
955186681Sed		break;
956186681Sed	case 45: /* Enable reverse wraparound. */
957186681Sed		teken_printf("DECSET reverse wraparound\n");
958186681Sed		break;
959186681Sed	case 47: /* Switch to alternate buffer. */
960186681Sed		teken_printf("Switch away from alternate buffer\n");
961186681Sed		break;
962186681Sed	default:
963186681Sed		teken_printf("Unknown DECSET: %u\n", cmd);
964186681Sed	}
965186681Sed}
966186681Sed
967186681Sedstatic void
968186681Sedteken_subr_set_mode(teken_t *t, unsigned int cmd)
969186681Sed{
970186681Sed
971186681Sed	switch (cmd) {
972186681Sed	case 4:
973186681Sed		teken_printf("Insert mode\n");
974186681Sed		t->t_stateflags |= TS_INSERT;
975186681Sed		break;
976186681Sed	default:
977186681Sed		teken_printf("Unknown set mode: %u\n", cmd);
978186681Sed	}
979186681Sed}
980186681Sed
981186681Sedstatic void
982186681Sedteken_subr_set_graphic_rendition(teken_t *t, unsigned int ncmds,
983186681Sed    unsigned int cmds[])
984186681Sed{
985186681Sed	unsigned int i, n;
986186681Sed
987186681Sed	/* No attributes means reset. */
988186681Sed	if (ncmds == 0) {
989186681Sed		t->t_curattr = t->t_defattr;
990186681Sed		return;
991186681Sed	}
992186681Sed
993186681Sed	for (i = 0; i < ncmds; i++) {
994186681Sed		n = cmds[i];
995186681Sed
996186681Sed		switch (n) {
997186681Sed		case 0: /* Reset. */
998186681Sed			t->t_curattr = t->t_defattr;
999186681Sed			break;
1000186681Sed		case 1: /* Bold. */
1001186681Sed			t->t_curattr.ta_format |= TF_BOLD;
1002186681Sed			break;
1003186681Sed		case 4: /* Underline. */
1004186681Sed			t->t_curattr.ta_format |= TF_UNDERLINE;
1005186681Sed			break;
1006186681Sed		case 5: /* Blink. */
1007186681Sed			t->t_curattr.ta_format |= TF_BLINK;
1008186681Sed			break;
1009186681Sed		case 7: /* Reverse. */
1010186681Sed			t->t_curattr.ta_format |= TF_REVERSE;
1011186681Sed			break;
1012186681Sed		case 22: /* Remove bold. */
1013186681Sed			t->t_curattr.ta_format &= ~TF_BOLD;
1014186681Sed			break;
1015186681Sed		case 24: /* Remove underline. */
1016186681Sed			t->t_curattr.ta_format &= ~TF_UNDERLINE;
1017186681Sed			break;
1018186681Sed		case 25: /* Remove blink. */
1019186681Sed			t->t_curattr.ta_format &= ~TF_BLINK;
1020186681Sed			break;
1021186681Sed		case 27: /* Remove reverse. */
1022186681Sed			t->t_curattr.ta_format &= ~TF_REVERSE;
1023186681Sed			break;
1024186681Sed		case 30: /* Set foreground color: black */
1025186681Sed		case 31: /* Set foreground color: red */
1026186681Sed		case 32: /* Set foreground color: green */
1027186681Sed		case 33: /* Set foreground color: brown */
1028186681Sed		case 34: /* Set foreground color: blue */
1029186681Sed		case 35: /* Set foreground color: magenta */
1030186681Sed		case 36: /* Set foreground color: cyan */
1031186681Sed		case 37: /* Set foreground color: white */
1032186681Sed			t->t_curattr.ta_fgcolor = n - 30;
1033186681Sed			break;
1034186681Sed		case 39: /* Set default foreground color. */
1035186681Sed			t->t_curattr.ta_fgcolor = t->t_defattr.ta_fgcolor;
1036186681Sed			break;
1037186681Sed		case 40: /* Set background color: black */
1038186681Sed		case 41: /* Set background color: red */
1039186681Sed		case 42: /* Set background color: green */
1040186681Sed		case 43: /* Set background color: brown */
1041186681Sed		case 44: /* Set background color: blue */
1042186681Sed		case 45: /* Set background color: magenta */
1043186681Sed		case 46: /* Set background color: cyan */
1044186681Sed		case 47: /* Set background color: white */
1045186681Sed			t->t_curattr.ta_bgcolor = n - 40;
1046186681Sed			break;
1047186681Sed		case 49: /* Set default background color. */
1048186681Sed			t->t_curattr.ta_bgcolor = t->t_defattr.ta_bgcolor;
1049186681Sed			break;
1050186681Sed		default:
1051186681Sed			teken_printf("unsupported attribute %u\n", n);
1052186681Sed		}
1053186681Sed	}
1054186681Sed}
1055186681Sed
1056186681Sedstatic void
1057186681Sedteken_subr_set_top_and_bottom_margins(teken_t *t, unsigned int top,
1058186681Sed    unsigned int bottom)
1059186681Sed{
1060186681Sed
1061186681Sed	/* Adjust top row number. */
1062186681Sed	if (top > 0)
1063186681Sed		top--;
1064186681Sed	/* Adjust bottom row number. */
1065186681Sed	if (bottom == 0 || bottom > t->t_winsize.tp_row)
1066186681Sed		bottom = t->t_winsize.tp_row;
1067186681Sed
1068186681Sed	/* Invalid arguments. */
1069186681Sed	if (top >= bottom - 1) {
1070186681Sed		top = 0;
1071186681Sed		bottom = t->t_winsize.tp_row;
1072186681Sed	}
1073186681Sed
1074186681Sed	t->t_scrollreg.ts_begin = top;
1075186681Sed	t->t_scrollreg.ts_end = bottom;
1076186681Sed	if (t->t_stateflags & TS_ORIGIN) {
1077186681Sed		/* XXX: home cursor? */
1078186681Sed		t->t_originreg = t->t_scrollreg;
1079186681Sed		t->t_cursor.tp_row = t->t_originreg.ts_begin;
1080186681Sed		t->t_cursor.tp_col = 0;
1081186681Sed		t->t_stateflags &= ~TS_WRAPPED;
1082186681Sed		teken_funcs_cursor(t);
1083186681Sed	}
1084186681Sed}
1085186681Sed
1086186681Sedstatic void
1087186681Sedteken_subr_single_height_double_width_line(teken_t *t __unused)
1088186681Sed{
1089186681Sed
1090186681Sed	teken_printf("single height double width???\n");
1091186681Sed}
1092186681Sed
1093186681Sedstatic void
1094186681Sedteken_subr_single_height_single_width_line(teken_t *t __unused)
1095186681Sed{
1096186681Sed
1097186681Sed	teken_printf("single height single width???\n");
1098186681Sed}
1099186681Sed
1100186681Sedstatic void
1101186681Sedteken_subr_string_terminator(teken_t *t __unused)
1102186681Sed{
1103186681Sed
1104186681Sed	teken_printf("string terminator???\n");
1105186681Sed}
1106186681Sed
1107186681Sedstatic void
1108186681Sedteken_subr_tab_clear(teken_t *t, unsigned int cmd)
1109186681Sed{
1110186681Sed
1111186681Sed	switch (cmd) {
1112186681Sed	case 0:
1113186681Sed		teken_tab_clear(t, t->t_cursor.tp_col);
1114186681Sed		break;
1115186681Sed	case 3:
1116186681Sed		memset(&t->t_tabstops, 0, T_NUMCOL / 8);
1117186681Sed		break;
1118186681Sed	}
1119186681Sed}
1120186681Sed
1121186681Sedstatic void
1122186681Sedteken_subr_vertical_position_absolute(teken_t *t, unsigned int row)
1123186681Sed{
1124186681Sed
1125186681Sed	t->t_cursor.tp_row = t->t_originreg.ts_begin + row - 1;
1126186681Sed	if (row >= t->t_originreg.ts_end)
1127186681Sed		t->t_cursor.tp_row = t->t_originreg.ts_end - 1;
1128186681Sed
1129186681Sed
1130186681Sed	t->t_stateflags &= ~TS_WRAPPED;
1131186681Sed	teken_funcs_cursor(t);
1132186681Sed}
1133