Mercurial > hg > xemacs-beta
comparison src/console-stream.c @ 396:6719134a07c2 r21-2-13
Import from CVS: tag r21-2-13
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:12:05 +0200 |
parents | bbff43aa5eb7 |
children | 74fd4e045ea6 |
comparison
equal
deleted
inserted
replaced
395:de2c2a7459d2 | 396:6719134a07c2 |
---|---|
44 Lisp_Object Vterminal_frame; | 44 Lisp_Object Vterminal_frame; |
45 | 45 |
46 Lisp_Object Vstdio_str; | 46 Lisp_Object Vstdio_str; |
47 | 47 |
48 static void | 48 static void |
49 allocate_stream_console_struct (struct console *con) | 49 stream_init_console (struct console *con, Lisp_Object params) |
50 { | 50 { |
51 if (!CONSOLE_STREAM_DATA (con)) | 51 Lisp_Object tty = CONSOLE_CONNECTION (con); |
52 CONSOLE_STREAM_DATA (con) = xnew_and_zero (struct stream_console); | 52 struct stream_console *stream_con; |
53 | |
54 if (CONSOLE_STREAM_DATA (con) == NULL) | |
55 CONSOLE_STREAM_DATA (con) = xnew (struct stream_console); | |
56 | |
57 stream_con = CONSOLE_STREAM_DATA (con); | |
58 | |
59 stream_con->needs_newline = 0; | |
60 | |
61 /* Open the specified console */ | |
62 if (NILP (tty) || internal_equal (tty, Vstdio_str, 0)) | |
63 { | |
64 stream_con->in = stdin; | |
65 stream_con->out = stdout; | |
66 stream_con->err = stderr; | |
67 } | |
53 else | 68 else |
54 xzero (*CONSOLE_STREAM_DATA (con)); | |
55 } | |
56 | |
57 static void | |
58 stream_init_console (struct console *con, Lisp_Object params) | |
59 { | |
60 Lisp_Object tty = CONSOLE_CONNECTION (con); | |
61 FILE *infd, *outfd, *errfd; | |
62 | |
63 /* Open the specified console */ | |
64 | |
65 if (NILP (tty) || internal_equal (tty, Vstdio_str, 0)) | |
66 { | |
67 infd = stdin; | |
68 outfd = stdout; | |
69 errfd = stderr; | |
70 } | |
71 else | |
72 { | 69 { |
73 CHECK_STRING (tty); | 70 CHECK_STRING (tty); |
74 infd = outfd = errfd = | 71 stream_con->in = stream_con->out = stream_con->err = |
75 fopen ((char *) XSTRING_DATA (tty), "r+"); | 72 fopen ((char *) XSTRING_DATA (tty), "r+"); |
76 if (!infd) | 73 if (!stream_con->in) |
77 error ("Unable to open tty %s", XSTRING_DATA (tty)); | 74 error ("Unable to open tty %s", XSTRING_DATA (tty)); |
78 } | 75 } |
79 | |
80 allocate_stream_console_struct (con); | |
81 CONSOLE_STREAM_DATA (con)->infd = infd; | |
82 CONSOLE_STREAM_DATA (con)->outfd = outfd; | |
83 CONSOLE_STREAM_DATA (con)->errfd = errfd; | |
84 } | 76 } |
85 | 77 |
86 static void | 78 static void |
87 stream_init_device (struct device *d, Lisp_Object params) | 79 stream_init_device (struct device *d, Lisp_Object params) |
88 { | 80 { |
89 struct console *con = XCONSOLE (DEVICE_CONSOLE (d)); | 81 struct console *con = XCONSOLE (DEVICE_CONSOLE (d)); |
90 | 82 |
91 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->infd); | 83 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->in); |
92 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->outfd); | 84 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->out); |
93 init_baud_rate (d); | 85 init_baud_rate (d); |
94 init_one_device (d); | 86 init_one_device (d); |
95 } | 87 } |
96 | 88 |
97 static int | 89 static int |
98 stream_initially_selected_for_input (struct console *con) | 90 stream_initially_selected_for_input (struct console *con) |
99 { | 91 { |
100 return noninteractive && initialized; | 92 return noninteractive && initialized; |
101 } | 93 } |
102 | 94 |
103 static void | 95 extern int stdout_needs_newline; |
104 free_stream_console_struct (struct console *con) | 96 |
105 { | 97 static void |
106 if (CONSOLE_STREAM_DATA (con)) | 98 stream_delete_console (struct console *con) |
107 { | 99 { |
108 xfree (CONSOLE_STREAM_DATA (con)); | 100 struct stream_console *stream_con = CONSOLE_STREAM_DATA (con); |
101 if (stream_con) | |
102 { | |
103 if (/* stream_con->needs_newline */ | |
104 stdout_needs_newline) /* #### clean this up */ | |
105 { | |
106 fputc ('\n', stream_con->out); | |
107 fflush (stream_con->out); | |
108 } | |
109 if (stream_con->in != stdin) | |
110 fclose (stream_con->in); | |
111 | |
112 xfree (stream_con); | |
109 CONSOLE_STREAM_DATA (con) = NULL; | 113 CONSOLE_STREAM_DATA (con) = NULL; |
110 } | 114 } |
111 } | |
112 | |
113 extern int stdout_needs_newline; | |
114 | |
115 static void | |
116 stream_delete_console (struct console *con) | |
117 { | |
118 if (/* CONSOLE_STREAM_DATA (con)->needs_newline */ | |
119 stdout_needs_newline) /* #### clean this up */ | |
120 { | |
121 fputc ('\n', CONSOLE_STREAM_DATA (con)->outfd); | |
122 fflush (CONSOLE_STREAM_DATA (con)->outfd); | |
123 } | |
124 if (CONSOLE_STREAM_DATA (con)->infd != stdin) | |
125 fclose (CONSOLE_STREAM_DATA (con)->infd); | |
126 free_stream_console_struct (con); | |
127 } | 115 } |
128 | 116 |
129 Lisp_Object | 117 Lisp_Object |
130 stream_semi_canonicalize_console_connection (Lisp_Object connection, | 118 stream_semi_canonicalize_console_connection (Lisp_Object connection, |
131 Error_behavior errb) | 119 Error_behavior errb) |
241 } | 229 } |
242 | 230 |
243 static void | 231 static void |
244 stream_clear_region (Lisp_Object window, struct device* d, struct frame * f, | 232 stream_clear_region (Lisp_Object window, struct device* d, struct frame * f, |
245 face_index findex, int x, int y, | 233 face_index findex, int x, int y, |
246 int width, int height, Lisp_Object fcolor, Lisp_Object bcolor, | 234 int width, int height, Lisp_Object fcolor, Lisp_Object bcolor, |
247 Lisp_Object background_pixmap) | 235 Lisp_Object background_pixmap) |
248 { | 236 { |
249 } | 237 } |
250 | 238 |
251 static void | 239 static void |
261 | 249 |
262 static void | 250 static void |
263 stream_ring_bell (struct device *d, int volume, int pitch, int duration) | 251 stream_ring_bell (struct device *d, int volume, int pitch, int duration) |
264 { | 252 { |
265 struct console *c = XCONSOLE (DEVICE_CONSOLE (d)); | 253 struct console *c = XCONSOLE (DEVICE_CONSOLE (d)); |
266 fputc (07, CONSOLE_STREAM_DATA (c)->outfd); | 254 fputc (07, CONSOLE_STREAM_DATA (c)->out); |
267 fflush (CONSOLE_STREAM_DATA (c)->outfd); | 255 fflush (CONSOLE_STREAM_DATA (c)->out); |
268 } | 256 } |
269 | 257 |
270 | 258 |
271 /************************************************************************/ | 259 /************************************************************************/ |
272 /* initialization */ | 260 /* initialization */ |