comparison src/console-tty.c @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents 190b164ddcac
children e38acbeb1cae
comparison
equal deleted inserted replaced
770:336a418893b5 771:943eaba38521
1 /* TTY console functions. 1 /* TTY console functions.
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois. 2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
3 Copyright (C) 1994, 1995 Free Software Foundation, Inc. 3 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
4 Copyright (C) 1996 Ben Wing. 4 Copyright (C) 1996, 2001 Ben Wing.
5 5
6 This file is part of XEmacs. 6 This file is part of XEmacs.
7 7
8 XEmacs is free software; you can redistribute it and/or modify it 8 XEmacs is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the 9 under the terms of the GNU General Public License as published by the
33 #include "frame.h" 33 #include "frame.h"
34 #include "lstream.h" 34 #include "lstream.h"
35 #include "glyphs.h" 35 #include "glyphs.h"
36 #include "sysdep.h" 36 #include "sysdep.h"
37 #include "sysfile.h" 37 #include "sysfile.h"
38 #ifdef FILE_CODING
39 #include "file-coding.h" 38 #include "file-coding.h"
40 #endif
41 39
42 DEFINE_CONSOLE_TYPE (tty); 40 DEFINE_CONSOLE_TYPE (tty);
43 DECLARE_IMAGE_INSTANTIATOR_FORMAT (nothing); 41 DECLARE_IMAGE_INSTANTIATOR_FORMAT (nothing);
44 DECLARE_IMAGE_INSTANTIATOR_FORMAT (string); 42 DECLARE_IMAGE_INSTANTIATOR_FORMAT (string);
45 DECLARE_IMAGE_INSTANTIATOR_FORMAT (formatted_string); 43 DECLARE_IMAGE_INSTANTIATOR_FORMAT (formatted_string);
77 75
78 if (!NILP (terminal_type)) 76 if (!NILP (terminal_type))
79 CHECK_STRING (terminal_type); 77 CHECK_STRING (terminal_type);
80 else 78 else
81 { 79 {
82 char *temp_type = getenv ("TERM"); 80 Intbyte *temp_type = egetenv ("TERM");
83 81
84 if (!temp_type) 82 if (!temp_type)
85 { 83 {
86 invalid_state ("Cannot determine terminal type", Qunbound); 84 invalid_state ("Cannot determine terminal type", Qunbound);
87 } 85 }
88 else 86 else
89 terminal_type = build_string (temp_type); 87 terminal_type = build_intstring (temp_type);
90 } 88 }
91 89
92 /* Determine the controlling process */ 90 /* Determine the controlling process */
93 if (!NILP (controlling_process)) 91 if (!NILP (controlling_process))
94 CHECK_INT (controlling_process); 92 CHECK_INT (controlling_process);
105 tty_con->is_stdio = 1; 103 tty_con->is_stdio = 1;
106 } 104 }
107 else 105 else
108 { 106 {
109 tty_con->infd = tty_con->outfd = 107 tty_con->infd = tty_con->outfd =
110 open ((char *) XSTRING_DATA (tty), O_RDWR); 108 qxe_open (XSTRING_DATA (tty), O_RDWR);
111 if (tty_con->infd < 0) 109 if (tty_con->infd < 0)
112 signal_error (Qio_error, "Unable to open tty", tty); 110 signal_error (Qio_error, "Unable to open tty", tty);
113 tty_con->is_stdio = 0; 111 tty_con->is_stdio = 0;
114 } 112 }
115 113
116 tty_con->instream = make_filedesc_input_stream (tty_con->infd, 0, -1, 0); 114 tty_con->instream = make_filedesc_input_stream (tty_con->infd, 0, -1, 0);
115 Lstream_set_buffering (XLSTREAM (tty_con->instream), LSTREAM_UNBUFFERED, 0);
116 tty_con->instream =
117 make_coding_input_stream (XLSTREAM (tty_con->instream),
118 get_coding_system_for_text_file (Qkeyboard, 0),
119 CODING_DECODE);
120 Lstream_set_buffering (XLSTREAM (tty_con->instream), LSTREAM_UNBUFFERED, 0);
121 Lstream_set_character_mode (XLSTREAM (tty_con->instream));
117 tty_con->outstream = make_filedesc_output_stream (tty_con->outfd, 0, -1, 0); 122 tty_con->outstream = make_filedesc_output_stream (tty_con->outfd, 0, -1, 0);
118 #ifdef FILE_CODING
119 tty_con->instream =
120 make_decoding_input_stream (XLSTREAM (tty_con->instream),
121 Fget_coding_system (Qkeyboard));
122 Lstream_set_character_mode (XLSTREAM (tty_con->instream));
123 tty_con->outstream = 123 tty_con->outstream =
124 make_encoding_output_stream (XLSTREAM (tty_con->outstream), 124 make_coding_output_stream (XLSTREAM (tty_con->outstream),
125 Fget_coding_system (Qterminal)); 125 get_coding_system_for_text_file (Qterminal, 0),
126 #endif /* FILE_CODING */ 126 CODING_ENCODE);
127 tty_con->terminal_type = terminal_type; 127 tty_con->terminal_type = terminal_type;
128 tty_con->controlling_process = controlling_process; 128 tty_con->controlling_process = controlling_process;
129 129
130 if (NILP (CONSOLE_NAME (con))) 130 if (NILP (CONSOLE_NAME (con)))
131 CONSOLE_NAME (con) = Ffile_name_nondirectory (tty); 131 CONSOLE_NAME (con) = Ffile_name_nondirectory (tty);
140 TTY. This is OK because a process group can never simultaneously 140 TTY. This is OK because a process group can never simultaneously
141 be the foreground process group of two TTY's (in that case it 141 be the foreground process group of two TTY's (in that case it
142 would have two controlling TTY's, which is not allowed). */ 142 would have two controlling TTY's, which is not allowed). */
143 143
144 EMACS_GET_TTY_PROCESS_GROUP (tty_con->infd, &tty_pg); 144 EMACS_GET_TTY_PROCESS_GROUP (tty_con->infd, &tty_pg);
145 cfd = open ("/dev/tty", O_RDWR, 0); 145 cfd = qxe_open ((Intbyte *) "/dev/tty", O_RDWR, 0);
146 EMACS_GET_TTY_PROCESS_GROUP (cfd, &controlling_tty_pg); 146 EMACS_GET_TTY_PROCESS_GROUP (cfd, &controlling_tty_pg);
147 close (cfd); 147 retry_close (cfd);
148 if (tty_pg == controlling_tty_pg) 148 if (tty_pg == controlling_tty_pg)
149 { 149 {
150 tty_con->controlling_terminal = 1; 150 tty_con->controlling_terminal = 1;
151 XSETCONSOLE (Vcontrolling_terminal, con); 151 XSETCONSOLE (Vcontrolling_terminal, con);
152 munge_tty_process_group (); 152 munge_tty_process_group ();
193 tty_delete_console (struct console *con) 193 tty_delete_console (struct console *con)
194 { 194 {
195 Lstream_close (XLSTREAM (CONSOLE_TTY_DATA (con)->instream)); 195 Lstream_close (XLSTREAM (CONSOLE_TTY_DATA (con)->instream));
196 Lstream_close (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream)); 196 Lstream_close (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream));
197 if (!CONSOLE_TTY_DATA (con)->is_stdio) 197 if (!CONSOLE_TTY_DATA (con)->is_stdio)
198 close (CONSOLE_TTY_DATA (con)->infd); 198 retry_close (CONSOLE_TTY_DATA (con)->infd);
199 if (CONSOLE_TTY_DATA (con)->controlling_terminal) 199 if (CONSOLE_TTY_DATA (con)->controlling_terminal)
200 { 200 {
201 Vcontrolling_terminal = Qnil; 201 Vcontrolling_terminal = Qnil;
202 unmunge_tty_process_group (); 202 unmunge_tty_process_group ();
203 } 203 }
229 (console)) 229 (console))
230 { 230 {
231 return CONSOLE_TTY_DATA (decode_tty_console (console))->controlling_process; 231 return CONSOLE_TTY_DATA (decode_tty_console (console))->controlling_process;
232 } 232 }
233 233
234 #ifdef FILE_CODING
235 234
236 DEFUN ("console-tty-input-coding-system", Fconsole_tty_input_coding_system, 235 DEFUN ("console-tty-input-coding-system", Fconsole_tty_input_coding_system,
237 0, 1, 0, /* 236 0, 1, 0, /*
238 Return the input coding system of tty console CONSOLE. 237 Return the input coding system of tty console CONSOLE.
239 */ 238 */
240 (console)) 239 (console))
241 { 240 {
242 return decoding_stream_coding_system 241 return coding_stream_detected_coding_system
243 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->instream)); 242 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->instream));
244 } 243 }
245 244
246 DEFUN ("set-console-tty-input-coding-system", Fset_console_tty_input_coding_system, 245 DEFUN ("set-console-tty-input-coding-system", Fset_console_tty_input_coding_system,
247 0, 2, 0, /* 246 0, 2, 0, /*
249 CONSOLE defaults to the selected console. 248 CONSOLE defaults to the selected console.
250 CODESYS defaults to the value of `keyboard-coding-system'. 249 CODESYS defaults to the value of `keyboard-coding-system'.
251 */ 250 */
252 (console, codesys)) 251 (console, codesys))
253 { 252 {
254 set_decoding_stream_coding_system 253 set_coding_stream_coding_system
255 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->instream), 254 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->instream),
256 Fget_coding_system (NILP (codesys) ? Qkeyboard : codesys)); 255 get_coding_system_for_text_file (NILP (codesys) ? Qkeyboard : codesys,
256 0));
257 return Qnil; 257 return Qnil;
258 } 258 }
259 259
260 DEFUN ("console-tty-output-coding-system", Fconsole_tty_output_coding_system, 260 DEFUN ("console-tty-output-coding-system", Fconsole_tty_output_coding_system,
261 0, 1, 0, /* 261 0, 1, 0, /*
262 Return TTY CONSOLE's output coding system. 262 Return TTY CONSOLE's output coding system.
263 */ 263 */
264 (console)) 264 (console))
265 { 265 {
266 return encoding_stream_coding_system 266 return coding_stream_coding_system
267 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->outstream)); 267 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->outstream));
268 } 268 }
269 269
270 DEFUN ("set-console-tty-output-coding-system", Fset_console_tty_output_coding_system, 270 DEFUN ("set-console-tty-output-coding-system", Fset_console_tty_output_coding_system,
271 0, 2, 0, /* 271 0, 2, 0, /*
273 CONSOLE defaults to the selected console. 273 CONSOLE defaults to the selected console.
274 CODESYS defaults to the value of `terminal-coding-system'. 274 CODESYS defaults to the value of `terminal-coding-system'.
275 */ 275 */
276 (console, codesys)) 276 (console, codesys))
277 { 277 {
278 set_encoding_stream_coding_system 278 set_coding_stream_coding_system
279 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->outstream), 279 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->outstream),
280 Fget_coding_system (NILP (codesys) ? Qterminal : codesys)); 280 get_coding_system_for_text_file (NILP (codesys) ? Qterminal : codesys,
281 0));
281 /* Redraw tty */ 282 /* Redraw tty */
282 face_property_was_changed (Vdefault_face, Qfont, Qtty); 283 face_property_was_changed (Vdefault_face, Qfont, Qtty);
283 return Qnil; 284 return Qnil;
284 } 285 }
285 286
296 { 297 {
297 Fset_console_tty_input_coding_system (console, codesys); 298 Fset_console_tty_input_coding_system (console, codesys);
298 Fset_console_tty_output_coding_system (console, codesys); 299 Fset_console_tty_output_coding_system (console, codesys);
299 return Qnil; 300 return Qnil;
300 } 301 }
301 #endif /* FILE_CODING */
302 302
303 303
304 Lisp_Object 304 Lisp_Object
305 tty_semi_canonicalize_console_connection (Lisp_Object connection, 305 tty_semi_canonicalize_console_connection (Lisp_Object connection,
306 Error_Behavior errb) 306 Error_Behavior errb)
339 { 339 {
340 DEFSUBR (Fconsole_tty_terminal_type); 340 DEFSUBR (Fconsole_tty_terminal_type);
341 DEFSUBR (Fconsole_tty_controlling_process); 341 DEFSUBR (Fconsole_tty_controlling_process);
342 DEFSYMBOL (Qterminal_type); 342 DEFSYMBOL (Qterminal_type);
343 DEFSYMBOL (Qcontrolling_process); 343 DEFSYMBOL (Qcontrolling_process);
344 #ifdef FILE_CODING
345 DEFSUBR (Fconsole_tty_output_coding_system); 344 DEFSUBR (Fconsole_tty_output_coding_system);
346 DEFSUBR (Fset_console_tty_output_coding_system); 345 DEFSUBR (Fset_console_tty_output_coding_system);
347 DEFSUBR (Fconsole_tty_input_coding_system); 346 DEFSUBR (Fconsole_tty_input_coding_system);
348 DEFSUBR (Fset_console_tty_input_coding_system); 347 DEFSUBR (Fset_console_tty_input_coding_system);
349 DEFSUBR (Fset_console_tty_coding_system); 348 DEFSUBR (Fset_console_tty_coding_system);
350 #endif /* FILE_CODING */
351 } 349 }
352 350
353 void 351 void
354 console_type_create_tty (void) 352 console_type_create_tty (void)
355 { 353 {