# $Id$
#
# $Log$
+# Revision 1.3 2008/02/07 00:39:13 james
+# *** empty log message ***
+#
# Revision 1.2 2008/02/04 01:32:39 james
# *** empty log message ***
#
INCLUDES =
-SRCS= ansi.c crt.c html.c libsympathy.c render.c testtty.c version.c vt102.c
+SRCS= ansi.c crt.c html.c libsympathy.c render.c testtty.c version.c vt102.c tty.c
CPROTO=cproto
SYMPATHYSRCS=${SRCS}
/*
* $Log$
+ * Revision 1.9 2008/02/07 00:43:27 james
+ * *** empty log message ***
+ *
* Revision 1.8 2008/02/07 00:39:13 james
* *** empty log message ***
*
}
-int ansi_read(ANSI *a,void *buf,int n)
+int
+ansi_read (ANSI * a, void *buf, int n)
{
-int red;
+ int red;
- set_nonblocking(a->fd);
-red=read(a->fd,buf,n);
+ set_nonblocking (a->fd);
+ red = read (a->fd, buf, n);
-if (!red) return -1;
+ if (!red)
+ return -1;
-if ((red==-1) && (errno==EAGAIN)) {
- return 0;
-}
+ if ((red == -1) && (errno == EAGAIN))
+ {
+ return 0;
+ }
-return red;
+ return red;
}
void
ansi_write (ANSI * a, char *buf, int n)
{
- set_blocking(a->fd);
+ set_blocking (a->fd);
write (a->fd, buf, n);
}
crt_reset (&a->crt);
ansi_cls (a);
- ansi_write(a,"\033=",2);
+ ansi_write (a, "\033=", 2);
ansi_draw (a, &a->crt);
}
-void ansi_flush_escape(ANSI *a,VT102 *v)
+
+void
+ansi_flush_escape (ANSI * a, VT102 * v)
{
-ANSI_Parser *p=&a->parser;
-int i;
+ ANSI_Parser *p = &a->parser;
+ int i;
-for (i=0;i<p->escape_ptr;++i) {
-vt102_send(v,p->escape_buf[i]);
-}
+ for (i = 0; i < p->escape_ptr; ++i)
+ {
+ vt102_send (v, p->escape_buf[i]);
+ }
-p->escape_ptr=0;
-p->in_escape=0;
+ p->escape_ptr = 0;
+ p->in_escape = 0;
}
-void ansi_parse_deckey(ANSI *a,VT102 *v)
+void
+ansi_parse_deckey (ANSI * a, VT102 * v)
{
-ANSI_Parser *p=&a->parser;
-if ((p->escape_buf[1]!='[') && (p->escape_buf[1]!='O')) {
- ansi_flush_escape(a,v);
- return;
-}
-
-if ((p->escape_buf[2]>='A') || (p->escape_buf[2]<='Z')){
- vt102_send(v,KEY_UP+(p->escape_buf[2]-'A'));
-}else if ((p->escape_buf[2]>='a') || (p->escape_buf[2]<='z')){
- vt102_send(v,KEY_154+(p->escape_buf[2]-'a'));
-} else {
- ansi_flush_escape(a,v);
- return;
-}
-p->in_escape=0;
-p->escape_ptr=0;
+ ANSI_Parser *p = &a->parser;
+ if ((p->escape_buf[1] != '[') && (p->escape_buf[1] != 'O'))
+ {
+ ansi_flush_escape (a, v);
+ return;
+ }
+
+ if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z'))
+ {
+ vt102_send (v, KEY_UP + (p->escape_buf[2] - 'A'));
+ }
+ else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z'))
+ {
+ vt102_send (v, KEY_154 + (p->escape_buf[2] - 'a'));
+ }
+ else
+ {
+ ansi_flush_escape (a, v);
+ return;
+ }
+ p->in_escape = 0;
+ p->escape_ptr = 0;
}
-void ansi_parse_ansikey(ANSI *a,VT102 *v)
+void
+ansi_parse_ansikey (ANSI * a, VT102 * v)
{
-ANSI_Parser *p=&a->parser;
+ ANSI_Parser *p = &a->parser;
-if ((p->escape_buf[1]!='[') ||(p->escape_buf[3]!='~')) {
- ansi_flush_escape(a,v);
- return;
-}
-if ((p->escape_buf[2]>='0') || (p->escape_buf[2]<='9')){
- vt102_send(v,KEY_180+(p->escape_buf[2]-'0'));
-} else {
- ansi_flush_escape(a,v);
- return;
-}
+ if ((p->escape_buf[1] != '[') || (p->escape_buf[3] != '~'))
+ {
+ ansi_flush_escape (a, v);
+ return;
+ }
+ if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9'))
+ {
+ vt102_send (v, KEY_180 + (p->escape_buf[2] - '0'));
+ }
+ else
+ {
+ ansi_flush_escape (a, v);
+ return;
+ }
-p->in_escape=0;
-p->escape_ptr=0;
+ p->in_escape = 0;
+ p->escape_ptr = 0;
}
-void ansi_parse_escape(ANSI *a,VT102 *v)
+void
+ansi_parse_escape (ANSI * a, VT102 * v)
{
-ANSI_Parser *p=&a->parser;
-switch(p->escape_ptr) {
-case 0:
-case 1:
- return;
-case 2:
- switch (p->escape_buf[1]) {
- case '[':
- case 'O':
- break;
- default:
- ansi_flush_escape(a,v);
- }
- break;
-case 3:
- switch(p->escape_buf[1]) {
- case 'O':
- ansi_parse_deckey(a,v);
- break;
- case '[':
- if ((p->escape_buf[2]>='A') &&
- (p->escape_buf[2]<='Z'))
- ansi_parse_deckey(a,v);
- break;
- default:
- ansi_flush_escape(a,v);
- }
- break;
-case 4:
- switch(p->escape_buf[1]) {
- case '[':
- ansi_parse_ansikey(a,v);
- break;
- default:
- ansi_flush_escape(a,v);
- }
- break;
-case 5:
- ansi_flush_escape(a,v);
-}
+ ANSI_Parser *p = &a->parser;
+ switch (p->escape_ptr)
+ {
+ case 0:
+ case 1:
+ return;
+ case 2:
+ switch (p->escape_buf[1])
+ {
+ case '[':
+ case 'O':
+ break;
+ default:
+ ansi_flush_escape (a, v);
+ }
+ break;
+ case 3:
+ switch (p->escape_buf[1])
+ {
+ case 'O':
+ ansi_parse_deckey (a, v);
+ break;
+ case '[':
+ if ((p->escape_buf[2] >= 'A') && (p->escape_buf[2] <= 'Z'))
+ ansi_parse_deckey (a, v);
+ break;
+ default:
+ ansi_flush_escape (a, v);
+ }
+ break;
+ case 4:
+ switch (p->escape_buf[1])
+ {
+ case '[':
+ ansi_parse_ansikey (a, v);
+ break;
+ default:
+ ansi_flush_escape (a, v);
+ }
+ break;
+ case 5:
+ ansi_flush_escape (a, v);
+ }
}
-void ansi_check_escape(ANSI *a,VT102 *v)
+void
+ansi_check_escape (ANSI * a, VT102 * v)
{
-ANSI_Parser *p=&a->parser;
- struct timeval now,diff;
- gettimeofday(&now,NULL);
- timersub(&now,&p->last_escape,&diff);
+ ANSI_Parser *p = &a->parser;
+ struct timeval now, diff;
+ gettimeofday (&now, NULL);
+ timersub (&now, &p->last_escape, &diff);
#if 0
-fprintf(stderr,"ie %d tl %d.%06d eb %d\n",
- p->in_escape,diff.tv_sec,diff.tv_usec,p->escape_ptr);
+ fprintf (stderr, "ie %d tl %d.%06d eb %d\n",
+ p->in_escape, diff.tv_sec, diff.tv_usec, p->escape_ptr);
#endif
-if (!p->in_escape) return;
+ if (!p->in_escape)
+ return;
- /*Time up?*/
- if (diff.tv_sec || (diff.tv_usec > ANSI_ESCAPE_TIMEOUT))
- ansi_flush_escape(a,v);
+ /*Time up? */
+ if (diff.tv_sec || (diff.tv_usec > ANSI_ESCAPE_TIMEOUT))
+ ansi_flush_escape (a, v);
}
-void ansi_parse_char(ANSI *a,int c,VT102 *v)
+void
+ansi_parse_char (ANSI * a, int c, VT102 * v)
{
-ANSI_Parser *p=&a->parser;
+ ANSI_Parser *p = &a->parser;
/*See if it's time to flush the escape*/
-ansi_check_escape(a,v);
+ ansi_check_escape (a, v);
-if (c==033) {
- if (p->in_escape)
- ansi_flush_escape(a,v);
+ if (c == 033)
+ {
+ if (p->in_escape)
+ ansi_flush_escape (a, v);
- p->in_escape++;
- p->escape_ptr=0;
- gettimeofday(&p->last_escape,NULL);
-}
+ p->in_escape++;
+ p->escape_ptr = 0;
+ gettimeofday (&p->last_escape, NULL);
+ }
-if (p->in_escape) {
- p->escape_buf[p->escape_ptr++]=c;
- ansi_parse_escape(a,v);
-} else {
- vt102_send(v,c);
-}
+ if (p->in_escape)
+ {
+ p->escape_buf[p->escape_ptr++] = c;
+ ansi_parse_escape (a, v);
+ }
+ else
+ {
+ vt102_send (v, c);
+ }
}
-void ansi_parse(ANSI *a,char *buf,int len,VT102 *v)
+void
+ansi_parse (ANSI * a, char *buf, int len, VT102 * v)
{
-while (len--)
-ansi_parse_char(a,*(buf++),v);
+ while (len--)
+ ansi_parse_char (a, *(buf++), v);
}
-int ansi_dispatch(ANSI *a,VT102 *v)
+int
+ansi_dispatch (ANSI * a, VT102 * v)
{
-char buf[1024];
-int red;
+ char buf[1024];
+ int red;
-ansi_check_escape(a,v);
+ ansi_check_escape (a, v);
-red=ansi_read(a,buf,sizeof(buf));
-if (red<=0) return red;
+ red = ansi_read (a, buf, sizeof (buf));
+ if (red <= 0)
+ return red;
-if (*buf==3) return -1;
+ if (*buf == 3)
+ return -1;
-ansi_parse(a,buf,red,v);
+ ansi_parse (a, buf, red, v);
-return 0;
+ return 0;
}
/*
* $Log$
+ * Revision 1.4 2008/02/07 00:43:27 james
+ * *** empty log message ***
+ *
* Revision 1.3 2008/02/07 00:39:13 james
* *** empty log message ***
*
#define ANSI_INVAL -1
#define ANSI_ESCAPE_BUF_LEN 10
-#define ANSI_ESCAPE_TIMEOUT 100000 /*in ms*/
+#define ANSI_ESCAPE_TIMEOUT 100000 /*in ms */
-typedef struct {
-int in_escape;
-struct timeval last_escape;
-char escape_buf[ANSI_ESCAPE_BUF_LEN];
-int escape_ptr;
+typedef struct
+{
+ int in_escape;
+ struct timeval last_escape;
+ char escape_buf[ANSI_ESCAPE_BUF_LEN];
+ int escape_ptr;
} ANSI_Parser;
typedef struct
+/*
+ * src/keys.h:
+ *
+ * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * All rights reserved.
+ *
+ */
+
+/*
+ * $Id$
+ */
+
+/*
+ * $Log$
+ * Revision 1.4 2008/02/07 00:44:07 james
+ * *** empty log message ***
+ *
+ */
+
+#ifndef __KEYS_H__
+#define __KEYS_H__
+
#define KEY_UP 128 /*A*/
#define KEY_DOWN 129 /*B*/
#define KEY_RIGHT 130 /*C*/
#define KEY_188 188 /*8 */
#define KEY_189 189 /*9 */
#define KEY_NUM 190
+#endif /* __KEYS_H__ */
/*
* $Log$
+ * Revision 1.8 2008/02/07 00:43:27 james
+ * *** empty log message ***
+ *
* Revision 1.7 2008/02/07 00:39:13 james
* *** empty log message ***
*
ansi_reset (&a);
- t=tty_new_test();
- v=vt102_new(t);
+ t = tty_new_test ();
+ v = vt102_new (t);
FD_ZERO (&rfd);
for (;;)
{
}
#endif
- if (ansi_dispatch(&a,v))
- break;
+ if (ansi_dispatch (&a, v))
+ break;
- if (FD_ISSET (t->fd, &rfd)) {
- if (vt102_dispatch (v)) break;
- }
+ if (FD_ISSET (t->fd, &rfd))
+ {
+ if (vt102_dispatch (v))
+ break;
+ }
if (had_winch)
{
ansi_reset (&a);
ansi_draw (&a, &v->crt);
}
- ansi_draw (&a, &v->crt);
+ ansi_draw (&a, &v->crt);
}
tcsetattr (0, TCSANOW, &old);
printf ("QUAT\n");
/*
* $Log$
+ * Revision 1.5 2008/02/07 00:39:13 james
+ * *** empty log message ***
+ *
* Revision 1.4 2008/02/06 20:26:58 james
* *** empty log message ***
*
#include <termio.h>
#include <termios.h>
#include <signal.h>
+#include <fcntl.h>
+#include <errno.h>
#include <utmp.h>
#include <pty.h>
/* 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_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);
+int ansi_read (ANSI * a, void *buf, int n);
+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_flush_escape (ANSI * a, VT102 * v);
+void ansi_parse_deckey (ANSI * a, VT102 * v);
+void ansi_parse_ansikey (ANSI * a, VT102 * v);
+void ansi_parse_escape (ANSI * a, VT102 * v);
+void ansi_check_escape (ANSI * a, VT102 * v);
+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);
-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_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);
-int vt102_cursor_home(VT102 *v);
-int vt102_cursor_absolute(VT102 *v, int x, int y);
-int vt102_cursor_relative(VT102 *v, int x, int y);
-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);
+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);
+int vt102_cursor_home (VT102 * v);
+int vt102_cursor_absolute (VT102 * v, int x, int y);
+int vt102_cursor_relative (VT102 * v, int x, int y);
+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);
/* 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);
+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);
/*
* $Log$
+ * Revision 1.2 2008/02/07 00:43:27 james
+ * *** empty log message ***
+ *
* Revision 1.1 2008/02/06 20:26:58 james
* *** empty log message ***
*
#ifndef __TTY_H__
#define __TTY_H__
-typedef struct {
- int fd;
+typedef struct
+{
+ int fd;
} TTY;
#endif /* __TTY_H__ */
/*
* $Log$
+ * Revision 1.15 2008/02/07 00:43:27 james
+ * *** empty log message ***
+ *
* Revision 1.14 2008/02/07 00:40:23 james
* *** empty log message ***
*
{
uint8_t c;
#if 0
- fprintf(stderr,"vts: %d(%c)\n",key,(key>31)?key:' ');
+ fprintf (stderr, "vts: %d(%c)\n", key, (key > 31) ? key : ' ');
#endif
if ((key > 31) && (key < 127))
{
/*
* $Log$
+ * Revision 1.8 2008/02/07 00:39:13 james
+ * *** empty log message ***
+ *
* Revision 1.7 2008/02/06 20:26:58 james
* *** empty log message ***
*
int application_keypad_mode;
- TTY *t;
+ TTY *tty;
} VT102;