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