chiark / gitweb /
*** empty log message ***
authorjames <james>
Sun, 24 Feb 2008 00:42:52 +0000 (00:42 +0000)
committerjames <james>
Sun, 24 Feb 2008 00:42:52 +0000 (00:42 +0000)
17 files changed:
Makefile.am
apps/Makefile.am
apps/mainloop.c
apps/sympathy.c
apps/usage.c
src/Makefile.am
src/ansi.c
src/ansi.h
src/crt.h
src/prototypes.h
src/ptty.c
src/serial.c
src/utf8.c
src/utf8.h
src/util.c
src/vt102.c
src/vt102.h

index 778ebd9d7c8a6833a3efd4bf7173cba96ef7ad96..519169107807be96a7f671afff82241118ff1034 100644 (file)
@@ -8,6 +8,9 @@
 # $Id$
 #
 # $Log$
+# Revision 1.2  2008/02/24 00:42:52  james
+# *** empty log message ***
+#
 # Revision 1.1  2008/02/03 16:20:23  james
 # *** empty log message ***
 #
@@ -40,3 +43,12 @@ version.sed: $(VFD)/version-files $(VFD)/version-major \
                echo "s/%VERSION%/${VNUM}/g" > version.sed; \
        fi
 
+protos:
+       (cd src && ${MAKE} protos)
+
+tidy:
+       cvs commit -m ""
+       (cd src && ${MAKE} tidy)
+       (cd apps && ${MAKE} tidy)
+
+       
index 513e8ad02b4f3cf32a5558a5730820aca95e1cf0..51a39e4ff610fa11003e12424440244f33c4d8d1 100644 (file)
@@ -7,6 +7,9 @@
 # $Id$
 #
 # $Log$
+# Revision 1.11  2008/02/24 00:42:53  james
+# *** empty log message ***
+#
 # Revision 1.10  2008/02/20 18:35:10  james
 # *** empty log message ***
 #
@@ -44,11 +47,18 @@ INCLUDES = -I$(srcdir)/../src
 
 bin_PROGRAMS = sympathy
 
-noinst_HEADERS=clients.h mainloop.h
+HDRS=clients.h mainloop.h
+SRCS=sympathy.c usage.c clients.c mainloop.c
 
-sympathy_SOURCES = sympathy.c usage.c clients.c mainloop.c
+noinst_HEADERS=${HDRS}
+
+sympathy_SOURCES = ${SRCS}
 sympathy_LDADD = ../src/libsympathy.la  -lutil
 
+tidy: ${SRCS} ${HDRS}
+       indent -i2 -ts0 ${SRCS} ${HDRS} 
+       /bin/rm -f *~
+
 AM_CFLAGS=-g -Werror
 
 
index e674b2e06dd61237ba87adcbbe7b8dbc74ffdfeb..73b2236695bb8f8d86dee60b278b5b5768be3d33 100644 (file)
@@ -6,10 +6,14 @@
  *
  */
 
-static char rcsid[] = "$Id$";
+static char rcsid[] =
+  "$Id$";
 
 /*
  * $Log$
+ * Revision 1.11  2008/02/24 00:43:55  james
+ * *** empty log message ***
+ *
  * Revision 1.10  2008/02/23 13:05:57  staffcvs
  * *** empty log message ***
  *
index b24e6d001ad9c5b27312cfcaa27670f35bde5707..13b54ef7938ef242740409ebbb45bf9e35af7655 100644 (file)
@@ -11,6 +11,12 @@ static char rcsid[] =
 
 /*
  * $Log$
+ * Revision 1.14  2008/02/24 00:43:55  james
+ * *** empty log message ***
+ *
+ * Revision 1.13  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.12  2008/02/23 11:48:52  james
  * *** empty log message ***
  *
@@ -258,7 +264,7 @@ main (int argc, char *argv[])
     "sympathy -c      [-H] -k skt\n"
     "sympathy -r id   [-H]\n" "sympathy {-l|-ls}\n"
 #endif
-    while ((c = getopt (argc, argv, "tscr:lKHd:pb:fL:Fk:n:")) != EOF)
+    while ((c = getopt (argc, argv, "utscr:lKHd:pb:fL:Fk:n:")) != EOF)
     {
       switch (c)
         {
@@ -480,7 +486,9 @@ main (int argc, char *argv[])
       else
         {
           terminal_register_handlers ();
-          ansi = ansi_new_from_terminal (terminal_open (0, 1));
+          ansi =
+            ansi_new_from_terminal (terminal_open (0, 1),
+                                    oflags['u'] ? 0 : 1);
           ansi->reset (ansi, NULL);
         }
     }
index b0893d2fb1a9bf2be7caafd75663152a0300290d..07da7faebafcbc324680586f667c50933813504d 100644 (file)
@@ -10,6 +10,12 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.9  2008/02/24 00:43:55  james
+ * *** empty log message ***
+ *
+ * Revision 1.8  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.7  2008/02/23 11:48:52  james
  * *** empty log message ***
  *
@@ -41,13 +47,13 @@ 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"
-           "sympathy [-s -c] [-K] [-d serialdev|-p] [-b baud] [-f] [-L log] [-k skt]\n"
+           "sympathy -t      [-K] [-d serialdev|-p] [-b baud] [-f] [-L log] [-u]\n"
+           "sympathy -s      [-K] [-d serialdev|-p] [-b baud] [-f] [-L log] [-u] [-F]\n"
+           "                      [-k skt] [-n hlines]\n"
+           "sympathy [-s -c] [-K] [-d serialdev|-p] [-b baud] [-f] [-L log] [-u] [-k skt]\n"
            "                      [-n hlines]\n"
-           "sympathy -c      [-H] -k skt\n"
-           "sympathy -r id   [-H]\n"
+           "sympathy -c      [-H] [-u] -k skt\n"
+           "sympathy -r id   [-H] [-u]\n"
            "sympathy {-l|-ls}\n"
            "sympathy -h\n"
            "\n"
@@ -85,7 +91,9 @@ usage (void)
            "         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");
+           "                 server, that are replayed on connexion\n"
+           "   -u  don't emit utf-8 instead map all non ascii characters as ?\n");
+
 
   exit (1);
 }
index ad3e0ada9239b9fe364d4163954cd772b6c97ee9..7e0a3b93deab94568a72ed968fc31cb9a0055408 100644 (file)
@@ -8,6 +8,9 @@
 # $Id$
 #
 # $Log$
+# Revision 1.17  2008/02/24 00:42:53  james
+# *** empty log message ***
+#
 # Revision 1.16  2008/02/22 23:39:27  james
 # *** empty log message ***
 #
@@ -113,6 +116,7 @@ protos:
 
 tidy: ${SRCS} ${HDRS}
        indent -i2 -ts0 ${SRCS} ${HDRS} 
+       /bin/rm -f *~
 
 sympathy.h: ${PROJECTHDRS} sympathy.h.head sympathy.h.tail
        cat sympathy.h.head ${PROJECTHDRS} sympathy.h.tail > $@ || /bin/rm -f $@
index 256f7fb95d4d508d458e68d3d3f8631ea33d381b..7a0d630a18406a3966d4bf9bb949d60d713d8e4b 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.30  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.29  2008/02/23 11:48:37  james
  * *** empty log message ***
  *
@@ -316,21 +319,30 @@ ansi_set_attr (ANSI * a, int attr)
 
 }
 
+static void
+ansi_emit_noutf8 (TTY * t, uint32_t ch)
+{
+  uint8_t c = (ch > 0x7f) ? '?' : ch;
+  t->xmit (t, &c, 1);
+}
 
 static void
 ansi_render (ANSI * a, CRT_CA ca)
 {
   int dif;
 
-  if (ca.chr < 32)
+  if (ca.chr < 0x20)
     ca.chr = ' ';
-  if (ca.chr > 126)
+  if ((ca.chr > 0x7e) && (ca.chr < 0xa0))
     ca.chr = ' ';
 
   ansi_set_attr (a, ca.attr);
   ansi_set_color (a, ca.color);
 
-  a->terminal->xmit (a->terminal, &ca.chr, 1);
+  if (a->utf8)
+    utf8_emit (a->terminal, ca.chr);
+  else
+    ansi_emit_noutf8 (a->terminal, ca.chr);
 
   a->pos.x++;
 
@@ -883,7 +895,7 @@ ansi_free (ANSI * a)
 }
 
 ANSI *
-ansi_new_from_terminal (TTY * t)
+ansi_new_from_terminal (TTY * t, int utf8)
 {
   ANSI *ret;
 
@@ -892,6 +904,7 @@ ansi_new_from_terminal (TTY * t)
 
   ret->terminal = t;
 
+  ret->utf8 = utf8;
   ret->update = ansi_update;
   ret->reset = ansi_reset;
   ret->terminal_reset = ansi_terminal_reset;
index 8895a8221d084e4fbed24e2e45b22f5392e2c469..61ffff01dc5daa902d123417901e73f6e6148b6e 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.13  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.12  2008/02/23 11:48:37  james
  * *** empty log message ***
  *
@@ -82,6 +85,8 @@ typedef struct ANSI_struct
   int attr;
   int color;
 
+  int utf8;
+
   int history_ptr;
   FILE *file;
 
index 933dc7bfac04a419b05ff7bd633edb51d8b30640..d2119a36e88eeedd8ba26f4cc727fdc37e6b2f85 100644 (file)
--- a/src/crt.h
+++ b/src/crt.h
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.10  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.9  2008/02/20 19:25:09  james
  * *** empty log message ***
  *
@@ -84,9 +87,9 @@
 
 #define CRT_COLOR_NORMAL       CRT_MAKE_COLOR(CRT_FGCOLOR_NORMAL,CRT_BGCOLOR_NORMAL)
 
-typedef struct
+typedef struct __attribute__ ((packed))
 {
-  uint8_t chr;
+  uint32_t chr;
   uint8_t attr;
   uint8_t color;
 } CRT_CA;
index 9c5eec4ec59649b3d918af54b7364d08c00c96e1..a084d3219972cfeeb2ef2af8dcf2beb69fd0102e 100644 (file)
@@ -1,6 +1,6 @@
 /* ansi.c */
 extern int ansi_dispatch(ANSI *a, Context *c);
-extern ANSI *ansi_new_from_terminal(TTY *t);
+extern ANSI *ansi_new_from_terminal(TTY *t, int utf8);
 /* crt.c */
 extern void crt_erase(CRT *c, CRT_Pos s, CRT_Pos e, int ea, int color);
 extern void crt_cls(CRT *c);
@@ -37,7 +37,7 @@ 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_regular_char(Context *c, VT102 *v, int 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);
@@ -90,8 +90,8 @@ 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 void client_termios(struct termios *termios);
 /* log.c */
 extern Log *file_log_new(char *fn);
 extern void log_f(Log *log, char *fmt, ...);
@@ -158,5 +158,6 @@ 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 void utf8_parse(Context *c, int ch);
+extern void utf8_parse(Context *c, uint32_t ch);
 extern UTF8 *utf8_new(void);
+extern void utf8_emit(TTY *t, int ch);
index e2688259a51b591ff692073d15232b97ef96abea..bddc56ec4d8385d635aea7c33afddad9b6468663 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.10  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.9  2008/02/23 13:05:58  staffcvs
  * *** empty log message ***
  *
@@ -137,19 +140,16 @@ ptty_open (char *path, char *argv[])
   pid_t child;
   char name[1024];
   struct winsize winsize = { 0 };
-  struct termios termios = { 0 };
+  struct termios ctermios = { 0 };
   int fd;
   char *default_argv[] = { "-", (char *) 0 };
 
 
-  default_termios (&termios);
-  cfsetispeed (&termios, B9600);
-  cfsetospeed (&termios, B9600);
-
+  client_termios (&ctermios);
   winsize.ws_row = VT102_ROWS;
   winsize.ws_col = VT102_COLS;
 
-  child = forkpty (&fd, name, &termios, &winsize);
+  child = forkpty (&fd, name, &ctermios, &winsize);
 
   switch (child)
     {
@@ -169,6 +169,16 @@ ptty_open (char *path, char *argv[])
 
   set_nonblocking (fd);
 
+#if 0
+  {
+    struct termios termios = { 0 };
+
+    tcgetattr (fd, &termios);
+    default_termios (&termios);
+    tcsetattr (fd, TCSANOW, &termios);
+  }
+#endif
+
   t = (PTTY *) malloc (sizeof (PTTY));
 
   strncpy (t->name, name, sizeof (t->name));
index 378457365296fa7bfe2f0cae2662269ffe92a96c..ab06e60ecaafb6b1420a8c2781c8149f20411e66 100644 (file)
@@ -10,6 +10,12 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.10  2008/02/24 00:47:14  james
+ * *** empty log message ***
+ *
+ * Revision 1.9  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.8  2008/02/23 13:05:58  staffcvs
  * *** empty log message ***
  *
index 52ba39896a67e1c1291e5392842e905cc54bd0b5..ff8a2ecdc3f13d9a9180a93042ec50afd3c8ce2e 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.5  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.4  2008/02/23 13:05:58  staffcvs
  * *** empty log message ***
  *
@@ -61,7 +64,7 @@ utf8_flush (Context * c)
 }
 
 void
-utf8_parse (Context * c, int ch)
+utf8_parse (Context * c, uint32_t ch)
 {
   UTF8 *u = c->u;
 
@@ -74,7 +77,8 @@ utf8_parse (Context * c, int ch)
 
   if (!u->in_utf8)
     {
-      /*FIXME: for the moment we bodge utf8 support */
+      /*FIXME: for the moment we bodge utf8 support - need to do */
+      /* L->R and R->L and double width characters */
       if (ch == 0xb9)
         {                       /*CSI, not a valid utf8 start char */
           vt102_parse_char (c, ch);
@@ -123,7 +127,7 @@ utf8_parse (Context * c, int ch)
           u->in_utf8--;
 
           if (!u->in_utf8)
-            vt102_parse_char (c, ch);
+            vt102_parse_char (c, u->ch);
         }
     }
 }
@@ -140,3 +144,39 @@ utf8_new (void)
   ret->in_utf8 = 0;
 
 }
+
+
+
+void
+utf8_emit (TTY * t, int ch)
+{
+  uint8_t buf[4];
+
+  if (ch < 0x80)
+    {
+      buf[0] = ch;
+      t->xmit (t, buf, 1);
+    }
+  else if (ch < 0x800)
+    {
+      buf[0] = 0xc0 | (ch >> 6);
+      buf[1] = 0x80 | (ch & 0x3f);
+
+      t->xmit (t, buf, 2);
+    }
+  else if (ch < 0x10000)
+    {
+      buf[0] = 0xe0 | (ch >> 12);
+      buf[1] = 0x80 | ((ch >> 6) & 0x3f);
+      buf[2] = 0x80 | (ch & 0x3f);
+      t->xmit (t, buf, 3);
+    }
+  else if (ch < 0x1fffff)
+    {
+      buf[0] = 0xf0 | (ch >> 18);
+      buf[1] = 0x80 | ((ch >> 12) & 0x3f);
+      buf[2] = 0x80 | ((ch >> 6) & 0x3f);
+      buf[3] = 0x80 | (ch & 0x3f);
+      t->xmit (t, buf, 4);
+    }
+}
index 4fbf37827fbd08fdef437690b9c7aa9bab892c49..22ee91552170aa2e5c6e41564ae49c00432af3a8 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.4  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.3  2008/02/23 11:48:37  james
  * *** empty log message ***
  *
@@ -35,7 +38,7 @@ typedef struct
   uint8_t utf_buf[4];
   int utf_ptr;
 
-  int ch;
+  uint32_t ch;
   int sh;
 } UTF8;
 
index ba1e30946584a627019b4166e4a0b1f4065fad6b..e8b221acba01c78783b1e7a5bfcdf7546f99eede 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.5  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.4  2008/02/23 13:05:58  staffcvs
  * *** empty log message ***
  *
@@ -78,17 +81,15 @@ set_blocking (int fd)
   fcntl (fd, F_SETFL, arg);
 }
 
+
+
 void
-raw_termios (struct termios *termios)
+default_termios (struct termios *termios)
 {
-
-  termios->c_iflag = 0;
-/*ICRNL | IXON;*/
+  termios->c_iflag = PARMRK | INPCK;
   termios->c_oflag = NL0 | CR0 | TAB0 | BS0 | VT0 | FF0;
   termios->c_lflag = 0;
-/*
-    ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE;
-*/
+  termios->c_cflag = CS8 | CREAD | CLOCAL;
 
   termios->c_cc[VINTR] = 003;
   termios->c_cc[VQUIT] = 034;
@@ -105,19 +106,36 @@ raw_termios (struct termios *termios)
   termios->c_cc[VREPRINT] = 022;
   termios->c_cc[VDISCARD] = 017;
 
+
 }
 
 void
-default_termios (struct termios *termios)
+client_termios (struct termios *termios)
 {
+  memset (termios, 0, sizeof (termios));
 
-//  memset (termios, 0, sizeof (termios));
+  termios->c_iflag = ICRNL | IXON | PARMRK | INPCK;
+  termios->c_oflag = OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0;
+  termios->c_lflag =
+    ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE;
+  termios->c_cflag = CS8 | CREAD | CLOCAL;
 
-  raw_termios (termios);
+  termios->c_cc[VINTR] = 003;
+  termios->c_cc[VQUIT] = 034;
+  termios->c_cc[VERASE] = 0177;
+  termios->c_cc[VKILL] = 025;
+  termios->c_cc[VEOF] = 004;
+  termios->c_cc[VEOL] = 0;
+  termios->c_cc[VEOL2] = 0;
+  termios->c_cc[VSTART] = 021;
+  termios->c_cc[VSTOP] = 023;
+  termios->c_cc[VSUSP] = 032;
+  termios->c_cc[VLNEXT] = 026;
+  termios->c_cc[VWERASE] = 027;
+  termios->c_cc[VREPRINT] = 022;
+  termios->c_cc[VDISCARD] = 017;
 
-  termios->c_cflag = CS8 | CREAD | CLOCAL;
-  termios->c_iflag |= PARMRK | INPCK;
 
-  //cfsetispeed (termios, B9600);
-  //cfsetospeed (termios, B9600);
+  cfsetispeed (termios, B9600);
+  cfsetospeed (termios, B9600);
 }
index 9b316cefb6b94ee920ca96089d738f7f9b257931..5a2ab376edbcd712d6a8d03206d8b977f8d142f2 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.35  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.34  2008/02/23 11:48:37  james
  * *** empty log message ***
  *
@@ -894,7 +897,7 @@ vt102_restore_state (VT102 * v)
 }
 
 void
-vt102_regular_char (Context * c, VT102 * v, char ch)
+vt102_regular_char (Context * c, VT102 * v, int ch)
 {
 
   vt102_do_pending_wrap (c);
@@ -1307,10 +1310,12 @@ vt102_parse_char (Context * c, int ch)
 #endif
 
 /* Turn anything non-ascii into '?' */
+#if 0
   if ((ch != SYM_CHAR_RESET) && (ch != 0xb9) && (ch > 127))
     {
       ch = '?';
     }
+#endif
 
 
   if (ch == SYM_CHAR_RESET)
index 6343e6dcdf1140131ddfc915d86e714c83633437..d12182a4aa8cd88bf10c57bdc5689f3b9b74b752 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.15  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
  * Revision 1.14  2008/02/23 11:48:37  james
  * *** empty log message ***
  *
@@ -107,7 +110,7 @@ typedef struct
 
   int application_keypad_mode;
 
-  char last_reg_char;
+  int last_reg_char;
   int xn_glitch;
 
 } VT102;