annotate lib-src/gnuclient.c @ 2286:04bc9d2f42c7

[xemacs-hg @ 2004-09-20 19:18:55 by james] Mark all unused parameters as unused. Also eliminate some unneeded local variables.
author james
date Mon, 20 Sep 2004 19:20:08 +0000
parents dfee0026a079
children c164e88b1977
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"
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 881
diff changeset
56 #include "compiler.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 442
diff changeset
58 char gnuserv_version[] = "gnuclient version " GNUSERV_VERSION;
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 442
diff changeset
59
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 #include "getopt.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 #include <sysfile.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 !defined(INTERNET_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 fprintf (stderr, "Sorry, the Emacs server is only "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 "supported on systems that have\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 fprintf (stderr, "Unix Domain sockets, Internet Domain "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 "sockets or System V IPC.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 } /* main */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
77 static char cwd[PATH_MAX+2]; /* current working directory when calculated */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 static char *cp = NULL; /* ptr into valid bit of cwd above */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 static pid_t emacs_pid; /* Process id for emacs process */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 void initialize_signals (void);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 881
diff changeset
85 tell_emacs_to_resume (int UNUSED (sig))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 char buffer[GSERV_BUFSZ+1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 int s; /* socket / msqid to server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 int connect_type; /* CONN_UNIX, CONN_INTERNET, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 ONN_IPC */
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 /* Why is SYSV so retarded? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 /* We want emacs to realize that we are resuming */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 #ifdef SIGCONT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 signal(SIGCONT, tell_emacs_to_resume);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
98 connect_type = make_connection (NULL, 0, &s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 sprintf(buffer,"(gnuserv-eval '(resume-pid-console %d))", (int)getpid());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 send_string(s, buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 if (connect_type == (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 disconnect_from_ipc_server (s, msgp, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 #else /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 if (connect_type != (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 disconnect_from_server (s, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 #endif /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 }
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 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 pass_signal_to_emacs (int sig)
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 if (kill (emacs_pid, sig) == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 fprintf (stderr, "gnuattach: Could not pass signal to emacs process\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 initialize_signals ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 }
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 void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
124 initialize_signals (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 /* Set up signal handler to pass relevant signals to emacs process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 We used to send SIGSEGV, SIGBUS, SIGPIPE, SIGILL and others to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 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
129 Emacs should SIGSEGV whenever gnuclient SIGSEGV-s, etc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 signal (SIGQUIT, pass_signal_to_emacs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 signal (SIGINT, pass_signal_to_emacs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 #ifdef SIGWINCH
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 signal (SIGWINCH, pass_signal_to_emacs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 #ifdef SIGCONT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 /* We want emacs to realize that we are resuming */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 signal (SIGCONT, tell_emacs_to_resume);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 get_current_working_directory -- return the cwd.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 static char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 get_current_working_directory (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 if (cp == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 { /* haven't calculated it yet */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
151 #ifdef HAVE_GETCWD
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
152 if (getcwd (cwd,PATH_MAX) == NULL)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
153 #else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 if (getwd (cwd) == 0)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
155 #endif /* HAVE_GETCWD */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 perror (progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 fprintf (stderr, "%s: unable to get current working directory\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 } /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 /* on some systems, cwd can look like '@machine/' ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 /* ignore everything before the first '/' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 for (cp = cwd; *cp && *cp != '/'; ++cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 } /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 return cp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 } /* get_current_working_directory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 filename_expand -- try to convert the given filename into a fully-qualified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 pathname.
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 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 filename_expand (char *fullpath, char *filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 /* fullpath - returned full pathname */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 /* filename - filename to expand */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 {
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
184 #ifdef CYGWIN
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
185 char cygwinFilename[PATH_MAX+1];
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 464
diff changeset
186 extern void cygwin_conv_to_posix_path(const char *, char *);
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
187 #endif
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
188
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 int len;
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
190 fullpath[0] = '\0';
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
192 #ifdef CYGWIN
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
193 /*
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
194 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
195 */
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
196 cygwin_conv_to_posix_path(filename, cygwinFilename);
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
197 filename = cygwinFilename;
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
198 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 if (filename[0] && filename[0] == '/')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 /* Absolute (unix-style) pathname. Do nothing */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 strcat (fullpath, filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 /* Assume relative Unix style path. Get the current directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 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
209 "\foo", where we need to get the current drive. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
210
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 strcat (fullpath, get_current_working_directory ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 len = strlen (fullpath);
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 if (len > 0 && fullpath[len-1] == '/') /* trailing slash already? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 ; /* yep */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 strcat (fullpath, "/"); /* nope, append trailing slash */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 /* Don't forget to add the filename! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 strcat (fullpath,filename);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 } /* filename_expand */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 /* Encase the string in quotes, escape all the backslashes and quotes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 in string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 static char *
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
226 clean_string (const char *s)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 int i = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 char *p, *res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
232 const char *const_p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 for (const_p = s; *const_p; const_p++, i++)
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 if (*const_p == '\\' || *const_p == '\"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 ++i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 else if (*const_p == '\004')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 i += 3;
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 p = res = (char *) malloc (i + 2 + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 *p++ = '\"';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 for (; *s; p++, s++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 switch (*s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 case '\\':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 *p++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 *p = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 case '\"':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 *p++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 *p = '\"';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 case '\004':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 *p++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 *p++ = 'C';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 *p++ = '-';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 *p = 'd';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 *p = *s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 }
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 *p = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 return res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 #define GET_ARGUMENT(var, desc) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 if (*(p + 1)) (var) = p + 1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 else \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 if (!argv[++i]) \
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 fprintf (stderr, "%s: `%s' must be followed by an argument\n", \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 progname, desc); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 exit (1); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (var) = argv[i]; \
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 over = 1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
286 /* A strdup imitation. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 static char *
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
288 my_strdup (const char *s)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
290 char *new_s = (char *) malloc (strlen (s) + 1);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
291 if (new_s)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
292 strcpy (new_s, s);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
293 return new_s;
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 int starting_line = 1; /* line to start editing at */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
300 char command[PATH_MAX+50]; /* emacs command buffer */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
301 char fullpath[PATH_MAX+1]; /* full pathname to file */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 char *eval_form = NULL; /* form to evaluate with `-eval' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 char *eval_function = NULL; /* function to evaluate with `-f' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 char *load_library = NULL; /* library to load */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 int quick = 0; /* quick edit, don't wait for user to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 finish */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 int batch = 0; /* batch mode */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 int view = 0; /* view only. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 int nofiles = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 int errflg = 0; /* option error */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 int s; /* socket / msqid to server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 int connect_type; /* CONN_UNIX, CONN_INTERNET, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 * CONN_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 int suppress_windows_system = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 char *display = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 #ifdef INTERNET_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 char *hostarg = NULL; /* remote hostname */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 char *remotearg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 char thishost[HOSTNAMSZ]; /* this hostname */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
320 char remotepath[PATH_MAX+1]; /* remote pathname */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 char *path;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 int rflg = 0; /* pathname given on cmdline */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 char *portarg;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
324 unsigned short port = 0; /* port to server */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 #endif /* INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 struct msgbuf *msgp; /* message */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 #endif /* SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 char *tty = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 char buffer[GSERV_BUFSZ + 1]; /* buffer to read pid */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 char result[GSERV_BUFSZ + 1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 #ifdef INTERNET_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 memset (remotepath, 0, sizeof (remotepath));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 #endif /* INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 progname = strrchr (argv[0], '/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 if (progname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 ++progname;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 progname = argv[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
344 #ifdef WIN32_NATIVE
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
345 tmpdir = getenv ("TEMP");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
346 if (!tmpdir)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
347 tmpdir = getenv ("TMP");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
348 if (!tmpdir)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
349 tmpdir = "c:\\";
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
350 #else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 #ifdef USE_TMPDIR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 tmpdir = getenv ("TMPDIR");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 if (!tmpdir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 tmpdir = "/tmp";
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
356 #endif /* WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 display = getenv ("DISPLAY");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 if (display)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 display = my_strdup (display);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 #ifndef HAVE_MS_WINDOWS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 suppress_windows_system = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 for (i = 1; argv[i] && !errflg; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 if (*argv[i] != '-')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 else if (*argv[i] == '-'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 && (*(argv[i] + 1) == '\0'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 || (*(argv[i] + 1) == '-' && *(argv[i] + 2) == '\0')))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 /* `-' or `--' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 ++i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 }
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 if (!strcmp (argv[i], "-batch") || !strcmp (argv[i], "--batch"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 batch = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 else if (!strcmp (argv[i], "-eval") || !strcmp (argv[i], "--eval"))
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 if (!argv[++i])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 fprintf (stderr, "%s: `-eval' must be followed by an argument\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 eval_form = argv[i];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 else if (!strcmp (argv[i], "-display") || !strcmp (argv[i], "--display"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 suppress_windows_system = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 if (!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 fprintf (stderr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 "%s: `-display' must be followed by an argument\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 exit (1);
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 if (display)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 free (display);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 /* no need to strdup. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 display = argv[i];
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 else if (!strcmp (argv[i], "-nw"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 suppress_windows_system = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 /* Iterate over one-letter options. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 char *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 int over = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 for (p = argv[i] + 1; *p && !over; p++)
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 switch (*p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 case 'q':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 quick = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 case 'v':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 view = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 case 'f':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 GET_ARGUMENT (eval_function, "-f");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 case 'l':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 GET_ARGUMENT (load_library, "-l");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 #ifdef INTERNET_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 case 'h':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 GET_ARGUMENT (hostarg, "-h");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 case 'p':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 GET_ARGUMENT (portarg, "-p");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 port = atoi (portarg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 case 'r':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 GET_ARGUMENT (remotearg, "-r");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 strcpy (remotepath, remotearg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 rflg = 1;
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 #endif /* INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 errflg = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 } /* for */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 } /* else */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 } /* for */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 if (errflg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 fprintf (stderr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 #ifdef INTERNET_DOMAIN_SOCKETS
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
453 "Usage: %s [-nw] [-display display] [-q] [-v] [-l library]\n"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 " [-batch] [-f function] [-eval form]\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 " [-h host] [-p port] [-r remote-path] [[+line] file] ...\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 #else /* !INTERNET_DOMAIN_SOCKETS */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
457 "Usage: %s [-nw] [-q] [-v] [-l library] [-f function] [-eval form] "
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 "[[+line] path] ...\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 #endif /* !INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 if (batch && argv[i])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 fprintf (stderr, "%s: Cannot specify `-batch' with file names\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 }
881
dfee0026a079 [xemacs-hg @ 2002-06-25 08:09:01 by stephent]
stephent
parents: 771
diff changeset
469 #if defined(INTERNET_DOMAIN_SOCKETS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 if (suppress_windows_system && hostarg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 fprintf (stderr, "%s: Remote editing is available only on X\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 }
881
dfee0026a079 [xemacs-hg @ 2002-06-25 08:09:01 by stephent]
stephent
parents: 771
diff changeset
476 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 *result = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 if (eval_function || eval_form || load_library)
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 #if defined(INTERNET_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 connect_type = make_connection (hostarg, port, &s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 #else
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
483 connect_type = make_connection (NULL, 0, &s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 sprintf (command, "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 send_string (s, command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 if (load_library)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 send_string (s , "(load-library ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 send_string (s, clean_string(load_library));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 send_string (s, ") ");
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 if (eval_form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 send_string (s, eval_form);
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_function)
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, "(");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 send_string (s, eval_function);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 send_string (s, ")");
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 /* disconnect already sends EOT_STR */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 if (connect_type == (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 disconnect_from_ipc_server (s, msgp, batch && !quick);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 #else /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 if (connect_type != (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 disconnect_from_server (s, batch && !quick);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 #endif /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 } /* eval_function || eval_form || load_library */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 else if (batch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 /* no sexp on the command line, so read it from stdin */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 int nb;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 #if defined(INTERNET_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 connect_type = make_connection (hostarg, port, &s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 #else
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
521 connect_type = make_connection (NULL, 0, &s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 sprintf (command, "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 send_string (s, command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 while ((nb = read(fileno(stdin), buffer, GSERV_BUFSZ-1)) > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 buffer[nb] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 send_string(s, buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 send_string(s,"))");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 /* disconnect already sends EOT_STR */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 if (connect_type == (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 disconnect_from_ipc_server (s, msgp, batch && !quick);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 #else /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 if (connect_type != (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 disconnect_from_server (s, batch && !quick);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 #endif /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 if (!batch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 if (suppress_windows_system)
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 tty = ttyname (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 if (!tty)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 fprintf (stderr, "%s: Not connected to a tty", progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 #if defined(INTERNET_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 connect_type = make_connection (hostarg, port, &s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 #else
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
555 connect_type = make_connection (NULL, 0, &s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 send_string (s, "(gnuserv-eval '(emacs-pid))");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 send_string (s, EOT_STR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 if (read_line (s, buffer) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 fprintf (stderr, "%s: Could not establish Emacs process id\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
566 /* Don't do disconnect_from_server because we have already read
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 data, and disconnect doesn't do anything else. */
881
dfee0026a079 [xemacs-hg @ 2002-06-25 08:09:01 by stephent]
stephent
parents: 771
diff changeset
568 #ifdef SYSV_IPC
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 if (connect_type == (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 disconnect_from_ipc_server (s, msgp, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 #endif /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 emacs_pid = (pid_t)atol(buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 initialize_signals();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 } /* suppress_windows_system */
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 #if defined(INTERNET_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 connect_type = make_connection (hostarg, port, &s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 #else
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
580 connect_type = make_connection (NULL, 0, &s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 #ifdef INTERNET_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 if (connect_type == (int) CONN_INTERNET)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 char *ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 gethostname (thishost, HOSTNAMSZ);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 if (!rflg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 { /* attempt to generate a path
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 * to this machine */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 if ((ptr = getenv ("GNU_NODE")) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 /* user specified a path */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 strcpy (remotepath, ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 #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
596 #if defined (hp9000s300) || defined (hp9000s800)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 else if (strcmp (thishost,hostarg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 { /* try /net/thishost */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 strcpy (remotepath, "/net/"); /* (this fails using internet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 addresses) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 strcat (remotepath, thishost);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 { /* same machines, no need for path */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 remotepath[0] = '\0'; /* default is the empty path */
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 #endif /* INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 if ((msgp = (struct msgbuf *)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 malloc (sizeof *msgp + GSERV_BUFSZ)) == NULL)
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 fprintf (stderr, "%s: not enough memory for message buffer\n", progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 } /* if */
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 msgp->mtext[0] = '\0'; /* ready for later strcats */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 #endif /* SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 if (suppress_windows_system)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 char *term = getenv ("TERM");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 if (!term)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 fprintf (stderr, "%s: unknown terminal type\n", progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 sprintf (command, "(gnuserv-edit-files '(tty %s %s %d) '(",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 clean_string (tty), clean_string (term), (int)getpid ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 else /* !suppress_windows_system */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 {
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
636 if (0)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
637 ;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
638 #ifdef HAVE_X_WINDOWS
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
639 else if (display)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 sprintf (command, "(gnuserv-edit-files '(x %s) '(",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 clean_string (display));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
642 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
643 #ifdef HAVE_GTK
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
644 else if (display)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
645 strcpy (command, "(gnuserv-edit-files '(gtk nil) '(");
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
646 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 #ifdef HAVE_MS_WINDOWS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 sprintf (command, "(gnuserv-edit-files '(mswindows nil) '(");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 } /* !suppress_windows_system */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 send_string (s, command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 if (!argv[i])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 nofiles = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 for (; argv[i]; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 if (i < argc - 1 && *argv[i] == '+')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 starting_line = atoi (argv[i++]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 starting_line = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 /* If the last argument is +something, treat it as a file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 if (i == argc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 {
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 --i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 filename_expand (fullpath, argv[i]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 #ifdef INTERNET_DOMAIN_SOCKETS
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
671 path = (char *) malloc (strlen (remotepath) + strlen (fullpath) + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 sprintf (path, "%s%s", remotepath, fullpath);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 path = my_strdup (fullpath);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 sprintf (command, "(%d . %s)", starting_line, clean_string (path));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 send_string (s, command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 free (path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 } /* for */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 sprintf (command, ")%s%s",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 (quick || (nofiles && !suppress_windows_system)) ? " 'quick" : "",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 view ? " 'view" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 send_string (s, command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 send_string (s, ")");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 if (connect_type == (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 disconnect_from_ipc_server (s, msgp, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 #else /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 if (connect_type != (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 disconnect_from_server (s, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 #endif /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 } /* not batch */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 } /* main */
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 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */