/*
* Copyright (c) 1988 University of Utah.
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Science Department.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: Utah Hdr: ite.c 1.1 90/07/09
* from: @(#)ite.c 7.6 (Berkeley) 5/16/91
*/
/*
* ite - bitmapped terminal.
* Supports VT200, a few terminal features will be unavailable until
* the system actually probes the device (i.e. not after consinit())
*/
/*
* Keep track of the device number of the ite console. Only used in the
* itematch/iteattach functions.
*/
static int cons_ite = -1;
static int
itematch(device_t parent, cfdata_t cf, void *aux)
{
/*
* Handle early console stuff. The first unit number
* is the console unit. All other early matches will fail.
*/
if (atari_realconfig == 0) {
if (cons_ite >= 0)
return 0;
cons_ite = cf->cf_unit;
return 1;
}
return 1;
}
static void
iteattach(device_t parent, device_t self, void *aux)
{
struct grf_softc *gsc;
struct ite_softc *sc;
int s;
int maj, unit;
iteinit(gsc->g_itedev);
aprint_normal(": %dx%d", sc->rows, sc->cols);
aprint_normal(" repeat at (%d/100)s next at (%d/100)s",
start_repeat_timeo, next_repeat_timeo);
if (kbd_ite == NULL)
kbd_ite = sc;
if (kbd_ite == sc)
aprint_normal(" has keyboard");
aprint_normal("\n");
sc->flags |= ITE_ATTACHED;
} else {
if (con_itesoftc.grf != NULL &&
con_itesoftc.grf->g_conpri > gsc->g_conpri)
return;
con_itesoftc.grf = gsc;
con_itesoftc.tabs = cons_tabs;
}
}
static struct ite_softc *
getitesp(dev_t dev)
{
if (atari_realconfig && (con_itesoftc.grf == NULL))
return(device_lookup_private(&ite_cd, ITEUNIT(dev)));
if (con_itesoftc.grf == NULL)
panic("no ite_softc for console");
return(&con_itesoftc);
}
/*
* cons.c entry points into ite device.
*/
/*
* Return a priority in consdev->cn_pri field highest wins. This function
* is called before any devices have been probed.
*/
void
itecnprobe(struct consdev *cd)
{
/*
* return priority of the best ite (already picked from attach)
* or CN_DEAD.
*/
if (con_itesoftc.grf == NULL)
cd->cn_pri = CN_DEAD;
else {
cd->cn_pri = con_itesoftc.grf->g_conpri;
cd->cn_dev = con_itesoftc.grf->g_itedev;
}
}
/*
* ite_cnfinish() is called in ite_init() when the device is
* being probed in the normal fashion, thus we can finish setting
* up this ite now that the system is more functional.
*/
void
ite_cnfinish(struct ite_softc *sc)
{
static int done;
if (done)
return;
done = 1;
}
int
itecngetc(dev_t dev)
{
int c;
do {
c = kbdgetcn();
c = ite_cnfilter(c, ITEFILT_CONSOLE);
} while (c == -1);
return (c);
}
void
itecnputc(dev_t dev, int c)
{
static int paniced;
struct ite_softc *sc;
char ch;
/*
* iteinit() is the standard entry point for initialization of
* an ite device, it is also called from itecninit().
*
*/
void
iteinit(dev_t dev)
{
struct ite_softc *sc;
/*
* has to be global because of the shared filters.
*/
static u_char last_dead;
/*
* Used in console at startup only and for DDB.
*/
int
ite_cnfilter(u_int c, enum caller caller)
{
struct key key;
struct kbdmap *kbdmap;
u_char code, up;
int s;
up = KBD_RELEASED(c);
c = KBD_SCANCODE(c);
code = 0;
kbdmap = (kbd_ite == NULL) ? &ascii_kbdmap : kbd_ite->kbdmap;
s = spltty();
/*
* No special action if key released
*/
if (up) {
splx(s);
return -1;
}
/* translate modifiers */
if (kbd_modifier & KBD_MOD_SHIFT) {
if (kbd_modifier & KBD_MOD_ALT)
key = kbdmap->alt_shift_keys[c];
else
key = kbdmap->shift_keys[c];
}
else if (kbd_modifier & KBD_MOD_ALT)
key = kbdmap->alt_keys[c];
else {
key = kbdmap->keys[c];
/*
* If CAPS and key is CAPable (no pun intended)
*/
if ((kbd_modifier & KBD_MOD_CAPS) && (key.mode & KBD_MODE_CAPS))
key = kbdmap->shift_keys[c];
}
code = key.code;
#ifdef notyet /* LWP: Didn't have time to look at this yet */
/*
* If string return simple console filter
*/
if (key->mode & (KBD_MODE_STRING | KBD_MODE_KPAD)) {
splx(s);
return -1;
}
/* handle dead keys */
if (key->mode & KBD_MODE_DEAD) {
/* if entered twice, send accent itself */
if (last_dead == (key->mode & KBD_MODE_ACCMASK))
last_dead = 0;
else {
last_dead = key->mode & KBD_MODE_ACCMASK;
splx(s);
return -1;
}
}
if (last_dead) {
/* can't apply dead flag to string-keys */
if (code >= '@' && code < 0x7f)
code =
acctable[KBD_MODE_ACCENT(last_dead)][code - '@'];
last_dead = 0;
}
#endif
if (kbd_modifier & KBD_MOD_CTRL)
code &= 0x1f;
if (!again) {
/* XXX */
callout_init(&repeat_ch, 0);
again = true;
}
if (kbd_ite == NULL)
return;
kbd_tty = kbd_ite->tp;
kbdmap = kbd_ite->kbdmap;
up = KBD_RELEASED(c);
c = KBD_SCANCODE(c);
code = 0;
/* have to make sure we're at spltty in here */
s = spltty();
/*
* keyboard interrupts come at priority 2, while softint
* generated keyboard-repeat interrupts come at level 1. So,
* to not allow a key-up event to get thru before a repeat for
* the key-down, we remove any outstanding callout requests..
*/
rem_sicallback((si_farg)ite_filter);
/*
* Stop repeating on up event
*/
if (up) {
if (tout_pending) {
callout_stop(&repeat_ch);
tout_pending = 0;
last_char = 0;
}
splx(s);
return;
}
else if (tout_pending && last_char != c) {
/*
* Different character, stop also
*/
callout_stop(&repeat_ch);
tout_pending = 0;
last_char = 0;
}
/*
* Handle ite-switching ALT + Fx
*/
if ((kbd_modifier == KBD_MOD_ALT) && (c >= 0x3b) && (c <= 0x44)) {
ite_switch(c - 0x3b);
splx(s);
return;
}
/*
* Safety button, switch back to ascii keymap.
*/
if (kbd_modifier == (KBD_MOD_ALT | KBD_MOD_LSHIFT) && c == 0x3b) {
/* ALT + LSHIFT + F1 */
memcpy(kbdmap, &ascii_kbdmap, sizeof(struct kbdmap));
splx(s);
return;
#ifdef DDB
} else if (kbd_modifier == (KBD_MOD_ALT | KBD_MOD_LSHIFT) &&
c == 0x43) {
/*
* ALT + LSHIFT + F9 -> Debugger!
*/
Debugger();
splx(s);
return;
#endif
}
/*
* The rest of the code is senseless when the device is not open.
*/
if (kbd_tty == NULL) {
splx(s);
return;
}
/*
* Translate modifiers
*/
if (kbd_modifier & KBD_MOD_SHIFT) {
if (kbd_modifier & KBD_MOD_ALT)
key = kbdmap->alt_shift_keys[c];
else
key = kbdmap->shift_keys[c];
}
else if (kbd_modifier & KBD_MOD_ALT)
key = kbdmap->alt_keys[c];
else {
key = kbdmap->keys[c];
/*
* If CAPS and key is CAPable (no pun intended)
*/
if ((kbd_modifier & KBD_MOD_CAPS) && (key.mode & KBD_MODE_CAPS))
key = kbdmap->shift_keys[c];
}
code = key.code;
/*
* Arrange to repeat the keystroke. By doing this at the level
* of scan-codes, we can have function keys, and keys that
* send strings, repeat too. This also entitles an additional
* overhead, since we have to do the conversion each time, but
* I guess that's ok.
*/
if (!tout_pending && caller == ITEFILT_TTY && kbd_ite->key_repeat) {
tout_pending = 1;
last_char = c;
callout_reset(&repeat_ch, start_repeat_timeo * hz / 100,
repeat_handler, NULL);
} else if (!tout_pending && caller==ITEFILT_REPEATER &&
kbd_ite->key_repeat) {
tout_pending = 1;
last_char = c;
callout_reset(&repeat_ch, next_repeat_timeo * hz / 100,
repeat_handler, NULL);
}
/* handle dead keys */
if (key.mode & KBD_MODE_DEAD) {
/* if entered twice, send accent itself */
if (last_dead == (key.mode & KBD_MODE_ACCMASK))
last_dead = 0;
else {
last_dead = key.mode & KBD_MODE_ACCMASK;
splx(s);
return;
}
}
if (last_dead) {
/* can't apply dead flag to string-keys */
if (!(key.mode & KBD_MODE_STRING) && code >= '@' &&
code < 0x7f)
code = acctable[KBD_MODE_ACCENT(last_dead)][code - '@'];
last_dead = 0;
}
/*
* If not string, apply CTRL modifiers
*/
if (!(key.mode & KBD_MODE_STRING) &&
(!(key.mode & KBD_MODE_KPAD) ||
(kbd_ite && !kbd_ite->keypad_appmode))) {
if (kbd_modifier & KBD_MOD_CTRL)
code &= 0x1f;
} else if ((key.mode & KBD_MODE_KPAD) &&
(kbd_ite && kbd_ite->keypad_appmode)) {
static const char * const in = "0123456789-+.\r()/*";
static const char * const out = "pqrstuvwxymlnMPQRS";
char *cp = strchr(in, code);
/*
* keypad-appmode sends SS3 followed by the above
* translated character
*/
kbd_tty->t_linesw->l_rint(27, kbd_tty);
kbd_tty->t_linesw->l_rint('O', kbd_tty);
kbd_tty->t_linesw->l_rint(out[cp - in], kbd_tty);
splx(s);
return;
} else {
/* *NO* I don't like this.... */
static u_char app_cursor[] =
{
3, 27, 'O', 'A',
3, 27, 'O', 'B',
3, 27, 'O', 'C',
3, 27, 'O', 'D'};
str = kbdmap->strings + code;
/*
* if this is a cursor key, AND it has the default
* keymap setting, AND we're in app-cursor mode, switch
* to the above table. This is *nasty* !
*/
if (((c == 0x48) || (c == 0x4b) ||(c == 0x4d) || (c == 0x50)) &&
kbd_ite->cursor_appmode &&
!memcmp(str, "\x03\x1b[", 3) &&
strchr("ABCD", str[3]))
str = app_cursor + 4 * (str[3] - 'A');
/*
* using a length-byte instead of 0-termination allows
* to embed \0 into strings, although this is not used
* in the default keymap
*/
for (i = *str++; i; i--)
kbd_tty->t_linesw->l_rint(*str++, kbd_tty);
splx(s);
return;
}
kbd_tty->t_linesw->l_rint(code, kbd_tty);
splx(s);
return;
}
/* helper functions, makes the code below more readable */
static inline void
ite_sendstr(const char *str)
{
struct tty *kbd_tty;
kbd_tty = kbd_ite->tp;
KDASSERT(kbd_tty);
while (*str)
kbd_tty->t_linesw->l_rint(*str++, kbd_tty);
}
static void
alignment_display(struct ite_softc *sc)
{
int i, j;
for (j = 0; j < sc->rows; j++)
for (i = 0; i < sc->cols; i++)
SUBR_PUTC(sc, 'E', j, i, ATTR_NOR);
attrclr(sc, 0, 0, sc->rows, sc->cols);
SUBR_CURSOR(sc, DRAW_CURSOR);
}
static inline void
ite_dnline(struct ite_softc *sc, int n)
{
/*
* interesting.. if the cursor is outside the scrolling
* region, this command is simply ignored..
*/
if (sc->cury < sc->top_margin || sc->cury > sc->bottom_margin)
return;
n = uimin(n, sc->bottom_margin + 1 - sc->cury);
if (n <= sc->bottom_margin - sc->cury) {
SUBR_SCROLL(sc, sc->cury + n, 0, n, SCROLL_UP);
attrmov(sc, sc->cury + n, 0, sc->cury, 0,
sc->bottom_margin + 1 - sc->cury - n, sc->cols);
}
SUBR_CLEAR(sc, sc->bottom_margin - n + 1, 0, n, sc->cols);
attrclr(sc, sc->bottom_margin - n + 1, 0, n, sc->cols);
SUBR_CURSOR(sc, DRAW_CURSOR);
}
static inline void
ite_inline(struct ite_softc *sc, int n)
{
/*
* interesting.. if the cursor is outside the scrolling
* region, this command is simply ignored..
*/
if (sc->cury < sc->top_margin || sc->cury > sc->bottom_margin)
return;
n = uimin(n, sc->bottom_margin + 1 - sc->cury);
if (n <= sc->bottom_margin - sc->cury) {
SUBR_SCROLL(sc, sc->cury, 0, n, SCROLL_DOWN);
attrmov(sc, sc->cury, 0, sc->cury + n, 0,
sc->bottom_margin + 1 - sc->cury - n, sc->cols);
}
SUBR_CLEAR(sc, sc->cury, 0, n, sc->cols);
attrclr(sc, sc->cury, 0, n, sc->cols);
SUBR_CURSOR(sc, DRAW_CURSOR);
}
if (sc->escape)
{
switch (sc->escape)
{
case ESC:
switch (c)
{
/* first 7bit equivalents for the 8bit control characters */
case 'D':
c = IND;
sc->escape = 0;
break; /* and fall into the next switch below (same for all `break') */
case 'E':
c = NEL;
sc->escape = 0;
break;
case 'H':
c = HTS;
sc->escape = 0;
break;
case 'M':
c = RI;
sc->escape = 0;
break;
case 'N':
c = SS2;
sc->escape = 0;
break;
case 'O':
c = SS3;
sc->escape = 0;
break;
case 'P':
c = DCS;
sc->escape = 0;
break;
case '[':
c = CSI;
sc->escape = 0;
break;
case '\\':
c = ST;
sc->escape = 0;
break;
case ']':
c = OSC;
sc->escape = 0;
break;
case '^':
c = PM;
sc->escape = 0;
break;
case '_':
c = APC;
sc->escape = 0;
break;
/* introduces 7/8bit control */
case ' ':
/* can be followed by either F or G */
sc->escape = ' ';
break;
/* a lot of character set selections, not yet used...
94-character sets: */
case '(': /* G0 */
case ')': /* G1 */
sc->escape = c;
return;
case '*': /* G2 */
case '+': /* G3 */
case 'B': /* ASCII */
case 'A': /* ISO latin 1 */
case '<': /* user preferred suplemental */
case '0': /* DEC special graphics */
/* 96-character sets: */
case '-': /* G1 */
case '.': /* G2 */
case '/': /* G3 */
/* national character sets: */
case '4': /* dutch */
case '5':
case 'C': /* finnish */
case 'R': /* french */
case 'Q': /* french canadian */
case 'K': /* german */
case 'Y': /* italian */
case '6': /* norwegian/danish */
/* note: %5 and %6 are not supported (two chars..) */
sc->escape = 0;
/* just ignore for now */
return;
/* locking shift modes (as you might guess, not yet supported..) */
case '`':
sc->GR = &sc->G1;
sc->escape = 0;
return;
case 'n':
sc->GL = &sc->G2;
sc->escape = 0;
return;
case '}':
sc->GR = &sc->G2;
sc->escape = 0;
return;
case 'o':
sc->GL = &sc->G3;
sc->escape = 0;
return;
case '|':
sc->GR = &sc->G3;
sc->escape = 0;
return;
case '~':
sc->GR = &sc->G1;
sc->escape = 0;
return;
/* font width/height control */
case '#':
sc->escape = '#';
return;
/* hard terminal reset .. */
case 'c':
ite_reset (sc);
SUBR_CURSOR(sc, MOVE_CURSOR);
sc->escape = 0;
return;
case CSI:
/* the biggie... */
switch (c)
{
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case ';': case '\"': case '$': case '>':
if (sc->ap < sc->argbuf + MAX_ARGSIZE)
*sc->ap++ = c;
return;
case BS:
/* you wouldn't believe such perversion is possible?
it is.. BS is allowed in between cursor sequences
(at least), according to vttest.. */
if (--sc->curx < 0)
sc->curx = 0;
else
SUBR_CURSOR(sc, MOVE_CURSOR);
break;
case 'c':
*sc->ap = 0;
if (sc->argbuf[0] == '>')
{
ite_sendstr ("\033[>24;0;0;0c");
}
else switch (ite_zargnum(sc))
{
case 0:
/* primary DA request, send primary DA response */
if (sc->emul_level == EMUL_VT100)
ite_sendstr ("\033[?1;1c");
else
ite_sendstr ("\033[?63;1c");
break;
}
sc->escape = 0;
return;
case 'n':
switch (ite_zargnum(sc))
{
case 5:
ite_sendstr ("\033[0n"); /* no malfunction */
break;
case 6:
/* cursor position report */
snprintf (sc->argbuf, sizeof(sc->argbuf), "\033[%d;%dR",
sc->cury + 1, sc->curx + 1);
ite_sendstr (sc->argbuf);
break;
}
sc->escape = 0;
return;
case 'x':
switch (ite_zargnum(sc))
{
case 0:
/* Fake some terminal parameters. */
ite_sendstr ("\033[2;1;1;112;112;1;0x");
break;
case 1:
ite_sendstr ("\033[3;1;1;112;112;1;0x");
break;
}
sc->escape = 0;
return;
case 'g':
switch (ite_zargnum(sc))
{
case 0:
if (sc->curx < sc->cols)
sc->tabs[sc->curx] = 0;
break;
case 3:
for (n = 0; n < sc->cols; n++)
sc->tabs[n] = 0;
break;
}
sc->escape = 0;
return;
case 'h': case 'l':
n = ite_zargnum (sc);
switch (n)
{
case 4:
sc->imode = (c == 'h'); /* insert/replace mode */
break;
case 20:
sc->linefeed_newline = (c == 'h');
break;
}
sc->escape = 0;
return;
case 'M':
ite_dnline (sc, ite_argnum (sc));
sc->escape = 0;
return;
case 'L':
ite_inline (sc, ite_argnum (sc));
sc->escape = 0;
return;
case 'P':
ite_dnchar (sc, ite_argnum (sc));
sc->escape = 0;
return;
case '@':
ite_inchar (sc, ite_argnum (sc));
sc->escape = 0;
return;
case 'G':
/* this one was *not* in my vt320 manual but in
a vt320 termcap entry.. who is right?
It's supposed to set the horizontal cursor position. */
*sc->ap = 0;
x = atoi (sc->argbuf);
if (x) x--;
sc->curx = uimin(x, sc->cols - 1);
sc->escape = 0;
SUBR_CURSOR(sc, MOVE_CURSOR);
clr_attr (sc, ATTR_INV);
return;
case 'd':
/* same thing here, this one's for setting the absolute
vertical cursor position. Not documented... */
*sc->ap = 0;
y = atoi (sc->argbuf);
if (y) y--;
if (sc->inside_margins)
y += sc->top_margin;
sc->cury = uimin(y, sc->rows - 1);
sc->escape = 0;
snap_cury(sc);
SUBR_CURSOR(sc, MOVE_CURSOR);
clr_attr (sc, ATTR_INV);
return;
case 'H':
case 'f':
*sc->ap = 0;
y = atoi (sc->argbuf);
x = 0;
cp = strchr(sc->argbuf, ';');
if (cp)
x = atoi (cp + 1);
if (x) x--;
if (y) y--;
if (sc->inside_margins)
y += sc->top_margin;
sc->cury = uimin(y, sc->rows - 1);
sc->curx = uimin(x, sc->cols - 1);
sc->escape = 0;
snap_cury(sc);
SUBR_CURSOR(sc, MOVE_CURSOR);
clr_attr (sc, ATTR_INV);
return;
case 'A':
n = ite_argnum (sc);
n = sc->cury - (n ? n : 1);
if (n < 0) n = 0;
if (sc->inside_margins)
n = uimax(sc->top_margin, n);
else if (n == sc->top_margin - 1)
/* allow scrolling outside region, but don't scroll out
of active region without explicit CUP */
n = sc->top_margin;
sc->cury = n;
sc->escape = 0;
SUBR_CURSOR(sc, MOVE_CURSOR);
clr_attr (sc, ATTR_INV);
return;
case 'B':
n = ite_argnum (sc);
n = sc->cury + (n ? n : 1);
n = uimin(sc->rows - 1, n);
if (sc->inside_margins)
n = uimin(sc->bottom_margin, n);
else if (n == sc->bottom_margin + 1)
/* allow scrolling outside region, but don't scroll out
of active region without explicit CUP */
n = sc->bottom_margin;
sc->cury = n;
sc->escape = 0;
SUBR_CURSOR(sc, MOVE_CURSOR);
clr_attr (sc, ATTR_INV);
return;
case 'C':
n = ite_argnum (sc);
n = n ? n : 1;
sc->curx = uimin(sc->curx + n, sc->cols - 1);
sc->escape = 0;
SUBR_CURSOR(sc, MOVE_CURSOR);
clr_attr (sc, ATTR_INV);
return;
case 'D':
n = ite_argnum (sc);
n = n ? n : 1;
n = sc->curx - n;
sc->curx = n >= 0 ? n : 0;
sc->escape = 0;
SUBR_CURSOR(sc, MOVE_CURSOR);
clr_attr (sc, ATTR_INV);
return;
case 'J':
*sc->ap = 0;
n = ite_zargnum (sc);
if (n == 0)
ite_clrtoeos(sc);
else if (n == 1)
ite_clrtobos(sc);
else if (n == 2)
ite_clrscreen(sc);
sc->escape = 0;
return;
case 'K':
n = ite_zargnum (sc);
if (n == 0)
ite_clrtoeol(sc);
else if (n == 1)
ite_clrtobol(sc);
else if (n == 2)
ite_clrline(sc);
sc->escape = 0;
return;
case 'X':
n = ite_argnum(sc) - 1;
n = uimin(n, sc->cols - 1 - sc->curx);
for (; n >= 0; n--)
{
attrclr(sc, sc->cury, sc->curx + n, 1, 1);
SUBR_PUTC(sc, ' ', sc->cury, sc->curx + n, ATTR_NOR);
}
sc->escape = 0;
return;
case '}': case '`':
/* status line control */
sc->escape = 0;
return;
case 'r':
*sc->ap = 0;
x = atoi (sc->argbuf);
x = x ? x : 1;
y = sc->rows;
cp = strchr(sc->argbuf, ';');
if (cp)
{
y = atoi (cp + 1);
y = y ? y : sc->rows;
}
if (y - x < 2)
{
/* if illegal scrolling region, reset to defaults */
x = 1;
y = sc->rows;
}
x--;
y--;
sc->top_margin = uimin(x, sc->rows - 1);
sc->bottom_margin = uimin(y, sc->rows - 1);
if (sc->inside_margins)
{
sc->cury = sc->top_margin;
sc->curx = 0;
SUBR_CURSOR(sc, MOVE_CURSOR);
}
sc->escape = 0;
return;
case 'm':
/* big attribute setter/resetter */
{
char *chp;
*sc->ap = 0;
/* kludge to make CSIm work (== CSI0m) */
if (sc->ap == sc->argbuf)
sc->ap++;
for (chp = sc->argbuf; chp < sc->ap; )
{
switch (*chp)
{
case 0:
case '0':
clr_attr (sc, ATTR_ALL);
chp++;
break;
case '1':
set_attr (sc, ATTR_BOLD);
chp++;
break;
case '2':
switch (chp[1])
{
case '2':
clr_attr (sc, ATTR_BOLD);
chp += 2;
break;
case '4':
clr_attr (sc, ATTR_UL);
chp += 2;
break;
case '5':
clr_attr (sc, ATTR_BLINK);
chp += 2;
break;
case '7':
clr_attr (sc, ATTR_INV);
chp += 2;
break;
default:
chp++;
break;
}
break;
case '4':
set_attr (sc, ATTR_UL);
chp++;
break;
case '5':
set_attr (sc, ATTR_BLINK);
chp++;
break;
case '?': /* CSI ? */
switch (c) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case ';': case '\"': case '$':
/* Don't fill the last character; it's needed. */
/* XXX yeah, where ?? */
if (sc->ap < sc->argbuf + MAX_ARGSIZE - 1)
*sc->ap++ = c;
return;
case 'n':
*sc->ap = 0;
if (sc->ap == &sc->argbuf[2])
{
if (! strncmp (sc->argbuf, "15", 2))
/* printer status: no printer */
ite_sendstr ("\033[13n");
else if (! strncmp (sc->argbuf, "25", 2))
/* udk status */
ite_sendstr ("\033[20n");
else if (! strncmp (sc->argbuf, "26", 2))
/* keyboard dialect: US */
ite_sendstr ("\033[27;1n");
}
sc->escape = 0;
return;
case 'h': case 'l':
n = ite_zargnum (sc);
switch (n)
{
case 1:
sc->cursor_appmode = (c == 'h');
break;
case 3:
/* 132/80 columns (132 == 'h') */
break;
case 4: /* smooth scroll */
break;
case 5:
/* light background (=='h') /dark background(=='l') */
break;
case VT: /* VT is treated like LF */
case FF: /* so is FF */
case LF:
/* cr->crlf distinction is done here, on output,
not on input! */
if (sc->linefeed_newline)
ite_crlf (sc);
else
ite_lf (sc);
break;
case CR:
ite_cr (sc);
break;
case BS:
if (--sc->curx < 0)
sc->curx = 0;
else
SUBR_CURSOR(sc, MOVE_CURSOR);
break;
case HT:
for (n = sc->curx + 1; n < sc->cols; n++) {
if (sc->tabs[n]) {
sc->curx = n;
SUBR_CURSOR(sc, MOVE_CURSOR);
break;
}
}
break;
case BEL:
if (kbd_tty && kbd_ite && kbd_ite->tp == kbd_tty)
kbdbell();
break;
case SO:
sc->GL = &sc->G1;
break;
case SI:
sc->GL = &sc->G0;
break;
case ENQ:
/* send answer-back message !! */
break;
case CAN:
sc->escape = 0; /* cancel any escape sequence in progress */
break;
case SUB:
sc->escape = 0; /* dito, but see below */
/* should also display a reverse question mark!! */
break;
case ESC:
sc->escape = ESC;
break;
/* now it gets weird.. 8bit control sequences.. */
case IND: /* index: move cursor down, scroll */
ite_lf (sc);
break;
case NEL: /* next line. next line, first pos. */
ite_crlf (sc);
break;
case HTS: /* set horizontal tab */
if (sc->curx < sc->cols)
sc->tabs[sc->curx] = 1;
break;
case RI: /* reverse index */
ite_rlf (sc);
break;
case SS2: /* go into G2 for one character */
/* not yet supported */
break;
case SS3: /* go into G3 for one character */
break;
case DCS: /* device control string introducer */
sc->escape = DCS;
sc->ap = sc->argbuf;
break;
case CSI: /* control sequence introducer */
sc->escape = CSI;
sc->ap = sc->argbuf;
break;
case ST: /* string terminator */
/* ignore, if not used as terminator */
break;
case OSC: /* introduces OS command. Ignore everything upto ST */
sc->escape = OSC;
break;
case PM: /* privacy message, ignore everything upto ST */
sc->escape = PM;
break;
case APC: /* application program command, ignore everything upto ST */
sc->escape = APC;
break;