chiark / gitweb /
*** empty log message ***
authorjames <james>
Fri, 22 Feb 2008 23:39:27 +0000 (23:39 +0000)
committerjames <james>
Fri, 22 Feb 2008 23:39:27 +0000 (23:39 +0000)
apps/mainloop.c
src/Makefile.am
src/context.h
src/prototypes.h
src/tty.c
src/tty.h
src/utf8.c
src/utf8.h
src/vt102.c

index fd8f9821525d0d98b15f316203770e39c5c40122..7fb269adeda9c124b405e065d9c475153e4715eb 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.8  2008/02/22 23:39:30  james
+ * *** empty log message ***
+ *
  * Revision 1.7  2008/02/20 20:16:07  james
  * *** empty log message ***
  *
@@ -334,7 +337,7 @@ msg_from_server (ANSI *a,IPC_Msg * m, Context * c)
       //FIXME HTML hook
       break;
     case IPC_MSG_TYPE_TERM:
-      vt102_parse (c, m->term.term, m->term.len);
+      tty_parse (c, m->term.term, m->term.len);
       break;
     case IPC_MSG_TYPE_STATUS:
       cmd_new_status (c->d, c, m->status.status);
@@ -464,7 +467,7 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
             {
               if (clients)
                 send_output (clients, buf, red);
-              vt102_parse (&c, buf, red);
+              tty_parse (&c, buf, red);
             }
         }
 
index d162ccd2c7936da9b511161dd89dec682ca90fde..ad3e0ada9239b9fe364d4163954cd772b6c97ee9 100644 (file)
@@ -8,6 +8,9 @@
 # $Id$
 #
 # $Log$
+# Revision 1.16  2008/02/22 23:39:27  james
+# *** empty log message ***
+#
 # Revision 1.15  2008/02/15 16:48:56  james
 # *** empty log message ***
 #
@@ -60,7 +63,7 @@
 INCLUDES=
 
 # NB order here matters.
-PROJECTHDRS= crt.h tty.h ansi.h vt102.h keys.h history.h ring.h slide.h \
+PROJECTHDRS= crt.h utf8.h tty.h ansi.h vt102.h keys.h history.h ring.h slide.h \
                log.h ipc.h symsocket.h keydis.h cmd.h lockfile.h context.h \
                prototypes.h
 
@@ -68,7 +71,7 @@ HDRS=project.h
 
 SRCS=ansi.c crt.c html.c libsympathy.c render.c  version.c vt102.c tty.c \
        keydis.c history.c ring.c ptty.c terminal.c util.c log.c ipc.c \
-       slide.c symsocket.c  serial.c cmd.c lockfile.c
+       slide.c symsocket.c  serial.c cmd.c lockfile.c utf8.c
 
 CPROTO=cproto
 
index 358a938cc03d2f6760cc808fde3de0c71d0cd31d..255be5a414fe27e7402dea8a1bae3dd41521c5e9 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.7  2008/02/22 23:39:27  james
+ * *** empty log message ***
+ *
  * Revision 1.6  2008/02/15 03:32:07  james
  * *** empty log message ***
  *
@@ -43,6 +46,7 @@ typedef struct Context_struct
   Log *l;
   KeyDis *k;
   Cmd *d;
+  UTF8 *u;
 } Context;
 
 #endif /* __CONTEXT_H__ */
index f0aaa8a186a6b87627add7d2cddea5b8b9b56fed..39e03ae1763a44243778ab463c46e5e5f4cd8bc8 100644 (file)
@@ -42,13 +42,11 @@ extern void vt102_scs(Context *c, int g, int s);
 extern void vt102_parse_esc(Context *c, int ch);
 extern void vt102_parse_csi(Context *c, char *buf, int len);
 extern void vt102_status_line(VT102 *v, char *str);
-extern void vt102_parse_char(Context *c, int ch);
-extern int vt102_parse(Context *c, char *buf, int len);
 extern void vt102_parser_reset(VT102_parser *p);
+extern void vt102_reset_state(VT102 *v);
+extern void vt102_parse_char(Context *c, int ch);
 extern void vt102_send(Context *c, uint8_t key);
 extern void vt102_reset(VT102 *v);
-extern int vt102_dispatch(Context *c);
-extern int vt102_dispatch_one(Context *c);
 extern VT102 *vt102_new(void);
 extern void vt102_set_ansi(VT102 *v, int ansi);
 extern void vt102_free(VT102 *v);
@@ -59,6 +57,8 @@ extern void tty_set_baud(TTY *t, int rate);
 extern void tty_send_break(TTY *t);
 extern void tty_set_flow(TTY *t, int flow);
 extern void tty_hangup(TTY *t);
+extern void tty_stats(TTY_Parser *p, int err, int ch);
+extern void tty_parse(Context *c, uint8_t *buf, int len);
 /* keydis.c */
 extern KeyDis *keydis_vt102_new(void);
 extern KeyDis *keydis_ipc_new(Socket *s);
@@ -153,3 +153,7 @@ extern void lockfile_unlock(Filelist *fl);
 extern int serial_lock_check(Serial_lock *l);
 extern void serial_lock_free(Serial_lock *l);
 extern Serial_lock *serial_lock_new(char *dev, int mode);
+/* utf8.c */
+extern void utf8_flush(Context *c);
+extern int utf8_parse(Context *c, int ch);
+extern UTF8 *utf8_new(void);
index 1765878c27c977f56aa6feb5258c30b832887878..1ac8c87467fc03e3b1c78f361f48413d6397a361 100644 (file)
--- a/src/tty.c
+++ b/src/tty.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.12  2008/02/22 23:39:27  james
+ * *** empty log message ***
+ *
  * Revision 1.11  2008/02/20 18:31:53  james
  * *** empty log message ***
  *
@@ -226,10 +229,6 @@ tty_pre_select (TTY * t, fd_set * rfds, fd_set * wfds)
       timersub (&now, &t->hangup_clock, &dif);
       if (dif.tv_sec)
         {
-#if 0
-          fprintf (stderr, "+DTR\n");
-#endif
-
           line = TIOCM_DTR;
           ioctl (t->rfd, TIOCMBIS, &line);
           t->hanging_up = 0;
@@ -247,11 +246,6 @@ tty_get_status (TTY * t, TTY_Status * s)
   s->lines = 0;
   ioctl (t->rfd, TIOCMGET, &s->lines);
 
-#if 0
-  if (t->hanging_up)
-    fprintf (stderr, "s->lines & TIOCM_DTR=%x\n", s->lines & TIOCM_DTR);
-#endif
-
   if (tcgetattr (t->rfd, &s->termios))
     return -1;
 
@@ -313,24 +307,99 @@ tty_hangup (TTY * t)
 
   t->hanging_up = 1;
   gettimeofday (&t->hangup_clock, NULL);
-#if 0
-  fprintf (stderr, "-DTR\n");
-#endif
 
 }
 
 
 #if 0
-int
-tty_post_select (Context * c, fd_set * rfds, fd_set * wfds)
+typedef struct
+{
+  int in_dle;
+  int in_errmark;
+
+  int bit_edge_frequency[8];
+  int errs;
+}
+#endif
+
+#define DLE 0377
+
+#define bit(p,b,z,o) \
+       do { \
+         if ((b && z)) { \
+           p->bitfreq[z]++; \
+           z = 0; \
+         } \
+         \
+         if ((!b && o)) \
+         { \
+           p->bitfreq[z]++; \
+           o = 0; \
+         } \
+         \
+         if (b) \
+           o++; \
+         else \
+           z++; \
+         } \
+       while (0)
+
+void
+tty_stats (TTY_Parser * p, int err, int ch)
 {
+  int c = 128;
+  int zc = 0, oc = 0;
+
+  if (err)
+    p->biterrs++;
+
+  bit (p, 0, zc, oc);
 
-  if (FD_ISSET (c->t->rfd, rfds))
+  while (c)
     {
-      if (vt102_dispatch (&c))
-        return -1;
+      bit (p,ch & c,zc,oc);
+      c >>= 1;
     }
-  return 0;
+  bit (p, 1, zc, oc);
 }
 
-#endif
+void
+tty_parse (Context * c, uint8_t * buf, int len)
+{
+  TTY_Parser *p = &c->t->parser;
+
+  while (len--)
+    {
+
+      if (p->in_dle)
+        {
+          p->in_dle = 0;
+          switch (*buf)
+            {
+            case DLE:
+              tty_bit_analyse (p, 0, *buf);
+              utf8_parse (c, *buf);
+              break;
+            case 0:
+              p->in_errmark = 1;
+              break;
+            default:
+              log_f (c->l, "%s:%d DLE parsing error: \\377 \\%03o", *buf);
+            }
+        }
+      else if (p->in_errmark)
+        {
+          p->in_errmark = 0;
+          log_f (c->l, "%s:%d tty reports error: \\377 \\000 \\%03o", *buf);
+          utf8_parse (c, *buf);
+          tty_bit_analyse (p, 1, *buf);
+          utf8_parse (c, SYM_CHAR_RESET);
+        }
+      else
+        {
+          tty_bit_analyse (p, 0, *buf);
+          utf8_parse (c, *buf);
+        }
+      buf++;
+    }
+}
index 5585a027958f902cbe55792a9b7e8b754468284c..47b3cad02d74c4a55faa5464e1524a88a958080b 100644 (file)
--- a/src/tty.h
+++ b/src/tty.h
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.10  2008/02/22 23:39:27  james
+ * *** empty log message ***
+ *
  * Revision 1.9  2008/02/22 19:12:05  james
  * *** empty log message ***
  *
        int rfd; \
        int wfd; \
        int hanging_up; \
-       struct timeval hangup_clock
+       struct timeval hangup_clock; \
+       TTY_Parser parser;
+       
+
+typedef struct
+{
+  int in_dle;
+  int in_errmark;
+
+  int bitfreq[8];
+  int biterrs;
+} TTY_Parser;
+
 
 typedef struct TTY_struct
 {
   TTY_SIGNATURE;
 } TTY;
 
-typedef struct {
+typedef struct
+{
   int lines;
   int blocked;
   struct termios termios;
index 18ca3ebeab5e647126a6801d7ae2e2c032e66e64..09066db0a282bac7bb71b6d2490b91bff2d357fe 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/22 23:39:27  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/22 19:12:05  james
  * *** empty log message ***
  *
@@ -18,21 +21,61 @@ static char rcsid[] = "$Id$";
 #include "project.h"
 
 
-  /*FIXME: for the moment we bodge utf8 support*/
-  if ((ch>=0xc0) && (ch<0xe0)) /*Start of two byte unicode sequence*/
-  {
-       p->in_utf8=2;
-  } else if ((ch>=0xe0) && (ch<0xf0)) /*Start of three byte unicode sequence*/
-  {
-       p->in_utf8=3;
-  } else if ((ch>=0xf0) && (ch<0xf7)) /*Start of four byte unicode sequence*/
-       p->in_utf8=4;
+void utf8_flush(Context *c)
+{
+UTF8 *u=c->u;
+int i;
+
+for (i=0;i<u->utf_ptr;++i) 
+       vt102_parse(c,u->utf_buf[i]);
+
+u->utf_ptr=0;
+u->in_utf8=0;
+}
+
+int utf8_parse(Context *c,int ch)
+{
+UTF8 *u=&c->u;
+  
+  if (!u->in_utf8) {
+         /*FIXME: for the moment we bodge utf8 support*/
+         if (ch==0xb9) { /*CSI, not a valid utf8 start char*/
+               vt102_parse(c,ch);
+         } else if ((ch & 0xe0) == 0xc0) { /*Start of two byte unicode sequence*/
+               u->in_utf8=2;
+               u->utf_ptr=0;
+               u->utf_buf[u->utf_ptr++]=ch;
+         } else if ((ch & 0xf0) ==0xe0) { /*Start of three byte unicode sequence*/
+               u->in_utf8=3;
+               u->utf_ptr=0;
+               u->utf_buf[u->utf_ptr++]=ch;
+         } else if ((ch & 0xf8) ==0xf0) {
+               u->in_utf8=4;
+               u->utf_ptr=0;
+               u->utf_buf[u->utf_ptr++]=ch;
+         } else {
+               vt102_parse(c,ch);
+         } 
+  } else {
+       if ((ch & 0xc0) != 0x80) {
+               utf8_flush(c);
+               vt102_parse(c,ch);
+       } else {
+               u->utf_buf[u->utf_ptr++]=ch;
+               u->in_utf8--;
+       }
   }
+}
+
+
+
+UTF8 *utf8_new(void)
+{
+UTF8 *ret;
+
+ret=(UTF8 *) malloc(sizeof(UTF8));
+
+ret->in_utf8=0;
 
-  if (p->utf_8) {
-       p->in_utf8--;
-       ch='?';
-  }  
+}
 
-  if (!p->utf_8)  {
-       /*Not first or last byte in sequence*/
index faa8d7ab1755b71a402235beae5b3405c1708eeb..cbfcb7f30eca00de00de80afea444aff5b234edd 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/22 23:39:27  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/22 19:12:05  james
  * *** empty log message ***
  *
 
 typedef struct
 {
-  int in_escape;
-  int in_csi;
   int in_utf8;
-  int csi_ptr;
-  char csi_buf[VT102_CSI_LEN];
-} UTF8_Parser;
+  uint8_t utf_buf[4];
+  int utf_ptr;
+} UTF8;
 
 #endif /* __UTF8_H__ */
index e136637afd7e9c6d653e8383b4c9c4a9ee5bba3a..7a1a0982f7a384e3a45dcc2a031098103e64841a 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.33  2008/02/22 23:39:27  james
+ * *** empty log message ***
+ *
  * Revision 1.32  2008/02/22 19:12:05  james
  * *** empty log message ***
  *
@@ -1578,7 +1581,7 @@ vt102_reset (VT102 * v)
   VT102_parser *p = &v->parser;
 
   vt102_parser_reset (p);
-  vt102_reset_state(p);
+  vt102_reset_state(v);
 
   crt_cls (&v->crt);
   v->current_line = v->pos;