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