aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/Makefile.am7
-rw-r--r--src/ansi.h18
-rw-r--r--src/crt.c27
-rw-r--r--src/crt.h32
-rw-r--r--src/prototypes.h60
-rw-r--r--src/vt102.c181
-rw-r--r--src/vt102.h29
7 files changed, 239 insertions, 115 deletions
diff --git a/apps/Makefile.am b/apps/Makefile.am
index 0ef4af7..f2b82b4 100644
--- a/apps/Makefile.am
+++ b/apps/Makefile.am
@@ -7,6 +7,9 @@
# $Id$
#
# $Log$
+# Revision 1.2 2008/02/06 11:30:45 james
+# *** empty log message ***
+#
# Revision 1.1 2008/02/03 16:20:24 james
# *** empty log message ***
#
@@ -18,10 +21,10 @@ INCLUDES = -I$(srcdir)/../src
noinst_PROGRAMS = sympathyd sympathy
sympathy_SOURCES = sympathy.c
-sympathy_LDADD = ../src/libsympathy.la
+sympathy_LDADD = ../src/libsympathy.la -lutil
sympathyd_SOURCES = sympathyd.c
-sympathyd_LDADD = ../src/libsympathy.la
+sympathyd_LDADD = ../src/libsympathy.la -lutil
AM_CFLAGS=-g
diff --git a/src/ansi.h b/src/ansi.h
index b687ac6..2a5977b 100644
--- a/src/ansi.h
+++ b/src/ansi.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.2 2008/02/06 11:30:37 james
+ * *** empty log message ***
+ *
* Revision 1.1 2008/02/03 23:31:25 james
* *** empty log message ***
*
@@ -22,15 +25,16 @@
#define ANSI_INVAL -1
-typedef struct {
-int fd;
+typedef struct
+{
+ int fd;
-CRT crt;
-CRT_Pos pos;
-CRT_Pos size;
-int hide_cursor;
+ CRT crt;
+ CRT_Pos pos;
+ CRT_Pos size;
+ int hide_cursor;
-int attr;
+ int attr;
} ANSI;
diff --git a/src/crt.c b/src/crt.c
index 7b8e7dd..b839150 100644
--- a/src/crt.c
+++ b/src/crt.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.5 2008/02/06 11:30:37 james
+ * *** empty log message ***
+ *
* Revision 1.4 2008/02/05 01:11:46 james
* *** empty log message ***
*
@@ -27,7 +30,7 @@ static char rcsid[] = "$Id$";
#include "project.h"
void
-crt_erase (CRT * c, CRT_Pos s, CRT_Pos e,int ea)
+crt_erase (CRT * c, CRT_Pos s, CRT_Pos e, int ea)
{
CRT_CA *ps = &c->screen[CRT_ADDR_POS (&s)];
CRT_CA *pe = &c->screen[CRT_ADDR_POS (&e)];
@@ -36,7 +39,7 @@ crt_erase (CRT * c, CRT_Pos s, CRT_Pos e,int ea)
{
ps->chr = ' ';
if (ea)
- ps->attr = CRT_ATTR_NORMAL;
+ ps->attr = CRT_ATTR_NORMAL;
ps++;
}
@@ -49,7 +52,7 @@ crt_cls (CRT * c)
CRT_Pos e = { CRT_COLS - 1, CRT_ROWS - 1 };
int i;
- crt_erase (c, s, e,1);
+ crt_erase (c, s, e, 1);
#if 0
for (i = 0; i < CRT_ROWS; ++i)
@@ -62,13 +65,13 @@ crt_cls (CRT * c)
}
void
-crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e,int ea)
+crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea)
{
int l, n;
int p;
- s.x=0;
- e.x=CRT_COLS-1;
+ s.x = 0;
+ e.x = CRT_COLS - 1;
l = e.x - s.x;
l++;
@@ -85,18 +88,18 @@ crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e,int ea)
}
s.y = e.y;
- crt_erase (c, s, e,ea);
+ crt_erase (c, s, e, ea);
}
void
-crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e,int ea)
+crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea)
{
int l, n;
int p;
- s.x=0;
- e.x=CRT_COLS-1;
+ s.x = 0;
+ e.x = CRT_COLS - 1;
l = e.x - s.x;
l++;
@@ -109,12 +112,12 @@ crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e,int ea)
while (n--)
{
- memcpy (&c->screen[p],&c->screen[p-CRT_COLS], l);
+ memcpy (&c->screen[p], &c->screen[p - CRT_COLS], l);
p -= CRT_COLS;
}
e.y = s.y;
- crt_erase (c, s, e,ea);
+ crt_erase (c, s, e, ea);
}
diff --git a/src/crt.h b/src/crt.h
index ca3fc00..002f67f 100644
--- a/src/crt.h
+++ b/src/crt.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.3 2008/02/06 11:30:37 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/02/04 20:23:55 james
* *** empty log message ***
*
@@ -36,26 +39,31 @@
#define CRT_ATTR_BLINK 0x4
#define CRT_ATTR_BOLD 0x8
-typedef struct {
- uint8_t chr;
- uint8_t attr;
+typedef struct
+{
+ uint8_t chr;
+ uint8_t attr;
} CRT_CA;
-typedef struct {
- int x;
- int y;
+typedef struct
+{
+ int x;
+ int y;
} CRT_Pos;
-typedef struct {
- CRT_CA screen[CRT_CELS];
- CRT_Pos pos;
- int hide_cursor;
+typedef struct
+{
+ CRT_CA screen[CRT_CELS];
+ CRT_Pos pos;
+ int hide_cursor;
} CRT;
-static inline crt_ca_cmp(CRT_CA a,CRT_CA b) {
- return memcmp(&a,&b,sizeof(a));
+static inline
+crt_ca_cmp (CRT_CA a, CRT_CA b)
+{
+ return memcmp (&a, &b, sizeof (a));
}
#endif /* __CRT_H__ */
diff --git a/src/prototypes.h b/src/prototypes.h
index 67e3aaf..56af551 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -1,39 +1,39 @@
/* ansi.c */
-void ansi_write(ANSI *a, char *buf, int n);
-void ansi_getsize(ANSI *a);
-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_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_write (ANSI * a, char *buf, int n);
+void ansi_getsize (ANSI * a);
+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_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);
/* 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 */
/* testtty.c */
-int open_fd_to_bash(void);
+int open_fd_to_bash (void);
/* version.c */
/* vt102.c */
-void vt102_cursor_normalize(VT102 *v, int do_wrapscroll, int use_margins);
-void vt102_cursor_motion(VT102 *v, int x, int y, int wrapscroll);
-void vt102_delete_from_line(VT102 *v, CRT_Pos p);
-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);
-void vt102_parser_reset(VT102_parser *p);
-void vt102_reset(VT102 *v);
+void vt102_cursor_normalize (VT102 * v, int do_wrapscroll, int use_margins);
+void vt102_cursor_motion (VT102 * v, int x, int y, int wrapscroll);
+void vt102_delete_from_line (VT102 * v, CRT_Pos p);
+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);
+void vt102_parser_reset (VT102_parser * p);
+void vt102_reset (VT102 * v);
diff --git a/src/vt102.c b/src/vt102.c
index da3a587..8b61929 100644
--- a/src/vt102.c
+++ b/src/vt102.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.7 2008/02/06 11:30:37 james
+ * *** empty log message ***
+ *
* Revision 1.6 2008/02/05 01:11:46 james
* *** empty log message ***
*
@@ -236,10 +239,85 @@ vt102_delete_from_line (VT102 * v, CRT_Pos p)
&v->crt.screen[CRT_ADDR_POS (&p) + 1], sizeof (CRT_CA) * n);
}
- v->crt.screen[CRT_ADDR (v->bottom_margin.x, p.y)].chr = ' ';
+ v->crt.screen[CRT_ADDR (p.y, v->bottom_margin.x)].chr = ' ';
/*But not attr due to vt102 bug*/
}
+void
+vt102_change_mode (VT102 * v, int private, char *ns, int set)
+{
+ int m;
+
+
+ if (*ns)
+ {
+ m = atoi (ns);
+ }
+ else
+ {
+ m = 1;
+ }
+
+ if (m < 0)
+ return;
+ if (m >= VT102_NMODES)
+ return;
+
+ if (private)
+ v->private_modes[m] = set;
+ else
+ v->modes[m] = set;
+
+ fprintf (stderr, "mode set=%d private=%d num=%d\n", set, private, m);
+}
+
+void
+vt102_parse_mode_string (VT102 * v, char *buf, int len)
+{
+ int private = 0;
+ char last = buf[len - 1];
+ char num[4];
+ int o;
+
+ memset (num, 0, sizeof (num));
+ o = sizeof (num) - 1;
+
+ len--;
+
+ if (*buf == '?')
+ {
+ private++;
+ buf++;
+ len--;
+ }
+
+ if (len < 0)
+ return;
+
+ while (len--)
+ {
+ if (*buf == ';')
+ {
+ vt102_change_mode (v, private, &num[o], last == 'h');
+ memset (num, 0, sizeof (num));
+ o = sizeof (num) - 1;
+ buf++;
+ continue;
+ }
+
+ num[0] = num[1];
+ num[1] = num[2];
+ num[2] = *buf;
+
+ if (o)
+ o--;
+
+ buf++;
+ }
+
+ vt102_change_mode (v, private, &num[o], last == 'h');
+
+}
void
vt102_parse_esc (VT102 * v, int c)
@@ -262,7 +340,7 @@ vt102_parse_csi (VT102 * v, char *buf, int len)
buf[len - 1] = 0;
#endif
- if (len>2)
+ if (len > 2)
{
narg = atoi (arg);
}
@@ -300,7 +378,7 @@ vt102_parse_csi (VT102 * v, char *buf, int len)
vt102_cursor_normalize (v, 0, 0);
break;
case 'J':
- fprintf(stderr,"OCTOPUS %d\n",narg);
+ fprintf (stderr, "OCTOPUS %d\n", narg);
switch (narg)
{
case 1:
@@ -315,27 +393,24 @@ vt102_parse_csi (VT102 * v, char *buf, int len)
{
CRT_Pos ls = { 0, v->pos.y };
CRT_Pos le = { VT102_COLS - 1, v->pos.y };
- if (len==2)
+ if (len == 2)
narg = 0; /*Different default */
switch (narg)
{
case 0:
- fprintf(stderr,"FISH %d %d -> %d %d\n",
- v->pos.x,v->pos.y,
- le.x,le.y);
+ fprintf (stderr, "FISH %d %d -> %d %d\n",
+ v->pos.x, v->pos.y, le.x, le.y);
crt_erase (&v->crt, v->pos, le, 1);
break;
case 1:
- fprintf(stderr,"SOUP %d %d -> %d %d\n",
- ls.x,ls.y,
- v->pos.x,v->pos.y);
+ fprintf (stderr, "SOUP %d %d -> %d %d\n",
+ ls.x, ls.y, v->pos.x, v->pos.y);
crt_erase (&v->crt, ls, v->pos, 1);
break;
case 2:
- fprintf(stderr,"TREE %d %d -> %d %d\n",
- ls.x,ls.y,
- le.x,le.y);
+ fprintf (stderr, "TREE %d %d -> %d %d\n",
+ ls.x, ls.y, le.x, le.y);
crt_erase (&v->crt, ls, le, 1);
break;
}
@@ -364,41 +439,50 @@ vt102_parse_csi (VT102 * v, char *buf, int len)
}
break;
- case 'g':
- case 'h':
- case 'l':
- fprintf (stderr, "C: CSI %s buf[0]=%c\n", buf,buf[0]);
- break;
-
- case 'm':
- //horror of horrors parsing the ;
- break;
- case 'r':
- v->top_margin=v->screen_start;
- v->bottom_margin=v->screen_end;
-
- if ((len>2) && (ptr=index(arg,';'))) {
- ptr++;
- v->top_margin.y=narg-1;
- v->bottom_margin.y=atoi(ptr)-1;
- }
-
- if (v->top_margin.y<v->screen_start.y) v->top_margin.y=v->screen_start.y;
- if (v->top_margin.y>v->screen_end.y) v->top_margin.y=v->screen_end.y;
- if (v->bottom_margin.y<v->screen_start.y) v->bottom_margin.y=v->screen_start.y;
- if (v->bottom_margin.y>v->screen_end.y) v->bottom_margin.y=v->screen_end.y;
-
- fprintf(stderr,"D: %d %d\n",v->top_margin.y,v->bottom_margin.y);
-
- v->pos=v->top_margin;
- break;
+ case 'g':
+ fprintf (stderr, "C: CSI %s buf[0]=%c\n", buf, buf[0]);
+ break;
+
+ case 'h':
+ case 'l':
+ fprintf (stderr, "D: CSI %s buf[0]=%c\n", buf, buf[0]);
+ vt102_parse_mode_string (v, &buf[1], len - 1);
+ break;
+
+ case 'm':
+ //horror of horrors parsing the ;
+ break;
+ case 'r':
+ v->top_margin = v->screen_start;
+ v->bottom_margin = v->screen_end;
+
+ if ((len > 2) && (ptr = index (arg, ';')))
+ {
+ ptr++;
+ v->top_margin.y = narg - 1;
+ v->bottom_margin.y = atoi (ptr) - 1;
+ }
+
+ if (v->top_margin.y < v->screen_start.y)
+ v->top_margin.y = v->screen_start.y;
+ if (v->top_margin.y > v->screen_end.y)
+ v->top_margin.y = v->screen_end.y;
+ if (v->bottom_margin.y < v->screen_start.y)
+ v->bottom_margin.y = v->screen_start.y;
+ if (v->bottom_margin.y > v->screen_end.y)
+ v->bottom_margin.y = v->screen_end.y;
+
+ fprintf (stderr, "D: %d %d\n", v->top_margin.y, v->bottom_margin.y);
+
+ v->pos = v->top_margin;
+ break;
default:
- fprintf (stderr, "A: CSI %s buf[0]=%c\n", buf,buf[0]);
+ fprintf (stderr, "A: CSI %s buf[0]=%c\n", buf, buf[0]);
}
break;
default:
- fprintf (stderr, "B: CSI %s buf[0]=%c\n", buf,buf[0]);
+ fprintf (stderr, "B: CSI %s buf[0]=%c\n", buf, buf[0]);
}
@@ -429,8 +513,8 @@ vt102_parse_char (VT102 * v, int c)
VT102_parser *p = &v->parser;
#if 0
- fprintf (stderr, "%c pc %d %d %d %d %d\n", c, c, p->in_csi, p->in_escape,
- v->pos.x, v->pos.y);
+ fprintf (stderr, "%c pc %d %d %d %d %d\n", (c > 31) ? 32 : c, c,
+ p->in_csi, p->in_escape, v->pos.x, v->pos.y);
#endif
if (p->in_csi)
{
@@ -469,13 +553,14 @@ vt102_parse_char (VT102 * v, int c)
/*ENQ*/ case 5:
/*ACK*/ case 6:
/*BEL*/ case 7:
+ break;
/*BS*/ case 8:
vt102_cursor_motion (v, -1, 0, 1);
break;
/*HT*/ case 9:
- v->pos.x+=8;
- v->pos.x&=~7;
- vt102_cursor_normalize(v,1,1);
+ v->pos.x += 8;
+ v->pos.x &= ~7;
+ vt102_cursor_normalize (v, 1, 1);
break;
/*LF*/ case 10:
/*VT*/ case 11:
diff --git a/src/vt102.h b/src/vt102.h
index 6942175..1007353 100644
--- a/src/vt102.h
+++ b/src/vt102.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.4 2008/02/06 11:30:37 james
+ * *** empty log message ***
+ *
* Revision 1.3 2008/02/04 20:23:55 james
* *** empty log message ***
*
@@ -28,10 +31,12 @@
#define VT102_CSI_LEN 128
-#define VT102_ROWS 24
-#define VT102_COLS 80
+#define VT102_ROWS 24
+#define VT102_COLS 80
#define VT102_STATUS_ROW 24
+#define VT102_NMODES 32
+
typedef struct
{
int in_escape;
@@ -42,13 +47,29 @@ typedef struct
typedef struct
{
- CRT_Pos top_margin,bottom_margin;
- CRT_Pos screen_start,screen_end;
+ CRT_Pos top_margin, bottom_margin;
+ CRT_Pos screen_start, screen_end;
VT102_parser parser;
int attr;
CRT crt;
CRT_Pos pos;
+
+ uint8_t modes[VT102_NMODES];
+ uint8_t private_modes[VT102_NMODES];
} VT102;
+#define VT102_PRIVATE_MODE_CURSOR_MODE 1
+#define VT102_PRIVATE_MODE_VT52 2
+#define VT102_PRIVATE_MODE_132COLS 3
+#define VT102_PRIVATE_MODE_SMOOTH_SCROLL 4
+#define VT102_PRIVATE_MODE_REVERSE_SCREEN 5
+#define VT102_PRIVATE_MODE_ORIGIN_MODE 6
+#define VT102_PRIVATE_MODE_AUTO_WRAP 7
+#define VT102_PRIVATE_MODE_AUTO_REPEAT 8
+
+#define VT102_MODE_KEYBOARD_DISABLE 2
+#define VT102_MODE_INSERT 4
+#define VT102_PRIVATE_MODE_LOCAL_ECHO_OFF 12
+#define VT102_MODE_NEWLINE_MODE 20
#endif /* __VT102_H__ */