0
|
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 /*
|
|
17 * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
|
|
18 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
|
|
19 * Please see the note at the end of the README file for details.
|
|
20 *
|
|
21 * (If gnuserv came bundled with your emacs, the README file is probably
|
|
22 * ../etc/gnuserv.README relative to the directory containing this file)
|
|
23 */
|
|
24
|
|
25 #if 0
|
|
26 static char rcsid [] = "!Header: gnudoit.c,v 2.1 95/02/16 11:59:02 arup alpha !";
|
|
27 #endif
|
|
28
|
|
29 #include "gnuserv.h"
|
|
30 #include "getopt.h"
|
|
31
|
|
32 #include <stdlib.h>
|
|
33 #include <stdio.h>
|
|
34 #include <sys/types.h>
|
|
35 #include <unistd.h>
|
|
36
|
|
37 #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
|
|
38 main ()
|
|
39 {
|
|
40 fprintf (stderr,"Sorry, the Emacs server is only supported on systems that have\n");
|
|
41 fprintf (stderr,"Unix Domain sockets, Internet Domain sockets or System V IPC.\n");
|
|
42 exit (1);
|
|
43 } /* main */
|
|
44 #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|
|
45
|
|
46 void
|
|
47 main(argc,argv)
|
|
48 int argc;
|
|
49 char *argv[];
|
|
50 {
|
|
51 int qflg = 0; /* don't wait around for
|
|
52 * gnu emacs to eval cmd */
|
|
53 int errflg = 0; /* option error */
|
|
54 int c; /* char from getopt */
|
|
55 int s; /* socket / msqid to server */
|
|
56 int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
|
57 * CONN_IPC */
|
|
58 #ifdef INTERNET_DOMAIN_SOCKETS
|
|
59 char *hostarg = NULL; /* remote hostname argument */
|
|
60 u_short portarg = 0; /* port number */
|
|
61 #endif /* INTERNET_DOMAIN_SOCKETS */
|
|
62 #ifdef SYSV_IPC
|
|
63 struct msgbuf *msgp; /* message */
|
|
64 #endif /* SYSV_IPC */
|
|
65
|
|
66 progname = argv[0];
|
|
67
|
|
68 while ((c = getopt(argc, argv,
|
|
69 #ifdef INTERNET_DOMAIN_SOCKETS
|
|
70 "qh:p:"
|
|
71 #else /* !INTERNET_DOMAIN_SOCKETS */
|
|
72 "q"
|
|
73 #endif /* !INTERNET_DOMAIN_SOCKETS */
|
|
74 )) != EOF)
|
|
75 switch (c) {
|
|
76 #ifdef INTERNET_DOMAIN_SOCKETS
|
|
77 case 'h': /* host name specified */
|
|
78 hostarg = optarg;
|
|
79 break;
|
|
80 case 'p': /* port number specified */
|
|
81 portarg = atoi(optarg);
|
|
82 break;
|
|
83 #endif /* INTERNET_DOMAIN_SOCKETS */
|
|
84 case 'q': /* quick mode specified */
|
|
85 qflg++;
|
|
86 break;
|
|
87 case '?':
|
|
88 errflg++;
|
|
89 }; /* switch */
|
|
90
|
|
91 if (errflg) {
|
|
92 fprintf(stderr,
|
|
93 #ifdef INTERNET_DOMAIN_SOCKETS
|
|
94 "usage: %s [-q] [-h hostname] [-p port] [sexpr]...\n",
|
|
95 #else /* !INTERNET_DOMAIN_SOCKETS */
|
|
96 "usage: %s [-q] [sexpr]...\n",
|
|
97 #endif /* !INTERNET_DOMAIN_SOCKETS */
|
|
98 progname);
|
|
99 exit (1);
|
|
100 }; /* if */
|
|
101
|
|
102 #ifdef INTERNET_DOMAIN_SOCKETS
|
|
103 connect_type = make_connection(hostarg, portarg, &s);
|
|
104 #else
|
|
105 connect_type = make_connection(NULL, (u_short) 0, &s);
|
|
106 #endif
|
|
107
|
|
108 #ifdef SYSV_IPC
|
|
109 if ((msgp = (struct msgbuf *)
|
|
110 malloc(sizeof *msgp + GSERV_BUFSZ)) == NULL) {
|
|
111 fprintf(stderr,"%s: not enough memory for message buffer\n",progname);
|
|
112 exit(1);
|
|
113 }; /* if */
|
|
114
|
|
115 msgp->mtext[0] = '\0'; /* ready for later strcats */
|
|
116 #endif /* SYSV_IPC */
|
|
117
|
|
118 if (qflg) {
|
|
119 send_string(s,"(server-eval-quickly '(progn ");
|
|
120 }
|
|
121 else {
|
|
122 send_string(s,"(server-eval '(progn ");
|
|
123 };
|
|
124
|
|
125 if (optind < argc) {
|
|
126 for (; optind < argc; optind++) {
|
|
127 send_string(s, argv[optind]);
|
|
128 send_string(s, " ");
|
|
129 }
|
|
130 } else {
|
|
131 /* no sexp on the command line, so read it from stdin */
|
|
132 int nb;
|
|
133 char buf[GSERV_BUFSZ];
|
|
134 while ((nb = read(fileno(stdin), buf, GSERV_BUFSZ-1)) > 0) {
|
|
135 buf[nb] = '\0';
|
|
136 send_string(s, buf);
|
|
137 }
|
|
138 }
|
|
139 send_string(s,"))");
|
|
140
|
|
141 #ifdef SYSV_IPC
|
|
142 if (connect_type == (int) CONN_IPC)
|
|
143 disconnect_from_ipc_server(s,msgp,!qflg);
|
|
144 else
|
|
145 #else /* !SYSV_IPC */
|
|
146 disconnect_from_server(s,!qflg);
|
|
147 #endif /* !SYSV_IPC */
|
|
148
|
|
149 exit(0);
|
|
150
|
|
151 } /* main */
|
|
152
|
|
153 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|