chiark / gitweb /
*** empty log message ***
[sympathy.git] / apps / sympathy.c
index 29cf0ace8f1c5fffb29405b44020d99a069b554e..e93c9302398df284a2cbbcee273c7abe6ac5678d 100644 (file)
@@ -6,10 +6,41 @@
  *
  */
 
-static char rcsid[] = "$Id$";
+static char rcsid[] =
+  "$Id$";
 
 /*
  * $Log$
+ * Revision 1.17  2008/02/27 09:42:21  james
+ * *** empty log message ***
+ *
+ * Revision 1.16  2008/02/27 01:31:38  james
+ * *** empty log message ***
+ *
+ * Revision 1.15  2008/02/27 01:31:14  james
+ * *** empty log message ***
+ *
+ * Revision 1.14  2008/02/24 00:43:55  james
+ * *** empty log message ***
+ *
+ * Revision 1.13  2008/02/24 00:42:53  james
+ * *** empty log message ***
+ *
+ * Revision 1.12  2008/02/23 11:48:52  james
+ * *** empty log message ***
+ *
+ * Revision 1.11  2008/02/20 20:16:07  james
+ * *** empty log message ***
+ *
+ * Revision 1.10  2008/02/20 19:44:37  james
+ * @@
+ *
+ * Revision 1.9  2008/02/20 18:49:11  staffcvs
+ * *** empty log message ***
+ *
+ * Revision 1.8  2008/02/20 18:33:37  james
+ * *** empty log message ***
+ *
  * Revision 1.7  2008/02/20 18:31:44  james
  * *** empty log message ***
  *
@@ -40,6 +71,9 @@ static char rcsid[] = "$Id$";
 #include <sys/utsname.h>
 #include <sys/stat.h>
 #include <dirent.h>
+#include <string.h>
+#include <strings.h>
+#include <malloc.h>
 
 #include "mainloop.h"
 
@@ -214,6 +248,7 @@ main (int argc, char *argv[])
   int c;
   extern char *optarg;
   extern int optind, opterr, optopt;
+  CRT_Pos size={VT102_COLS_80,VT102_ROWS};
 
   int oflags[128];
   char *oargs[128];
@@ -230,16 +265,7 @@ main (int argc, char *argv[])
 
   memset (oflags, 0, sizeof (oflags));
   memset (oargs, 0, sizeof (oargs));
-#if 0
-  "sympathy -t      [-K] [-d serialdev|-p] [-b baud] [-f] [-L log]\n"
-    "sympathy -s      [-K] [-d serialdev|-p] [-b baud] [-f] [-L log] [-F] [-k skt]\n"
-    "                      [-n hlines]\n"
-    "sympathy [-s -c] [-K] [-d serialdev|-p] [-b baud] [-f] [-L log] [-k skt]\n"
-    "                      [-n hlines]\n"
-    "sympathy -c      [-H] -k skt\n"
-    "sympathy -r id   [-H]\n" "sympathy {-l|-ls}\n"
-#endif
-    while ((c = getopt (argc, argv, "tscr:lKHd:pb:fL:Fk:n:")) != EOF)
+  while ((c = getopt (argc, argv, "vw:utscr:lKHd:pb:fL:Fk:n:")) != EOF)
     {
       switch (c)
         {
@@ -287,11 +313,16 @@ main (int argc, char *argv[])
     sum += (oflags['s'] || oflags['c']) ? 1 : 0;
     sum += oflags['r'];
     sum += oflags['l'];
+    sum += oflags['v'];
 
     if (sum != 1)
-      fatal_moan ("specifiy exactly one of ( -c and or -s ), -t, -r and -l");
+      fatal_moan ("specifiy exactly one of ( -c and or -s ), -t, -r, -l and -v");
   }
 
+  if (oflags['v']) {
+       fprintf("Version: %s\n",libsympathy_version());
+       return 0;
+  }
 
   if (oflags['l'])
     return list_sockets ();
@@ -303,11 +334,11 @@ main (int argc, char *argv[])
 
   if (oflags['n'])
     {
-      nhistory = safe_atoi (oargs['n']);
-      if (nhistory < 0)
+      history = safe_atoi (oargs['n']);
+      if (history < 0)
         fatal_moan ("cannot parse -n %s as an integer", oargs['n']);
 
-      if (!nhistory)
+      if (!history)
         fatal_moan ("agrument to -n must be greater than zero");
     }
 
@@ -372,6 +403,7 @@ main (int argc, char *argv[])
           oflags['f'] = 0;
           oflags['L'] = 0;
           oflags['n'] = 0;
+          oflags['w'] = 0;
           if (server_socket)
             {
               socket_free_parent (server_socket);
@@ -380,6 +412,7 @@ main (int argc, char *argv[])
         }
     }
 
+
   if (oflags['c'] && !oflags['k'])
     fatal_moan ("-c requires a socket to be specified with -s or -k");
 
@@ -393,6 +426,31 @@ main (int argc, char *argv[])
         oflags['p']++;
     }
 
+  if (oflags['w'])
+    {
+       char buf[128],*ptr;
+       strcpy(buf,oargs['w']);
+       ptr=index(buf,'x');
+       if (ptr) {
+               *ptr=0;
+               ptr++;
+               size.y=safe_atoi(ptr);
+       }
+       size.x=safe_atoi(buf);  
+
+      if ((size.x > VT102_MAX_COLS) || (size.x < 1))
+        fatal_moan ("-w requires a width between 1 and %d\n", VT102_MAX_COLS);
+
+      if ((size.y > VT102_ROWS) || (size.y < 1))
+        fatal_moan ("-w requires a height between 1 and %d\n", VT102_MAX_COLS);
+       
+    }
+
+  if (oflags['s'] && !oflags['F'])
+    {
+      daemon (1, 0);            /*incase socket is relative path, unlink then will fail */
+    }
+
 
   if (oflags['s'] || oflags['t'])
     {
@@ -406,7 +464,7 @@ main (int argc, char *argv[])
 
       if (oflags['p'])
         {
-          tty = ptty_open (NULL, NULL);
+          tty = ptty_open (NULL, NULL, &size);
           if (!tty)
             fatal_moan ("unable to open a ptty");
         }
@@ -445,34 +503,29 @@ main (int argc, char *argv[])
 
     }
 
-  if (oflags['s'] && !oflags['F'])
-    {
-      daemon (1, 0);            /*incase socket is relative path, unlink then will fail */
-    }
 
   if (oflags['c'] || oflags['t'])
     {
 
       if (oflags['H'])
         {
-          fatal_moan ("fix a bug in HTML dispatcher before this works");
+          ansi = ansi_new_html (stdout);
         }
       else
         {
-          ansi = (ANSI *) malloc (sizeof (ANSI));
-          memset (ansi, 0, sizeof (ANSI));
-
           terminal_register_handlers ();
-          ansi->terminal = terminal_open (0, 1);
-          ansi_reset (ansi, NULL);
+          ansi =
+            ansi_new_from_terminal (terminal_open (0, 1),
+                                    oflags['u'] ? 0 : 1);
+          ansi->reset (ansi, NULL);
         }
     }
 
-  mainloop (tty, server_socket, client_socket, ansi, log, nhistory);
+  mainloop (tty, server_socket, client_socket, ansi, log, history, &size);
 
   if (ansi)
     {
-      ansi_terminal_reset (ansi);
+      ansi->close (ansi);
       terminal_atexit ();
     }
 
@@ -486,6 +539,7 @@ main (int argc, char *argv[])
   if (client_socket)
     socket_free (client_socket);
 
-  printf ("you have now exited sympathy\n");
+  if (!oflags['H'])
+    printf ("you have now exited sympathy\n");
   return 0;
 }