428
|
1 /* Console functions for X windows.
|
|
2 Copyright (C) 1996 Ben Wing.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not in FSF. */
|
|
22
|
442
|
23 /* This file Mule-ized by Ben Wing, 7-10-00. */
|
|
24
|
428
|
25 /* Authorship:
|
|
26
|
|
27 Ben Wing: January 1996, for 19.14.
|
|
28 */
|
|
29
|
|
30 #include <config.h>
|
|
31 #include "lisp.h"
|
|
32
|
|
33 #include "console-x.h"
|
442
|
34 #include "buffer.h"
|
428
|
35 #include "process.h" /* canonicalize_host_name */
|
|
36 #include "redisplay.h" /* for display_arg */
|
|
37
|
|
38 DEFINE_CONSOLE_TYPE (x);
|
|
39
|
|
40 static int
|
|
41 x_initially_selected_for_input (struct console *con)
|
|
42 {
|
|
43 return 1;
|
|
44 }
|
|
45
|
444
|
46 /* Parse a DISPLAY specification like "host:10.0" or ":0" */
|
428
|
47 static void
|
|
48 split_up_display_spec (Lisp_Object display, int *hostname_length,
|
|
49 int *display_length, int *screen_length)
|
|
50 {
|
444
|
51 Bufbyte *beg = XSTRING_DATA (display);
|
|
52 Bufbyte *end = beg + XSTRING_LENGTH (display);
|
|
53 Bufbyte *p = end;
|
428
|
54
|
444
|
55 while (p > beg)
|
428
|
56 {
|
444
|
57 DEC_CHARPTR (p);
|
|
58 if (charptr_emchar (p) == ':')
|
|
59 {
|
|
60 *hostname_length = p - beg;
|
428
|
61
|
444
|
62 while (p < end - 1)
|
|
63 {
|
|
64 INC_CHARPTR (p);
|
|
65 if (charptr_emchar (p) == '.')
|
|
66 {
|
|
67 *display_length = p - beg - *hostname_length;
|
|
68 *screen_length = end - p;
|
|
69 return;
|
|
70 }
|
|
71 }
|
|
72 /* No '.' found. */
|
|
73 *display_length = XSTRING_LENGTH (display) - *hostname_length;
|
|
74 *screen_length = 0;
|
|
75 return;
|
|
76 }
|
428
|
77 }
|
|
78
|
444
|
79 /* No ':' found. */
|
|
80 *hostname_length = XSTRING_LENGTH (display);
|
|
81 *display_length = 0;
|
|
82 *screen_length = 0;
|
428
|
83 }
|
|
84
|
|
85 /* Remember, in all of the following functions, we have to verify
|
|
86 the integrity of our input, because the generic functions don't. */
|
|
87
|
|
88 static Lisp_Object
|
578
|
89 x_device_to_console_connection (Lisp_Object connection, Error_Behavior errb)
|
428
|
90 {
|
|
91 /* Strip the trailing .# off of the connection, if it's there. */
|
|
92
|
|
93 if (NILP (connection))
|
|
94 return Qnil;
|
|
95 else
|
|
96 {
|
|
97 int hostname_length, display_length, screen_length;
|
|
98
|
|
99 if (!ERRB_EQ (errb, ERROR_ME))
|
|
100 {
|
|
101 if (!STRINGP (connection))
|
|
102 return Qunbound;
|
|
103 }
|
|
104 else
|
|
105 CHECK_STRING (connection);
|
|
106
|
|
107 split_up_display_spec (connection, &hostname_length, &display_length,
|
|
108 &screen_length);
|
|
109 connection = make_string (XSTRING_DATA (connection),
|
|
110 hostname_length + display_length);
|
|
111 }
|
|
112
|
|
113 return connection;
|
|
114 }
|
|
115
|
|
116 static Lisp_Object
|
|
117 get_display_arg_connection (void)
|
|
118 {
|
442
|
119 const Extbyte *disp_name;
|
428
|
120
|
|
121 /* If the user didn't explicitly specify a display to use when
|
|
122 they called make-x-device, then we first check to see if a
|
|
123 display was specified on the command line with -display. If
|
|
124 so, we set disp_name to it. Otherwise we use XDisplayName to
|
|
125 see what DISPLAY is set to. XtOpenDisplay knows how to do
|
|
126 both of these things, but we need to know the name to use. */
|
|
127 if (display_arg)
|
|
128 {
|
|
129 int elt;
|
|
130 int argc;
|
442
|
131 Extbyte **argv;
|
428
|
132 Lisp_Object conn;
|
|
133
|
|
134 make_argc_argv (Vx_initial_argv_list, &argc, &argv);
|
|
135
|
|
136 disp_name = NULL;
|
|
137 for (elt = 0; elt < argc; elt++)
|
|
138 {
|
|
139 if (!strcmp (argv[elt], "-d") || !strcmp (argv[elt], "-display"))
|
|
140 {
|
|
141 if (elt + 1 == argc)
|
|
142 {
|
|
143 suppress_early_error_handler_backtrace = 1;
|
563
|
144 invalid_argument ("-display specified with no arg", Qunbound);
|
428
|
145 }
|
|
146 else
|
|
147 {
|
|
148 disp_name = argv[elt + 1];
|
|
149 break;
|
|
150 }
|
|
151 }
|
|
152 }
|
|
153
|
|
154 /* assert: display_arg is only set if we found the display
|
|
155 arg earlier so we can't fail to find it now. */
|
|
156 assert (disp_name != NULL);
|
442
|
157 conn = build_ext_string (disp_name, Qcommand_argument_encoding);
|
428
|
158 free_argc_argv (argv);
|
|
159 return conn;
|
|
160 }
|
|
161 else
|
442
|
162 return build_ext_string (XDisplayName (0), Qx_display_name_encoding);
|
428
|
163 }
|
|
164
|
|
165 /* "semi-canonicalize" means convert to a nicer form for printing, but
|
|
166 don't completely canonicalize (into some likely ugly form) */
|
|
167
|
|
168 static Lisp_Object
|
|
169 x_semi_canonicalize_console_connection (Lisp_Object connection,
|
578
|
170 Error_Behavior errb)
|
428
|
171 {
|
|
172 struct gcpro gcpro1;
|
|
173
|
|
174 GCPRO1 (connection);
|
|
175
|
|
176 if (NILP (connection))
|
|
177 connection = get_display_arg_connection ();
|
|
178 else
|
|
179 {
|
|
180 if (!ERRB_EQ (errb, ERROR_ME))
|
|
181 {
|
|
182 if (!STRINGP (connection))
|
|
183 RETURN_UNGCPRO (Qunbound);
|
|
184 }
|
|
185 else
|
|
186 CHECK_STRING (connection);
|
|
187 }
|
|
188
|
|
189
|
|
190 /* Be lenient, allow people to specify a device connection instead of
|
|
191 a console connection -- e.g. "foo:0.0" instead of "foo:0". This
|
|
192 only happens in `find-console' and `get-console'. */
|
|
193 connection = x_device_to_console_connection (connection, errb);
|
|
194
|
|
195 /* Check for a couple of standard special cases */
|
444
|
196 if (string_char (XSTRING (connection), 0) == ':')
|
428
|
197 connection = concat2 (build_string ("localhost"), connection);
|
444
|
198 else
|
|
199 {
|
|
200 /* connection =~ s/^unix:/localhost:/; */
|
|
201 const Bufbyte *p = XSTRING_DATA (connection);
|
|
202 const Bufbyte *end = XSTRING_DATA (connection) + XSTRING_LENGTH (connection);
|
|
203 size_t i;
|
|
204
|
|
205 for (i = 0; i < sizeof ("unix:") - 1; i++)
|
|
206 {
|
|
207 if (p == end || charptr_emchar (p) != "unix:"[i])
|
|
208 goto ok;
|
|
209 INC_CHARPTR (p);
|
|
210 }
|
|
211
|
|
212 connection = concat2 (build_string ("localhost:"),
|
|
213 make_string (p, end - p));
|
|
214 }
|
|
215 ok:
|
428
|
216
|
|
217 RETURN_UNGCPRO (connection);
|
|
218 }
|
|
219
|
|
220 static Lisp_Object
|
578
|
221 x_canonicalize_console_connection (Lisp_Object connection, Error_Behavior errb)
|
428
|
222 {
|
|
223 Lisp_Object hostname = Qnil;
|
|
224 struct gcpro gcpro1, gcpro2;
|
|
225
|
|
226 GCPRO2 (connection, hostname);
|
|
227
|
|
228 connection = x_semi_canonicalize_console_connection (connection, errb);
|
|
229 if (UNBOUNDP (connection))
|
|
230 RETURN_UNGCPRO (Qunbound);
|
|
231
|
|
232 {
|
|
233 int hostname_length, display_length, screen_length;
|
|
234
|
|
235 split_up_display_spec (connection, &hostname_length, &display_length,
|
|
236 &screen_length);
|
|
237 hostname = Fsubstring (connection, Qzero, make_int (hostname_length));
|
|
238 hostname = canonicalize_host_name (hostname);
|
|
239 connection = concat2 (hostname,
|
|
240 make_string (XSTRING_DATA (connection)
|
|
241 + hostname_length, display_length));
|
|
242 }
|
|
243
|
|
244 RETURN_UNGCPRO (connection);
|
|
245 }
|
|
246
|
|
247 static Lisp_Object
|
|
248 x_semi_canonicalize_device_connection (Lisp_Object connection,
|
578
|
249 Error_Behavior errb)
|
428
|
250 {
|
|
251 int hostname_length, display_length, screen_length;
|
|
252 struct gcpro gcpro1;
|
|
253
|
|
254 GCPRO1 (connection);
|
|
255 if (NILP (connection))
|
|
256 connection = get_display_arg_connection ();
|
|
257 else
|
|
258 {
|
|
259 if (!ERRB_EQ (errb, ERROR_ME))
|
|
260 {
|
|
261 if (!STRINGP (connection))
|
|
262 RETURN_UNGCPRO (Qunbound);
|
|
263 }
|
|
264 else
|
|
265 CHECK_STRING (connection);
|
|
266 }
|
|
267
|
|
268 split_up_display_spec (connection, &hostname_length, &display_length,
|
|
269 &screen_length);
|
|
270
|
|
271 if (!screen_length)
|
|
272 connection = concat2 (connection, build_string (".0"));
|
|
273 RETURN_UNGCPRO (connection);
|
|
274 }
|
|
275
|
|
276 static Lisp_Object
|
578
|
277 x_canonicalize_device_connection (Lisp_Object connection, Error_Behavior errb)
|
428
|
278 {
|
|
279 int hostname_length, display_length, screen_length;
|
|
280 Lisp_Object screen_str = Qnil;
|
|
281 struct gcpro gcpro1, gcpro2;
|
|
282
|
|
283 GCPRO2 (screen_str, connection);
|
|
284 connection = x_semi_canonicalize_device_connection (connection, errb);
|
|
285 if (UNBOUNDP (connection))
|
|
286 RETURN_UNGCPRO (Qunbound);
|
|
287
|
|
288 split_up_display_spec (connection, &hostname_length, &display_length,
|
|
289 &screen_length);
|
|
290
|
444
|
291 screen_str = make_string (XSTRING_DATA (connection)
|
|
292 + hostname_length + display_length, screen_length);
|
428
|
293 connection = x_canonicalize_console_connection (connection, errb);
|
|
294
|
|
295 RETURN_UNGCPRO (concat2 (connection, screen_str));
|
|
296 }
|
|
297
|
|
298 void
|
|
299 console_type_create_x (void)
|
|
300 {
|
|
301 INITIALIZE_CONSOLE_TYPE (x, "x", "console-x-p");
|
|
302
|
|
303 CONSOLE_HAS_METHOD (x, semi_canonicalize_console_connection);
|
|
304 CONSOLE_HAS_METHOD (x, canonicalize_console_connection);
|
|
305 CONSOLE_HAS_METHOD (x, semi_canonicalize_device_connection);
|
|
306 CONSOLE_HAS_METHOD (x, canonicalize_device_connection);
|
|
307 CONSOLE_HAS_METHOD (x, device_to_console_connection);
|
|
308 CONSOLE_HAS_METHOD (x, initially_selected_for_input);
|
|
309 }
|
|
310
|
|
311
|
|
312 void
|
|
313 reinit_console_type_create_x (void)
|
|
314 {
|
|
315 REINITIALIZE_CONSOLE_TYPE (x);
|
|
316 }
|