From 4cd3114c5013aeccd790582f6cd1dd2760be9dd0 Mon Sep 17 00:00:00 2001 From: james <> Date: Fri, 7 Mar 2008 12:37:04 +0000 Subject: *** empty log message *** --- src/ansi.c | 739 +++++++--------- src/ansi.h | 11 +- src/cmd.c | 72 +- src/cmd.h | 13 +- src/context.h | 9 +- src/crt.c | 43 +- src/crt.h | 12 +- src/history.c | 16 +- src/history.h | 9 +- src/html.c | 105 +-- src/ipc.c | 85 +- src/ipc.h | 9 +- src/keydis.c | 7 +- src/keydis.h | 9 +- src/keys.h | 143 +-- src/libsympathy.c | 7 +- src/lockfile.c | 239 +++-- src/lockfile.h | 9 +- src/log.c | 80 +- src/log.h | 9 +- src/project.h | 9 +- src/ptty.c | 78 +- src/raw.c | 51 +- src/render.c | 7 +- src/ring.c | 33 +- src/ring.h | 9 +- src/rotate.c | 39 +- src/rx.h | 9 +- src/serial.c | 67 +- src/slide.c | 18 +- src/slide.h | 9 +- src/symsocket.c | 104 ++- src/symsocket.h | 9 +- src/terminal.c | 88 +- src/tty.c | 387 ++++---- src/tty.h | 9 +- src/utf8.c | 193 ++-- src/utf8.h | 9 +- src/util.c | 7 +- src/version.c | 7 +- src/vt102.c | 2433 ++++++++++++++++++++++++--------------------------- src/vt102.h | 9 +- src/vt102_charset.c | 15 +- src/vt102_charset.h | 9 +- 44 files changed, 2518 insertions(+), 2716 deletions(-) diff --git a/src/ansi.c b/src/ansi.c index e1aaeee..a70a51d 100644 --- a/src/ansi.c +++ b/src/ansi.c @@ -1,4 +1,4 @@ -/* +/* * ansi.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.49 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.48 2008/03/06 22:51:39 james * *** empty log message *** * @@ -167,96 +170,67 @@ ansi_move (ANSI * a, CRT_Pos p) int dy = p.y - a->pos.y; int err = 0; -// a->pos.x = ANSI_INVAL; + // a->pos.x = ANSI_INVAL; - if (a->pos.x != ANSI_INVAL) - { + if (a->pos.x != ANSI_INVAL) { - if ((!dx) && (!dy)) - return 0; - - if (!dy) - { - if (dx == 1) - { - if (a->terminal->xmit (a->terminal, "\033[C", 3) != 3) - err++; - } - else if (dx == -1) - { - if (a->terminal->xmit (a->terminal, "\033[D", 3) != 3) - err++; - } - else - { - n = snprintf (buf, sizeof (buf), "\033[%dG", p.x + 1); - if (a->terminal->xmit (a->terminal, buf, n) != n) - err++; - } - } - else if (!dx) - { - if (dy == -1) - { - if (a->terminal->xmit (a->terminal, "\033[A", 3) != 3) - err++; - } - else if (dy == 1) - { - if (a->terminal->xmit (a->terminal, "\033[B", 3) != 3) - err++; - } - else if (dy < 0) - { - n = snprintf (buf, sizeof (buf), "\033[%dA", -dy); - if (a->terminal->xmit (a->terminal, buf, n) != n) - err++; - } - else - { - n = snprintf (buf, sizeof (buf), "\033[%dB", dy); - if (a->terminal->xmit (a->terminal, buf, n) != n) - err++; - } - } - else if (!p.x) - { - if (dy == 1) - { - if (a->terminal->xmit (a->terminal, "\033[E", 3) != 3) - err++; - } - else if (dy == -1) - { - if (a->terminal->xmit (a->terminal, "\033[F", 3) != 3) - err++; - } - else if (dy > 0) - { - n = snprintf (buf, sizeof (buf), "\033[%dE", dy); - if (a->terminal->xmit (a->terminal, buf, n) != n) - err++; - } - else - { - n = snprintf (buf, sizeof (buf), "\033[%dF", -dy); - if (a->terminal->xmit (a->terminal, buf, n) != n) - err++; - } - } - else - { - n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1); - if (a->terminal->xmit (a->terminal, buf, n) != n) - err++; - } - } - else - { + if ((!dx) && (!dy)) + return 0; + + if (!dy) { + if (dx == 1) { + if (a->terminal->xmit (a->terminal, "\033[C", 3) != 3) + err++; + } else if (dx == -1) { + if (a->terminal->xmit (a->terminal, "\033[D", 3) != 3) + err++; + } else { + n = snprintf (buf, sizeof (buf), "\033[%dG", p.x + 1); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; + } + } else if (!dx) { + if (dy == -1) { + if (a->terminal->xmit (a->terminal, "\033[A", 3) != 3) + err++; + } else if (dy == 1) { + if (a->terminal->xmit (a->terminal, "\033[B", 3) != 3) + err++; + } else if (dy < 0) { + n = snprintf (buf, sizeof (buf), "\033[%dA", -dy); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; + } else { + n = snprintf (buf, sizeof (buf), "\033[%dB", dy); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; + } + } else if (!p.x) { + if (dy == 1) { + if (a->terminal->xmit (a->terminal, "\033[E", 3) != 3) + err++; + } else if (dy == -1) { + if (a->terminal->xmit (a->terminal, "\033[F", 3) != 3) + err++; + } else if (dy > 0) { + n = snprintf (buf, sizeof (buf), "\033[%dE", dy); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; + } else { + n = snprintf (buf, sizeof (buf), "\033[%dF", -dy); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; + } + } else { n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1); if (a->terminal->xmit (a->terminal, buf, n) != n) err++; } + } else { + n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1); + if (a->terminal->xmit (a->terminal, buf, n) != n) + err++; + } a->pos = p; @@ -271,16 +245,13 @@ ansi_showhide_cursor (ANSI * a, int hide) if (a->hide_cursor == hide) return err; - if (hide) - { - if (a->terminal->xmit (a->terminal, "\033[?25l", 6) != 6) - err++; - } - else - { - if (a->terminal->xmit (a->terminal, "\033[?25h", 6) != 6) - err++; - } + if (hide) { + if (a->terminal->xmit (a->terminal, "\033[?25l", 6) != 6) + err++; + } else { + if (a->terminal->xmit (a->terminal, "\033[?25h", 6) != 6) + err++; + } a->hide_cursor = hide; return err; @@ -329,23 +300,17 @@ ansi_set_color (ANSI * a, int color) fg = CRT_COLOR_FG (color); bg = CRT_COLOR_BG (color); - if (fg & CRT_COLOR_INTENSITY) - { - fg += 90; - } - else - { - fg += 30; - } + if (fg & CRT_COLOR_INTENSITY) { + fg += 90; + } else { + fg += 30; + } - if (bg & CRT_COLOR_INTENSITY) - { - bg += 100; - } - else - { - bg += 40; - } + if (bg & CRT_COLOR_INTENSITY) { + bg += 100; + } else { + bg += 40; + } i = sprintf (buf, "\033[%d;%dm", fg, bg); #if 0 @@ -373,54 +338,41 @@ ansi_set_attr (ANSI * a, int attr) a->attr = attr; #if 0 - if (attr == CRT_ATTR_NORMAL) - { - ansi_force_attr_normal (a); - return; - } + if (attr == CRT_ATTR_NORMAL) { + ansi_force_attr_normal (a); + return; + } #endif - if (dif & CRT_ATTR_UNDERLINE) - { - if (attr & CRT_ATTR_UNDERLINE) - { - if (a->terminal->xmit (a->terminal, "\033[4m", 4)!=4) - err++; - } - else - { - if (a->terminal->xmit (a->terminal, "\033[24m", 5)!=5) - err++; - } + if (dif & CRT_ATTR_UNDERLINE) { + if (attr & CRT_ATTR_UNDERLINE) { + if (a->terminal->xmit (a->terminal, "\033[4m", 4) != 4) + err++; + } else { + if (a->terminal->xmit (a->terminal, "\033[24m", 5) != 5) + err++; } - if (dif & CRT_ATTR_REVERSE) - { - if (attr & CRT_ATTR_REVERSE) - { - if (a->terminal->xmit (a->terminal, "\033[7m", 4)!=4) - err++; - } - else - { - if (a->terminal->xmit (a->terminal, "\033[27m", 5)!=5) - err++; - } + } + if (dif & CRT_ATTR_REVERSE) { + if (attr & CRT_ATTR_REVERSE) { + if (a->terminal->xmit (a->terminal, "\033[7m", 4) != 4) + err++; + } else { + if (a->terminal->xmit (a->terminal, "\033[27m", 5) != 5) + err++; } - if (dif & CRT_ATTR_BOLD) - { - if (attr & CRT_ATTR_BOLD) - { - if (a->terminal->xmit (a->terminal, "\033[1m", 4)!=4) - err++; - } - else - { - if (a->terminal->xmit (a->terminal, "\033[21m", 5)!=5) - err++; - if (a->terminal->xmit (a->terminal, "\033[22m", 5)!=5) - err++; - } + } + if (dif & CRT_ATTR_BOLD) { + if (attr & CRT_ATTR_BOLD) { + if (a->terminal->xmit (a->terminal, "\033[1m", 4) != 4) + err++; + } else { + if (a->terminal->xmit (a->terminal, "\033[21m", 5) != 5) + err++; + if (a->terminal->xmit (a->terminal, "\033[22m", 5) != 5) + err++; } + } return err; } @@ -430,36 +382,32 @@ ascii_emit (TTY * t, uint32_t ch) { int i; -/*Some quick obvious subsititons for quotation marks*/ - switch (ch) - { - case 0x2018: - ch = '`'; - break; - case 0x2019: - ch = '\''; - break; - case 0x201c: - case 0x201d: - ch = '"'; - break; - } - -/*Short cut the easy stuff*/ - if (ch < 0x7f) - { - uint8_t c = ch; - return (t->xmit (t, &c, 1) == 1) ? 0 : -1; - } - - for (i = 0; i < VT102_CHARSET_SIZE; ++i) - { - if (vt102_charset_gl[i] == ch) - { - uint8_t c[3] = { 016, i, 017 }; - return (t->xmit (t, &c, 3) == 3) ? 0 : -1; - } - } + /* Some quick obvious subsititons for quotation marks */ + switch (ch) { + case 0x2018: + ch = '`'; + break; + case 0x2019: + ch = '\''; + break; + case 0x201c: + case 0x201d: + ch = '"'; + break; + } + + /* Short cut the easy stuff */ + if (ch < 0x7f) { + uint8_t c = ch; + return (t->xmit (t, &c, 1) == 1) ? 0 : -1; + } + + for (i = 0; i < VT102_CHARSET_SIZE; ++i) { + if (vt102_charset_gl[i] == ch) { + uint8_t c[3] = { 016, i, 017 }; + return (t->xmit (t, &c, 3) == 3) ? 0 : -1; + } + } return (t->xmit (t, "?", 1) == 1) ? 0 : -1; @@ -480,21 +428,18 @@ ansi_render (ANSI * a, CRT_CA ca) ansi_set_attr (a, ca.attr); ansi_set_color (a, ca.color); - if (a->utf8) - { - if (utf8_emit (a->terminal, ca.chr)) - err++; - } - else - { - if (ascii_emit (a->terminal, ca.chr)) - err++; - } + if (a->utf8) { + if (utf8_emit (a->terminal, ca.chr)) + err++; + } else { + if (ascii_emit (a->terminal, ca.chr)) + err++; + } a->pos.x++; -/*Can't easily wrap round here as don't know size of destination screen*/ -/*so invalidate the cached cursor position*/ + /* Can't easily wrap round here as don't know size of destination screen */ + /* so invalidate the cached cursor position */ if (a->pos.x >= a->size.x) a->pos.x = ANSI_INVAL; @@ -515,7 +460,8 @@ ansi_cls (ANSI * a) err += ansi_move (a, p); if (a->terminal->xmit (a->terminal, "\033[2J", 4) != 4) err++; -/*different emulators leave cursor in different places after cls differently*/ + /* different emulators leave cursor in different places after cls + differently */ a->pos.x = ANSI_INVAL; return err; @@ -529,25 +475,23 @@ ansi_draw_line (ANSI * a, CRT_CA * cap, int y) CRT_Pos p = { 0, y }; CRT_CA *acap = &a->crt.screen[CRT_ADDR_POS (&p)]; - for (p.x = 0; p.x < a->crt.size.x; ++p.x) - { - if (p.x >= a->size.x) - continue; - - if (crt_ca_cmp (*acap, *cap)) - { - err += ansi_showhide_cursor (a, 1); + for (p.x = 0; p.x < a->crt.size.x; ++p.x) { + if (p.x >= a->size.x) + continue; - *acap = *cap; + if (crt_ca_cmp (*acap, *cap)) { + err += ansi_showhide_cursor (a, 1); - err += ansi_move (a, p); - err += ansi_render (a, *acap); - } + *acap = *cap; - acap++; - cap++; + err += ansi_move (a, p); + err += ansi_render (a, *acap); } + acap++; + cap++; + } + return err; } @@ -557,49 +501,45 @@ ansi_resize_check (ANSI * a, CRT_Pos * size) int err = 0; if ((size && crt_pos_cmp (a->crt.size, *size)) - || crt_pos_cmp (a->terminal->size, a->size)) - { + || crt_pos_cmp (a->terminal->size, a->size)) { - terminal_getsize (a->terminal); + terminal_getsize (a->terminal); - a->size = a->terminal->size; + a->size = a->terminal->size; - a->pos.x = ANSI_INVAL; - a->hide_cursor = ANSI_INVAL; + a->pos.x = ANSI_INVAL; + a->hide_cursor = ANSI_INVAL; - crt_reset (&a->crt); + crt_reset (&a->crt); - if (size) - a->crt.size = *size; + if (size) + a->crt.size = *size; -// FIXME: -- echos back crap? -// a->terminal->xmit (a->terminal, "\033[c", 3); + // FIXME: -- echos back crap? + // a->terminal->xmit (a->terminal, "\033[c", 3); -// maybe - issue 132 column command if we're 132? + // maybe - issue 132 column command if we're 132? - ansi_cls (a); - if (a->terminal->xmit (a->terminal, "\033=", 2) != 2) + ansi_cls (a); + if (a->terminal->xmit (a->terminal, "\033=", 2) != 2) + err++; + if (a->terminal->xmit (a->terminal, "\033[?6l", 5) != 5) + err++; + if (a->terminal->xmit (a->terminal, "\033[r", 3) != 3) + err++; + if (a->utf8) { + if (a->terminal->xmit (a->terminal, "\033%G", 3) != 3) err++; - if (a->terminal->xmit (a->terminal, "\033[?6l", 5) != 5) + } else { + if (a->terminal->xmit (a->terminal, "\033(B", 3) != 3) err++; - if (a->terminal->xmit (a->terminal, "\033[r", 3) != 3) + if (a->terminal->xmit (a->terminal, "\033)0", 3) != 3) + err++; + if (a->terminal->xmit (a->terminal, "\017", 1) != 3) err++; - if (a->utf8) - { - if (a->terminal->xmit (a->terminal, "\033%G", 3) != 3) - err++; - } - else - { - if (a->terminal->xmit (a->terminal, "\033(B", 3) != 3) - err++; - if (a->terminal->xmit (a->terminal, "\033)0", 3) != 3) - err++; - if (a->terminal->xmit (a->terminal, "\017", 1) != 3) - err++; - } - } + + } return err; } @@ -611,7 +551,7 @@ ansi_history (ANSI * a, History * h) int i; int guess_scroll; int err = 0; -/*Do we need to catch up on history?*/ + /* Do we need to catch up on history? */ if (a->history_ptr == h->wptr) return err; @@ -621,7 +561,7 @@ ansi_history (ANSI * a, History * h) if ((a->size.x < a->crt.size.x) || (a->size.y < a->crt.size.y)) return err; - guess_scroll = a->crt.size.y - 1; /*Bototm line should be a status line */ + guess_scroll = a->crt.size.y - 1; /* Bototm line should be a status line */ err += ansi_force_attr_normal (a); @@ -632,61 +572,59 @@ ansi_history (ANSI * a, History * h) err++; - while (a->history_ptr != h->wptr) - { - - History_ent *e = &h->lines[a->history_ptr]; + while (a->history_ptr != h->wptr) { - HISTORY_INC (h, a->history_ptr); + History_ent *e = &h->lines[a->history_ptr]; - if (!e->valid) - continue; + HISTORY_INC (h, a->history_ptr); - /*If so write the line ot the top of the screen */ - err += ansi_draw_line (a, e->line, 0); + if (!e->valid) + continue; + /* If so write the line ot the top of the screen */ + err += ansi_draw_line (a, e->line, 0); - /*Roll guess_scroll lines up putting the top line into the xterm's history */ + /* Roll guess_scroll lines up putting the top line into the xterm's + history */ - /*Make extra lines a predictable colour */ - err += ansi_set_color (a, CRT_COLOR_NORMAL); - err += ansi_showhide_cursor (a, 1); + /* Make extra lines a predictable colour */ + err += ansi_set_color (a, CRT_COLOR_NORMAL); - i = sprintf (buf, "\033[%d;%dH", guess_scroll, 1); - if (a->terminal->xmit (a->terminal, buf, i) != i) - err++; + err += ansi_showhide_cursor (a, 1); - if (a->terminal->xmit (a->terminal, "\033D", 2) != 2) - err++; + i = sprintf (buf, "\033[%d;%dH", guess_scroll, 1); + if (a->terminal->xmit (a->terminal, buf, i) != i) + err++; - a->pos.x = ANSI_INVAL; + if (a->terminal->xmit (a->terminal, "\033D", 2) != 2) + err++; - /*now do the same in our image of the screen */ + a->pos.x = ANSI_INVAL; - { - CRT_Pos s = { 0 } - , e = - { - 0}; + /* now do the same in our image of the screen */ - /*scroll lines up */ - for (s.y++; s.y < guess_scroll; s.y++, e.y++) - { - memcpy (&a->crt.screen[CRT_ADDR_POS (&e)], - &a->crt.screen[CRT_ADDR_POS (&s)], - sizeof (CRT_CA) * a->crt.size.x); - } + { + CRT_Pos s = { 0 } + , e = { + 0}; - /* erase new line */ - s.y = e.y; - e.x = CRT_COLS - 1; - crt_erase (&a->crt, s, e, 1, CRT_COLOR_NORMAL); + /* scroll lines up */ + for (s.y++; s.y < guess_scroll; s.y++, e.y++) { + memcpy (&a->crt.screen[CRT_ADDR_POS (&e)], + &a->crt.screen[CRT_ADDR_POS (&s)], + sizeof (CRT_CA) * a->crt.size.x); } + /* erase new line */ + s.y = e.y; + e.x = CRT_COLS - 1; + crt_erase (&a->crt, s, e, 1, CRT_COLOR_NORMAL); } -/*reset margins*/ + + } + /* reset margins */ if (a->terminal->xmit (a->terminal, "\033[r", 3) != 3) err++; @@ -709,45 +647,42 @@ ansi_draw (ANSI * a, CRT * c) err += ansi_resize_check (a, &c->size); - for (p.y = 0; p.y < a->crt.size.y; ++p.y) - { - if (p.y >= a->size.y) - continue; + for (p.y = 0; p.y < a->crt.size.y; ++p.y) { + if (p.y >= a->size.y) + continue; - err += ansi_draw_line (a, &c->screen[CRT_ADDR (p.y, 0)], p.y); + err += ansi_draw_line (a, &c->screen[CRT_ADDR (p.y, 0)], p.y); - } + } - if ((c->size.x > a->size.x) || (c->size.y > a->size.y)) - { - char msg[1024]; // = "Window is too small"; - int i; - p.x = 0; - p.y = 0; + if ((c->size.x > a->size.x) || (c->size.y > a->size.y)) { + char msg[1024]; // = "Window is too small"; + int i; + p.x = 0; + p.y = 0; - i = - sprintf (msg, "Window too small (%dx%d need %dx%d)", a->size.x, - a->size.y, c->size.x, c->size.y); + i = + sprintf (msg, "Window too small (%dx%d need %dx%d)", a->size.x, + a->size.y, c->size.x, c->size.y); - err += ansi_showhide_cursor (a, 1); - err += ansi_set_attr (a, CRT_ATTR_REVERSE); - err += - ansi_set_color (a, CRT_MAKE_COLOR (CRT_COLOR_WHITE, CRT_COLOR_RED)); - err += ansi_move (a, p); + err += ansi_showhide_cursor (a, 1); + err += ansi_set_attr (a, CRT_ATTR_REVERSE); + err += + ansi_set_color (a, CRT_MAKE_COLOR (CRT_COLOR_WHITE, CRT_COLOR_RED)); + err += ansi_move (a, p); - if (a->terminal->xmit (a->terminal, msg, i) != i) - err++; + if (a->terminal->xmit (a->terminal, msg, i) != i) + err++; - a->pos.x = ANSI_INVAL; - } + a->pos.x = ANSI_INVAL; + } - if ((c->pos.x >= a->size.x) || (c->pos.y >= a->size.y)) - { - err += ansi_showhide_cursor (a, 1); - return err; - } + if ((c->pos.x >= a->size.x) || (c->pos.y >= a->size.y)) { + err += ansi_showhide_cursor (a, 1); + return err; + } a->crt.pos = c->pos; err += ansi_move (a, a->crt.pos); @@ -783,25 +718,17 @@ ansi_key (ANSI * a, Context * c, int key) cmd_show_status (c->d, c); - if (c->d->active) - { - if (key == CMD_CANCEL_KEY) - { - return cmd_deactivate (c->d, c); - } - else if (key == CMD_KEY) - { - cmd_deactivate (c->d, c); - } - else - { - return cmd_key (c->d, c, a, key); - } - } - else if (key == CMD_KEY) - { - return cmd_activate (c->d, c); + if (c->d->active) { + if (key == CMD_CANCEL_KEY) { + return cmd_deactivate (c->d, c); + } else if (key == CMD_KEY) { + cmd_deactivate (c->d, c); + } else { + return cmd_key (c->d, c, a, key); } + } else if (key == CMD_KEY) { + return cmd_activate (c->d, c); + } return c->k->key (c->k, c, key); } @@ -813,10 +740,9 @@ ansi_flush_escape (ANSI * a, Context * c) ANSI_Parser *p = &a->parser; int i; - for (i = 0; i < p->escape_ptr; ++i) - { - ansi_key (a, c, p->escape_buf[i]); - } + for (i = 0; i < p->escape_ptr; ++i) { + ansi_key (a, c, p->escape_buf[i]); + } p->escape_ptr = 0; p->in_escape = 0; @@ -826,25 +752,19 @@ static void ansi_parse_deckey (ANSI * a, Context * c) { ANSI_Parser *p = &a->parser; - if ((p->escape_buf[1] != '[') && (p->escape_buf[1] != 'O')) - { - ansi_flush_escape (a, c); - return; - } + if ((p->escape_buf[1] != '[') && (p->escape_buf[1] != 'O')) { + ansi_flush_escape (a, c); + return; + } - if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z')) - { - ansi_key (a, c, KEY_UP + (p->escape_buf[2] - 'A')); - } - else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z')) - { - ansi_key (a, c, KEY_154 + (p->escape_buf[2] - 'a')); - } - else - { - ansi_flush_escape (a, c); - return; - } + if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z')) { + ansi_key (a, c, KEY_UP + (p->escape_buf[2] - 'A')); + } else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z')) { + ansi_key (a, c, KEY_154 + (p->escape_buf[2] - 'a')); + } else { + ansi_flush_escape (a, c); + return; + } p->in_escape = 0; p->escape_ptr = 0; } @@ -857,19 +777,17 @@ ansi_parse_ansikey (ANSI * a, Context * c) char *end; int k; - if ((p->escape_buf[1] != '[') || (p->escape_buf[l] != '~')) - { - ansi_flush_escape (a, c); - return; - } + if ((p->escape_buf[1] != '[') || (p->escape_buf[l] != '~')) { + ansi_flush_escape (a, c); + return; + } k = strtol (&p->escape_buf[2], &end, 10); - if (end != &p->escape_buf[l]) - { - ansi_flush_escape (a, c); - return; - } + if (end != &p->escape_buf[l]) { + ansi_flush_escape (a, c); + return; + } ansi_key (a, c, KEY_180 + k); @@ -883,45 +801,42 @@ static void ansi_parse_escape (ANSI * a, Context * c) { ANSI_Parser *p = &a->parser; - switch (p->escape_ptr) - { - case 0: - case 1: - return; - case 2: - switch (p->escape_buf[1]) - { - case '[': - case 'O': - break; - default: - ansi_flush_escape (a, c); - } + switch (p->escape_ptr) { + case 0: + case 1: + return; + case 2: + switch (p->escape_buf[1]) { + case '[': + case 'O': break; - case 3: - switch (p->escape_buf[1]) - { - case 'O': - ansi_parse_deckey (a, c); - break; - case '[': - if ((p->escape_buf[2] >= 'A') && (p->escape_buf[2] <= 'Z')) - ansi_parse_deckey (a, c); - break; - default: - ansi_flush_escape (a, c); - } + default: + ansi_flush_escape (a, c); + } + break; + case 3: + switch (p->escape_buf[1]) { + case 'O': + ansi_parse_deckey (a, c); break; - case 4: - case 5: - case 6: - case 7: - if (p->escape_buf[p->escape_ptr - 1] == '~') - ansi_parse_ansikey (a, c); + case '[': + if ((p->escape_buf[2] >= 'A') && (p->escape_buf[2] <= 'Z')) + ansi_parse_deckey (a, c); break; default: ansi_flush_escape (a, c); } + break; + case 4: + case 5: + case 6: + case 7: + if (p->escape_buf[p->escape_ptr - 1] == '~') + ansi_parse_ansikey (a, c); + break; + default: + ansi_flush_escape (a, c); + } } @@ -942,7 +857,7 @@ ansi_check_escape (ANSI * a, Context * c) return; - /*Time up? */ + /* Time up? */ if (diff.tv_sec || (diff.tv_usec > ANSI_ESCAPE_TIMEOUT)) ansi_flush_escape (a, c); @@ -955,28 +870,24 @@ ansi_parse_char (ANSI * a, Context * c, int ch) ANSI_Parser *p = &a->parser; -/*See if it's time to flush the escape*/ + /* See if it's time to flush the escape */ ansi_check_escape (a, c); - if (ch == 033) - { - if (p->in_escape) - ansi_flush_escape (a, c); - - p->in_escape++; - p->escape_ptr = 0; - gettimeofday (&p->last_escape, NULL); - } + if (ch == 033) { + if (p->in_escape) + ansi_flush_escape (a, c); - if (p->in_escape) - { - p->escape_buf[p->escape_ptr++] = ch; - ansi_parse_escape (a, c); - } - else - { - ansi_key (a, c, ch); - } + p->in_escape++; + p->escape_ptr = 0; + gettimeofday (&p->last_escape, NULL); + } + + if (p->in_escape) { + p->escape_buf[p->escape_ptr++] = ch; + ansi_parse_escape (a, c); + } else { + ansi_key (a, c, ch); + } } diff --git a/src/ansi.h b/src/ansi.h index beb0baa..5ea6cad 100644 --- a/src/ansi.h +++ b/src/ansi.h @@ -1,4 +1,4 @@ -/* +/* * ansi.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.19 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.18 2008/03/06 21:34:09 james * *** empty log message *** * @@ -74,7 +77,7 @@ #define ANSI_INVAL -1 #define ANSI_ESCAPE_BUF_LEN 10 -#define ANSI_ESCAPE_TIMEOUT 100000 /*in ms */ +#define ANSI_ESCAPE_TIMEOUT 100000 /* in ms */ typedef struct { diff --git a/src/cmd.c b/src/cmd.c index 2707332..3f98331 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1,4 +1,4 @@ -/* +/* * cmd.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.12 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.11 2008/03/03 06:04:42 james * *** empty log message *** * @@ -69,13 +72,11 @@ cmd_parse (Cmd * c, Context * ctx, ANSI * a, char *buf) ctx->k->hangup (ctx->k, ctx); else if (!strcmp (buf, "reset")) ctx->k->reset (ctx->k, ctx); - else if (!strcmp (buf, "expand")) - { - int w = a->terminal->size.x; - int h = a->terminal->size.y - 1; - ctx->k->set_size (ctx->k, ctx, w, h); - } - else if (!strncmp (buf, "width", 5)) + else if (!strcmp (buf, "expand")) { + int w = a->terminal->size.x; + int h = a->terminal->size.y - 1; + ctx->k->set_size (ctx->k, ctx, w, h); + } else if (!strncmp (buf, "width", 5)) ctx->k->set_size (ctx->k, ctx, atoi (buf + 5), 0); else if (!strncmp (buf, "height", 6)) ctx->k->set_size (ctx->k, ctx, 0, atoi (buf + 6)); @@ -106,42 +107,35 @@ int cmd_key (Cmd * c, Context * ctx, ANSI * a, int key) { - if (c->error) - { - c->error = 0; + if (c->error) { + c->error = 0; + c->active = 0; + cmd_show_status (c, ctx); + return 0; + } + + if (key == 13) { + if (cmd_parse (c, ctx, a, c->buf + 1)) { + c->error++; + } else { c->active = 0; - cmd_show_status (c, ctx); - return 0; } + cmd_show_status (c, ctx); + return 0; + } - if (key == 13) - { - if (cmd_parse (c, ctx, a, c->buf + 1)) - { - c->error++; - } - else - { - c->active = 0; - } - cmd_show_status (c, ctx); - return 0; - } - - if (((key == 8) || (key == 127)) && (c->ptr > 1)) - { - c->ptr--; - c->buf[c->ptr] = 0; - } + if (((key == 8) || (key == 127)) && (c->ptr > 1)) { + c->ptr--; + c->buf[c->ptr] = 0; + } - if ((key >= 32) && (key < 127)) - { + if ((key >= 32) && (key < 127)) { - c->buf[c->ptr] = key; - c->ptr++; - c->buf[c->ptr] = 0; + c->buf[c->ptr] = key; + c->ptr++; + c->buf[c->ptr] = 0; - } + } cmd_show_status (c, ctx); diff --git a/src/cmd.h b/src/cmd.h index 2a199e0..7094485 100644 --- a/src/cmd.h +++ b/src/cmd.h @@ -1,4 +1,4 @@ -/* +/* * cmd.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.7 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.6 2008/03/03 06:04:42 james * *** empty log message *** * @@ -35,8 +38,8 @@ #ifndef __CMD_H__ #define __CMD_H__ -#define CMD_KEY 2 /*CTRL B */ -#define CMD_CANCEL_KEY 3 /*CTRL C */ +#define CMD_KEY 2 /* CTRL B */ +#define CMD_CANCEL_KEY 3 /* CTRL C */ typedef struct { diff --git a/src/context.h b/src/context.h index 9245bf2..139a8f0 100644 --- a/src/context.h +++ b/src/context.h @@ -1,4 +1,4 @@ -/* +/* * context.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.12 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.11 2008/03/06 16:49:05 james * *** empty log message *** * diff --git a/src/crt.c b/src/crt.c index 8caca0c..2a5feaf 100644 --- a/src/crt.c +++ b/src/crt.c @@ -1,4 +1,4 @@ -/* +/* * crt.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.18 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.17 2008/03/03 06:04:42 james * *** empty log message *** * @@ -71,16 +74,14 @@ crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color) CRT_CA *ps = &c->screen[CRT_ADDR_POS (&s)]; CRT_CA *pe = &c->screen[CRT_ADDR_POS (&e)]; - while (ps <= pe) - { - ps->chr = ' '; - if (ea) - { - ps->attr = CRT_ATTR_NORMAL; - ps->color = color; - } - ps++; + while (ps <= pe) { + ps->chr = ' '; + if (ea) { + ps->attr = CRT_ATTR_NORMAL; + ps->color = color; } + ps++; + } } @@ -122,11 +123,10 @@ crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color) p = CRT_ADDR_POS (&s); - while (n--) - { - memcpy (&c->screen[p], &c->screen[p + CRT_COLS], l); - p += CRT_COLS; - } + while (n--) { + memcpy (&c->screen[p], &c->screen[p + CRT_COLS], l); + p += CRT_COLS; + } s.y = e.y; crt_erase (c, s, e, ea, color); @@ -153,15 +153,14 @@ crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color) l *= sizeof (CRT_CA); n = e.y - s.y; - //n++; + // n++; p = CRT_ADDR_POS (&e); - while (n--) - { - p -= CRT_COLS; - memcpy (&c->screen[p], &c->screen[p - CRT_COLS], l); - } + while (n--) { + p -= CRT_COLS; + memcpy (&c->screen[p], &c->screen[p - CRT_COLS], l); + } e.y = s.y; crt_erase (c, s, e, ea, color); diff --git a/src/crt.h b/src/crt.h index 9ba699d..7f5c1e1 100644 --- a/src/crt.h +++ b/src/crt.h @@ -1,4 +1,4 @@ -/* +/* * crt.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.17 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.16 2008/03/03 06:04:42 james * *** empty log message *** * @@ -105,8 +108,7 @@ #define CRT_COLOR_NORMAL CRT_MAKE_COLOR(CRT_FGCOLOR_NORMAL,CRT_BGCOLOR_NORMAL) -typedef struct __attribute__ ((packed)) -{ +typedef struct __attribute__ ((packed)) { uint32_t chr; uint8_t attr; uint8_t color; diff --git a/src/history.c b/src/history.c index bfb28dc..6ba2719 100644 --- a/src/history.c +++ b/src/history.c @@ -1,4 +1,4 @@ -/* +/* * history.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.6 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.5 2008/03/03 06:04:42 james * *** empty log message *** * @@ -72,11 +75,10 @@ history_add (History * h, CRT_CA * c) #if 0 { int i = CRT_COLS; - while (i--) - { - fputc (c->chr, stderr); - c++; - } + while (i--) { + fputc (c->chr, stderr); + c++; + } fputc ('\n', stderr); } #endif diff --git a/src/history.h b/src/history.h index 009b439..8ca80b2 100644 --- a/src/history.h +++ b/src/history.h @@ -1,4 +1,4 @@ -/* +/* * history.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.6 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.5 2008/03/03 06:04:42 james * *** empty log message *** * diff --git a/src/html.c b/src/html.c index e789d11..dc5e3f8 100644 --- a/src/html.c +++ b/src/html.c @@ -1,4 +1,4 @@ -/* +/* * html.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.14 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.13 2008/03/06 16:49:39 james * *** empty log message *** * @@ -80,35 +83,29 @@ static int colormap[] = { static void html_entity (FILE * f, int c) { - switch (c) - { - case 32: - fprintf (f, " "); - break; - case 38: - fprintf (f, "&"); - break; - case 60: - fprintf (f, "<"); - break; - case 62: - fprintf (f, ">"); - break; - default: - - if ((c >= 32) && (c < 127)) - { - fputc (c, f); - } - else if (c > 127) - { - fprintf (f, "&#x%04x;", c); - } - else - { - fputc (' ', f); - } + switch (c) { + case 32: + fprintf (f, " "); + break; + case 38: + fprintf (f, "&"); + break; + case 60: + fprintf (f, "<"); + break; + case 62: + fprintf (f, ">"); + break; + default: + + if ((c >= 32) && (c < 127)) { + fputc (c, f); + } else if (c > 127) { + fprintf (f, "&#x%04x;", c); + } else { + fputc (' ', f); } + } } static void @@ -116,18 +113,15 @@ html_render (FILE * f, CRT_CA c) { int fg, bg; - if (c.attr & CRT_ATTR_REVERSE) - { - fg = CRT_COLOR_BG (c.color); - bg = CRT_COLOR_FG (c.color); - } - else - { - fg = CRT_COLOR_FG (c.color); - bg = CRT_COLOR_BG (c.color); - if (c.attr & CRT_ATTR_BOLD) - fg |= CRT_COLOR_INTENSITY; - } + if (c.attr & CRT_ATTR_REVERSE) { + fg = CRT_COLOR_BG (c.color); + bg = CRT_COLOR_FG (c.color); + } else { + fg = CRT_COLOR_FG (c.color); + bg = CRT_COLOR_BG (c.color); + if (c.attr & CRT_ATTR_BOLD) + fg |= CRT_COLOR_INTENSITY; + } #ifdef CSS fprintf (f, "", colormap[fg], colormap[bg]); @@ -148,10 +142,9 @@ html_render (FILE * f, CRT_CA c) fprintf (f, ""); if (c.attr & CRT_ATTR_UNDERLINE) fprintf (f, ""); - if (c.attr & CRT_ATTR_REVERSE) - { - fprintf (f, ""); - } + if (c.attr & CRT_ATTR_REVERSE) { + fprintf (f, ""); + } #ifdef CSS fprintf (f, ""); #else @@ -171,22 +164,20 @@ html_draw (FILE * f, CRT * c) #else fprintf (f, "\n"); #endif - for (p.y = 0; p.y < c->size.y; ++p.y) - { - o = CRT_ADDR (p.y, 0); + for (p.y = 0; p.y < c->size.y; ++p.y) { + o = CRT_ADDR (p.y, 0); #ifndef CSS - fprintf (f, ""); + fprintf (f, ""); #endif - for (p.x = 0; p.x < c->size.x; ++p.x, ++o) - { - html_render (f, c->screen[o]); - } + for (p.x = 0; p.x < c->size.x; ++p.x, ++o) { + html_render (f, c->screen[o]); + } #ifdef CSS - fprintf (f, "\n"); + fprintf (f, "\n"); #else - fprintf (f, "\n"); + fprintf (f, "\n"); #endif - } + } #ifdef CSS fprintf (f, "\n"); #else diff --git a/src/ipc.c b/src/ipc.c index 38f5d08..a45d5e6 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1,4 +1,4 @@ -/* +/* * ipc.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.9 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.8 2008/03/03 18:16:16 james * *** empty log message *** * @@ -253,44 +256,42 @@ ipc_msg_send_reset (Socket * s) void ipc_execute_message (IPC_Msg * m, Context * c) { - switch (m->hdr.type) - { - case IPC_MSG_TYPE_NOOP: - break; - case IPC_MSG_TYPE_DEBUG: - log_f (c->l, "", m->debug.msg); - break; - case IPC_MSG_TYPE_KEY: - vt102_send (c, m->key.key); - break; - case IPC_MSG_TYPE_SETBAUD: - tty_set_baud (c->t, m->setbaud.baud); - tty_parse_reset (c); - log_f (c->l, "", m->setbaud.baud); - break; - case IPC_MSG_TYPE_SENDBREAK: - log_f (c->l, ""); - tty_send_break (c->t); - break; - case IPC_MSG_TYPE_SETFLOW: - log_f (c->l, "", - m->setflow.flow ? "on" : "off"); - tty_set_flow (c->t, m->setflow.flow); - break; - case IPC_MSG_TYPE_SETANSI: - vt102_set_ansi (c->v, m->setansi.ansi); - break; - case IPC_MSG_TYPE_HANGUP: - log_f (c->l, ""); - tty_hangup (c->t); - break; - case IPC_MSG_TYPE_SETSIZE: - vt102_resize (c, m->setsize.winsize); - break; - case IPC_MSG_TYPE_RESET: - vt102_reset (c); - break; - default: - log_f (c->l, "", m->hdr.type); - } + switch (m->hdr.type) { + case IPC_MSG_TYPE_NOOP: + break; + case IPC_MSG_TYPE_DEBUG: + log_f (c->l, "", m->debug.msg); + break; + case IPC_MSG_TYPE_KEY: + vt102_send (c, m->key.key); + break; + case IPC_MSG_TYPE_SETBAUD: + tty_set_baud (c->t, m->setbaud.baud); + tty_parse_reset (c); + log_f (c->l, "", m->setbaud.baud); + break; + case IPC_MSG_TYPE_SENDBREAK: + log_f (c->l, ""); + tty_send_break (c->t); + break; + case IPC_MSG_TYPE_SETFLOW: + log_f (c->l, "", m->setflow.flow ? "on" : "off"); + tty_set_flow (c->t, m->setflow.flow); + break; + case IPC_MSG_TYPE_SETANSI: + vt102_set_ansi (c->v, m->setansi.ansi); + break; + case IPC_MSG_TYPE_HANGUP: + log_f (c->l, ""); + tty_hangup (c->t); + break; + case IPC_MSG_TYPE_SETSIZE: + vt102_resize (c, m->setsize.winsize); + break; + case IPC_MSG_TYPE_RESET: + vt102_reset (c); + break; + default: + log_f (c->l, "", m->hdr.type); + } } diff --git a/src/ipc.h b/src/ipc.h index bd97759..46766a5 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -1,4 +1,4 @@ -/* +/* * ipc.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.9 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.8 2008/03/03 06:04:42 james * *** empty log message *** * diff --git a/src/keydis.c b/src/keydis.c index 64962e0..8d88d46 100644 --- a/src/keydis.c +++ b/src/keydis.c @@ -1,4 +1,4 @@ -/* +/* * keydis.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.14 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.13 2008/03/03 18:16:16 james * *** empty log message *** * diff --git a/src/keydis.h b/src/keydis.h index 66cc586..ac69b7a 100644 --- a/src/keydis.h +++ b/src/keydis.h @@ -1,4 +1,4 @@ -/* +/* * keydis.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.9 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.8 2008/03/03 06:04:42 james * *** empty log message *** * diff --git a/src/keys.h b/src/keys.h index 0406ed8..f030f5c 100644 --- a/src/keys.h +++ b/src/keys.h @@ -1,4 +1,4 @@ -/* +/* * src/keys.h: * * Copyright (c) 2008 James McKenzie , @@ -6,22 +6,25 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.8 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.7 2008/03/06 16:49:39 james * *** empty log message *** * * Revision 1.6 2008/03/06 01:49:19 james * *** empty log message *** * - * Revision 1.5 2008 /03 /06 01:41:48 james + * Revision 1.5 2008 /03 /06 01:41:48 james * *** empty log message *** * - * Revision 1.4 2008 /02 /07 00:44:07 james + * Revision 1.4 2008 /02 /07 00:44:07 james * *** empty log message *** * */ @@ -44,10 +47,10 @@ #define KEY_ENTER 140 /*M*/ #define KEY_141 141 /*N*/ #define KEY_142 142 /*O*/ -#define KEY_PF1 143 /*P*/ /*Also F1 */ -#define KEY_PF2 144 /*Q*/ /*Also F2 */ -#define KEY_PF3 145 /*R*/ /*Also F3 */ -#define KEY_PF4 146 /*S*/ /*Also F4 */ +#define KEY_PF1 143 /*P*/ /* Also F1 */ +#define KEY_PF2 144 /*Q*/ /* Also F2 */ +#define KEY_PF3 145 /*R*/ /* Also F3 */ +#define KEY_PF4 146 /*S*/ /* Also F4 */ #define KEY_147 147 /*T*/ #define KEY_148 148 /*U*/ #define KEY_149 149 /*V*/ @@ -55,66 +58,66 @@ #define KEY_151 151 /*X*/ #define KEY_152 152 /*Y*/ #define KEY_153 153 /*Z*/ -#define KEY_154 154 /*a */ -#define KEY_155 155 /*b */ -#define KEY_156 156 /*c */ -#define KEY_157 157 /*d */ -#define KEY_158 158 /*e */ -#define KEY_159 159 /*f */ -#define KEY_160 160 /*g */ -#define KEY_161 161 /*h */ -#define KEY_162 162 /*i */ -#define KEY_STAR 163 /*j */ -#define KEY_PLUS 164 /*k */ -#define KEY_COMMA 165 /*l */ -#define KEY_MINUS 166 /*m */ -#define KEY_PERIOD 167 /*n */ -#define KEY_DIVIDE 168 /*o */ -#define KEY_0 169 /*p */ -#define KEY_1 170 /*q */ -#define KEY_2 171 /*r */ -#define KEY_3 172 /*s */ -#define KEY_4 173 /*t */ -#define KEY_5 174 /*u */ -#define KEY_6 175 /*v */ -#define KEY_7 176 /*w */ -#define KEY_8 177 /*x */ -#define KEY_9 178 /*y */ -#define KEY_179 179 /*z */ -#define KEY_180 180 /*0 */ -#define KEY_VT220_HOME 181 /*1 */ -#define KEY_INSERT 182 /*2 */ -#define KEY_DELETE 183 /*3 */ -#define KEY_VT220_END 184 /*4 */ -#define KEY_PGUP 185 /*5 */ -#define KEY_PGDN 186 /*6 */ -#define KEY_187 187 /*7 */ -#define KEY_188 188 /*8 */ -#define KEY_189 189 /*9 */ -#define KEY_190 190 /*10 */ -#define KEY_F1 191 /*11 */ -#define KEY_F2 192 /*12 */ -#define KEY_F3 193 /*13 */ -#define KEY_F4 194 /*14 */ -#define KEY_F5 195 /*15 */ -#define KEY_196 196 /*16 */ -#define KEY_F6 197 /*17 */ -#define KEY_F7 198 /*18 */ -#define KEY_F8 199 /*19 */ -#define KEY_F9 200 /*20 */ -#define KEY_F10 201 /*21 */ -#define KEY_202 202 /*22 */ -#define KEY_F11 203 /*23 */ -#define KEY_F12 204 /*24 */ -#define KEY_F13 205 /*25 */ -#define KEY_F14 206 /*26 */ -#define KEY_207 207 /*27 */ -#define KEY_F15 208 /*28 */ -#define KEY_F16 209 /*29 */ -#define KEY_210 210 /*30 */ -#define KEY_F17 211 /*31 */ -#define KEY_F18 212 /*32 */ -#define KEY_F19 213 /*33 */ -#define KEY_F20 214 /*34 */ +#define KEY_154 154 /* a */ +#define KEY_155 155 /* b */ +#define KEY_156 156 /* c */ +#define KEY_157 157 /* d */ +#define KEY_158 158 /* e */ +#define KEY_159 159 /* f */ +#define KEY_160 160 /* g */ +#define KEY_161 161 /* h */ +#define KEY_162 162 /* i */ +#define KEY_STAR 163 /* j */ +#define KEY_PLUS 164 /* k */ +#define KEY_COMMA 165 /* l */ +#define KEY_MINUS 166 /* m */ +#define KEY_PERIOD 167 /* n */ +#define KEY_DIVIDE 168 /* o */ +#define KEY_0 169 /* p */ +#define KEY_1 170 /* q */ +#define KEY_2 171 /* r */ +#define KEY_3 172 /* s */ +#define KEY_4 173 /* t */ +#define KEY_5 174 /* u */ +#define KEY_6 175 /* v */ +#define KEY_7 176 /* w */ +#define KEY_8 177 /* x */ +#define KEY_9 178 /* y */ +#define KEY_179 179 /* z */ +#define KEY_180 180 /* 0 */ +#define KEY_VT220_HOME 181 /* 1 */ +#define KEY_INSERT 182 /* 2 */ +#define KEY_DELETE 183 /* 3 */ +#define KEY_VT220_END 184 /* 4 */ +#define KEY_PGUP 185 /* 5 */ +#define KEY_PGDN 186 /* 6 */ +#define KEY_187 187 /* 7 */ +#define KEY_188 188 /* 8 */ +#define KEY_189 189 /* 9 */ +#define KEY_190 190 /* 10 */ +#define KEY_F1 191 /* 11 */ +#define KEY_F2 192 /* 12 */ +#define KEY_F3 193 /* 13 */ +#define KEY_F4 194 /* 14 */ +#define KEY_F5 195 /* 15 */ +#define KEY_196 196 /* 16 */ +#define KEY_F6 197 /* 17 */ +#define KEY_F7 198 /* 18 */ +#define KEY_F8 199 /* 19 */ +#define KEY_F9 200 /* 20 */ +#define KEY_F10 201 /* 21 */ +#define KEY_202 202 /* 22 */ +#define KEY_F11 203 /* 23 */ +#define KEY_F12 204 /* 24 */ +#define KEY_F13 205 /* 25 */ +#define KEY_F14 206 /* 26 */ +#define KEY_207 207 /* 27 */ +#define KEY_F15 208 /* 28 */ +#define KEY_F16 209 /* 29 */ +#define KEY_210 210 /* 30 */ +#define KEY_F17 211 /* 31 */ +#define KEY_F18 212 /* 32 */ +#define KEY_F19 213 /* 33 */ +#define KEY_F20 214 /* 34 */ #define KEY_NUM 215 #endif /* __KEYS_H__ */ diff --git a/src/libsympathy.c b/src/libsympathy.c index 70cdcfd..4a80c94 100644 --- a/src/libsympathy.c +++ b/src/libsympathy.c @@ -1,4 +1,4 @@ -/* +/* * libsympathy.c: * * Copyright (c) 2008 James McKenzie , @@ -9,8 +9,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.19 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.18 2008/02/14 00:57:58 james * *** empty log message *** * diff --git a/src/lockfile.c b/src/lockfile.c index 6b08ae0..31343cc 100644 --- a/src/lockfile.c +++ b/src/lockfile.c @@ -1,4 +1,4 @@ -/* +/* * lockfile.c: * * Copyright (c) 2008 James McKenzie , @@ -9,8 +9,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.13 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.12 2008/03/03 06:04:42 james * *** empty log message *** * @@ -132,11 +135,10 @@ void filelist_print (Filelist * fl, FILE * f) { Filelist_ent *fle; - if (!fl) - { - fprintf (f, "(empty list)\n"); - return; - } + if (!fl) { + fprintf (f, "(empty list)\n"); + return; + } for (fle = fl->head; fle; fle = fle->next) fprintf (f, "%s\n", fle->name); } @@ -151,18 +153,14 @@ chown_uucp (fd) static int uuid = -1, ugid; struct passwd *pw; - if (uuid < 0) - { - if (pw = getpwnam ("uucp")) - { - uuid = pw->pw_uid; - ugid = pw->pw_gid; - } - else - { - return -1; - } + if (uuid < 0) { + if (pw = getpwnam ("uucp")) { + uuid = pw->pw_uid; + ugid = pw->pw_gid; + } else { + return -1; } + } return fchown (fd, uuid, ugid); } @@ -189,28 +187,25 @@ lockfile_make (char *name) unlink (tmpfn); fd = open (tmpfn, O_WRONLY | O_CREAT | O_TRUNC, 0444); - if (fd < 0) - { - unlink (tmpfn); - return -1; - } + if (fd < 0) { + unlink (tmpfn); + return -1; + } write (fd, buf, i); fchmod (fd, 044); - if (chown_uucp (fd)) - { - close (fd); - unlink (tmpfn); - return -1; - } + if (chown_uucp (fd)) { + close (fd); + unlink (tmpfn); + return -1; + } close (fd); - if (link (tmpfn, name) < 0) - { - unlink (tmpfn); - return -1; - } + if (link (tmpfn, name) < 0) { + unlink (tmpfn); + return -1; + } unlink (tmpfn); return 0; @@ -229,29 +224,27 @@ lockfile_add_places (Filelist * fl, char *leaf) }; int i; - for (i = 0; i < (sizeof (lock_dirs) / sizeof (char *)); ++i) - { - if (stat (lock_dirs[i], &stbuf)) - continue; - strcpy (buf, lock_dirs[i]); - strcat (buf, "/"); - strcat (buf, leaf); - filelist_add (fl, buf); - } + for (i = 0; i < (sizeof (lock_dirs) / sizeof (char *)); ++i) { + if (stat (lock_dirs[i], &stbuf)) + continue; + strcpy (buf, lock_dirs[i]); + strcat (buf, "/"); + strcat (buf, leaf); + filelist_add (fl, buf); + } } static void do_tedious_mangling (Filelist * fl, char *buf, char *ptr, char inv, int lower) { - while (*ptr) - { - if (lower && (*ptr >= 'A') && (*ptr <= 'Z')) - *ptr |= 32; - if (*ptr == '/') - *ptr = inv; - ptr++; - } + while (*ptr) { + if (lower && (*ptr >= 'A') && (*ptr <= 'Z')) + *ptr |= 32; + if (*ptr == '/') + *ptr = inv; + ptr++; + } lockfile_add_places (fl, buf); } @@ -290,11 +283,10 @@ lockfile_add_name_from_path (Filelist * fl, char *file) ptr++; lockfile_regularize_and_add (fl, ptr); - if (!strncmp (ptr, "dev/", 4)) - { - ptr += 4; - lockfile_regularize_and_add (fl, ptr); - } + if (!strncmp (ptr, "dev/", 4)) { + ptr += 4; + lockfile_regularize_and_add (fl, ptr); + } } @@ -319,21 +311,20 @@ lockfile_check_dir_for_dev (Filelist * fl, char *dir, dev_t dev) if (!d) return; - while ((de = readdir (d))) - { - strcpy (buf, dir); - strcat (buf, de->d_name); + while ((de = readdir (d))) { + strcpy (buf, dir); + strcat (buf, de->d_name); - if (stat (buf, &ent_stat)) - continue; - if (!S_ISCHR (ent_stat.st_mode)) - continue; - if (ent_stat.st_rdev != dev) - continue; + if (stat (buf, &ent_stat)) + continue; + if (!S_ISCHR (ent_stat.st_mode)) + continue; + if (ent_stat.st_rdev != dev) + continue; - lockfile_add_name_from_path (fl, buf); + lockfile_add_name_from_path (fl, buf); - } + } closedir (d); } @@ -380,31 +371,28 @@ remove_stale_lock (char *path) apid[length] = 0; pid = 0; - if (length == sizeof (pid) || sscanf (apid, "%d", &pid) != 1 || pid == 0) - { - pid = *((int *) apid); + if (length == sizeof (pid) || sscanf (apid, "%d", &pid) != 1 || pid == 0) { + pid = *((int *) apid); #ifdef LOCK_ASCII - fprintf (stderr, - "compiled with ascii locks, found binary lock file (length=%d, pid=%d)!", - length, pid); + fprintf (stderr, + "compiled with ascii locks, found binary lock file (length=%d, pid=%d)!", + length, pid); #endif - } + } #ifdef LOCK_BINARY - else - { - fprintf (stderr, - "compiled with binary locks, found ascii lock file (length=%d, pid=%d)!", - length, pid); - } + else { + fprintf (stderr, + "compiled with binary locks, found ascii lock file (length=%d, pid=%d)!", + length, pid); + } #endif close (fd); - if ((kill (pid, 0) < 0) && (errno == ESRCH)) - { - fprintf (stderr, "removing stale lock file %s\n", path); - unlink (path); - } + if ((kill (pid, 0) < 0) && (errno == ESRCH)) { + fprintf (stderr, "removing stale lock file %s\n", path); + unlink (path); + } } @@ -414,12 +402,11 @@ lockfile_remove_stale (Filelist * fl) Filelist_ent *fle; struct stat buf; - for (fle = fl->head; fle; fle = fle->next) - { - if (stat (fle->name, &buf)) - continue; - remove_stale_lock (fle->name); - } + for (fle = fl->head; fle; fle = fle->next) { + if (stat (fle->name, &buf)) + continue; + remove_stale_lock (fle->name); + } } @@ -435,16 +422,14 @@ lockfile_lock (Filelist * fl) lockfile_remove_stale (fl); - for (fle = fl->head; fle; fle = fle->next) - { - if (lockfile_make (fle->name)) - { - fprintf (stderr, "Failed to get lockfile %s\n", fle->name); - filelist_free (ret); - return NULL; - } - filelist_add (ret, fle->name); + for (fle = fl->head; fle; fle = fle->next) { + if (lockfile_make (fle->name)) { + fprintf (stderr, "Failed to get lockfile %s\n", fle->name); + filelist_free (ret); + return NULL; } + filelist_add (ret, fle->name); + } return ret; } @@ -453,11 +438,10 @@ void lockfile_unlock (Filelist * fl) { - while (fl->head) - { - unlink (fl->head->name); - filelist_remove (fl, fl->head); - } + while (fl->head) { + unlink (fl->head->name); + filelist_remove (fl, fl->head); + } } @@ -474,11 +458,10 @@ serial_lock_check (Serial_lock * l) if (l->mode == SERIAL_LOCK_ACTIVE) return 0; - for (fle = l->locks_to_check->head; fle; fle = fle->next) - { - if (!stat (fle->name, &buf)) - locks_found++; - } + for (fle = l->locks_to_check->head; fle; fle = fle->next) { + if (!stat (fle->name, &buf)) + locks_found++; + } if (!locks_found) return 0; @@ -486,11 +469,10 @@ serial_lock_check (Serial_lock * l) gettimeofday (&now, NULL); timersub (&now, &l->last_stale_purge, &dif); - if (dif.tv_sec > STALE_CHECK_INTERVAL) - { - lockfile_remove_stale (l->locks_to_check); - l->last_stale_purge = now; - } + if (dif.tv_sec > STALE_CHECK_INTERVAL) { + lockfile_remove_stale (l->locks_to_check); + l->last_stale_purge = now; + } return 1; } @@ -501,16 +483,14 @@ serial_lock_free (Serial_lock * l) if (!l) return; - if (l->locks_held) - { - lockfile_unlock (l->locks_held); - filelist_free (l->locks_held); - } + if (l->locks_held) { + lockfile_unlock (l->locks_held); + filelist_free (l->locks_held); + } - if (l->locks_to_check) - { - filelist_free (l->locks_to_check); - } + if (l->locks_to_check) { + filelist_free (l->locks_to_check); + } free (l); } @@ -536,11 +516,10 @@ serial_lock_new (char *dev, int mode) return l; l->locks_held = lockfile_lock (l->locks_to_check); - if (!l->locks_held) - { - serial_lock_free (l); - return NULL; - } + if (!l->locks_held) { + serial_lock_free (l); + return NULL; + } return l; } diff --git a/src/lockfile.h b/src/lockfile.h index 3736c08..b8b1775 100644 --- a/src/lockfile.h +++ b/src/lockfile.h @@ -1,4 +1,4 @@ -/* +/* * lockfile.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.10 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.9 2008/03/03 06:04:42 james * *** empty log message *** * diff --git a/src/log.c b/src/log.c index 864af34..2f41951 100644 --- a/src/log.c +++ b/src/log.c @@ -1,4 +1,4 @@ -/* +/* * log.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.10 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.9 2008/03/03 06:20:14 james * *** empty log message *** * @@ -79,12 +82,11 @@ flog_log (Log * _l, char *buf) fputc ('\n', l->fp); fflush (l->fp); - if (l->rotate && rotate_check (l->filename)) - { - fclose (l->fp); - rotate (l->filename); - l->fp = fopen (l->filename, "a+"); - } + if (l->rotate && rotate_check (l->filename)) { + fclose (l->fp); + rotate (l->filename); + l->fp = fopen (l->filename, "a+"); + } } @@ -108,17 +110,14 @@ file_log_new (char *fn, int rotate) FILE *f; int dc = 1; - if (fn && strcmp (fn, "-")) - { - f = fopen (fn, "a+"); - if (!f) - return NULL; - } - else - { - f = stderr; - dc = 0; - } + if (fn && strcmp (fn, "-")) { + f = fopen (fn, "a+"); + if (!f) + return NULL; + } else { + f = stderr; + dc = 0; + } l = malloc (sizeof (File_Log)); @@ -146,35 +145,32 @@ log_f (Log * log, char *fmt, ...) if (!log) return; - if (!size) - { - size = 128; - buf = malloc (size); - } + if (!size) { + size = 128; + buf = malloc (size); + } if (!buf) return; - while (1) - { - va_start (ap, fmt); - n = vsnprintf (buf, size, fmt, ap); - va_end (ap); + while (1) { + va_start (ap, fmt); + n = vsnprintf (buf, size, fmt, ap); + va_end (ap); - if (n > -1 && n < size) - { - log->log (log, buf); - return; - } + if (n > -1 && n < size) { + log->log (log, buf); + return; + } - if (n > -1) /* glibc 2.1 */ - size = n + 1; - else /* glibc 2.0 */ - size *= 2; /* twice the old size */ + if (n > -1) /* glibc 2.1 */ + size = n + 1; + else /* glibc 2.0 */ + size *= 2; /* twice the old size */ - buf = realloc (buf, size); + buf = realloc (buf, size); - if (!buf) - return; - } + if (!buf) + return; + } } diff --git a/src/log.h b/src/log.h index ced5e5b..27510b9 100644 --- a/src/log.h +++ b/src/log.h @@ -1,4 +1,4 @@ -/* +/* * log.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.5 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.4 2008/03/03 06:04:42 james * *** empty log message *** * diff --git a/src/project.h b/src/project.h index 8d5def2..b7d9df5 100644 --- a/src/project.h +++ b/src/project.h @@ -1,4 +1,4 @@ -/* +/* * project.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.11 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.10 2008/02/22 14:51:54 james * *** empty log message *** * diff --git a/src/ptty.c b/src/ptty.c index cd3dbae..5f4651d 100644 --- a/src/ptty.c +++ b/src/ptty.c @@ -1,4 +1,4 @@ -/* +/* * ptty.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.19 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.18 2008/03/03 06:04:42 james * *** empty log message *** * @@ -112,19 +115,18 @@ ptty_read (TTY * _t, void *buf, int len) PTTY *t = (PTTY *) _t; int red, done = 0; - do - { + do { - red = wrap_read (t->fd, buf, len); - if (red < 0) - return -1; - if (!red) - return done; + red = wrap_read (t->fd, buf, len); + if (red < 0) + return -1; + if (!red) + return done; - buf += red; - len -= red; - done += red; - } + buf += red; + len -= red; + done += red; + } while (len); @@ -138,19 +140,18 @@ ptty_write (TTY * _t, void *buf, int len) int writ, done = 0; PTTY *t = (PTTY *) _t; - do - { + do { - writ = wrap_write (t->fd, buf, len); - if (writ < 0) - return -1; - if (!writ) - sleep (1); + writ = wrap_write (t->fd, buf, len); + if (writ < 0) + return -1; + if (!writ) + sleep (1); - buf += writ; - len -= writ; - done += writ; - } + buf += writ; + len -= writ; + done += writ; + } while (len); @@ -175,21 +176,20 @@ ptty_open (char *path, char *argv[], CRT_Pos * size) child = forkpty (&fd, name, &ctermios, &winsize); - switch (child) - { - case -1: /*boo hiss */ - return NULL; - case 0: /*waaah */ - setenv ("TERM", "xterm", 1); - if (!path) - path = "/bin/sh"; - - if (!argv) - argv = default_argv; - - execv (path, argv); - _exit (-1); - } + switch (child) { + case -1: /* boo hiss */ + return NULL; + case 0: /* waaah */ + setenv ("TERM", "xterm", 1); + if (!path) + path = "/bin/sh"; + + if (!argv) + argv = default_argv; + + execv (path, argv); + _exit (-1); + } set_nonblocking (fd); diff --git a/src/raw.c b/src/raw.c index 7116c97..e5a58dc 100644 --- a/src/raw.c +++ b/src/raw.c @@ -1,4 +1,4 @@ -/* +/* * raw.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.6 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.5 2008/03/06 21:34:09 james * *** empty log message *** * @@ -85,19 +88,18 @@ raw_terminal_read (TTY * _t, void *buf, int len) set_nonblocking (t->rfd); - do - { + do { - red = wrap_read (t->rfd, buf, len); - if (red < 0) - return -1; - if (!red) - return done; + red = wrap_read (t->rfd, buf, len); + if (red < 0) + return -1; + if (!red) + return done; - buf += red; - len -= red; - done += red; - } + buf += red; + len -= red; + done += red; + } while (len); @@ -113,20 +115,19 @@ raw_terminal_write (TTY * _t, void *buf, int len) set_blocking (t->wfd); - do - { + do { - writ = wrap_write (t->wfd, buf, len); - if (writ < 0) - return -1; + writ = wrap_write (t->wfd, buf, len); + if (writ < 0) + return -1; - if (!writ) - usleep (1000); + if (!writ) + usleep (1000); - buf += writ; - len -= writ; - done += writ; - } + buf += writ; + len -= writ; + done += writ; + } while (len); @@ -162,7 +163,7 @@ terminal_new_raw (int rfd, int wfd) set_nonblocking (wfd); t->recv = raw_terminal_read; -// t->xmit = raw_terminal_write; + // t->xmit = raw_terminal_write; t->close = raw_terminal_close; t->blocked = 0; diff --git a/src/render.c b/src/render.c index 52fa0ff..666dbda 100644 --- a/src/render.c +++ b/src/render.c @@ -1,4 +1,4 @@ -/* +/* * render.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.3 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.2 2008/02/04 02:05:06 james * *** empty log message *** * diff --git a/src/ring.c b/src/ring.c index 9e04fd3..44b2bb9 100644 --- a/src/ring.c +++ b/src/ring.c @@ -1,4 +1,4 @@ -/* +/* * ring.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.7 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.6 2008/03/03 06:04:42 james * *** empty log message *** * @@ -37,15 +40,14 @@ ring_read (Ring * r, void *b, int n) { int red = 0; - while (n--) - { + while (n--) { - if (!ring_read_one (r, b)) - break; + if (!ring_read_one (r, b)) + break; - b++; - red++; - } + b++; + red++; + } return red; } @@ -55,15 +57,14 @@ ring_write (Ring * r, void *b, int n) { int writ = 0; - while (n--) - { + while (n--) { - if (!ring_write_one (r, b)) - break; + if (!ring_write_one (r, b)) + break; - b++; - writ++; - } + b++; + writ++; + } return writ; } diff --git a/src/ring.h b/src/ring.h index 372fad3..303faca 100644 --- a/src/ring.h +++ b/src/ring.h @@ -1,4 +1,4 @@ -/* +/* * ring.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.5 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.4 2008/03/03 06:04:42 james * *** empty log message *** * diff --git a/src/rotate.c b/src/rotate.c index b40ae1a..ad1752e 100644 --- a/src/rotate.c +++ b/src/rotate.c @@ -1,4 +1,4 @@ -/* +/* * rotate.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.9 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.8 2008/03/06 01:41:48 james * *** empty log message *** * @@ -46,14 +49,13 @@ static char rcsid[] = "$Id$"; void rotate_gzip (char *file) { - switch (fork ()) - { - case 0: - break; - case -1: - default: - return; - } + switch (fork ()) { + case 0: + break; + case -1: + default: + return; + } daemon (1, 0); execlp ("gzip", "gzip", file, (char *) 0); @@ -72,16 +74,15 @@ rotate (char *file) buf1 = malloc (i); buf2 = malloc (i); - for (i = NUM_FILES_TO_KEEP; i > 0; --i) - { - sprintf (buf1, "%s.%d", file, i - 1); - sprintf (buf2, "%s.%d", file, i); - rename (buf1, buf2); + for (i = NUM_FILES_TO_KEEP; i > 0; --i) { + sprintf (buf1, "%s.%d", file, i - 1); + sprintf (buf2, "%s.%d", file, i); + rename (buf1, buf2); - sprintf (buf1, "%s.%d.gz", file, i - 1); - sprintf (buf2, "%s.%d.gz", file, i); - rename (buf1, buf2); - } + sprintf (buf1, "%s.%d.gz", file, i - 1); + sprintf (buf2, "%s.%d.gz", file, i); + rename (buf1, buf2); + } sprintf (buf1, "%s.%d", file, 0); rename (file, buf1); diff --git a/src/rx.h b/src/rx.h index ad140a6..c1c58ea 100644 --- a/src/rx.h +++ b/src/rx.h @@ -1,4 +1,4 @@ -/* +/* * rx.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.4 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.3 2008/03/06 16:49:39 james * *** empty log message *** * diff --git a/src/serial.c b/src/serial.c index 25748ac..bc3558a 100644 --- a/src/serial.c +++ b/src/serial.c @@ -1,4 +1,4 @@ -/* +/* * serial.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.15 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.14 2008/03/03 06:04:42 james * *** empty log message *** * @@ -120,19 +123,18 @@ serial_read (TTY * _t, void *buf, int len) if (t->blocked) return 0; - do - { + do { - red = wrap_read (t->fd, buf, len); - if (red < 0) - return -1; - if (!red) - return done; + red = wrap_read (t->fd, buf, len); + if (red < 0) + return -1; + if (!red) + return done; - buf += red; - len -= red; - done += red; - } + buf += red; + len -= red; + done += red; + } while (len); @@ -150,19 +152,18 @@ serial_write (TTY * _t, void *buf, int len) if (t->blocked) return 0; - do - { + do { - writ = wrap_write (t->fd, buf, len); - if (writ < 0) - return -1; - if (!writ) - sleep (1); + writ = wrap_write (t->fd, buf, len); + if (writ < 0) + return -1; + if (!writ) + sleep (1); - buf += writ; - len -= writ; - done += writ; - } + buf += writ; + len -= writ; + done += writ; + } while (len); @@ -190,18 +191,16 @@ serial_open (char *path, int lock_mode) set_nonblocking (fd); - if (tcgetattr (fd, &termios)) - { - close (fd); - return NULL; - } + if (tcgetattr (fd, &termios)) { + close (fd); + return NULL; + } default_termios (&termios); - if (tcsetattr (fd, TCSANOW, &termios)) - { - close (fd); - return NULL; - } + if (tcsetattr (fd, TCSANOW, &termios)) { + close (fd); + return NULL; + } t = (Serial *) malloc (sizeof (Serial)); diff --git a/src/slide.c b/src/slide.c index b04e430..7561f60 100644 --- a/src/slide.c +++ b/src/slide.c @@ -1,4 +1,4 @@ -/* +/* * slide.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.6 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.5 2008/03/03 06:04:42 james * *** empty log message *** * @@ -55,11 +58,10 @@ slide_consume (Slide * s, int n) memmove (s->slide, s->slide + n, s->nbytes); - if ((s->size > s->target_size) && (s->nbytes <= s->target_size)) - { - s->size = s->target_size; - s->slide = realloc (s->slide, s->size); - } + if ((s->size > s->target_size) && (s->nbytes <= s->target_size)) { + s->size = s->target_size; + s->slide = realloc (s->slide, s->size); + } } @@ -94,7 +96,7 @@ slide_expand (Slide * s, int n) while (n > s->size) s->size <<= 1; -//FIXME -- might fail + // FIXME -- might fail s->slide = realloc (s->slide, s->size); } diff --git a/src/slide.h b/src/slide.h index 560aaea..f42b99c 100644 --- a/src/slide.h +++ b/src/slide.h @@ -1,4 +1,4 @@ -/* +/* * ring.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.4 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.3 2008/03/03 06:04:42 james * *** empty log message *** * diff --git a/src/symsocket.c b/src/symsocket.c index 461ed12..15b58c5 100644 --- a/src/symsocket.c +++ b/src/symsocket.c @@ -1,4 +1,4 @@ -/* +/* * symsocket.c: * * Copyright (c) 2008 James McKenzie , @@ -9,8 +9,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.11 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.10 2008/03/03 18:16:16 james * *** empty log message *** * @@ -92,11 +95,10 @@ socket_free (Socket * s) slide_free (s->read_buf); if (s->write_buf) slide_free (s->write_buf); - if (s->path_to_unlink) - { - unlink (s->path_to_unlink); - free (s->path_to_unlink); - } + if (s->path_to_unlink) { + unlink (s->path_to_unlink); + free (s->path_to_unlink); + } close (s->fd); free (s); } @@ -141,20 +143,18 @@ socket_listen (char *path) sun->sun_family = AF_UNIX; strcpy (sun->sun_path, path); - if (bind (fd, (struct sockaddr *) sun, SUN_LEN (sun)) < 0) - { - free (sun); - close (fd); - return NULL; - } + if (bind (fd, (struct sockaddr *) sun, SUN_LEN (sun)) < 0) { + free (sun); + close (fd); + return NULL; + } free (sun); - if (listen (fd, 5) < 0) - { - close (fd); - return NULL; - } + if (listen (fd, 5) < 0) { + close (fd); + return NULL; + } set_nonblocking (fd); @@ -200,7 +200,7 @@ socket_accept (Socket * l) } -/*Blocking for now*/ +/* Blocking for now */ Socket * socket_connect (char *path) { @@ -222,12 +222,11 @@ socket_connect (char *path) sun->sun_family = AF_UNIX; strcpy (sun->sun_path, path); - if (connect (fd, (struct sockaddr *) sun, SUN_LEN (sun))) - { - free (sun); - close (fd); - return NULL; - } + if (connect (fd, (struct sockaddr *) sun, SUN_LEN (sun))) { + free (sun); + close (fd); + return NULL; + } free (sun); @@ -263,12 +262,11 @@ socket_pre_select (Socket * s, fd_set * rfds, fd_set * wfds) char buf[1024]; int n; - /*Server socket */ - if (SOCKET_IS_LISTENER (s)) - { - FD_SET (s->fd, rfds); - return; - } + /* Server socket */ + if (SOCKET_IS_LISTENER (s)) { + FD_SET (s->fd, rfds); + return; + } if (!SLIDE_EMPTY (s->write_buf)) FD_SET (s->fd, wfds); @@ -286,29 +284,27 @@ socket_post_select (Socket * s, fd_set * rfds, fd_set * wfds) int error = 0; - if ((!SLIDE_EMPTY (s->write_buf)) && FD_ISSET (s->fd, wfds)) - { - n = - (SLIDE_BYTES (s->write_buf) > - MAX_TXN) ? MAX_TXN : SLIDE_BYTES (s->write_buf); - n = wrap_send (s->fd, SLIDE_RPTR (s->write_buf), n); - if (n > 0) - slide_consume (s->write_buf, n); - if (n < 0) - error = -1; - } - - if (!SLIDE_FULL (s->read_buf) && FD_ISSET (s->fd, rfds)) - { - n = - (SLIDE_SPACE (s->read_buf) > - MAX_TXN) ? MAX_TXN : SLIDE_SPACE (s->read_buf); - n = wrap_recv (s->fd, SLIDE_WPTR (s->read_buf), n); - if (n > 0) - slide_added (s->read_buf, n); - if (n < 0) - error = -1; - } + if ((!SLIDE_EMPTY (s->write_buf)) && FD_ISSET (s->fd, wfds)) { + n = + (SLIDE_BYTES (s->write_buf) > + MAX_TXN) ? MAX_TXN : SLIDE_BYTES (s->write_buf); + n = wrap_send (s->fd, SLIDE_RPTR (s->write_buf), n); + if (n > 0) + slide_consume (s->write_buf, n); + if (n < 0) + error = -1; + } + + if (!SLIDE_FULL (s->read_buf) && FD_ISSET (s->fd, rfds)) { + n = + (SLIDE_SPACE (s->read_buf) > + MAX_TXN) ? MAX_TXN : SLIDE_SPACE (s->read_buf); + n = wrap_recv (s->fd, SLIDE_WPTR (s->read_buf), n); + if (n > 0) + slide_added (s->read_buf, n); + if (n < 0) + error = -1; + } s->msg = ipc_check_for_message_in_slide (s->read_buf); diff --git a/src/symsocket.h b/src/symsocket.h index 5c32517..fdc4ff5 100644 --- a/src/symsocket.h +++ b/src/symsocket.h @@ -1,4 +1,4 @@ -/* +/* * symsocket.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.5 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.4 2008/03/03 06:04:42 james * *** empty log message *** * diff --git a/src/terminal.c b/src/terminal.c index 65ec41c..c89ca16 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -1,4 +1,4 @@ -/* +/* * terminal.c: * * Copyright (c) 2008 James McKenzie , @@ -9,8 +9,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.15 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.14 2008/03/03 06:04:42 james * *** empty log message *** * @@ -113,15 +116,19 @@ terminal_close (TTY * _t) set_nonblocking (t->wfd); - t->xmit (_t, "\033%@", 3); //Leave UTF-8 - t->xmit (_t, "\033(B", 3); //US-ASCII in G0 - t->xmit (_t, "\033)B", 3); //US-ASCII in G1 - t->xmit (_t, "\017", 1); //Select G0 - t->xmit (_t, "\033[r", 3); //No margins - t->xmit (_t, "\033[0m", 4); //Default attributes - i = sprintf (buf, "\033[%d;%dH", t->displayed_length ? (t->displayed_length + 1) : (CRT_ROWS + 1), 1); //Cursor to bottom + t->xmit (_t, "\033%@", 3); // Leave UTF-8 + t->xmit (_t, "\033(B", 3); // US-ASCII in G0 + t->xmit (_t, "\033)B", 3); // US-ASCII in G1 + t->xmit (_t, "\017", 1); // Select G0 + t->xmit (_t, "\033[r", 3); // No margins + t->xmit (_t, "\033[0m", 4); // Default attributes + i = sprintf (buf, "\033[%d;%dH", t->displayed_length ? (t->displayed_length + 1) : (CRT_ROWS + 1), 1); // Cursor + // + // + // to + // bottom t->xmit (_t, buf, i); - t->xmit (_t, "\033[J", 3); //erase rest of screen + t->xmit (_t, "\033[J", 3); // erase rest of screen set_blocking (t->rfd); set_blocking (t->wfd); @@ -160,16 +167,13 @@ terminal_getsize (TTY * _t) if (!t) return; - if (ioctl (t->wfd, TIOCGWINSZ, &sz)) - { - t->size.x = CRT_COLS; - t->size.y = CRT_ROWS; - } - else - { - t->size.x = sz.ws_col; - t->size.y = sz.ws_row; - } + if (ioctl (t->wfd, TIOCGWINSZ, &sz)) { + t->size.x = CRT_COLS; + t->size.y = CRT_ROWS; + } else { + t->size.x = sz.ws_col; + t->size.y = sz.ws_row; + } } @@ -199,19 +203,18 @@ terminal_read (TTY * _t, void *buf, int len) terminal_dispatch (); set_nonblocking (t->rfd); - do - { + do { - red = wrap_read (t->rfd, buf, len); - if (red < 0) - return -1; - if (!red) - return done; + red = wrap_read (t->rfd, buf, len); + if (red < 0) + return -1; + if (!red) + return done; - buf += red; - len -= red; - done += red; - } + buf += red; + len -= red; + done += red; + } while (len); @@ -229,20 +232,19 @@ terminal_write (TTY * _t, void *buf, int len) set_blocking (t->wfd); - do - { + do { - writ = wrap_write (t->wfd, buf, len); - if (writ < 0) - return -1; + writ = wrap_write (t->wfd, buf, len); + if (writ < 0) + return -1; - if (!writ) - usleep (1000); + if (!writ) + usleep (1000); - buf += writ; - len -= writ; - done += writ; - } + buf += writ; + len -= writ; + done += writ; + } while (len); @@ -290,7 +292,7 @@ terminal_open (int rfd, int wfd) cfmakeraw (&termios); - //raw_termios (&termios); + // raw_termios (&termios); tcsetattr (wfd, TCSANOW, &termios); diff --git a/src/tty.c b/src/tty.c index 62af184..57962e7 100644 --- a/src/tty.c +++ b/src/tty.c @@ -1,4 +1,4 @@ -/* +/* * tty.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.24 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.23 2008/03/06 16:49:39 james * *** empty log message *** * @@ -81,85 +84,84 @@ static char rcsid[] = "$Id$"; static int speed_t_to_baud (speed_t s) { - switch (s) - { + switch (s) { #ifdef B0 - case B0: - return 0; + case B0: + return 0; #endif #ifdef B50 - case B50: - return 50; + case B50: + return 50; #endif #ifdef B75 - case B75: - return 75; + case B75: + return 75; #endif #ifdef B110 - case B110: - return 110; + case B110: + return 110; #endif #ifdef B134 - case B134: - return 134; + case B134: + return 134; #endif #ifdef B150 - case B150: - return 150; + case B150: + return 150; #endif #ifdef B200 - case B200: - return 200; + case B200: + return 200; #endif #ifdef B300 - case B300: - return 300; + case B300: + return 300; #endif #ifdef B600 - case B600: - return 600; + case B600: + return 600; #endif #ifdef B1200 - case B1200: - return 1200; + case B1200: + return 1200; #endif #ifdef B1800 - case B1800: - return 1800; + case B1800: + return 1800; #endif #ifdef B2400 - case B2400: - return 2400; + case B2400: + return 2400; #endif #ifdef B4800 - case B4800: - return 4800; + case B4800: + return 4800; #endif #ifdef B9600 - case B9600: - return 9600; + case B9600: + return 9600; #endif #ifdef B19200 - case B19200: - return 19200; + case B19200: + return 19200; #endif #ifdef B38400 - case B38400: - return 38400; + case B38400: + return 38400; #endif #ifdef B57600 - case B57600: - return 57600; + case B57600: + return 57600; #endif #ifdef B115200 - case B115200: - return 115200; + case B115200: + return 115200; #endif #ifdef B230400 - case B230400: - return 230400; + case B230400: + return 230400; #endif - } + } return -1; } @@ -167,85 +169,84 @@ speed_t_to_baud (speed_t s) static speed_t baud_to_speed_t (int baud) { - switch (baud) - { + switch (baud) { #ifdef B0 - case 0: - return B0; + case 0: + return B0; #endif #ifdef B50 - case 50: - return B50; + case 50: + return B50; #endif #ifdef B75 - case 75: - return B75; + case 75: + return B75; #endif #ifdef B110 - case 110: - return B110; + case 110: + return B110; #endif #ifdef B134 - case 134: - return B134; + case 134: + return B134; #endif #ifdef B150 - case 150: - return B150; + case 150: + return B150; #endif #ifdef B200 - case 200: - return B200; + case 200: + return B200; #endif #ifdef B300 - case 300: - return B300; + case 300: + return B300; #endif #ifdef B600 - case 600: - return B600; + case 600: + return B600; #endif #ifdef B1200 - case 1200: - return B1200; + case 1200: + return B1200; #endif #ifdef B1800 - case 1800: - return B1800; + case 1800: + return B1800; #endif #ifdef B2400 - case 2400: - return B2400; + case 2400: + return B2400; #endif #ifdef B4800 - case 4800: - return B4800; + case 4800: + return B4800; #endif #ifdef B9600 - case 9600: - return B9600; + case 9600: + return B9600; #endif #ifdef B19200 - case 19200: - return B19200; + case 19200: + return B19200; #endif #ifdef B38400 - case 38400: - return B38400; + case 38400: + return B38400; #endif #ifdef B57600 - case 57600: - return B57600; + case 57600: + return B57600; #endif #ifdef B115200 - case 115200: - return B115200; + case 115200: + return B115200; #endif #ifdef B230400 - case 230400: - return B230400; + case 230400: + return B230400; #endif - } + } return -1; } @@ -255,18 +256,16 @@ tty_pre_select (TTY * t, fd_set * rfds, fd_set * wfds) int line; struct timeval now, dif; - if (t->hanging_up) - { - - gettimeofday (&now, NULL); - timersub (&now, &t->hangup_clock, &dif); - if (dif.tv_sec) - { - line = TIOCM_DTR; - ioctl (t->rfd, TIOCMBIS, &line); - t->hanging_up = 0; - } + if (t->hanging_up) { + + gettimeofday (&now, NULL); + timersub (&now, &t->hangup_clock, &dif); + if (dif.tv_sec) { + line = TIOCM_DTR; + ioctl (t->rfd, TIOCMBIS, &line); + t->hanging_up = 0; } + } FD_SET (t->rfd, rfds); @@ -414,31 +413,28 @@ tty_bit_analyse (Context * c, int err, int ch) bit (p, 0, zc, oc); - for (d = 1; d < 0x100; d <<= 1) - { - bit (p, ch & d, zc, oc); - } + for (d = 1; d < 0x100; d <<= 1) { + bit (p, ch & d, zc, oc); + } bit (p, 1, zc, oc); - if (err) - { - p->biterrs++; - gettimeofday (&p->lasterr, NULL); - } + if (err) { + p->biterrs++; + gettimeofday (&p->lasterr, NULL); + } - if (p->biterrs) - { - log_f (c->l, - "", - ch & 0x01 ? 1 : 0, ch & 0x02 ? 1 : 0, ch & 0x04 ? 1 : 0, - ch & 0x08 ? 1 : 0, ch & 0x10 ? 1 : 0, ch & 0x20 ? 1 : 0, - ch & 0x40 ? 1 : 0, ch & 0x80 ? 1 : 0, p->bitfreq[0], - p->bitfreq[1], p->bitfreq[2], p->bitfreq[3], p->bitfreq[4], - p->bitfreq[5], p->bitfreq[6], p->bitfreq[7], p->bitfreq[8], - p->bitfreq[9]); - } + if (p->biterrs) { + log_f (c->l, + "", + ch & 0x01 ? 1 : 0, ch & 0x02 ? 1 : 0, ch & 0x04 ? 1 : 0, + ch & 0x08 ? 1 : 0, ch & 0x10 ? 1 : 0, ch & 0x20 ? 1 : 0, + ch & 0x40 ? 1 : 0, ch & 0x80 ? 1 : 0, p->bitfreq[0], + p->bitfreq[1], p->bitfreq[2], p->bitfreq[3], p->bitfreq[4], + p->bitfreq[5], p->bitfreq[6], p->bitfreq[7], p->bitfreq[8], + p->bitfreq[9]); + } } @@ -458,64 +454,54 @@ tty_analyse (Context * c) struct timeval now, dif; int i, j, max; - if (!p->biterrs) - { - p->guessed_baud = 0; - return; - } + if (!p->biterrs) { + p->guessed_baud = 0; + return; + } gettimeofday (&now, NULL); timersub (&now, &p->lasterr, &dif); - if (dif.tv_sec > 10) - { - tty_parse_reset (c); - return; - } + if (dif.tv_sec > 10) { + tty_parse_reset (c); + return; + } max = -1; j = 0; - for (i = 0; i < TTY_BITFREQ_LEN; ++i) - { - if (p->bitfreq[i] > max) - { - max = p->bitfreq[i]; - j = i; - } + for (i = 0; i < TTY_BITFREQ_LEN; ++i) { + if (p->bitfreq[i] > max) { + max = p->bitfreq[i]; + j = i; } + } if (c->t) i = tty_get_baud (c->t); else i = -1; - if (j == 1) - { - /*Closest bit edge is one bit, so the baud rate is too low */ - p->guessed_baud = -1; + if (j == 1) { + /* Closest bit edge is one bit, so the baud rate is too low */ + p->guessed_baud = -1; - } - else - { - if (i > 0) - p->guessed_baud = i / j; - else - p->guessed_baud = 0; + } else { + if (i > 0) + p->guessed_baud = i / j; + else + p->guessed_baud = 0; - } + } - if (p->guessed_baud == -1) - { - log_f (c->l, "", - p->biterrs, i); - } - else - { - log_f (c->l, "", - p->biterrs, i, p->guessed_baud); - } + if (p->guessed_baud == -1) { + log_f (c->l, "", + p->biterrs, i); + } else { + log_f (c->l, "", + p->biterrs, i, p->guessed_baud); + } } @@ -539,57 +525,48 @@ tty_parse (Context * c, uint8_t * buf, int len) p = c->tp; - while (len--) - { - - if (p->in_dle) - { - p->in_dle = 0; - switch (*buf) - { - case DLE: - tty_bit_analyse (c, 0, *buf); - err += utf8_parse (c, *buf); - break; - case 0: - p->in_errmark = 1; - break; - default: - log_f (c->l, "%s:%d DLE parsing error: \\377 \\%03o", __FILE__, - __LINE__, *buf); - } - } - else if (p->in_errmark) - { - p->in_errmark = 0; - - log_f (c->l, "", - __FILE__, __LINE__, *buf); - - tty_bit_analyse (c, 1, *buf); - - tty_analyse (c); - - err += utf8_parse (c, *buf); - - err += utf8_parse (c, SYM_CHAR_RESET); - - } - else if (*buf == DLE) - { - p->in_dle = 1; - - } - else - { - tty_bit_analyse (c, 0, *buf); - - tty_analyse (c); - - err += utf8_parse (c, *buf); - - } - buf++; + while (len--) { + + if (p->in_dle) { + p->in_dle = 0; + switch (*buf) { + case DLE: + tty_bit_analyse (c, 0, *buf); + err += utf8_parse (c, *buf); + break; + case 0: + p->in_errmark = 1; + break; + default: + log_f (c->l, "%s:%d DLE parsing error: \\377 \\%03o", __FILE__, + __LINE__, *buf); + } + } else if (p->in_errmark) { + p->in_errmark = 0; + + log_f (c->l, "", + __FILE__, __LINE__, *buf); + + tty_bit_analyse (c, 1, *buf); + + tty_analyse (c); + + err += utf8_parse (c, *buf); + + err += utf8_parse (c, SYM_CHAR_RESET); + + } else if (*buf == DLE) { + p->in_dle = 1; + + } else { + tty_bit_analyse (c, 0, *buf); + + tty_analyse (c); + + err += utf8_parse (c, *buf); + } + buf++; + } return err; } diff --git a/src/tty.h b/src/tty.h index 0766212..b5b3888 100644 --- a/src/tty.h +++ b/src/tty.h @@ -1,4 +1,4 @@ -/* +/* * tty.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.15 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.14 2008/03/03 06:04:42 james * *** empty log message *** * diff --git a/src/utf8.c b/src/utf8.c index fd34fbf..baa03cb 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -1,4 +1,4 @@ -/* +/* * utf8.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.14 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.13 2008/03/06 16:49:39 james * *** empty log message *** * @@ -61,25 +64,24 @@ utf8_flush (Context * c) int i; int err = 0; - switch (u->utf_ptr) - { - case 1: - log_f (c->l, "", u->utf_buf[0]); - break; - case 2: - log_f (c->l, "", - u->utf_buf[0], u->utf_buf[1]); - break; - case 3: - log_f (c->l, "", - u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]); - break; - case 4: - log_f (c->l, - "", - u->utf_buf[0], u->utf_buf[1], u->utf_buf[2], u->utf_buf[3]); - break; - } + switch (u->utf_ptr) { + case 1: + log_f (c->l, "", u->utf_buf[0]); + break; + case 2: + log_f (c->l, "", + u->utf_buf[0], u->utf_buf[1]); + break; + case 3: + log_f (c->l, "", + u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]); + break; + case 4: + log_f (c->l, + "", + u->utf_buf[0], u->utf_buf[1], u->utf_buf[2], u->utf_buf[3]); + break; + } for (i = 0; i < u->utf_ptr; ++i) err += vt102_parse_char (c, u->utf_buf[i]); @@ -97,68 +99,54 @@ utf8_parse (Context * c, uint32_t ch) UTF8 *u = c->u; int err = 0; - if (ch == SYM_CHAR_RESET) - { - u->in_utf8 = 0; + if (ch == SYM_CHAR_RESET) { + u->in_utf8 = 0; + err += vt102_parse_char (c, ch); + return err; + } + + if (!u->in_utf8) { + /* FIXME: for the moment we bodge utf8 support - need to do */ + /* L->R and R->L and double width characters */ + if (ch == 0xb9) // FIXME - OTHER 8 bit control chars + { /* CSI, not a valid utf8 start char */ + err += vt102_parse_char (c, ch); + } else if ((ch & 0xe0) == 0xc0) { /* Start of two byte unicode sequence */ + u->in_utf8 = 1; + u->utf_ptr = 0; + u->utf_buf[u->utf_ptr++] = ch; + u->ch = (ch & 0x1f) << 6; + u->sh = 0; + } else if ((ch & 0xf0) == 0xe0) { /* Start of three byte unicode sequence + */ + u->in_utf8 = 2; + u->utf_ptr = 0; + u->utf_buf[u->utf_ptr++] = ch; + u->ch = (ch & 0x0f) << 12; + u->sh = 6; + } else if ((ch & 0xf8) == 0xf0) { + u->in_utf8 = 3; + u->utf_ptr = 0; + u->utf_buf[u->utf_ptr++] = ch; + u->ch = (ch & 0x07) << 18; + u->sh = 12; + } else { err += vt102_parse_char (c, ch); - return err; - } - - if (!u->in_utf8) - { - /*FIXME: for the moment we bodge utf8 support - need to do */ - /* L->R and R->L and double width characters */ - if (ch == 0xb9) //FIXME - OTHER 8 bit control chars - { /*CSI, not a valid utf8 start char */ - err += vt102_parse_char (c, ch); - } - else if ((ch & 0xe0) == 0xc0) - { /*Start of two byte unicode sequence */ - u->in_utf8 = 1; - u->utf_ptr = 0; - u->utf_buf[u->utf_ptr++] = ch; - u->ch = (ch & 0x1f) << 6; - u->sh = 0; - } - else if ((ch & 0xf0) == 0xe0) - { /*Start of three byte unicode sequence */ - u->in_utf8 = 2; - u->utf_ptr = 0; - u->utf_buf[u->utf_ptr++] = ch; - u->ch = (ch & 0x0f) << 12; - u->sh = 6; - } - else if ((ch & 0xf8) == 0xf0) - { - u->in_utf8 = 3; - u->utf_ptr = 0; - u->utf_buf[u->utf_ptr++] = ch; - u->ch = (ch & 0x07) << 18; - u->sh = 12; - } - else - { - err += vt102_parse_char (c, ch); - } } - else - { - if ((ch & 0xc0) != 0x80) - { - err += utf8_flush (c); - err += vt102_parse_char (c, ch); - } - else - { - u->utf_buf[u->utf_ptr++] = ch; - u->ch |= (ch & 0x3f) << u->sh; - u->sh -= 6; - u->in_utf8--; - - if (!u->in_utf8) - err += vt102_parse_char (c, u->ch); - } + } else { + if ((ch & 0xc0) != 0x80) { + err += utf8_flush (c); + err += vt102_parse_char (c, ch); + } else { + u->utf_buf[u->utf_ptr++] = ch; + u->ch |= (ch & 0x3f) << u->sh; + u->sh -= 6; + u->in_utf8--; + + if (!u->in_utf8) + err += vt102_parse_char (c, u->ch); } + } return err; } @@ -179,32 +167,25 @@ int utf8_encode (char *ptr, int ch) { - if (ch < 0x80) - { - ptr[0] = ch; - return 1; - } - else if (ch < 0x800) - { - ptr[0] = 0xc0 | (ch >> 6); - ptr[1] = 0x80 | (ch & 0x3f); - return 2; - } - else if (ch < 0x10000) - { - ptr[0] = 0xe0 | (ch >> 12); - ptr[1] = 0x80 | ((ch >> 6) & 0x3f); - ptr[2] = 0x80 | (ch & 0x3f); - return 3; - } - else if (ch < 0x1fffff) - { - ptr[0] = 0xf0 | (ch >> 18); - ptr[1] = 0x80 | ((ch >> 12) & 0x3f); - ptr[2] = 0x80 | ((ch >> 6) & 0x3f); - ptr[3] = 0x80 | (ch & 0x3f); - return 4; - } + if (ch < 0x80) { + ptr[0] = ch; + return 1; + } else if (ch < 0x800) { + ptr[0] = 0xc0 | (ch >> 6); + ptr[1] = 0x80 | (ch & 0x3f); + return 2; + } else if (ch < 0x10000) { + ptr[0] = 0xe0 | (ch >> 12); + ptr[1] = 0x80 | ((ch >> 6) & 0x3f); + ptr[2] = 0x80 | (ch & 0x3f); + return 3; + } else if (ch < 0x1fffff) { + ptr[0] = 0xf0 | (ch >> 18); + ptr[1] = 0x80 | ((ch >> 12) & 0x3f); + ptr[2] = 0x80 | ((ch >> 6) & 0x3f); + ptr[3] = 0x80 | (ch & 0x3f); + return 4; + } return 0; } diff --git a/src/utf8.h b/src/utf8.h index f09e2cb..e1958d5 100644 --- a/src/utf8.h +++ b/src/utf8.h @@ -1,4 +1,4 @@ -/* +/* * utf8.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.7 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.6 2008/03/03 06:04:42 james * *** empty log message *** * diff --git a/src/util.c b/src/util.c index d63c142..877a86e 100644 --- a/src/util.c +++ b/src/util.c @@ -1,4 +1,4 @@ -/* +/* * util.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.9 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.8 2008/03/02 10:50:32 staffcvs * *** empty log message *** * diff --git a/src/version.c b/src/version.c index e62a5f9..7770fbd 100644 --- a/src/version.c +++ b/src/version.c @@ -1,4 +1,4 @@ -/* +/* * version.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.4 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.3 2008/02/27 09:42:22 james * *** empty log message *** * diff --git a/src/vt102.c b/src/vt102.c index 604a41e..2105802 100644 --- a/src/vt102.c +++ b/src/vt102.c @@ -1,4 +1,4 @@ -/* +/* * vt102.c: * * Copyright (c) 2008 James McKenzie , @@ -8,8 +8,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.64 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.63 2008/03/07 12:00:58 james * *** empty log message *** * @@ -202,160 +205,100 @@ static char rcsid[] = "$Id$"; */ -/* Termcap he say: - -VT102: - -vt102|dec vt102:\ - :mi:\ - :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100: - -vt100|vt100-am|dec vt100 (w/advanced video):\ - :am:bs:ms:xn:xo:\ - :co#80:it#8:li#24:vt#3:\ - :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\ - :UP=\E[%dA:\ - :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\ - :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\ - :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\ - :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\ - :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\ - :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\ - :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\ - :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\ - :us=\E[4m:tc=vt100+fnkeys: - -vt100+fnkeys|dec vt100 numeric keypad:\ - :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\ - :tc=vt100+pfkeys: - -vt100+pfkeys|dec vt100 numeric keypad:\ - :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad: - -vt100+keypad|dec vt100 numeric keypad no fkeys:\ - :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn: - -*/ - -/* -so the parser needs to be able to at least do -CTRL-G -CTRL-H -CTRL-I -CTRL-J -CTRL-M -CTRL-N - -CTRL-O -ESC7 -ESC8 -ESCH -ESCM -ESC> - -ESC[%dA -ESC[%dB -ESC[%dC -ESC[%dD -ESC[H -ESC[%d;%dH -ESC[J -ESC[K -ESC[1K -ESC[L -ESC[M -ESC[P - -ESC[3g -ESC[4h -ESC[4l -ESC[m -ESC[1m -ESC[4m -ESC[5m -ESC[7m -ESC[%d;%dr - - -ESC[?3l -ESC[?4l -ESC[?5l -ESC[?7h -ESC[?7h -ESC[?7l -ESC[?8h - -ESC(B -ESC)0 - - -TODO: - -ESC(B -ESC)0 - -CTRL-O - -ANSI: - - - -ansi|ansi/pc-term compatible with color:\ - :u6=\E[%i%d;%dR:u7=\E[6n:u9=\E[c:tc=ecma+color:\ - :tc=klone+sgr:tc=ansi-m: -ansi-m|ansi-mono|ANSI X3.64-1979 terminal with ANSI.SYS compatible attributes:\ - :5i:\ - :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\ - :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\ - :cb=\E[1K:ch=\E[%i%dG:ct=\E[2g:cv=\E[%i%dd:ec=\E[%dX:ei=:\ - :im=:kB=\E[Z:kI=\E[L:kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:\ - :nw=\r\E[S:pf=\E[4i:po=\E[5i:s0=\E(B:s1=\E)B:s2=\E*B:\ - :s3=\E+B:ta=\E[I:tc=pcansi-m: -pcansi-m|pcansi-mono|ibm-pc terminal programs claiming to be ansi (mono mode):\ - :am:bs:mi:ms:\ - :co#80:it#8:li#24:\ - :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\ - :cm=\E[%i%d;%dH:cr=^M:ct=\E[2g:dc=\E[P:dl=\E[M:do=\E[B:\ - :ho=\E[H:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\ - :le=\E[D:nd=\E[C:sf=^J:st=\EH:ta=^I:up=\E[A:\ - :tc=klone+sgr-dumb: -klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 m):\ - :as=\E[12m:mb=\E[5m:md=\E[1m:me=\E[0;10m:mk=\E[8m:\ - :mr=\E[7m:se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:tc=klone+acs: -klone+acs|alternate character set for ansi.sys displays:\ - :ac=+\020,\021-\030.^Y0\333`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376:\ - :ae=\E[10m:as=\E[11m: -ecma+color|color control for ECMA-48-compatible terminals:\ - :Co#8:NC#3:pa#64:\ - :AB=\E[4%dm:AF=\E[3%dm:op=\E[39;49m: - - -Ignoreing ones in the VT102 spec - -ESC[%d@ -ESC[I -ESC[....R -ESC[%dS -ESC[%dT -ESC[X -ESC[Z - -ESC[c -*ESC[%db -ESC[....d -ESC[....f -ESC[2g -ESC[4i -ESC[5i -ESC[6n - -ESC(B -ESC)B -ESC*B -ESC+B - - -*/ +/* + * Termcap he say: + * + * VT102: + * + * vt102|dec vt102:\ :mi:\ + * :al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:tc=vt100: + * + * vt100|vt100-am|dec vt100 (w/advanced video):\ :am:bs:ms:xn:xo:\ + * :co#80:it#8:li#24:vt#3:\ + * :DO=\E[%dB:LE=\E[%dD:RA=\E[?7l:RI=\E[%dC:SA=\E[?7h:\ :UP=\E[%dA:\ + * :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~:\ + * :ae=^O:as=^N:bl=^G:cb=\E[1K:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\ + * :cm=\E[%i%d;%dH:cr=^M:cs=\E[%i%d;%dr:ct=\E[3g:do=^J:\ + * :eA=\E(B\E)0:ho=\E[H:kb=^H:kd=\EOB:ke=\E[?1l\E>:kl=\EOD:\ + * :kr=\EOC:ks=\E[?1h\E=:ku=\EOA:le=^H:mb=\E[5m:md=\E[1m:\ + * :me=\E[m\017:mr=\E[7m:nd=\E[C:rc=\E8:\ + * :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:sc=\E7:se=\E[m:\ + * :sf=^J:so=\E[7m:sr=\EM:st=\EH:ta=^I:ue=\E[m:up=\E[A:\ + * :us=\E[4m:tc=vt100+fnkeys: + * + * vt100+fnkeys|dec vt100 numeric keypad:\ + * :k0=\EOy:k5=\EOt:k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:\ + * :tc=vt100+pfkeys: + * + * vt100+pfkeys|dec vt100 numeric keypad:\ + * :@8=\EOM:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:tc=vt100+keypad: + * + * vt100+keypad|dec vt100 numeric keypad no fkeys:\ + * :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn: + * + */ + +/* + * so the parser needs to be able to at least do CTRL-G CTRL-H CTRL-I + * CTRL-J CTRL-M CTRL-N + * + * CTRL-O ESC7 ESC8 ESCH ESCM ESC> + * + * ESC[%dA ESC[%dB ESC[%dC ESC[%dD ESC[H ESC[%d;%dH ESC[J ESC[K ESC[1K + * ESC[L ESC[M ESC[P + * + * ESC[3g ESC[4h ESC[4l ESC[m ESC[1m ESC[4m ESC[5m ESC[7m ESC[%d;%dr + * + * + * ESC[?3l ESC[?4l ESC[?5l ESC[?7h ESC[?7h ESC[?7l ESC[?8h + * + * ESC(B ESC)0 + * + * + * TODO: + * + * ESC(B ESC)0 + * + * CTRL-O + * + * ANSI: + * + * + * + * ansi|ansi/pc-term compatible with color:\ + * :u6=\E[%i%d;%dR:u7=\E[6n:u9=\E[c:tc=ecma+color:\ + * :tc=klone+sgr:tc=ansi-m: ansi-m|ansi-mono|ANSI X3.64-1979 terminal with + * ANSI.SYS compatible attributes:\ :5i:\ + * :AL=\E[%dL:DC=\E[%dP:DL=\E[%dM:DO=\E[%dB:IC=\E[%d@:\ + * :LE=\E[%dD:RI=\E[%dC:SF=\E[%dS:SR=\E[%dT:UP=\E[%dA:\ + * :cb=\E[1K:ch=\E[%i%dG:ct=\E[2g:cv=\E[%i%dd:ec=\E[%dX:ei=:\ + * :im=:kB=\E[Z:kI=\E[L:kb=^H:kd=\E[B:kl=\E[D:kr=\E[C:ku=\E[A:\ + * :nw=\r\E[S:pf=\E[4i:po=\E[5i:s0=\E(B:s1=\E)B:s2=\E*B:\ + * :s3=\E+B:ta=\E[I:tc=pcansi-m: pcansi-m|pcansi-mono|ibm-pc terminal + * programs claiming to be ansi (mono mode):\ :am:bs:mi:ms:\ + * :co#80:it#8:li#24:\ + * :al=\E[L:bl=^G:bt=\E[Z:cd=\E[J:ce=\E[K:cl=\E[H\E[J:\ + * :cm=\E[%i%d;%dH:cr=^M:ct=\E[2g:dc=\E[P:dl=\E[M:do=\E[B:\ + * :ho=\E[H:kb=^H:kd=\E[B:kh=\E[H:kl=\E[D:kr=\E[C:ku=\E[A:\ + * :le=\E[D:nd=\E[C:sf=^J:st=\EH:ta=^I:up=\E[A:\ :tc=klone+sgr-dumb: + * klone+sgr-dumb|attribute control for ansi.sys displays (no ESC [ 11 + * m):\ :as=\E[12m:mb=\E[5m:md=\E[1m:me=\E[0;10m:mk=\E[8m:\ + * :mr=\E[7m:se=\E[m:so=\E[7m:ue=\E[m:us=\E[4m:tc=klone+acs: + * klone+acs|alternate character set for ansi.sys displays:\ + * :ac=+\020,\021-\030.^Y0\333`\004a\261f\370g\361h\260j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376:\ + * :ae=\E[10m:as=\E[11m: ecma+color|color control for ECMA-48-compatible terminals:\ :Co#8:NC#3:pa#64:\ :AB=\E[4%dm:AF=\E[3%dm:op=\E[39;49m: + * + * + * Ignoreing ones in the VT102 spec + * + * ESC[%d@ ESC[I ESC[....R ESC[%dS ESC[%dT ESC[X ESC[Z + * + * ESC[c *ESC[%db ESC[....d ESC[....f ESC[2g ESC[4i ESC[5i ESC[6n + * + * ESC(B ESC)B ESC*B ESC+B + * + * + */ #include "project.h" #include "syslog.h" @@ -366,7 +309,10 @@ ESC+B static char terminal_id[] = "vt102"; -/* number of aditional chars after \033 ... to complete the escape if it's fixed length*/ +/* + * number of aditional chars after \033 ... to complete the escape if it's + * fixed length + */ int vt102_cmd_length[TABLE_LENGTH] = { ['('] = 1, [')'] = 1, @@ -377,7 +323,10 @@ int vt102_cmd_length[TABLE_LENGTH] = { ['Y'] = 2, }; -/* method for determining end if if's not fixed length, -ve numbers from #defines, +ve are literals */ +/* + * method for determining end if if's not fixed length, -ve numbers from + * #defines, +ve are literals + */ #define CSI_ENDER -1 int vt102_cmd_termination[TABLE_LENGTH] = { [']'] = 7, @@ -448,11 +397,10 @@ vt102_crt_update (Context * c) v->crt.hide_cursor = v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1; - if (v->current_line.y != v->pos.y) - { - vt102_log_line (c, v->current_line.y); - v->current_line = v->pos; - } + if (v->current_line.y != v->pos.y) { + vt102_log_line (c, v->current_line.y); + v->current_line = v->pos; + } if (c->d) cmd_show_status (c->d, c); @@ -493,29 +441,31 @@ vt102_log_line (Context * c, int line) return; - for (; e.x > 0; --e.x) - { - if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ') - break; - } - - for (; p.x <= e.x; ++p.x) - { - int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr; - if (ch < 32) - ch = ' '; - logptr += utf8_encode (logptr, ch); - } + for (; e.x > 0; --e.x) { + if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ') + break; + } + + for (; p.x <= e.x; ++p.x) { + int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr; + if (ch < 32) + ch = ' '; + logptr += utf8_encode (logptr, ch); + } *logptr = 0; c->l->log (c->l, logbuf); } -/*Called for every upward scroll with same args*/ +/* + * Called for every upward scroll with same args + */ void vt102_history (Context * c, CRT_Pos t, CRT_Pos b) { -/*Only log if it scrolls off the top*/ + /* + * Only log if it scrolls off the top + */ if (t.y) return; @@ -543,14 +493,11 @@ vt102_cursor_normalize (VT102 * v) { CRT_Pos *top, *bottom; - if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE]) - { - vt102_clip_cursor (v, v->top_margin, v->bottom_margin); - } - else - { - vt102_clip_cursor (v, v->screen_start, v->screen_end); - } + if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE]) { + vt102_clip_cursor (v, v->top_margin, v->bottom_margin); + } else { + vt102_clip_cursor (v, v->screen_start, v->screen_end); + } } @@ -567,18 +514,21 @@ vt102_cursor_advance_line (Context * c) VT102 *v = c->v; int couldscroll = in_margins (v, v->pos); -/*have wraped off end of last line in scrolling region */ -/* (|| not necessary, but shuts compiler up */ - if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) && - (couldscroll)) - { - vt102_log_line (c, v->pos.y); + /* + * have wraped off end of last line in scrolling region + */ + /* + * (|| not necessary, but shuts compiler up + */ + if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) + && (couldscroll)) { + vt102_log_line (c, v->pos.y); - vt102_history (c, v->top_margin, v->bottom_margin); + vt102_history (c, v->top_margin, v->bottom_margin); - crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color); - return; - } + crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color); + return; + } if (v->pos.y != v->screen_end.y) v->pos.y++; @@ -592,16 +542,19 @@ vt102_cursor_retreat_line (Context * c) VT102 *v = c->v; int couldscroll = in_margins (v, v->pos); -/*have wraped off end of last line in scrolling region */ -/* (|| not necessary, but shuts compiler up */ + /* + * have wraped off end of last line in scrolling region + */ + /* + * (|| not necessary, but shuts compiler up + */ if (((v->pos.y == v->top_margin.y) || (v->pos.y == v->screen_start.y)) && - (couldscroll)) - { - vt102_log_line (c, v->pos.y); + (couldscroll)) { + vt102_log_line (c, v->pos.y); - crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1, v->color); - return; - } + crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1, v->color); + return; + } if (v->pos.y != v->screen_start.y) v->pos.y--; @@ -619,22 +572,23 @@ vt102_do_pending_wrap (Context * c) if (!v->pending_wrap) return; -/*End of line but no autowrap, nothing to do*/ + /* + * End of line but no autowrap, nothing to do + */ if (!autowrap) return; -/*End of screen and not allowed to scroll, nothing to do*/ + /* + * End of screen and not allowed to scroll, nothing to do + */ if ((v->pos.y == v->screen_end.y) && (!couldscroll)) return; - if (couldscroll) - { - v->pos.x = v->top_margin.x; - } - else - { - v->pos.x = 0; - } + if (couldscroll) { + v->pos.x = v->top_margin.x; + } else { + v->pos.x = 0; + } vt102_cursor_advance_line (c); } @@ -644,13 +598,14 @@ vt102_cursor_advance (Context * c) { VT102 *v = c->v; - if (v->pos.x < v->bottom_margin.x) - { -/*Normal advance*/ - v->pos.x++; - v->pending_wrap = 0; - return; - } + if (v->pos.x < v->bottom_margin.x) { + /* + * Normal advance + */ + v->pos.x++; + v->pending_wrap = 0; + return; + } v->pending_wrap++; if (!c->v->xn_glitch) vt102_do_pending_wrap (c); @@ -661,10 +616,9 @@ vt102_cursor_advance (Context * c) void vt102_cursor_retreat (VT102 * v) { - if (v->pos.x != v->top_margin.x) - { - v->pos.x--; - } + if (v->pos.x != v->top_margin.x) { + v->pos.x--; + } v->pending_wrap = 0; } @@ -676,22 +630,20 @@ vt102_reset_tabs (VT102 * v) memset (v->tabs, 0, sizeof (v->tabs)); - for (i = 0; i < VT102_MAX_COLS; i += 8) - { - v->tabs[i]++; - } + for (i = 0; i < VT102_MAX_COLS; i += 8) { + v->tabs[i]++; + } } void vt102_cursor_advance_tab (VT102 * v) { if (v->pos.x == v->bottom_margin.x) return; - while (v->pos.x < v->bottom_margin.x) - { - v->pos.x++; - if (v->tabs[v->pos.x]) - break; - } + while (v->pos.x < v->bottom_margin.x) { + v->pos.x++; + if (v->tabs[v->pos.x]) + break; + } v->pending_wrap = 0; } @@ -700,12 +652,11 @@ vt102_cursor_retreat_tab (VT102 * v) { if (v->pos.x == v->top_margin.x) return; - while (v->pos.x > v->top_margin.x) - { - v->pos.x--; - if (v->tabs[v->pos.x]) - break; - } + while (v->pos.x > v->top_margin.x) { + v->pos.x--; + if (v->tabs[v->pos.x]) + break; + } v->pending_wrap = 0; } @@ -719,16 +670,13 @@ vt102_cursor_home (VT102 * v) vt102_cursor_absolute (VT102 * v, int x, int y) { - if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE]) - { - v->pos.x = x + v->top_margin.x; - v->pos.y = y + v->top_margin.y; - } - else - { - v->pos.x = x; - v->pos.y = y; - } + if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE]) { + v->pos.x = x + v->top_margin.x; + v->pos.y = y + v->top_margin.y; + } else { + v->pos.x = x; + v->pos.y = y; + } vt102_cursor_normalize (v); v->pending_wrap = 0; } @@ -751,15 +699,16 @@ vt102_delete_from_line (VT102 * v, CRT_Pos p) if (n < 0) return; - if (n) - { + if (n) { - memmove (&v->crt.screen[CRT_ADDR_POS (&p)], - &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n); - } + memmove (&v->crt.screen[CRT_ADDR_POS (&p)], + &v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n); + } v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' '; -/*But not attr due to vt102 bug*/ + /* + * But not attr due to vt102 bug + */ } void @@ -770,12 +719,11 @@ vt102_insert_into_line (VT102 * v, CRT_Pos p) if (n < 0) return; - if (n) - { + if (n) { - memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1], - &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n); - } + memmove (&v->crt.screen[CRT_ADDR_POS (&p) + 1], + &v->crt.screen[CRT_ADDR_POS (&p)], sizeof (CRT_CA) * n); + } v->crt.screen[CRT_ADDR_POS (&p)].chr = ' '; v->crt.screen[CRT_ADDR_POS (&p)].attr = CRT_ATTR_NORMAL; @@ -791,46 +739,42 @@ vt102_change_mode (Context * c, int private, char *ns, int set) int m; - if (*ns) - { - m = atoi (ns); - } - else - { - m = 1; - } + if (*ns) { + m = atoi (ns); + } else { + m = 1; + } if (m < 0) return; if (m >= VT102_NMODES) return; - if (private) - { - v->private_modes[m] = set; - switch (m) - { - case VT102_PRIVATE_MODE_CURSOR_MODE: - if (v->application_keypad_mode) - v->private_modes[m] = 0; - break; - case VT102_PRIVATE_MODE_ORIGIN_MODE: - vt102_cursor_home (v); - break; - case VT102_PRIVATE_MODE_132COLS: - /* We don't implement 132 col mode - yet */ - - v->current_size.x = - v-> - private_modes[VT102_PRIVATE_MODE_132COLS] ? VT102_COLS_132 : - VT102_COLS_80; + if (private) { + v->private_modes[m] = set; + switch (m) { + case VT102_PRIVATE_MODE_CURSOR_MODE: + if (v->application_keypad_mode) + v->private_modes[m] = 0; + break; + case VT102_PRIVATE_MODE_ORIGIN_MODE: + vt102_cursor_home (v); + break; + case VT102_PRIVATE_MODE_132COLS: + /* + * We don't implement 132 col mode - yet + */ - vt102_do_resize (c); - break; - } + v->current_size.x = + v-> + private_modes[VT102_PRIVATE_MODE_132COLS] ? VT102_COLS_132 : + VT102_COLS_80; + vt102_do_resize (c); + break; } - else + + } else v->modes[m] = set; } @@ -848,36 +792,33 @@ vt102_parse_mode_string (Context * c, char *buf, int len) len--; - if (*buf == '?') - { - private++; - buf++; - len--; - } + if (*buf == '?') { + private++; + buf++; + len--; + } if (len < 0) return; - while (len--) - { - if (*buf == ';') - { - vt102_change_mode (c, private, &num[o], last == 'h'); - memset (num, 0, sizeof (num)); - o = sizeof (num) - 1; - buf++; - continue; - } + while (len--) { + if (*buf == ';') { + vt102_change_mode (c, private, &num[o], last == 'h'); + memset (num, 0, sizeof (num)); + o = sizeof (num) - 1; + buf++; + continue; + } - num[0] = num[1]; - num[1] = num[2]; - num[2] = *buf; + num[0] = num[1]; + num[1] = num[2]; + num[2] = *buf; - if (o) - o--; + if (o) + o--; - buf++; - } + buf++; + } vt102_change_mode (c, private, &num[o], last == 'h'); @@ -890,109 +831,105 @@ vt102_change_attr (VT102 * v, char *na) int a; - if (*na) - { - a = atoi (na); - } - else - { - a = 0; - } - - switch (a) - { - case 0: - v->attr = CRT_ATTR_NORMAL; - v->color = CRT_COLOR_NORMAL; - break; - case 1: - v->attr |= CRT_ATTR_BOLD; - break; - case 21: - case 22: - v->attr &= ~CRT_ATTR_BOLD; - break; - case 4: - v->attr |= CRT_ATTR_UNDERLINE; - break; - case 24: - v->attr &= ~CRT_ATTR_UNDERLINE; - break; - case 5: - v->attr |= CRT_ATTR_BLINK; - break; - case 25: - v->attr &= ~CRT_ATTR_BLINK; - break; - case 7: - v->attr |= CRT_ATTR_REVERSE; - break; - case 27: - v->attr &= ~CRT_ATTR_REVERSE; - break; - case 30: - case 31: - case 32: - case 33: - case 34: - case 35: - case 36: - case 37: - v->color &= ~CRT_COLOR_FG_MASK; - v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK; - break; - case 90: - case 91: - case 92: - case 93: - case 94: - case 95: - case 96: - case 97: - v->color &= ~CRT_COLOR_FG_MASK; - v->color |= - (((a - - 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) & - CRT_COLOR_FG_MASK; - break; - case 39: - case 99: - v->color &= ~CRT_COLOR_FG_MASK; - v->color |= - (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK; - break; - case 40: - case 41: - case 42: - case 43: - case 44: - case 45: - case 46: - case 47: - v->color &= ~CRT_COLOR_BG_MASK; - v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK; - break; - case 100: - case 101: - case 102: - case 103: - case 104: - case 105: - case 106: - case 107: - v->color &= ~CRT_COLOR_BG_MASK; - v->color |= - (((a - - 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) & - CRT_COLOR_BG_MASK; - break; - case 49: - case 109: - v->color &= ~CRT_COLOR_BG_MASK; - v->color |= - (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK; - break; - } + if (*na) { + a = atoi (na); + } else { + a = 0; + } + + switch (a) { + case 0: + v->attr = CRT_ATTR_NORMAL; + v->color = CRT_COLOR_NORMAL; + break; + case 1: + v->attr |= CRT_ATTR_BOLD; + break; + case 21: + case 22: + v->attr &= ~CRT_ATTR_BOLD; + break; + case 4: + v->attr |= CRT_ATTR_UNDERLINE; + break; + case 24: + v->attr &= ~CRT_ATTR_UNDERLINE; + break; + case 5: + v->attr |= CRT_ATTR_BLINK; + break; + case 25: + v->attr &= ~CRT_ATTR_BLINK; + break; + case 7: + v->attr |= CRT_ATTR_REVERSE; + break; + case 27: + v->attr &= ~CRT_ATTR_REVERSE; + break; + case 30: + case 31: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + v->color &= ~CRT_COLOR_FG_MASK; + v->color |= ((a - 30) << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK; + break; + case 90: + case 91: + case 92: + case 93: + case 94: + case 95: + case 96: + case 97: + v->color &= ~CRT_COLOR_FG_MASK; + v->color |= + (((a - + 90) | CRT_COLOR_INTENSITY) << CRT_COLOR_FG_SHIFT) & + CRT_COLOR_FG_MASK; + break; + case 39: + case 99: + v->color &= ~CRT_COLOR_FG_MASK; + v->color |= + (CRT_FGCOLOR_NORMAL << CRT_COLOR_FG_SHIFT) & CRT_COLOR_FG_MASK; + break; + case 40: + case 41: + case 42: + case 43: + case 44: + case 45: + case 46: + case 47: + v->color &= ~CRT_COLOR_BG_MASK; + v->color |= ((a - 40) << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK; + break; + case 100: + case 101: + case 102: + case 103: + case 104: + case 105: + case 106: + case 107: + v->color &= ~CRT_COLOR_BG_MASK; + v->color |= + (((a - + 100) | CRT_COLOR_INTENSITY) << CRT_COLOR_BG_SHIFT) & + CRT_COLOR_BG_MASK; + break; + case 49: + case 109: + v->color &= ~CRT_COLOR_BG_MASK; + v->color |= + (CRT_BGCOLOR_NORMAL << CRT_COLOR_BG_SHIFT) & CRT_COLOR_BG_MASK; + break; + } } @@ -1013,26 +950,24 @@ vt102_parse_attr_string (VT102 * v, char *buf, int len) if (len < 0) return; - while (len--) - { - if (*buf == ';') - { - vt102_change_attr (v, &num[o]); - memset (num, 0, sizeof (num)); - o = sizeof (num) - 1; - buf++; - continue; - } + while (len--) { + if (*buf == ';') { + vt102_change_attr (v, &num[o]); + memset (num, 0, sizeof (num)); + o = sizeof (num) - 1; + buf++; + continue; + } - num[0] = num[1]; - num[1] = num[2]; - num[2] = *buf; + num[0] = num[1]; + num[1] = num[2]; + num[2] = *buf; - if (o) - o--; + if (o) + o--; - buf++; - } + buf++; + } vt102_change_attr (v, &num[o]); } @@ -1070,18 +1005,14 @@ vt102_regular_char (Context * c, VT102 * v, uint32_t ch) v->last_reg_char = ch; - if (ch < VT102_CHARSET_SIZE) - { - int cs; - if ((cs = vt102_charset_c0[ch])) - { - ch = cs; - } - else if ((cs = charset_from_csid[v->g[v->cs]][ch])) - { - ch = cs; - } + if (ch < VT102_CHARSET_SIZE) { + int cs; + if ((cs = vt102_charset_c0[ch])) { + ch = cs; + } else if ((cs = charset_from_csid[v->g[v->cs]][ch])) { + ch = cs; } + } v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch; v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr; v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color; @@ -1092,11 +1023,10 @@ vt102_regular_char (Context * c, VT102 * v, uint32_t ch) vt102_send_id (Context * c, char *buf) { - if (c->t) - { - int l = strlen (buf); - c->t->xmit (c->t, buf, l); - } + if (c->t) { + int l = strlen (buf); + c->t->xmit (c->t, buf, l); + } } void @@ -1106,30 +1036,28 @@ vt102_scs (Context * c, int g, int s) int cs = VT102_CSID_US; - switch (s) - { - case 'A': - cs = VT102_CSID_UK; - break; - case '1': - case '2': - case 'B': - cs = VT102_CSID_US; - break; - case '0': - cs = VT102_CSID_GL; - break; - } - - switch (g) - { - case '(': - v->g[0] = cs; - break; - case ')': - v->g[1] = cs; - break; - } + switch (s) { + case 'A': + cs = VT102_CSID_UK; + break; + case '1': + case '2': + case 'B': + cs = VT102_CSID_US; + break; + case '0': + cs = VT102_CSID_GL; + break; + } + + switch (g) { + case '(': + v->g[0] = cs; + break; + case ')': + v->g[1] = cs; + break; + } } @@ -1148,280 +1076,264 @@ vt102_parse_csi (Context * c, char *buf, int len) last = buf[len - 1]; - if (len > 2) - { - narg = atoi (arg); - } - else - { - narg = 1; - } + if (len > 2) { + narg = atoi (arg); + } else { + narg = 1; + } + + switch (buf[0]) { + case '[': /* CSI */ + switch (last) { + case '@': /* ICH */ + while (narg--) + vt102_insert_into_line (v, v->pos); + break; + case 'A': /* CUU */ + vt102_cursor_relative (v, 0, -narg); + break; + case 'e': /* VPR */ + case 'B': /* CUD */ + vt102_cursor_relative (v, 0, narg); + break; + case 'a': /* HPR */ + case 'C': /* CUF */ + vt102_cursor_relative (v, narg, 0); + break; + case 'D': /* CUB */ + vt102_cursor_relative (v, -narg, 0); + break; + case 'E': /* CNL */ + vt102_cursor_relative (v, 0, narg); + vt102_cursor_carriage_return (v); + break; + case 'F': /* CPL */ + vt102_cursor_relative (v, 0, -narg); + vt102_cursor_carriage_return (v); + break; + case 'G': + /* CHG */ + vt102_cursor_absolute (v, narg - 1, v->pos.y); + break; + case 'H': /* CUP */ + case 'f': /* HVP */ + { + int x, y; - switch (buf[0]) - { - case '[': /*CSI*/ - switch (last) - { - case '@': /*ICH*/ - while (narg--) - vt102_insert_into_line (v, v->pos); - break; - case 'A': /*CUU*/ - vt102_cursor_relative (v, 0, -narg); - break; - case 'e': /*VPR*/ - case 'B': /*CUD*/ - vt102_cursor_relative (v, 0, narg); - break; - case 'a': /*HPR*/ - case 'C': /*CUF*/ - vt102_cursor_relative (v, narg, 0); - break; - case 'D': /*CUB*/ - vt102_cursor_relative (v, -narg, 0); - break; - case 'E': /*CNL*/ - vt102_cursor_relative (v, 0, narg); - vt102_cursor_carriage_return (v); - break; - case 'F': /*CPL*/ - vt102_cursor_relative (v, 0, -narg); - vt102_cursor_carriage_return (v); - break; - case 'G': /*CHG*/ - vt102_cursor_absolute (v, narg - 1, v->pos.y); - break; - case 'H': /*CUP*/ - case 'f': /*HVP*/ - { - int x, y; + y = narg - 1; - y = narg - 1; + ptr = index (arg, ';'); + if (ptr) + x = atoi (ptr + 1) - 1; + else + x = 0; - ptr = index (arg, ';'); - if (ptr) - x = atoi (ptr + 1) - 1; - else - x = 0; + vt102_cursor_absolute (v, x, y); + } + break; + case 'I': /* CHT */ + while (narg--) + vt102_cursor_advance_tab (c->v); + break; + case 'J': /* ED */ + if (len == 2) + narg = 0; /* Different default */ + switch (narg) { + case 0: + crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color); + break; + case 1: + crt_erase (&v->crt, v->screen_start, v->pos, 1, v->color); + break; + case 2: + crt_erase (&v->crt, v->screen_start, v->screen_end, 1, v->color); + break; + } + break; + case 'K': /* EL */ + { + CRT_Pos ls = { 0, v->pos.y }; + CRT_Pos le = { v->current_size.x - 1, v->pos.y }; + if (len == 2) + narg = 0; /* Different default */ - vt102_cursor_absolute (v, x, y); - } - break; - case 'I': /*CHT*/ - while (narg--) - vt102_cursor_advance_tab (c->v); + switch (narg) { + case 0: + crt_erase (&v->crt, v->pos, le, 1, v->color); break; - case 'J': /*ED*/ - if (len == 2) - narg = 0; /*Different default */ - switch (narg) - { - case 0: - crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color); - break; - case 1: - crt_erase (&v->crt, v->screen_start, v->pos, 1, v->color); - break; - case 2: - crt_erase (&v->crt, v->screen_start, v->screen_end, 1, - v->color); - break; - } + case 1: + crt_erase (&v->crt, ls, v->pos, 1, v->color); break; - case 'K': /*EL*/ - { - CRT_Pos ls = { 0, v->pos.y }; - CRT_Pos le = { v->current_size.x - 1, v->pos.y }; - if (len == 2) - narg = 0; /*Different default */ - - switch (narg) - { - case 0: - crt_erase (&v->crt, v->pos, le, 1, v->color); - break; - case 1: - crt_erase (&v->crt, ls, v->pos, 1, v->color); - break; - case 2: - crt_erase (&v->crt, ls, le, 1, v->color); - break; - } - } + case 2: + crt_erase (&v->crt, ls, le, 1, v->color); break; + } + } + break; - case 'L': /*IL*/ - if ((v->pos.y >= v->top_margin.y) - && (v->pos.y <= v->bottom_margin.y)) - { - while (narg--) - crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1, - v->color); - } - break; + case 'L': /* IL */ + if ((v->pos.y >= v->top_margin.y) + && (v->pos.y <= v->bottom_margin.y)) { + while (narg--) + crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1, v->color); + } + break; - case 'M': /*DL*/ - if ((v->pos.y >= v->top_margin.y) - && (v->pos.y <= v->bottom_margin.y)) - { - while (narg--) - { - vt102_history (c, v->pos, v->bottom_margin); - crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1, - v->color); - } - } - break; - case 'P': /*DCH*/ - while (narg--) - vt102_delete_from_line (v, v->pos); - break; - case 'S': /*SU*/ - while (narg--) - { - vt102_history (c, v->top_margin, v->bottom_margin); - crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, - v->color); - } - break; - case 'T': /*SD*/ - while (narg--) - crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1, - v->color); - break; - case 'X': /*ECH*/ - { - CRT_Pos end = v->pos; - if (!narg) - narg++; - - end.x += narg - 1; - if (end.x > v->bottom_margin.x) - end.x = v->bottom_margin.x; - - crt_erase (&v->crt, v->pos, end, 1, v->color); - } - break; - case 'Z': /*CBT*/ - while (narg--) - vt102_cursor_retreat_tab (c->v); - break; - case '`': /*HPA*/ - vt102_cursor_absolute (v, narg - 1, v->pos.y); - break; - case 'b': /*REP*/ - while (narg--) - { - vt102_regular_char (c, v, v->last_reg_char); - err += vt102_rx_hook (c, v->last_reg_char); - } - break; - case 'c': /*DA*/ - /* For some obscure reason some programs seem to send */ - /* CSI [ ? .. c, which we ignore */ - if (buf[1] != '?') - vt102_send_id (c, "\033[?2c"); - break; - case 'd': /*VPA*/ - vt102_cursor_absolute (v, v->pos.x, narg - 1); - break; - case 'g': /*TBC*/ - if (len == 2) - narg = 0; /*Different default */ - - switch (narg) - { - case 0: - v->tabs[v->pos.x] = 0; - break; - case 2: //FIXME: - LA120 says current line only WTF? - case 3: - memset (v->tabs, 0, sizeof (v->tabs)); - break; - } - break; + case 'M': /* DL */ + if ((v->pos.y >= v->top_margin.y) + && (v->pos.y <= v->bottom_margin.y)) { + while (narg--) { + vt102_history (c, v->pos, v->bottom_margin); + crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1, v->color); + } + } + break; + case 'P': /* DCH */ + while (narg--) + vt102_delete_from_line (v, v->pos); + break; + case 'S': /* SU */ + while (narg--) { + vt102_history (c, v->top_margin, v->bottom_margin); + crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1, v->color); + } + break; + case 'T': /* SD */ + while (narg--) + crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1, + v->color); + break; + case 'X': /* ECH */ + { + CRT_Pos end = v->pos; + if (!narg) + narg++; - case 'i': /*MC*/ //Printer commands - //FIXME - break; - case 'h': /*SM*/ - case 'l': /*RM*/ - vt102_parse_mode_string (c, &buf[1], len - 1); - break; - case 'm': /*SGR*/ - vt102_parse_attr_string (v, &buf[1], len - 1); - break; - case 'n': /*DSR*/ //Device status report - switch (buf[1]) - { - case '5': - vt102_send_id (c, "\033[0n"); - break; - case '6': /*CPR*/ - if (c->t) - { - char buf[16]; - int i; - i = - sprintf (buf, "\033[%d;%dR", v->pos.y + 1, v->pos.x + 1); - c->t->xmit (c->t, buf, i); - } - break; - default: - //?15n printer status - log_f (c->l, "<%s:%d unhandled DSR: \\033%s>", __FILE__, - __LINE__, buf); - } - break; - case 'q': /*DECLL*/ //Load LED on off - break; - case 'r': /*DECSTBM*/ - v->top_margin = v->screen_start; - v->bottom_margin = v->screen_end; - - if ((len > 2) && (ptr = index (arg, ';'))) - { - ptr++; - v->top_margin.y = narg - 1; - v->bottom_margin.y = atoi (ptr) - 1; - } - - if (v->top_margin.y < v->screen_start.y) - v->top_margin.y = v->screen_start.y; - if (v->top_margin.y > v->screen_end.y) - v->top_margin.y = v->screen_end.y; - if (v->bottom_margin.y < v->screen_start.y) - v->bottom_margin.y = v->screen_start.y; - if (v->bottom_margin.y > v->screen_end.y) - v->bottom_margin.y = v->screen_end.y; - - vt102_cursor_home (v); - break; - case 's': /*SCP*/ - v->saved.pos = v->pos; - break; - case 'u': /*RCP*/ - v->pos = v->saved.pos; - vt102_cursor_normalize (v); - v->pending_wrap = 0; - break; - case 'y': /*DECTST*/ //Invoke confidence test - break; - case 'z': /*DECVERP*/ //request terminal parameters - break; + end.x += narg - 1; + if (end.x > v->bottom_margin.x) + end.x = v->bottom_margin.x; + + crt_erase (&v->crt, v->pos, end, 1, v->color); + } + break; + case 'Z': /* CBT */ + while (narg--) + vt102_cursor_retreat_tab (c->v); + break; + case '`': /* HPA */ + vt102_cursor_absolute (v, narg - 1, v->pos.y); + break; + case 'b': /* REP */ + while (narg--) { + vt102_regular_char (c, v, v->last_reg_char); + err += vt102_rx_hook (c, v->last_reg_char); + } + break; + case 'c': /* DA */ + /* For some obscure reason some programs seem to send */ + /* CSI [ ? .. c, which we ignore */ + if (buf[1] != '?') + vt102_send_id (c, "\033[?2c"); + break; + case 'd': /* VPA */ + vt102_cursor_absolute (v, v->pos.x, narg - 1); + break; + case 'g': /* TBC */ + if (len == 2) + narg = 0; /* Different default */ - default: - log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__, - buf); + switch (narg) { + case 0: + v->tabs[v->pos.x] = 0; + break; + case 2: // FIXME: - LA120 says current line only WTF? + case 3: + memset (v->tabs, 0, sizeof (v->tabs)); + break; + } + break; - ; + case 'i': /* MC */ + // Printer commands + // FIXME + break; + case 'h': /* SM */ + case 'l': /* RM */ + vt102_parse_mode_string (c, &buf[1], len - 1); + break; + case 'm': /* SGR */ + vt102_parse_attr_string (v, &buf[1], len - 1); + break; + case 'n': /* DSR */ + // Device status report + switch (buf[1]) { + case '5': + vt102_send_id (c, "\033[0n"); + break; + case '6': /* CPR */ + if (c->t) { + char buf[16]; + int i; + i = sprintf (buf, "\033[%d;%dR", v->pos.y + 1, v->pos.x + 1); + c->t->xmit (c->t, buf, i); } + break; + default: + // ?15n printer status + log_f (c->l, "<%s:%d unhandled DSR: \\033%s>", __FILE__, + __LINE__, buf); + } + break; + case 'q': /* DECLL */ + // Load LED on off + break; + case 'r': /* DECSTBM */ + v->top_margin = v->screen_start; + v->bottom_margin = v->screen_end; + + if ((len > 2) && (ptr = index (arg, ';'))) { + ptr++; + v->top_margin.y = narg - 1; + v->bottom_margin.y = atoi (ptr) - 1; + } + + if (v->top_margin.y < v->screen_start.y) + v->top_margin.y = v->screen_start.y; + if (v->top_margin.y > v->screen_end.y) + v->top_margin.y = v->screen_end.y; + if (v->bottom_margin.y < v->screen_start.y) + v->bottom_margin.y = v->screen_start.y; + if (v->bottom_margin.y > v->screen_end.y) + v->bottom_margin.y = v->screen_end.y; + + vt102_cursor_home (v); + break; + case 's': /* SCP */ + v->saved.pos = v->pos; + break; + case 'u': /* RCP */ + v->pos = v->saved.pos; + vt102_cursor_normalize (v); + v->pending_wrap = 0; + break; + case 'y': /* DECTST */ + // Invoke confidence test + break; + case 'z': /* DECVERP */ + // request terminal parameters break; + default: - log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, - __LINE__, buf); + log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__, buf); + ; } + break; + default: + log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, + __LINE__, buf); + ; + } @@ -1442,185 +1354,199 @@ vt102_parse_esc (Context * c) !v->private_modes[VT102_PRIVATE_MODE_VT52], p->cmd_buf); #endif - if (!v->private_modes[VT102_PRIVATE_MODE_VT52]) - { - int ate = 1; - - switch (p->cmd_buf[0]) - { - case 'A': /*CURSOR UP*/ - vt102_cursor_relative (v, 0, -1); - break; - case 'B': /*CURSOR DOWN*/ - vt102_cursor_relative (v, 0, 1); - break; - case 'C': /*CURSOR RIGHT*/ - vt102_cursor_relative (v, 1, 0); - break; - case 'D': /*CURSOR LEFT*/ - vt102_cursor_relative (v, -1, 0); - break; - case 'F': /*ENTER GRAPHICS MODE*/ - v->cs = 1; - v->g[1] = VT102_CSID_VT52; - break; - case 'G': /*EXIT GRAPHICS MODE*/ - v->cs = 0; - v->g[0] = VT102_CSID_US; - break; - case 'H': /*CURSOR HOME*/ - vt102_cursor_absolute (v, 0, 0); - break; - case 'I': /*REVERSE LINE FEED*/ - vt102_cursor_retreat_line (c); - break; - case 'J': /*ERASE TO END OF SCREEN*/ - crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color); - break; - case 'K': /*ERASE TO END OF LINE*/ - { - CRT_Pos le = { v->current_size.x - 1, v->pos.y }; - crt_erase (&v->crt, v->pos, le, 1, v->color); - } - break; - case 'Y': /*DIRECT CURSOR ADDRESS*/ - vt102_cursor_absolute (v, p->cmd_buf[2] - 040, p->cmd_buf[1] - 040); - break; - case 'V': /*PRINT CURSOR LINE*/ //Print current line - break; - case 'W': //Printer on - break; - case 'X': //printer off - break; - case ']': /*PRINT SCREEN */ //print screen - break; - case 'Z': //ID - vt102_send_id (c, "\033/K"); - break; - case '^': //Autoprint on - break; - case '_': //Autoprint off - break; - case '=': /*ENTER ALTERNATE KEYPAD MODE*/ - v->application_keypad_mode = 1; - break; - case '>': /*EXIT ALTERNATE KEYPAD MODE*/ - v->application_keypad_mode = 0; - break; - default: - ate = 0; - } - if (ate) - return; - } - + if (!v->private_modes[VT102_PRIVATE_MODE_VT52]) { + int ate = 1; -/*If you edit this switch don't forget to edit the length and termination tables*/ - switch (p->cmd_buf[0]) - { - case 'D': /*IND*/ - vt102_cursor_advance_line (c); + switch (p->cmd_buf[0]) { + case 'A': /* CURSOR UP */ + vt102_cursor_relative (v, 0, -1); break; - - case 'E': /*NEL*/ - vt102_cursor_advance_line (c); - v->pos.x = v->top_margin.x; - vt102_cursor_normalize (v); - v->pending_wrap = 0; + case 'B': /* CURSOR DOWN */ + vt102_cursor_relative (v, 0, 1); break; -/*F SSA*/ -/*G ESA*/ - case 'H': /*HTS*/ - v->tabs[v->pos.x]++; + case 'C': /* CURSOR RIGHT */ + vt102_cursor_relative (v, 1, 0); break; -/*I HTJ*/ -/*J VTS*/ -/*K PLD*/ -/*L PLU*/ - case 'M': /*RI*/ + case 'D': /* CURSOR LEFT */ + vt102_cursor_relative (v, -1, 0); + break; + case 'F': /* ENTER GRAPHICS MODE */ + v->cs = 1; + v->g[1] = VT102_CSID_VT52; + break; + case 'G': /* EXIT GRAPHICS MODE */ + v->cs = 0; + v->g[0] = VT102_CSID_US; + break; + case 'H': /* CURSOR HOME */ + vt102_cursor_absolute (v, 0, 0); + break; + case 'I': /* REVERSE LINE FEED */ vt102_cursor_retreat_line (c); break; - case 'N': /*SS2*/ //select G2 for one char - break; - case 'O': /*SS3*/ //select G3 for one char - break; -/*P DCS*/ -/*Q PU1*/ -/*R PU2*/ -/*S STS*/ -/*T CCH*/ -/*U MW*/ -/*V SPA*/ -/*W EPA*/ -/*X SOS*/ -/*Y SGCI*/ - case 'Z': /*DECID*/ - vt102_send_id (c, terminal_id); + case 'J': /* ERASE TO END OF SCREEN */ + crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color); + break; + case 'K': /* ERASE TO END OF LINE */ + { + CRT_Pos le = { v->current_size.x - 1, v->pos.y }; + crt_erase (&v->crt, v->pos, le, 1, v->color); + } break; - case 'c': /*RIS*/ - vt102_reset (c); + case 'Y': /* DIRECT CURSOR ADDRESS */ + vt102_cursor_absolute (v, p->cmd_buf[2] - 040, p->cmd_buf[1] - 040); break; - case '=': /*DECKPAM*/ - v->application_keypad_mode = 1; + case 'V': /* PRINT CURSOR LINE */ + // Print current line break; - case '>': /*DECKPNM*/ - v->application_keypad_mode = 0; + case 'W': + // Printer on break; - - case '#': - switch (p->cmd_buf[1]) - { - case '3': /*DECDHL*/ //top of double height line - case '4': /*DECDHL*/ //bottom of double height line - case '5': /*DECSWL*/ //single width line - case '6': /*DECDWL*/ //double width line - break; - case '8': - /*DECALN*/ - { - int i; - crt_erase (&v->crt, v->screen_start, v->screen_end, 1, - CRT_COLOR_NORMAL); - for (i = 0; i < CRT_ADDR_POS (&v->screen_end); ++i) - v->crt.screen[i].chr = 'E'; - } - break; - default: - - log_f (c->l, - "<%s:%d unhandled ESC: \\033 \\043 \\%03o (ESC # %c)>", - __FILE__, __LINE__, p->cmd_buf[1], safe_ch (p->cmd_buf[1])); - - } + case 'X': + // printer off break; - case '<': /*DECANM*/ - /*Set ansi mode - ignored */ + case ']': /* PRINT SCREEN */ + // print screen break; - - case '7': /*DECSC*/ - vt102_save_state (v); + case 'Z': // ID + vt102_send_id (c, "\033/K"); + break; + case '^': + // Autoprint on break; - case '8': /*DECRC*/ - vt102_restore_state (v); + case '_': + // Autoprint off break; - case ']': /*Set various titles in xterm - ignored*/ + case '=': /* ENTER ALTERNATE KEYPAD MODE */ + v->application_keypad_mode = 1; + break; + case '>': /* EXIT ALTERNATE KEYPAD MODE */ + v->application_keypad_mode = 0; break; - case '[': /*CSI*/ - err += vt102_parse_csi (c, p->cmd_buf, p->cmd_ptr); + default: + ate = 0; + } + if (ate) + return; + } + + + /* + * If you edit this switch don't forget to edit the length and + * termination tables + */ + switch (p->cmd_buf[0]) { + case 'D': /* IND */ + vt102_cursor_advance_line (c); + break; + + case 'E': /* NEL */ + vt102_cursor_advance_line (c); + v->pos.x = v->top_margin.x; + vt102_cursor_normalize (v); + v->pending_wrap = 0; + break; + /* F SSA */ + /* G ESA */ + case 'H': /* HTS */ + v->tabs[v->pos.x]++; + break; + /* I HTJ */ + /* J VTS */ + /* K PLD */ + /* L PLU */ + case 'M': /* RI */ + vt102_cursor_retreat_line (c); + break; + case 'N': /* SS2 */ + // select G2 for one char + break; + case 'O': /* SS3 */ + // select G3 for one char + break; + /* P DCS */ + /* Q PU1 */ + /* R PU2 */ + /* S STS */ + /* T CCH */ + /* U MW */ + /* V SPA */ + /* W EPA */ + /* X SOS */ + /* Y SGCI */ + case 'Z': /* DECID */ + vt102_send_id (c, terminal_id); + break; + case 'c': /* RIS */ + vt102_reset (c); + break; + case '=': + /* DECKPAM */ + v->application_keypad_mode = 1; + break; + case '>': + /* DECKPNM */ + v->application_keypad_mode = 0; + break; + + case '#': + switch (p->cmd_buf[1]) { + case '3': /* DECDHL */ + // top of double height line + case '4': /* DECDHL */ + // bottom of double height line + case '5': /* DECSWL */ + // single width line + case '6': /* DECDWL */ + // double width line break; - case '(': /*SCS*/ /*Charsets */ - case ')': /*SCS*/ - case '+': /*SCS*/ - case '*': /*SCS*/ - case '%': /*SCS*/ - vt102_scs (c, p->cmd_buf[0], p->cmd_buf[1]); + case '8': /* DECALN */ + { + int i; + crt_erase (&v->crt, v->screen_start, v->screen_end, 1, + CRT_COLOR_NORMAL); + for (i = 0; i < CRT_ADDR_POS (&v->screen_end); ++i) + v->crt.screen[i].chr = 'E'; + } break; default: - log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__, - __LINE__, p->cmd_buf[0], safe_ch (p->cmd_buf[0])); - ; + log_f (c->l, + "<%s:%d unhandled ESC: \\033 \\043 \\%03o (ESC # %c)>", + __FILE__, __LINE__, p->cmd_buf[1], safe_ch (p->cmd_buf[1])); + } + break; + case '<': /* DECANM */ + // Set ansi mode - ignored + break; + + case '7': /* DECSC */ + vt102_save_state (v); + break; + case '8': /* DECRC */ + vt102_restore_state (v); + break; + case ']': + /* Set various titles in xterm - ignored */ + break; + case '[': /* CSI */ + err += vt102_parse_csi (c, p->cmd_buf, p->cmd_ptr); + break; + /* Charsets */ + case '(': /* SCS */ + case ')': /* SCS */ + case '+': /* SCS */ + case '*': /* SCS */ + case '%': /* SCS */ + vt102_scs (c, p->cmd_buf[0], p->cmd_buf[1]); + break; + default: + log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__, + __LINE__, p->cmd_buf[0], safe_ch (p->cmd_buf[0])); + + ; + } p->cmd_buf[p->cmd_ptr] = 0; #ifdef DEBUG @@ -1636,23 +1562,21 @@ vt102_status_line (VT102 * v, char *str) int i; CRT_CA *ca = &v->crt.screen[CRT_ADDR (v->current_size.y, 0)]; - for (i = 0; i < v->current_size.x; ++i) - { - ca->attr = CRT_ATTR_REVERSE; - ca->color = CRT_COLOR_NORMAL; - ca->chr = *str ? *str : ' '; - if (*str) - str++; - ca++; - } - - for (; i < VT102_MAX_COLS; ++i) - { - ca->attr = CRT_ATTR_NORMAL; - ca->color = CRT_COLOR_NORMAL; - ca->chr = ' '; - ca++; - } + for (i = 0; i < v->current_size.x; ++i) { + ca->attr = CRT_ATTR_REVERSE; + ca->color = CRT_COLOR_NORMAL; + ca->chr = *str ? *str : ' '; + if (*str) + str++; + ca++; + } + + for (; i < VT102_MAX_COLS; ++i) { + ca->attr = CRT_ATTR_NORMAL; + ca->color = CRT_COLOR_NORMAL; + ca->chr = ' '; + ca++; + } } @@ -1709,19 +1633,17 @@ pre_parse_cmd (int ch, VT102_parser * p) p->in_cmd = 0; p->cmd_termination = vt102_cmd_termination[ch]; - if (p->cmd_termination) - { - p->in_cmd++; - return; - } + if (p->cmd_termination) { + p->in_cmd++; + return; + } p->cmd_more_bytes = vt102_cmd_length[ch]; - if (p->cmd_more_bytes) - { - p->in_cmd++; - return; - } + if (p->cmd_more_bytes) { + p->in_cmd++; + return; + } } int @@ -1747,91 +1669,83 @@ vt102_parse_char (Context * c, int ch) p->cmd_termination, v->pos.x, v->pos.y, v->pending_wrap); #endif - if (ch == SYM_CHAR_RESET) - { - vt102_reset_state (c); - } - else if (p->in_cmd && !ctrl_chr (ch, p->cmd_termination)) - { - p->cmd_buf[p->cmd_ptr++] = ch; - if (p->cmd_ptr == VT102_CMD_LEN) - p->in_cmd = 0; - if (p->cmd_more_bytes) - { - p->cmd_more_bytes--; - + if (ch == SYM_CHAR_RESET) { + vt102_reset_state (c); + } else if (p->in_cmd && !ctrl_chr (ch, p->cmd_termination)) { + p->cmd_buf[p->cmd_ptr++] = ch; + if (p->cmd_ptr == VT102_CMD_LEN) + p->in_cmd = 0; + if (p->cmd_more_bytes) { + p->cmd_more_bytes--; - if (!p->cmd_more_bytes == 1) - p->in_cmd = 0; - } - - switch (p->cmd_termination) - { - case 0: - break; - default: - if (p->cmd_termination == ch) - p->in_cmd = 0; - break; - case CSI_ENDER: - if (csi_ender (ch)) - p->in_cmd = 0; - break; - } - if (!p->in_cmd) - { - err += vt102_parse_esc (c); - p->cmd_more_bytes = 0; - p->cmd_termination = 0; - } + if (!p->cmd_more_bytes == 1) + p->in_cmd = 0; } - else if (p->in_escape && !ctrl_chr (ch, 0)) - { - p->cmd_ptr = 0; - p->cmd_buf[p->cmd_ptr++] = ch; - p->in_escape = 0; - pre_parse_cmd (ch, p); + switch (p->cmd_termination) { + case 0: + break; + default: + if (p->cmd_termination == ch) + p->in_cmd = 0; + break; + case CSI_ENDER: + if (csi_ender (ch)) + p->in_cmd = 0; + break; + } - if (!p->in_cmd) - err += vt102_parse_esc (c); + if (!p->in_cmd) { + err += vt102_parse_esc (c); + p->cmd_more_bytes = 0; + p->cmd_termination = 0; } - else if ((ch>=0x80) && (ch<0xa0)) - { /*C1 characters*/ -switch (ch) { -case 0x80: /*@ PAD*/ -case 0x81: /*A HOP*/ -case 0x82: /*B BPH*/ -case 0x83: /*C NBH*/ -case 0x84: /*D IND*/ -case 0x85: /*E NEL*/ -case 0x86: /*F SSA*/ -case 0x87: /*G ESA*/ -case 0x88: /*H HTS*/ -case 0x89: /*I HTJ*/ -case 0x8a: /*J VTS*/ -case 0x8b: /*K PLD*/ -case 0x8c: /*L PLU*/ -case 0x8d: /*M RI*/ -case 0x8e: /*N SS2*/ -case 0x8f: /*O SS3*/ -case 0x90: /*P DCS*/ -case 0x91: /*Q PU1*/ -case 0x92: /*R PU2*/ -case 0x93: /*S STS*/ -case 0x94: /*T CCH*/ -case 0x95: /*U MW*/ -case 0x96: /*V SPA*/ -case 0x97: /*W EPA*/ -case 0x98: /*X SOS*/ -case 0x99: /*Y SGCI*/ -case 0x9a: /*Z DECID*/ -case 0x9b: /*[ CSI*/ -case 0x9c: /*\ ST*/ -case 0x9d: /*] OSC*/ -case 0x9e: /*^ PM*/ -case 0x9f: /*_ APC*/ + } else if (p->in_escape && !ctrl_chr (ch, 0)) { + p->cmd_ptr = 0; + p->cmd_buf[p->cmd_ptr++] = ch; + p->in_escape = 0; + + pre_parse_cmd (ch, p); + + if (!p->in_cmd) + err += vt102_parse_esc (c); + } else if ((ch >= 0x80) && (ch < 0xa0)) { + /* C1 characters */ + switch (ch) { + case 0x80: /* @ PAD */ + case 0x81: /* A HOP */ + case 0x82: /* B BPH */ + case 0x83: /* C NBH */ + case 0x84: /* D IND */ + case 0x85: /* E NEL */ + case 0x86: /* F SSA */ + case 0x87: /* G ESA */ + case 0x88: /* H HTS */ + case 0x89: /* I HTJ */ + case 0x8a: /* J VTS */ + case 0x8b: /* K PLD */ + case 0x8c: /* L PLU */ + case 0x8d: /* M RI */ + case 0x8e: /* N SS2 */ + case 0x8f: /* O SS3 */ + case 0x90: /* P DCS */ + case 0x91: /* Q PU1 */ + case 0x92: /* R PU2 */ + case 0x93: /* S STS */ + case 0x94: /* T CCH */ + case 0x95: /* U MW */ + case 0x96: /* V SPA */ + case 0x97: /* W EPA */ + case 0x98: /* X SOS */ + case 0x99: /* Y SGCI */ + case 0x9a: /* Z DECID */ + case 0x9b: /* [ CSI */ + case 0x9c: /* \ ST */ + case 0x9d: /* ] OSC */ + case 0x9e: /* ^ PM */ + case 0x9f: + /*_ APC*/ p->cmd_ptr = 0; p->cmd_buf[p->cmd_ptr++] = ch; p->in_escape = 0; @@ -1841,102 +1755,99 @@ case 0x9f: /*_ APC*/ if (!p->in_cmd) err += vt102_parse_esc (c); break; -} } - else - { + } else { #ifdef DEBUG - if (ch != 27) - log_f (c->l, - "pos.x, v->pos.y, v->pending_wrap, ch, ch, safe_ch (ch)); + if (ch != 27) + log_f (c->l, + "pos.x, v->pos.y, v->pending_wrap, ch, ch, safe_ch (ch)); #endif - switch (ch) - { - /*NUL*/ case 0: - break; + switch (ch) { + case 0: /* NUL */ + break; #ifdef HIDE_NON_PRINTABLES - /*SOH*/ case 1: - /*STX*/ case 2: - /*ETX*/ case 3: - /*EOT*/ case 4: - break; + case 1: /* SOH */ + case 2: /* STX */ + case 3: /* ETX */ + case 4: /* EOT */ + break; #endif - /*ENQ*/ case 5: - vt102_send_id (c, terminal_id); - break; + case 5: /* ENQ */ + vt102_send_id (c, terminal_id); + break; #ifdef HIDE_NON_PRINTABLES - /*ACK*/ case 6: - break; + case 6: /* ACK */ + break; #endif - /*BEL*/ case 7: - //FIXME beep - break; - /*BS*/ case 8: - vt102_cursor_retreat (c->v); - err += vt102_rx_hook (c, ch); - break; - /*HT*/ case 9: - vt102_cursor_advance_tab (c->v); - err += vt102_rx_hook (c, ch); - break; - /*LF*/ case 10: - /*VT*/ case 11: - /*FF*/ case 12: - vt102_cursor_advance_line (c); - err += vt102_rx_hook (c, 10); - if (!v->modes[VT102_MODE_NEWLINE_MODE]) - break; - /*CR*/ case 13: - vt102_cursor_carriage_return (v); - err += vt102_rx_hook (c, 13); - break; - /*SO*/ case 14: - /*select G1 */ - v->cs = 1; - break; - /*SI*/ case 15: - /*select G0 */ - v->cs = 0; - break; + case 7: /* BEL */ + // FIXME beep + break; + case 8: /* BS */ + vt102_cursor_retreat (c->v); + err += vt102_rx_hook (c, ch); + break; + case 9: /* HT */ + vt102_cursor_advance_tab (c->v); + err += vt102_rx_hook (c, ch); + break; + case 10: /* LF */ + case 11: /* VT */ + case 12: /* FF */ + vt102_cursor_advance_line (c); + err += vt102_rx_hook (c, 10); + if (!v->modes[VT102_MODE_NEWLINE_MODE]) + break; + case 13: /* CR */ + vt102_cursor_carriage_return (v); + err += vt102_rx_hook (c, 13); + break; + case 14: /* SO */ + /* select G1 */ + v->cs = 1; + break; + case 15: /* SI */ + /* select G0 */ + v->cs = 0; + break; #ifdef HIDE_NON_PRINTABLES - /*DLE*/ case 16: - /*DC1 */ case 17: - /*DC2 */ case 18: - /*DC3 */ case 19: - /*DC4 */ case 20: - /*NAK*/ case 21: - /*SYN*/ case 22: - /*ETB*/ case 23: - /*CAN*/ case 24: - /*EM*/ case 25: - /*SUB*/ case 26: - break; + case 16: /* DLE */ + case 17: /* DC1 */ + case 18: /* DC2 */ + case 19: /* DC3 */ + case 20: /* DC4 */ + case 21: /* NAK */ + case 22: /* SYN */ + case 23: /* ETB */ + case 24: /* CAN */ + case 25: /* EM */ + case 26: /* SUB */ + break; #endif - /*ESC*/ case 27: - p->in_escape++; - break; + case 27: /* ESC */ + p->in_escape++; + break; #ifdef HIDE_NON_PRINTABLES - /*FS*/ case 28: - /*GS*/ case 29: - /*RS*/ case 30: - /*US*/ case 31: - /*DEL*/ case 127: - break; + case 28: /* FS */ + case 29: /* GS */ + case 30: /* RS */ + case 31: /* US */ + case 127: /* DEL */ + break; #endif - /*regular character */ default: - vt102_regular_char (c, v, ch); - err += vt102_rx_hook (c, ch); - } + default: /* regular character */ + vt102_regular_char (c, v, ch); + err += vt102_rx_hook (c, ch); + } #ifdef DEBUG - if (ch != 27) - log_f (c->l, "", v->pos.x, v->pos.y, - v->pending_wrap); + if (ch != 27) + log_f (c->l, "", v->pos.x, v->pos.y, + v->pending_wrap); #endif - } + } vt102_crt_update (c); @@ -1952,184 +1863,171 @@ vt102_send (Context * c, uint8_t key) if (!c->t) return; - if ((key > 31) && (key < 127)) + if ((key > 31) && (key < 127)) { + c->t->xmit (c->t, &key, 1); + return; + } + + switch (key) { + case 0: /* NUL */ + case 1: /* SOH */ + case 2: /* STX */ + case 3: /* ETX */ + case 4: /* EOT */ + case 5: /* ENQ */ + case 6: /* ACK */ + case 7: /* BEL */ + case 8: /* BS */ + case 9: /* HT */ + case 10: /* LF */ + case 11: /* VT */ + case 12: /* FF */ + c->t->xmit (c->t, &key, 1); + break; + case 13: /* CR */ + c->t->xmit (c->t, &key, 1); + if (c->v->modes[VT102_MODE_NEWLINE_MODE]) { + ch = 10; + c->t->xmit (c->t, &ch, 1); + } + break; + case 14: /* SO */ + case 15: /* SI */ + case 16: /* DLE */ + case 17: /* DC1 */ + case 18: /* DC2 */ + case 19: /* DC3 */ + case 20: /* DC4 */ + case 21: /* NAK */ + case 22: /* SYN */ + case 23: /* ETB */ + case 24: /* CAN */ + case 25: /* EM */ + case 26: /* SUB */ + c->t->xmit (c->t, &key, 1); + break; + case 27: /* ESC */ + case 28: /* FS */ + case 29: /* GS */ + case 30: /* RS */ + case 31: /* US */ + case 127: /* DEL */ + c->t->xmit (c->t, &key, 1); + break; + + case KEY_UP: + case KEY_DOWN: + case KEY_RIGHT: + case KEY_LEFT: + case KEY_HOME: + case KEY_MIDDLE: + case KEY_END: + + if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE]) { + uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) }; + c->t->xmit (c->t, &buf, sizeof (buf)); + } else { + uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) }; + c->t->xmit (c->t, &buf, sizeof (buf)); + } + break; + case KEY_STAR: + case KEY_PLUS: + case KEY_COMMA: + case KEY_PERIOD: + case KEY_DIVIDE: + case KEY_0: + case KEY_1: + case KEY_2: + case KEY_3: + case KEY_4: + case KEY_5: + case KEY_6: + case KEY_7: + case KEY_8: + case KEY_9: + if (c->v->application_keypad_mode) { + uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) }; + c->t->xmit (c->t, &buf, sizeof (buf)); + } else { + static char kpoff[KEY_NUM] = { + [KEY_STAR] = '*', + [KEY_PLUS] = '+', + [KEY_COMMA] = ',', + [KEY_MINUS] = '-', + [KEY_PERIOD] = '.', + [KEY_DIVIDE] = '/', + [KEY_0] = '0', + [KEY_1] = '1', + [KEY_2] = '2', + [KEY_3] = '3', + [KEY_4] = '4', + [KEY_5] = '5', + [KEY_6] = '6', + [KEY_7] = '7', + [KEY_8] = '8', + [KEY_9] = '9' + }; + + c->t->xmit (c->t, &kpoff[key], 1); + } + break; + case KEY_ENTER: + if (c->v->application_keypad_mode) { + uint8_t buf[] = { 033, 'O', 'M' }; + c->t->xmit (c->t, &buf, sizeof (buf)); + } else { + ch = 13; + c->t->xmit (c->t, &ch, 1); + if (c->v->modes[VT102_MODE_NEWLINE_MODE]) { + ch = 10; + c->t->xmit (c->t, &ch, 1); + } + } + break; + case KEY_PF1: + case KEY_PF2: + case KEY_PF3: + case KEY_PF4: { - c->t->xmit (c->t, &key, 1); - return; + uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) }; + c->t->xmit (c->t, &buf, sizeof (buf)); } - - switch (key) + break; + case KEY_VT220_HOME: + case KEY_INSERT: + case KEY_DELETE: + case KEY_VT220_END: + case KEY_PGUP: + case KEY_PGDN: + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + case KEY_F11: + case KEY_F12: + case KEY_F13: + case KEY_F14: + case KEY_F15: + case KEY_F16: + case KEY_F17: + case KEY_F18: + case KEY_F19: + case KEY_F20: { - /*NUL*/ case 0: - /*SOH*/ case 1: - /*STX*/ case 2: - /*ETX*/ case 3: - /*EOT*/ case 4: - /*ENQ*/ case 5: - /*ACK*/ case 6: - /*BEL*/ case 7: - /*BS*/ case 8: - /*HT*/ case 9: - /*LF*/ case 10: - /*VT*/ case 11: - /*FF*/ case 12: - c->t->xmit (c->t, &key, 1); - break; - /*CR*/ case 13: - c->t->xmit (c->t, &key, 1); - if (c->v->modes[VT102_MODE_NEWLINE_MODE]) - { - ch = 10; - c->t->xmit (c->t, &ch, 1); - } - break; - /*SO*/ case 14: - /*SI*/ case 15: - /*DLE*/ case 16: - /*DC1 */ case 17: - /*DC2 */ case 18: - /*DC3 */ case 19: - /*DC4 */ case 20: - /*NAK*/ case 21: - /*SYN*/ case 22: - /*ETB*/ case 23: - /*CAN*/ case 24: - /*EM*/ case 25: - /*SUB*/ case 26: - c->t->xmit (c->t, &key, 1); - break; - /*ESC*/ case 27: - /*FS*/ case 28: - /*GS*/ case 29: - /*RS*/ case 30: - /*US*/ case 31: - /*DEL*/ case 127: - c->t->xmit (c->t, &key, 1); - break; - - case KEY_UP: - case KEY_DOWN: - case KEY_RIGHT: - case KEY_LEFT: - case KEY_HOME: - case KEY_MIDDLE: - case KEY_END: - - if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE]) - { - uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) }; - c->t->xmit (c->t, &buf, sizeof (buf)); - } - else - { - uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) }; - c->t->xmit (c->t, &buf, sizeof (buf)); - } - break; - case KEY_STAR: - case KEY_PLUS: - case KEY_COMMA: - case KEY_PERIOD: - case KEY_DIVIDE: - case KEY_0: - case KEY_1: - case KEY_2: - case KEY_3: - case KEY_4: - case KEY_5: - case KEY_6: - case KEY_7: - case KEY_8: - case KEY_9: - if (c->v->application_keypad_mode) - { - uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) }; - c->t->xmit (c->t, &buf, sizeof (buf)); - } - else - { - static char kpoff[KEY_NUM] = { - [KEY_STAR] = '*', - [KEY_PLUS] = '+', - [KEY_COMMA] = ',', - [KEY_MINUS] = '-', - [KEY_PERIOD] = '.', - [KEY_DIVIDE] = '/', - [KEY_0] = '0', - [KEY_1] = '1', - [KEY_2] = '2', - [KEY_3] = '3', - [KEY_4] = '4', - [KEY_5] = '5', - [KEY_6] = '6', - [KEY_7] = '7', - [KEY_8] = '8', - [KEY_9] = '9' - }; - - c->t->xmit (c->t, &kpoff[key], 1); - } - break; - case KEY_ENTER: - if (c->v->application_keypad_mode) - { - uint8_t buf[] = { 033, 'O', 'M' }; - c->t->xmit (c->t, &buf, sizeof (buf)); - } - else - { - ch = 13; - c->t->xmit (c->t, &ch, 1); - if (c->v->modes[VT102_MODE_NEWLINE_MODE]) - { - ch = 10; - c->t->xmit (c->t, &ch, 1); - } - } - break; - case KEY_PF1: - case KEY_PF2: - case KEY_PF3: - case KEY_PF4: - { - uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) }; - c->t->xmit (c->t, &buf, sizeof (buf)); - } - break; - case KEY_VT220_HOME: - case KEY_INSERT: - case KEY_DELETE: - case KEY_VT220_END: - case KEY_PGUP: - case KEY_PGDN: - case KEY_F1: - case KEY_F2: - case KEY_F3: - case KEY_F4: - case KEY_F5: - case KEY_F6: - case KEY_F7: - case KEY_F8: - case KEY_F9: - case KEY_F10: - case KEY_F11: - case KEY_F12: - case KEY_F13: - case KEY_F14: - case KEY_F15: - case KEY_F16: - case KEY_F17: - case KEY_F18: - case KEY_F19: - case KEY_F20: - { - uint8_t buf[16]; - int i; - i = sprintf (buf, "\033[%d~", (key - KEY_180)); - c->t->xmit (c->t, &buf, i); - } - break; + uint8_t buf[16]; + int i; + i = sprintf (buf, "\033[%d~", (key - KEY_180)); + c->t->xmit (c->t, &buf, i); } + break; + } } @@ -2177,26 +2075,23 @@ vt102_new (CRT_Pos * size) v->xn_glitch = 1; - if (size) - { - v->original_size = *size; + if (size) { + v->original_size = *size; - if (v->original_size.x < 1) - v->original_size.x = 1; - if (v->original_size.y < 1) - v->original_size.y = 1; + if (v->original_size.x < 1) + v->original_size.x = 1; + if (v->original_size.y < 1) + v->original_size.y = 1; - if (v->original_size.x > VT102_MAX_COLS) - v->original_size.x = VT102_MAX_COLS; - if (v->original_size.y > VT102_MAX_ROWS) - v->original_size.y = VT102_MAX_ROWS; + if (v->original_size.x > VT102_MAX_COLS) + v->original_size.x = VT102_MAX_COLS; + if (v->original_size.y > VT102_MAX_ROWS) + v->original_size.y = VT102_MAX_ROWS; - } - else - { - v->original_size.x = VT102_COLS_80; - v->original_size.y = VT102_ROWS_24; - } + } else { + v->original_size.x = VT102_COLS_80; + v->original_size.y = VT102_ROWS_24; + } return v; } diff --git a/src/vt102.h b/src/vt102.h index f475b9f..54fa84c 100644 --- a/src/vt102.h +++ b/src/vt102.h @@ -1,4 +1,4 @@ -/* +/* * vt102.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.24 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.23 2008/03/03 06:04:42 james * *** empty log message *** * diff --git a/src/vt102_charset.c b/src/vt102_charset.c index 43e6012..00ac30e 100644 --- a/src/vt102_charset.c +++ b/src/vt102_charset.c @@ -1,4 +1,4 @@ -/* +/* * vt102_charset.c: * * Copyright (c) 2008 James McKenzie , @@ -9,8 +9,11 @@ static char rcsid[] = "$Id$"; -/* +/* * $Log$ + * Revision 1.5 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.4 2008/02/27 00:54:16 james * *** empty log message *** * @@ -83,13 +86,13 @@ uint32_t vt102_charset_vt52[VT102_CHARSET_SIZE] = { [0x69] = 0x2026, [0x6a] = 0x00f7, [0x6b] = 0x2193, - [0x6c] = 0x23ba, //bar scan 0 + [0x6c] = 0x23ba, // bar scan 0 [0x6d] = 0x23ba, - [0x6e] = 0x23bb, //bar scan 2 + [0x6e] = 0x23bb, // bar scan 2 [0x6f] = 0x23bb, - [0x70] = 0x2500, //bar scan 4 + [0x70] = 0x2500, // bar scan 4 [0x71] = 0x23bc, - [0x72] = 0x23bd, //bar scan 6 + [0x72] = 0x23bd, // bar scan 6 [0x73] = 0x23bd, [0x74] = 0x2080, [0x75] = 0x2081, diff --git a/src/vt102_charset.h b/src/vt102_charset.h index a1130fa..8a6ba75 100644 --- a/src/vt102_charset.h +++ b/src/vt102_charset.h @@ -1,4 +1,4 @@ -/* +/* * vt102_charset.h: * * Copyright (c) 2008 James McKenzie , @@ -6,12 +6,15 @@ * */ -/* +/* * $Id$ */ -/* +/* * $Log$ + * Revision 1.2 2008/03/07 12:37:04 james + * *** empty log message *** + * * Revision 1.1 2008/02/27 01:32:41 james * *** empty log message *** * -- cgit v1.2.3