annotate lib-src/emacsclient.c @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents bcdc7deadc19
children c7528f8e288d
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 /* Client process that communicates with GNU Emacs acting as server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1986, 1987, 1993, 1994 Free Software Foundation, Inc.
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 GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: FSF 19.28. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 #define NO_SHORTNAMES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include <../src/config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #undef read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #undef write
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #undef open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #undef close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #undef signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #if __STDC__ || defined(STDC_HEADERS)
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 <unistd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include <fcntl.h> /* for creat() */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #if !defined(HAVE_SOCKETS) && !defined(HAVE_SYSVIPC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
41 main (argc, argv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
42 int argc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
43 char **argv;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 fprintf (stderr, "%s: Sorry, the Emacs server is supported only\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 fprintf (stderr, "on systems with Berkeley sockets or System V IPC.\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #else /* HAVE_SOCKETS or HAVE_SYSVIPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #if ! defined (HAVE_SYSVIPC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 /* BSD code is very different from SYSV IPC code */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #include <sys/socket.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 #include <sys/un.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 #include <errno.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 extern char *strerror ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 extern int errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
66 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
67 main (argc, argv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
68 int argc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
69 char **argv;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 char system_name[256];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 int s, i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 FILE *out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 struct sockaddr_un server;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 char *cwd, *str;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 char string[BUFSIZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 if (argc < 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 fprintf (stderr, "Usage: %s [+linenumber] filename\n", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 * Open up an AF_UNIX socket in this person's home directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 fprintf (stderr, "%s: ", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 perror ("socket");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 server.sun_family = AF_UNIX;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 #ifndef SERVER_HOME_DIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 struct stat statbfr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 gethostname (system_name, sizeof (system_name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 sprintf (server.sun_path, "/tmp/esrv%d-%s", (int) geteuid (), system_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 if (stat (server.sun_path, &statbfr) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 if (errno == ENOENT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 fprintf (stderr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 "Can't find socket; have you started the server?\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 perror ("stat");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 if (statbfr.st_uid != geteuid())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 fprintf (stderr, "Illegal socket owner\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 if (getenv ("HOME") == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 fprintf (stderr, "%s: No home directory\n", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 sprintf (server.sun_path, "/tmp/esrv%d", geteuid ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 strcpy (server.sun_path, getenv ("HOME"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 strcat (server.sun_path, "/.emacs_server");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 #endif /* SERVER_HOME_DIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 if (connect (s, (struct sockaddr *) &server, strlen (server.sun_path) + 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 fprintf (stderr, "%s: ", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 perror ("connect");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 if ((out = (FILE *) fdopen (s, "r+")) == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 fprintf (stderr, "%s: ", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 perror ("fdopen");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 #ifdef BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 cwd = (char *) getwd (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 cwd = (char *) getcwd (string, sizeof (string));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 if (cwd == 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 /* getwd puts message in STRING if it fails. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 fprintf (stderr, "%s: %s (%s)\n", argv[0], string, strerror (errno));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 for (i = 1; i < argc; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 if (*argv[i] == '+')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 char *p = argv[i] + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 while (*p >= '0' && *p <= '9') p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 if (*p != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 fprintf (out, "%s/", cwd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 else if (*argv[i] != '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 fprintf (out, "%s/", cwd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 fprintf (out, "%s ", argv[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 fprintf (out, "\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 fflush (out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 printf ("Waiting for Emacs...");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 fflush (stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 rewind (out); /* re-read the output */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 str = fgets (string, BUFSIZ, out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 /* Now, wait for an answer and print any messages. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 while ((str = fgets (string, BUFSIZ, out)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 printf ("%s", str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
183 exit (0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 #else /* This is the SYSV IPC section */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 #include <sys/ipc.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 #include <sys/msg.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 char *getwd ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 #if !__STDC__ && !defined(STDC_HEADERS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 char *getcwd (), *getenv ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
198 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
199 main (argc, argv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
200 int argc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
201 char **argv;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 int s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 key_t key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 /* Size of text allocated in MSGP. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 int size_allocated = BUFSIZ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 /* Amount of text used in MSGP. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 int used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 struct msgbuf *msgp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 = (struct msgbuf *) malloc (sizeof (struct msgbuf) + size_allocated);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 struct msqid_ds * msg_st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 char *homedir, buf[BUFSIZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 char gwdirb[BUFSIZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 char *cwd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 char *temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 char progname[BUFSIZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 strcpy (progname, argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 if (argc < 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 fprintf (stderr, "Usage: %s [+linenumber] filename\n", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 * Create a message queue using ~/.emacs_server as the path for ftok
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 if ((homedir = getenv ("HOME")) == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 fprintf (stderr, "%s: No home directory\n", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 strcpy (buf, homedir);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 strcat (buf, "/.emacs_server");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 creat (buf, 0600);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 key = ftok (buf, 1); /* unlikely to be anyone else using it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 s = msgget (key, 0600 | IPC_CREAT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 if (s == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 fprintf (stderr, "%s: ", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 perror ("msgget");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 /* Determine working dir, so we can prefix it to all the arguments. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 #ifdef BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 temp = getwd (gwdirb);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 temp = getcwd (gwdirb, sizeof gwdirb);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 cwd = gwdirb;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 if (temp != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 /* On some systems, cwd can look like `@machine/...';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ignore everything before the first slash in such a case. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 while (*cwd && *cwd != '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 cwd++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 strcat (cwd, "/");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 fprintf (stderr, cwd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 msgp->mtext[0] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 used = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 argc--; argv++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 while (argc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 int need_cwd = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 char *modified_arg = argv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 if (*modified_arg == '+')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 char *p = modified_arg + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 while (*p >= '0' && *p <= '9') p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 if (*p != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 need_cwd = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 else if (*modified_arg != '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 need_cwd = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 if (need_cwd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 used += strlen (cwd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 used += strlen (modified_arg) + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 while (used + 2 > size_allocated)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 size_allocated *= 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 msgp = (struct msgbuf *) realloc (msgp,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (sizeof (struct msgbuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 + size_allocated));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 if (need_cwd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 strcat (msgp->mtext, cwd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 strcat (msgp->mtext, modified_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 strcat (msgp->mtext, " ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 argv++; argc--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 strcat (msgp->mtext, "\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 #ifdef HPUX /* HPUX has a bug. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 if (strlen (msgp->mtext) >= 512)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 fprintf (stderr, "emacsclient: args too long for msgsnd\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 msgp->mtype = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 if (msgsnd (s, msgp, strlen (msgp->mtext)+1, 0) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 fprintf (stderr, "%s: ", progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 perror ("msgsnd");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 * Now, wait for an answer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 printf ("Waiting for Emacs...");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 fflush (stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 msgrcv (s, msgp, BUFSIZ, getpid (), 0); /* wait for anything back */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 strcpy (buf, msgp->mtext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 printf ("\n%s\n", buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 exit (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 #endif /* HAVE_SYSVIPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 #endif /* HAVE_SOCKETS or HAVE_SYSVIPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 #ifndef HAVE_STRERROR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 char *
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
338 strerror (errnum)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 12
diff changeset
339 int errnum;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 extern char *sys_errlist[];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 extern int sys_nerr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 if (errnum >= 0 && errnum < sys_nerr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 return sys_errlist[errnum];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 return (char *) "Unknown error";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 #endif /* ! HAVE_STRERROR */