annotate lib-src/gnuclient.c @ 557:f486da5f1a3b

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