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