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