annotate lib-src/gnuclient.c @ 5258:1ed4cefddd12

Add a couple of extra docstring backslashes, #'format-time-string 2010-09-05 Aidan Kehoe <kehoea@parhasard.net> * editfns.c (Fformat_time_string): Use two backslashes so that there is at least one present in the output of describe function, when describing the Roman month number syntax in this function's docstring. Thanks for provoking me to look at this, Stephen Turnbull.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 05 Sep 2010 19:22:37 +0100
parents 1086297242fe
children 308d34e9f07d
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
2424
c164e88b1977 [xemacs-hg @ 2004-12-06 23:23:41 by ben]
ben
parents: 2286
diff changeset
77 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
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
2424
c164e88b1977 [xemacs-hg @ 2004-12-06 23:23:41 by ben]
ben
parents: 2286
diff changeset
80 static pid_t emacs_pid; /* Process id for emacs process */
428
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
2424
c164e88b1977 [xemacs-hg @ 2004-12-06 23:23:41 by ben]
ben
parents: 2286
diff changeset
152 if (getcwd (cwd,QXE_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
2424
c164e88b1977 [xemacs-hg @ 2004-12-06 23:23:41 by ben]
ben
parents: 2286
diff changeset
185 char cygwinFilename[QXE_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;
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
190 fullpath[0] = fullpath[QXE_PATH_MAX] = '\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 */
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
203 strncat (fullpath, filename, QXE_PATH_MAX);
428
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
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
211 strncat (fullpath, get_current_working_directory (), QXE_PATH_MAX);
428
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
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
214 /* If no trailing slash, add one */
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
215 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
216 {
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
217 strcat (fullpath, "/");
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
218 len++;
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
219 }
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
220
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 /* Don't forget to add the filename! */
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
222 strncat (fullpath, filename, QXE_PATH_MAX - len);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 } /* filename_expand */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 /* Encase the string in quotes, escape all the backslashes and quotes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 in string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 static char *
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
229 clean_string (const char *s)
428
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 int i = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 char *p, *res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
235 const char *const_p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 for (const_p = s; *const_p; const_p++, i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 if (*const_p == '\\' || *const_p == '\"')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 ++i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 else if (*const_p == '\004')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 i += 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 p = res = (char *) malloc (i + 2 + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 *p++ = '\"';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 for (; *s; p++, s++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 switch (*s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 case '\\':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 *p++ = '\\';
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 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 case '\"':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 *p++ = '\\';
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 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 case '\004':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 *p++ = '\\';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 *p++ = 'C';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 *p++ = '-';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 *p = 'd';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 *p = *s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 *p++ = '\"';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 *p = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 return res;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 #define GET_ARGUMENT(var, desc) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 if (*(p + 1)) (var) = p + 1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 else \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 if (!argv[++i]) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 fprintf (stderr, "%s: `%s' must be followed by an argument\n", \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 progname, desc); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 exit (1); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (var) = argv[i]; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 over = 1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
289 /* A strdup imitation. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 static char *
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
291 my_strdup (const char *s)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
293 char *new_s = (char *) malloc (strlen (s) + 1);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
294 if (new_s)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
295 strcpy (new_s, s);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
296 return new_s;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 main (int argc, char *argv[])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 {
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
302 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
303 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
304 char fullpath[QXE_PATH_MAX+1];/* full pathname to file */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 char *eval_form = NULL; /* form to evaluate with `-eval' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 char *eval_function = NULL; /* function to evaluate with `-f' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 char *load_library = NULL; /* library to load */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 int quick = 0; /* quick edit, don't wait for user to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 finish */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 int batch = 0; /* batch mode */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 int view = 0; /* view only. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 int nofiles = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 int errflg = 0; /* option error */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 int s; /* socket / msqid to server */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 int connect_type; /* CONN_UNIX, CONN_INTERNET, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 * CONN_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 int suppress_windows_system = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 char *display = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 #ifdef INTERNET_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 char *hostarg = NULL; /* remote hostname */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 char *remotearg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 char thishost[HOSTNAMSZ]; /* this hostname */
2424
c164e88b1977 [xemacs-hg @ 2004-12-06 23:23:41 by ben]
ben
parents: 2286
diff changeset
323 char remotepath[QXE_PATH_MAX+1]; /* remote pathname */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 char *path;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 int rflg = 0; /* pathname given on cmdline */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 char *portarg;
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
327 unsigned short port = 0; /* port to server */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 #endif /* INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 struct msgbuf *msgp; /* message */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 #endif /* SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 char *tty = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 char buffer[GSERV_BUFSZ + 1]; /* buffer to read pid */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 char result[GSERV_BUFSZ + 1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 #ifdef INTERNET_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 memset (remotepath, 0, sizeof (remotepath));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 #endif /* INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 progname = strrchr (argv[0], '/');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 if (progname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 ++progname;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 progname = argv[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
347 #ifdef WIN32_NATIVE
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
348 tmpdir = getenv ("TEMP");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
349 if (!tmpdir)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
350 tmpdir = getenv ("TMP");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
351 if (!tmpdir)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
352 tmpdir = "c:\\";
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
353 #else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 #ifdef USE_TMPDIR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 tmpdir = getenv ("TMPDIR");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 if (!tmpdir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 tmpdir = "/tmp";
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 502
diff changeset
359 #endif /* WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 display = getenv ("DISPLAY");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 if (display)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 display = my_strdup (display);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 #ifndef HAVE_MS_WINDOWS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 suppress_windows_system = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 for (i = 1; argv[i] && !errflg; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 if (*argv[i] != '-')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 else if (*argv[i] == '-'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 && (*(argv[i] + 1) == '\0'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 || (*(argv[i] + 1) == '-' && *(argv[i] + 2) == '\0')))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 /* `-' or `--' */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 ++i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 if (!strcmp (argv[i], "-batch") || !strcmp (argv[i], "--batch"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 batch = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 else if (!strcmp (argv[i], "-eval") || !strcmp (argv[i], "--eval"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 if (!argv[++i])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 fprintf (stderr, "%s: `-eval' must be followed by an argument\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 eval_form = argv[i];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 else if (!strcmp (argv[i], "-display") || !strcmp (argv[i], "--display"))
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 suppress_windows_system = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 if (!argv[++i])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 fprintf (stderr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 "%s: `-display' must be followed by an argument\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 if (display)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 free (display);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 /* no need to strdup. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 display = argv[i];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 else if (!strcmp (argv[i], "-nw"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 suppress_windows_system = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 /* Iterate over one-letter options. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 char *p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 int over = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 for (p = argv[i] + 1; *p && !over; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 switch (*p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 case 'q':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 quick = 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 'v':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 view = 1;
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 'f':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 GET_ARGUMENT (eval_function, "-f");
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 case 'l':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 GET_ARGUMENT (load_library, "-l");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 #ifdef INTERNET_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 case 'h':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 GET_ARGUMENT (hostarg, "-h");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 case 'p':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 GET_ARGUMENT (portarg, "-p");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 port = atoi (portarg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 case 'r':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 GET_ARGUMENT (remotearg, "-r");
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
441 strncpy (remotepath, remotearg, QXE_PATH_MAX);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 rflg = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 #endif /* INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 errflg = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 } /* for */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 } /* else */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 } /* for */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 if (errflg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 fprintf (stderr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 #ifdef INTERNET_DOMAIN_SOCKETS
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
456 "Usage: %s [-nw] [-display display] [-q] [-v] [-l library]\n"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 " [-batch] [-f function] [-eval form]\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 " [-h host] [-p port] [-r remote-path] [[+line] file] ...\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 #else /* !INTERNET_DOMAIN_SOCKETS */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
460 "Usage: %s [-nw] [-q] [-v] [-l library] [-f function] [-eval form] "
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 "[[+line] path] ...\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 #endif /* !INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 if (batch && argv[i])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 fprintf (stderr, "%s: Cannot specify `-batch' with file names\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 }
881
dfee0026a079 [xemacs-hg @ 2002-06-25 08:09:01 by stephent]
stephent
parents: 771
diff changeset
472 #if defined(INTERNET_DOMAIN_SOCKETS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 if (suppress_windows_system && hostarg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 fprintf (stderr, "%s: Remote editing is available only on X\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 }
881
dfee0026a079 [xemacs-hg @ 2002-06-25 08:09:01 by stephent]
stephent
parents: 771
diff changeset
479 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 *result = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 if (eval_function || eval_form || load_library)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 #if defined(INTERNET_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 connect_type = make_connection (hostarg, port, &s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 #else
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
486 connect_type = make_connection (NULL, 0, &s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 sprintf (command, "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 send_string (s, command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 if (load_library)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 send_string (s , "(load-library ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 send_string (s, clean_string(load_library));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 send_string (s, ") ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 if (eval_form)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 send_string (s, eval_form);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 if (eval_function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 send_string (s, "(");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 send_string (s, eval_function);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 send_string (s, ")");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 send_string (s, "))");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 /* disconnect already sends EOT_STR */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 #ifdef 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_ipc_server (s, msgp, batch && !quick);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 #else /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 if (connect_type != (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 disconnect_from_server (s, batch && !quick);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 #endif /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 } /* eval_function || eval_form || load_library */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 else if (batch)
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 /* no sexp on the command line, so read it from stdin */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 int nb;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 #if defined(INTERNET_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 connect_type = make_connection (hostarg, port, &s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 #else
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
524 connect_type = make_connection (NULL, 0, &s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 sprintf (command, "(gnuserv-eval%s '(progn ", quick ? "-quickly" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 send_string (s, command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 while ((nb = read(fileno(stdin), buffer, GSERV_BUFSZ-1)) > 0)
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 buffer[nb] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 send_string(s, buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 send_string(s,"))");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 /* disconnect already sends EOT_STR */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 #ifdef 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_ipc_server (s, msgp, batch && !quick);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 #else /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 if (connect_type != (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 disconnect_from_server (s, batch && !quick);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 #endif /* !SYSV_IPC */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 if (!batch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 if (suppress_windows_system)
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 tty = ttyname (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 if (!tty)
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 fprintf (stderr, "%s: Not connected to a tty", progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 #if defined(INTERNET_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 connect_type = make_connection (hostarg, port, &s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 #else
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
558 connect_type = make_connection (NULL, 0, &s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 send_string (s, "(gnuserv-eval '(emacs-pid))");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 send_string (s, EOT_STR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 if (read_line (s, buffer) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 fprintf (stderr, "%s: Could not establish Emacs process id\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
569 /* Don't do disconnect_from_server because we have already read
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 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
571 #ifdef SYSV_IPC
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 if (connect_type == (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 disconnect_from_ipc_server (s, msgp, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 #endif /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 emacs_pid = (pid_t)atol(buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 initialize_signals();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 } /* suppress_windows_system */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 #if defined(INTERNET_DOMAIN_SOCKETS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 connect_type = make_connection (hostarg, port, &s);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 #else
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
583 connect_type = make_connection (NULL, 0, &s);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 #endif
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 #ifdef INTERNET_DOMAIN_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 if (connect_type == (int) CONN_INTERNET)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 char *ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 gethostname (thishost, HOSTNAMSZ);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 if (!rflg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 { /* attempt to generate a path
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 * to this machine */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 if ((ptr = getenv ("GNU_NODE")) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 /* user specified a path */
3556
2161ac78b41e [xemacs-hg @ 2006-08-11 17:37:17 by james]
james
parents: 2424
diff changeset
596 strncpy (remotepath, ptr, QXE_PATH_MAX);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 #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
599 #if defined (hp9000s800)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 else if (strcmp (thishost,hostarg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 { /* try /net/thishost */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 strcpy (remotepath, "/net/"); /* (this fails using internet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 addresses) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 strcat (remotepath, thishost);
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 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 { /* same machines, no need for path */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 remotepath[0] = '\0'; /* default is the empty path */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 #endif /* INTERNET_DOMAIN_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 #ifdef SYSV_IPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 if ((msgp = (struct msgbuf *)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 malloc (sizeof *msgp + GSERV_BUFSZ)) == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 fprintf (stderr, "%s: not enough memory for message buffer\n", progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 } /* if */
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 msgp->mtext[0] = '\0'; /* ready for later strcats */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 #endif /* SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 if (suppress_windows_system)
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 char *term = getenv ("TERM");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 if (!term)
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 fprintf (stderr, "%s: unknown terminal type\n", progname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 exit (1);
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 sprintf (command, "(gnuserv-edit-files '(tty %s %s %d) '(",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 clean_string (tty), clean_string (term), (int)getpid ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 else /* !suppress_windows_system */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 {
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
639 if (0)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
640 ;
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
641 #ifdef HAVE_X_WINDOWS
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
642 else if (display)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 sprintf (command, "(gnuserv-edit-files '(x %s) '(",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 clean_string (display));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
645 #endif
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
646 #ifdef HAVE_GTK
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
647 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
648 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
649 /* #### 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
650 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
651 "(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
652 ":key #'valid-device-type-p) '(", clean_string (display));
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 458
diff changeset
653 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 #ifdef HAVE_MS_WINDOWS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 sprintf (command, "(gnuserv-edit-files '(mswindows nil) '(");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 } /* !suppress_windows_system */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 send_string (s, command);
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 if (!argv[i])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 nofiles = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 for (; argv[i]; i++)
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 if (i < argc - 1 && *argv[i] == '+')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 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
668
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 /* 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
670 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
671
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 filename_expand (fullpath, argv[i]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 #ifdef INTERNET_DOMAIN_SOCKETS
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
674 path = (char *) malloc (strlen (remotepath) + strlen (fullpath) + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 sprintf (path, "%s%s", remotepath, fullpath);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 path = my_strdup (fullpath);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 #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
679 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
680 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
681 } 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
682 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
683 }
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
684
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 send_string (s, command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 free (path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 } /* for */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 sprintf (command, ")%s%s",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 (quick || (nofiles && !suppress_windows_system)) ? " 'quick" : "",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 view ? " 'view" : "");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 send_string (s, command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 send_string (s, ")");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 #ifdef 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_ipc_server (s, msgp, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 #else /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 if (connect_type != (int) CONN_IPC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 disconnect_from_server (s, FALSE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 #endif /* !SYSV_IPC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 } /* not batch */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 } /* main */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */