chiark / gitweb /
*** empty log message ***
authorjames <james>
Thu, 28 Feb 2008 22:00:42 +0000 (22:00 +0000)
committerjames <james>
Thu, 28 Feb 2008 22:00:42 +0000 (22:00 +0000)
apps/sympathy.c
src/ansi.c
src/cmd.c
src/keydis.c
src/prototypes.h
sympathy.1
version-md5sums
version-micro
version-stamps

index b5bf326f1395e46d4e17502153690afa49a4393b..23398535369ae2a45c89c41eb9c15fc0cac7e6e1 100644 (file)
@@ -11,6 +11,9 @@ static char rcsid[] =
 
 /*
  * $Log$
+ * Revision 1.24  2008/02/28 22:00:42  james
+ * *** empty log message ***
+ *
  * Revision 1.23  2008/02/28 16:57:51  james
  * *** empty log message ***
  *
@@ -269,6 +272,9 @@ main (int argc, char *argv[])
   extern int optind, opterr, optopt;
   CRT_Pos size = { VT102_COLS_80, VT102_ROWS_24 };
 
+  int csnok_pipe[2] = { 0 };
+  int csnok = 0;
+
   int oflags[128];
   char *oargs[128];
 
@@ -278,7 +284,7 @@ main (int argc, char *argv[])
   Log *log = NULL;
 
   int history = 200;
-
+  int pid;
 
   get_hostname ();
 
@@ -386,43 +392,35 @@ main (int argc, char *argv[])
   if (oflags['p'] && oflags['d'])
     fatal_moan ("-p incompatible with -d");
 
-  /*implement server and client by opening the server socket to prevent */
-  /*a race condition, and then forking and munging the cmd line options */
-  /*in the parent and child so that the child is the server and the */
-  /*parent becomes its client */
 
   if (oflags['c'] && oflags['s'] && oflags['F'])
     fatal_moan ("-F is incompatible with -c -s");
 
-  if (oflags['s'] && !oflags['k'])
-    {
-      char *path;
-      path = mome ("/.sympathy");
-      mkdir (path, 0700);
-      free (path);
-
-      oargs['k'] = mome ("/.sympathy/%s%d", hostname, getpid ());
-      oflags['k']++;
-    }
-
-  if (oflags['s'])
-    {
-      server_socket = socket_listen (oargs['k']);
-      if (!server_socket)
-        fatal_moan ("failed to create socket %s for listening", oargs['k']);
-    }
+  /*implement server and client: this process forks. The parent */
+  /*becomes the client and the child forks again to become the */
+  /*server. If there's no -k argument the client (parent) needs */
+  /*to find out the pid of the server, we use a pipe */
 
   if (oflags['s'] && oflags['c'])
     {
-      switch (fork ())
+      if (!oflags['k'])
+        {
+          csnok++;
+          pipe (csnok_pipe);
+        }
+
+      switch (pid = fork ())
         {
         case 0:                /*child becomes the server */
           oflags['c'] = 0;
           oflags['H'] = 0;
+
+          if (csnok)
+            close (csnok_pipe[0]);
           break;
         case -1:
           fatal_moan ("fork failed");
-        default:
+        default:             /*parent becomes client*/
           oflags['s'] = 0;
           oflags['K'] = 0;
           oflags['d'] = 0;
@@ -432,10 +430,26 @@ main (int argc, char *argv[])
           oflags['L'] = 0;
           oflags['n'] = 0;
           oflags['w'] = 0;
-          if (server_socket)
+
+         /*Collect the child*/
+          waitpid (pid, NULL, 0);
+
+          /*if there was no k argument we need to find the*/
+          /*pid of the server process so that we can work out*/
+          /*what the socket is called. The server tells us on*/
+         /*a pipe*/
+
+          if (csnok)
             {
-              socket_free_parent (server_socket);
-              server_socket = NULL;
+              close (csnok_pipe[1]);
+
+              if (read (csnok_pipe[0], &pid, sizeof (pid)) != sizeof (pid))
+                fatal_moan ("Failed to receive pid of server process");
+
+              close (csnok_pipe[0]);
+
+              oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid);
+              oflags['k']++;
             }
         }
     }
@@ -478,10 +492,41 @@ main (int argc, char *argv[])
 
   if (oflags['s'] && !oflags['F'])
     {
-      daemon (1, 0);            /*incase socket is relative path, unlink then will fail */
+      /*nochdir incase socket is relative path, unlink then will fail */
+      daemon (1, 0);
+
+      /*Tell our parent's parent what our pid is */
+      if (csnok)
+        {
+          pid = getpid ();
+
+          write (csnok_pipe[1], &pid, sizeof (pid));
+          close (csnok_pipe[1]);
+        }
     }
 
 
+  if (oflags['s'] )
+    {
+      char *path;
+      path = mome ("/.sympathy");
+      mkdir (path, 0700);
+      free (path);
+
+
+      if (!oflags['k']) {
+      pid = getpid ();
+       
+      oargs['k'] = mome ("/.sympathy/%s%d", hostname, pid);
+      oflags['k']++;
+       }
+
+      server_socket = socket_listen (oargs['k']);
+      if (!server_socket)
+        fatal_moan ("failed to create socket %s for listening", oargs['k']);
+
+    }
+
   if (oflags['s'] || oflags['t'])
     {
 
index 4113a36b773aa8aeff72dccd8a3d9f023d970026..970d353a2670d874d0f59ce80f04d897bd52da5a 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.36  2008/02/28 22:00:42  james
+ * *** empty log message ***
+ *
  * Revision 1.35  2008/02/28 16:57:51  james
  * *** empty log message ***
  *
@@ -728,6 +731,26 @@ ansi_terminal_reset (ANSI * a)
   ansi_move (a, p);
 }
 
+
+int ansi_key(ANSI *a,Context *c,int key)
+{
+
+  if (!c->d)
+    return c->k->key (c->k, c, key);
+
+  cmd_show_status (c->d, c);
+
+  if (c->d->active)
+    return cmd_key (c->d, c,a, key);
+
+  if (key == CMD_KEY)
+    return cmd_activate (c->d, c);
+
+
+  return c->k->key (c->k, c, key);
+}
+
+
 static void
 ansi_flush_escape (ANSI * a, Context * c)
 {
@@ -736,7 +759,7 @@ ansi_flush_escape (ANSI * a, Context * c)
 
   for (i = 0; i < p->escape_ptr; ++i)
     {
-      keydis_key (c->k, c, p->escape_buf[i]);
+      ansi_key (a, c, p->escape_buf[i]);
     }
 
   p->escape_ptr = 0;
@@ -755,11 +778,11 @@ ansi_parse_deckey (ANSI * a, Context * c)
 
   if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z'))
     {
-      keydis_key (c->k, c, KEY_UP + (p->escape_buf[2] - 'A'));
+      ansi_key (a, c, KEY_UP + (p->escape_buf[2] - 'A'));
     }
   else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z'))
     {
-      keydis_key (c->k, c, KEY_154 + (p->escape_buf[2] - 'a'));
+      ansi_key (a, c, KEY_154 + (p->escape_buf[2] - 'a'));
     }
   else
     {
@@ -782,7 +805,7 @@ ansi_parse_ansikey (ANSI * a, Context * c)
     }
   if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9'))
     {
-      keydis_key (c->k, c, KEY_180 + (p->escape_buf[2] - '0'));
+      ansi_key (a, c, KEY_180 + (p->escape_buf[2] - '0'));
     }
   else
     {
@@ -895,7 +918,7 @@ ansi_parse_char (ANSI * a, Context * c, int ch)
     }
   else
     {
-      keydis_key (c->k, c, ch);
+      ansi_key (a, c, ch);
     }
 
 }
index 7e86977a7e1c7a2e2d4e96305aa8b0c44124babf..34dc2f4e54bd42db849423094d2deb3a86f239c3 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.7  2008/02/28 22:00:42  james
+ * *** empty log message ***
+ *
  * Revision 1.6  2008/02/28 16:57:51  james
  * *** empty log message ***
  *
@@ -34,7 +37,7 @@ static char rcsid[] = "$Id$";
 
 
 int
-cmd_parse (Cmd * c, Context * ctx, char *buf)
+cmd_parse (Cmd * c, Context * ctx,ANSI *a, char *buf)
 {
   if (!strcmp (buf, "quit"))
     c->disconnect++;
@@ -54,6 +57,11 @@ cmd_parse (Cmd * c, Context * ctx, char *buf)
     ctx->k->hangup (ctx->k, ctx);
   else if (!strcmp (buf, "reset"))
     ctx->k->reset (ctx->k, ctx);
+  else if (!strcmp (buf, "expand")) {
+       int w=a->terminal->size.x;
+       int h=a->terminal->size.y-1;
+    ctx->k->set_size (ctx->k, ctx, w,h);
+  }
   else if (!strncmp (buf, "width", 5))
     ctx->k->set_size (ctx->k, ctx, atoi (buf + 5), 0);
   else if (!strncmp (buf, "height", 6))
@@ -82,7 +90,7 @@ cmd_show_status (Cmd * c, Context * ctx)
 }
 
 int
-cmd_key (Cmd * c, Context * ctx, int key)
+cmd_key (Cmd * c, Context * ctx,ANSI *a, int key)
 {
 
   if (c->error)
@@ -95,7 +103,7 @@ cmd_key (Cmd * c, Context * ctx, int key)
 
   if (key == 13)
     {
-      if (cmd_parse (c, ctx, c->buf + 1))
+      if (cmd_parse (c, ctx, a,c->buf + 1))
         {
           c->error++;
         }
index c6e4db2362decb599f8d27ca939ae4301e1c8ee2..a288347df4905e1b65dfaa83d60b3638e76356ab 100644 (file)
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
 
 /*
  * $Log$
+ * Revision 1.9  2008/02/28 22:00:42  james
+ * *** empty log message ***
+ *
  * Revision 1.8  2008/02/28 16:57:52  james
  * *** empty log message ***
  *
@@ -276,6 +279,7 @@ keydis_ipc_new (Socket * s)
 
 
 
+#if 0
 int
 keydis_key (KeyDis * t, Context * c, int key)
 {
@@ -294,3 +298,4 @@ keydis_key (KeyDis * t, Context * c, int key)
 
   return t->key (t, c, key);
 }
+#endif
index e96cb1bd39c95f46e3ea119bcc6138da7f26ea46..c3787644d521508b23a5fefb610fb030de9772a9 100644 (file)
@@ -1,4 +1,5 @@
 /* ansi.c */
+extern int ansi_key(ANSI *a, Context *c, int key);
 extern int ansi_dispatch(ANSI *a, Context *c);
 extern ANSI *ansi_new_from_terminal(TTY *t, int utf8);
 /* crt.c */
@@ -66,6 +67,7 @@ extern void tty_set_baud(TTY *t, int rate);
 extern void tty_send_break(TTY *t);
 extern void tty_set_flow(TTY *t, int flow);
 extern void tty_hangup(TTY *t);
+extern void tty_length(TTY *t, int l);
 extern void tty_winch(TTY *t, CRT_Pos size);
 extern void tty_parse_reset(Context *c);
 extern void tty_analyse(Context *c);
@@ -74,7 +76,6 @@ extern void tty_parse(Context *c, uint8_t *buf, int len);
 /* keydis.c */
 extern KeyDis *keydis_vt102_new(void);
 extern KeyDis *keydis_ipc_new(Socket *s);
-extern int keydis_key(KeyDis *t, Context *c, int key);
 /* history.c */
 extern History *history_new(int n);
 extern void history_free(History *h);
@@ -143,9 +144,8 @@ extern int socket_write(Socket *s, void *buf, int len);
 /* serial.c */
 extern TTY *serial_open(char *path, int lock_mode);
 /* cmd.c */
-extern int cmd_parse(Cmd *c, Context *ctx, char *buf);
+extern int cmd_parse(Cmd *c, Context *ctx, ANSI *a, char *buf);
 extern void cmd_show_status(Cmd *c, Context *ctx);
-extern int cmd_key(Cmd *c, Context *ctx, int key);
 extern int cmd_activate(Cmd *c, Context *ctx);
 extern void cmd_new_status(Cmd *c, Context *ctx, char *msg);
 extern Cmd *cmd_new(void);
index f7b34b43e0a091efbb32e0e87a7971be0911b291..7a7e436277d35b8335104133fc47508b8667c1af 100644 (file)
@@ -181,7 +181,7 @@ log activity to the file \fIlogfile\fP. If \fIlogfile\fP is `-' then log to \fIs
 that logging to \fIstdout\fP only makes sense with the \-\fBF\fP \fIserver_option\fP. 
 .TP 5
 .B \-w \fIwidth\fP[x\fIheight\fP]
-set the initialise size of the terminal emulator's frame buffer to be \fIwidth\fP columns
+set the initial size of the terminal emulator's frame buffer to be \fIwidth\fP columns
 by \fIheight\fP rows. If \fIheight\fP is omitted it defaults to 24, the default width
 is 80. These values may
 be overridden later by terminal escape sequences. If \-\fBp\fP is also specified
@@ -345,6 +345,9 @@ set the current height of the screen to \fInn\fP, and reset the terminal emulato
 .B reset
 reset the terminal emulator
 .TP 7
+.B expand
+expand the size of the screen to fit the size of the current outer terminal emulator window
+.TP 7
 .B quit
 exit this instance of sympathy (disconnect from the server if present)
 .SH CHARACTER ENCODINGS
index 08fdf3454faf21c040bef0d08115e52057c44e36..a0fd8246e7d540c600ca84c196947ce02ae723a0 100644 (file)
@@ -10,3 +10,4 @@ f844259e45d571cf913580d8851ee261      1.1.3
 0baf4bcc06f0271dba444738df2ef1e3       1.1.6
 30b3685c955c05efa7ba0affb9fbca1a       1.1.7
 b9ef98229248516850808e590721c0e5       1.1.8
+a5ee6f647e6d98d5f06b75a70b7bf9a5       1.1.9
index 45a4fb75db864000d01701c0f7a51864bd4daabf..ec635144f60048986bc560c5576355344005e6e7 100644 (file)
@@ -1 +1 @@
-8
+9
index 9a07f4920d0b2ff45420932c6e912fe6446f1291..3e0ada77e4888dff6ff158a2cac8e2db8f13cbac 100644 (file)
@@ -3,3 +3,4 @@
 0baf4bcc06f0271dba444738df2ef1e3       "February 28, 2008"
 30b3685c955c05efa7ba0affb9fbca1a       "February 28, 2008"
 b9ef98229248516850808e590721c0e5       "February 28, 2008"
+a5ee6f647e6d98d5f06b75a70b7bf9a5       "February 28, 2008"