annotate lib-src/gnuclient.c @ 370:bd866891f083

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