1 /* Console functions for X windows.
2 Copyright (C) 1996 Ben Wing.
4 This file is part of SXEmacs
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Synched up with: Not in FSF. */
22 /* This file Mule-ized by Ben Wing, 7-10-00. */
26 Ben Wing: January 1996, for 19.14.
32 #include "console-x.h"
34 #include "process.h" /* canonicalize_host_name */
35 #include "ui/redisplay.h" /* for display_arg */
37 DEFINE_CONSOLE_TYPE(x);
39 static int x_initially_selected_for_input(struct console *con)
44 /* Parse a DISPLAY specification like "host:10.0" or ":0" */
46 split_up_display_spec(Lisp_Object display, int *hostname_length,
47 int *display_length, int *screen_length)
49 Bufbyte *beg = XSTRING_DATA(display);
50 Bufbyte *end = beg + XSTRING_LENGTH(display);
51 Bufbyte const *p = end;
55 if (charptr_emchar(p) == ':') {
56 *hostname_length = p - beg;
60 if (charptr_emchar(p) == '.') {
62 p - beg - *hostname_length;
63 *screen_length = end - p;
69 XSTRING_LENGTH(display) - *hostname_length;
76 *hostname_length = XSTRING_LENGTH(display);
81 /* Remember, in all of the following functions, we have to verify
82 the integrity of our input, because the generic functions don't. */
85 x_device_to_console_connection(Lisp_Object connection, Error_behavior errb)
87 /* Strip the trailing .# off of the connection, if it's there. */
92 int hostname_length, display_length, screen_length;
94 if (!ERRB_EQ(errb, ERROR_ME)) {
95 if (!STRINGP(connection))
98 CHECK_STRING(connection);
100 split_up_display_spec(connection, &hostname_length,
101 &display_length, &screen_length);
103 make_string(XSTRING_DATA(connection),
104 hostname_length + display_length);
110 static Lisp_Object get_display_arg_connection(void)
112 const Extbyte *disp_name;
114 /* If the user didn't explicitly specify a display to use when
115 they called make-x-device, then we first check to see if a
116 display was specified on the command line with -display. If
117 so, we set disp_name to it. Otherwise we use XDisplayName to
118 see what DISPLAY is set to. XtOpenDisplay knows how to do
119 both of these things, but we need to know the name to use. */
126 make_argc_argv(Vx_initial_argv_list, &argc, &argv);
129 for (elt = 0; elt < argc; elt++) {
130 if (!strcmp(argv[elt], "-d")
131 || !strcmp(argv[elt], "-display")) {
132 if (elt + 1 == argc) {
133 suppress_early_error_handler_backtrace =
135 type_error(Qinvalid_argument,
136 "-display specified with no arg");
138 disp_name = argv[elt + 1];
144 /* assert: display_arg is only set if we found the display
145 arg earlier so we can't fail to find it now. */
146 assert(disp_name != NULL);
147 conn = build_ext_string(disp_name, Qcommand_argument_encoding);
148 free_argc_argv(argv);
151 return build_ext_string(XDisplayName(0),
152 Qx_display_name_encoding);
155 /* "semi-canonicalize" means convert to a nicer form for printing, but
156 don't completely canonicalize (into some likely ugly form) */
159 x_semi_canonicalize_console_connection(Lisp_Object connection,
166 if (NILP(connection))
167 connection = get_display_arg_connection();
169 if (!ERRB_EQ(errb, ERROR_ME)) {
170 if (!STRINGP(connection))
171 RETURN_UNGCPRO(Qunbound);
173 CHECK_STRING(connection);
176 /* Be lenient, allow people to specify a device connection instead of
177 a console connection -- e.g. "foo:0.0" instead of "foo:0". This
178 only happens in `find-console' and `get-console'. */
179 connection = x_device_to_console_connection(connection, errb);
181 /* Check for a couple of standard special cases */
182 if (string_char(XSTRING(connection), 0) == ':') {
183 connection = concat2(build_string("localhost"), connection);
185 /* connection =~ s/^unix:/localhost:/; */
186 Bufbyte *p = XSTRING_DATA(connection);
188 XSTRING_DATA(connection) + XSTRING_LENGTH(connection);
191 for (i = 0; i < sizeof("unix:") - 1; i++) {
192 if (p == end || charptr_emchar(p) != "unix:"[i])
197 connection = concat2(build_string("localhost:"),
198 make_string(p, end - p));
201 RETURN_UNGCPRO(connection);
205 x_canonicalize_console_connection(Lisp_Object connection, Error_behavior errb)
207 Lisp_Object hostname = Qnil;
208 struct gcpro gcpro1, gcpro2;
210 GCPRO2(connection, hostname);
212 connection = x_semi_canonicalize_console_connection(connection, errb);
213 if (UNBOUNDP(connection))
214 RETURN_UNGCPRO(Qunbound);
217 int hostname_length, display_length, screen_length;
219 split_up_display_spec(connection, &hostname_length,
220 &display_length, &screen_length);
222 Fsubstring(connection, Qzero, make_int(hostname_length));
223 hostname = canonicalize_host_name(hostname);
224 connection = concat2(hostname,
225 make_string(XSTRING_DATA(connection)
230 RETURN_UNGCPRO(connection);
234 x_semi_canonicalize_device_connection(Lisp_Object connection,
237 int hostname_length, display_length, screen_length;
241 if (NILP(connection))
242 connection = get_display_arg_connection();
244 if (!ERRB_EQ(errb, ERROR_ME)) {
245 if (!STRINGP(connection))
246 RETURN_UNGCPRO(Qunbound);
248 CHECK_STRING(connection);
251 split_up_display_spec(connection, &hostname_length, &display_length,
255 connection = concat2(connection, build_string(".0"));
256 RETURN_UNGCPRO(connection);
260 x_canonicalize_device_connection(Lisp_Object connection, Error_behavior errb)
262 int hostname_length, display_length, screen_length;
263 Lisp_Object screen_str = Qnil;
264 struct gcpro gcpro1, gcpro2;
266 GCPRO2(screen_str, connection);
267 connection = x_semi_canonicalize_device_connection(connection, errb);
268 if (UNBOUNDP(connection))
269 RETURN_UNGCPRO(Qunbound);
271 split_up_display_spec(connection, &hostname_length, &display_length,
274 screen_str = make_string(XSTRING_DATA(connection)
275 + hostname_length + display_length,
277 connection = x_canonicalize_console_connection(connection, errb);
279 RETURN_UNGCPRO(concat2(connection, screen_str));
282 void console_type_create_x(void)
284 INITIALIZE_CONSOLE_TYPE(x, "x", "console-x-p");
286 CONSOLE_HAS_METHOD(x, semi_canonicalize_console_connection);
287 CONSOLE_HAS_METHOD(x, canonicalize_console_connection);
288 CONSOLE_HAS_METHOD(x, semi_canonicalize_device_connection);
289 CONSOLE_HAS_METHOD(x, canonicalize_device_connection);
290 CONSOLE_HAS_METHOD(x, device_to_console_connection);
291 CONSOLE_HAS_METHOD(x, initially_selected_for_input);
294 void reinit_console_type_create_x(void)
296 REINITIALIZE_CONSOLE_TYPE(x);