aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ansi.c71
-rw-r--r--src/keys.h24
-rw-r--r--src/libsympathy.c73
-rw-r--r--src/project.h5
-rw-r--r--src/prototypes.h16
-rw-r--r--src/tty.h27
-rw-r--r--src/vt102.c374
-rw-r--r--src/vt102.h16
8 files changed, 449 insertions, 157 deletions
diff --git a/src/ansi.c b/src/ansi.c
index 3e925c5..4e951bb 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.7 2008/02/06 20:26:57 james
+ * *** empty log message ***
+ *
* Revision 1.6 2008/02/06 17:53:28 james
* *** empty log message ***
*
@@ -271,10 +274,7 @@ ansi_draw (ANSI * a, CRT * c)
{
CRT_Pos p;
int o;
- int hidden_cursor=0;
-
-
-
+ int hidden_cursor = 0;
for (p.y = 0; p.y < CRT_ROWS; ++p.y)
{
@@ -287,7 +287,7 @@ ansi_draw (ANSI * a, CRT * c)
continue;
if (crt_ca_cmp (a->crt.screen[o], c->screen[o]))
{
- ansi_showhide_cursor (a, 1);
+ ansi_showhide_cursor (a, 1);
a->crt.screen[o] = c->screen[o];
ansi_move (a, p);
@@ -297,25 +297,26 @@ ansi_draw (ANSI * a, CRT * c)
}
- if ((CRT_COLS>a->size.x) || (CRT_ROWS>a->size.y)) {
- char msg[]="Window is too small";
- p.x=0;
- p.y=0;
+ if ((CRT_COLS > a->size.x) || (CRT_ROWS > a->size.y))
+ {
+ char msg[] = "Window is too small";
+ p.x = 0;
+ p.y = 0;
+
+ ansi_showhide_cursor (a, 1);
+ ansi_set_attr (a, CRT_ATTR_REVERSE);
+ ansi_move (a, p);
+
+ ansi_write (a, msg, sizeof (msg));
+ a->pos.x = ANSI_INVAL;
+ }
- ansi_showhide_cursor (a, 1);
- ansi_set_attr (a, CRT_ATTR_REVERSE);
- ansi_move(a,p);
-
- ansi_write (a, msg, sizeof(msg));
- a->pos.x = ANSI_INVAL;
- }
-
- if ((c->pos.x>=a->size.x)
- || (c->pos.y>=a->size.y)) {
- ansi_showhide_cursor (a, 1);
- return;
- }
+ if ((c->pos.x >= a->size.x) || (c->pos.y >= a->size.y))
+ {
+ ansi_showhide_cursor (a, 1);
+ return;
+ }
a->crt.pos = c->pos;
ansi_move (a, a->crt.pos);
@@ -339,3 +340,29 @@ ansi_reset (ANSI * a)
ansi_cls (a);
ansi_draw (a, &a->crt);
}
+
+void ansi_parse_char(ANSI *a,int c,VT102 *v)
+{
+vt102_send(v,c);
+}
+
+void ansi_parse(ANSI *a,char *buf,int len,VT102 *v)
+{
+while (len--)
+ansi_parse_char(a,*(buf++),v);
+}
+
+int ansi_dispatch(ANSI *a,VT102 *v)
+{
+char buf[1024];
+int red;
+
+red=read(a.fd,buf,sizeof(buf));
+if (red<0) return -1;
+if (!red) return -1;
+
+ansi_parse(a,buf,red,v);
+
+return 0;
+}
+int
diff --git a/src/keys.h b/src/keys.h
new file mode 100644
index 0000000..eea1287
--- /dev/null
+++ b/src/keys.h
@@ -0,0 +1,24 @@
+#define KEY_UP 128
+#define KEY_DOWN 129
+#define KEY_RIGHT 130
+#define KEY_LEFT 131
+
+#define KEY_0 140
+#define KEY_1 141
+#define KEY_2 142
+#define KEY_3 143
+#define KEY_4 144
+#define KEY_5 145
+#define KEY_6 146
+#define KEY_7 147
+#define KEY_8 148
+#define KEY_9 149
+#define KEY_MINUS 150
+#define KEY_COMMA 151
+#define KEY_PERIOD 152
+#define KEY_ENTER 153
+
+#define KEY_PF1 160
+#define KEY_PF2 161
+#define KEY_PF3 162
+#define KEY_PF4 163
diff --git a/src/libsympathy.c b/src/libsympathy.c
index d8eb76f..5c24ef2 100644
--- a/src/libsympathy.c
+++ b/src/libsympathy.c
@@ -11,6 +11,9 @@ static char rcsid[] =
/*
* $Log$
+ * Revision 1.6 2008/02/06 20:26:58 james
+ * *** empty log message ***
+ *
* Revision 1.5 2008/02/06 17:53:28 james
* *** empty log message ***
*
@@ -32,15 +35,17 @@ static char rcsid[] =
#include "project.h"
struct termios old = { 0 };
-static int had_winch=0;
+static int had_winch = 0;
-static void quit (int not)
+static void
+quit (int not)
{
tcsetattr (0, TCSANOW, &old);
exit (1);
}
-static void winch (int not)
+static void
+winch (int not)
{
had_winch++;
}
@@ -50,68 +55,62 @@ void
testy (void)
{
struct termios raw = { 0 };
- VT102 v = { 0 };
ANSI a = { 0 };
fd_set rfd;
int fd;
char c;
+ TTY *y;
+ VT102 *v;
signal (SIGINT, quit);
-{
-struct sigaction sa={0};
+ {
+ struct sigaction sa = { 0 };
+
+ sa.sa_handler = winch;
+ sa.sa_flags = SA_RESTART;
+ sigaction (SIGWINCH, &sa, NULL);
+ }
-sa.sa_handler=winch;
-sa.sa_flags=SA_RESTART;
-sigaction(SIGWINCH,&sa,NULL);
-}
-
tcgetattr (0, &old);
tcgetattr (0, &raw);
cfmakeraw (&raw);
tcsetattr (0, TCSANOW, &raw);
- a.fd = 1;
-
- vt102_reset (&v);
+ a.fd = 0;
ansi_reset (&a);
- fd = open_fd_to_bash ();
+ t=tty_new_test();
+ v=vt102_new(t);
FD_ZERO (&rfd);
-
-
for (;;)
{
- struct timeval tv={0,100000};
+ struct timeval tv = { 0, 100000 };
- FD_SET (fd, &rfd);
- FD_SET (0, &rfd);
- if (select (fd + 1, &rfd, NULL, NULL, &tv)<0) continue;
+ FD_SET (t->fd, &rfd);
+ FD_SET (a.fd, &rfd);
+ if (select (t->fd + 1, &rfd, NULL, NULL, &tv) < 0)
+ continue;
- if (FD_ISSET (0, &rfd))
+ if (FD_ISSET (a.fd, &rfd))
{
- if ((read (0, &c, 1) <= 0) || (c == 3))
- break;
-
- write (fd, &c, 1);
+ if (ansi_dispatch(&a,v)) break;
}
- if (FD_ISSET (fd, &rfd))
+
+ if (FD_ISSET (t->fd, &rfd)) {
+ if (vt102_dispatch (v)) break;
+ }
+
+ if (had_winch)
{
- if ((read (fd, &c, 1) <= 0))
- break;
- //write (1, &c, 1);
- vt102_parse_char (&v, c);
+ had_winch = 0;
+ ansi_getsize (&a);
+ ansi_reset (&a);
ansi_draw (&a, &v.crt);
}
- if (had_winch) {
- had_winch=0;
- ansi_getsize(&a);
- ansi_reset(&a);
- ansi_draw (&a, &v.crt);
- }
}
tcsetattr (0, TCSANOW, &old);
printf ("QUAT\n");
diff --git a/src/project.h b/src/project.h
index f8be4ca..259bb6a 100644
--- a/src/project.h
+++ b/src/project.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.4 2008/02/06 20:26:58 james
+ * *** empty log message ***
+ *
* Revision 1.3 2008/02/04 05:45:55 james
* ::
*
@@ -73,9 +76,11 @@
#include <utmp.h>
#include <pty.h>
+#include "tty.h"
#include "crt.h"
#include "ansi.h"
#include "vt102.h"
+#include "keys.h"
#include "prototypes.h"
diff --git a/src/prototypes.h b/src/prototypes.h
index 9477d24..9a674db 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -9,6 +9,9 @@ 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_parse_char(ANSI *a, int c, VT102 *v);
+void ansi_parse(ANSI *a, char *buf, int len, VT102 *v);
+int ansi_dispatch(ANSI *a, VT102 *v);
/* crt.c */
void crt_erase(CRT *c, CRT_Pos s, CRT_Pos e, int ea);
void crt_cls(CRT *c);
@@ -28,11 +31,13 @@ void testy(void);
int open_fd_to_bash(void);
/* version.c */
/* vt102.c */
-int vt102_inmargins(VT102 *v, CRT_Pos p);
+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);
@@ -43,9 +48,18 @@ 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_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);
+int vt102_parse(VT102 *v, char *buf, int len);
void vt102_parser_reset(VT102_parser *p);
+void vt102_send(VT102 *v, uint8_t key);
void vt102_reset(VT102 *v);
+int vt102_dispatch(VT102 *v);
+VT102 *vt102_new(TTY *t);
+void vt102_free(VT102 *v);
diff --git a/src/tty.h b/src/tty.h
new file mode 100644
index 0000000..14a791b
--- /dev/null
+++ b/src/tty.h
@@ -0,0 +1,27 @@
+/*
+ * tty.h:
+ *
+ * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * All rights reserved.
+ *
+ */
+
+/*
+ * $Id$
+ */
+
+/*
+ * $Log$
+ * Revision 1.1 2008/02/06 20:26:58 james
+ * *** empty log message ***
+ *
+ */
+
+#ifndef __TTY_H__
+#define __TTY_H__
+
+typedef struct {
+ int fd;
+} TTY;
+
+#endif /* __TTY_H__ */
diff --git a/src/vt102.c b/src/vt102.c
index 9f32ce0..000ef7b 100644
--- a/src/vt102.c
+++ b/src/vt102.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.11 2008/02/06 20:26:58 james
+ * *** empty log message ***
+ *
* Revision 1.10 2008/02/06 17:53:28 james
* *** empty log message ***
*
@@ -193,11 +196,12 @@ vt102_log_line (VT102 * v, int line)
CRT_Pos e = { VT102_COLS - 1, line };
CRT_Pos p = { 0, line };
- if (!log)
- log=fopen("log","a+");
+ if (!log)
+ log = fopen ("log", "a+");
+
+ if (!log)
+ return;
- if (!log) return;
-
for (; e.x > 0; --e.x)
{
@@ -365,7 +369,7 @@ vt102_cursor_home (VT102 * v)
v->pos = v->top_margin;
vt102_cursor_normalize (v);
v->pending_wrap = 0;
-
+
}
vt102_cursor_absolute (VT102 * v, int x, int y)
@@ -568,7 +572,7 @@ vt102_change_attr (VT102 * v, char *na)
v->attr &= ~CRT_ATTR_REVERSE;
break;
default:
- ;
+ ;
#if 0
fprintf (stderr, "unhandled SGR %d\n", a);
#endif
@@ -616,20 +620,22 @@ vt102_parse_attr_string (VT102 * v, char *buf, int len)
vt102_change_attr (v, &num[o]);
}
-void vt102_save_state(VT102 *v)
+void
+vt102_save_state (VT102 * v)
{
-v->saved.pos=v->pos;
-v->saved.attr=v->attr;
-v->saved.origin_mode=v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
+ v->saved.pos = v->pos;
+ v->saved.attr = v->attr;
+ v->saved.origin_mode = v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
}
-void vt102_restore_state(VT102 *v)
+void
+vt102_restore_state (VT102 * v)
{
-v->pos=v->saved.pos;
-v->attr=v->saved.attr;
-v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE]=v->saved.origin_mode;
-vt102_cursor_normalize(v);
-v->pending_wrap = 0;
+ v->pos = v->saved.pos;
+ v->attr = v->saved.attr;
+ v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE] = v->saved.origin_mode;
+ vt102_cursor_normalize (v);
+ v->pending_wrap = 0;
}
void
@@ -637,46 +643,48 @@ vt102_parse_esc (VT102 * v, int c)
{
switch (c)
{
-case 'E':
- if(v->pos.y==v->bottom_margin.y) {
- vt102_log_line (v, v->pos.y);
- crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
- } else {
- vt102_cursor_relative(v,0,1);
- }
- break;
-case 'H':
- v->tabs[v->pos.x]++;
- break;
-case 'M':
- if(v->pos.y==v->top_margin.y) {
- crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1);
- } else {
- vt102_cursor_relative(v,0,-1);
- }
- break;
-case '7':
- vt102_save_state(v);
- break;
-case '8':
- vt102_restore_state(v);
- break;
-#if 0
+ case 'E':
+ if (v->pos.y == v->bottom_margin.y)
+ {
+ vt102_log_line (v, v->pos.y);
+ crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
+ }
+ else
+ {
+ vt102_cursor_relative (v, 0, 1);
+ }
+ break;
+ case 'H':
+ v->tabs[v->pos.x]++;
+ break;
+ case 'M':
+ if (v->pos.y == v->top_margin.y)
+ {
+ crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1);
+ }
+ else
+ {
+ vt102_cursor_relative (v, 0, -1);
+ }
+ break;
+ case '7':
+ vt102_save_state (v);
+ break;
+ case '8':
+ vt102_restore_state (v);
+ break;
case '=':
+ v->application_keypad_mode=1;
+ break;
case '>':
- {
- char s[] = { 033, c };
-/*Horrid hack for the moment in testing change the key mode of the upstream te*/
- write (1, s, 2);
- }
+ v->application_keypad_mode=0;
break;
-#endif
default:
#if 0
fprintf (stderr, "unhandled ESC \\033 \\%03o (ESC %c)\n", c,
(c < 32) ? '?' : c);
#endif
- ;
+ ;
}
}
void
@@ -720,19 +728,19 @@ vt102_parse_csi (VT102 * v, char *buf, int len)
case 'D':
vt102_cursor_relative (v, -narg, 0);
break;
- case 'E':
+ case 'E':
vt102_cursor_relative (v, 0, narg);
vt102_cursor_carriage_return (v);
- break;
- case 'F':
+ break;
+ case 'F':
vt102_cursor_relative (v, 0, -narg);
vt102_cursor_carriage_return (v);
- break;
- case 'G':
- vt102_cursor_absolute (v, narg-1, v->pos.y);
- break;
+ break;
+ case 'G':
+ vt102_cursor_absolute (v, narg - 1, v->pos.y);
+ break;
case 'H':
- case 'f':
+ case 'f':
{
int x, y;
@@ -847,27 +855,27 @@ vt102_parse_csi (VT102 * v, char *buf, int len)
vt102_cursor_home (v);
break;
- case 's':
- v->saved.pos=v->pos;
- break;
- case 'u':
- v->pos=v->saved.pos;
- vt102_cursor_normalize(v);
- v->pending_wrap = 0;
- break;
+ case 's':
+ v->saved.pos = v->pos;
+ break;
+ case 'u':
+ v->pos = v->saved.pos;
+ vt102_cursor_normalize (v);
+ v->pending_wrap = 0;
+ break;
default:
#if 0
fprintf (stderr, "unhandled CSI \\033%s\n", buf, buf[0]);
#endif
- ;
+ ;
}
break;
default:
#if 0
fprintf (stderr, "unhandled CSI \\033%s\n", buf, buf[0]);
#endif
- ;
+ ;
}
@@ -935,10 +943,10 @@ vt102_parse_char (VT102 * v, int c)
/*STX*/ case 2:
/*ETX*/ case 3:
/*EOT*/ case 4:
- break;
+ break;
/*ENQ*/ case 5:
- /*FIXME: Should send ack*/
- break;
+ tty_write (v->tty, "vt102", 5);
+ break;
/*ACK*/ case 6:
/*BEL*/ case 7:
break;
@@ -993,7 +1001,8 @@ vt102_parse_char (VT102 * v, int c)
}
v->crt.pos = v->pos;
- v->crt.hide_cursor=v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0:1;
+ v->crt.hide_cursor =
+ v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0 : 1;
if (v->current_line.y != v->pos.y)
{
@@ -1004,6 +1013,13 @@ vt102_parse_char (VT102 * v, int c)
vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
}
+vt102_parse(VT102 *v,char *buf,int len)
+{
+while (len--)
+ vt102_parse_char(v,*(buf++));
+}
+
+
void
vt102_parser_reset (VT102_parser * p)
{
@@ -1012,6 +1028,169 @@ vt102_parser_reset (VT102_parser * p)
p->csi_ptr = 0;
}
+
+void
+vt102_send (VT102 * v, uint8_t key)
+{
+ uint8_t c;
+ if ((key > 31) || (key < 127))
+ {
+ tty_write (v->t, &key, 1);
+ return;
+ }
+
+ switch (key)
+ {
+ /*NUL*/ case 0:
+ /*SOH*/ case 1:
+ /*STX*/ case 2:
+ /*ETX*/ case 3:
+ /*EOT*/ case 4:
+ /*ENQ*/ case 5:
+ /*ACK*/ case 6:
+ /*BEL*/ case 7:
+ /*BS*/ case 8:
+ /*HT*/ case 9:
+ /*LF*/ case 10:
+ /*VT*/ case 11:
+ /*FF*/ case 12:
+ tty_write (v->t, &key, 1);
+ break;
+ /*CR*/ case 13:
+ tty_write (v->t, &key, 1);
+ if (v->modes[VT102_MODE_NEWLINE_MODE])
+ {
+ c = 10;
+ tty_write (v->t, &c, 1);
+ }
+ break;
+ /*SO*/ case 14:
+ /*SI*/ case 15:
+ /*DLE*/ case 16:
+ /*DC1 */ case 17:
+ /*DC2 */ case 18:
+ /*DC3 */ case 19:
+ /*DC4 */ case 20:
+ /*NAK*/ case 21:
+ /*SYN*/ case 22:
+ /*ETB*/ case 23:
+ /*CAN*/ case 24:
+ /*EM*/ case 25:
+ /*SUB*/ case 26:
+ tty_write (v->t, &key, 1);
+ break;
+ /*ESC*/ case 27:
+ /*FS*/ case 28:
+ /*GS*/ case 29:
+ /*RS*/ case 30:
+ /*US*/ case 31:
+ /*DEL*/ case 127:
+ tty_write (v->t, &key, 1);
+ break;
+
+ case KEY_UP:
+ case KEY_DOWN:
+ case KEY_RIGHT:
+ case KEY_LEFT:
+ if (v->private_modes[VT102_PRIVATE_MODE_CURSOR_MODE])
+ {
+ uint8_t buf[] = { 033, '[', 'A' + (key - KEY_UP) };
+ tty_write (v->t, &key, sizeof (buf));
+ }
+ else
+ {
+ uint8_t buf[] = { 033, '[', 'O' + (key - KEY_UP) };
+ tty_write (v->t, &key, sizeof (buf));
+ }
+ break;
+ case KEY_0:
+ case KEY_1:
+ case KEY_2:
+ case KEY_3:
+ case KEY_4:
+ case KEY_5:
+ case KEY_6:
+ case KEY_7:
+ case KEY_8:
+ case KEY_9:
+ if (v->application_keypad_mode)
+ {
+ uint8_t buf[] = { 033, 'O', 'p' + (key - KEY_0) };
+ tty_write (v->t, &key, sizeof (buf));
+ }
+ else
+ {
+ c = '0' + (key - KEY_0);
+ tty_write (v->t, &c, 1);
+ }
+ break;
+ case KEY_MINUS:
+ if (v->application_keypad_mode)
+ {
+ uint8_t buf[] = { 033, 'O', 'm' };
+ tty_write (v->t, &key, sizeof (buf));
+ }
+ else
+ {
+ c = '-';
+ tty_write (v->t, &c, 1);
+ }
+ break;
+ case KEY_COMMA:
+ if (v->application_keypad_mode)
+ {
+ uint8_t buf[] = { 033, 'O', 'l' };
+ tty_write (v->t, &key, sizeof (buf));
+ }
+ else
+ {
+ c = ',';
+ tty_write (v->t, &c, 1);
+ }
+ break;
+ case KEY_PERIOD:
+ if (v->application_keypad_mode)
+ {
+ uint8_t buf[] = { 033, 'O', 'n' };
+ tty_write (v->t, &key, sizeof (buf));
+ }
+ else
+ {
+ c = '.';
+ tty_write (v->t, &c, 1);
+ }
+ break;
+ case KEY_ENTER:
+ if (v->application_keypad_mode)
+ {
+ uint8_t buf[] = { 033, 'O', 'M' };
+ tty_write (v->t, &key, sizeof (buf));
+ }
+ else
+ {
+ c = 13;
+ tty_write (v->t, &c, 1);
+ if (v->modes[VT102_MODE_NEWLINE_MODE])
+ {
+ c = 10;
+ tty_write (v->t, &c, 1);
+ }
+ }
+ break;
+ case KEY_PF1:
+ case KEY_PF2:
+ case KEY_PF3:
+ case KEY_PF4:
+ {
+ uint8_t buf[] = { 033, 'O', 'P' + (key - KEY_PF1) };
+ tty_write (v->t, &key, sizeof (buf));
+ }
+ break;
+
+ }
+
+}
+
void
vt102_reset (VT102 * v)
{
@@ -1021,6 +1200,7 @@ vt102_reset (VT102 * v)
crt_cls (&v->crt);
+ v->application_keypad_mode=0;
v->current_line = v->pos;
v->pending_wrap = 0;
@@ -1039,38 +1219,46 @@ vt102_reset (VT102 * v)
v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP] = 1;
v->private_modes[VT102_PRIVATE_MODE_AUTO_REPEAT] = 1;
v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] = 1;
+ v->modes[VT102_MODE_LOCAL_ECHO_OFF] = 1;
vt102_cursor_home (v);
vt102_reset_tabs (v);
v->current_line = v->pos;
- vt102_save_state(v);
+ vt102_save_state (v);
-#if 0
+ vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
+
+}
+
+int vt102_dispatch(VT102 *v)
{
-char buf[3];
-int i;
- for (i=0;i<200;++i) {
- sprintf(buf,"%3d",i);
- vt102_parse_char (v,buf[0]);
- vt102_parse_char (v,buf[1]);
- vt102_parse_char (v,buf[2]);
- vt102_parse_char (v,13);
- vt102_parse_char (v,27);
- vt102_parse_char (v,'M');
- }
- vt102_parse_char(v,'f');
- vt102_parse_char (v,13);
- for (i=0;i<23;++i) {
- vt102_parse_char (v,27);
- vt102_parse_char (v,'M');
- }
- vt102_parse_char(v,'b');
- vt102_parse_char (v,13);
+char buf[1024];
+int red;
+
+red=tty_read(v->t,buf,sizeof(buf));
+if (red<0) return -1;
+if (!red) return 0;
+
+vt102_parse(v,buf,red);
+
+return 0;
}
-#endif
+VT102 *vt102_new(TTY *t)
+{
+VT102 *v;
- vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
+v=(VT102 *) malloc(sizeof(VT102));
+
+vt102_reset(v);
+
+v->tty=t;
+return v;
+}
+
+void vt102_free(VT102 *v)
+{
+free(v);
}
diff --git a/src/vt102.h b/src/vt102.h
index 081f802..2fa56e6 100644
--- a/src/vt102.h
+++ b/src/vt102.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.7 2008/02/06 20:26:58 james
+ * *** empty log message ***
+ *
* Revision 1.6 2008/02/06 17:53:28 james
* *** empty log message ***
*
@@ -51,7 +54,8 @@ typedef struct
char csi_buf[VT102_CSI_LEN];
} VT102_parser;
-typedef struct {
+typedef struct
+{
CRT_Pos pos;
int attr;
int origin_mode;
@@ -67,8 +71,8 @@ typedef struct
CRT crt;
int pending_wrap;
- CRT_Pos pos,current_line;
-
+ CRT_Pos pos, current_line;
+
VT102_State saved;
uint8_t modes[VT102_NMODES];
@@ -76,6 +80,10 @@ typedef struct
uint8_t tabs[VT102_COLS];
+ int application_keypad_mode;
+
+ TTY *t;
+
} VT102;
#define VT102_PRIVATE_MODE_CURSOR_MODE 1
@@ -90,7 +98,7 @@ typedef struct
#define VT102_MODE_KEYBOARD_DISABLE 2
#define VT102_MODE_INSERT 4
-#define VT102_PRIVATE_MODE_LOCAL_ECHO_OFF 12
+#define VT102_MODE_LOCAL_ECHO_OFF 12
#define VT102_MODE_NEWLINE_MODE 20
#endif /* __VT102_H__ */