annotate lib-src/gnudoit.c @ 9:6f2bbbbbe05a

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