aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjames <>2008-02-12 22:36:46 +0000
committerjames <>2008-02-12 22:36:46 +0000
commit8688a9519c349b6ee8664be6ce2897a59c0f52be (patch)
treeacfb9332cedbc05b114aa5c5d70fc08741ae8ce7
parent5ee4b614cdc64a13aeeb00bf0e0ecbc234e8852d (diff)
downloadsympathy-8688a9519c349b6ee8664be6ce2897a59c0f52be.tar.gz
sympathy-8688a9519c349b6ee8664be6ce2897a59c0f52be.tar.bz2
sympathy-8688a9519c349b6ee8664be6ce2897a59c0f52be.zip
*** empty log message ***
-rw-r--r--src/Makefile.am18
-rw-r--r--src/context.h12
-rw-r--r--src/history.c47
-rw-r--r--src/history.h21
-rw-r--r--src/libsympathy.c5
-rw-r--r--src/prototypes.h15
-rw-r--r--src/ptty.c67
-rw-r--r--src/ring.c56
-rw-r--r--src/ring.h44
-rw-r--r--src/terminal.c189
-rw-r--r--src/tty.c4
11 files changed, 364 insertions, 114 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 3afac2b..94f0f7b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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 ***
#
@@ -30,15 +33,19 @@
#
#
-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
diff --git a/src/context.h b/src/context.h
index 365931f..607f249 100644
--- a/src/context.h
+++ b/src/context.h
@@ -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 ***
*
@@ -20,10 +23,11 @@
#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__ */
diff --git a/src/history.c b/src/history.c
index 026714c..b8637aa 100644
--- a/src/history.c
+++ b/src/history.c
@@ -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;
-}
+}
diff --git a/src/history.h b/src/history.h
index 6c1bdba..79661af 100644
--- a/src/history.h
+++ b/src/history.h
@@ -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 ***
*
@@ -20,16 +23,18 @@
#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__ */
diff --git a/src/libsympathy.c b/src/libsympathy.c
index 9c3608b..e91d08a 100644
--- a/src/libsympathy.c
+++ b/src/libsympathy.c
@@ -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;
}
diff --git a/src/prototypes.h b/src/prototypes.h
index 4468fe8..8468fb6 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -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[]);
diff --git a/src/ptty.c b/src/ptty.c
index dee241b..b59f823 100644
--- a/src/ptty.c
+++ b/src/ptty.c
@@ -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;
}
diff --git a/src/ring.c b/src/ring.c
index 310ea64..f9ef6af 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -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;
}
diff --git a/src/ring.h b/src/ring.h
index d0dd3a0..bd15cd4 100644
--- a/src/ring.h
+++ b/src/ring.h
@@ -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 ***
*
@@ -20,11 +23,12 @@
#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
index 0000000..a4cd31b
--- /dev/null
+++ b/src/terminal.c
@@ -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);
+}
+
+
diff --git a/src/tty.c b/src/tty.c
index 8f01f24..e38ee51 100644
--- 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 ***
*
*/
-