0
|
1 /* -*-C-*-
|
|
2 Client code to allow local and remote editing of files by XEmacs.
|
|
3 Copyright (C) 1989 Free Software Foundation, Inc.
|
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
149
|
5 Copyright (C) 1997 Free Software Foundation, Inc.
|
0
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA.
|
|
23
|
272
|
24 Author: Andy Norman (ange@hplb.hpl.hp.com), based on
|
0
|
25 'etc/emacsclient.c' from the GNU Emacs 18.52 distribution.
|
|
26
|
294
|
27 Please mail bugs and suggestions to the XEmacs maintainer.
|
0
|
28 */
|
|
29
|
|
30 /*
|
|
31 * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
|
|
32 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
|
|
33 * GNUATTACH support added by Ben Wing <wing@xemacs.org>.
|
|
34 * Please see the note at the end of the README file for details.
|
|
35 *
|
|
36 * (If gnuserv came bundled with your emacs, the README file is probably
|
|
37 * ../etc/gnuserv.README relative to the directory containing this file)
|
|
38 */
|
|
39
|
371
|
40 #if 0
|
|
41 /* Hand-munged RCS header */
|
|
42 static char rcsid [] = "!Header: gnuclient.c,v 2.2 95/12/12 01:39:21 wing nene !";
|
|
43 #endif
|
0
|
44
|
371
|
45 #include "gnuserv.h"
|
0
|
46 #include "getopt.h"
|
|
47
|
|
48 #include <stdio.h>
|
|
49 #include <stdlib.h>
|
171
|
50 #include <sys/types.h>
|
412
|
51 #define DONT_ENCAPSULATE
|
398
|
52 #include <sysfile.h>
|
171
|
53
|
149
|
54 #ifdef HAVE_STRING_H
|
0
|
55 #include <string.h>
|
149
|
56 #endif /* HAVE_STRING_H */
|
171
|
57
|
149
|
58 #ifdef HAVE_UNISTD_H
|
0
|
59 #include <unistd.h>
|
149
|
60 #endif /* HAVE_UNISTD_H */
|
171
|
61
|
149
|
62 #include <signal.h>
|
|
63
|
0
|
64 #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
|
|
65 !defined(INTERNET_DOMAIN_SOCKETS)
|
78
|
66 int
|
|
67 main (int argc, char *argv[])
|
0
|
68 {
|
|
69 fprintf (stderr, "Sorry, the Emacs server is only "
|
|
70 "supported on systems that have\n");
|
|
71 fprintf (stderr, "Unix Domain sockets, Internet Domain "
|
|
72 "sockets or System V IPC.\n");
|
|
73 exit (1);
|
|
74 } /* main */
|
|
75 #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|
|
76
|
|
77 static char cwd[MAXPATHLEN+2]; /* current working directory when calculated */
|
|
78 static char *cp = NULL; /* ptr into valid bit of cwd above */
|
|
79
|
108
|
80 static pid_t emacs_pid; /* Process id for emacs process */
|
|
81
|
149
|
82 void initialize_signals (void);
|
|
83
|
167
|
84 static void
|
149
|
85 tell_emacs_to_resume (int sig)
|
108
|
86 {
|
149
|
87 char buffer[GSERV_BUFSZ+1];
|
|
88 int s; /* socket / msqid to server */
|
|
89 int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
|
90 ONN_IPC */
|
108
|
91
|
|
92 /* Why is SYSV so retarded? */
|
|
93 /* We want emacs to realize that we are resuming */
|
398
|
94 #ifdef SIGCONT
|
272
|
95 signal(SIGCONT, tell_emacs_to_resume);
|
398
|
96 #endif
|
108
|
97
|
149
|
98 connect_type = make_connection (NULL, (u_short) 0, &s);
|
108
|
99
|
153
|
100 sprintf(buffer,"(gnuserv-eval '(resume-pid-console %d))", (int)getpid());
|
149
|
101 send_string(s, buffer);
|
|
102
|
108
|
103 #ifdef SYSV_IPC
|
|
104 if (connect_type == (int) CONN_IPC)
|
|
105 disconnect_from_ipc_server (s, msgp, FALSE);
|
|
106 #else /* !SYSV_IPC */
|
|
107 if (connect_type != (int) CONN_IPC)
|
|
108 disconnect_from_server (s, FALSE);
|
|
109 #endif /* !SYSV_IPC */
|
|
110 }
|
|
111
|
167
|
112 static void
|
149
|
113 pass_signal_to_emacs (int sig)
|
108
|
114 {
|
149
|
115 if (kill (emacs_pid, sig) == -1)
|
|
116 {
|
|
117 fprintf (stderr, "gnuattach: Could not pass signal to emacs process\n");
|
|
118 exit (1);
|
|
119 }
|
|
120 initialize_signals ();
|
108
|
121 }
|
|
122
|
149
|
123 void
|
412
|
124 initialize_signals ()
|
108
|
125 {
|
149
|
126 /* Set up signal handler to pass relevant signals to emacs process.
|
|
127 We used to send SIGSEGV, SIGBUS, SIGPIPE, SIGILL and others to
|
|
128 Emacs, but I think it's better not to. I can see no reason why
|
|
129 Emacs should SIGSEGV whenever gnuclient SIGSEGV-s, etc. */
|
|
130 signal (SIGQUIT, pass_signal_to_emacs);
|
|
131 signal (SIGINT, pass_signal_to_emacs);
|
151
|
132 #ifdef SIGWINCH
|
|
133 signal (SIGWINCH, pass_signal_to_emacs);
|
|
134 #endif
|
108
|
135
|
398
|
136 #ifdef SIGCONT
|
108
|
137 /* We want emacs to realize that we are resuming */
|
149
|
138 signal (SIGCONT, tell_emacs_to_resume);
|
398
|
139 #endif
|
108
|
140 }
|
|
141
|
0
|
142
|
|
143 /*
|
|
144 get_current_working_directory -- return the cwd.
|
|
145 */
|
|
146 static char *
|
|
147 get_current_working_directory (void)
|
|
148 {
|
|
149 if (cp == NULL)
|
|
150 { /* haven't calculated it yet */
|
|
151 #ifdef BSD
|
|
152 if (getwd (cwd) == 0)
|
|
153 #else /* !BSD */
|
|
154 if (getcwd (cwd,MAXPATHLEN) == NULL)
|
|
155 #endif /* !BSD */
|
|
156 {
|
|
157 perror (progname);
|
|
158 fprintf (stderr, "%s: unable to get current working directory\n",
|
|
159 progname);
|
|
160 exit (1);
|
|
161 } /* if */
|
272
|
162
|
0
|
163 /* on some systems, cwd can look like '@machine/' ... */
|
|
164 /* ignore everything before the first '/' */
|
|
165 for (cp = cwd; *cp && *cp != '/'; ++cp)
|
|
166 ;
|
|
167
|
|
168 } /* if */
|
|
169
|
|
170 return cp;
|
|
171
|
|
172 } /* get_current_working_directory */
|
|
173
|
|
174
|
|
175 /*
|
|
176 filename_expand -- try to convert the given filename into a fully-qualified
|
|
177 pathname.
|
|
178 */
|
|
179 static void
|
|
180 filename_expand (char *fullpath, char *filename)
|
|
181 /* fullpath - returned full pathname */
|
|
182 /* filename - filename to expand */
|
|
183 {
|
|
184 int len;
|
|
185
|
|
186 fullpath[0] = '\0';
|
272
|
187
|
373
|
188 if (filename[0] && filename[0] == '/')
|
|
189 {
|
|
190 /* Absolute (unix-style) pathname. Do nothing */
|
|
191 strcat (fullpath, filename);
|
|
192 }
|
412
|
193 #ifdef __CYGWIN32__
|
373
|
194 else if (filename[0] && filename[0] == '\\' &&
|
|
195 filename[1] && filename[1] == '\\')
|
|
196 {
|
|
197 /* This path includes the server name (something like
|
|
198 "\\server\path"), so we assume it's absolute. Do nothing to
|
|
199 it. */
|
|
200 strcat (fullpath, filename);
|
|
201 }
|
|
202 else if (filename[0] &&
|
|
203 filename[1] && filename[1] == ':' &&
|
|
204 filename[2] && filename[2] == '\\')
|
|
205 {
|
|
206 /* Absolute pathname with drive letter. Convert "<drive>:"
|
|
207 to "//<drive>/". */
|
|
208 strcat (fullpath, "//");
|
|
209 strncat (fullpath, filename, 1);
|
|
210 strcat (fullpath, &filename[2]);
|
|
211 }
|
|
212 #endif
|
|
213 else
|
|
214 {
|
|
215 /* Assume relative Unix style path. Get the current directory
|
|
216 and prepend it. FIXME: need to fix the case of DOS paths like
|
|
217 "\foo", where we need to get the current drive. */
|
|
218
|
0
|
219 strcat (fullpath, get_current_working_directory ());
|
|
220 len = strlen (fullpath);
|
|
221
|
|
222 if (len > 0 && fullpath[len-1] == '/') /* trailing slash already? */
|
|
223 ; /* yep */
|
|
224 else
|
|
225 strcat (fullpath, "/"); /* nope, append trailing slash */
|
375
|
226 /* Don't forget to add the filename! */
|
|
227 strcat (fullpath,filename);
|
373
|
228 }
|
0
|
229 } /* filename_expand */
|
|
230
|
151
|
231 /* Encase the string in quotes, escape all the backslashes and quotes
|
|
232 in string. */
|
167
|
233 static char *
|
412
|
234 clean_string (CONST char *s)
|
151
|
235 {
|
|
236 int i = 0;
|
|
237 char *p, *res;
|
|
238
|
272
|
239 {
|
412
|
240 CONST char *const_p;
|
272
|
241 for (const_p = s; *const_p; const_p++, i++)
|
|
242 {
|
|
243 if (*const_p == '\\' || *const_p == '\"')
|
|
244 ++i;
|
|
245 else if (*const_p == '\004')
|
|
246 i += 3;
|
|
247 }
|
|
248 }
|
|
249
|
|
250 p = res = (char *) malloc (i + 2 + 1);
|
151
|
251 *p++ = '\"';
|
|
252 for (; *s; p++, s++)
|
|
253 {
|
|
254 switch (*s)
|
|
255 {
|
|
256 case '\\':
|
|
257 *p++ = '\\';
|
|
258 *p = '\\';
|
|
259 break;
|
|
260 case '\"':
|
|
261 *p++ = '\\';
|
|
262 *p = '\"';
|
|
263 break;
|
|
264 case '\004':
|
|
265 *p++ = '\\';
|
|
266 *p++ = 'C';
|
|
267 *p++ = '-';
|
|
268 *p = 'd';
|
|
269 break;
|
|
270 default:
|
|
271 *p = *s;
|
|
272 }
|
|
273 }
|
|
274 *p++ = '\"';
|
|
275 *p = '\0';
|
|
276 return res;
|
|
277 }
|
|
278
|
|
279 #define GET_ARGUMENT(var, desc) do { \
|
|
280 if (*(p + 1)) (var) = p + 1; \
|
|
281 else \
|
|
282 { \
|
|
283 if (!argv[++i]) \
|
|
284 { \
|
|
285 fprintf (stderr, "%s: `%s' must be followed by an argument\n", \
|
|
286 progname, desc); \
|
|
287 exit (1); \
|
|
288 } \
|
|
289 (var) = argv[i]; \
|
|
290 } \
|
|
291 over = 1; \
|
|
292 } while (0)
|
|
293
|
412
|
294 /* A strdup immitation. */
|
153
|
295 static char *
|
412
|
296 my_strdup (CONST char *s)
|
153
|
297 {
|
412
|
298 char *new = malloc (strlen (s) + 1);
|
|
299 if (new)
|
|
300 strcpy (new, s);
|
|
301 return new;
|
153
|
302 }
|
151
|
303
|
78
|
304 int
|
|
305 main (int argc, char *argv[])
|
0
|
306 {
|
151
|
307 int starting_line = 1; /* line to start editing at */
|
|
308 char command[MAXPATHLEN+50]; /* emacs command buffer */
|
|
309 char fullpath[MAXPATHLEN+1]; /* full pathname to file */
|
|
310 char *eval_form = NULL; /* form to evaluate with `-eval' */
|
|
311 char *eval_function = NULL; /* function to evaluate with `-f' */
|
|
312 char *load_library = NULL; /* library to load */
|
|
313 int quick = 0; /* quick edit, don't wait for user to
|
|
314 finish */
|
|
315 int batch = 0; /* batch mode */
|
|
316 int view = 0; /* view only. */
|
|
317 int nofiles = 0;
|
|
318 int errflg = 0; /* option error */
|
|
319 int s; /* socket / msqid to server */
|
|
320 int connect_type; /* CONN_UNIX, CONN_INTERNET, or
|
|
321 * CONN_IPC */
|
149
|
322 int suppress_windows_system = 0;
|
153
|
323 char *display = NULL;
|
0
|
324 #ifdef INTERNET_DOMAIN_SOCKETS
|
151
|
325 char *hostarg = NULL; /* remote hostname */
|
|
326 char *remotearg;
|
|
327 char thishost[HOSTNAMSZ]; /* this hostname */
|
|
328 char remotepath[MAXPATHLEN+1]; /* remote pathname */
|
|
329 char *path;
|
|
330 int rflg = 0; /* pathname given on cmdline */
|
|
331 char *portarg;
|
|
332 u_short port = 0; /* port to server */
|
0
|
333 #endif /* INTERNET_DOMAIN_SOCKETS */
|
|
334 #ifdef SYSV_IPC
|
151
|
335 struct msgbuf *msgp; /* message */
|
0
|
336 #endif /* SYSV_IPC */
|
173
|
337 char *tty = NULL;
|
151
|
338 char buffer[GSERV_BUFSZ + 1]; /* buffer to read pid */
|
|
339 char result[GSERV_BUFSZ + 1];
|
|
340 int i;
|
0
|
341
|
|
342 #ifdef INTERNET_DOMAIN_SOCKETS
|
|
343 memset (remotepath, 0, sizeof (remotepath));
|
|
344 #endif /* INTERNET_DOMAIN_SOCKETS */
|
|
345
|
151
|
346 progname = strrchr (argv[0], '/');
|
|
347 if (progname)
|
|
348 ++progname;
|
|
349 else
|
|
350 progname = argv[0];
|
0
|
351
|
259
|
352 #ifdef USE_TMPDIR
|
|
353 tmpdir = getenv ("TMPDIR");
|
|
354 #endif
|
|
355 if (!tmpdir)
|
|
356 tmpdir = "/tmp";
|
|
357
|
149
|
358 display = getenv ("DISPLAY");
|
286
|
359 if (display)
|
|
360 display = my_strdup (display);
|
|
361 #ifndef HAVE_MS_WINDOWS
|
|
362 else
|
149
|
363 suppress_windows_system = 1;
|
286
|
364 #endif
|
149
|
365
|
151
|
366 for (i = 1; argv[i] && !errflg; i++)
|
|
367 {
|
|
368 if (*argv[i] != '-')
|
0
|
369 break;
|
153
|
370 else if (*argv[i] == '-'
|
|
371 && (*(argv[i] + 1) == '\0'
|
|
372 || (*(argv[i] + 1) == '-' && *(argv[i] + 2) == '\0')))
|
|
373 {
|
|
374 /* `-' or `--' */
|
|
375 ++i;
|
|
376 break;
|
|
377 }
|
|
378
|
|
379 if (!strcmp (argv[i], "-batch") || !strcmp (argv[i], "--batch"))
|
151
|
380 batch = 1;
|
153
|
381 else if (!strcmp (argv[i], "-eval") || !strcmp (argv[i], "--eval"))
|
151
|
382 {
|
|
383 if (!argv[++i])
|
|
384 {
|
|
385 fprintf (stderr, "%s: `-eval' must be followed by an argument\n",
|
|
386 progname);
|
|
387 exit (1);
|
|
388 }
|
|
389 eval_form = argv[i];
|
|
390 }
|
153
|
391 else if (!strcmp (argv[i], "-display") || !strcmp (argv[i], "--display"))
|
151
|
392 {
|
|
393 suppress_windows_system = 0;
|
|
394 if (!argv[++i])
|
|
395 {
|
153
|
396 fprintf (stderr,
|
|
397 "%s: `-display' must be followed by an argument\n",
|
151
|
398 progname);
|
|
399 exit (1);
|
|
400 }
|
153
|
401 if (display)
|
|
402 free (display);
|
|
403 /* no need to strdup. */
|
151
|
404 display = argv[i];
|
|
405 }
|
|
406 else if (!strcmp (argv[i], "-nw"))
|
|
407 suppress_windows_system = 1;
|
|
408 else
|
|
409 {
|
|
410 /* Iterate over one-letter options. */
|
|
411 char *p;
|
|
412 int over = 0;
|
|
413 for (p = argv[i] + 1; *p && !over; p++)
|
|
414 {
|
|
415 switch (*p)
|
|
416 {
|
|
417 case 'q':
|
|
418 quick = 1;
|
|
419 break;
|
|
420 case 'v':
|
|
421 view = 1;
|
|
422 break;
|
|
423 case 'f':
|
|
424 GET_ARGUMENT (eval_function, "-f");
|
|
425 break;
|
|
426 case 'l':
|
|
427 GET_ARGUMENT (load_library, "-l");
|
|
428 break;
|
0
|
429 #ifdef INTERNET_DOMAIN_SOCKETS
|
151
|
430 case 'h':
|
|
431 GET_ARGUMENT (hostarg, "-h");
|
|
432 break;
|
|
433 case 'p':
|
|
434 GET_ARGUMENT (portarg, "-p");
|
|
435 port = atoi (portarg);
|
|
436 break;
|
|
437 case 'r':
|
|
438 GET_ARGUMENT (remotearg, "-r");
|
|
439 strcpy (remotepath, remotearg);
|
|
440 rflg = 1;
|
|
441 break;
|
0
|
442 #endif /* INTERNET_DOMAIN_SOCKETS */
|
151
|
443 default:
|
|
444 errflg = 1;
|
|
445 }
|
|
446 } /* for */
|
|
447 } /* else */
|
|
448 } /* for */
|
0
|
449
|
|
450 if (errflg)
|
|
451 {
|
|
452 fprintf (stderr,
|
|
453 #ifdef INTERNET_DOMAIN_SOCKETS
|
181
|
454 "usage: %s [-nw] [-display display] [-q] [-v] [-l library]\n"
|
|
455 " [-batch] [-f function] [-eval form]\n"
|
|
456 " [-h host] [-p port] [-r remote-path] [[+line] file] ...\n",
|
151
|
457 #else /* !INTERNET_DOMAIN_SOCKETS */
|
181
|
458 "usage: %s [-nw] [-q] [-v] [-l library] [-f function] [-eval form] "
|
0
|
459 "[[+line] path] ...\n",
|
|
460 #endif /* !INTERNET_DOMAIN_SOCKETS */
|
|
461 progname);
|
|
462 exit (1);
|
151
|
463 }
|
|
464 if (batch && argv[i])
|
0
|
465 {
|
151
|
466 fprintf (stderr, "%s: Cannot specify `-batch' with file names\n",
|
149
|
467 progname);
|
|
468 exit (1);
|
|
469 }
|
153
|
470 if (suppress_windows_system && hostarg)
|
|
471 {
|
|
472 fprintf (stderr, "%s: Remote editing is available only on X\n",
|
|
473 progname);
|
|
474 exit (1);
|
|
475 }
|
|
476
|
151
|
477 *result = '\0';
|
|
478 if (eval_function || eval_form || load_library)
|
|
479 {
|
|
480 #if defined(INTERNET_DOMAIN_SOCKETS)
|
|
481 connect_type = make_connection (hostarg, port, &s);
|
|
482 #else
|
|
483 connect_type = make_connection (NULL, (u_short) 0, &s);
|
|
484 #endif
|
|
485 sprintf (command, "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
|
|
486 send_string (s, command);
|
|
487 if (load_library)
|
|
488 {
|
267
|
489 send_string (s , "(load-library ");
|
|
490 send_string (s, clean_string(load_library));
|
|
491 send_string (s, ") ");
|
151
|
492 }
|
|
493 if (eval_form)
|
|
494 {
|
267
|
495 send_string (s, eval_form);
|
151
|
496 }
|
|
497 if (eval_function)
|
|
498 {
|
267
|
499 send_string (s, "(");
|
|
500 send_string (s, eval_function);
|
|
501 send_string (s, ")");
|
151
|
502 }
|
|
503 send_string (s, "))");
|
294
|
504 /* disconnect already sends EOT_STR */
|
|
505 #ifdef SYSV_IPC
|
|
506 if (connect_type == (int) CONN_IPC)
|
|
507 disconnect_from_ipc_server (s, msgp, batch && !quick);
|
|
508 #else /* !SYSV_IPC */
|
|
509 if (connect_type != (int) CONN_IPC)
|
|
510 disconnect_from_server (s, batch && !quick);
|
|
511 #endif /* !SYSV_IPC */
|
151
|
512 } /* eval_function || eval_form || load_library */
|
|
513 else if (batch)
|
|
514 {
|
278
|
515 /* no sexp on the command line, so read it from stdin */
|
|
516 int nb;
|
|
517
|
|
518 #if defined(INTERNET_DOMAIN_SOCKETS)
|
|
519 connect_type = make_connection (hostarg, port, &s);
|
|
520 #else
|
|
521 connect_type = make_connection (NULL, (u_short) 0, &s);
|
|
522 #endif
|
|
523 sprintf (command, "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
|
|
524 send_string (s, command);
|
|
525
|
|
526 while ((nb = read(fileno(stdin), buffer, GSERV_BUFSZ-1)) > 0)
|
|
527 {
|
|
528 buffer[nb] = '\0';
|
|
529 send_string(s, buffer);
|
|
530 }
|
|
531 send_string(s,"))");
|
294
|
532 /* disconnect already sends EOT_STR */
|
|
533 #ifdef SYSV_IPC
|
|
534 if (connect_type == (int) CONN_IPC)
|
|
535 disconnect_from_ipc_server (s, msgp, batch && !quick);
|
|
536 #else /* !SYSV_IPC */
|
|
537 if (connect_type != (int) CONN_IPC)
|
|
538 disconnect_from_server (s, batch && !quick);
|
|
539 #endif /* !SYSV_IPC */
|
151
|
540 }
|
|
541
|
|
542 if (!batch)
|
|
543 {
|
|
544 if (suppress_windows_system)
|
|
545 {
|
|
546 tty = ttyname (0);
|
|
547 if (!tty)
|
|
548 {
|
|
549 fprintf (stderr, "%s: Not connected to a tty", progname);
|
|
550 exit (1);
|
|
551 }
|
|
552 #if defined(INTERNET_DOMAIN_SOCKETS)
|
153
|
553 connect_type = make_connection (hostarg, port, &s);
|
151
|
554 #else
|
153
|
555 connect_type = make_connection (NULL, (u_short) 0, &s);
|
151
|
556 #endif
|
153
|
557 send_string (s, "(gnuserv-eval '(emacs-pid))");
|
|
558 send_string (s, EOT_STR);
|
151
|
559
|
153
|
560 if (read_line (s, buffer) == 0)
|
|
561 {
|
380
|
562 fprintf (stderr, "%s: Could not establish Emacs process id\n",
|
153
|
563 progname);
|
|
564 exit (1);
|
|
565 }
|
151
|
566 /* Don't do disconnect_from_server becasue we have already read
|
|
567 data, and disconnect doesn't do anything else. */
|
|
568 #ifndef INTERNET_DOMAIN_SOCKETS
|
153
|
569 if (connect_type == (int) CONN_IPC)
|
|
570 disconnect_from_ipc_server (s, msgp, FALSE);
|
108
|
571 #endif /* !SYSV_IPC */
|
|
572
|
153
|
573 emacs_pid = (pid_t)atol(buffer);
|
|
574 initialize_signals();
|
|
575 } /* suppress_windows_system */
|
108
|
576
|
151
|
577 #if defined(INTERNET_DOMAIN_SOCKETS)
|
|
578 connect_type = make_connection (hostarg, port, &s);
|
0
|
579 #else
|
151
|
580 connect_type = make_connection (NULL, (u_short) 0, &s);
|
0
|
581 #endif
|
|
582
|
|
583 #ifdef INTERNET_DOMAIN_SOCKETS
|
151
|
584 if (connect_type == (int) CONN_INTERNET)
|
|
585 {
|
|
586 char *ptr;
|
|
587 gethostname (thishost, HOSTNAMSZ);
|
|
588 if (!rflg)
|
272
|
589 { /* attempt to generate a path
|
0
|
590 * to this machine */
|
151
|
591 if ((ptr = getenv ("GNU_NODE")) != NULL)
|
|
592 /* user specified a path */
|
|
593 strcpy (remotepath, ptr);
|
|
594 }
|
0
|
595 #if 0 /* This is really bogus... re-enable it if you must have it! */
|
|
596 #if defined (hp9000s300) || defined (hp9000s800)
|
151
|
597 else if (strcmp (thishost,hostarg))
|
|
598 { /* try /net/thishost */
|
272
|
599 strcpy (remotepath, "/net/"); /* (this fails using internet
|
151
|
600 addresses) */
|
|
601 strcat (remotepath, thishost);
|
|
602 }
|
0
|
603 #endif
|
|
604 #endif
|
151
|
605 }
|
|
606 else
|
|
607 { /* same machines, no need for path */
|
|
608 remotepath[0] = '\0'; /* default is the empty path */
|
|
609 }
|
0
|
610 #endif /* INTERNET_DOMAIN_SOCKETS */
|
|
611
|
|
612 #ifdef SYSV_IPC
|
272
|
613 if ((msgp = (struct msgbuf *)
|
151
|
614 malloc (sizeof *msgp + GSERV_BUFSZ)) == NULL)
|
|
615 {
|
|
616 fprintf (stderr, "%s: not enough memory for message buffer\n", progname);
|
|
617 exit (1);
|
|
618 } /* if */
|
0
|
619
|
151
|
620 msgp->mtext[0] = '\0'; /* ready for later strcats */
|
0
|
621 #endif /* SYSV_IPC */
|
|
622
|
151
|
623 if (suppress_windows_system)
|
149
|
624 {
|
151
|
625 char *term = getenv ("TERM");
|
|
626 if (!term)
|
|
627 {
|
|
628 fprintf (stderr, "%s: unknown terminal type\n", progname);
|
|
629 exit (1);
|
|
630 }
|
|
631 sprintf (command, "(gnuserv-edit-files '(tty %s %s %d) '(",
|
153
|
632 clean_string (tty), clean_string (term), (int)getpid ());
|
149
|
633 }
|
151
|
634 else /* !suppress_windows_system */
|
|
635 {
|
286
|
636 if (display)
|
|
637 sprintf (command, "(gnuserv-edit-files '(x %s) '(",
|
|
638 clean_string (display));
|
|
639 #ifdef HAVE_MS_WINDOWS
|
|
640 else
|
|
641 sprintf (command, "(gnuserv-edit-files '(mswindows nil) '(");
|
|
642 #endif
|
151
|
643 } /* !suppress_windows_system */
|
|
644 send_string (s, command);
|
149
|
645
|
151
|
646 if (!argv[i])
|
|
647 nofiles = 1;
|
0
|
648
|
151
|
649 for (; argv[i]; i++)
|
0
|
650 {
|
151
|
651 if (i < argc - 1 && *argv[i] == '+')
|
|
652 starting_line = atoi (argv[i++]);
|
|
653 else
|
|
654 starting_line = 1;
|
|
655 /* If the last argument is +something, treat it as a file. */
|
|
656 if (i == argc)
|
|
657 {
|
|
658 starting_line = 1;
|
|
659 --i;
|
|
660 }
|
|
661 filename_expand (fullpath, argv[i]);
|
0
|
662 #ifdef INTERNET_DOMAIN_SOCKETS
|
412
|
663 path = malloc (strlen (remotepath) + strlen (fullpath) + 1);
|
151
|
664 sprintf (path, "%s%s", remotepath, fullpath);
|
|
665 #else
|
153
|
666 path = my_strdup (fullpath);
|
0
|
667 #endif
|
151
|
668 sprintf (command, "(%d . %s)", starting_line, clean_string (path));
|
|
669 send_string (s, command);
|
|
670 free (path);
|
|
671 } /* for */
|
|
672
|
|
673 sprintf (command, ")%s%s",
|
|
674 (quick || (nofiles && !suppress_windows_system)) ? " 'quick" : "",
|
|
675 view ? " 'view" : "");
|
149
|
676 send_string (s, command);
|
151
|
677 send_string (s, ")");
|
0
|
678
|
|
679 #ifdef SYSV_IPC
|
151
|
680 if (connect_type == (int) CONN_IPC)
|
|
681 disconnect_from_ipc_server (s, msgp, FALSE);
|
0
|
682 #else /* !SYSV_IPC */
|
151
|
683 if (connect_type != (int) CONN_IPC)
|
|
684 disconnect_from_server (s, FALSE);
|
0
|
685 #endif /* !SYSV_IPC */
|
151
|
686 } /* not batch */
|
|
687
|
0
|
688
|
78
|
689 return 0;
|
0
|
690
|
|
691 } /* main */
|
|
692
|
|
693 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
|