annotate lib-src/gnudoit.c @ 54:05472e90ae02 r19-16-pre2

Import from CVS: tag r19-16-pre2
author cvs
date Mon, 13 Aug 2007 08:57:55 +0200
parents bcdc7deadc19
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* -*-C-*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Client code to locally and remotely evaluate lisp forms using GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 Copying is permitted under those conditions described by the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 General Public License.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Copyright (C) 1989 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 Author: Andy Norman (ange@hplb.hpl.hp.com).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 Please mail bugs and suggestions to the author at the above address.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 * Please see the note at the end of the README file for details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 * (If gnuserv came bundled with your emacs, the README file is probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 * ../etc/gnuserv.README relative to the directory containing this file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 static char rcsid [] = "!Header: gnudoit.c,v 2.1 95/02/16 11:59:02 arup alpha !";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include "gnuserv.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include "getopt.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include <unistd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && !defined(INTERNET_DOMAIN_SOCKETS)
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
38 int
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
39 main (int argc, char *argv[])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 fprintf (stderr,"Sorry, the Emacs server is only supported on systems that have\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 fprintf (stderr,"Unix Domain sockets, Internet Domain sockets or System V IPC.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 } /* main */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
47 int
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
48 main(int argc,char *argv[])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 int qflg = 0; /* don't wait around for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 * gnu emacs to eval cmd */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 int errflg = 0; /* option error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 int c; /* char from getopt */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 int s; /* socket / msqid to server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 int connect_type; /* CONN_UNIX, CONN_INTERNET, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 * CONN_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 char *hostarg = NULL; /* remote hostname argument */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 u_short portarg = 0; /* port number */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 struct msgbuf *msgp; /* message */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #endif /* SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 progname = argv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 while ((c = getopt(argc, argv,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 "qh:p:"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 #else /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 "q"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 #endif /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 )) != EOF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 switch (c) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 case 'h': /* host name specified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 hostarg = optarg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 case 'p': /* port number specified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 portarg = atoi(optarg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 case 'q': /* quick mode specified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 qflg++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 case '?':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 errflg++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 }; /* switch */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 if (errflg) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 fprintf(stderr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 "usage: %s [-q] [-h hostname] [-p port] [sexpr]...\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 #else /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "usage: %s [-q] [sexpr]...\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 #endif /* !INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 connect_type = make_connection(hostarg, portarg, &s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 connect_type = make_connection(NULL, (u_short) 0, &s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 if ((msgp = (struct msgbuf *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 malloc(sizeof *msgp + GSERV_BUFSZ)) == NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 fprintf(stderr,"%s: not enough memory for message buffer\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 }; /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 msgp->mtext[0] = '\0'; /* ready for later strcats */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 #endif /* SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 if (qflg) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 send_string(s,"(server-eval-quickly '(progn ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 send_string(s,"(server-eval '(progn ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 if (optind < argc) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 for (; optind < argc; optind++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 send_string(s, argv[optind]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 send_string(s, " ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 } else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 /* no sexp on the command line, so read it from stdin */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 int nb;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 char buf[GSERV_BUFSZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 while ((nb = read(fileno(stdin), buf, GSERV_BUFSZ-1)) > 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 buf[nb] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 send_string(s, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 send_string(s,"))");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 if (connect_type == (int) CONN_IPC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 disconnect_from_ipc_server(s,msgp,!qflg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 #else /* !SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 disconnect_from_server(s,!qflg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 #endif /* !SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
12
bcdc7deadc19 Import from CVS: tag r19-15b7
cvs
parents: 0
diff changeset
148 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 } /* main */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */