annotate lib-src/gnuclient.c @ 412:697ef44129c6 r21-2-14

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