aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjames <>2008-02-23 11:49:23 +0000
committerjames <>2008-02-23 11:49:23 +0000
commitfc338d9b30500f311d9555545477e4ba1775b403 (patch)
treea860ad9af01332c74527e49bac77662af3e99f3b
parent029a61812e82b58803c618ed53df42180106412f (diff)
downloadsympathy-fc338d9b30500f311d9555545477e4ba1775b403.tar.gz
sympathy-fc338d9b30500f311d9555545477e4ba1775b403.tar.bz2
sympathy-fc338d9b30500f311d9555545477e4ba1775b403.zip
*** empty log message ***
-rw-r--r--DOCS/xterm.pdfbin0 -> 45892 bytes
-rw-r--r--apps/clients.c6
-rw-r--r--apps/mainloop.c58
-rw-r--r--apps/sympathy.c16
-rw-r--r--apps/usage.c12
-rw-r--r--src/ansi.c7
-rw-r--r--src/ansi.h15
-rw-r--r--src/cmd.h18
-rw-r--r--src/context.h4
-rw-r--r--src/crt.c13
-rw-r--r--src/ipc.h53
-rw-r--r--src/keydis.c10
-rw-r--r--src/keydis.h5
-rw-r--r--src/lockfile.h15
-rw-r--r--src/log.c56
-rw-r--r--src/log.h8
-rw-r--r--src/prototypes.h275
-rw-r--r--src/ptty.c4
-rw-r--r--src/tty.c101
-rw-r--r--src/tty.h15
-rw-r--r--src/utf8.c146
-rw-r--r--src/utf8.h7
-rw-r--r--src/vt102.c137
-rw-r--r--src/vt102.h5
24 files changed, 642 insertions, 344 deletions
diff --git a/DOCS/xterm.pdf b/DOCS/xterm.pdf
new file mode 100644
index 0000000..807b2eb
--- /dev/null
+++ b/DOCS/xterm.pdf
Binary files differ
diff --git a/apps/clients.c b/apps/clients.c
index 069ae40..598121e 100644
--- a/apps/clients.c
+++ b/apps/clients.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.11 2008/02/23 11:48:51 james
+ * *** empty log message ***
+ *
* Revision 1.10 2008/02/22 17:06:59 james
* *** empty log message ***
*
@@ -66,6 +69,9 @@ client_msg (IPC_Msg * m, Context * c)
break;
case IPC_MSG_TYPE_SETBAUD:
tty_set_baud (c->t, m->setbaud.baud);
+ tty_parse_reset (c);
+
+ log_f (c->l, "<baud changed to %d>", m->setbaud.baud);
break;
case IPC_MSG_TYPE_SENDBREAK:
tty_send_break (c->t);
diff --git a/apps/mainloop.c b/apps/mainloop.c
index 7fb269a..ad2812e 100644
--- a/apps/mainloop.c
+++ b/apps/mainloop.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.9 2008/02/23 11:48:51 james
+ * *** empty log message ***
+ *
* Revision 1.8 2008/02/22 23:39:30 james
* *** empty log message ***
*
@@ -300,8 +303,29 @@ check_status (Context * c, Clients * cs)
sprintf (ptr, ", %d client%s", status.nclients,
(status.nclients == 1) ? "" : "s");
+ if (c->tp->biterrs)
+ {
+
+ ptr +=
+ sprintf (ptr, ", %d err%s", c->tp->biterrs,
+ (c->tp->biterrs == 1) ? "" : "s");
+
+ if (c->tp->guessed_baud == -1)
+ {
+ ptr += sprintf (ptr, " try higher");
+ }
+ else if (c->tp->guessed_baud > 0)
+ {
+ ptr += sprintf (ptr, " try %d", status.baud / c->tp->guessed_baud);
+ }
+ }
+
*ptr = 0;
+#if 0
+ log_f (c->l, "%s:%d %s", __FILE__, __LINE__, buf);
+#endif
+
if (cs)
send_status (cs, buf);
else
@@ -311,7 +335,7 @@ check_status (Context * c, Clients * cs)
static int
-msg_from_server (ANSI *a,IPC_Msg * m, Context * c)
+msg_from_server (ANSI * a, IPC_Msg * m, Context * c)
{
switch (m->hdr.type)
{
@@ -330,10 +354,11 @@ msg_from_server (ANSI *a,IPC_Msg * m, Context * c)
*(c->v) = m->vt102.vt102;
- if (a->one_shot) {
- a->one_shot(a,&c->v->crt);
- return 1;
- }
+ if (a->one_shot)
+ {
+ a->one_shot (a, &c->v->crt);
+ return 1;
+ }
//FIXME HTML hook
break;
case IPC_MSG_TYPE_TERM:
@@ -345,7 +370,7 @@ msg_from_server (ANSI *a,IPC_Msg * m, Context * c)
default:
fprintf (stderr, "Unhandeled message type %d\n", m->hdr.type);
}
-return 0;
+ return 0;
}
@@ -357,6 +382,8 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
Context c = { 0 };
Clients *clients;
+ c.tp = tty_parser_new ();
+ c.u = utf8_new ();
c.v = vt102_new ();
c.h = history_new (nhistory);
@@ -401,7 +428,7 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
for (;;)
{
- struct timeval tv = { 1, 0 };
+ struct timeval tv = { 0, 250000 };
if ((c.d) && (c.d->disconnect))
break;
@@ -476,18 +503,19 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
/*any data from the server */
if (client_socket)
{
- int one_shot;
+ int one_shot;
if (socket_post_select (client_socket, &rfds, &wfds))
break;
while (client_socket->msg)
{
- if (msg_from_server (ansi,client_socket->msg, &c))
- one_shot++;
-
+ if (msg_from_server (ansi, client_socket->msg, &c))
+ one_shot++;
+
socket_consume_msg (client_socket);
}
- if (one_shot) break;
+ if (one_shot)
+ break;
}
@@ -495,10 +523,10 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
if (ansi)
{
if (ansi->dispatch)
- ansi->dispatch (ansi, &c);
+ ansi->dispatch (ansi, &c);
- if (ansi->update)
- ansi->update (ansi, &c);
+ if (ansi->update)
+ ansi->update (ansi, &c);
}
}
diff --git a/apps/sympathy.c b/apps/sympathy.c
index 4ea7bf0..b24e6d0 100644
--- a/apps/sympathy.c
+++ b/apps/sympathy.c
@@ -6,10 +6,14 @@
*
*/
-static char rcsid[] = "$Id$";
+static char rcsid[] =
+ "$Id$";
/*
* $Log$
+ * Revision 1.12 2008/02/23 11:48:52 james
+ * *** empty log message ***
+ *
* Revision 1.11 2008/02/20 20:16:07 james
* *** empty log message ***
*
@@ -471,13 +475,13 @@ main (int argc, char *argv[])
if (oflags['H'])
{
- ansi=ansi_new_html(stdout);
+ ansi = ansi_new_html (stdout);
}
else
{
terminal_register_handlers ();
- ansi=ansi_new_from_terminal(terminal_open(0,1));
- ansi->reset(ansi, NULL);
+ ansi = ansi_new_from_terminal (terminal_open (0, 1));
+ ansi->reset (ansi, NULL);
}
}
@@ -485,7 +489,7 @@ main (int argc, char *argv[])
if (ansi)
{
- ansi->close(ansi);
+ ansi->close (ansi);
terminal_atexit ();
}
@@ -500,6 +504,6 @@ main (int argc, char *argv[])
socket_free (client_socket);
if (!oflags['H'])
- printf ("you have now exited sympathy\n");
+ printf ("you have now exited sympathy\n");
return 0;
}
diff --git a/apps/usage.c b/apps/usage.c
index 1a9273f..b0893d2 100644
--- a/apps/usage.c
+++ b/apps/usage.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.7 2008/02/23 11:48:52 james
+ * *** empty log message ***
+ *
* Revision 1.6 2008/02/20 18:49:11 staffcvs
* *** empty log message ***
*
@@ -40,9 +43,9 @@ usage (void)
fprintf (stderr, "Usage:\n"
"sympathy -t [-K] [-d serialdev|-p] [-b baud] [-f] [-L log]\n"
"sympathy -s [-K] [-d serialdev|-p] [-b baud] [-f] [-L log] [-F] [-k skt]\n"
- " [-n hlines]\n"
+ " [-n hlines]\n"
"sympathy [-s -c] [-K] [-d serialdev|-p] [-b baud] [-f] [-L log] [-k skt]\n"
- " [-n hlines]\n"
+ " [-n hlines]\n"
"sympathy -c [-H] -k skt\n"
"sympathy -r id [-H]\n"
"sympathy {-l|-ls}\n"
@@ -81,9 +84,8 @@ usage (void)
" -H instead of connecting the user's terminal to the session\n"
" emit HTML of the current state of the screen on stdout\n"
" -L log activity on the device to the file log\n"
- " -n hlines the number of lines of history to store in the\n"
- " server, that are replayed on connexion\n"
-);
+ " -n hlines the number of lines of history to store in the\n"
+ " server, that are replayed on connexion\n");
exit (1);
}
diff --git a/src/ansi.c b/src/ansi.c
index 66c70f1..256f7fb 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.29 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.28 2008/02/22 17:07:00 james
* *** empty log message ***
*
@@ -531,7 +534,7 @@ ansi_history (ANSI * a, History * h)
/*Roll HISTORY_GUESS_SCROLL lines up putting the top line into the xterm's history */
- /*Make extra lines a predictable colour*/
+ /*Make extra lines a predictable colour */
ansi_set_color (a, CRT_COLOR_NORMAL);
ansi_showhide_cursor (a, 1);
@@ -559,7 +562,7 @@ ansi_history (ANSI * a, History * h)
/* erase new line */
s.y = e.y;
e.x = CRT_COLS - 1;
- crt_erase (&a->crt, s, e, 1,CRT_COLOR_NORMAL);
+ crt_erase (&a->crt, s, e, 1, CRT_COLOR_NORMAL);
}
}
diff --git a/src/ansi.h b/src/ansi.h
index 22c0bcd..8895a82 100644
--- a/src/ansi.h
+++ b/src/ansi.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.12 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.11 2008/02/20 20:16:07 james
* *** empty log message ***
*
@@ -82,12 +85,12 @@ typedef struct ANSI_struct
int history_ptr;
FILE *file;
- int (*dispatch)(struct ANSI_struct *,struct Context_struct *);
- void (*update)(struct ANSI_struct *,struct Context_struct *);
- void (*one_shot)(struct ANSI_struct *,struct CRT_struct *);
- void (*reset)(struct ANSI_struct *,struct CRT_struct *);
- void (*terminal_reset)(struct ANSI_struct *);
- void (*close)(struct ANSI_struct *);
+ int (*dispatch) (struct ANSI_struct *, struct Context_struct *);
+ void (*update) (struct ANSI_struct *, struct Context_struct *);
+ void (*one_shot) (struct ANSI_struct *, struct CRT_struct *);
+ void (*reset) (struct ANSI_struct *, struct CRT_struct *);
+ void (*terminal_reset) (struct ANSI_struct *);
+ void (*close) (struct ANSI_struct *);
} ANSI;
diff --git a/src/cmd.h b/src/cmd.h
index fb4e0ac..43a1bbf 100644
--- a/src/cmd.h
+++ b/src/cmd.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.2 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.1 2008/02/15 15:14:19 james
* *** empty log message ***
*
@@ -20,14 +23,15 @@
#ifndef __CMD_H__
#define __CMD_H__
-#define CMD_KEY 2 /*CTRL B*/
+#define CMD_KEY 2 /*CTRL B */
-typedef struct {
- int active;
- int disconnect;
- char csl[128];
- char buf[128];
- int ptr;
+typedef struct
+{
+ int active;
+ int disconnect;
+ char csl[128];
+ char buf[128];
+ int ptr;
} Cmd;
#endif /* __CMD_H__ */
diff --git a/src/context.h b/src/context.h
index 255be5a..8f88342 100644
--- a/src/context.h
+++ b/src/context.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.8 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.7 2008/02/22 23:39:27 james
* *** empty log message ***
*
@@ -42,6 +45,7 @@ typedef struct Context_struct
{
VT102 *v;
TTY *t;
+ TTY_Parser *tp;
History *h;
Log *l;
KeyDis *k;
diff --git a/src/crt.c b/src/crt.c
index 5f5656b..87b814d 100644
--- a/src/crt.c
+++ b/src/crt.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.11 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.10 2008/02/22 17:07:00 james
* *** empty log message ***
*
@@ -45,7 +48,7 @@ static char rcsid[] = "$Id$";
#include "project.h"
void
-crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea,int color)
+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)];
@@ -75,7 +78,7 @@ crt_cls (CRT * c)
}
void
-crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea,int color)
+crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color)
{
int l, n;
int p;
@@ -104,12 +107,12 @@ crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea,int color)
}
s.y = e.y;
- crt_erase (c, s, e, ea,color);
+ crt_erase (c, s, e, ea, color);
}
void
-crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea,int color)
+crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color)
{
int l, n;
int p;
@@ -137,7 +140,7 @@ crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea,int color)
}
e.y = s.y;
- crt_erase (c, s, e, ea,color);
+ crt_erase (c, s, e, ea, color);
}
diff --git a/src/ipc.h b/src/ipc.h
index 1820511..91589ed 100644
--- a/src/ipc.h
+++ b/src/ipc.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.5 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.4 2008/02/22 17:07:00 james
* *** empty log message ***
*
@@ -66,14 +69,14 @@ typedef struct
char msg[0];
} IPC_Msg_debug;
-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;
@@ -82,14 +85,14 @@ 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;
@@ -98,14 +101,14 @@ typedef struct
} IPC_Msg_term;
-typedef struct
+typedef struct
{
int32_t size;
int32_t type;
- char status[0];
+ char status[0];
} IPC_Msg_status;
-typedef struct
+typedef struct
{
int32_t size;
int32_t type;
@@ -113,14 +116,14 @@ typedef struct
} 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;
@@ -128,7 +131,7 @@ typedef struct
} IPC_Msg_setflow;
-typedef struct
+typedef struct
{
int32_t size;
int32_t type;
@@ -136,7 +139,7 @@ typedef struct
} IPC_Msg_setansi;
-typedef struct
+typedef struct
{
int32_t size;
int32_t type;
@@ -144,21 +147,21 @@ typedef struct
-typedef union
+typedef union
{
-IPC_Msg_hdr hdr;
-IPC_Msg_noop noop;
-IPC_Msg_debug debug;
-IPC_Msg_history history;
-IPC_Msg_VT102 vt102;
-IPC_Msg_key key;
-IPC_Msg_term term;
-IPC_Msg_status status;
-IPC_Msg_setbaud setbaud;
-IPC_Msg_sendbreak sendbreak;
-IPC_Msg_setflow setflow;
-IPC_Msg_setansi setansi;
-IPC_Msg_hangup hangup;
+ IPC_Msg_hdr hdr;
+ IPC_Msg_noop noop;
+ IPC_Msg_debug debug;
+ IPC_Msg_history history;
+ IPC_Msg_VT102 vt102;
+ IPC_Msg_key key;
+ IPC_Msg_term term;
+ IPC_Msg_status status;
+ IPC_Msg_setbaud setbaud;
+ IPC_Msg_sendbreak sendbreak;
+ IPC_Msg_setflow setflow;
+ IPC_Msg_setansi setansi;
+ IPC_Msg_hangup hangup;
} IPC_Msg;
diff --git a/src/keydis.c b/src/keydis.c
index 73f6306..9a7bd45 100644
--- a/src/keydis.c
+++ b/src/keydis.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.5 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.4 2008/02/22 17:07:00 james
* *** empty log message ***
*
@@ -95,7 +98,7 @@ keydis_ipc_set_ansi (KeyDis * _t, Context * c, int ansi)
{
KeyDis_IPC *t = (KeyDis_IPC *) _t;
- vt102_set_ansi (c->v, ansi);
+ vt102_set_ansi (c->v, ansi);
ipc_msg_send_setansi (t->s, ansi);
@@ -128,6 +131,9 @@ keydis_vt102_set_baud (KeyDis * _t, Context * c, int baud)
KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
tty_set_baud (c->t, baud);
+ tty_parse_reset (c);
+
+ log_f (c->l, "<baud changed to %d>", baud);
return 0;
}
@@ -158,7 +164,7 @@ keydis_vt102_set_ansi (KeyDis * _t, Context * c, int ansi)
KeyDis_VT102 *t = (KeyDis_VT102 *) _t;
if (c->v)
- c->v->xn_glitch=ansi ? 0:1;
+ c->v->xn_glitch = ansi ? 0 : 1;
return 0;
}
diff --git a/src/keydis.h b/src/keydis.h
index 89bf9e2..21a73f8 100644
--- a/src/keydis.h
+++ b/src/keydis.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.5 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.4 2008/02/22 17:07:00 james
* *** empty log message ***
*
@@ -44,7 +47,7 @@ struct Context_struct;
int (*set_ansi)(struct KeyDis_struct *,struct Context_struct *,int ansi); \
int (*hangup)(struct KeyDis_struct *,struct Context_struct *)
-
+
typedef struct KeyDis_struct
{
diff --git a/src/lockfile.h b/src/lockfile.h
index eb089ed..6941a1e 100644
--- a/src/lockfile.h
+++ b/src/lockfile.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.7 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.6 2008/02/15 23:52:12 james
* *** empty log message ***
*
@@ -40,13 +43,15 @@
#define FILE_LIST_MAX_LEN 1024
-typedef struct Filelist_ent {
- char name[FILE_LIST_MAX_LEN];
- struct Filelist_ent *next;
+typedef struct Filelist_ent
+{
+ char name[FILE_LIST_MAX_LEN];
+ struct Filelist_ent *next;
} Filelist_ent;
-typedef struct {
- Filelist_ent *head;
+typedef struct
+{
+ Filelist_ent *head;
} Filelist;
diff --git a/src/log.c b/src/log.c
index 65860f3..0f96964 100644
--- a/src/log.c
+++ b/src/log.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.3 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/02/22 14:51:54 james
* *** empty log message ***
*
@@ -74,28 +77,32 @@ file_log_new (char *fn)
{
File_Log *l;
FILE *f;
- int dc=1;
+ int dc = 1;
- if (fn && strcmp(fn,"-")) {
- f = fopen (fn, "a+");
- if (!f)
- return NULL;
- } else {
- f=stderr;
- dc=0;
- }
+ if (fn && strcmp (fn, "-"))
+ {
+ f = fopen (fn, "a+");
+ if (!f)
+ return NULL;
+ }
+ else
+ {
+ f = stderr;
+ dc = 0;
+ }
l = malloc (sizeof (File_Log));
l->log = flog_log;
l->close = flog_close;
l->fp = f;
- l->do_close=dc;
+ l->do_close = dc;
return (Log *) l;
}
-void
-log_f (Log *log,char *fmt, ...)
+
+void
+log_f (Log * log, char *fmt, ...)
{
int n;
@@ -103,12 +110,14 @@ log_f (Log *log,char *fmt, ...)
va_list ap;
static int size;
- if (!log) return;
+ if (!log)
+ return;
- if (!size) {
- size = 128;
- buf = malloc (size);
- }
+ if (!size)
+ {
+ size = 128;
+ buf = malloc (size);
+ }
if (!buf)
return;
@@ -116,13 +125,14 @@ log_f (Log *log,char *fmt, ...)
while (1)
{
va_start (ap, fmt);
- n = vsnprintf (buf , size, fmt, ap);
+ 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;
@@ -132,6 +142,6 @@ log_f (Log *log,char *fmt, ...)
buf = realloc (buf, size);
if (!buf)
- return;
+ return;
}
}
diff --git a/src/log.h b/src/log.h
index 0b248df..475fe16 100644
--- a/src/log.h
+++ b/src/log.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.2 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.1 2008/02/14 12:14:50 james
* *** empty log message ***
*
@@ -24,8 +27,9 @@
void (*log)(struct Log_struct *,char *); \
void (*close)(struct Log_struct *)
-typedef struct Log_struct {
- LOG_SIGNATURE;
+typedef struct Log_struct
+{
+ LOG_SIGNATURE;
} Log;
diff --git a/src/prototypes.h b/src/prototypes.h
index 39e03ae..ba847e4 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -1,159 +1,162 @@
/* ansi.c */
-extern int ansi_dispatch(ANSI *a, Context *c);
-extern ANSI *ansi_new_from_terminal(TTY *t);
+extern int ansi_dispatch (ANSI * a, Context * c);
+extern ANSI *ansi_new_from_terminal (TTY * t);
/* crt.c */
-extern void crt_erase(CRT *c, CRT_Pos s, CRT_Pos e, int ea, int color);
-extern void crt_cls(CRT *c);
-extern void crt_scroll_up(CRT *c, CRT_Pos s, CRT_Pos e, int ea, int color);
-extern void crt_scroll_down(CRT *c, CRT_Pos s, CRT_Pos e, int ea, int color);
-extern void crt_reset(CRT *c);
-extern void crt_insert(CRT *c, CRT_CA ca);
+extern void crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color);
+extern void crt_cls (CRT * c);
+extern void crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color);
+extern void crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea,
+ int color);
+extern void crt_reset (CRT * c);
+extern void crt_insert (CRT * c, CRT_CA ca);
/* html.c */
-extern ANSI *ansi_new_html(FILE *f);
+extern ANSI *ansi_new_html (FILE * f);
/* libsympathy.c */
/* render.c */
/* version.c */
/* vt102.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 void vt102_cursor_normalize(VT102 *v);
-extern void vt102_cursor_carriage_return(VT102 *v);
-extern void vt102_cursor_advance_line(Context *c);
-extern void vt102_do_pending_wrap(Context *c);
-extern void vt102_cursor_advance(Context *c);
-extern void vt102_cursor_retard(VT102 *v);
-extern void vt102_reset_tabs(VT102 *v);
-extern void vt102_cursor_advance_tab(VT102 *v);
-extern void vt102_cursor_retard_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_delete_from_line(VT102 *v, CRT_Pos p);
-extern void vt102_insert_into_line(VT102 *v, CRT_Pos p);
-extern void vt102_change_mode(VT102 *v, int private, char *ns, int set);
-extern void vt102_parse_mode_string(VT102 *v, char *buf, int len);
-extern void vt102_change_attr(VT102 *v, char *na);
-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, char ch);
-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_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 VT102 *vt102_new(void);
-extern void vt102_set_ansi(VT102 *v, int ansi);
-extern void vt102_free(VT102 *v);
+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 void vt102_cursor_normalize (VT102 * v);
+extern void vt102_cursor_carriage_return (VT102 * v);
+extern void vt102_cursor_advance_line (Context * c);
+extern void vt102_do_pending_wrap (Context * c);
+extern void vt102_cursor_advance (Context * c);
+extern void vt102_cursor_retard (VT102 * v);
+extern void vt102_reset_tabs (VT102 * v);
+extern void vt102_cursor_advance_tab (VT102 * v);
+extern void vt102_cursor_retard_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_delete_from_line (VT102 * v, CRT_Pos p);
+extern void vt102_insert_into_line (VT102 * v, CRT_Pos p);
+extern void vt102_change_mode (VT102 * v, int private, char *ns, int set);
+extern void vt102_parse_mode_string (VT102 * v, char *buf, int len);
+extern void vt102_change_attr (VT102 * v, char *na);
+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, char ch);
+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_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 VT102 *vt102_new (void);
+extern void vt102_set_ansi (VT102 * v, int ansi);
+extern void vt102_free (VT102 * v);
/* tty.c */
-extern void tty_pre_select(TTY *t, fd_set *rfds, fd_set *wfds);
-extern int tty_get_status(TTY *t, TTY_Status *s);
-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);
+extern void tty_pre_select (TTY * t, fd_set * rfds, fd_set * wfds);
+extern int tty_get_status (TTY * t, TTY_Status * s);
+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_parse_reset (Context * c);
+extern void analyse (Context * c);
+extern TTY_Parser *tty_parser_new (void);
+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);
-extern int keydis_key(KeyDis *t, Context *c, int key);
+extern KeyDis *keydis_vt102_new (void);
+extern KeyDis *keydis_ipc_new (Socket * s);
+extern int keydis_key (KeyDis * t, Context * c, int key);
/* history.c */
-extern History *history_new(int n);
-extern void history_free(History *h);
-extern void history_add(History *h, CRT_CA *c);
+extern History *history_new (int n);
+extern void history_free (History * h);
+extern void history_add (History * h, CRT_CA * c);
/* ring.c */
-extern int ring_read(Ring *r, void *b, int n);
-extern int ring_write(Ring *r, void *b, int n);
-extern int ring_space(Ring *r);
-extern int ring_bytes(Ring *r);
-extern Ring *ring_new(int n);
+extern int ring_read (Ring * r, void *b, int n);
+extern int ring_write (Ring * r, void *b, int n);
+extern int ring_space (Ring * r);
+extern int ring_bytes (Ring * r);
+extern Ring *ring_new (int n);
/* ptty.c */
-extern TTY *ptty_open(char *path, char *argv[]);
+extern TTY *ptty_open (char *path, char *argv[]);
/* terminal.c */
extern int terminal_winches;
-extern void terminal_atexit(void);
-extern void terminal_getsize(TTY *_t);
-extern void terminal_dispatch(void);
-extern void terminal_register_handlers(void);
-extern TTY *terminal_open(int rfd, int wfd);
+extern void terminal_atexit (void);
+extern void terminal_getsize (TTY * _t);
+extern void terminal_dispatch (void);
+extern void terminal_register_handlers (void);
+extern TTY *terminal_open (int rfd, int wfd);
/* util.c */
-extern int wrap_read(int fd, void *buf, int len);
-extern int wrap_write(int fd, void *buf, int len);
-extern void set_nonblocking(int fd);
-extern void set_blocking(int fd);
-extern void raw_termios(struct termios *termios);
-extern void default_termios(struct termios *termios);
+extern int wrap_read (int fd, void *buf, int len);
+extern int wrap_write (int fd, void *buf, int len);
+extern void set_nonblocking (int fd);
+extern void set_blocking (int fd);
+extern void raw_termios (struct termios *termios);
+extern void default_termios (struct termios *termios);
/* log.c */
-extern Log *file_log_new(char *fn);
-extern void log_f(Log *log, char *fmt, ...);
+extern Log *file_log_new (char *fn);
+extern void log_f (Log * log, char *fmt, ...);
/* ipc.c */
-extern IPC_Msg *ipc_check_for_message_in_slide(Slide *s);
-extern void ipc_consume_message_in_slide(Slide *s);
-extern int ipc_msg_send(Socket *s, IPC_Msg *m);
-extern int ipc_msg_send_debug(Socket *s, char *msg);
-extern int ipc_msg_send_history(Socket *s, History_ent *l);
-extern int ipc_msg_send_vt102(Socket *s, VT102 *v);
-extern int ipc_msg_send_key(Socket *s, int key);
-extern int ipc_msg_send_term(Socket *s, void *buf, int len);
-extern int ipc_msg_send_status(Socket *s, char *buf);
-extern int ipc_msg_send_setbaud(Socket *s, int baud);
-extern int ipc_msg_send_sendbreak(Socket *s);
-extern int ipc_msg_send_setflow(Socket *s, int flow);
-extern int ipc_msg_send_setansi(Socket *s, int ansi);
-extern int ipc_msg_send_hangup(Socket *s);
+extern IPC_Msg *ipc_check_for_message_in_slide (Slide * s);
+extern void ipc_consume_message_in_slide (Slide * s);
+extern int ipc_msg_send (Socket * s, IPC_Msg * m);
+extern int ipc_msg_send_debug (Socket * s, char *msg);
+extern int ipc_msg_send_history (Socket * s, History_ent * l);
+extern int ipc_msg_send_vt102 (Socket * s, VT102 * v);
+extern int ipc_msg_send_key (Socket * s, int key);
+extern int ipc_msg_send_term (Socket * s, void *buf, int len);
+extern int ipc_msg_send_status (Socket * s, char *buf);
+extern int ipc_msg_send_setbaud (Socket * s, int baud);
+extern int ipc_msg_send_sendbreak (Socket * s);
+extern int ipc_msg_send_setflow (Socket * s, int flow);
+extern int ipc_msg_send_setansi (Socket * s, int ansi);
+extern int ipc_msg_send_hangup (Socket * s);
/* slide.c */
-extern void slide_free(Slide *s);
-extern void slide_consume(Slide *s, int n);
-extern void slide_added(Slide *s, int n);
-extern Slide *slide_new(int n);
-extern void slide_expand(Slide *s, int n);
+extern void slide_free (Slide * s);
+extern void slide_consume (Slide * s, int n);
+extern void slide_added (Slide * s, int n);
+extern Slide *slide_new (int n);
+extern void slide_expand (Slide * s, int n);
/* symsocket.c */
-extern int wrap_recv(int fd, void *buf, int len);
-extern int wrap_send(int fd, void *buf, int len);
-extern void socket_free(Socket *s);
-extern void socket_free_parent(Socket *s);
-extern Socket *socket_listen(char *path);
-extern Socket *socket_accept(Socket *l);
-extern Socket *socket_connect(char *path);
-extern void socket_consume_msg(Socket *s);
-extern void socket_pre_select(Socket *s, fd_set *rfds, fd_set *wfds);
-extern int socket_post_select(Socket *s, fd_set *rfds, fd_set *wfds);
-extern int socket_write(Socket *s, void *buf, int len);
+extern int wrap_recv (int fd, void *buf, int len);
+extern int wrap_send (int fd, void *buf, int len);
+extern void socket_free (Socket * s);
+extern void socket_free_parent (Socket * s);
+extern Socket *socket_listen (char *path);
+extern Socket *socket_accept (Socket * l);
+extern Socket *socket_connect (char *path);
+extern void socket_consume_msg (Socket * s);
+extern void socket_pre_select (Socket * s, fd_set * rfds, fd_set * wfds);
+extern int socket_post_select (Socket * s, fd_set * rfds, fd_set * wfds);
+extern int socket_write (Socket * s, void *buf, int len);
/* serial.c */
-extern TTY *serial_open(char *path, int lock_mode);
+extern TTY *serial_open (char *path, int lock_mode);
/* cmd.c */
-extern void cmd_parse(Cmd *c, Context *ctx, char *buf);
-extern void cmd_show_status(Cmd *c, Context *ctx);
-extern int cmd_key(Cmd *c, Context *ctx, int key);
-extern int cmd_activate(Cmd *c, Context *ctx);
-extern void cmd_new_status(Cmd *c, Context *ctx, char *msg);
-extern Cmd *cmd_new(void);
+extern void cmd_parse (Cmd * c, Context * ctx, char *buf);
+extern void cmd_show_status (Cmd * c, Context * ctx);
+extern int cmd_key (Cmd * c, Context * ctx, int key);
+extern int cmd_activate (Cmd * c, Context * ctx);
+extern void cmd_new_status (Cmd * c, Context * ctx, char *msg);
+extern Cmd *cmd_new (void);
/* lockfile.c */
-extern Filelist *filelist_new(void);
-extern void filelist_remove(Filelist *fl, Filelist_ent *fle);
-extern void filelist_add(Filelist *fl, char *fn);
-extern void filelist_free(Filelist *fl);
-extern void filelist_print(Filelist *fl, FILE *f);
-extern int lockfile_make(char *name);
-extern void lockfile_add_places(Filelist *fl, char *leaf);
-extern void lockfile_regularize_and_add(Filelist *fl, char *leaf);
-extern void lockfile_add_name_from_path(Filelist *fl, char *file);
-extern void lockfile_add_name_from_dev(Filelist *fl, dev_t dev);
-extern void lockfile_check_dir_for_dev(Filelist *fl, char *dir, dev_t dev);
-extern Filelist *lockfile_make_list(char *device);
-extern void lockfile_remove_stale(Filelist *fl);
-extern Filelist *lockfile_lock(Filelist *fl);
-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);
+extern Filelist *filelist_new (void);
+extern void filelist_remove (Filelist * fl, Filelist_ent * fle);
+extern void filelist_add (Filelist * fl, char *fn);
+extern void filelist_free (Filelist * fl);
+extern void filelist_print (Filelist * fl, FILE * f);
+extern int lockfile_make (char *name);
+extern void lockfile_add_places (Filelist * fl, char *leaf);
+extern void lockfile_regularize_and_add (Filelist * fl, char *leaf);
+extern void lockfile_add_name_from_path (Filelist * fl, char *file);
+extern void lockfile_add_name_from_dev (Filelist * fl, dev_t dev);
+extern void lockfile_check_dir_for_dev (Filelist * fl, char *dir, dev_t dev);
+extern Filelist *lockfile_make_list (char *device);
+extern void lockfile_remove_stale (Filelist * fl);
+extern Filelist *lockfile_lock (Filelist * fl);
+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);
+extern void utf8_flush (Context * c);
+extern void utf8_parse (Context * c, int ch);
+extern UTF8 *utf8_new (void);
diff --git a/src/ptty.c b/src/ptty.c
index 860928e..b0b247a 100644
--- a/src/ptty.c
+++ b/src/ptty.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.8 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.7 2008/02/22 17:07:00 james
* *** empty log message ***
*
@@ -149,7 +152,6 @@ ptty_open (char *path, char *argv[])
return NULL;
case 0: /*waaah */
setenv ("TERM", "xterm", 1);
- setenv ("LANG", "C", 1);
if (!path)
path = "/bin/sh";
diff --git a/src/tty.c b/src/tty.c
index 1ac8c87..3b8f731 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.13 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.12 2008/02/22 23:39:27 james
* *** empty log message ***
*
@@ -344,29 +347,93 @@ typedef struct
} \
while (0)
-void
-tty_stats (TTY_Parser * p, int err, int ch)
+static void
+tty_bit_analyse (TTY_Parser * p, int err, int ch)
{
int c = 128;
int zc = 0, oc = 0;
if (err)
- p->biterrs++;
+ {
+ p->biterrs++;
+ gettimeofday (&p->lasterr, NULL);
+ }
bit (p, 0, zc, oc);
while (c)
{
- bit (p,ch & c,zc,oc);
+ bit (p, ch & c, zc, oc);
c >>= 1;
}
bit (p, 1, zc, oc);
}
void
+tty_parse_reset (Context * c)
+{
+ TTY_Parser *p = c->tp;
+ memset (p->bitfreq, 0, sizeof (p->bitfreq));
+ p->biterrs = 0;
+ p->guessed_baud = 0;
+}
+
+void
+analyse (Context * c)
+{
+ TTY_Parser *p = c->tp;
+ struct timeval now, dif;
+ int i;
+
+ 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;
+ }
+
+#define TTY_BITFREQ_LEN 10
+
+ for (i = 0; i < TTY_BITFREQ_LEN && (!p->bitfreq[i]); ++i);
+
+ if (!i)
+ {
+ /*Closest bit edge is one bit, so the baud rate is too low */
+ p->guessed_baud = -1;
+
+ }
+
+ p->guessed_baud = i;
+
+}
+
+TTY_Parser *
+tty_parser_new (void)
+{
+ TTY_Parser *p;
+
+ p = (TTY_Parser *) malloc (sizeof (TTY_Parser));
+
+ memset (p, 0, sizeof (TTY_Parser));
+
+ return p;
+}
+
+void
tty_parse (Context * c, uint8_t * buf, int len)
{
- TTY_Parser *p = &c->t->parser;
+ TTY_Parser *p;
+
+ p = c->tp;
while (len--)
{
@@ -384,21 +451,39 @@ tty_parse (Context * c, uint8_t * buf, int len)
p->in_errmark = 1;
break;
default:
- log_f (c->l, "%s:%d DLE parsing error: \\377 \\%03o", *buf);
+ 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, "%s:%d tty reports error: \\377 \\000 \\%03o", *buf);
- utf8_parse (c, *buf);
+ log_f (c->l, "%s:%d tty reports error: \\377 \\000 \\%03o",
+ __FILE__, __LINE__, *buf);
+
+
tty_bit_analyse (p, 1, *buf);
+
+ analyse (c);
+
+ utf8_parse (c, *buf);
+
utf8_parse (c, SYM_CHAR_RESET);
+
+ }
+ else if (*buf == DLE)
+ {
+ p->in_dle = 1;
+
}
else
{
tty_bit_analyse (p, 0, *buf);
+
+ analyse (c);
+
utf8_parse (c, *buf);
+
}
buf++;
}
diff --git a/src/tty.h b/src/tty.h
index 47b3cad..76f9fbb 100644
--- a/src/tty.h
+++ b/src/tty.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.11 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.10 2008/02/22 23:39:27 james
* *** empty log message ***
*
@@ -60,17 +63,21 @@
int rfd; \
int wfd; \
int hanging_up; \
- struct timeval hangup_clock; \
- TTY_Parser parser;
-
+ struct timeval hangup_clock;
+
+
+#define TTY_BITFREQ_LEN 10
typedef struct
{
int in_dle;
int in_errmark;
- int bitfreq[8];
+ int bitfreq[TTY_BITFREQ_LEN];
int biterrs;
+
+ struct timeval lasterr;
+ int guessed_baud;
} TTY_Parser;
diff --git a/src/utf8.c b/src/utf8.c
index 09066db..9d04d19 100644
--- a/src/utf8.c
+++ b/src/utf8.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.3 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/02/22 23:39:27 james
* *** empty log message ***
*
@@ -21,61 +24,118 @@ static char rcsid[] = "$Id$";
#include "project.h"
-void utf8_flush(Context *c)
+void
+utf8_flush (Context * c)
{
-UTF8 *u=c->u;
-int i;
+ UTF8 *u = c->u;
+ int i;
-for (i=0;i<u->utf_ptr;++i)
- vt102_parse(c,u->utf_buf[i]);
+ switch (u->utf_ptr)
+ {
+ case 1:
+ log_f (c->l, "%s:%d invalid utf-8 sequence: \\%03o",
+ __FILE__, __LINE__, u->utf_buf[0]);
+ break;
+ case 2:
+ log_f (c->l, "%s:%d invalid utf-8 sequence: \\%03o \\%03o",
+ __FILE__, __LINE__, u->utf_buf[0], u->utf_buf[1]);
+ break;
+ case 3:
+ log_f (c->l, "%s:%d invalid utf-8 sequence: \\%03o \\%03o \\%03o",
+ __FILE__, __LINE__, u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]);
+ break;
+ case 4:
+ log_f (c->l,
+ "%s:%d invalid utf-8 sequence: \\%03o \\%03o \\%03o \\%03o",
+ __FILE__, __LINE__,
+ u->utf_buf[0], u->utf_buf[1], u->utf_buf[2], u->utf_buf[3]);
+ break;
+ }
-u->utf_ptr=0;
-u->in_utf8=0;
+ for (i = 0; i < u->utf_ptr; ++i)
+ vt102_parse_char (c, u->utf_buf[i]);
+
+ u->utf_ptr = 0;
+ u->in_utf8 = 0;
}
-int utf8_parse(Context *c,int ch)
+void
+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 *u = c->u;
+
+ if (ch == SYM_CHAR_RESET)
+ {
+ u->in_utf8 = 0;
+ vt102_parse_char (c, ch);
+ return;
+ }
+
+ if (!u->in_utf8)
+ {
+ /*FIXME: for the moment we bodge utf8 support */
+ if (ch == 0xb9)
+ { /*CSI, not a valid utf8 start char */
+ 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
+ {
+ vt102_parse_char (c, ch);
+ }
+ }
+ else
+ {
+ if ((ch & 0xc0) != 0x80)
+ {
+ utf8_flush (c);
+ 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)
+ vt102_parse_char (c, ch);
+ }
+ }
}
-UTF8 *utf8_new(void)
+UTF8 *
+utf8_new (void)
{
-UTF8 *ret;
+ UTF8 *ret;
-ret=(UTF8 *) malloc(sizeof(UTF8));
+ ret = (UTF8 *) malloc (sizeof (UTF8));
-ret->in_utf8=0;
+ ret->in_utf8 = 0;
}
-
diff --git a/src/utf8.h b/src/utf8.h
index cbfcb7f..4fbf378 100644
--- a/src/utf8.h
+++ b/src/utf8.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.3 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/02/22 23:39:27 james
* *** empty log message ***
*
@@ -28,8 +31,12 @@
typedef struct
{
int in_utf8;
+
uint8_t utf_buf[4];
int utf_ptr;
+
+ int ch;
+ int sh;
} UTF8;
#endif /* __UTF8_H__ */
diff --git a/src/vt102.c b/src/vt102.c
index 7a1a098..9b316ce 100644
--- a/src/vt102.c
+++ b/src/vt102.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.34 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.33 2008/02/22 23:39:27 james
* *** empty log message ***
*
@@ -272,10 +275,13 @@ ESC+B
static inline int
-safe_ch(int c) {
-if (c<32) return ' ';
-if (c>126) return ' ';
-return c;
+safe_ch (int c)
+{
+ if (c < 32)
+ return ' ';
+ if (c > 126)
+ return ' ';
+ return c;
}
static inline int
@@ -429,7 +435,8 @@ vt102_cursor_advance_line (Context * c)
return;
}
- if (v->pos.y!=v->screen_end.y) v->pos.y++;
+ if (v->pos.y != v->screen_end.y)
+ v->pos.y++;
v->pending_wrap = 0;
}
@@ -483,7 +490,7 @@ vt102_cursor_advance (Context * c)
}
v->pending_wrap++;
if (!c->v->xn_glitch)
- vt102_do_pending_wrap(c);
+ vt102_do_pending_wrap (c);
}
@@ -920,7 +927,8 @@ vt102_parse_esc (Context * c, int ch)
{
vt102_log_line (c, v->pos.y);
vt102_history (c, v->top_margin, v->bottom_margin);
- crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
+ crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,
+ v->color);
}
else
{
@@ -933,7 +941,8 @@ vt102_parse_esc (Context * c, int ch)
case 'M':
if (v->pos.y == v->top_margin.y)
{
- crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
+ crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,
+ v->color);
}
else
{
@@ -952,8 +961,12 @@ vt102_parse_esc (Context * c, int ch)
case '>':
v->application_keypad_mode = 0;
break;
+ case ']':
+ v->parser.ignore_until_bell++;
+ break;
default:
- log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__,__LINE__,ch,safe_ch(ch));
+ log_f (c->l, "<%s:%d unhandled ESC: \\033 \\%03o (ESC %c)>", __FILE__,
+ __LINE__, ch, safe_ch (ch));
;
}
@@ -1039,18 +1052,19 @@ vt102_parse_csi (Context * c, char *buf, int len)
vt102_cursor_advance_tab (c->v);
break;
case 'J':
- if (len == 2)
- narg = 0; /*Different default */
+ if (len == 2)
+ narg = 0; /*Different default */
switch (narg)
{
case 0:
- crt_erase (&v->crt, v->pos, v->screen_end, 1,v->color);
+ 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);
+ 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);
+ crt_erase (&v->crt, v->screen_start, v->screen_end, 1,
+ v->color);
break;
}
break;
@@ -1064,13 +1078,13 @@ vt102_parse_csi (Context * c, char *buf, int len)
switch (narg)
{
case 0:
- crt_erase (&v->crt, v->pos, le, 1,v->color);
+ crt_erase (&v->crt, v->pos, le, 1, v->color);
break;
case 1:
- crt_erase (&v->crt, ls, v->pos, 1,v->color);
+ crt_erase (&v->crt, ls, v->pos, 1, v->color);
break;
case 2:
- crt_erase (&v->crt, ls, le, 1,v->color);
+ crt_erase (&v->crt, ls, le, 1, v->color);
break;
}
}
@@ -1081,7 +1095,8 @@ vt102_parse_csi (Context * c, char *buf, int len)
&& (v->pos.y <= v->bottom_margin.y))
{
while (narg--)
- crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1,v->color);
+ crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1,
+ v->color);
}
break;
@@ -1092,7 +1107,8 @@ vt102_parse_csi (Context * c, char *buf, int len)
while (narg--)
{
vt102_history (c, v->pos, v->bottom_margin);
- crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1,v->color);
+ crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1,
+ v->color);
}
}
break;
@@ -1107,23 +1123,26 @@ vt102_parse_csi (Context * c, char *buf, int len)
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);
+ crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,
+ v->color);
}
break;
case 'T':
while (narg--)
- crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,v->color);
+ crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,
+ v->color);
break;
case 'X':
{
CRT_Pos end = v->pos;
- if (!narg) narg++;
+ if (!narg)
+ narg++;
- end.x += narg-1;
+ 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);
+ crt_erase (&v->crt, v->pos, end, 1, v->color);
}
break;
case 'Z':
@@ -1206,13 +1225,15 @@ vt102_parse_csi (Context * c, char *buf, int len)
break;
default:
- log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__,__LINE__,buf);
+ log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__,
+ buf);
;
}
break;
default:
- log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__,__LINE__,buf);
+ log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, __LINE__,
+ buf);
;
}
@@ -1244,13 +1265,14 @@ vt102_parser_reset (VT102_parser * p)
{
p->in_csi = 0;
p->in_escape = 0;
+ p->ignore_until_bell = 0;
}
void
-vt102_reset_state(VT102 *v)
+vt102_reset_state (VT102 * v)
{
- vt102_parser_reset(&v->parser);
+ vt102_parser_reset (&v->parser);
v->attr = CRT_ATTR_NORMAL;
v->color = CRT_COLOR_NORMAL;
@@ -1278,14 +1300,29 @@ vt102_parse_char (Context * c, int ch)
VT102 *v = c->v;
VT102_parser *p = &v->parser;
-#if 1
- log_f (c->l, "char %3d %c pc %d %d %d %2d %2d %d",ch,safe_ch(ch),
- p->in_utf8,p->in_escape, p->in_csi, v->pos.x, v->pos.y,v->pending_wrap);
+#if 0
+ log_f (c->l, "char %3d %c pc %d %d %d %2d %2d %d", ch, safe_ch (ch),
+ p->ignore_until_bell, p->in_escape, p->in_csi, v->pos.x, v->pos.y,
+ v->pending_wrap);
#endif
- if (ch==SYM_CHAR_RESET) {
- vt102_reset_state(v);
- } else if (p->in_csi)
+/* Turn anything non-ascii into '?' */
+ if ((ch != SYM_CHAR_RESET) && (ch != 0xb9) && (ch > 127))
+ {
+ ch = '?';
+ }
+
+
+ if (ch == SYM_CHAR_RESET)
+ {
+ vt102_reset_state (v);
+ }
+ if (p->ignore_until_bell)
+ {
+ if (ch == 7)
+ p->ignore_until_bell = 0;
+ }
+ else if (p->in_csi)
{
p->csi_buf[p->csi_ptr++] = ch;
if (csi_ender (ch) || (p->csi_ptr == VT102_CSI_LEN))
@@ -1300,7 +1337,10 @@ vt102_parse_char (Context * c, int ch)
}
else
{
- log_f (c->l, "<%s:%d no dispatcher for sequence starting \\033 \\%03o (ESC %c)>", __FILE__,__LINE__,p->csi_buf[0],safe_ch(p->csi_buf[0]));
+ log_f (c->l,
+ "<%s:%d no dispatcher for sequence starting \\033 \\%03o (ESC %c)>",
+ __FILE__, __LINE__, p->csi_buf[0],
+ safe_ch (p->csi_buf[0]));
}
p->in_csi = 0;
}
@@ -1320,12 +1360,12 @@ vt102_parse_char (Context * c, int ch)
vt102_parse_esc (c, ch);
}
}
- else if (ch==0x9b) /*One byte CSI*/
+ else if (ch == 0x9b) /*One byte CSI */
{
- p->csi_ptr = 0;
- p->csi_buf[p->csi_ptr++] = '[';
- p->in_csi++;
- }
+ p->csi_ptr = 0;
+ p->csi_buf[p->csi_ptr++] = '[';
+ p->in_csi++;
+ }
else
{
@@ -1338,8 +1378,8 @@ vt102_parse_char (Context * c, int ch)
/*EOT*/ case 4:
break;
/*ENQ*/ case 5:
- if (c->t)
- c->t->xmit (c->t, "vt102", 5);
+ if (c->t)
+ c->t->xmit (c->t, "vt102", 5);
break;
/*ACK*/ case 6:
/*BEL*/ case 7:
@@ -1580,8 +1620,6 @@ vt102_reset (VT102 * v)
{
VT102_parser *p = &v->parser;
- vt102_parser_reset (p);
- vt102_reset_state(v);
crt_cls (&v->crt);
v->current_line = v->pos;
@@ -1598,10 +1636,14 @@ vt102_reset (VT102 * v)
vt102_reset_tabs (v);
v->current_line = v->pos;
+ vt102_parser_reset (p);
+ vt102_reset_state (v);
+
vt102_save_state (v);
v->last_reg_char = ' ';
}
+
VT102 *
vt102_new (void)
{
@@ -1609,7 +1651,7 @@ vt102_new (void)
v = (VT102 *) malloc (sizeof (VT102));
- v->xn_glitch=1;
+ v->xn_glitch = 1;
vt102_reset (v);
@@ -1617,9 +1659,10 @@ vt102_new (void)
return v;
}
-void vt102_set_ansi(VT102 *v,int ansi)
+void
+vt102_set_ansi (VT102 * v, int ansi)
{
-v->xn_glitch=ansi ? 0:1;
+ v->xn_glitch = ansi ? 0 : 1;
}
void
diff --git a/src/vt102.h b/src/vt102.h
index 9d7f9d6..6343e6d 100644
--- a/src/vt102.h
+++ b/src/vt102.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.14 2008/02/23 11:48:37 james
+ * *** empty log message ***
+ *
* Revision 1.13 2008/02/22 17:07:00 james
* *** empty log message ***
*
@@ -69,8 +72,8 @@ typedef struct
{
int in_escape;
int in_csi;
- int in_utf8;
int csi_ptr;
+ int ignore_until_bell;
char csi_buf[VT102_CSI_LEN];
} VT102_parser;