From: james Date: Thu, 7 Feb 2008 00:39:13 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c41d259a13d31aa9a1698ef5f22e06d2694ba85e;p=sympathy.git *** empty log message *** --- diff --git a/src/Makefile.am b/src/Makefile.am index 1c63eaf..a163fd0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,9 @@ # $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 *** # @@ -20,7 +23,7 @@ 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} diff --git a/src/ansi.c b/src/ansi.c index 16d9970..cf92e71 100644 --- a/src/ansi.c +++ b/src/ansi.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $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 *** * @@ -56,26 +59,29 @@ set_blocking (int fd) } -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); } @@ -377,176 +383,206 @@ ansi_reset (ANSI * a) 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;iescape_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; } diff --git a/src/ansi.h b/src/ansi.h index 1b84ddc..bc24524 100644 --- a/src/ansi.h +++ b/src/ansi.h @@ -12,6 +12,9 @@ /* * $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 *** * @@ -29,13 +32,14 @@ #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 diff --git a/src/keys.h b/src/keys.h index 93b27f9..1e6c062 100644 --- a/src/keys.h +++ b/src/keys.h @@ -1,3 +1,25 @@ +/* + * src/keys.h: + * + * Copyright (c) 2008 James McKenzie , + * 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*/ @@ -61,3 +83,4 @@ #define KEY_188 188 /*8 */ #define KEY_189 189 /*9 */ #define KEY_NUM 190 +#endif /* __KEYS_H__ */ diff --git a/src/libsympathy.c b/src/libsympathy.c index 8f28c17..5ffd04d 100644 --- a/src/libsympathy.c +++ b/src/libsympathy.c @@ -11,6 +11,9 @@ static char rcsid[] = /* * $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 *** * @@ -85,8 +88,8 @@ testy (void) ansi_reset (&a); - t=tty_new_test(); - v=vt102_new(t); + t = tty_new_test (); + v = vt102_new (t); FD_ZERO (&rfd); for (;;) @@ -102,12 +105,14 @@ testy (void) { } #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) { @@ -116,7 +121,7 @@ testy (void) 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"); diff --git a/src/project.h b/src/project.h index 259bb6a..e7ed065 100644 --- a/src/project.h +++ b/src/project.h @@ -12,6 +12,9 @@ /* * $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 *** * @@ -72,6 +75,8 @@ #include #include #include +#include +#include #include #include diff --git a/src/prototypes.h b/src/prototypes.h index 5bbd01a..9418624 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -1,70 +1,76 @@ /* 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); diff --git a/src/tty.h b/src/tty.h index 14a791b..1da8339 100644 --- a/src/tty.h +++ b/src/tty.h @@ -12,6 +12,9 @@ /* * $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 *** * @@ -20,8 +23,9 @@ #ifndef __TTY_H__ #define __TTY_H__ -typedef struct { - int fd; +typedef struct +{ + int fd; } TTY; #endif /* __TTY_H__ */ diff --git a/src/vt102.c b/src/vt102.c index 25d7187..301e224 100644 --- a/src/vt102.c +++ b/src/vt102.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $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 *** * @@ -1052,7 +1055,7 @@ vt102_send (VT102 * v, uint8_t key) { 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)) { diff --git a/src/vt102.h b/src/vt102.h index 2fa56e6..fcf7aca 100644 --- a/src/vt102.h +++ b/src/vt102.h @@ -12,6 +12,9 @@ /* * $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 *** * @@ -82,7 +85,7 @@ typedef struct int application_keypad_mode; - TTY *t; + TTY *tty; } VT102;