chiark / gitweb /
*** empty log message ***
[sympathy.git] / apps / mainloop.c
index f515478810cf824ca0fb9ce251c025019ac41a5e..fd2947f8af97729d5fa382f988cb4eba0e69d43c 100644 (file)
@@ -10,6 +10,12 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.5  2008/02/20 18:31:44  james
+ * *** empty log message ***
+ *
+ * Revision 1.4  2008/02/20 17:18:33  james
+ * *** empty log message ***
+ *
  * Revision 1.3  2008/02/20 02:11:35  james
  * *** empty log message ***
  *
@@ -59,8 +65,8 @@ static char rcsid[] = "$Id$";
 
 #include <sys/time.h>
 #include <sympathy.h>
+#include "mainloop.h"
 
-#include "client.h"
 #include "clients.h"
 
 typedef struct
@@ -230,11 +236,11 @@ check_status (Context * c, Clients * cs)
   status = get_status (c->t, cs);
   if (!memcmp (&status, &old_status, sizeof (status)))
     return;
-  old_status = status;
-
 
   log_line_changes (c, old_status.lines, status.lines);
 
+  old_status = status;
+
   ptr += sprintf (ptr, "CTRL-B ");
 
   t = c->t->name;
@@ -290,7 +296,7 @@ check_status (Context * c, Clients * cs)
   if (cs)
     send_status (cs, buf);
   else
-    cmd_new_status (c->d, c, m->status.status);
+    cmd_new_status (c->d, c, buf);
 
 }
 
@@ -314,7 +320,7 @@ msg_from_server (IPC_Msg * m, Context * c)
         abort ();
 
       *(c->v) = m->vt102.vt102;
-       //FIXME HTML hook
+      //FIXME HTML hook
       break;
     case IPC_MSG_TYPE_TERM:
       vt102_parse (c, m->term.term, m->term.len);
@@ -329,23 +335,22 @@ msg_from_server (IPC_Msg * m, Context * c)
 
 
 void
-mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, Ansi * a,
-          Log * log)
+mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
+          ANSI * ansi, Log * log, int nhistory)
 {
   fd_set rfds, wfds;
-  Context c;
+  Context c = { 0 };
   Clients *clients;
 
 
   c.v = vt102_new ();
-  c.h = history_new (200);
-  c.l = log
-    /* are we being fed by a tty or a socket */
-    if (client_socket)
+  c.h = history_new (nhistory);
+  c.l = log;
+  /* are we being fed by a tty or a socket */
+  if (client_socket)
     {
       if (server_socket)
         abort ();
-      c.s = client_socket;
       c.k = keydis_ipc_new (client_socket);
     }
   else
@@ -383,8 +388,12 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, Ansi * a,
     {
       struct timeval tv = { 1, 0 };
 
-      /*update the status lines, locally or remotely*/
-      check_status (&c, clients);
+      if ((c.d) && (c.d->disconnect))
+        break;
+
+      /*update the status lines, locally or remotely */
+      if (c.t)
+        check_status (&c, clients);
 
       FD_ZERO (&rfds);
       FD_ZERO (&wfds);
@@ -411,7 +420,7 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, Ansi * a,
         {
           Socket *new_client_socket;
           if (FD_ISSET (server_socket->fd, &rfds)
-              && ((new_client_socket = socket_accept (s))))
+              && ((new_client_socket = socket_accept (server_socket))))
             {
               {
                 Client *new_client;
@@ -441,14 +450,15 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, Ansi * a,
 
           if (red)
             {
-              send_output (clients, buf, red);
+              if (clients)
+                send_output (clients, buf, red);
               vt102_parse (&c, buf, red);
             }
         }
 
 
 
-      /*any data from the server*/
+      /*any data from the server */
       if (client_socket)
         {
           if (socket_post_select (client_socket, &rfds, &wfds))
@@ -462,7 +472,7 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, Ansi * a,
         }
 
 
-      /*update our local screen*/
+      /*update our local screen */
       if (ansi)
         {
           if (ansi_dispatch (ansi, &c))
@@ -473,8 +483,5 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket, Ansi * a,
     }
 
   if (clients)
-    {
-      clients_shutdown (clients);
-    }
-  printf ("QUAT\n");
+    clients_shutdown (clients);
 }