X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=sympathy.git;a=blobdiff_plain;f=src%2Fptty.c;h=c0f85f5689e647e7f1afc8e8a62e1d5c33222dc5;hp=dee241b8c1497c00c210ca728a6abc764089cedc;hb=940f48e7089157e6ffae29936226ade7b1176b02;hpb=b1f5cc058d5f2880b75b7af5dcc746942c2d7279 diff --git a/src/ptty.c b/src/ptty.c index dee241b..c0f85f5 100644 --- a/src/ptty.c +++ b/src/ptty.c @@ -10,6 +10,12 @@ static char rcsid[] = "$Id$"; /* * $Log$ + * Revision 1.3 2008/02/13 09:12:21 james + * *** empty log message *** + * + * 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 +39,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 +64,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 +91,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 +112,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,47 +121,49 @@ 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 }; + + + default_termios (&termios); + + winsize.ws_row = VT102_ROWS; + winsize.ws_col = VT102_COLS; child = forkpty (&fd, name, &termios, &winsize); switch (child) { case -1: /*boo hiss */ - return -1; + return NULL; 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)); - - strncpy(t->name,name,sizeof(t->name)); - t->name[sizeof(t->name)-1]=0; + t = (PTTY *) malloc (sizeof (PTTY)); - 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; + strncpy (t->name, name, sizeof (t->name)); + t->name[sizeof (t->name) - 1] = 0; - t->fd = open_fd_to_pty (path,argv); - t->pid=child; - t->rfd=t->fd; - t->wfd=0; + t->recv = ptty_read; + t->xmit = ptty_write; + t->close = ptty_close; + t->fd = fd; + t->child = child; + t->rfd = t->fd; + t->wfd = t->fd; + t->size.x = winsize.ws_row; + t->size.y = winsize.ws_col; return (TTY *) t; }