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