aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjames <>2008-02-13 09:12:21 +0000
committerjames <>2008-02-13 09:12:21 +0000
commit23dc931ca671e938da071d24d8e9b6052e49923a (patch)
treef60e7ebd00db56a2757479334f4c8742cd6fcc13
parent4d50b220e63c52d412bacebb3e44cc712f2e2804 (diff)
downloadsympathy-23dc931ca671e938da071d24d8e9b6052e49923a.tar.gz
sympathy-23dc931ca671e938da071d24d8e9b6052e49923a.tar.bz2
sympathy-23dc931ca671e938da071d24d8e9b6052e49923a.zip
*** empty log message ***
-rw-r--r--src/Makefile.am5
-rw-r--r--src/ansi.c112
-rw-r--r--src/context.h4
-rw-r--r--src/crt.h5
-rw-r--r--src/libsympathy.c50
-rw-r--r--src/project.h6
-rw-r--r--src/prototypes.h154
-rw-r--r--src/ptty.c31
-rw-r--r--src/ring.c5
-rw-r--r--src/terminal.c101
-rw-r--r--src/tty.h5
-rw-r--r--src/util.c10
-rw-r--r--src/vt102.c172
13 files changed, 351 insertions, 309 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 94f0f7b..968d9de 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,6 +8,9 @@
# $Id$
#
# $Log$
+# Revision 1.8 2008/02/13 09:12:20 james
+# *** empty log message ***
+#
# Revision 1.7 2008/02/12 22:36:46 james
# *** empty log message ***
#
@@ -39,7 +42,7 @@ HDRS=ansi.h context.h crt.h history.h keys.h project.h prototypes.h \
ring.h sympathy.h tty.h vt102.h
SRCS=ansi.c crt.c html.c libsympathy.c render.c version.c vt102.c tty.c \
- history.c ring.c ptty.c
+ history.c ring.c ptty.c terminal.c util.c
CPROTO=cproto
diff --git a/src/ansi.c b/src/ansi.c
index b6f30f9..12a0563 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.18 2008/02/13 09:12:21 james
+ * *** empty log message ***
+ *
* Revision 1.17 2008/02/13 01:08:18 james
* *** empty log message ***
*
@@ -64,24 +67,6 @@ static char rcsid[] = "$Id$";
*/
#include "project.h"
-static void
-set_nonblocking (int fd)
-{
- long arg;
- arg = fcntl (fd, F_GETFL, arg);
- arg |= O_NONBLOCK;
- fcntl (fd, F_SETFL, arg);
-}
-
-static void
-set_blocking (int fd)
-{
- long arg;
- arg = fcntl (fd, F_GETFL, arg);
- arg &= ~O_NONBLOCK;
- fcntl (fd, F_SETFL, arg);
-}
-
void
ansi_move (ANSI * a, CRT_Pos p)
@@ -431,7 +416,26 @@ ansi_draw (ANSI * a, CRT * c)
int o;
int hidden_cursor = 0;
- if (crt_pos_cmp(a->terminal.size,a->size)) {
+ if (crt_pos_cmp (a->terminal->size, a->size))
+ {
+ terminal_getsize (a->terminal);
+
+ a->size = a->terminal->size;
+
+ a->pos.x = ANSI_INVAL;
+ a->hide_cursor = ANSI_INVAL;
+
+ crt_reset (&a->crt);
+
+// FIXME: -- echos back crap?
+// a->terminal->xmit (a->terminal, "\033[c", 3);
+
+ ansi_cls (a);
+ a->terminal->xmit (a->terminal, "\033=", 2);
+ a->terminal->xmit (a->terminal, "\033[?6l", 5);
+ a->terminal->xmit (a->terminal, "\033[r", 3);
+
+ }
for (p.y = 0; p.y < CRT_ROWS; ++p.y)
@@ -487,34 +491,19 @@ ansi_draw (ANSI * a, CRT * c)
void
ansi_reset (ANSI * a)
{
-// FIXME: -- echos back crap?
-// a->terminal->xmit (a->terminal, "\033[c", 3);
-
- terminal_getsize(a->terminal);
-
- a->size=a->terminal->size;
-
- a->pos.x = ANSI_INVAL;
- a->hide_cursor = ANSI_INVAL;
-
- crt_reset (&a->crt);
-
- ansi_cls (a);
- a->terminal->xmit (a->terminal, "\033=", 2);
- a->terminal->xmit (a->terminal, "\033[?6l", 5);
- a->terminal->xmit (a->terminal, "\033[r", 3);
+ a->size.x = -1;
ansi_draw (a, &a->crt);
}
void
-ansi_flush_escape (ANSI * a, Context *c)
+ansi_flush_escape (ANSI * a, Context * c)
{
ANSI_Parser *p = &a->parser;
int i;
for (i = 0; i < p->escape_ptr; ++i)
{
- vt102_send (c->v, p->escape_buf[i], c->t);
+ vt102_send (c, p->escape_buf[i]);
}
p->escape_ptr = 0;
@@ -522,7 +511,7 @@ ansi_flush_escape (ANSI * a, Context *c)
}
void
-ansi_parse_deckey (ANSI * a, Context *c)
+ansi_parse_deckey (ANSI * a, Context * c)
{
ANSI_Parser *p = &a->parser;
if ((p->escape_buf[1] != '[') && (p->escape_buf[1] != 'O'))
@@ -533,15 +522,15 @@ ansi_parse_deckey (ANSI * a, Context *c)
if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z'))
{
- vt102_send (c->v, KEY_UP + (p->escape_buf[2] - 'A'), c->t);
+ vt102_send (c, KEY_UP + (p->escape_buf[2] - 'A'));
}
else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z'))
{
- vt102_send (c->v, KEY_154 + (p->escape_buf[2] - 'a'), c->t);
+ vt102_send (c, KEY_154 + (p->escape_buf[2] - 'a'));
}
else
{
- ansi_flush_escape (a,c);
+ ansi_flush_escape (a, c);
return;
}
p->in_escape = 0;
@@ -549,7 +538,7 @@ ansi_parse_deckey (ANSI * a, Context *c)
}
void
-ansi_parse_ansikey (ANSI * a,Context *c)
+ansi_parse_ansikey (ANSI * a, Context * c)
{
ANSI_Parser *p = &a->parser;
@@ -560,11 +549,11 @@ ansi_parse_ansikey (ANSI * a,Context *c)
}
if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9'))
{
- vt102_send (c->v, KEY_180 + (p->escape_buf[2] - '0'), c->t);
+ vt102_send (c, KEY_180 + (p->escape_buf[2] - '0'));
}
else
{
- ansi_flush_escape (a,c);
+ ansi_flush_escape (a, c);
return;
}
@@ -575,7 +564,7 @@ ansi_parse_ansikey (ANSI * a,Context *c)
void
-ansi_parse_escape (ANSI * a,Context *c)
+ansi_parse_escape (ANSI * a, Context * c)
{
ANSI_Parser *p = &a->parser;
switch (p->escape_ptr)
@@ -590,7 +579,7 @@ ansi_parse_escape (ANSI * a,Context *c)
case 'O':
break;
default:
- ansi_flush_escape (a,c);
+ ansi_flush_escape (a, c);
}
break;
case 3:
@@ -601,10 +590,10 @@ ansi_parse_escape (ANSI * a,Context *c)
break;
case '[':
if ((p->escape_buf[2] >= 'A') && (p->escape_buf[2] <= 'Z'))
- ansi_parse_deckey (a,c);
+ ansi_parse_deckey (a, c);
break;
default:
- ansi_flush_escape (a,c);
+ ansi_flush_escape (a, c);
}
break;
case 4:
@@ -614,17 +603,17 @@ ansi_parse_escape (ANSI * a,Context *c)
ansi_parse_ansikey (a, c);
break;
default:
- ansi_flush_escape (a,c);
+ ansi_flush_escape (a, c);
}
break;
case 5:
- ansi_flush_escape (a,c);
+ ansi_flush_escape (a, c);
}
}
void
-ansi_check_escape (ANSI * a, Context *c)
+ansi_check_escape (ANSI * a, Context * c)
{
ANSI_Parser *p = &a->parser;
struct timeval now, diff;
@@ -642,13 +631,13 @@ ansi_check_escape (ANSI * a, Context *c)
/*Time up? */
if (diff.tv_sec || (diff.tv_usec > ANSI_ESCAPE_TIMEOUT))
- ansi_flush_escape (a,c);
+ ansi_flush_escape (a, c);
}
void
-ansi_parse_char (ANSI * a,Context *c, int ch)
+ansi_parse_char (ANSI * a, Context * c, int ch)
{
ANSI_Parser *p = &a->parser;
@@ -659,7 +648,7 @@ ansi_parse_char (ANSI * a,Context *c, int ch)
if (ch == 033)
{
if (p->in_escape)
- ansi_flush_escape (a,c);
+ ansi_flush_escape (a, c);
p->in_escape++;
p->escape_ptr = 0;
@@ -669,32 +658,31 @@ ansi_parse_char (ANSI * a,Context *c, int ch)
if (p->in_escape)
{
p->escape_buf[p->escape_ptr++] = ch;
- ansi_parse_escape (a,c);
+ ansi_parse_escape (a, c);
}
else
{
- vt102_send (c->v, ch, c->t);
+ vt102_send (c, ch);
}
}
void
-ansi_parse (ANSI * a,Context *c, char *buf, int len)
+ansi_parse (ANSI * a, Context * c, char *buf, int len)
{
while (len--)
- ansi_parse_char (a,c, *(buf++));
+ ansi_parse_char (a, c, *(buf++));
}
int
-ansi_dispatch (ANSI * a, Context *c)
+ansi_dispatch (ANSI * a, Context * c)
{
char buf[1024];
int red;
ansi_check_escape (a, c);
-
- red = a->terminal->recv(a->terminal,buf,sizeof(buf));
+ red = a->terminal->recv (a->terminal, buf, sizeof (buf));
if (red <= 0)
return red;
@@ -709,7 +697,7 @@ ansi_dispatch (ANSI * a, Context *c)
#endif
- ansi_parse (a,c, buf, red );
+ ansi_parse (a, c, buf, red);
return 0;
}
diff --git a/src/context.h b/src/context.h
index 607f249..c2b7798 100644
--- a/src/context.h
+++ b/src/context.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.3 2008/02/13 09:12:21 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/02/12 22:36:46 james
* *** empty log message ***
*
@@ -28,6 +31,7 @@ typedef struct
VT102 *v;
TTY *t;
History *h;
+ Log *l;
} Context;
#endif /* __CONTEXT_H__ */
diff --git a/src/crt.h b/src/crt.h
index addaed8..410b390 100644
--- a/src/crt.h
+++ b/src/crt.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.8 2008/02/13 09:12:21 james
+ * *** empty log message ***
+ *
* Revision 1.7 2008/02/13 01:08:18 james
* *** empty log message ***
*
@@ -115,7 +118,7 @@ crt_ca_cmp (CRT_CA a, CRT_CA b)
}
static inline
-crt_pos_cmp (CRT_POS a, CRT_POS b)
+crt_pos_cmp (CRT_Pos a, CRT_Pos b)
{
return memcmp (&a, &b, sizeof (a));
}
diff --git a/src/libsympathy.c b/src/libsympathy.c
index 7e6d78b..989b664 100644
--- a/src/libsympathy.c
+++ b/src/libsympathy.c
@@ -11,6 +11,9 @@ static char rcsid[] =
/*
* $Log$
+ * Revision 1.16 2008/02/13 09:12:21 james
+ * *** empty log message ***
+ *
* Revision 1.15 2008/02/13 01:08:18 james
* *** empty log message ***
*
@@ -66,12 +69,12 @@ static char rcsid[] =
void
testy (void)
{
+ fd_set rfd;
struct termios raw = { 0 };
ANSI a = { 0 };
Context c;
#if 0
- fd_set rfd;
int fd;
char c;
@@ -81,15 +84,18 @@ testy (void)
int i;
#endif
-
+
ansi_reset (&a);
- c.t = tty_new_test ();
+ c.t = ptty_open (NULL, NULL);
c.v = vt102_new ();
+ c.h = history_new (200);
+ c.l = NULL;
- a.terminal=terminal_open(0,1);
+ terminal_register_handlers ();
+ a.terminal = terminal_open (0, 1);
FD_ZERO (&rfd);
@@ -97,33 +103,21 @@ testy (void)
{
struct timeval tv = { 0, 100000 };
- FD_SET (t->fd, &rfd);
- FD_SET (a.fd, &rfd);
- select (t->fd + 1, &rfd, NULL, NULL, &tv);
-#if 0
- if (FD_ISSET (a.fd, &rfd))
- {
- }
-#endif
+ FD_SET (c.t->rfd, &rfd);
+ FD_SET (a.terminal->rfd, &rfd);
- switch (ansi_dispatch (&a, v, t))
- {
- case -1:
- break;
- case 1:
- ansi_getsize (&a);
- ansi_reset (&a);
- ansi_draw (&a, &v->crt);
- break;
- }
+ select (FD_SETSIZE, &rfd, NULL, NULL, &tv);
- if (FD_ISSET (t->fd, &rfd))
+ ansi_dispatch (&a, &c);
+
+ if (FD_ISSET (c.t->rfd, &rfd))
{
- if (vt102_dispatch_one (v, t, h))
+ if (vt102_dispatch (&c))
break;
}
+#if 0
if (had_winch)
{
had_winch = 0;
@@ -131,8 +125,10 @@ testy (void)
ansi_reset (&a);
ansi_draw (&a, &v->crt);
}
- ansi_draw (&a, &v->crt);
+#endif
+ //FIXME history
+ ansi_draw (&a, &c.v->crt);
}
- tcsetattr (0, TCSANOW, &old);
- printf ("QUAT\n");
+
+ terminal_atexit ();
}
diff --git a/src/project.h b/src/project.h
index 9de6b17..ed33123 100644
--- a/src/project.h
+++ b/src/project.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.7 2008/02/13 09:12:21 james
+ * *** empty log message ***
+ *
* Revision 1.6 2008/02/09 15:47:28 james
* *** empty log message ***
*
@@ -84,13 +87,14 @@
#include <utmp.h>
#include <pty.h>
-#include "tty.h"
#include "crt.h"
+#include "tty.h"
#include "ansi.h"
#include "vt102.h"
#include "keys.h"
#include "history.h"
#include "ring.h"
+#include "log.h"
#include "context.h"
diff --git a/src/prototypes.h b/src/prototypes.h
index 17027e1..f1f0742 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -1,83 +1,93 @@
/* ansi.c */
-void ansi_move(ANSI *a, CRT_Pos p);
-void ansi_showhide_cursor(ANSI *a, int hide);
-void ansi_force_attr_normal(ANSI *a);
-void ansi_set_color(ANSI *a, int color);
-void ansi_set_attr(ANSI *a, int attr);
-void ansi_render(ANSI *a, CRT_CA ca);
-void ansi_cls(ANSI *a);
-int ansi_scroll_up(ANSI *a, CRT_Pos s, CRT_Pos e);
-void ansi_spot_scroll_up(ANSI *a, CRT *c);
-void ansi_spot_scroll(ANSI *a, CRT *c);
-void ansi_draw(ANSI *a, CRT *c);
-void ansi_reset(ANSI *a);
-void ansi_flush_escape(ANSI *a, Context *c);
-void ansi_parse_deckey(ANSI *a, Context *c);
-void ansi_parse_ansikey(ANSI *a, Context *c);
-void ansi_parse_escape(ANSI *a, Context *c);
-void ansi_check_escape(ANSI *a, Context *c);
-void ansi_parse_char(ANSI *a, Context *c, int ch);
-void ansi_parse(ANSI *a, Context *c, char *buf, int len);
-int ansi_dispatch(ANSI *a, Context *c);
+void ansi_move (ANSI * a, CRT_Pos p);
+void ansi_showhide_cursor (ANSI * a, int hide);
+void ansi_force_attr_normal (ANSI * a);
+void ansi_set_color (ANSI * a, int color);
+void ansi_set_attr (ANSI * a, int attr);
+void ansi_render (ANSI * a, CRT_CA ca);
+void ansi_cls (ANSI * a);
+void ansi_draw (ANSI * a, CRT * c);
+void ansi_reset (ANSI * a);
+void ansi_flush_escape (ANSI * a, Context * c);
+void ansi_parse_deckey (ANSI * a, Context * c);
+void ansi_parse_ansikey (ANSI * a, Context * c);
+void ansi_parse_escape (ANSI * a, Context * c);
+void ansi_check_escape (ANSI * a, Context * c);
+void ansi_parse_char (ANSI * a, Context * c, int ch);
+void ansi_parse (ANSI * a, Context * c, char *buf, int len);
+int ansi_dispatch (ANSI * a, Context * c);
/* crt.c */
-void crt_erase(CRT *c, CRT_Pos s, CRT_Pos e, int ea);
-void crt_cls(CRT *c);
-void crt_scroll_up(CRT *c, CRT_Pos s, CRT_Pos e, int ea);
-void crt_scroll_down(CRT *c, CRT_Pos s, CRT_Pos e, int ea);
-void crt_reset(CRT *c);
-void crt_insert(CRT *c, CRT_CA ca);
+void crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea);
+void crt_cls (CRT * c);
+void crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea);
+void crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea);
+void crt_reset (CRT * c);
+void crt_insert (CRT * c, CRT_CA ca);
/* html.c */
-void html_entity(FILE *f, int c);
-void html_render(FILE *f, CRT_CA c);
-void html_draw(FILE *f, CRT *c);
+void html_entity (FILE * f, int c);
+void html_render (FILE * f, CRT_CA c);
+void html_draw (FILE * f, CRT * c);
/* libsympathy.c */
-struct termios old;
-void testy(void);
+void testy (void);
/* render.c */
/* version.c */
/* vt102.c */
-void vt102_log_line(VT102 *v, int line);
-void vt102_clip_cursor(VT102 *v, CRT_Pos tl, CRT_Pos br);
-void vt102_cursor_normalize(VT102 *v);
-void vt102_cursor_carriage_return(VT102 *v);
-void vt102_cursor_advance_line(VT102 *v);
-void vt102_cursor_advance(VT102 *v);
-void vt102_do_pending_wrap(VT102 *v);
-void vt102_cursor_retard(VT102 *v);
-void vt102_reset_tabs(VT102 *v);
-void vt102_cursor_advance_tab(VT102 *v);
-int vt102_cursor_home(VT102 *v);
-int vt102_cursor_absolute(VT102 *v, int x, int y);
-int vt102_cursor_relative(VT102 *v, int x, int y);
-void vt102_delete_from_line(VT102 *v, CRT_Pos p);
-void vt102_insert_into_line(VT102 *v, CRT_Pos p);
-void vt102_change_mode(VT102 *v, int private, char *ns, int set);
-void vt102_parse_mode_string(VT102 *v, char *buf, int len);
-void vt102_change_attr(VT102 *v, char *na);
-void vt102_parse_attr_string(VT102 *v, char *buf, int len);
-void vt102_save_state(VT102 *v);
-void vt102_restore_state(VT102 *v);
-void vt102_scs(VT102 *c, int g, int s);
-void vt102_parse_esc(VT102 *v, int c);
-void vt102_parse_csi(VT102 *v, char *buf, int len);
-void vt102_status_line(VT102 *v, char *str);
-void vt102_parse_char(VT102 *v, int c, TTY *tty);
-int vt102_parse(VT102 *v, char *buf, int len, TTY *t);
-void vt102_parser_reset(VT102_parser *p);
-void vt102_send(VT102 *v, uint8_t key, TTY *tty);
-void vt102_reset(VT102 *v);
-int vt102_dispatch(VT102 *v, TTY *tty);
-int vt102_dispatch_one(VT102 *v, TTY *tty);
-VT102 *vt102_new(void);
-void vt102_free(VT102 *v);
+void vt102_log_line (Context * c, int line);
+void vt102_clip_cursor (VT102 * v, CRT_Pos tl, CRT_Pos br);
+void vt102_cursor_normalize (VT102 * v);
+void vt102_cursor_carriage_return (VT102 * v);
+void vt102_cursor_advance_line (Context * c);
+void vt102_cursor_advance (Context * c);
+void vt102_do_pending_wrap (Context * c);
+void vt102_cursor_retard (VT102 * v);
+void vt102_reset_tabs (VT102 * v);
+void vt102_cursor_advance_tab (VT102 * v);
+int vt102_cursor_home (VT102 * v);
+int vt102_cursor_absolute (VT102 * v, int x, int y);
+int vt102_cursor_relative (VT102 * v, int x, int y);
+void vt102_delete_from_line (VT102 * v, CRT_Pos p);
+void vt102_insert_into_line (VT102 * v, CRT_Pos p);
+void vt102_change_mode (VT102 * v, int private, char *ns, int set);
+void vt102_parse_mode_string (VT102 * v, char *buf, int len);
+void vt102_change_attr (VT102 * v, char *na);
+void vt102_parse_attr_string (VT102 * v, char *buf, int len);
+void vt102_save_state (VT102 * v);
+void vt102_restore_state (VT102 * v);
+void vt102_scs (Context * c, int g, int s);
+void vt102_parse_esc (Context * c, int ch);
+void vt102_parse_csi (Context * c, char *buf, int len);
+void vt102_status_line (VT102 * v, char *str);
+void vt102_parse_char (Context * c, int ch);
+int vt102_parse (Context * c, char *buf, int len);
+void vt102_parser_reset (VT102_parser * p);
+void vt102_send (Context * c, uint8_t key);
+void vt102_reset (VT102 * v);
+int vt102_dispatch (Context * c);
+int vt102_dispatch_one (Context * c);
+VT102 *vt102_new (void);
+void vt102_free (VT102 * v);
/* tty.c */
/* history.c */
-History *history_new(int n);
-void history_free(History *h);
-void history_add(History *h, CRT_CA *c);
+History *history_new (int n);
+void history_free (History * h);
+void history_add (History * h, CRT_CA * c);
/* ring.c */
-int ring_read(Ring *r, void *b, int n);
-int ring_write(Ring *r, void *b, int n);
-Ring *ring_new(int n);
+int ring_read (Ring * r, void *b, int n);
+int ring_write (Ring * r, void *b, int n);
+Ring *ring_new (int n);
/* ptty.c */
-TTY *ptty_open(char *path, char *argv[]);
+TTY *ptty_open (char *path, char *argv[]);
+/* terminal.c */
+int terminal_winches;
+void terminal_atexit (void);
+void terminal_getsize (TTY * _t);
+void terminal_dispatch (void);
+void terminal_register_handlers (void);
+TTY *terminal_open (int rfd, int wfd);
+/* util.c */
+int wrap_read (int fd, void *buf, int len);
+int wrap_write (int fd, void *buf, int len);
+void set_nonblocking (int fd);
+void set_blocking (int fd);
+void raw_termios (struct termios *termios);
+void default_termios (struct termios *termios);
diff --git a/src/ptty.c b/src/ptty.c
index b59f823..c0f85f5 100644
--- a/src/ptty.c
+++ b/src/ptty.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.3 2008/02/13 09:12:21 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/02/12 22:36:46 james
* *** empty log message ***
*
@@ -118,14 +121,20 @@ ptty_open (char *path, char *argv[])
struct winsize winsize = { 0 };
struct termios termios;
int fd;
- char *default_argv = { "-", (char *) 0 };
+ char *default_argv[] = { "-", (char *) 0 };
+
+
+ default_termios (&termios);
+
+ winsize.ws_row = VT102_ROWS;
+ winsize.ws_col = VT102_COLS;
child = forkpty (&fd, name, &termios, &winsize);
switch (child)
{
case -1: /*boo hiss */
- return -1;
+ return NULL;
case 0: /*waaah */
setenv ("TERM", "vt102", 1);
setenv ("LANG", "C", 1);
@@ -146,19 +155,15 @@ ptty_open (char *path, char *argv[])
strncpy (t->name, name, sizeof (t->name));
t->name[sizeof (t->name) - 1] = 0;
- t->read = ptty_read;
- t->write = ptty_write;
+ t->recv = ptty_read;
+ t->xmit = ptty_write;
t->close = ptty_close;
-
- default_termios (&termios);
-
- winsize.ws_row = VT102_ROWS;
- winsize.ws_col = VT102_COLS;
-
- t->fd = open_fd_to_pty (path, argv);
- t->pid = child;
+ t->fd = fd;
+ t->child = child;
t->rfd = t->fd;
- t->wfd = 0;
+ t->wfd = t->fd;
+ t->size.x = winsize.ws_row;
+ t->size.y = winsize.ws_col;
return (TTY *) t;
}
diff --git a/src/ring.c b/src/ring.c
index f9ef6af..ccd97ed 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.3 2008/02/13 09:12:21 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/02/12 22:36:46 james
* *** empty log message ***
*
@@ -62,7 +65,7 @@ Ring *
ring_new (int n)
{
Ring *ret = (Ring *) malloc (sizeof (Ring));
- ret->buf = (uint8_t *) malloc (n);
+ ret->ring = (uint8_t *) malloc (n);
ret->size = n;
ret->wptr = ret->rptr = 0;
diff --git a/src/terminal.c b/src/terminal.c
index f0472a1..1223c0f 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.3 2008/02/13 09:12:21 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/02/13 01:08:18 james
* *** empty log message ***
*
@@ -47,7 +50,7 @@ typedef struct TERMINAL_struct
} TERMINAL;
-static TERMINAL terminal_list=NULL;
+static TERMINAL *terminal_list = NULL;
int terminal_winches;
@@ -56,36 +59,39 @@ static void
terminal_close (TTY * _t)
{
TERMINAL *t = (TERMINAL *) _t;
- TERMINAL **ptr=&terminal_list;
+ TERMINAL **ptr = &terminal_list;
if (!t)
return;
/* Take out of cleanup list */
- while (*ptr && (*ptr != t)) ptr=&((*ptr)->next);
+ while (*ptr && (*ptr != t))
+ ptr = &((*ptr)->next);
- if (*ptr)
- *ptr=t->next;
+ if (*ptr)
+ *ptr = t->next;
- tcsetattr(t->wfd,TCSANOW,&t->orig_termios);
+ tcsetattr (t->wfd, TCSANOW, &t->orig_termios);
- set_blocking(t->rfd);
- set_blocking(t->wfd);
+ set_blocking (t->rfd);
+ set_blocking (t->wfd);
free (t);
}
-void terminal_atexit(void)
+void
+terminal_atexit (void)
{
-while (terminal_list)
- terminal_close(terminal_list);
+ while (terminal_list)
+ terminal_close ((TTY *) terminal_list);
}
-static void sigint(int dummy)
+static void
+sigint (int dummy)
{
-terminal_atexit();
-exit(-1);
+ terminal_atexit ();
+ exit (-1);
}
static void
@@ -96,14 +102,15 @@ sigwinch (int not)
void
-terminal_getsize (TTY *_t)
+terminal_getsize (TTY * _t)
{
-TERMINAL *t=(TTY *) _t;
+ TERMINAL *t = (TERMINAL *) _t;
struct winsize sz = { 0 };
-if (!t) return;
+ if (!t)
+ return;
-if (ioctl (a->wfd, TIOCGWINSZ, &sz))
+ if (ioctl (t->wfd, TIOCGWINSZ, &sz))
{
t->size.x = CRT_COLS;
t->size.y = CRT_ROWS;
@@ -116,17 +123,19 @@ if (ioctl (a->wfd, TIOCGWINSZ, &sz))
}
-void terminal_dispatch(void)
+void
+terminal_dispatch (void)
{
-TERMINAL *t;
+ TERMINAL *t;
-if (!terminal_winches) return;
+ if (!terminal_winches)
+ return;
-terminal_winches=0;
+ terminal_winches = 0;
-for (t=terminal_list;t;t=t->next)
-terminal_getsize(t);
+ for (t = terminal_list; t; t = t->next)
+ terminal_getsize (t);
}
@@ -137,12 +146,12 @@ terminal_read (TTY * _t, void *buf, int len)
TERMINAL *t = (TERMINAL *) _t;
int red, done = 0;
- terminal_dispatch();
+ terminal_dispatch ();
do
{
- red = wrap_read (t->fd, buf, len);
+ red = wrap_read (t->rfd, buf, len);
if (red < 0)
return -1;
if (!red)
@@ -165,12 +174,12 @@ terminal_write (TTY * _t, void *buf, int len)
int writ, done = 0;
TERMINAL *t = (TERMINAL *) _t;
- terminal_dispatch();
+ terminal_dispatch ();
do
{
- writ = wrap_write (t->fd, buf, len);
+ writ = wrap_write (t->wfd, buf, len);
if (writ < 0)
return -1;
if (!writ)
@@ -187,21 +196,22 @@ terminal_write (TTY * _t, void *buf, int len)
}
-void terminal_register_handlers(void)
+void
+terminal_register_handlers (void)
{
- struct sigaction sa = { 0 };
+ struct sigaction sa = { 0 };
- sa.sa_handler = sigwinch;
- sa.sa_flags = SA_RESTART;
- sigaction (SIGWINCH, &sa, NULL);
+ sa.sa_handler = sigwinch;
+ sa.sa_flags = SA_RESTART;
+ sigaction (SIGWINCH, &sa, NULL);
- sa.sa_handler = sigint;
- sa.sa_flags = SA_RESTART;
- sigaction (SIGINT, &sa, NULL);
+ sa.sa_handler = sigint;
+ sa.sa_flags = SA_RESTART;
+ sigaction (SIGINT, &sa, NULL);
}
TTY *
-terminal_open (int rfd,int wfd)
+terminal_open (int rfd, int wfd)
{
TERMINAL *t;
pid_t child;
@@ -213,12 +223,12 @@ terminal_open (int rfd,int wfd)
t->rfd = rfd;
t->wfd = wfd;
- tcgetattr(wfd,&t->orig_termios);
+ tcgetattr (wfd, &t->orig_termios);
- t->next=terminal_list;
- terminal_list=t;
+ t->next = terminal_list;
+ terminal_list = t;
- tcgetattr(tfd,&termios);
+ tcgetattr (wfd, &termios);
set_nonblocking (rfd);
set_nonblocking (wfd);
@@ -226,15 +236,14 @@ terminal_open (int rfd,int wfd)
raw_termios (&termios);
- tcsetattr(wfd,TCSANOW,&termios);
+ tcsetattr (wfd, TCSANOW, &termios);
- t->read = terminal_read;
- t->write = terminal_write;
+ t->recv = terminal_read;
+ t->xmit = terminal_write;
t->close = terminal_close;
- terminal_getsize((TTY*) t);
+ terminal_getsize ((TTY *) t);
return (TTY *) t;
}
-
diff --git a/src/tty.h b/src/tty.h
index 76e2803..91b14c6 100644
--- a/src/tty.h
+++ b/src/tty.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.5 2008/02/13 09:12:21 james
+ * *** empty log message ***
+ *
* Revision 1.4 2008/02/13 01:08:18 james
* *** empty log message ***
*
@@ -31,7 +34,7 @@
#define TTY_SIGNATURE \
char name[1024]; \
- CRT_POS size; \
+ CRT_Pos size; \
void (*close)(struct TTY_struct *); \
int (*recv)(struct TTY_struct *,void *buf,int len); \
int (*xmit)(struct TTY_struct *,void *buf,int len); \
diff --git a/src/util.c b/src/util.c
index e8b315e..bd838b9 100644
--- a/src/util.c
+++ b/src/util.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.2 2008/02/13 09:12:21 james
+ * *** empty log message ***
+ *
* Revision 1.1 2008/02/13 01:08:38 james
* *** empty log message ***
*
@@ -66,7 +69,8 @@ set_blocking (int fd)
fcntl (fd, F_SETFL, arg);
}
-void raw_termios(struct termios *termios)
+void
+raw_termios (struct termios *termios)
{
termios->c_iflag = ICRNL | IXON;
@@ -97,12 +101,10 @@ default_termios (struct termios *termios)
memset (termios, 0, sizeof (termios));
- raw_termios(termios);
+ raw_termios (termios);
termios->c_cflag = CS8 | CREAD | CLOCAL;
cfsetispeed (termios, B9600);
cfsetospeed (termios, B9600);
}
-
-
diff --git a/src/vt102.c b/src/vt102.c
index f3101bb..a8d4388 100644
--- a/src/vt102.c
+++ b/src/vt102.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.24 2008/02/13 09:12:21 james
+ * *** empty log message ***
+ *
* Revision 1.23 2008/02/07 13:26:35 james
* *** empty log message ***
*
@@ -231,35 +234,34 @@ in_margins (VT102 * v, CRT_Pos p)
}
void
-vt102_log_line (VT102 * v, int line)
+vt102_log_line (Context * c, int line)
{
- static FILE *log;
CRT_Pos e = { VT102_COLS - 1, line };
CRT_Pos p = { 0, line };
+ char logbuf[VT102_COLS + 1];
- if (!log)
- log = fopen ("log", "a+");
-
- if (!log)
+ if (!c->l)
return;
for (; e.x > 0; --e.x)
{
- if (v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
+ if (c->v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
break;
}
for (; p.x <= e.x; ++p.x)
{
- int c = v->crt.screen[CRT_ADDR_POS (&p)].chr;
- if (c < 32)
- c = ' ';
- if (c > 126)
- c = ' ';
- fputc (c, log);
+ int ch = c->v->crt.screen[CRT_ADDR_POS (&p)].chr;
+ if (ch < 32)
+ ch = ' ';
+ if (ch > 126)
+ ch = ' ';
+ logbuf[p.x] = ch;
}
- fputc ('\n', log);
+ logbuf[p.x] = 0;
+
+ c->l->log (c->l, logbuf);
}
void
@@ -301,8 +303,9 @@ vt102_cursor_carriage_return (VT102 * v)
}
void
-vt102_cursor_advance_line (VT102 * v)
+vt102_cursor_advance_line (Context * c)
{
+ VT102 *v = c->v;
int couldscroll = in_margins (v, v->pos);
/*have wraped off end of last line in scrolling region */
@@ -310,7 +313,8 @@ vt102_cursor_advance_line (VT102 * v)
if (((v->pos.y == v->bottom_margin.y) || (v->pos.y == v->screen_end.y)) &&
(couldscroll))
{
- vt102_log_line (v, v->pos.y);
+ vt102_log_line (c, v->pos.y);
+ //FIXME call out to history
crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
return;
}
@@ -321,8 +325,9 @@ vt102_cursor_advance_line (VT102 * v)
void
-vt102_cursor_advance (VT102 * v)
+vt102_cursor_advance (Context * c)
{
+ VT102 *v = c->v;
if (v->pos.x < v->bottom_margin.x)
{
@@ -336,8 +341,9 @@ vt102_cursor_advance (VT102 * v)
void
-vt102_do_pending_wrap (VT102 * v)
+vt102_do_pending_wrap (Context * c)
{
+ VT102 *v = c->v;
int couldscroll = in_margins (v, v->pos);
int autowrap = v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP];
@@ -366,7 +372,7 @@ vt102_do_pending_wrap (VT102 * v)
v->pos.x = 0;
}
- vt102_cursor_advance_line (v);
+ vt102_cursor_advance_line (c);
}
@@ -755,20 +761,21 @@ vt102_restore_state (VT102 * v)
}
void
-vt102_scs (VT102 * c, int g, int s)
+vt102_scs (Context * c, int g, int s)
{
/*Ignoring charsets*/
}
void
-vt102_parse_esc (VT102 * v, int c)
+vt102_parse_esc (Context * c, int ch)
{
- switch (c)
+ VT102 *v = c->v;
+ switch (ch)
{
case 'E':
if (v->pos.y == v->bottom_margin.y)
{
- vt102_log_line (v, v->pos.y);
+ vt102_log_line (c, v->pos.y);
crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
}
else
@@ -803,20 +810,22 @@ vt102_parse_esc (VT102 * v, int c)
break;
default:
#if 0
- fprintf (stderr, "unhandled ESC \\033 \\%03o (ESC %c)\n", c,
- (c < 32) ? '?' : c);
+ fprintf (stderr, "unhandled ESC \\033 \\%03o (ESC %c)\n", ch,
+ (ch < 32) ? '?' : ch);
#endif
;
}
}
void
-vt102_parse_csi (VT102 * v, char *buf, int len)
+vt102_parse_csi (Context * c, char *buf, int len)
{
char last;
char *ptr;
char *arg = buf + 1;
int narg;
+ VT102 *v = c->v;
+
buf[len] = 0;
last = buf[len - 1];
@@ -928,7 +937,10 @@ vt102_parse_csi (VT102 * v, char *buf, int len)
&& (v->pos.y <= v->bottom_margin.y))
{
while (narg--)
- crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 0);
+ {
+ //FIXME call out to history
+ crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 0);
+ }
}
break;
@@ -1024,53 +1036,53 @@ vt102_status_line (VT102 * v, char *str)
void
-vt102_parse_char (VT102 * v, int c, TTY * tty)
+vt102_parse_char (Context * c, int ch)
{
+ VT102 *v = c->v;
VT102_parser *p = &v->parser;
-
#if 0
fprintf (stderr, "char %c pc %d %d %d %d %d\n", (c < 32) ? 32 : c, c,
p->in_csi, p->in_escape, v->pos.x, v->pos.y);
#endif
if (p->in_csi)
{
- p->csi_buf[p->csi_ptr++] = c;
- if (csi_ender (c) || (p->csi_ptr == VT102_CSI_LEN))
+ p->csi_buf[p->csi_ptr++] = ch;
+ if (csi_ender (ch) || (p->csi_ptr == VT102_CSI_LEN))
{
- vt102_parse_csi (v, p->csi_buf, p->csi_ptr);
+ vt102_parse_csi (c, p->csi_buf, p->csi_ptr);
p->in_csi = 0;
}
}
else if (p->in_escape)
{
- if (csi_starter (c))
+ if (csi_starter (ch))
{
p->csi_ptr = 0;
- p->csi_buf[p->csi_ptr++] = c;
+ p->csi_buf[p->csi_ptr++] = ch;
p->in_csi++;
p->in_escape = 0;
}
- else if (scs_starter (c))
+ else if (scs_starter (ch))
{
- p->in_scs = c;
+ p->in_scs = ch;
p->in_escape = 0;
}
else
{
p->in_escape = 0;
- vt102_parse_esc (v, c);
+ vt102_parse_esc (c, ch);
}
}
else if (p->in_scs)
{
- vt102_scs (v, p->in_scs, c);
+ vt102_scs (c, p->in_scs, ch);
p->in_scs = 0;
}
else
{
- switch (c)
+ switch (ch)
{
/*NUL*/ case 0:
/*SOH*/ case 1:
@@ -1079,21 +1091,21 @@ vt102_parse_char (VT102 * v, int c, TTY * tty)
/*EOT*/ case 4:
break;
/*ENQ*/ case 5:
- tty_write (tty, "vt102", 5);
+ c->t->xmit (c->t, "vt102", 5);
break;
/*ACK*/ case 6:
/*BEL*/ case 7:
break;
/*BS*/ case 8:
- vt102_cursor_retard (v);
+ vt102_cursor_retard (c->v);
break;
/*HT*/ case 9:
- vt102_cursor_advance_tab (v);
+ vt102_cursor_advance_tab (c->v);
break;
/*LF*/ case 10:
/*VT*/ case 11:
/*FF*/ case 12:
- vt102_cursor_advance_line (v);
+ vt102_cursor_advance_line (c);
if (!v->modes[VT102_MODE_NEWLINE_MODE])
break;
/*CR*/ case 13:
@@ -1129,15 +1141,15 @@ vt102_parse_char (VT102 * v, int c, TTY * tty)
/*DEL*/ case 127:
break;
/*regular character */ default:
- vt102_do_pending_wrap (v);
+ vt102_do_pending_wrap (c);
if (v->modes[VT102_MODE_INSERT])
vt102_insert_into_line (v, v->pos);
- v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = c;
+ 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;
- vt102_cursor_advance (v);
+ vt102_cursor_advance (c);
}
}
@@ -1147,17 +1159,17 @@ vt102_parse_char (VT102 * v, int c, TTY * tty)
if (v->current_line.y != v->pos.y)
{
- vt102_log_line (v, v->current_line.y);
+ vt102_log_line (c, v->current_line.y);
v->current_line = v->pos;
}
vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
}
-vt102_parse (VT102 * v, char *buf, int len, TTY * t)
+vt102_parse (Context * c, char *buf, int len)
{
while (len--)
- vt102_parse_char (v, *(buf++), t);
+ vt102_parse_char (c, *(buf++));
}
@@ -1172,15 +1184,15 @@ vt102_parser_reset (VT102_parser * p)
void
-vt102_send (VT102 * v, uint8_t key, TTY * tty)
+vt102_send (Context * c, uint8_t key)
{
- uint8_t c;
+ uint8_t ch;
#if 0
fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
#endif
if ((key > 31) && (key < 127))
{
- tty_write (tty, &key, 1);
+ c->t->xmit (c->t, &key, 1);
return;
}
@@ -1199,14 +1211,14 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
/*LF*/ case 10:
/*VT*/ case 11:
/*FF*/ case 12:
- tty_write (tty, &key, 1);
+ c->t->xmit (c->t, &key, 1);
break;
/*CR*/ case 13:
- tty_write (tty, &key, 1);
- if (v->modes[VT102_MODE_NEWLINE_MODE])
+ c->t->xmit (c->t, &key, 1);
+ if (c->v->modes[VT102_MODE_NEWLINE_MODE])
{
- c = 10;
- tty_write (tty, &c, 1);
+ ch = 10;
+ c->t->xmit (c->t, &ch, 1);
}
break;
/*SO*/ case 14:
@@ -1222,7 +1234,7 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
/*CAN*/ case 24:
/*EM*/ case 25:
/*SUB*/ case 26:
- tty_write (tty, &key, 1);
+ c->t->xmit (c->t, &key, 1);
break;
/*ESC*/ case 27:
/*FS*/ case 28:
@@ -1230,7 +1242,7 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
/*RS*/ case 30:
/*US*/ case 31:
/*DEL*/ case 127:
- tty_write (tty, &key, 1);
+ c->t->xmit (c->t, &key, 1);
break;
case KEY_UP:
@@ -1241,15 +1253,15 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
case KEY_MIDDLE:
case KEY_END:
- if (v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
+ if (c->v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
{
uint8_t buf[] = { 033, 'O', 'A' + (key - KEY_UP) };
- tty_write (tty, &buf, sizeof (buf));
+ c->t->xmit (c->t, &buf, sizeof (buf));
}
else
{
uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
- tty_write (tty, &buf, sizeof (buf));
+ c->t->xmit (c->t, &buf, sizeof (buf));
}
break;
case KEY_STAR:
@@ -1267,10 +1279,10 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
case KEY_7:
case KEY_8:
case KEY_9:
- if (v->application_keypad_mode)
+ if (c->v->application_keypad_mode)
{
uint8_t buf[] = { 033, 'O', 'a' + (key - KEY_154) };
- tty_write (tty, &buf, sizeof (buf));
+ c->t->xmit (c->t, &buf, sizeof (buf));
}
else
{
@@ -1293,23 +1305,23 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
[KEY_9] = '9'
};
- tty_write (tty, &kpoff[key], 1);
+ c->t->xmit (c->t, &kpoff[key], 1);
}
break;
case KEY_ENTER:
- if (v->application_keypad_mode)
+ if (c->v->application_keypad_mode)
{
uint8_t buf[] = { 033, 'O', 'M' };
- tty_write (tty, &buf, sizeof (buf));
+ c->t->xmit (c->t, &buf, sizeof (buf));
}
else
{
- c = 13;
- tty_write (tty, &c, 1);
- if (v->modes[VT102_MODE_NEWLINE_MODE])
+ ch = 13;
+ c->t->xmit (c->t, &ch, 1);
+ if (c->v->modes[VT102_MODE_NEWLINE_MODE])
{
- c = 10;
- tty_write (tty, &c, 1);
+ ch = 10;
+ c->t->xmit (c->t, &ch, 1);
}
}
break;
@@ -1319,7 +1331,7 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
case KEY_PF4:
{
uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
- tty_write (tty, &buf, sizeof (buf));
+ c->t->xmit (c->t, &buf, sizeof (buf));
}
break;
case KEY_INSERT:
@@ -1328,7 +1340,7 @@ vt102_send (VT102 * v, uint8_t key, TTY * tty)
case KEY_PGDN:
{
uint8_t buf[] = { 033, '[', '0' + (key - KEY_180), '~' };
- tty_write (tty, &buf, sizeof (buf));
+ c->t->xmit (c->t, &buf, sizeof (buf));
}
break;
}
@@ -1378,12 +1390,12 @@ vt102_reset (VT102 * v)
}
int
-vt102_dispatch (VT102 * v, TTY * tty)
+vt102_dispatch (Context * c)
{
char buf[1024];
int red;
- red = tty_read (tty, buf, sizeof (buf));
+ red = c->t->recv (c->t, buf, sizeof (buf));
if (red < 0)
return -1;
@@ -1391,26 +1403,26 @@ vt102_dispatch (VT102 * v, TTY * tty)
return 0;
- vt102_parse (v, buf, red, tty);
+ vt102_parse (c, buf, red);
return 0;
}
int
-vt102_dispatch_one (VT102 * v, TTY * tty)
+vt102_dispatch_one (Context * c)
{
char buf;
int red;
- red = tty_read (tty, &buf, sizeof (buf));
+ red = c->t->recv (c->t, &buf, sizeof (buf));
if (red < 0)
return -1;
if (!red)
return 0;
- vt102_parse_char (v, buf, tty);
+ vt102_parse_char (c, buf);
return 0;
}