diff options
| author | james <> | 2012-06-22 10:22:25 +0000 | 
|---|---|---|
| committer | james <> | 2012-06-22 10:22:25 +0000 | 
| commit | c945112e89222e697c3733c69eab685f606a5be5 (patch) | |
| tree | 20d0d125ed4d76259f87740d5cd9344bcade24d5 /src | |
| parent | 9a219228a74b32f3b3202609a155d8f22ba47da8 (diff) | |
| download | sympathy-c945112e89222e697c3733c69eab685f606a5be5.tar.gz sympathy-c945112e89222e697c3733c69eab685f606a5be5.tar.bz2 sympathy-c945112e89222e697c3733c69eab685f606a5be5.zip  | |
*** empty log message ***
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 7 | ||||
| -rw-r--r-- | src/ansi.c | 713 | ||||
| -rw-r--r-- | src/ansi.h | 9 | ||||
| -rw-r--r-- | src/cmd.c | 70 | ||||
| -rw-r--r-- | src/cmd.h | 6 | ||||
| -rw-r--r-- | src/context.h | 6 | ||||
| -rw-r--r-- | src/crt.c | 38 | ||||
| -rw-r--r-- | src/crt.h | 19 | ||||
| -rw-r--r-- | src/history.c | 12 | ||||
| -rw-r--r-- | src/history.h | 9 | ||||
| -rw-r--r-- | src/html.c | 101 | ||||
| -rw-r--r-- | src/ipc.c | 6 | ||||
| -rw-r--r-- | src/ipc.h | 57 | ||||
| -rw-r--r-- | src/keydis.c | 25 | ||||
| -rw-r--r-- | src/keydis.h | 6 | ||||
| -rw-r--r-- | src/lockfile.c | 269 | ||||
| -rw-r--r-- | src/lockfile.h | 12 | ||||
| -rw-r--r-- | src/log.c | 153 | ||||
| -rw-r--r-- | src/log.h | 6 | ||||
| -rw-r--r-- | src/project.h | 9 | ||||
| -rw-r--r-- | src/prototypes.h | 15 | ||||
| -rw-r--r-- | src/ptty.c | 85 | ||||
| -rw-r--r-- | src/raw.c | 63 | ||||
| -rw-r--r-- | src/render.c | 5 | ||||
| -rw-r--r-- | src/ring.c | 29 | ||||
| -rw-r--r-- | src/ring.h | 6 | ||||
| -rw-r--r-- | src/rotate.c | 35 | ||||
| -rw-r--r-- | src/rx.h | 6 | ||||
| -rw-r--r-- | src/serial.c | 69 | ||||
| -rw-r--r-- | src/slide.c | 12 | ||||
| -rw-r--r-- | src/slide.h | 6 | ||||
| -rw-r--r-- | src/sympathy.h.head.in | 6 | ||||
| -rw-r--r-- | src/symsocket.c | 104 | ||||
| -rw-r--r-- | src/symsocket.h | 6 | ||||
| -rw-r--r-- | src/terminal.c | 75 | ||||
| -rw-r--r-- | src/tty.c | 396 | ||||
| -rw-r--r-- | src/tty.h | 12 | ||||
| -rw-r--r-- | src/utf8.c | 204 | ||||
| -rw-r--r-- | src/utf8.h | 6 | ||||
| -rw-r--r-- | src/util.c | 9 | ||||
| -rw-r--r-- | src/version.c | 9 | ||||
| -rw-r--r-- | src/vt102.c | 2170 | ||||
| -rw-r--r-- | src/vt102.h | 14 | 
43 files changed, 2720 insertions, 2155 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 4e4daa7..f980e4c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,9 @@  # $Id$  #  # $Log$ +# Revision 1.25  2012/06/22 10:22:24  james +# *** empty log message *** +#  # Revision 1.24  2008/03/07 13:16:02  james  # *** empty log message ***  # @@ -113,7 +116,7 @@ clean-local:  libsympathy_a_SOURCES =  ${SYMPATHYSRCS}  libsympathy_la_SOURCES = ${SYMPATHYSRCS} -libsympathy_a_CFLAGS = ${AM_CFLAGS} +libsympathy_a_CFLAGS = ${AM_CFLAGS}   BUILT_SOURCES = version.h sympathy.h @@ -122,7 +125,7 @@ lib_LTLIBRARIES=libsympathy.la  include_HEADERS=sympathy.h -AM_CFLAGS=-g -Werror +AM_CFLAGS=-g -Wall  libsympathy_la_LDFLAGS = \          -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.51  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.50  2008/03/07 13:16:02  james   * *** empty log message ***   * @@ -175,65 +178,94 @@ ansi_move (ANSI * a, CRT_Pos p)    // 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 { +  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 +    {        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; @@ -248,13 +280,16 @@ 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; @@ -293,7 +328,6 @@ ansi_set_title (ANSI * a, char *t)  static int  ansi_set_color (ANSI * a, int color)  { -  int dif;    char buf[16];    int i;    int fg, bg; @@ -303,17 +337,23 @@ 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 @@ -341,41 +381,54 @@ 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;  } @@ -386,31 +439,35 @@ 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; -  } +  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; -  } +  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; +  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; @@ -420,7 +477,6 @@ static int  ansi_render (ANSI * a, CRT_CA ca)  {    int err = 0; -  int dif;    if ((ca.chr < VT102_CHARSET_SIZE) && (vt102_charset_c0[ca.chr]))      ca.chr = vt102_charset_c0[ca.chr]; @@ -431,13 +487,16 @@ 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++; @@ -454,7 +513,7 @@ static int  ansi_cls (ANSI * a)  {    CRT_Pos p = { 0 }; -  int err; +  int err = 0;    crt_cls (&a->crt); @@ -478,22 +537,24 @@ 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; +  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); +      if (crt_ca_cmp (*acap, *cap)) +        { +          err += ansi_showhide_cursor (a, 1); -      *acap = *cap; +          *acap = *cap; -      err += ansi_move (a, p); -      err += ansi_render (a, *acap); -    } +          err += ansi_move (a, p); +          err += ansi_render (a, *acap); +        } -    acap++; -    cap++; -  } +      acap++; +      cap++; +    }    return err;  } @@ -504,43 +565,47 @@ 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; -    // a->terminal->xmit (a->terminal, "\033c", 3); -    // maybe - issue 132 column command if we're 132? +      // a->terminal->xmit (a->terminal, "\033c", 3); +      // maybe - issue 132 column command if we're 132? -    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) +      ansi_cls (a); +      if (a->terminal->xmit (a->terminal, "\033=", 2) != 2)          err++; -    } else { -      if (a->terminal->xmit (a->terminal, "\033(B", 3) != 3) +      if (a->terminal->xmit (a->terminal, "\033[?6l", 5) != 5)          err++; -      if (a->terminal->xmit (a->terminal, "\033)0", 3) != 3) +      if (a->terminal->xmit (a->terminal, "\033[r", 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;  } @@ -573,58 +638,61 @@ ansi_history (ANSI * a, History * h)      err++; -  while (a->history_ptr != h->wptr) { +  while (a->history_ptr != h->wptr) +    { + +      History_ent *e = &h->lines[a->history_ptr]; -    History_ent *e = &h->lines[a->history_ptr]; +      HISTORY_INC (h, a->history_ptr); -    HISTORY_INC (h, a->history_ptr); +      if (!e->valid) +        continue; -    if (!e->valid) -      continue; +      /* If so write the line ot the top of the screen */ +      err += ansi_draw_line (a, e->line, 0); -    /* 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); -    /* Make extra lines a predictable colour */ -    err += ansi_set_color (a, CRT_COLOR_NORMAL); +      err += ansi_showhide_cursor (a, 1); -    err += ansi_showhide_cursor (a, 1); +      i = sprintf (buf, "\033[%d;%dH", guess_scroll, 1); +      if (a->terminal->xmit (a->terminal, buf, i) != i) +        err++; -    i = sprintf (buf, "\033[%d;%dH", guess_scroll, 1); -    if (a->terminal->xmit (a->terminal, buf, i) != i) -      err++; +      if (a->terminal->xmit (a->terminal, "\033D", 2) != 2) +        err++; -    if (a->terminal->xmit (a->terminal, "\033D", 2) != 2) -      err++; +      a->pos.x = ANSI_INVAL; -    a->pos.x = ANSI_INVAL; +      /* now do the same in our image of the screen */ -    /* now do the same in our image of the screen */ +      { +        CRT_Pos s = { 0 } +        , e = +        { +        0}; -    { -      CRT_Pos s = { 0 } -      , e = { -      0}; +        /* 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); +          } -      /* 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);        } -      /* erase new line */ -      s.y = e.y; -      e.x = CRT_COLS - 1; -      crt_erase (&a->crt, s, e, 1, CRT_COLOR_NORMAL);      } - -  }    /* reset margins */    if (a->terminal->xmit (a->terminal, "\033[r", 3) != 3)      err++; @@ -641,49 +709,50 @@ static int  ansi_draw (ANSI * a, CRT * c)  {    CRT_Pos p; -  int o; -  int hidden_cursor = 0;    int err = 0;    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); @@ -719,17 +788,25 @@ 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); +  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);      } -  } else if (key == CMD_KEY) { -    return cmd_activate (c->d, c); -  }    return c->k->key (c->k, c, key);  } @@ -741,9 +818,10 @@ 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; @@ -753,19 +831,25 @@ 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;  } @@ -778,17 +862,19 @@ 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); @@ -802,42 +888,45 @@ 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': +  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); +        }        break; -    default: -      ansi_flush_escape (a, c); -    } -    break; -  case 3: -    switch (p->escape_buf[1]) { -    case 'O': -      ansi_parse_deckey (a, c); +    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); +        }        break; -    case '[': -      if ((p->escape_buf[2] >= 'A') && (p->escape_buf[2] <= 'Z')) -        ansi_parse_deckey (a, c); +    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);      } -    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); -  }  } @@ -874,21 +963,25 @@ ansi_parse_char (ANSI * a, Context * c, int ch)    /* 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); +  if (ch == 033) +    { +      if (p->in_escape) +        ansi_flush_escape (a, c); + +      p->in_escape++; +      p->escape_ptr = 0; +      gettimeofday (&p->last_escape, NULL); +    } -    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); -  } +  if (p->in_escape) +    { +      p->escape_buf[p->escape_ptr++] = ch; +      ansi_parse_escape (a, c); +    } +  else +    { +      ansi_key (a, c, ch); +    }  } @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.21  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.20  2008/03/10 11:49:32  james   * *** empty log message ***   * @@ -82,7 +85,8 @@  #define ANSI_ESCAPE_BUF_LEN 10  #define ANSI_ESCAPE_TIMEOUT	100000 /* in ms */ -typedef struct { +typedef struct +{    int in_escape;    struct timeval last_escape;    char escape_buf[ANSI_ESCAPE_BUF_LEN]; @@ -92,7 +96,8 @@ typedef struct {  struct CRT_struct;  struct Context_struct; -typedef struct ANSI_struct { +typedef struct ANSI_struct +{    ANSI_Parser parser;    TTY *terminal; @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.14  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.13  2008/03/07 13:16:02  james   * *** empty log message ***   * @@ -75,11 +78,13 @@ 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)); @@ -110,35 +115,42 @@ int  cmd_key (Cmd * c, Context * ctx, ANSI * a, int key)  { -  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 { +  if (c->error) +    { +      c->error = 0;        c->active = 0; +      cmd_show_status (c, ctx); +      return 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 == 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 >= 32) && (key < 127)) { +  if (((key == 8) || (key == 127)) && (c->ptr > 1)) +    { +      c->ptr--; +      c->buf[c->ptr] = 0; +    } + +  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); @@ -187,4 +199,6 @@ cmd_new (void)    ret->active = 0;    ret->error = 0;    ret->csl[0] = 0; + +  return ret;  } @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.9  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.8  2008/03/10 11:49:32  james   * *** empty log message ***   * @@ -44,7 +47,8 @@  #define CMD_KEY 2               /* CTRL B */  #define CMD_CANCEL_KEY 3        /* CTRL C */ -typedef struct { +typedef struct +{    int active;    int error;    int disconnect; diff --git a/src/context.h b/src/context.h index affa883..1df7b26 100644 --- a/src/context.h +++ b/src/context.h @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.15  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.14  2010/07/27 14:49:35  james   * add support for byte logging   * @@ -59,7 +62,8 @@  #ifndef __CONTEXT_H__  #define __CONTEXT_H__ -typedef struct Context_struct { +typedef struct Context_struct +{    VT102 *v;    TTY *t;    TTY_Parser *tp; @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.19  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.18  2008/03/07 12:37:04  james   * *** empty log message ***   * @@ -74,14 +77,16 @@ 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; +  while (ps <= pe) +    { +      ps->chr = ' '; +      if (ea) +        { +          ps->attr = CRT_ATTR_NORMAL; +          ps->color = color; +        } +      ps++;      } -    ps++; -  }  } @@ -90,7 +95,6 @@ crt_cls (CRT * c)  {    CRT_Pos s = { 0, 0 };    CRT_Pos e = { CRT_COLS - 1, CRT_ROWS - 1 }; -  int i;    crt_erase (c, s, e, 1, CRT_COLOR_NORMAL);  #if 0 @@ -123,10 +127,11 @@ 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); @@ -157,10 +162,11 @@ crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color)    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); @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.19  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.18  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -111,25 +114,29 @@  #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;  } CRT_CA; -typedef struct { +typedef struct +{    int x;    int y;  } CRT_Pos; -typedef struct { +typedef struct +{    CRT_Pos s;    CRT_Pos e;    int dir;  } CRT_ScrollHint; -typedef struct CRT_struct { +typedef struct CRT_struct +{    CRT_CA screen[CRT_CELS];    CRT_Pos pos;    int hide_cursor; @@ -137,13 +144,13 @@ typedef struct CRT_struct {  } CRT; -static inline +static inline int  crt_ca_cmp (CRT_CA a, CRT_CA b)  {    return memcmp (&a, &b, sizeof (a));  } -static inline +static inline int  crt_pos_cmp (CRT_Pos a, CRT_Pos b)  {    return memcmp (&a, &b, sizeof (a)); diff --git a/src/history.c b/src/history.c index d80a1b6..745c2bd 100644 --- a/src/history.c +++ b/src/history.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.8  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.7  2008/03/07 13:16:02  james   * *** empty log message ***   * @@ -78,10 +81,11 @@ 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 3baa097..9d64e30 100644 --- a/src/history.h +++ b/src/history.h @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.8  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.7  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -38,13 +41,15 @@  #ifndef __HISTORY_H__  #define __HISTORY_H__ -typedef struct { +typedef struct +{    int valid;    time_t t;    CRT_CA line[CRT_COLS];  } History_ent; -typedef struct { +typedef struct +{    History_ent *lines;    int nlines;    int wptr; @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.16  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.15  2008/03/07 13:16:02  james   * *** empty log message ***   * @@ -86,29 +89,35 @@ 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,15 +125,18 @@ 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, "<span style='color: #%06x; background-color: #%06x'>",             colormap[fg], colormap[bg]); @@ -145,9 +157,10 @@ html_render (FILE * f, CRT_CA c)      fprintf (f, "</b>");    if (c.attr & CRT_ATTR_UNDERLINE)      fprintf (f, "</ul>"); -  if (c.attr & CRT_ATTR_REVERSE) { -    fprintf (f, "</font>"); -  } +  if (c.attr & CRT_ATTR_REVERSE) +    { +      fprintf (f, "</font>"); +    }  #ifdef CSS    fprintf (f, "</span>");  #else @@ -167,20 +180,22 @@ html_draw (FILE * f, CRT * c)  #else    fprintf (f, "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\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, "<tr>"); +      fprintf (f, "<tr>");  #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, "</tr>\n"); +      fprintf (f, "</tr>\n");  #endif -  } +    }  #ifdef CSS    fprintf (f, "</pre>\n");  #else @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.12  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.11  2008/03/07 14:13:40  james   * *** empty log message ***   * @@ -86,7 +89,6 @@ ipc_msg_send_debug (Socket * s, char *msg)  {    char buf[sizeof (IPC_Msg_hdr) + IPC_MAX_BUF];    IPC_Msg_debug *m; -  int len;    m = (IPC_Msg_debug *) buf; @@ -114,7 +116,6 @@ int  ipc_msg_send_history (Socket * s, History_ent * l)  {    IPC_Msg_history m; -  int len;    m.type = IPC_MSG_TYPE_HISTORY; @@ -128,7 +129,6 @@ int  ipc_msg_send_vt102 (Socket * s, VT102 * v)  {    IPC_Msg_VT102 m; -  int len;    m.type = IPC_MSG_TYPE_VT102; @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.13  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.12  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -72,38 +75,44 @@  #define IPC_MSG_TYPE_RESET 14  #define IPC_MSG_TYPE_KILLME 15 -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    uint8_t payload[0];  } IPC_Msg_hdr; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;  } IPC_Msg_noop; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    char msg[0];  } IPC_Msg_debug; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    char msg[0];  } IPC_Msg_initialize; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    History_ent history;  } IPC_Msg_history; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    int32_t len; @@ -111,13 +120,15 @@ typedef struct {  } IPC_Msg_VT102; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    int32_t key;  } IPC_Msg_key; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    int32_t len; @@ -125,66 +136,76 @@ typedef struct {  } IPC_Msg_term; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    char status[0];  } IPC_Msg_status; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    int32_t baud;  } IPC_Msg_setbaud; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;  } IPC_Msg_sendbreak; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    int32_t flow;  } IPC_Msg_setflow; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    int32_t ansi;  } IPC_Msg_setansi; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;  } IPC_Msg_hangup; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;    CRT_Pos winsize;  } IPC_Msg_setsize; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;  } IPC_Msg_reset; -typedef struct { +typedef struct +{    int32_t size;    int32_t type;  } IPC_Msg_killme; -typedef union { +typedef union +{    IPC_Msg_hdr hdr;    IPC_Msg_noop noop;    IPC_Msg_debug debug; diff --git a/src/keydis.c b/src/keydis.c index ad75996..d4f415e 100644 --- a/src/keydis.c +++ b/src/keydis.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.17  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.16  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -68,11 +71,13 @@ static char rcsid[] = "$Id$";  #define CMD_BUFLEN	128 -typedef struct { +typedef struct +{    KEYDIS_SIGNATURE;  } KeyDis_VT102; -typedef struct { +typedef struct +{    KEYDIS_SIGNATURE;    Socket *s;  } KeyDis_IPC; @@ -176,7 +181,7 @@ keydis_ipc_reset (KeyDis * _t, Context * c)  static int  keydis_vt102_key (KeyDis * _t, Context * c, int key)  { -  KeyDis_VT102 *t = (KeyDis_VT102 *) _t; +  //KeyDis_VT102 *t = (KeyDis_VT102 *) _t;    vt102_send (c, key);    return 0; @@ -185,7 +190,7 @@ keydis_vt102_key (KeyDis * _t, Context * c, int key)  static int  keydis_vt102_set_baud (KeyDis * _t, Context * c, int baud)  { -  KeyDis_VT102 *t = (KeyDis_VT102 *) _t; +  //KeyDis_VT102 *t = (KeyDis_VT102 *) _t;    tty_set_baud (c->t, baud);    tty_parse_reset (c); @@ -198,7 +203,7 @@ keydis_vt102_set_baud (KeyDis * _t, Context * c, int baud)  static int  keydis_vt102_send_break (KeyDis * _t, Context * c)  { -  KeyDis_VT102 *t = (KeyDis_VT102 *) _t; +  //KeyDis_VT102 *t = (KeyDis_VT102 *) _t;    log_f (c->l, "<break sent>");    tty_send_break (c->t); @@ -209,7 +214,7 @@ keydis_vt102_send_break (KeyDis * _t, Context * c)  static int  keydis_vt102_set_flow (KeyDis * _t, Context * c, int flow)  { -  KeyDis_VT102 *t = (KeyDis_VT102 *) _t; +  //KeyDis_VT102 *t = (KeyDis_VT102 *) _t;    log_f (c->l, "<flow control turned %s>", flow ? "on" : "off");    tty_set_flow (c->t, flow); @@ -220,7 +225,7 @@ keydis_vt102_set_flow (KeyDis * _t, Context * c, int flow)  static int  keydis_vt102_set_ansi (KeyDis * _t, Context * c, int ansi)  { -  KeyDis_VT102 *t = (KeyDis_VT102 *) _t; +  //KeyDis_VT102 *t = (KeyDis_VT102 *) _t;    if (c->v)      c->v->xn_glitch = ansi ? 0 : 1; @@ -231,7 +236,7 @@ keydis_vt102_set_ansi (KeyDis * _t, Context * c, int ansi)  static int  keydis_vt102_hangup (KeyDis * _t, Context * c)  { -  KeyDis_VT102 *t = (KeyDis_VT102 *) _t; +  //KeyDis_VT102 *t = (KeyDis_VT102 *) _t;    log_f (c->l, "<hangup initiated>");    tty_hangup (c->t); @@ -242,7 +247,7 @@ keydis_vt102_hangup (KeyDis * _t, Context * c)  static int  keydis_vt102_set_size (KeyDis * _t, Context * c, int w, int h)  { -  KeyDis_VT102 *t = (KeyDis_VT102 *) _t; +  //KeyDis_VT102 *t = (KeyDis_VT102 *) _t;    CRT_Pos p = { w, h };    vt102_resize (c, p); @@ -253,7 +258,7 @@ keydis_vt102_set_size (KeyDis * _t, Context * c, int w, int h)  static int  keydis_vt102_reset (KeyDis * _t, Context * c)  { -  KeyDis_VT102 *t = (KeyDis_VT102 *) _t; +  //KeyDis_VT102 *t = (KeyDis_VT102 *) _t;    vt102_reset (c); diff --git a/src/keydis.h b/src/keydis.h index f1f2c2b..17998f9 100644 --- a/src/keydis.h +++ b/src/keydis.h @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.11  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.10  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -66,7 +69,8 @@ struct Context_struct; -typedef struct KeyDis_struct { +typedef struct KeyDis_struct +{    KEYDIS_SIGNATURE;  } KeyDis; diff --git a/src/lockfile.c b/src/lockfile.c index 1a77815..d176325 100644 --- a/src/lockfile.c +++ b/src/lockfile.c @@ -11,6 +11,9 @@ static char rcsid[] =  /*    * $Log$ + * Revision 1.18  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.17  2010/07/16 11:04:10  james   * ignore tedious return values   * @@ -64,6 +67,12 @@ static char rcsid[] =   *   */ +static inline char * +stop_wno_unused_on_rcsid (void) +{ +  return rcsid; +} +  #define LOCK_ASCII  #undef LOCK_BINARY @@ -83,6 +92,7 @@ static char rcsid[] =  #include <errno.h>  #include <time.h>  #include <sys/time.h> +#include <signal.h>  #include "lockfile.h" @@ -149,10 +159,11 @@ 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);  } @@ -167,14 +178,18 @@ 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);  } @@ -201,30 +216,33 @@ 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; +    }    int result;    result = write (fd, buf, i);    fchmod (fd, 044);  #if 0 -  if (chown_uucp (fd)) { -    close (fd); -    unlink (tmpfn); -    return -1; -  } +  if (chown_uucp (fd)) +    { +      close (fd); +      unlink (tmpfn); +      return -1; +    }  #else    chown_uucp (fd);  #endif    close (fd); -  if (link (tmpfn, name) < 0) { -    unlink (tmpfn); -    return -1; -  } +  if (link (tmpfn, name) < 0) +    { +      unlink (tmpfn); +      return -1; +    }    unlink (tmpfn);    return 0; @@ -243,27 +261,29 @@ 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);  } @@ -302,10 +322,11 @@ 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); +    }  } @@ -330,20 +351,21 @@ 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);  } @@ -361,15 +383,16 @@ lockfile_make_list (char *device)    ret = filelist_new (); -  if (ret) { -    lockfile_add_name_from_dev (ret, dev_stat.st_rdev); +  if (ret) +    { +      lockfile_add_name_from_dev (ret, dev_stat.st_rdev); -    lockfile_add_name_from_path (ret, device); +      lockfile_add_name_from_path (ret, device); -    lockfile_check_dir_for_dev (ret, "/dev/", dev_stat.st_rdev); -    lockfile_check_dir_for_dev (ret, "/dev/usb/", dev_stat.st_rdev); -    lockfile_check_dir_for_dev (ret, "/dev/tts/", dev_stat.st_rdev); -  } +      lockfile_check_dir_for_dev (ret, "/dev/", dev_stat.st_rdev); +      lockfile_check_dir_for_dev (ret, "/dev/usb/", dev_stat.st_rdev); +      lockfile_check_dir_for_dev (ret, "/dev/tts/", dev_stat.st_rdev); +    }    return ret;  } @@ -392,28 +415,34 @@ 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 *)(void *)(char *) apid; +      memcpy (&pid, apid, sizeof (pid)); +  #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); +    }  } @@ -423,11 +452,12 @@ 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); +    }  } @@ -441,18 +471,21 @@ lockfile_lock (Filelist * fl)    ret = filelist_new (); -  if (ret) { -    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); +  if (ret) +    { +      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); +        }      } -  }    return ret;  } @@ -461,10 +494,11 @@ 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); +    }  } @@ -481,10 +515,11 @@ 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; @@ -492,10 +527,11 @@ 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;  } @@ -506,14 +542,16 @@ 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);  } @@ -539,10 +577,11 @@ 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 cfd1899..03a1764 100644 --- a/src/lockfile.h +++ b/src/lockfile.h @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.12  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.11  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -55,17 +58,20 @@  #define FILE_LIST_MAX_LEN 1024 -typedef struct Filelist_ent { +typedef struct Filelist_ent +{    char name[FILE_LIST_MAX_LEN];    struct Filelist_ent *next;  } Filelist_ent; -typedef struct { +typedef struct +{    Filelist_ent *head;  } Filelist; -typedef struct { +typedef struct +{    int mode;    int i;    struct timeval last_stale_purge; @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.18  2012/06/22 10:22:24  james + * *** empty log message *** + *   * Revision 1.17  2011/02/04 16:14:16  james   * *** empty log message ***   * @@ -65,7 +68,8 @@ static char rcsid[] = "$Id$";  #include "project.h" -typedef struct { +typedef struct +{    LOG_SIGNATURE;    int do_close;    int rotate; @@ -83,17 +87,18 @@ sighup (int dummy)  {    Log *l; -  for (l = loggers; l; l = l->next) { -    if (l->sighup) -      l->sighup (l); -  } +  for (l = loggers; l; l = l->next) +    { +      if (l->sighup) +        l->sighup (l); +    }  }  void  log_register_handlers (void)  { -  struct sigaction sa = { 0 }; +  struct sigaction sa = { {0} };    sa.sa_handler = sighup;    sa.sa_flags = SA_RESTART; @@ -123,13 +128,15 @@ log_remove (Log * l)      *ptr = l->next;  } -static void flog_newline(Log *_l,int force)  +static void +flog_newline (Log * _l, int force)  {    File_Log *l = (File_Log *) _l; -  if (force || !l->needs_newline) return; +  if (force || !l->needs_newline) +    return; -  l->needs_newline=0; +  l->needs_newline = 0;    fputc ('\n', l->fp);    fflush (l->fp); @@ -150,16 +157,18 @@ flog_sighup (Log * _l)    log_f (_l, "<sighup received - opening log file>");  } -static void  -flog_emit_stamp(Log *_l) +static void +flog_emit_stamp (Log * _l)  {    File_Log *l = (File_Log *) _l;    struct timeval tv = { 0 };    struct tm *tm;    time_t t; +#if 0    static const char *days[] = { "Sun", "Mon", "Tue",      "Wed", "Thu", "Fri", "Sat"    }; +#endif    static const char *months[] = {      "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",      "Nov", "Dec" @@ -168,49 +177,56 @@ flog_emit_stamp(Log *_l)    if (!l->fp)      return; -  flog_newline(_l,0); +  flog_newline (_l, 0);    gettimeofday (&tv, NULL);    t = tv.tv_sec;    tm = localtime (&t);    fprintf (l->fp, "%s %2d %02d:%02d:%02d.%06d ", months[tm->tm_mon], -           tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec,(int) tv.tv_usec); +           tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, +           (int) tv.tv_usec);  } -static void flog_check_rotate(Log *_l) +static void +flog_check_rotate (Log * _l)  {    File_Log *l = (File_Log *) _l; -  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+"); +    }  }  static void -flog_log_bytes (Log * _l, void *_buf,int len) +flog_log_bytes (Log * _l, void *_buf, int len)  {    File_Log *l = (File_Log *) _l; -  uint8_t *buf=(uint8_t *) _buf; +  uint8_t *buf = (uint8_t *) _buf;    if (!l->fp)      return; -  while (len--) { -	if (*buf=='\n') { -	   	flog_newline(_l,1);	 -  		flog_check_rotate(_l); -  		flog_emit_stamp(_l); -	} else {  -		l->needs_newline++; -  		fputc (*buf, l->fp); -	} -	buf++; -  } +  while (len--) +    { +      if (*buf == '\n') +        { +          flog_newline (_l, 1); +          flog_check_rotate (_l); +          flog_emit_stamp (_l); +        } +      else +        { +          l->needs_newline++; +          fputc (*buf, l->fp); +        } +      buf++; +    }  }  static void @@ -221,13 +237,13 @@ flog_log (Log * _l, char *buf)    if (!l->fp)      return; -  flog_emit_stamp(_l); +  flog_emit_stamp (_l);    fputs (buf, l->fp);    fputc ('\n', l->fp);    fflush (l->fp); -  flog_check_rotate(_l); +  flog_check_rotate (_l);  } @@ -252,17 +268,21 @@ file_log_new (char *fn, int rotate)    l = xmalloc (sizeof (File_Log)); -  if (fn && strcmp (fn, "-")) { -    l->fp = fopen (fn, "a+"); -    if (!l->fp) { -      free (l); -      return NULL; +  if (fn && strcmp (fn, "-")) +    { +      l->fp = fopen (fn, "a+"); +      if (!l->fp) +        { +          free (l); +          return NULL; +        } +      l->sighup = flog_sighup; +    } +  else +    { +      l->fp = stderr; +      dc = 0;      } -    l->sighup = flog_sighup; -  } else { -    l->fp = stderr; -    dc = 0; -  }    l->log = flog_log; @@ -272,7 +292,7 @@ file_log_new (char *fn, int rotate)    l->rotate = rotate;    l->filename = strdup (fn); -  l->needs_newline=0; +  l->needs_newline = 0;    fput_cp (l->fp, 0xffef); @@ -293,32 +313,35 @@ 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 = xrealloc (buf, size); +      buf = xrealloc (buf, size); -    if (!buf) -      return; -  } +      if (!buf) +        return; +    }  } @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.8  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.7  2010/07/27 14:49:35  james   * add support for byte logging   * @@ -45,7 +48,8 @@  	void (*sighup)(struct Log_struct *); \  	void (*close)(struct Log_struct *) -typedef struct Log_struct { +typedef struct Log_struct +{    LOG_SIGNATURE;  } Log; diff --git a/src/project.h b/src/project.h index b7d9df5..59ba8c7 100644 --- a/src/project.h +++ b/src/project.h @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.12  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.11  2008/03/07 12:37:04  james   * *** empty log message ***   * @@ -104,4 +107,10 @@  #include "sympathy.h" +static inline char * +stop_wno_unused_on_rcsid (void) +{ +  return rcsid; +} +  #endif /* __PROJECT_H__ */ diff --git a/src/prototypes.h b/src/prototypes.h index 107ab1f..e92a83c 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -22,6 +22,7 @@ extern void vt102_do_resize (Context * c);  extern void vt102_log_line (Context * c, int line);  extern void vt102_history (Context * c, CRT_Pos t, CRT_Pos b);  extern void vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br); +extern int vt102_normalize_arg (int narg);  extern void vt102_cursor_normalize (VT102 * v);  extern void vt102_cursor_carriage_return (VT102 * v);  extern void vt102_cursor_advance_line (Context * c); @@ -32,9 +33,9 @@ extern void vt102_cursor_retreat (VT102 * v);  extern void vt102_reset_tabs (VT102 * v);  extern void vt102_cursor_advance_tab (VT102 * v);  extern void vt102_cursor_retreat_tab (VT102 * v); -extern int vt102_cursor_home (VT102 * v); -extern int vt102_cursor_absolute (VT102 * v, int x, int y); -extern int vt102_cursor_relative (VT102 * v, int x, int y); +extern void vt102_cursor_home (VT102 * v); +extern void vt102_cursor_absolute (VT102 * v, int x, int y); +extern void vt102_cursor_relative (VT102 * v, int x, int y);  extern void vt102_delete_from_line (VT102 * v, CRT_Pos p);  extern void vt102_insert_into_line (VT102 * v, CRT_Pos p);  extern void vt102_change_mode (Context * c, int private, char *ns, int set); @@ -44,7 +45,7 @@ extern void vt102_parse_attr_string (VT102 * v, char *buf, int len);  extern void vt102_save_state (VT102 * v);  extern void vt102_restore_state (VT102 * v);  extern void vt102_regular_char (Context * c, VT102 * v, uint32_t ch); -extern int vt102_send_id (Context * c, char *buf); +extern void vt102_send_id (Context * c, char *buf);  extern void vt102_scs (Context * c, int g, int s);  extern void vt102_status_line (VT102 * v, char *str);  extern void vt102_parser_reset (VT102_parser * p); @@ -106,6 +107,9 @@ extern void *xmalloc (size_t s);  extern void *xrealloc (void *p, size_t s);  extern char *xstrdup (const char *s);  /* log.c */ +extern void log_register_handlers (void); +extern void log_add (Log * l); +extern void log_remove (Log * l);  extern Log *file_log_new (char *fn, int rotate);  extern void log_f (Log * log, char *fmt, ...);  /* ipc.c */ @@ -126,6 +130,7 @@ extern int ipc_msg_send_setansi (Socket * s, int ansi);  extern int ipc_msg_send_hangup (Socket * s);  extern int ipc_msg_send_setsize (Socket * s, CRT_Pos size);  extern int ipc_msg_send_reset (Socket * s); +extern int ipc_msg_send_killme (Socket * s);  /* slide.c */  extern void slide_free (Slide * s);  extern void slide_consume (Slide * s, int n); @@ -177,7 +182,7 @@ extern Serial_lock *serial_lock_new (char *dev, int mode);  extern int utf8_flush (Context * c);  extern int utf8_parse (Context * c, uint32_t ch);  extern UTF8 *utf8_new (void); -extern int utf8_encode (char *ptr, int ch); +extern int utf8_encode (uint8_t * ptr, int ch);  extern int utf8_emit (TTY * t, int ch);  /* vt102_charset.c */  extern uint32_t vt102_charset_c0[128]; @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.24  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.23  2008/03/12 01:30:23  james   * *** empty log message ***   * @@ -99,7 +102,8 @@ static char rcsid[] = "$Id$";  #include "project.h" -typedef struct { +typedef struct +{    TTY_SIGNATURE;    int fd;    pid_t child; @@ -126,18 +130,19 @@ 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); @@ -151,18 +156,19 @@ 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); @@ -187,24 +193,25 @@ 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; - -    if (path[0] == '/') -      execv (path, argv); -    else -      execvp (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; + +      if (path[0] == '/') +        execv (path, argv); +      else +        execvp (path, argv); + +      _exit (-1); +    }    set_nonblocking (fd); @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.11  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.10  2011/02/28 18:10:43  james   * *** empty log message ***   * @@ -45,13 +48,15 @@ static char rcsid[] = "$Id$";  #include "project.h" -typedef struct { +typedef struct +{    RX_SIGNATURE;    int rfd;    int wfd;  } RX_Raw; -typedef struct { +typedef struct +{    TTY_SIGNATURE;  } RAW_TERMINAL; @@ -64,6 +69,8 @@ rx_raw_rx (RX * _r, int ch)    uint8_t c = ch;    set_blocking (r->wfd);    ret = (write (r->wfd, &c, 1) == 1) ? 0 : -1; + +  return ret;  }  static void @@ -89,7 +96,8 @@ rx_new_raw (int rfd, int wfd)    return (RX *) ret;  } -static int my_wrap_read (int fd, void *buf, int len) +static int +my_wrap_read (int fd, void *buf, int len)  {    int red; @@ -115,18 +123,19 @@ raw_terminal_read (TTY * _t, void *buf, int len)    set_nonblocking (t->rfd); -  do { +  do +    { -    red = my_wrap_read (t->rfd, buf, len); -    if (red < 0) -	return done ? done:-1; -    if (!red) -      return done; +      red = my_wrap_read (t->rfd, buf, len); +      if (red < 0) +        return done ? done : -1; +      if (!red) +        return done; -    buf += red; -    len -= red; -    done += red; -  } +      buf += red; +      len -= red; +      done += red; +    }    while (len); @@ -134,6 +143,7 @@ raw_terminal_read (TTY * _t, void *buf, int len)  } +#if 0  static int  raw_terminal_write (TTY * _t, void *buf, int len)  { @@ -142,24 +152,26 @@ 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);    return done;  } +#endif @@ -197,10 +209,12 @@ terminal_new_raw (int rfd, int wfd)    return (TTY *) t;  } +#if 0  static void  ansi_raw_one_shot (ANSI * a, CRT * c)  {  } +#endif  static int  ansi_raw_key (ANSI * a, Context * c, int key) @@ -228,10 +242,11 @@ ansi_raw_dispatch (ANSI * a, Context * c)    if (red <= 0)      return red; -  ansi_raw_parse (a, c, buf, red); +  ansi_raw_parse (a, c, (uint8_t *) buf, red);    return 0;  } +  static void  ansi_raw_free (ANSI * a)  { diff --git a/src/render.c b/src/render.c index 666dbda..5434201 100644 --- a/src/render.c +++ b/src/render.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.4  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.3  2008/03/07 12:37:04  james   * *** empty log message ***   * @@ -20,3 +23,5 @@ static char rcsid[] = "$Id$";   * *** empty log message ***   *   */ + +#include "project.h" @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.9  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.8  2008/03/07 13:16:02  james   * *** empty log message ***   * @@ -43,14 +46,15 @@ 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;  } @@ -60,14 +64,15 @@ 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;  } @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.7  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.6  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -35,7 +38,8 @@  #ifndef __RING_H__  #define __RING_H__ -typedef struct { +typedef struct +{    uint8_t *ring;    int wptr;    int rptr; diff --git a/src/rotate.c b/src/rotate.c index bd4f040..12cfec9 100644 --- a/src/rotate.c +++ b/src/rotate.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.12  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.11  2010/07/16 11:04:10  james   * ignore tedious return values   * @@ -55,13 +58,14 @@ 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; +    }    int result; @@ -82,15 +86,16 @@ rotate (char *file)    buf1 = xmalloc (i);    buf2 = xmalloc (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); @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.6  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.5  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -37,7 +40,8 @@    void (*close)(struct RX_struct *); -typedef struct RX_struct { +typedef struct RX_struct +{    RX_SIGNATURE;  } RX; diff --git a/src/serial.c b/src/serial.c index 731bae7..5c880a2 100644 --- a/src/serial.c +++ b/src/serial.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.19  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.18  2011/02/06 16:51:22  james   * *** empty log message ***   * @@ -99,7 +102,8 @@ static char rcsid[] = "$Id$";  #include <sys/stat.h> -typedef struct { +typedef struct +{    TTY_SIGNATURE;    Serial_lock *lock;    int fd; @@ -131,18 +135,19 @@ 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 done ? done:-1; -    if (!red) -      return done; +      red = wrap_read (t->fd, buf, len); +      if (red < 0) +        return done ? done : -1; +      if (!red) +        return done; -    buf += red; -    len -= red; -    done += red; -  } +      buf += red; +      len -= red; +      done += red; +    }    while (len); @@ -160,18 +165,19 @@ 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); @@ -182,9 +188,6 @@ TTY *  serial_open (char *path, int lock_mode)  {    Serial *t; -  pid_t child; -  char name[1024]; -  struct winsize winsize = { 0 };    struct termios termios;    int fd;    Serial_lock *l; @@ -199,16 +202,18 @@ 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 *) xmalloc (sizeof (Serial)); diff --git a/src/slide.c b/src/slide.c index 692b8d5..1f89966 100644 --- a/src/slide.c +++ b/src/slide.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.9  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.8  2008/03/07 14:13:40  james   * *** empty log message ***   * @@ -64,10 +67,11 @@ 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); +    }  } diff --git a/src/slide.h b/src/slide.h index d92726b..789707d 100644 --- a/src/slide.h +++ b/src/slide.h @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.6  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.5  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -38,7 +41,8 @@  #ifndef __SLIDE_H__  #define __SLIDE_H__ -typedef struct { +typedef struct +{    uint8_t *slide;    int nbytes;    int target_size; diff --git a/src/sympathy.h.head.in b/src/sympathy.h.head.in index 1e67cbb..22fcc1e 100644 --- a/src/sympathy.h.head.in +++ b/src/sympathy.h.head.in @@ -12,6 +12,9 @@  /*   * $Log$ + * Revision 1.5  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.4  2010/07/16 11:06:39  james   * add missing G2   * @@ -91,5 +94,4 @@ extern "C" {  #include <termio.h>  #include <termios.h> - - +#include <string.h> diff --git a/src/symsocket.c b/src/symsocket.c index 653cd35..db90475 100644 --- a/src/symsocket.c +++ b/src/symsocket.c @@ -11,6 +11,9 @@ static char rcsid[] =  /*    * $Log$ + * Revision 1.14  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.13  2008/03/07 14:13:40  james   * *** empty log message ***   * @@ -101,10 +104,11 @@ 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);  } @@ -149,18 +153,20 @@ 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); @@ -180,7 +186,7 @@ Socket *  socket_accept (Socket * l)  {    Socket *ret; -  int len; +  socklen_t len;    int fd;    struct sockaddr_un sun; @@ -228,11 +234,12 @@ 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); @@ -252,7 +259,6 @@ socket_connect (char *path)  void  socket_consume_msg (Socket * s)  { -  int n;    if (!s->msg)      return; @@ -265,14 +271,13 @@ socket_consume_msg (Socket * s)  void  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; -  } +  if (SOCKET_IS_LISTENER (s)) +    { +      FD_SET (s->fd, rfds); +      return; +    }    if (!SLIDE_EMPTY (s->write_buf))      FD_SET (s->fd, wfds); @@ -285,32 +290,33 @@ socket_pre_select (Socket * s, fd_set * rfds, fd_set * wfds)  int  socket_post_select (Socket * s, fd_set * rfds, fd_set * wfds)  { -  char buf[1024];    int n;    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); @@ -332,9 +338,11 @@ socket_write (Socket * s, void *buf, int len)      (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 0    {      uint8_t *c = SLIDE_RPTR (s->write_buf);    } +#endif    if (n > 0)      slide_consume (s->write_buf, n); diff --git a/src/symsocket.h b/src/symsocket.h index 7d93beb..a46b9fb 100644 --- a/src/symsocket.h +++ b/src/symsocket.h @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.7  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.6  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -35,7 +38,8 @@  #ifndef __SYMSOCKET_H__  #define __SYMSOCKET_H__ -typedef struct { +typedef struct +{    int fd;    Slide *read_buf; diff --git a/src/terminal.c b/src/terminal.c index 301ea74..4f31372 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -11,6 +11,9 @@ static char rcsid[] =  /*    * $Log$ + * Revision 1.25  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.24  2008/03/12 10:47:26  james   * @@   * @@ -106,7 +109,8 @@ static char rcsid[] =  #include "project.h" -typedef struct TERMINAL_struct { +typedef struct TERMINAL_struct +{    TTY_SIGNATURE;    struct termios orig_termios;    struct TERMINAL_struct *next; @@ -149,8 +153,11 @@ terminal_close (TTY * _t)    t->xmit (_t, "\033[?25h", 6); // Show cursor    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 +  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 @@ -191,13 +198,16 @@ 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; +    }  } @@ -227,18 +237,19 @@ 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); @@ -256,19 +267,20 @@ 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); @@ -279,7 +291,7 @@ terminal_write (TTY * _t, void *buf, int len)  void  terminal_register_handlers (void)  { -  struct sigaction sa = { 0 }; +  struct sigaction sa = { {0} };    sa.sa_handler = sigwinch;    sa.sa_flags = SA_RESTART; @@ -295,7 +307,6 @@ TTY *  terminal_open (int rfd, int wfd)  {    TERMINAL *t; -  pid_t child;    struct termios termios;    t = (TERMINAL *) xmalloc (sizeof (TERMINAL)); @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.28  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.27  2010/07/27 14:49:35  james   * add support for byte logging   * @@ -93,84 +96,85 @@ 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;  } @@ -178,84 +182,85 @@ 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;  } @@ -265,16 +270,18 @@ 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); @@ -302,7 +309,7 @@ tty_get_baud (TTY * t)    struct termios tios = { 0 };    if (tcgetattr (t->rfd, &tios)) -    return; +    return 0;    return speed_t_to_baud (cfgetispeed (&tios));  } @@ -383,7 +390,8 @@ tty_winch (TTY * t, CRT_Pos size)  #if 0 -typedef struct { +typedef struct +{    int in_dle;    int in_errmark; @@ -394,14 +402,14 @@ typedef struct {  #define DLE 0377  #define bit(p,b,z,o) \  	do { \ -	  if ((b && z)) { \ -	    p->bitfreq[z]++; \ +	  if (((b) && z)) { \ +	    (p)->bitfreq[(z)]++; \  	    z = 0; \  	  } \   	  \ -	  if ((!b && o)) \ +	  if ((!(b) && o)) \  	  { \ -	    p->bitfreq[z]++; \ +	    (p)->bitfreq[z]++; \  	    o = 0; \  	  } \   	  \ @@ -421,28 +429,31 @@ 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, -           "<tty_bit_analyse: 0%d%d%d%d%d%d%d%d1  [%d,%d,%d,%d,%d,%d,%d,%d,%d,%d]>", -           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, +             "<tty_bit_analyse: 0%d%d%d%d%d%d%d%d1  [%d,%d,%d,%d,%d,%d,%d,%d,%d,%d]>", +             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]); +    }  } @@ -462,54 +473,64 @@ 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 && j > 0) -      p->guessed_baud = i / j; -    else -      p->guessed_baud = 0; +    } +  else +    { +      if (i > 0 && j > 0) +        p->guessed_baud = i / j; +      else +        p->guessed_baud = 0; -  } +    } -  if (p->guessed_baud == -1) { -    log_f (c->l, "<tty_analyse: %6d errors, current rate %db is too low>", -           p->biterrs, i); -  } else { -    log_f (c->l, "<tty_analyse: %6d errors, current rate %db, suggest %db>", -           p->biterrs, i, p->guessed_baud); -  } +  if (p->guessed_baud == -1) +    { +      log_f (c->l, "<tty_analyse: %6d errors, current rate %db is too low>", +             p->biterrs, i); +    } +  else +    { +      log_f (c->l, "<tty_analyse: %6d errors, current rate %db, suggest %db>", +             p->biterrs, i, p->guessed_baud); +    }  } @@ -533,48 +554,57 @@ 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, "<tty reports error: \\377 \\000 \\%03o>", -             __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); - +  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, "<tty reports error: \\377 \\000 \\%03o>", +                 __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++;      } -    buf++; -  }    return err;  } @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.17  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.16  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -84,7 +87,8 @@  #define TTY_BITFREQ_LEN	10 -typedef struct { +typedef struct +{    int in_dle;    int in_errmark; @@ -96,11 +100,13 @@ typedef struct {  } TTY_Parser; -typedef struct TTY_struct { +typedef struct TTY_struct +{    TTY_SIGNATURE;  } TTY; -typedef struct { +typedef struct +{    int lines;    int blocked;    struct termios termios; @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.17  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.16  2010/07/27 14:49:35  james   * add support for byte logging   * @@ -70,24 +73,25 @@ utf8_flush (Context * c)    int i;    int err = 0; -  switch (u->utf_ptr) { -  case 1: -    log_f (c->l, "<invalid utf-8 sequence: \\%03o>", u->utf_buf[0]); -    break; -  case 2: -    log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o>", -           u->utf_buf[0], u->utf_buf[1]); -    break; -  case 3: -    log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o \\%03o>", -           u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]); -    break; -  case 4: -    log_f (c->l, -           "<invalid utf-8 sequence: \\%03o \\%03o \\%03o \\%03o>", -           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, "<invalid utf-8 sequence: \\%03o>", u->utf_buf[0]); +      break; +    case 2: +      log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o>", +             u->utf_buf[0], u->utf_buf[1]); +      break; +    case 3: +      log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o \\%03o>", +             u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]); +      break; +    case 4: +      log_f (c->l, +             "<invalid utf-8 sequence: \\%03o \\%03o \\%03o \\%03o>", +             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]); @@ -105,59 +109,75 @@ utf8_parse (Context * c, uint32_t ch)    UTF8 *u = c->u;    int err = 0; -  if (ch == SYM_CHAR_RESET) { -    u->in_utf8 = 0; -    err += vt102_parse_char (c, ch); -    return err; -  } - -  if (c->l && c->byte_logging) { -	uint8_t ch8=(uint8_t) ch; -	c->l->log_bytes(c->l,&ch8,1); -  } - -  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 { +  if (ch == SYM_CHAR_RESET) +    { +      u->in_utf8 = 0;        err += vt102_parse_char (c, ch); +      return err;      } -  } 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); + +  if (c->l && c->byte_logging) +    { +      uint8_t ch8 = (uint8_t) ch; +      c->l->log_bytes (c->l, &ch8, 1); +    } + +  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); +        }      } -  }    return err;  } @@ -172,31 +192,39 @@ utf8_new (void)    ret->in_utf8 = 0; +  return ret;  }  int -utf8_encode (char *ptr, int ch) +utf8_encode (uint8_t * 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;  } @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.9  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.8  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -43,7 +46,8 @@  #define __UTF8_H__ -typedef struct { +typedef struct +{    int in_utf8;    uint8_t utf_buf[4]; @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.12  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.11  2008/03/07 14:13:40  james   * *** empty log message ***   * @@ -86,7 +89,7 @@ wrap_write (int fd, void *buf, int len)  void  set_nonblocking (int fd)  { -  long arg; +  long arg = 0;    arg = fcntl (fd, F_GETFL, arg);    arg |= O_NONBLOCK;    fcntl (fd, F_SETFL, arg); @@ -95,7 +98,7 @@ set_nonblocking (int fd)  void  set_blocking (int fd)  { -  long arg; +  long arg = 0;    arg = fcntl (fd, F_GETFL, arg);    arg &= ~O_NONBLOCK;    fcntl (fd, F_SETFL, arg); @@ -165,7 +168,7 @@ fput_cp (FILE * f, uint32_t ch)  {    char buf[4];    int i; -  i = utf8_encode (buf, ch); +  i = utf8_encode ((uint8_t *) buf, ch);    if (!i)      return 0; diff --git a/src/version.c b/src/version.c index 7770fbd..6ab803c 100644 --- a/src/version.c +++ b/src/version.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.5  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.4  2008/03/07 12:37:04  james   * *** empty log message ***   * @@ -27,6 +30,12 @@ static char rcsid[] = "$Id$";  #include "version.h" +static inline char * +stop_wno_unused_on_rcsid (void) +{ +  return rcsid; +} +  char *  libsympathy_version (void)  { diff --git a/src/vt102.c b/src/vt102.c index b82556f..05ed800 100644 --- a/src/vt102.c +++ b/src/vt102.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";  /*    * $Log$ + * Revision 1.68  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.67  2010/07/27 14:49:35  james   * add support for byte logging   * @@ -406,10 +409,11 @@ 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); @@ -449,17 +453,20 @@ vt102_log_line (Context * c, int line)    if (!c->l || c->byte_logging)      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 ((uint8_t *) logptr, ch); +    }    *logptr = 0;    c->l->log (c->l, logbuf); @@ -496,16 +503,29 @@ vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br)  } +int +vt102_normalize_arg (int narg) +{ +  if (narg < 0) +    return 0; + +  if (narg > VT102_MAX_ARG) +    return VT102_MAX_ARG; + +  return narg; +} +  void  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); +    }  } @@ -525,14 +545,15 @@ vt102_cursor_advance_line (Context * c)    /* 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); +      && (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++; @@ -549,12 +570,13 @@ vt102_cursor_retreat_line (Context * c)    /* have wraped off end of first 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--; @@ -580,11 +602,14 @@ vt102_do_pending_wrap (Context * c)    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);  } @@ -594,12 +619,13 @@ 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); @@ -610,9 +636,10 @@ 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;  } @@ -624,20 +651,23 @@ 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;  } @@ -646,14 +676,16 @@ 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;  } +void  vt102_cursor_home (VT102 * v)  {    v->pos = v->top_margin; @@ -662,19 +694,24 @@ vt102_cursor_home (VT102 * v)  } +void  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;  } +void  vt102_cursor_relative (VT102 * v, int x, int y)  {    v->pos.x += x; @@ -693,11 +730,12 @@ 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 */ @@ -711,11 +749,12 @@ 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; @@ -731,45 +770,50 @@ 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: -      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: +          v->current_size.x = +            v->private_modes[VT102_PRIVATE_MODE_132COLS] ? VT102_COLS_132 : +            VT102_COLS_80; -      vt102_do_resize (c); -      break; -    } +          vt102_do_resize (c); +          break; +        } -  } else +    } +  else      v->modes[m] = set;  }  void  vt102_parse_mode_string (Context * c, char *buf, int len)  { -  VT102 *v = c->v; +  //VT102 *v = c->v;    int private = 0;    char last = buf[len - 1];    char num[4]; @@ -780,33 +824,36 @@ 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'); @@ -819,105 +866,109 @@ 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; +    }  } @@ -925,8 +976,6 @@ vt102_change_attr (VT102 * v, char *na)  void  vt102_parse_attr_string (VT102 * v, char *buf, int len)  { -  int private = 0; -  char last = buf[len - 1];    char num[4];    int o; @@ -938,24 +987,26 @@ 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]);  } @@ -993,14 +1044,18 @@ 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; @@ -1008,13 +1063,15 @@ vt102_regular_char (Context * c, VT102 * v, uint32_t ch)  } +void  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 @@ -1024,28 +1081,30 @@ 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; +    }  } @@ -1064,267 +1123,291 @@ vt102_parse_csi (Context * c, char *buf, int len)    last = buf[len - 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; - -        y = narg - 1; +  if (len > 2) +    { +      narg = atoi (arg); +    } +  else +    { +      narg = 1; +    } -        ptr = index (arg, ';'); -        if (ptr) -          x = atoi (ptr + 1) - 1; -        else -          x = 0; +  narg = vt102_normalize_arg (narg); -        vt102_cursor_absolute (v, x, y); -      } -      break; -    case 'I':                  /* CHT */ -      while (narg--) -        vt102_cursor_advance_tab (c->v); -      break; -    case 'J':                  /* ED */ -      /* Different default */ -      if (len == 2) -        narg = 0; -      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 }; -        /* Different default */ -        if (len == 2) -          narg = 0; - -        switch (narg) { -        case 0: -          crt_erase (&v->crt, v->pos, le, 1, v->color); +  switch (buf[0]) +    { +    case '[':                  /* CSI */ +      switch (last) +        { +        case '@':              /* ICH */ +          while (narg--) +            vt102_insert_into_line (v, v->pos);            break; -        case 1: -          crt_erase (&v->crt, ls, v->pos, 1, v->color); +        case 'A':              /* CUU */ +          vt102_cursor_relative (v, 0, -narg);            break; -        case 2: -          crt_erase (&v->crt, ls, le, 1, v->color); +        case 'e':              /* VPR */ +        case 'B':              /* CUD */ +          vt102_cursor_relative (v, 0, narg);            break; -        } -      } -      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; -    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; +            y = narg - 1; -    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, +            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 */ +          /* Different default */ +          if (len == 2) +            narg = 0; +          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 'X':                  /* ECH */ -      { -        CRT_Pos end = v->pos; -        if (!narg) -          narg++; +              break; +            } +          break; +        case 'K':              /* EL */ +          { +            CRT_Pos ls = { 0, v->pos.y }; +            CRT_Pos le = { v->current_size.x - 1, v->pos.y }; +            /* Different default */ +            if (len == 2) +              narg = 0; + +            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; +              } +          } +          break; -        end.x += narg - 1; -        if (end.x > v->bottom_margin.x) -          end.x = v->bottom_margin.x; +        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; -        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 */ -      /* Different default */ -      if (len == 2) -        narg = 0; - -      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++; + +            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 */ +          /* Different default */ +          if (len == 2) +            narg = 0; + +          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; -      } +        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; -      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; +        default: +          log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__, +                 buf); -      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 CSI: \\033%s>", __FILE__, __LINE__, buf); - +      log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, +             __LINE__, buf);        ;      } -    break; -  default: -    log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, -           __LINE__, buf); -    ; -  } @@ -1345,198 +1428,202 @@ 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; +  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; +      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 err; +    } + + +  /*  +   * 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 'G':                  /* EXIT GRAPHICS MODE */ -      v->cs = 0; -      v->g[0] = VT102_CSID_US; + +    case 'E':                  /* NEL */ +      vt102_cursor_advance_line (c); +      v->pos.x = v->top_margin.x; +      vt102_cursor_normalize (v); +      v->pending_wrap = 0;        break; -    case 'H':                  /* CURSOR HOME */ -      vt102_cursor_absolute (v, 0, 0); +      /* F SSA */ +      /* G ESA */ +    case 'H':                  /* HTS */ +      v->tabs[v->pos.x]++;        break; -    case 'I':                  /* REVERSE LINE FEED */ +      /* I HTJ */ +      /* J VTS */ +      /* K PLD */ +      /* L PLU */ +    case 'M':                  /* RI */        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); -      } +    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 'Y':                  /* DIRECT CURSOR ADDRESS */ -      vt102_cursor_absolute (v, p->cmd_buf[2] - 040, p->cmd_buf[1] - 040); +    case 'c':                  /* RIS */ +      vt102_reset (c);        break; -    case 'V':                  /* PRINT CURSOR LINE */ -      // Print current line +    case '=': +      /* DECKPAM */ +      v->application_keypad_mode = 1;        break; -    case 'W': -      // Printer on +    case '>': +      /* DECKPNM */ +      v->application_keypad_mode = 0;        break; -    case 'X': -      // printer off + +    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])); + +        }        break; -    case ']':                  /* PRINT SCREEN */ -      // print screen +    case '<':                  /* DECANM */ +      // Set ansi mode - ignored         break; -    case 'Z':                  // ID -      vt102_send_id (c, "\033/K"); +    case '7':                  /* DECSC */ +      vt102_save_state (v);        break; -    case '^': -      // Autoprint on +    case '8':                  /* DECRC */ +      vt102_restore_state (v);        break; -    case '_': -      // Autoprint off +    case ']': +      /* Set various titles in xterm - ignored */        break; -    case '=':                  /* ENTER ALTERNATE KEYPAD MODE */ -      v->application_keypad_mode = 1; +    case '[':                  /* CSI */ +      err += vt102_parse_csi (c, p->cmd_buf, p->cmd_ptr);        break; -    case '>':                  /* EXIT ALTERNATE KEYPAD MODE */ -      v->application_keypad_mode = 0; +      /* Charsets */ +    case '(':                  /* SCS */ +    case ')':                  /* SCS */ +    case '+':                  /* SCS */ +    case '*':                  /* SCS */ +    case '%':                  /* SCS */ +      vt102_scs (c, p->cmd_buf[0], p->cmd_buf[1]);        break;      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 '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])); +      log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__, +             __LINE__, p->cmd_buf[0], safe_ch (p->cmd_buf[0])); +      ;      } -    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 @@ -1552,21 +1639,23 @@ 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++; +    }  } @@ -1614,7 +1703,7 @@ vt102_reset_state (Context * c)  static void  pre_parse_cmd (int ch, VT102_parser * p)  { -  if (ch > TABLE_LENGTH) +  if (ch >= TABLE_LENGTH)      return;    if (ch < 0)      return; @@ -1623,17 +1712,19 @@ 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 @@ -1659,84 +1750,47 @@ 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; -    } +          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; -    } +      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->in_cmd) +        { +          err += vt102_parse_esc (c); +          p->cmd_more_bytes = 0; +          p->cmd_termination = 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); - -    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 */ -      /* C1 chars are equavlent to ESC ch-0x40 */ +  else if (p->in_escape && !ctrl_chr (ch, 0)) +    {        p->cmd_ptr = 0;        p->cmd_buf[p->cmd_ptr++] = ch;        p->in_escape = 0; @@ -1745,65 +1799,198 @@ vt102_parse_char (Context * c, int ch)        if (!p->in_cmd)          err += vt102_parse_esc (c); -      break;      } -  } else { +  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 */ +          /* C1 chars are equavlent to ESC ch-0x40 */ +          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); +          break; +        } +    } +  else +    {  #ifdef DEBUG -    if (ch != 27) -      log_f (c->l, -             "<chr in  x=%3d y=%2d aw=%d  \\%03o %3d %c", -             v->pos.x, v->pos.y, v->pending_wrap, ch, ch, safe_ch (ch)); +      if (ch != 27) +        log_f (c->l, +               "<chr in  x=%3d y=%2d aw=%d  \\%03o %3d %c", +               v->pos.x, v->pos.y, v->pending_wrap, ch, ch, safe_ch (ch));  #endif -    switch (ch) { -    case 0:                    /* NUL */ -      break; +      switch (ch) +        { +        case 0:                /* NUL */ +          break; +#ifdef HIDE_NON_PRINTABLES +        case 1:                /* SOH */ +        case 2:                /* STX */ +        case 3:                /* ETX */ +        case 4:                /* EOT */ +          break; +#endif +        case 5:                /* ENQ */ +          vt102_send_id (c, terminal_id); +          break; +#ifdef HIDE_NON_PRINTABLES +        case 6:                /* ACK */ +          break; +#endif +        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 +        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 +        case 27:               /* ESC */ +          p->in_escape++; +          break; +#ifdef HIDE_NON_PRINTABLES +        case 28:               /* FS */ +        case 29:               /* GS */ +        case 30:               /* RS */ +        case 31:               /* US */ +        case 127:              /* DEL */ +          break; +#endif +        default:               /* regular character */ +          vt102_regular_char (c, v, ch); +          err += vt102_rx_hook (c, ch); +        } + +#ifdef DEBUG +      if (ch != 27) +        log_f (c->l, "<chr out x=%3d y=%2d aw=%d>", v->pos.x, v->pos.y, +               v->pending_wrap); +#endif +    } + +  vt102_crt_update (c); + +  return err; +} + + +void +vt102_send (Context * c, uint8_t key) +{ +  uint8_t ch; + +  if (!c->t) +    return; + +  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 */ -      break; -#endif      case 5:                    /* ENQ */ -      vt102_send_id (c, terminal_id); -      break; -#ifdef HIDE_NON_PRINTABLES      case 6:                    /* ACK */ -      break; -#endif      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; +      c->t->xmit (c->t, &key, 1); +      break;      case 13:                   /* CR */ -      vt102_cursor_carriage_return (v); -      err += vt102_rx_hook (c, 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;      case 14:                   /* SO */ -      /* select G1 */ -      v->cs = 1; -      break;      case 15:                   /* SI */ -      /* select G0 */ -      v->cs = 0; -      break; -#ifdef HIDE_NON_PRINTABLES      case 16:                   /* DLE */      case 17:                   /* DC1 */      case 18:                   /* DC2 */ @@ -1815,210 +2002,140 @@ vt102_parse_char (Context * c, int ch)      case 24:                   /* CAN */      case 25:                   /* EM */      case 26:                   /* SUB */ +      c->t->xmit (c->t, &key, 1);        break; -#endif      case 27:                   /* ESC */ -      p->in_escape++; -      break; -#ifdef HIDE_NON_PRINTABLES      case 28:                   /* FS */      case 29:                   /* GS */      case 30:                   /* RS */      case 31:                   /* US */      case 127:                  /* DEL */ +      c->t->xmit (c->t, &key, 1);        break; -#endif -    default:                   /* regular character */ -      vt102_regular_char (c, v, ch); -      err += vt102_rx_hook (c, ch); -    } - -#ifdef DEBUG -    if (ch != 27) -      log_f (c->l, "<chr out x=%3d y=%2d aw=%d>", v->pos.x, v->pos.y, -             v->pending_wrap); -#endif -  } - -  vt102_crt_update (c); - -  return err; -} +    case KEY_UP: +    case KEY_DOWN: +    case KEY_RIGHT: +    case KEY_LEFT: +    case KEY_HOME: +    case KEY_MIDDLE: +    case KEY_END: -void -vt102_send (Context * c, uint8_t key) -{ -  uint8_t ch; - -  if (!c->t) -    return; - -  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); +      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 ((char *) buf, "\033[%d~", (key - KEY_180)); +        c->t->xmit (c->t, &buf, i); +      } +      break;      } -    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; -  }  } @@ -2066,23 +2183,26 @@ 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 246c6f0..8a7f419 100644 --- a/src/vt102.h +++ b/src/vt102.h @@ -12,6 +12,9 @@  /*    * $Log$ + * Revision 1.26  2012/06/22 10:22:25  james + * *** empty log message *** + *   * Revision 1.25  2008/03/10 11:49:33  james   * *** empty log message ***   * @@ -93,7 +96,7 @@  #define __VT102_H__  #define VT102_CMD_LEN 128 - +#define VT102_MAX_ARG 1024  #define VT102_MAX_ROWS		((CRT_ROWS) - 1)  #define VT102_ROWS_24		24  #define VT102_COLS_132		132 @@ -104,7 +107,8 @@  #define VT102_NMODES		32 -typedef struct { +typedef struct +{    int in_escape;    int in_cmd; @@ -114,7 +118,8 @@ typedef struct {    char cmd_buf[VT102_CMD_LEN];  } VT102_parser; -typedef struct { +typedef struct +{    CRT_Pos pos;    int attr;    int color; @@ -122,7 +127,8 @@ typedef struct {  } VT102_State; -typedef struct { +typedef struct +{    CRT_Pos top_margin, bottom_margin;    CRT_Pos screen_start, screen_end;    VT102_parser parser;  | 
