comparison src/console-tty.c @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents ec9a17fef872
children c7528f8e288d
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
40 #endif 40 #endif
41 41
42 DEFINE_CONSOLE_TYPE (tty); 42 DEFINE_CONSOLE_TYPE (tty);
43 43
44 Lisp_Object Qterminal_type; 44 Lisp_Object Qterminal_type;
45 Lisp_Object Qcontrolling_process; 45
46 46 Lisp_Object Vstdio_str;
47 extern Lisp_Object Vstdio_str; /* in console-stream.c */ 47
48 48
49 static void 49 static void
50 allocate_tty_console_struct (struct console *con) 50 allocate_tty_console_struct (struct console *con)
51 { 51 {
52 con->console_data = 52 con->console_data =
61 } 61 }
62 62
63 static void 63 static void
64 tty_init_console (struct console *con, Lisp_Object props) 64 tty_init_console (struct console *con, Lisp_Object props)
65 { 65 {
66 Lisp_Object tty = CONSOLE_CONNECTION (con); 66 Lisp_Object tty = CONSOLE_CONNECTION (con), terminal_type = Qnil;
67 Lisp_Object terminal_type = Qnil, controlling_process = Qnil;
68 int infd, outfd; 67 int infd, outfd;
69 struct gcpro gcpro1, gcpro2; 68 struct gcpro gcpro1;
70 69
71 GCPRO2 (terminal_type, controlling_process); 70 GCPRO1 (terminal_type);
72 71
73 terminal_type = Fplist_get (props, Qterminal_type, Qnil); 72 terminal_type = Fplist_get (props, Qterminal_type, Qnil);
74 controlling_process = Fplist_get(props, Qcontrolling_process, Qnil); 73
75
76 /* Determine the terminal type */ 74 /* Determine the terminal type */
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
86 error ("Cannot determine terminal type"); 84 error ("Cannot determine terminal type");
87 } 85 }
88 else 86 else
89 terminal_type = build_string (temp_type); 87 terminal_type = build_string (temp_type);
90 } 88 }
91
92 /* Determine the controlling process */
93 if (!NILP (controlling_process))
94 CHECK_INT (controlling_process);
95 89
96 /* Open the specified console */ 90 /* Open the specified console */
97 91
98 allocate_tty_console_struct (con); 92 allocate_tty_console_struct (con);
99 if (!NILP (Fequal (tty, Vstdio_str))) 93 if (!NILP (Fequal (tty, Vstdio_str)))
114 CONSOLE_TTY_DATA (con)->outfd = outfd; 108 CONSOLE_TTY_DATA (con)->outfd = outfd;
115 CONSOLE_TTY_DATA (con)->instream = make_filedesc_input_stream (infd, 0, 109 CONSOLE_TTY_DATA (con)->instream = make_filedesc_input_stream (infd, 0,
116 -1, 0); 110 -1, 0);
117 CONSOLE_TTY_DATA (con)->outstream = make_filedesc_output_stream (outfd, 0, 111 CONSOLE_TTY_DATA (con)->outstream = make_filedesc_output_stream (outfd, 0,
118 -1, 0); 112 -1, 0);
113 #ifdef MULE
114 CONSOLE_TTY_DATA (con)->instream =
115 make_decoding_input_stream (XLSTREAM (CONSOLE_TTY_DATA (con)->instream),
116 Fget_coding_system (Vkeyboard_coding_system));
117 Lstream_set_character_mode (XLSTREAM (CONSOLE_TTY_DATA (con)->instream));
118 CONSOLE_TTY_DATA (con)->outstream =
119 make_encoding_output_stream (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream),
120 Fget_coding_system (Vterminal_coding_system));
121 #endif /* MULE */
119 CONSOLE_TTY_DATA (con)->terminal_type = terminal_type; 122 CONSOLE_TTY_DATA (con)->terminal_type = terminal_type;
120 CONSOLE_TTY_DATA (con)->controlling_process = controlling_process;
121 if (NILP (CONSOLE_NAME (con))) 123 if (NILP (CONSOLE_NAME (con)))
122 CONSOLE_NAME (con) = Ffile_name_nondirectory (tty); 124 CONSOLE_NAME (con) = Ffile_name_nondirectory (tty);
123 { 125 {
124 int tty_pg; 126 int tty_pg;
125 int controlling_tty_pg; 127 int controlling_tty_pg;
203 (console)) 205 (console))
204 { 206 {
205 return CONSOLE_TTY_DATA (decode_tty_console (console))->terminal_type; 207 return CONSOLE_TTY_DATA (decode_tty_console (console))->terminal_type;
206 } 208 }
207 209
208 DEFUN ("console-tty-controlling-process", Fconsole_tty_controlling_process, 0, 1, 0, /*
209 Return the controlling process of TTY console CONSOLE.
210 */
211 (console))
212 {
213 return CONSOLE_TTY_DATA (decode_tty_console (console))->controlling_process;
214 }
215
216 extern Lisp_Object stream_semi_canonicalize_console_connection(Lisp_Object,
217 Error_behavior);
218 Lisp_Object 210 Lisp_Object
219 tty_semi_canonicalize_console_connection (Lisp_Object connection, 211 tty_semi_canonicalize_console_connection (Lisp_Object connection,
220 Error_behavior errb) 212 Error_behavior errb)
221 { 213 {
222 return stream_semi_canonicalize_console_connection (connection, errb); 214 if (NILP (connection))
223 } 215 return Vstdio_str;
224 216
225 extern Lisp_Object stream_canonicalize_console_connection(Lisp_Object, 217 return connection;
226 Error_behavior); 218 }
219
227 Lisp_Object 220 Lisp_Object
228 tty_canonicalize_console_connection (Lisp_Object connection, 221 tty_canonicalize_console_connection (Lisp_Object connection,
229 Error_behavior errb) 222 Error_behavior errb)
230 { 223 {
231 return stream_canonicalize_console_connection (connection, errb); 224 if (NILP (connection) || !NILP (Fequal (connection, Vstdio_str)))
225 return Vstdio_str;
226
227 if (!ERRB_EQ (errb, ERROR_ME))
228 {
229 if (!STRINGP (connection))
230 return Qunbound;
231 }
232 else
233 CHECK_STRING (connection);
234
235 return Ffile_truename (connection, Qnil);
232 } 236 }
233 237
234 Lisp_Object 238 Lisp_Object
235 tty_semi_canonicalize_device_connection (Lisp_Object connection, 239 tty_semi_canonicalize_device_connection (Lisp_Object connection,
236 Error_behavior errb) 240 Error_behavior errb)
237 { 241 {
238 return stream_semi_canonicalize_console_connection (connection, errb); 242 return tty_semi_canonicalize_console_connection (connection, errb);
239 } 243 }
240 244
241 Lisp_Object 245 Lisp_Object
242 tty_canonicalize_device_connection (Lisp_Object connection, 246 tty_canonicalize_device_connection (Lisp_Object connection,
243 Error_behavior errb) 247 Error_behavior errb)
244 { 248 {
245 return stream_canonicalize_console_connection (connection, errb); 249 return tty_canonicalize_console_connection (connection, errb);
246 } 250 }
247 251
248 252
249 /************************************************************************/ 253 /************************************************************************/
250 /* initialization */ 254 /* initialization */
252 256
253 void 257 void
254 syms_of_console_tty (void) 258 syms_of_console_tty (void)
255 { 259 {
256 DEFSUBR (Fconsole_tty_terminal_type); 260 DEFSUBR (Fconsole_tty_terminal_type);
257 DEFSUBR (Fconsole_tty_controlling_process);
258 defsymbol (&Qterminal_type, "terminal-type"); 261 defsymbol (&Qterminal_type, "terminal-type");
259 defsymbol (&Qcontrolling_process, "controlling-process");
260 } 262 }
261 263
262 void 264 void
263 console_type_create_tty (void) 265 console_type_create_tty (void)
264 { 266 {
277 279
278 void 280 void
279 vars_of_console_tty (void) 281 vars_of_console_tty (void)
280 { 282 {
281 Fprovide (Qtty); 283 Fprovide (Qtty);
282 } 284
285 Vstdio_str = build_string ("stdio");
286 staticpro (&Vstdio_str);
287 }