aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjames <>2008-02-22 23:39:30 +0000
committerjames <>2008-02-22 23:39:30 +0000
commit029a61812e82b58803c618ed53df42180106412f (patch)
treea35826fd1212f55fb0693dac8ebfeee0b6e35180
parent22301df1f4af5937bf96cb85091d5220d206d9bc (diff)
downloadsympathy-029a61812e82b58803c618ed53df42180106412f.tar.gz
sympathy-029a61812e82b58803c618ed53df42180106412f.tar.bz2
sympathy-029a61812e82b58803c618ed53df42180106412f.zip
*** empty log message ***
-rw-r--r--apps/mainloop.c7
-rw-r--r--src/Makefile.am7
-rw-r--r--src/context.h4
-rw-r--r--src/prototypes.h12
-rw-r--r--src/tty.c107
-rw-r--r--src/tty.h20
-rw-r--r--src/utf8.c73
-rw-r--r--src/utf8.h11
-rw-r--r--src/vt102.c5
9 files changed, 196 insertions, 50 deletions
diff --git a/apps/mainloop.c b/apps/mainloop.c
index fd8f982..7fb269a 100644
--- a/apps/mainloop.c
+++ b/apps/mainloop.c
@@ -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);
}
}
diff --git a/src/Makefile.am b/src/Makefile.am
index d162ccd..ad3e0ad 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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
diff --git a/src/context.h b/src/context.h
index 358a938..255be5a 100644
--- a/src/context.h
+++ b/src/context.h
@@ -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__ */
diff --git a/src/prototypes.h b/src/prototypes.h
index f0aaa8a..39e03ae 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -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);
diff --git a/src/tty.c b/src/tty.c
index 1765878..1ac8c87 100644
--- 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++;
+ }
+}
diff --git a/src/tty.h b/src/tty.h
index 5585a02..47b3cad 100644
--- 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 ***
*
@@ -57,14 +60,27 @@
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;
diff --git a/src/utf8.c b/src/utf8.c
index 18ca3eb..09066db 100644
--- a/src/utf8.c
+++ b/src/utf8.c
@@ -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*/
diff --git a/src/utf8.h b/src/utf8.h
index faa8d7a..cbfcb7f 100644
--- a/src/utf8.h
+++ b/src/utf8.h
@@ -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 ***
*
@@ -24,11 +27,9 @@
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__ */
diff --git a/src/vt102.c b/src/vt102.c
index e136637..7a1a098 100644
--- a/src/vt102.c
+++ b/src/vt102.c
@@ -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;