From: james Date: Mon, 4 Feb 2008 02:05:06 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=sympathy.git;a=commitdiff_plain;h=51d34367859892cb87c8727d93a02ed9f82fe958 *** empty log message *** --- diff --git a/src/ansi.c b/src/ansi.c index 5d6105e..49a7bc9 100644 --- a/src/ansi.c +++ b/src/ansi.c @@ -10,10 +10,14 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.2 2008/02/04 02:05:06 james + * *** empty log message *** + * * Revision 1.1 2008/02/03 23:31:25 james * *** empty log message *** * */ +#include "project.h" void ansi_write (ANSI * a, char *buf, int n) @@ -131,60 +135,62 @@ ansi_showhide_cursor (ANSI * a, int hide) } -void ansi_force_attr_normal(ANSI *a) +void +ansi_force_attr_normal (ANSI * a) { ansi_write (a, "\033[0m", 4); - a->attr=CRT_ATTR_NORMAL; + a->attr = CRT_ATTR_NORMAL; } void ansi_set_attr (ANSI * a, int attr) { + int dif; dif = attr ^ a->attr; if (!dif) return; - if (attr == ATTR_NORMAL) + if (attr == CRT_ATTR_NORMAL) { - ansi_force_attr_normal(a); - return; + ansi_force_attr_normal (a); + return; } - if (dif & CRT_ATTR_UNDERLINE) + if (dif & CRT_ATTR_UNDERLINE) + { + if (attr & CRT_ATTR_UNDERLINE) { - if (attr & CRT_ATTR_UNDERLINE) - { - ansi_write (a, "\033[4m", 4); - } - else - { - ansi_write (a, "\033[24m", 5); - } + ansi_write (a, "\033[4m", 4); } - if (dif & CRT_ATTR_REVERSE) + else { - if (attr & CRT_ATTR_REVERSE) - { - ansi_write (a, "\033[7m", 4); - } - else - { - ansi_write (a, "\033[27m", 5); - } + ansi_write (a, "\033[24m", 5); + } + } + if (dif & CRT_ATTR_REVERSE) + { + if (attr & CRT_ATTR_REVERSE) + { + ansi_write (a, "\033[7m", 4); } - if (dif & CRT_ATTR_BOLD) + else { - if (attr & CRT_ATTR_REVERSE) - { - ansi_write (a, "\033[1m", 4); - } - else - { - ansi_write (a, "\033[22m", 5); - } + ansi_write (a, "\033[27m", 5); } + } + if (dif & CRT_ATTR_BOLD) + { + if (attr & CRT_ATTR_REVERSE) + { + ansi_write (a, "\033[1m", 4); + } + else + { + ansi_write (a, "\033[22m", 5); + } + } } @@ -218,7 +224,7 @@ ansi_cls (ANSI * a) CRT_Pos p = { 0 }; crt_cls (&a->crt); - ansi_force_attr_normal(a); + ansi_force_attr_normal (a); ansi_move (a, p); ansi_write (a, "\033[2J", 4); /*different emulators leave cursor in different places after cls differently*/ @@ -238,17 +244,17 @@ ansi_draw (ANSI * a, CRT * c) { if (p.y >= a->size.y) continue; - o = CRT_ADDR (r, 0); + o = CRT_ADDR (p.y, 0); for (p.x = 0; p.x < CRT_COLS; ++p.x, ++o) { if (p.x >= a->size.x) continue; - if (crt_ca_cmp (a->crt.screen[p], c->screen[p])) + if (crt_ca_cmp (a->crt.screen[o], c->screen[o])) { - a->crt.screen[p] = c->screen[p]; + a->crt.screen[o] = c->screen[o]; ansi_move (a, p); - ansi_render (a, a->crt.screen[p]); + ansi_render (a, a->crt.screen[o]); } } } @@ -257,7 +263,7 @@ ansi_draw (ANSI * a, CRT * c) ansi_move (a, a->crt.pos); a->crt.hide_cursor = c->hide_cursor; - ansi_showhide_cursor (a, ci->crt.hide_cursor); + ansi_showhide_cursor (a, a->crt.hide_cursor); } void diff --git a/src/crt.c b/src/crt.c index 24c0f02..8b7f9d5 100644 --- a/src/crt.c +++ b/src/crt.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.2 2008/02/04 02:05:06 james + * *** empty log message *** + * * Revision 1.1 2008/02/03 23:31:25 james * *** empty log message *** * @@ -17,35 +20,42 @@ static char rcsid[] = "$Id$"; #include "project.h" -void crt_cls(CRT *c) +void +crt_cls (CRT * c) { -int i; + int i; -for (i=0;iscreen[i].chr=' '; - c->screen[i].chr=CRT_ATTR_NORMAL; -} + for (i = 0; i < CRT_CELS; ++i) + { + c->screen[i].chr = ' '; + c->screen[i].chr = CRT_ATTR_NORMAL; + } } -void crt_reset(CRT *c) +void +crt_reset (CRT * c) { -crt_cls(c); + crt_cls (c); -crt->pos.x=0; -crt->pos.y=0; -crt->hide_cursor=1; + c->pos.x = 0; + c->pos.y = 0; + c->hide_cursor = 1; } -void crt_insert(CRT *c,CRT_CA ca) +void +crt_insert (CRT * c, CRT_CA ca) { -if (c->pos.x<0) c->pos.x=0; -if (c->pos.x>=CRT_COLS) c->pos.x=CRT_COLS-1; -if (c->pos.y<0) c->pos.y=0; -if (c->pos.y>=CRT_ROWS) c->pos.y=CRT_ROWS-1; + if (c->pos.x < 0) + c->pos.x = 0; + if (c->pos.x >= CRT_COLS) + c->pos.x = CRT_COLS - 1; + if (c->pos.y < 0) + c->pos.y = 0; + if (c->pos.y >= CRT_ROWS) + c->pos.y = CRT_ROWS - 1; -crt->screen[CRT_ADDR(c->pos.y,c->pos.x)]=ca; + c->screen[CRT_ADDR (c->pos.y, c->pos.x)] = ca; } - diff --git a/src/html.c b/src/html.c index 5f48fe3..db142a9 100644 --- a/src/html.c +++ b/src/html.c @@ -10,11 +10,16 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.2 2008/02/04 02:05:06 james + * *** empty log message *** + * * Revision 1.1 2008/02/03 23:31:25 james * *** empty log message *** * */ +#include "project.h" + void html_entity (FILE * f, int c) { diff --git a/src/libsympathy.c b/src/libsympathy.c index 40f8a9d..d43bbc5 100644 --- a/src/libsympathy.c +++ b/src/libsympathy.c @@ -6,10 +6,14 @@ * */ -static char rcsid[] = "$Id$"; +static char rcsid[] = + "$Id$"; /* * $Log$ + * Revision 1.2 2008/02/04 02:05:06 james + * *** empty log message *** + * * Revision 1.1 2008/02/03 16:20:24 james * *** empty log message *** * @@ -17,4 +21,3 @@ static char rcsid[] = "$Id$"; */ #include "project.h" - diff --git a/src/project.h b/src/project.h index 079f38a..9ce651f 100644 --- a/src/project.h +++ b/src/project.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.2 2008/02/04 02:05:06 james + * *** empty log message *** + * * Revision 1.1 2008/02/03 16:20:24 james * *** empty log message *** * @@ -60,6 +63,13 @@ #include #endif +#include +#include + +#include "crt.h" +#include "ansi.h" +#include "vt102.h" + #include "prototypes.h" #endif /* __PROJECT_H__ */ diff --git a/src/render.c b/src/render.c index 6ef0e67..52fa0ff 100644 --- a/src/render.c +++ b/src/render.c @@ -10,19 +10,10 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.2 2008/02/04 02:05:06 james + * *** empty log message *** + * * Revision 1.1 2008/02/03 23:31:25 james * *** empty log message *** * */ - - - - - - - - - -} - - diff --git a/src/testtty.c b/src/testtty.c index 2cef3e0..dbdc918 100644 --- a/src/testtty.c +++ b/src/testtty.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * 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 *** * @@ -17,60 +20,63 @@ static char rcsid[] = "$Id$"; #include "project.h" -static void default_termios(struct termios *termios) +static void +default_termios (struct termios *termios) { -memset(termios,0,sizeof(termios)); - -termios->c_iflag=ICRNL|IXON; -termios->c_oflag=OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0; -termios->c_lflag=ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE; - -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; - -cfsetispeed(termios,B9600); -cfsetospeed(termios,B9600); + memset (termios, 0, sizeof (termios)); + + termios->c_iflag = ICRNL | IXON; + termios->c_oflag = OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0; + termios->c_lflag = + ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE; + + 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; + + cfsetispeed (termios, B9600); + cfsetospeed (termios, B9600); } -int open_fd_to_bash(void) /*thump*/ +int +open_fd_to_bash (void) /*thump */ { -pid_t child; -int fd; -struct winsize winsize={0}; -struct termios termios; + pid_t child; + int fd; + struct winsize winsize = { 0 }; + struct termios termios; -default_termios(&termios); + default_termios (&termios); -winsize.ws_row=CRT_ROWS; -winsize.ws_col=CRT_COLS; + winsize.ws_row = CRT_ROWS; + winsize.ws_col = CRT_COLS; -child=forkpty(&fd,NULL,&termios,&winsize); + child = forkpty (&fd, NULL, &termios, &winsize); -switch (child) -{ -case -1:/*boo hiss*/ - return -1; -case 0: /*waaah*/ - setenv("TERM","vt102",1); - execl("/bin/sh","-",(char *) 0); - _exit(-1); -} + switch (child) + { + case -1: /*boo hiss */ + return -1; + case 0: /*waaah */ + setenv ("TERM", "vt102", 1); + execl ("/bin/sh", "-", (char *) 0); + _exit (-1); + } -return fd; + return fd; } diff --git a/src/version.c b/src/version.c index 244ade0..651093d 100644 --- a/src/version.c +++ b/src/version.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.2 2008/02/04 02:05:06 james + * *** empty log message *** + * * Revision 1.1 2008/02/03 16:20:24 james * *** empty log message *** * @@ -19,7 +22,7 @@ static char rcsid[] = "$Id$"; #include "version.h" static char * -GetVersion(void) +GetVersion (void) { return VERSION; } diff --git a/src/vt102.c b/src/vt102.c index eb365da..8a7dc56 100644 --- a/src/vt102.c +++ b/src/vt102.c @@ -10,6 +10,9 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.3 2008/02/04 02:05:06 james + * *** empty log message *** + * * Revision 1.2 2008/02/04 01:32:39 james * *** empty log message *** * @@ -104,6 +107,8 @@ ESC[?8h */ +#include "project.h" + static inline int csi_ender (int c) @@ -128,63 +133,74 @@ csi_starter (int c) return 0; } -void vt102_cursor_normalize(VT102 *v,int wrap,int scroll) +void +vt102_cursor_normalize (VT102 * v, int wrap, int scroll) { - if (v->pos.x<-1) /*don't wrap backwards*/ - c->pos.x=0; - - if (v->pos.x>=CRT_COLS) { - if (wrap) { - c->pos.x=0; - c->pos.y++; - } else { - c->pos.x=CRT_COLS-1; - } - } - - if (v->pos.y<0) - c->pos.y=0 - - if (v->pos.y>=CRT_ROWS) { - if (scroll) - vt102_scroll(v,0,CRT_ROWS-1); - c->pos.y=CRT_ROWS-1; - } + if (v->pos.x < -1) /*don't wrap backwards */ + v->pos.x = 0; + + if (v->pos.x >= CRT_COLS) + { + if (wrap) + { + v->pos.x = 0; + v->pos.y++; + } + else + { + v->pos.x = CRT_COLS - 1; + } + } + + if (v->pos.y < 0) + v->pos.y = 0; + + if (v->pos.y >= CRT_ROWS) + { + if (scroll) + vt102_scroll (v, 0, CRT_ROWS - 1); + v->pos.y = CRT_ROWS - 1; + } } - -void vt102_cursor_motion(VT102 *v,int x,int y,int wrap,scroll) + +void +vt102_cursor_motion (VT102 * v, int x, int y, int wrap, int scroll) { -while (x>0) { - x--; - v->pos.x++; - vt102_cursor_normalize(v,wrap,scroll); -} - -while (x<0) { - x++; - v->pos.x--; - vt102_cursor_normalize(v,wrap,scroll); -} - -while (y>0) { - y--; - v->pos.y++; - vt102_cursor_normalize(v,wrap,scroll); -} - -while (y<0) { - y++; - v->pos.y--; - vt102_cursor_normalize(v,wrap,scroll); + while (x > 0) + { + x--; + v->pos.x++; + vt102_cursor_normalize (v, wrap, scroll); + } + + while (x < 0) + { + x++; + v->pos.x--; + vt102_cursor_normalize (v, wrap, scroll); + } + + while (y > 0) + { + y--; + v->pos.y++; + vt102_cursor_normalize (v, wrap, scroll); + } + + while (y < 0) + { + y++; + v->pos.y--; + vt102_cursor_normalize (v, wrap, scroll); + } } -} void vt102_parse_char (VT102 * v, int c) { - VT102_parser *p = &v->p; + VT102_parser *p = &v->parser; if (p->in_csi) @@ -225,27 +241,27 @@ vt102_parse_char (VT102 * v, int c) /*ACK*/ case 6: /*BEL*/ case 7: /*BS*/ case 8: - vt102_cursor_motion(v,-1,0,0,0); + vt102_cursor_motion (v, -1, 0, 0, 0); break; /*HT*/ case 9: break; /*LF*/ case 10: - vt102_cursor_motion(v,0,1,0,1); + vt102_cursor_motion (v, 0, 1, 0, 1); break; /*VT*/ case 11: break; /*FF*/ case 12: break; /*CR*/ case 13: - v->pos.x=0; + v->pos.x = 0; break; /*SO*/ case 14: /*SI*/ case 15: /*DLE*/ case 16: - /*DC1*/ case 17: - /*DC2*/ case 18: - /*DC3*/ case 19: - /*DC4*/ case 20: + /*DC1 */ case 17: + /*DC2 */ case 18: + /*DC3 */ case 19: + /*DC4 */ case 20: /*NAK*/ case 21: /*SYN*/ case 22: /*ETB*/ case 23: @@ -262,10 +278,10 @@ vt102_parse_char (VT102 * v, int c) /*US*/ case 31: /*DEL*/ case 127: break; - /*regular character*/ default: - v->crt->screen[CRT_ADDR_POS(&v->pos)].chr=c; - v->crt->screen[CRT_ADDR_POS(&v->pos)].attr=v->attr; - vt102_cursor_motion(v,1,0); + /*regular character */ default: + v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = c; + v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr; + vt102_cursor_motion (v, 1, 0, 1, 1); } } } diff --git a/src/vt102.h b/src/vt102.h index e5b62a5..5a2d686 100644 --- a/src/vt102.h +++ b/src/vt102.h @@ -12,6 +12,9 @@ /* * $Log$ + * Revision 1.2 2008/02/04 02:05:06 james + * *** empty log message *** + * * Revision 1.1 2008/02/03 23:36:41 james * *** empty log message *** * @@ -32,13 +35,10 @@ typedef struct typedef struct { - VT102_parser p; + VT102_parser parser; int attr; CRT crt; - CRT_Pos p; - - - + CRT_Pos pos; } VT102;