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)
|
12
|
38 int
|
|
39 main (int argc, char *argv[])
|
0
|
40 {
|
|
41 fprintf (stderr,"Sorry, the Emacs server is only supported on systems that have\n");
|
|
42 fprintf (stderr,"Unix Domain sockets, Internet Domain sockets or System V IPC.\n");
|
|
43 exit (1);
|
|
44 } /* main */
|
|
45 #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|
|
46
|
12
|
47 int
|
|
48 main(int argc,char *argv[])
|
0
|
49 {
|
|
50 int qflg = 0; /* don't wait around for
|
|
51 * gnu emacs to eval cmd */
|
|
52 int errflg = 0; /* option error */
|
|
53 int c; /* char from getopt */
|
|
54 int s; /* socket / msqid to server */
|
|
55 int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
|
56 * CONN_IPC */
|
|
57 #ifdef INTERNET_DOMAIN_SOCKETS
|
|
58 char *hostarg = NULL; /* remote hostname argument */
|
|
59 u_short portarg = 0; /* port number */
|
|
60 #endif /* INTERNET_DOMAIN_SOCKETS */
|
|
61 #ifdef SYSV_IPC
|
|
62 struct msgbuf *msgp; /* message */
|
|
63 #endif /* SYSV_IPC */
|
|
64
|
|
65 progname = argv[0];
|
|
66
|
|
67 while ((c = getopt(argc, argv,
|
|
68 #ifdef INTERNET_DOMAIN_SOCKETS
|
|
69 "qh:p:"
|
|
70 #else /* !INTERNET_DOMAIN_SOCKETS */
|
|
71 "q"
|
|
72 #endif /* !INTERNET_DOMAIN_SOCKETS */
|
|
73 )) != EOF)
|
|
74 switch (c) {
|
|
75 #ifdef INTERNET_DOMAIN_SOCKETS
|
|
76 case 'h': /* host name specified */
|
|
77 hostarg = optarg;
|
|
78 break;
|
|
79 case 'p': /* port number specified */
|
|
80 portarg = atoi(optarg);
|
|
81 break;
|
|
82 #endif /* INTERNET_DOMAIN_SOCKETS */
|
|
83 case 'q': /* quick mode specified */
|
|
84 qflg++;
|
|
85 break;
|
|
86 case '?':
|
|
87 errflg++;
|
|
88 }; /* switch */
|
|
89
|
|
90 if (errflg) {
|
|
91 fprintf(stderr,
|
|
92 #ifdef INTERNET_DOMAIN_SOCKETS
|
|
93 "usage: %s [-q] [-h hostname] [-p port] [sexpr]...\n",
|
|
94 #else /* !INTERNET_DOMAIN_SOCKETS */
|
|
95 "usage: %s [-q] [sexpr]...\n",
|
|
96 #endif /* !INTERNET_DOMAIN_SOCKETS */
|
|
97 progname);
|
|
98 exit (1);
|
|
99 }; /* if */
|
|
100
|
|
101 #ifdef INTERNET_DOMAIN_SOCKETS
|
|
102 connect_type = make_connection(hostarg, portarg, &s);
|
|
103 #else
|
|
104 connect_type = make_connection(NULL, (u_short) 0, &s);
|
|
105 #endif
|
|
106
|
|
107 #ifdef SYSV_IPC
|
|
108 if ((msgp = (struct msgbuf *)
|
|
109 malloc(sizeof *msgp + GSERV_BUFSZ)) == NULL) {
|
|
110 fprintf(stderr,"%s: not enough memory for message buffer\n",progname);
|
|
111 exit(1);
|
|
112 }; /* if */
|
|
113
|
|
114 msgp->mtext[0] = '\0'; /* ready for later strcats */
|
|
115 #endif /* SYSV_IPC */
|
|
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 if (optind < argc) {
|
|
125 for (; optind < argc; optind++) {
|
|
126 send_string(s, argv[optind]);
|
|
127 send_string(s, " ");
|
|
128 }
|
|
129 } else {
|
|
130 /* no sexp on the command line, so read it from stdin */
|
|
131 int nb;
|
|
132 char buf[GSERV_BUFSZ];
|
|
133 while ((nb = read(fileno(stdin), buf, GSERV_BUFSZ-1)) > 0) {
|
|
134 buf[nb] = '\0';
|
|
135 send_string(s, buf);
|
|
136 }
|
|
137 }
|
|
138 send_string(s,"))");
|
|
139
|
|
140 #ifdef SYSV_IPC
|
|
141 if (connect_type == (int) CONN_IPC)
|
|
142 disconnect_from_ipc_server(s,msgp,!qflg);
|
|
143 else
|
|
144 #else /* !SYSV_IPC */
|
|
145 disconnect_from_server(s,!qflg);
|
|
146 #endif /* !SYSV_IPC */
|
|
147
|
12
|
148 return 0;
|
0
|
149
|
|
150 } /* main */
|
|
151
|
|
152 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|