chiark / gitweb /
*** empty log message ***
[sympathy.git] / src / ptty.c
index dee241b8c1497c00c210ca728a6abc764089cedc..b59f823e40f8ebc667aacd8ee2208824ef308de5 100644 (file)
@@ -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;
 }