chiark / gitweb /
*** empty log message ***
authorjames <james>
Tue, 12 Feb 2008 22:36:46 +0000 (22:36 +0000)
committerjames <james>
Tue, 12 Feb 2008 22:36:46 +0000 (22:36 +0000)
src/Makefile.am
src/context.h
src/history.c
src/history.h
src/libsympathy.c
src/prototypes.h
src/ptty.c
src/ring.c
src/ring.h
src/terminal.c [new file with mode: 0644]
src/tty.c

index 3afac2b292e1d9f9ef3cd9da3643f7040b031eb5..94f0f7b2b45eb69d2645ea551fa340b94eb20163 100644 (file)
@@ -8,6 +8,9 @@
 # $Id$
 #
 # $Log$
+# Revision 1.7  2008/02/12 22:36:46  james
+# *** empty log message ***
+#
 # Revision 1.6  2008/02/09 15:47:28  james
 # *** empty log message ***
 #
 #
 #
 
-INCLUDES = 
+INCLUDES=
+
+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
 
-SRCS= ansi.c crt.c html.c libsympathy.c render.c  version.c vt102.c tty.c \
-       history.c buf.c ptty.c
 CPROTO=cproto
 
 SYMPATHYSRCS=${SRCS}
 
-noinst_HEADERS= project.h prototypes.h
+noinst_HEADERS= prototypes.h ${HDRS}
 
 
 libsympathy_a_SOURCES =  ${SYMPATHYSRCS}
@@ -72,6 +79,9 @@ protos:
        ${CPROTO} -v ${INCLUDES} ${SRCS} > prototypes.tmp
        mv -f prototypes.tmp prototypes.h
 
+tidy: ${SRCS} ${HDRS}
+       indent -i2 -ts0 ${SRCS} ${HDRS} 
+
 version.h: $(VFD)/version-files $(VFD)/version-major \
        $(VFD)/version-minor $(VFD)/version-micro \
        $(VFD)/version-md5sums ${VFS} Makefile
index 365931f14910e2dff2452888b24d8750eac9b4e5..607f24969f7fcc5fc2c3d4ba127e6786b49aa86a 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/12 22:36:46  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/09 15:47:28  james
  * *** empty log message ***
  *
 #ifndef __CONTEXT_H__
 #define __CONTEXT_H__
 
-typedef struct {
-VT102 *v;
-TTY *t;
-History *h;
+typedef struct
+{
+  VT102 *v;
+  TTY *t;
+  History *h;
 } Context;
 
 #endif /* __CONTEXT_H__ */
index 026714c42cf01fe2fd29f991bb6b92ea6ed7d33a..b8637aae63380be2143753a1b52eb5295a512ef3 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/12 22:36:46  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/08 15:06:42  james
  * *** empty log message ***
  *
@@ -17,36 +20,42 @@ static char rcsid[] = "$Id$";
 
 #include "project.h"
 
-History *history_new(int n)
+History *
+history_new (int n)
 {
-History *ret;
+  History *ret;
 
-ret=(History *) malloc(sizeof(History));
-ret->lines=malloc(n*sizeof(History_ent));
-memset(ret->lines,0,n*sizeof(History_ent));
+  ret = (History *) malloc (sizeof (History));
+  ret->lines = malloc (n * sizeof (History_ent));
+  memset (ret->lines, 0, n * sizeof (History_ent));
 
-ret->wptr=0;
-ret->nlines=n;
+  ret->wptr = 0;
+  ret->nlines = n;
 
-return ret;
+  return ret;
 }
 
-void history_free(History *h)
+void
+history_free (History * h)
 {
-if (!h) return;
-if (h->lines) free(h->lines);
-free(h);
+  if (!h)
+    return;
+  if (h->lines)
+    free (h->lines);
+  free (h);
 }
 
 
-void history_add(History *h,CRT_CA *c)
+void
+history_add (History * h, CRT_CA * c)
 {
-if (!h) return;
+  if (!h)
+    return;
 
-memcpy(h->lines[h->wptr].line,c,sizeof(CRT_CA)*CRT_COLS);
-h->wptr++;
+  memcpy (h->lines[h->wptr].line, c, sizeof (CRT_CA) * CRT_COLS);
+  h->wptr++;
 
-if (h->wptr==h->nlines)
-       h->wptr=0;
+  if (h->wptr == h->nlines)
+    h->wptr = 0;
 
-} 
+}
index 6c1bdbad0ea9b1316a3ebc7774de59cc3d0f7f9c..79661afd674496ec131e949193ac4d0c56f7fb9a 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/12 22:36:46  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/08 15:06:42  james
  * *** empty log message ***
  *
 #ifndef __HISTORY_H__
 #define __HISTORY_H__
 
-typedef struct {
-int valid;
-time_t t;
-CRT_CA line[CRT_COLS];
+typedef struct
+{
+  int valid;
+  time_t t;
+  CRT_CA line[CRT_COLS];
 } History_ent;
 
-typedef struct {
-History_ent *lines;
-int nlines;
-int wptr;
+typedef struct
+{
+  History_ent *lines;
+  int nlines;
+  int wptr;
 } History;
 
 #endif /* __HISTORY_H__ */
index 9c3608b166069d3c7a0408d41ee454c0c19897d6..e91d08a327bc76bf86d83cbeda5f6964ea6a6bc3 100644 (file)
@@ -11,6 +11,9 @@ static char rcsid[] =
 
 /*
  * $Log$
+ * Revision 1.14  2008/02/12 22:36:46  james
+ * *** empty log message ***
+ *
  * Revision 1.13  2008/02/08 15:06:42  james
  * *** empty log message ***
  *
@@ -136,7 +139,7 @@ testy (void)
 
       if (FD_ISSET (t->fd, &rfd))
         {
-          if (vt102_dispatch_one (v, t,h))
+          if (vt102_dispatch_one (v, t, h))
             break;
         }
 
index 4468fe8e93fc6b32b96d64b5a1aa0752e53f2e06..8468fb6b49dc91791ad0497440ebcd9ff4a869bc 100644 (file)
@@ -74,7 +74,14 @@ int vt102_dispatch_one(VT102 *v, TTY *tty);
 VT102 *vt102_new(void);
 void vt102_free(VT102 *v);
 /* tty.c */
-TTY *tty_new_test(void);
-int tty_read(TTY *t, void *buf, int len);
-int tty_write(TTY *t, void *buf, int len);
-void tty_free(TTY *t);
+/* history.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);
+/* ptty.c */
+void ptty_close(TTY *_t);
+TTY *ptty_open(char *path, char *argv[]);
index dee241b8c1497c00c210ca728a6abc764089cedc..b59f823e40f8ebc667aacd8ee2208824ef308de5 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/12 22:36:46  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/09 15:47:28  james
  * *** empty log message ***
  *
@@ -33,21 +36,24 @@ static char rcsid[] = "$Id$";
 #include "project.h"
 
 
-typedef struct {
-       TTY_SIGNATURE;
-       int fd;
-       pid_t child;
+typedef struct
+{
+  TTY_SIGNATURE;
+  int fd;
+  pid_t child;
 } PTTY;
 
 
-void ptty_close(TTY *_t)
+static void
+ptty_close (TTY * _t)
 {
-PTTY *t=(PTTY *) _t;
+  PTTY *t = (PTTY *) _t;
 
-if (!t) return;
+  if (!t)
+    return;
 
-close(t->fd);
-free(t);
+  close (t->fd);
+  free (t);
 }
 
 
@@ -55,7 +61,7 @@ free(t);
 static int
 ptty_read (TTY * _t, void *buf, int len)
 {
-PTTY *t=(PTTY *)_t;
+  PTTY *t = (PTTY *) _t;
   int red, done = 0;
 
   do
@@ -82,7 +88,7 @@ static int
 ptty_write (TTY * _t, void *buf, int len)
 {
   int writ, done = 0;
-  PTTY *t=(PTTY *) _t;
+  PTTY *t = (PTTY *) _t;
 
   do
     {
@@ -103,7 +109,8 @@ ptty_write (TTY * _t, void *buf, int len)
   return done;
 }
 
-TTY * ptty_open(char *path,char *argv[])
+TTY *
+ptty_open (char *path, char *argv[])
 {
   PTTY *t;
   pid_t child;
@@ -111,7 +118,7 @@ TTY * 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 };
 
   child = forkpty (&fd, name, &termios, &winsize);
 
@@ -122,36 +129,36 @@ TTY * ptty_open(char *path,char *argv[])
     case 0:                    /*waaah */
       setenv ("TERM", "vt102", 1);
       setenv ("LANG", "C", 1);
-       if (!path) 
-               path="/bin/sh";
-       if (!argv) 
-               argv=default_argv;
-               
-      execv (path,argv);
+      if (!path)
+        path = "/bin/sh";
+
+      if (!argv)
+        argv = default_argv;
+
+      execv (path, argv);
       _exit (-1);
     }
 
   set_nonblocking (fd);
 
-  t=(PTTY*) malloc(sizeof(PTTY));
+  t = (PTTY *) malloc (sizeof (PTTY));
 
-  strncpy(t->name,name,sizeof(t->name));
-  t->name[sizeof(t->name)-1]=0;
+  strncpy (t->name, name, sizeof (t->name));
+  t->name[sizeof (t->name) - 1] = 0;
 
-  t->read=ptty_read;
-  t->write=ptty_write;
-  t->close=ptty_close;
+  t->read = ptty_read;
+  t->write = 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->rfd=t->fd;
-  t->wfd=0;
+  t->fd = open_fd_to_pty (path, argv);
+  t->pid = child;
+  t->rfd = t->fd;
+  t->wfd = 0;
 
   return (TTY *) t;
 }
index 310ea64ddae3dd0d9dcbc6224414bc5c49d17425..f9ef6af861600260236b25e62cf5d413eec8405f 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/12 22:36:46  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/08 15:06:42  james
  * *** empty log message ***
  *
@@ -17,46 +20,51 @@ static char rcsid[] = "$Id$";
 
 #include "project.h"
 
-int ring_read(Ring *r,void *b,int n)
+int
+ring_read (Ring * r, void *b, int n)
 {
-int red=0;
+  int red = 0;
 
-while (n--) {
+  while (n--)
+    {
 
-if (!ring_read_one(r,b)) 
-       break;
+      if (!ring_read_one (r, b))
+        break;
 
-b++;
-red++;
-}
+      b++;
+      red++;
+    }
 
-return red;
+  return red;
 }
 
-int ring_write(Ring *r,void *b,int n)
+int
+ring_write (Ring * r, void *b, int n)
 {
-int writ=0;
+  int writ = 0;
 
-while (n--) {
+  while (n--)
+    {
 
-if (!ring_write_one(r,b)) 
-       break;
+      if (!ring_write_one (r, b))
+        break;
 
-b++;
-writ++;
-}
+      b++;
+      writ++;
+    }
 
-return writ;
+  return writ;
 }
 
 
 
-Ring *ring_new(int n)
+Ring *
+ring_new (int n)
 {
-Ring *ret=(Ring *)malloc(sizeof(Ring));
-ret->buf=(uint8_t *)malloc(n);
-ret->size=n;
-ret->wptr=ret->rptr=0;
+  Ring *ret = (Ring *) malloc (sizeof (Ring));
+  ret->buf = (uint8_t *) malloc (n);
+  ret->size = n;
+  ret->wptr = ret->rptr = 0;
 
-return ret;
+  return ret;
 }
index d0dd3a057470edd89bc4c562db750e15eece183a..bd15cd44150f5c7355f99e06f10a956c25ff01ac 100644 (file)
@@ -12,6 +12,9 @@
 
 /*
  * $Log$
+ * Revision 1.2  2008/02/12 22:36:46  james
+ * *** empty log message ***
+ *
  * Revision 1.1  2008/02/08 15:06:42  james
  * *** empty log message ***
  *
 #ifndef __RING_H__
 #define __RING_H__
 
-typedef struct {
-       uint8_t *ring;
-       int wptr;
-       int rptr;
-       int size;
+typedef struct
+{
+  uint8_t *ring;
+  int wptr;
+  int rptr;
+  int size;
 } Ring;
 
 #define RING_NEXT(r,a) (((a)+1) % ((r)->size))
@@ -34,30 +38,32 @@ typedef struct {
 #define RING_EMPTY(r) (((r)->wptr) == ((r)->rptr))
 #define RING_FULL(r) (RING_NEXT_W(r) == ((r)->rptr))
 
-static inline int ring_write_one(Ring *r,uint8_t *c)
+static inline int
+ring_write_one (Ring * r, uint8_t * c)
 {
-if (RING_FULL(r)) return 0;
+  if (RING_FULL (r))
+    return 0;
 
-r->ring[r->wptr++]=*c;
+  r->ring[r->wptr++] = *c;
 
-if (r->wptr==r->size)
-       r->wptr=0;
-}
+  if (r->wptr == r->size)
+    r->wptr = 0;
 
-return 1;
+  return 1;
 }
 
-static inline int ring_read_one(Ring *r,uint8_t *c)
+static inline int
+ring_read_one (Ring * r, uint8_t * c)
 {
-if (RING_EMPTY(r)) return 0;
+  if (RING_EMPTY (r))
+    return 0;
 
-*c=r->ring[r->rptr++];
+  *c = r->ring[r->rptr++];
 
-if (r->rptr==r->size)
-       r->rptr=0;
-}
+  if (r->rptr == r->size)
+    r->rptr = 0;
 
-return 1;
+  return 1;
 }
 
 
diff --git a/src/terminal.c b/src/terminal.c
new file mode 100644 (file)
index 0000000..a4cd31b
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+ * terminal.c:
+ *
+ * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * All rights reserved.
+ *
+ */
+
+static char rcsid[] = "$Id$";
+
+/*
+ * $Log$
+ * Revision 1.1  2008/02/12 22:36:46  james
+ * *** empty log message ***
+ *
+ * Revision 1.1  2008/02/09 15:47:28  james
+ * *** empty log message ***
+ *
+ * Revision 1.2  2008/02/07 11:11:14  staffcvs
+ * *** empty log message ***
+ *
+ * Revision 1.1  2008/02/07 01:02:52  james
+ * *** empty log message ***
+ *
+ * Revision 1.3  2008/02/06 17:53:28  james
+ * *** empty log message ***
+ *
+ * Revision 1.2  2008/02/04 02:05:06  james
+ * *** empty log message ***
+ *
+ * Revision 1.1  2008/02/04 01:32:39  james
+ * *** empty log message ***
+ *
+ */
+
+#include "project.h"
+
+
+typedef struct TERMINAL_struct
+{
+  TTY_SIGNATURE;
+  struct termios orig_termios;
+  struct TERMINAL_struct *next;
+} TERMINAL;
+
+
+static TERMINAL terminal_list=NULL;
+
+
+static void
+terminal_close (TTY * _t)
+{
+  TERMINAL *t = (TERMINAL *) _t;
+  TERMINAL **ptr=&terminal_list;
+
+  if (!t)
+    return;
+
+  /* Take out of cleanup list */
+  while (*ptr && (*ptr != t)) ptr=&((*ptr)->next);
+
+  if (*ptr) 
+       *ptr=t->next;
+
+  tcsetattr(t->wfd,TCSANOW,&t->orig_termios);
+
+  set_blocking(t->rfd);
+  set_blocking(t->wfd);
+
+  free (t);
+}
+
+
+
+static int
+terminal_read (TTY * _t, void *buf, int len)
+{
+  TERMINAL *t = (TERMINAL *) _t;
+  int red, done = 0;
+
+  do
+    {
+
+      red = wrap_read (t->fd, buf, len);
+      if (red < 0)
+        return -1;
+      if (!red)
+        return done;
+
+      buf += red;
+      len -= red;
+      done += red;
+    }
+  while (len);
+
+
+  return done;
+}
+
+
+static int
+terminal_write (TTY * _t, void *buf, int len)
+{
+  int writ, done = 0;
+  TERMINAL *t = (TERMINAL *) _t;
+
+  do
+    {
+
+      writ = wrap_write (t->fd, buf, len);
+      if (writ < 0)
+        return -1;
+      if (!writ)
+        sleep (1);
+
+      buf += writ;
+      len -= writ;
+      done += writ;
+    }
+  while (len);
+
+
+  return done;
+}
+
+TTY *
+terminal_open (int rfd,int wfd)
+{
+  TERMINAL *t;
+  pid_t child;
+  char name[1024];
+  struct termios termios;
+
+  t = (TERMINAL *) malloc (sizeof (TERMINAL));
+
+  t->rfd = rfd;
+  t->wfd = wfd;
+
+  tcgetattr(wfd,&t->orig_termios);
+
+  t->next=terminal_list;
+  terminal_list=t;
+
+  tcgetattr(tfd,&termios);
+
+  set_nonblocking (rfd);
+  set_nonblocking (wfd);
+
+
+  raw_termios (&termios);
+
+  tcsetattr(wfd,TCSANOW,&termios);
+
+  t->read = terminal_read;
+  t->write = terminal_write;
+  t->close = terminal_close;
+
+
+  return (TTY *) t;
+}
+
+void
+terminal_getsize (TTY *_t,CRT_POS *pos)
+{
+TERMINAL *t=(TTY *) _t;
+  struct winsize sz = { 0 };
+
+if ((!t) || (!pos)) return;
+
+if (ioctl (a->wfd, TIOCGWINSZ, &sz))
+    {
+      pos->x = CRT_COLS;
+      pos->y = CRT_ROWS;
+    }
+  else
+    {
+      pos->x = sz.ws_col;
+      pos->y = sz.ws_row;
+    }
+}
+
+
+void terminal_atexit(void)
+{
+while (terminal_list)
+       terminal_close(terminal_list);
+}
+
+
index 8f01f2493bd256c1253b933fa5dd9ee5a4cccb28..e38ee515902fac3f517a9258b4538093d36e522b 100644 (file)
--- a/src/tty.c
+++ b/src/tty.c
@@ -10,8 +10,10 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.4  2008/02/12 22:36:46  james
+ * *** empty log message ***
+ *
  * Revision 1.3  2008/02/09 15:47:28  james
  * *** empty log message ***
  *
  */
-