annotate lib-src/gnuclient.c @ 5905:85fd1ab80057

Fix a bug in #'parse-integer with negative bignums and non-nil JUNK-ALLOWED src/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * data.c (parse_integer): Fix a bug here with the interaction of negative bignums and a non-zero JUNK-ALLOWED argument. tests/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: Check for a bug just fixed with the interaction of negative bignums and :junk-allowed non-nil.
author Aidan Kehoe <kehoea@parhasard.net>
date Fri, 08 May 2015 16:24:57 +0100
parents 308d34e9f07d
children 0f2338afbabf
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5225
diff changeset
9 XEmacs is free software: you can redistribute it and/or modify it
428
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5225
diff changeset
11 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5225
diff changeset
12 option) any later version.
428
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5225
diff changeset
20 along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Author: Andy Norman (ange@hplb.hpl.hp.com), based on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 'etc/emacsclient.c' from the GNU Emacs 18.52 distribution.
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 Please mail bugs and suggestions to the XEmacs maintainer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
27 /* #### 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
28 Windows. (i.e. its entry point should be WinMain.) gnuattach functionality,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
29 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
30 calls the i.exe wrapper program, to obtain stdio handles.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
31
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
32 #### For that matter, both the functionality of gnuclient and gnuserv
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
33 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
34 Netscape and other modern programs.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
35
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
36 --ben */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
37
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 * GNUATTACH support added by Ben Wing <wing@xemacs.org>.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 * 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
43 *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 * (If gnuserv came bundled with your emacs, the README file is probably
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 * ../etc/gnuserv.README relative to the directory containing this file)
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
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
48 #ifdef CYGWIN
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
49 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
50 #endif
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
51
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 442
diff changeset
52 #include "gnuserv.h"
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 881
diff changeset
53 #include "compiler.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 442
diff changeset
55 char gnuserv_version[] = "gnuclient version " GNUSERV_VERSION;
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 442
diff changeset
56
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 #include "getopt.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 #include <sysfile.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 #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 !defined(INTERNET_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 main (int argc, char *argv[])
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 fprintf (stderr, "Sorry, the Emacs server is only "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 "supported on systems that have\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 fprintf (stderr, "Unix Domain sockets, Internet Domain "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 "sockets or System V IPC.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 } /* main */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
2424
c164e88b1977 [xemacs-hg @ 2004-12-06 23:23:41 by ben]
ben
parents: 2286
diff changeset
74 static char cwd[QXE_PATH_MAX+2];/* current working directory when calculated */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 static char *cp = NULL; /* ptr into valid bit of cwd above */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
2424
c164e88b1977 [xemacs-hg @ 2004-12-06 23:23:41 by ben]
ben
parents: 2286
diff changeset
77 static pid_t emacs_pid; /* Process id for emacs process */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 void initialize_signals (void);
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 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 881
diff changeset
82 tell_emacs_to_resume (int UNUSED (sig))
428
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 char buffer[GSERV_BUFSZ+1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 int s; /* socket / msqid to server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 int connect_type; /* CONN_UNIX, CONN_INTERNET, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 ONN_IPC */
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 /* Why is SYSV so retarded? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 /* We want emacs to realize that we are resuming */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 #ifdef SIGCONT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 signal(SIGCONT, tell_emacs_to_resume);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
95 connect_type = make_connection (NULL, 0, &s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 sprintf(buffer,"(gnuserv-eval '(resume-pid-console %d))", (int)getpid());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 send_string(s, buffer);
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 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 if (connect_type == (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 disconnect_from_ipc_server (s, msgp, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 #else /* !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_server (s, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 #endif /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 pass_signal_to_emacs (int sig)
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 if (kill (emacs_pid, sig) == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 fprintf (stderr, "gnuattach: Could not pass signal to emacs process\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 exit (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 initialize_signals ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 }
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 void
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
121 initialize_signals (void)
428
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 /* Set up signal handler to pass relevant signals to emacs process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 We used to send SIGSEGV, SIGBUS, SIGPIPE, SIGILL and others to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 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
126 Emacs should SIGSEGV whenever gnuclient SIGSEGV-s, etc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 signal (SIGQUIT, pass_signal_to_emacs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 signal (SIGINT, pass_signal_to_emacs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 #ifdef SIGWINCH
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 signal (SIGWINCH, pass_signal_to_emacs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 #ifdef SIGCONT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 /* We want emacs to realize that we are resuming */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 signal (SIGCONT, tell_emacs_to_resume);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 #endif
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
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 get_current_working_directory -- return the cwd.
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 static char *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 get_current_working_directory (void)
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 if (cp == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 { /* haven't calculated it yet */
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
148 #ifdef HAVE_GETCWD
2424
c164e88b1977 [xemacs-hg @ 2004-12-06 23:23:41 by ben]
ben
parents: 2286
diff changeset
149 if (getcwd (cwd,QXE_PATH_MAX) == NULL)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
150 #else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 if (getwd (cwd) == 0)
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
152 #endif /* HAVE_GETCWD */
428
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 perror (progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 fprintf (stderr, "%s: unable to get current working directory\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 } /* if */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 /* on some systems, cwd can look like '@machine/' ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 /* ignore everything before the first '/' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 for (cp = cwd; *cp && *cp != '/'; ++cp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 } /* if */
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 return cp;
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 } /* get_current_working_directory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170
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 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 filename_expand -- try to convert the given filename into a fully-qualified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 pathname.
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 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 filename_expand (char *fullpath, char *filename)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 /* fullpath - returned full pathname */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 /* filename - filename to expand */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 {
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
181 #ifdef CYGWIN
2424
c164e88b1977 [xemacs-hg @ 2004-12-06 23:23:41 by ben]
ben
parents: 2286
diff changeset
182 char cygwinFilename[QXE_PATH_MAX+1];
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 464
diff changeset
183 extern void cygwin_conv_to_posix_path(const char *, char *);
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
184 #endif
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
185
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 int len;
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
187 fullpath[0] = fullpath[QXE_PATH_MAX] = '\0';
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
464
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
189 #ifdef CYGWIN
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
190 /*
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
191 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
192 */
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
193 cygwin_conv_to_posix_path(filename, cygwinFilename);
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
194 filename = cygwinFilename;
5aa1854ad537 Import from CVS: tag r21-2-47
cvs
parents: 462
diff changeset
195 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 if (filename[0] && filename[0] == '/')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 /* Absolute (unix-style) pathname. Do nothing */
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
200 strncat (fullpath, filename, QXE_PATH_MAX);
428
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 /* Assume relative Unix style path. Get the current directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 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
206 "\foo", where we need to get the current drive. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
207
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
208 strncat (fullpath, get_current_working_directory (), QXE_PATH_MAX);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 len = strlen (fullpath);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
211 /* If no trailing slash, add one */
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
212 if (len <= 0 || (fullpath[len - 1] != '/' && len < QXE_PATH_MAX))
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
213 {
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
214 strcat (fullpath, "/");
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
215 len++;
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
216 }
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
217
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 /* Don't forget to add the filename! */
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
219 strncat (fullpath, filename, QXE_PATH_MAX - len);
428
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 {
4684
15c42a3f4065 Do not move cursor position in gnuclient started buffer if user did
It's me FKtPp \;) <m_pupil@yahoo.com.cn>
parents: 3556
diff changeset
299 int starting_line = 0; /* line to start editing at */
5225
1086297242fe Don't throw an error if gnuclient supports GTK and XEmacs doesn't.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4759
diff changeset
300 char command[QXE_PATH_MAX + 512];/* emacs command buffer */
2424
c164e88b1977 [xemacs-hg @ 2004-12-06 23:23:41 by ben]
ben
parents: 2286
diff changeset
301 char fullpath[QXE_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 */
2424
c164e88b1977 [xemacs-hg @ 2004-12-06 23:23:41 by ben]
ben
parents: 2286
diff changeset
320 char remotepath[QXE_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");
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
438 strncpy (remotepath, remotearg, QXE_PATH_MAX);
428
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 */
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
593 strncpy (remotepath, ptr, QXE_PATH_MAX);
428
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! */
4759
aa5ed11f473b Remove support for obsolete systems. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 4684
diff changeset
596 #if defined (hp9000s800)
428
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)
5225
1086297242fe Don't throw an error if gnuclient supports GTK and XEmacs doesn't.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4759
diff changeset
645 sprintf (command,
1086297242fe Don't throw an error if gnuclient supports GTK and XEmacs doesn't.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4759
diff changeset
646 /* #### We should probably do this sort of thing for
1086297242fe Don't throw an error if gnuclient supports GTK and XEmacs doesn't.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4759
diff changeset
647 other window systems. */
1086297242fe Don't throw an error if gnuclient supports GTK and XEmacs doesn't.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4759
diff changeset
648 "(gnuserv-edit-files (assoc* t '((gtk nil) (x %s)) "
1086297242fe Don't throw an error if gnuclient supports GTK and XEmacs doesn't.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4759
diff changeset
649 ":key #'valid-device-type-p) '(", clean_string (display));
462
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++]);
4684
15c42a3f4065 Do not move cursor position in gnuclient started buffer if user did
It's me FKtPp \;) <m_pupil@yahoo.com.cn>
parents: 3556
diff changeset
665
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 /* If the last argument is +something, treat it as a file. */
4684
15c42a3f4065 Do not move cursor position in gnuclient started buffer if user did
It's me FKtPp \;) <m_pupil@yahoo.com.cn>
parents: 3556
diff changeset
667 if (i == argc) --i;
15c42a3f4065 Do not move cursor position in gnuclient started buffer if user did
It's me FKtPp \;) <m_pupil@yahoo.com.cn>
parents: 3556
diff changeset
668
428
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
4684
15c42a3f4065 Do not move cursor position in gnuclient started buffer if user did
It's me FKtPp \;) <m_pupil@yahoo.com.cn>
parents: 3556
diff changeset
676 if ( starting_line ) {
15c42a3f4065 Do not move cursor position in gnuclient started buffer if user did
It's me FKtPp \;) <m_pupil@yahoo.com.cn>
parents: 3556
diff changeset
677 sprintf (command, "(%d . %s)", starting_line, clean_string (path));
15c42a3f4065 Do not move cursor position in gnuclient started buffer if user did
It's me FKtPp \;) <m_pupil@yahoo.com.cn>
parents: 3556
diff changeset
678 } else {
15c42a3f4065 Do not move cursor position in gnuclient started buffer if user did
It's me FKtPp \;) <m_pupil@yahoo.com.cn>
parents: 3556
diff changeset
679 sprintf (command, "(nil . %s)", clean_string (path));
15c42a3f4065 Do not move cursor position in gnuclient started buffer if user did
It's me FKtPp \;) <m_pupil@yahoo.com.cn>
parents: 3556
diff changeset
680 }
15c42a3f4065 Do not move cursor position in gnuclient started buffer if user did
It's me FKtPp \;) <m_pupil@yahoo.com.cn>
parents: 3556
diff changeset
681
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 send_string (s, command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 free (path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 } /* for */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 sprintf (command, ")%s%s",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 (quick || (nofiles && !suppress_windows_system)) ? " 'quick" : "",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 view ? " 'view" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 send_string (s, command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 send_string (s, ")");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 if (connect_type == (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 disconnect_from_ipc_server (s, msgp, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 #else /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 if (connect_type != (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 disconnect_from_server (s, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 #endif /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 } /* not batch */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 } /* main */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */