home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / gnuserv / gnudoit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-23  |  3.7 KB  |  140 lines

  1. /* -*-C-*-
  2.  Client code to locally and remotely evaluate lisp forms using GNU Emacs.
  3.  
  4.  This file is part of GNU Emacs.
  5.  
  6.  Copying is permitted under those conditions described by the GNU
  7.  General Public License.
  8.  
  9.  Copyright (C) 1989 Free Software Foundation, Inc.
  10.  
  11.  Author: Andy Norman (ange@hplb.hpl.hp.com).
  12.  
  13.  Please mail bugs and suggestions to the author at the above address.
  14. */
  15.  
  16. static char rcsid [] = "$Header: gnudoit.c,v 1.5 89/07/24 12:47:53 ange Exp $";
  17.  
  18. #include "gnuserv.h"
  19.  
  20. #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
  21. main ()
  22. {
  23.   fprintf (stderr,"Sorry, the Emacs server is only supported on systems that have\n");
  24.   fprintf (stderr,"Unix Domain sockets, Internet Domain sockets or System V IPC.\n");
  25.   exit (1);
  26. } /* main */
  27. #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
  28.  
  29. main(argc,argv)
  30.      int argc;
  31.      char *argv[];
  32. {
  33.   int starting_line = 1;            /* line to start editing at */
  34.   int qflg = 0;                    /* don't wait around for gnu emacs to eval cmd */
  35.   int errflg = 0;                /* option error */
  36.   int c;                    /* char from getopt */
  37.   int s;                    /* socket / msqid to server */
  38. #ifdef INTERNET_DOMAIN_SOCKETS
  39.   char remotehost[HOSTNAMSZ];            /* remote hostname */
  40.   int hflg = 0;                    /* hostname given on command line */
  41.   u_short port = 0;                /* port number */
  42.   char *ptr;                    /* return from getenv */
  43. #endif /* INTERNET_DOMAIN_SOCKETS */
  44. #ifdef SYSV_IPC
  45.   struct msgbuf *msgp;                /* message */
  46. #endif /* SYSV_IPC */
  47.  
  48.   progname = argv[0];
  49.  
  50.   while ((c = getopt(argc, argv,
  51. #ifdef INTERNET_DOMAIN_SOCKETS
  52.              "qh:p:"
  53. #else /* !INTERNET_DOMAIN_SOCKETS */
  54.              "q"
  55. #endif /* !INTERNET_DOMAIN_SOCKETS */
  56.              )) != EOF)
  57.     switch (c) {
  58. #ifdef INTERNET_DOMAIN_SOCKETS
  59.     case 'h':                    /* host name specified */
  60.       strcpy(remotehost,optarg);
  61.       hflg++;
  62.       break;
  63.     case 'p':                    /* port number specified */
  64.       port = atoi(optarg);
  65.       break;
  66. #endif /* INTERNET_DOMAIN_SOCKETS */
  67.     case 'q':                    /* quick mode specified */
  68.       qflg++;
  69.       break;
  70.     case '?':
  71.       errflg++;
  72.     }; /* switch */
  73.  
  74.   if (errflg) {
  75.     fprintf(stderr,
  76. #ifdef INTERNET_DOMAIN_SOCKETS
  77.         "usage: %s [-q] [-h hostname] [-p port] [sexpr]...\n",
  78. #else /* !INTERNET_DOMAIN_SOCKETS */
  79.         "usage: %s [-q] [sexpr]...\n",
  80. #endif /* !INTERNET_DOMAIN_SOCKETS */
  81.         progname);
  82.     exit (1);
  83.   }; /* if */
  84.  
  85. #ifdef INTERNET_DOMAIN_SOCKETS
  86.   if (!hflg) {
  87.     if((ptr=getenv("GNU_HOST")) != NULL)
  88.       strcpy(remotehost,ptr);
  89.     else
  90.       gethostname(remotehost,HOSTNAMSZ);    /* use this host by default */
  91.   }; /* if */
  92.  
  93.   if (port == 0 && (ptr=getenv("GNU_PORT")) != NULL)
  94.       port = atoi(ptr);
  95.  
  96. #ifdef UNIX_DOMAIN_SOCKETS
  97.   if (!strcmp(remotehost,"unix"))
  98.     s = connect_to_unix_server();
  99.   else
  100. #endif /* UNIX_DOMAIN_SOCKETS */
  101.     s = connect_to_internet_server(remotehost,port);
  102. #else /* !INTERNET_DOMAIN_SOCKETS */
  103. #ifdef UNIX_DOMAIN_SOCKETS
  104.   s = connect_to_unix_server();
  105. #endif /* UNIX_DOMAIN_SOCKETS */
  106. #ifdef SYSV_IPC
  107.   if ((msgp = (struct msgbuf *) malloc(sizeof *msgp + BUFSIZ)) == NULL) {
  108.     fprintf(stderr,"%s: not enough memory for message buffer\n",progname);
  109.     exit(1);
  110.   }; /* if */
  111.  
  112.   msgp->mtext[0] = '\0';            /* ready for later strcats */
  113.   s = connect_to_ipc_server();
  114. #endif /* SYSV_IPC */
  115. #endif /* !INTERNET_DOMAIN_SOCKETS */
  116.  
  117.   if (qflg) {
  118.     send_string(s,"(server-eval-quickly '(progn ");
  119.   }
  120.   else {
  121.     send_string(s,"(server-eval '(progn ");
  122.   };
  123.  
  124.   for (; optind < argc; optind++)
  125.     send_string(s,argv[optind]);
  126.  
  127.   send_string(s,"))");
  128.  
  129. #ifdef SYSV_IPC
  130.   disconnect_from_ipc_server(s,msgp,!qflg);
  131. #else /* !SYSV_IPC */
  132.   disconnect_from_server(s,!qflg);
  133. #endif /* !SYSV_IPC */
  134.  
  135.   exit(0);
  136.  
  137. } /* main */
  138.  
  139. #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
  140.