Mercurial > hg > xemacs-beta
comparison src/console-tty.c @ 272:c5d627a313b1 r21-0b34
Import from CVS: tag r21-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:28:48 +0200 |
parents | 966663fcf606 |
children | 7df0dd720c89 |
comparison
equal
deleted
inserted
replaced
271:c7b7086b0a39 | 272:c5d627a313b1 |
---|---|
27 #include <config.h> | 27 #include <config.h> |
28 #include "lisp.h" | 28 #include "lisp.h" |
29 | 29 |
30 #include "console-tty.h" | 30 #include "console-tty.h" |
31 #include "console-stream.h" | 31 #include "console-stream.h" |
32 #include "events.h" /* for Vcontrolling_terminal */ | |
33 #include "faces.h" | 32 #include "faces.h" |
34 #include "frame.h" | 33 #include "frame.h" |
35 #include "lstream.h" | 34 #include "lstream.h" |
36 #include "redisplay.h" | 35 #include "redisplay.h" |
37 #include "sysdep.h" | 36 #include "sysdep.h" |
37 #include "sysfile.h" | |
38 #ifdef FILE_CODING | 38 #ifdef FILE_CODING |
39 #include "file-coding.h" | 39 #include "file-coding.h" |
40 #endif | 40 #endif |
41 #ifdef HAVE_GPM | 41 #ifdef HAVE_GPM |
42 #include "gpmevent.h" | 42 #include "gpmevent.h" |
45 DEFINE_CONSOLE_TYPE (tty); | 45 DEFINE_CONSOLE_TYPE (tty); |
46 | 46 |
47 Lisp_Object Qterminal_type; | 47 Lisp_Object Qterminal_type; |
48 Lisp_Object Qcontrolling_process; | 48 Lisp_Object Qcontrolling_process; |
49 | 49 |
50 extern Lisp_Object Vstdio_str; /* in console-stream.c */ | |
51 | 50 |
52 static void | 51 static void |
53 allocate_tty_console_struct (struct console *con) | 52 allocate_tty_console_struct (struct console *con) |
54 { | 53 { |
55 /* zero out all slots except the lisp ones ... */ | 54 /* zero out all slots except the lisp ones ... */ |
56 con->console_data = xnew_and_zero (struct tty_console); | 55 CONSOLE_TTY_DATA (con) = xnew_and_zero (struct tty_console); |
57 CONSOLE_TTY_DATA (con)->terminal_type = Qnil; | 56 CONSOLE_TTY_DATA (con)->terminal_type = Qnil; |
58 CONSOLE_TTY_DATA (con)->instream = Qnil; | 57 CONSOLE_TTY_DATA (con)->instream = Qnil; |
59 CONSOLE_TTY_DATA (con)->outstream = Qnil; | 58 CONSOLE_TTY_DATA (con)->outstream = Qnil; |
60 } | 59 } |
61 | 60 |
62 static void | 61 static void |
63 tty_init_console (struct console *con, Lisp_Object props) | 62 tty_init_console (struct console *con, Lisp_Object props) |
64 { | 63 { |
65 Lisp_Object tty = CONSOLE_CONNECTION (con); | 64 Lisp_Object tty = CONSOLE_CONNECTION (con); |
66 Lisp_Object terminal_type = Qnil, controlling_process = Qnil; | 65 Lisp_Object terminal_type = Qnil; |
67 int infd, outfd; | 66 Lisp_Object controlling_process = Qnil; |
67 struct tty_console *tty_con; | |
68 struct gcpro gcpro1, gcpro2; | 68 struct gcpro gcpro1, gcpro2; |
69 | 69 |
70 GCPRO2 (terminal_type, controlling_process); | 70 GCPRO2 (terminal_type, controlling_process); |
71 | 71 |
72 terminal_type = Fplist_get (props, Qterminal_type, Qnil); | 72 terminal_type = Fplist_get (props, Qterminal_type, Qnil); |
73 controlling_process = Fplist_get(props, Qcontrolling_process, Qnil); | 73 controlling_process = Fplist_get (props, Qcontrolling_process, Qnil); |
74 | 74 |
75 /* Determine the terminal type */ | 75 /* Determine the terminal type */ |
76 | 76 |
77 if (!NILP (terminal_type)) | 77 if (!NILP (terminal_type)) |
78 CHECK_STRING (terminal_type); | 78 CHECK_STRING (terminal_type); |
79 else | 79 else |
80 { | 80 { |
81 char *temp_type = (char *) getenv ("TERM"); | 81 char *temp_type = getenv ("TERM"); |
82 | 82 |
83 if (!temp_type) | 83 if (!temp_type) |
84 { | 84 { |
85 error ("Cannot determine terminal type"); | 85 error ("Cannot determine terminal type"); |
86 } | 86 } |
93 CHECK_INT (controlling_process); | 93 CHECK_INT (controlling_process); |
94 | 94 |
95 /* Open the specified console */ | 95 /* Open the specified console */ |
96 | 96 |
97 allocate_tty_console_struct (con); | 97 allocate_tty_console_struct (con); |
98 tty_con = CONSOLE_TTY_DATA (con); | |
99 | |
98 if (internal_equal (tty, Vstdio_str, 0)) | 100 if (internal_equal (tty, Vstdio_str, 0)) |
99 { | 101 { |
100 infd = fileno (stdin); | 102 tty_con->infd = fileno (stdin); |
101 outfd = fileno (stdout); | 103 tty_con->outfd = fileno (stdout); |
102 CONSOLE_TTY_DATA (con)->is_stdio = 1; | 104 tty_con->is_stdio = 1; |
103 } | 105 } |
104 else | 106 else |
105 { | 107 { |
106 infd = outfd = open ((char *) XSTRING_DATA (tty), O_RDWR); | 108 tty_con->infd = tty_con->outfd = |
107 if (infd < 0) | 109 open ((char *) XSTRING_DATA (tty), O_RDWR); |
110 if (tty_con->infd < 0) | |
108 error ("Unable to open tty %s", XSTRING_DATA (tty)); | 111 error ("Unable to open tty %s", XSTRING_DATA (tty)); |
109 CONSOLE_TTY_DATA (con)->is_stdio = 0; | 112 tty_con->is_stdio = 0; |
110 } | 113 } |
111 | 114 |
112 CONSOLE_TTY_DATA (con)->infd = infd; | 115 tty_con->instream = make_filedesc_input_stream (tty_con->infd, 0, -1, 0); |
113 CONSOLE_TTY_DATA (con)->outfd = outfd; | 116 tty_con->outstream = make_filedesc_output_stream (tty_con->outfd, 0, -1, 0); |
114 CONSOLE_TTY_DATA (con)->instream = make_filedesc_input_stream (infd, 0, | |
115 -1, 0); | |
116 CONSOLE_TTY_DATA (con)->outstream = make_filedesc_output_stream (outfd, 0, | |
117 -1, 0); | |
118 #ifdef MULE | 117 #ifdef MULE |
119 CONSOLE_TTY_DATA (con)->instream = | 118 tty_con->instream = |
120 make_decoding_input_stream (XLSTREAM (CONSOLE_TTY_DATA (con)->instream), | 119 make_decoding_input_stream (XLSTREAM (tty_con->instream), |
121 Fget_coding_system (Vkeyboard_coding_system)); | 120 Fget_coding_system (Vkeyboard_coding_system)); |
122 Lstream_set_character_mode (XLSTREAM (CONSOLE_TTY_DATA (con)->instream)); | 121 Lstream_set_character_mode (XLSTREAM (tty_con->instream)); |
123 CONSOLE_TTY_DATA (con)->outstream = | 122 tty_con->outstream = |
124 make_encoding_output_stream (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream), | 123 make_encoding_output_stream (XLSTREAM (tty_con->outstream), |
125 Fget_coding_system (Vterminal_coding_system)); | 124 Fget_coding_system (Vterminal_coding_system)); |
126 #endif /* MULE */ | 125 #endif /* MULE */ |
127 CONSOLE_TTY_DATA (con)->terminal_type = terminal_type; | 126 tty_con->terminal_type = terminal_type; |
128 CONSOLE_TTY_DATA (con)->controlling_process = controlling_process; | 127 tty_con->controlling_process = controlling_process; |
129 | 128 |
130 #ifdef HAVE_GPM | 129 #ifdef HAVE_GPM |
131 connect_to_gpm(con); | 130 connect_to_gpm (con); |
132 #endif | 131 #endif |
133 | 132 |
134 if (NILP (CONSOLE_NAME (con))) | 133 if (NILP (CONSOLE_NAME (con))) |
135 CONSOLE_NAME (con) = Ffile_name_nondirectory (tty); | 134 CONSOLE_NAME (con) = Ffile_name_nondirectory (tty); |
136 { | 135 { |
143 if it has the same foreground process group as our controlling | 142 if it has the same foreground process group as our controlling |
144 TTY. This is OK because a process group can never simultaneously | 143 TTY. This is OK because a process group can never simultaneously |
145 be the foreground process group of two TTY's (in that case it | 144 be the foreground process group of two TTY's (in that case it |
146 would have two controlling TTY's, which is not allowed). */ | 145 would have two controlling TTY's, which is not allowed). */ |
147 | 146 |
148 EMACS_GET_TTY_PROCESS_GROUP (infd, &tty_pg); | 147 EMACS_GET_TTY_PROCESS_GROUP (tty_con->infd, &tty_pg); |
149 cfd = open ("/dev/tty", O_RDWR, 0); | 148 cfd = open ("/dev/tty", O_RDWR, 0); |
150 EMACS_GET_TTY_PROCESS_GROUP (cfd, &controlling_tty_pg); | 149 EMACS_GET_TTY_PROCESS_GROUP (cfd, &controlling_tty_pg); |
151 close (cfd); | 150 close (cfd); |
152 if (tty_pg == controlling_tty_pg) | 151 if (tty_pg == controlling_tty_pg) |
153 { | 152 { |
154 CONSOLE_TTY_DATA (con)->controlling_terminal = 1; | 153 tty_con->controlling_terminal = 1; |
155 XSETCONSOLE (Vcontrolling_terminal, con); | 154 XSETCONSOLE (Vcontrolling_terminal, con); |
156 munge_tty_process_group (); | 155 munge_tty_process_group (); |
157 } | 156 } |
158 else | 157 else |
159 CONSOLE_TTY_DATA (con)->controlling_terminal = 0; | 158 tty_con->controlling_terminal = 0; |
160 } | 159 } |
161 | 160 |
162 UNGCPRO; | 161 UNGCPRO; |
163 } | 162 } |
164 | 163 |
165 static void | 164 static void |
166 tty_mark_console (struct console *con, void (*markobj) (Lisp_Object)) | 165 tty_mark_console (struct console *con, void (*markobj) (Lisp_Object)) |
167 { | 166 { |
168 ((markobj) (CONSOLE_TTY_DATA (con)->terminal_type)); | 167 struct tty_console *tty_con = CONSOLE_TTY_DATA (con); |
169 ((markobj) (CONSOLE_TTY_DATA (con)->instream)); | 168 ((markobj) (tty_con->terminal_type)); |
170 ((markobj) (CONSOLE_TTY_DATA (con)->outstream)); | 169 ((markobj) (tty_con->instream)); |
170 ((markobj) (tty_con->outstream)); | |
171 } | 171 } |
172 | 172 |
173 static int | 173 static int |
174 tty_initially_selected_for_input (struct console *con) | 174 tty_initially_selected_for_input (struct console *con) |
175 { | 175 { |
177 } | 177 } |
178 | 178 |
179 static void | 179 static void |
180 free_tty_console_struct (struct console *con) | 180 free_tty_console_struct (struct console *con) |
181 { | 181 { |
182 struct tty_console *tcon = (struct tty_console *) con->console_data; | 182 struct tty_console *tty_con = CONSOLE_TTY_DATA (con); |
183 if (tcon && tcon->term_entry_buffer) /* allocated in term_init () */ | 183 if (tty_con) |
184 { | 184 { |
185 xfree (tcon->term_entry_buffer); | 185 if (tty_con->term_entry_buffer) /* allocated in term_init () */ |
186 tcon->term_entry_buffer = NULL; | 186 { |
187 } | 187 xfree (tty_con->term_entry_buffer); |
188 if (tcon) | 188 tty_con->term_entry_buffer = NULL; |
189 { | 189 } |
190 xfree (tcon); | 190 xfree (tty_con); |
191 con->console_data = NULL; | 191 CONSOLE_TTY_DATA (con) = NULL; |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 static void | 195 static void |
196 tty_delete_console (struct console *con) | 196 tty_delete_console (struct console *con) |
222 (console)) | 222 (console)) |
223 { | 223 { |
224 return CONSOLE_TTY_DATA (decode_tty_console (console))->terminal_type; | 224 return CONSOLE_TTY_DATA (decode_tty_console (console))->terminal_type; |
225 } | 225 } |
226 | 226 |
227 DEFUN ("console-tty-controlling-process", Fconsole_tty_controlling_process, 0, 1, 0, /* | 227 DEFUN ("console-tty-controlling-process", |
228 Return the controlling process of TTY console CONSOLE. | 228 Fconsole_tty_controlling_process, 0, 1, 0, /* |
229 Return the controlling process of tty console CONSOLE. | |
229 */ | 230 */ |
230 (console)) | 231 (console)) |
231 { | 232 { |
232 return CONSOLE_TTY_DATA (decode_tty_console (console))->controlling_process; | 233 return CONSOLE_TTY_DATA (decode_tty_console (console))->controlling_process; |
233 } | 234 } |
234 | 235 |
235 #ifdef MULE | 236 #ifdef MULE |
236 DEFUN ("set-console-tty-coding-system", Fset_console_tty_coding_system, 0, 2, 0, /* | 237 |
237 Set the coding system of tty console CONSOLE to CODESYS. | 238 DEFUN ("console-tty-input-coding-system", |
238 CONSOLE defaults to the selected console. | 239 Fconsole_tty_input_coding_system, 0, 1, 0, /* |
239 CODESYS defaults to the value of `terminal-coding-system'. | 240 Return the input coding system of tty console CONSOLE. |
240 */ | |
241 (console, codesys)) | |
242 { | |
243 struct console *con = decode_tty_console (console); | |
244 codesys = NILP (codesys) ? | |
245 Vterminal_coding_system : | |
246 Fget_coding_system (codesys); | |
247 if (!NILP(codesys)) { | |
248 set_encoding_stream_coding_system (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream), | |
249 codesys); | |
250 } | |
251 return Qnil; | |
252 } | |
253 #endif /* MULE */ | |
254 | |
255 | |
256 /* redefine coding system for console tty */ | |
257 #ifdef MULE | |
258 DEFUN ("console-tty-input-coding-system", Fconsole_tty_input_coding_system, 1, 1, 0, /* | |
259 Return TTY CONSOLE's input coding system. | |
260 */ | 241 */ |
261 (console)) | 242 (console)) |
262 { | 243 { |
263 struct console *con = decode_tty_console (console); | 244 return decoding_stream_coding_system |
264 return decoding_stream_coding_system (XLSTREAM (CONSOLE_TTY_DATA (con)->instream)); | 245 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->instream)); |
265 } | 246 } |
266 | 247 |
267 DEFUN ("set-console-tty-input-coding-system", Fset_console_tty_input_coding_system, 0, 2, 0, /* | 248 DEFUN ("set-console-tty-input-coding-system", |
268 Set the coding system of tty input of console CONSOLE to CODESYS. | 249 Fset_console_tty_input_coding_system, 0, 2, 0, /* |
250 Set the input coding system of tty console CONSOLE to CODESYS. | |
269 CONSOLE defaults to the selected console. | 251 CONSOLE defaults to the selected console. |
270 CODESYS defaults to the value of `keyboard-coding-system'. | 252 CODESYS defaults to the value of `keyboard-coding-system'. |
271 */ | 253 */ |
272 (console, codesys)) | 254 (console, codesys)) |
273 { | 255 { |
274 struct console *con; | 256 set_decoding_stream_coding_system |
275 if (!NILP(console)) { | 257 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->instream), |
276 con = decode_tty_console (console); | 258 Fget_coding_system (NILP (codesys) ? Vkeyboard_coding_system : codesys)); |
277 codesys = NILP (codesys) ? | |
278 Vkeyboard_coding_system : | |
279 Fget_coding_system (codesys); | |
280 set_encoding_stream_coding_system (XLSTREAM (CONSOLE_TTY_DATA (con)->instream), | |
281 codesys); | |
282 } | |
283 return Qnil; | 259 return Qnil; |
284 } | 260 } |
285 | 261 |
286 DEFUN ("console-tty-output-coding-system", Fconsole_tty_output_coding_system, 1, 1, 0, /* | 262 DEFUN ("console-tty-output-coding-system", |
263 Fconsole_tty_output_coding_system, 0, 1, 0, /* | |
287 Return TTY CONSOLE's output coding system. | 264 Return TTY CONSOLE's output coding system. |
288 */ | 265 */ |
289 (console)) | 266 (console)) |
290 { | 267 { |
291 struct console *con = decode_tty_console (console); | 268 return encoding_stream_coding_system |
292 return encoding_stream_coding_system (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream) ); | 269 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->outstream)); |
293 } | 270 } |
294 | 271 |
295 DEFUN ("set-console-tty-output-coding-system", Fset_console_tty_output_coding_system, 0, 2, 0, /* | 272 DEFUN ("set-console-tty-output-coding-system", |
273 Fset_console_tty_output_coding_system, 0, 2, 0, /* | |
296 Set the coding system of tty output of console CONSOLE to CODESYS. | 274 Set the coding system of tty output of console CONSOLE to CODESYS. |
297 CONSOLE defaults to the selected console. | 275 CONSOLE defaults to the selected console. |
298 CODESYS defaults to the value of `terminal-coding-system'. | 276 CODESYS defaults to the value of `terminal-coding-system'. |
299 */ | 277 */ |
300 (console, codesys)) | 278 (console, codesys)) |
301 { | 279 { |
302 struct console *con; | 280 set_encoding_stream_coding_system |
303 if (!NILP(console)) { | 281 (XLSTREAM (CONSOLE_TTY_DATA (decode_tty_console (console))->outstream), |
304 con = decode_tty_console (console); | 282 Fget_coding_system (NILP (codesys) ? Vterminal_coding_system : codesys)); |
305 codesys = NILP (codesys) ? | |
306 Vterminal_coding_system : | |
307 Fget_coding_system (codesys); | |
308 set_encoding_stream_coding_system (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream), | |
309 codesys); | |
310 } | |
311 return Qnil; | 283 return Qnil; |
312 } | 284 } |
313 | 285 |
286 /* ### Move this function to lisp */ | |
287 DEFUN ("set-console-tty-coding-system", | |
288 Fset_console_tty_coding_system, 0, 2, 0, /* | |
289 Set the input and output coding systems of tty console CONSOLE to CODESYS. | |
290 CONSOLE defaults to the selected console. | |
291 If CODESYS is nil, the values of `keyboard-coding-system' and | |
292 `terminal-coding-system' will be used for the input and | |
293 output coding systems of CONSOLE. | |
294 */ | |
295 (console, codesys)) | |
296 { | |
297 Fset_console_tty_input_coding_system (console, codesys); | |
298 Fset_console_tty_output_coding_system (console, codesys); | |
299 return Qnil; | |
300 } | |
314 #endif /* MULE */ | 301 #endif /* MULE */ |
315 | 302 |
316 | 303 |
317 Lisp_Object | 304 Lisp_Object |
318 tty_semi_canonicalize_console_connection (Lisp_Object connection, | 305 tty_semi_canonicalize_console_connection (Lisp_Object connection, |
358 DEFSUBR (Fconsole_tty_output_coding_system); | 345 DEFSUBR (Fconsole_tty_output_coding_system); |
359 DEFSUBR (Fset_console_tty_output_coding_system); | 346 DEFSUBR (Fset_console_tty_output_coding_system); |
360 DEFSUBR (Fconsole_tty_input_coding_system); | 347 DEFSUBR (Fconsole_tty_input_coding_system); |
361 DEFSUBR (Fset_console_tty_input_coding_system); | 348 DEFSUBR (Fset_console_tty_input_coding_system); |
362 DEFSUBR (Fset_console_tty_coding_system); | 349 DEFSUBR (Fset_console_tty_coding_system); |
363 #endif | 350 #endif /* MULE */ |
364 } | 351 } |
365 | 352 |
366 void | 353 void |
367 console_type_create_tty (void) | 354 console_type_create_tty (void) |
368 { | 355 { |