Mercurial > hg > xemacs-beta
annotate src/console-stream.c @ 5464:e79916901603 r21-5-30
XEmacs 21.5.30 "garlic" is released.
author | Stephen J. Turnbull <stephen@xemacs.org> |
---|---|
date | Wed, 27 Apr 2011 01:24:28 +0900 |
parents | 7be849cb8828 |
children | 308d34e9f07d |
rev | line source |
---|---|
428 | 1 /* Stream device functions. |
2 Copyright (C) 1995 Free Software Foundation, Inc. | |
1279 | 3 Copyright (C) 1996, 2001, 2002, 2003 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with XEmacs; see the file COPYING. If not, write to | |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 /* Synched up with: Not in FSF. */ | |
23 | |
24 /* This file has been Mule-ized. */ | |
25 | |
26 /* Written by Ben Wing. */ | |
27 | |
28 #include <config.h> | |
29 #include "lisp.h" | |
30 | |
872 | 31 #include "device-impl.h" |
428 | 32 #include "events.h" |
872 | 33 #include "frame-impl.h" |
428 | 34 #include "redisplay.h" |
35 #include "sysdep.h" | |
800 | 36 #include "window.h" |
37 | |
872 | 38 #include "console-stream-impl.h" |
800 | 39 #include "console-tty.h" |
40 | |
428 | 41 #include "sysfile.h" |
42 | |
43 DEFINE_CONSOLE_TYPE (stream); | |
44 | |
45 Lisp_Object Vterminal_console; | |
46 Lisp_Object Vterminal_device; | |
47 Lisp_Object Vterminal_frame; | |
48 | |
49 Lisp_Object Vstdio_str; | |
50 | |
1204 | 51 static const struct memory_description stream_console_data_description_1 [] = { |
52 { XD_LISP_OBJECT, offsetof (struct stream_console, instream) }, | |
53 { XD_END } | |
54 }; | |
55 | |
3092 | 56 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
57 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("stream-console", stream_console, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
58 0, stream_console_data_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
59 Lisp_Stream_Console); |
3092 | 60 #else /* not NEW_GC */ |
1204 | 61 const struct sized_memory_description stream_console_data_description = { |
62 sizeof (struct stream_console), stream_console_data_description_1 | |
63 }; | |
3092 | 64 #endif /* not NEW_GC */ |
1204 | 65 |
428 | 66 static void |
2286 | 67 stream_init_console (struct console *con, Lisp_Object UNUSED (params)) |
428 | 68 { |
69 Lisp_Object tty = CONSOLE_CONNECTION (con); | |
70 struct stream_console *stream_con; | |
71 | |
3092 | 72 #ifdef NEW_GC |
73 if (CONSOLE_STREAM_DATA (con) == NULL) | |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
74 CONSOLE_STREAM_DATA (con) = |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
75 XSTREAM_CONSOLE (ALLOC_NORMAL_LISP_OBJECT (stream_console)); |
3092 | 76 #else /* not NEW_GC */ |
428 | 77 if (CONSOLE_STREAM_DATA (con) == NULL) |
1204 | 78 CONSOLE_STREAM_DATA (con) = xnew_and_zero (struct stream_console); |
3092 | 79 #endif /* not NEW_GC */ |
428 | 80 |
81 stream_con = CONSOLE_STREAM_DATA (con); | |
82 | |
1204 | 83 stream_con->instream = Qnil; |
428 | 84 |
85 /* Open the specified console */ | |
86 if (NILP (tty) || internal_equal (tty, Vstdio_str, 0)) | |
87 { | |
88 stream_con->in = stdin; | |
89 stream_con->out = stdout; | |
90 stream_con->err = stderr; | |
91 } | |
92 else | |
93 { | |
94 CHECK_STRING (tty); | |
95 stream_con->in = stream_con->out = stream_con->err = | |
442 | 96 /* #### We don't currently do coding-system translation on |
97 this descriptor. */ | |
771 | 98 qxe_fopen (XSTRING_DATA (tty), READ_PLUS_TEXT); |
428 | 99 if (!stream_con->in) |
563 | 100 signal_error (Qio_error, "Unable to open tty", tty); |
428 | 101 } |
102 } | |
103 | |
104 static void | |
2286 | 105 stream_init_device (struct device *d, Lisp_Object UNUSED (params)) |
428 | 106 { |
107 struct console *con = XCONSOLE (DEVICE_CONSOLE (d)); | |
108 | |
109 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->in); | |
110 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->out); | |
111 init_baud_rate (d); | |
112 init_one_device (d); | |
113 } | |
114 | |
115 static int | |
2286 | 116 stream_initially_selected_for_input (struct console *UNUSED (con)) |
428 | 117 { |
118 return noninteractive && initialized; | |
119 } | |
120 | |
121 extern int stdout_needs_newline; | |
122 | |
123 static void | |
124 stream_delete_console (struct console *con) | |
125 { | |
126 struct stream_console *stream_con = CONSOLE_STREAM_DATA (con); | |
127 if (stream_con) | |
128 { | |
129 if (/* stream_con->needs_newline */ | |
130 stdout_needs_newline) /* #### clean this up */ | |
131 { | |
132 fputc ('\n', stream_con->out); | |
133 fflush (stream_con->out); | |
134 } | |
135 if (stream_con->in != stdin) | |
771 | 136 retry_fclose (stream_con->in); |
428 | 137 |
3263 | 138 #ifndef NEW_GC |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
139 xfree (stream_con); |
3092 | 140 #endif /* not NEW_GC */ |
428 | 141 CONSOLE_STREAM_DATA (con) = NULL; |
142 } | |
143 } | |
144 | |
145 Lisp_Object | |
146 stream_semi_canonicalize_console_connection (Lisp_Object connection, | |
2286 | 147 Error_Behavior UNUSED (errb)) |
428 | 148 { |
149 return NILP (connection) ? Vstdio_str : connection; | |
150 } | |
151 | |
152 Lisp_Object | |
153 stream_canonicalize_console_connection (Lisp_Object connection, | |
578 | 154 Error_Behavior errb) |
428 | 155 { |
156 if (NILP (connection) || internal_equal (connection, Vstdio_str, 0)) | |
157 return Vstdio_str; | |
158 | |
159 if (!ERRB_EQ (errb, ERROR_ME)) | |
160 { | |
161 if (!STRINGP (connection)) | |
162 return Qunbound; | |
163 } | |
164 else | |
165 CHECK_STRING (connection); | |
166 | |
167 return Ffile_truename (connection, Qnil); | |
168 } | |
169 | |
170 Lisp_Object | |
171 stream_semi_canonicalize_device_connection (Lisp_Object connection, | |
578 | 172 Error_Behavior errb) |
428 | 173 { |
174 return stream_semi_canonicalize_console_connection (connection, errb); | |
175 } | |
176 | |
177 Lisp_Object | |
178 stream_canonicalize_device_connection (Lisp_Object connection, | |
578 | 179 Error_Behavior errb) |
428 | 180 { |
181 return stream_canonicalize_console_connection (connection, errb); | |
182 } | |
183 | |
184 | |
185 static void | |
2286 | 186 stream_init_frame_1 (struct frame *f, Lisp_Object UNUSED (props), |
771 | 187 int frame_name_is_defaulted) |
428 | 188 { |
189 #if 0 | |
190 struct device *d = XDEVICE (FRAME_DEVICE (f)); | |
191 if (!NILP (DEVICE_FRAME_LIST (d))) | |
563 | 192 invalid_operation ("Only one frame allowed on stream devices", Qunbound); |
428 | 193 #endif |
771 | 194 if (frame_name_is_defaulted) |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4928
diff
changeset
|
195 f->name = build_ascstring ("stream"); |
428 | 196 f->height = 80; |
197 f->width = 24; | |
198 f->visible = 0; /* so redisplay doesn't try to do anything */ | |
199 } | |
200 | |
201 | |
202 static int | |
4928
ea701c23ed84
change text_width method to take a window, in preparation for unicode-internal changes
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
203 stream_text_width (struct window *UNUSED (w), |
2286 | 204 struct face_cachel *UNUSED (cachel), |
205 const Ichar *UNUSED (str), Charcount len) | |
428 | 206 { |
207 return len; | |
208 } | |
209 | |
210 static int | |
2286 | 211 stream_left_margin_width (struct window *UNUSED (w)) |
428 | 212 { |
213 return 0; | |
214 } | |
215 | |
216 static int | |
2286 | 217 stream_right_margin_width (struct window *UNUSED (w)) |
428 | 218 { |
219 return 0; | |
220 } | |
221 | |
222 static int | |
223 stream_divider_height (void) | |
224 { | |
225 return 1; | |
226 } | |
227 | |
228 static int | |
229 stream_eol_cursor_width (void) | |
230 { | |
231 return 1; | |
232 } | |
233 | |
1279 | 234 /* We used to try and check for redisplaying on stream devices (e.g. in |
235 redisplay_device(), and beg out if so. However, we didn't always manage | |
236 completely. Now we do manage completely, and to verify this we abort if | |
237 we try to display a stream device. This might fix some crashes I've | |
238 been getting in pdump -- the only difference between crash and non-crash | |
239 is a few changes to the redisplay critical-section handling. */ | |
240 | |
241 static void | |
2286 | 242 stream_window_output_begin (struct window *UNUSED (w)) |
1279 | 243 { |
2500 | 244 ABORT (); |
1279 | 245 } |
246 | |
247 static void | |
2286 | 248 stream_window_output_end (struct window *UNUSED (w)) |
1279 | 249 { |
2500 | 250 ABORT (); |
1279 | 251 } |
252 | |
253 static void | |
2286 | 254 stream_frame_output_begin (struct frame *UNUSED (f)) |
1279 | 255 { |
2500 | 256 ABORT (); |
1279 | 257 } |
258 | |
259 static void | |
2286 | 260 stream_frame_output_end (struct frame *UNUSED (f)) |
1279 | 261 { |
2500 | 262 ABORT (); |
1279 | 263 } |
264 | |
428 | 265 static void |
2286 | 266 stream_output_display_block (struct window *UNUSED (w), |
267 struct display_line *UNUSED (dl), | |
268 int UNUSED (block), int UNUSED (start), | |
269 int UNUSED (end), int UNUSED (start_pixpos), | |
270 int UNUSED (cursor_start), | |
271 int UNUSED (cursor_width), | |
272 int UNUSED (cursor_height)) | |
428 | 273 { |
2500 | 274 ABORT (); |
428 | 275 } |
276 | |
277 static void | |
2286 | 278 stream_clear_region (Lisp_Object UNUSED (window), struct device* UNUSED (d), |
279 struct frame *UNUSED (f), face_index UNUSED (findex), | |
280 int UNUSED (x), int UNUSED (y), int UNUSED (width), | |
281 int UNUSED (height), Lisp_Object UNUSED (fcolor), | |
282 Lisp_Object UNUSED (bcolor), | |
5080
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4976
diff
changeset
|
283 Lisp_Object UNUSED (background_pixmap), |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4976
diff
changeset
|
284 Lisp_Object UNUSED (background_placement)) |
428 | 285 { |
2500 | 286 ABORT (); |
428 | 287 } |
288 | |
289 static int | |
2286 | 290 stream_flash (struct device *UNUSED (d)) |
428 | 291 { |
292 return 0; /* sorry can't do it */ | |
293 } | |
294 | |
295 static void | |
2286 | 296 stream_ring_bell (struct device *d, int UNUSED (volume), int UNUSED (pitch), |
297 int UNUSED (duration)) | |
428 | 298 { |
299 struct console *c = XCONSOLE (DEVICE_CONSOLE (d)); | |
826 | 300 /* Don't output ^G when not a TTY -- in particular, under MS Windows, ^G |
301 is interpreted as bell by the console, but not when running under | |
302 VC++. Probably this would be the same under Unix. */ | |
303 if (isatty (fileno (CONSOLE_STREAM_DATA (c)->out))) | |
304 { | |
305 fputc (07, CONSOLE_STREAM_DATA (c)->out); | |
306 fflush (CONSOLE_STREAM_DATA (c)->out); | |
307 } | |
428 | 308 } |
309 | |
310 | |
311 /************************************************************************/ | |
312 /* initialization */ | |
313 /************************************************************************/ | |
314 | |
315 void | |
316 console_type_create_stream (void) | |
317 { | |
318 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p"); | |
319 | |
320 /* console methods */ | |
321 CONSOLE_HAS_METHOD (stream, init_console); | |
322 CONSOLE_HAS_METHOD (stream, initially_selected_for_input); | |
323 CONSOLE_HAS_METHOD (stream, delete_console); | |
324 CONSOLE_HAS_METHOD (stream, canonicalize_console_connection); | |
325 CONSOLE_HAS_METHOD (stream, canonicalize_device_connection); | |
326 CONSOLE_HAS_METHOD (stream, semi_canonicalize_console_connection); | |
327 CONSOLE_HAS_METHOD (stream, semi_canonicalize_device_connection); | |
328 | |
329 /* device methods */ | |
330 CONSOLE_HAS_METHOD (stream, init_device); | |
331 | |
332 /* frame methods */ | |
333 CONSOLE_HAS_METHOD (stream, init_frame_1); | |
334 | |
335 /* redisplay methods */ | |
1279 | 336 CONSOLE_HAS_METHOD (stream, text_width); |
428 | 337 CONSOLE_HAS_METHOD (stream, left_margin_width); |
338 CONSOLE_HAS_METHOD (stream, right_margin_width); | |
339 CONSOLE_HAS_METHOD (stream, divider_height); | |
340 CONSOLE_HAS_METHOD (stream, eol_cursor_width); | |
1279 | 341 CONSOLE_HAS_METHOD (stream, window_output_begin); |
342 CONSOLE_HAS_METHOD (stream, window_output_end); | |
343 CONSOLE_HAS_METHOD (stream, frame_output_begin); | |
344 CONSOLE_HAS_METHOD (stream, frame_output_end); | |
345 CONSOLE_HAS_METHOD (stream, output_display_block); | |
428 | 346 CONSOLE_HAS_METHOD (stream, clear_region); |
347 CONSOLE_HAS_METHOD (stream, flash); | |
348 CONSOLE_HAS_METHOD (stream, ring_bell); | |
349 } | |
350 | |
351 void | |
352 reinit_console_type_create_stream (void) | |
353 { | |
354 REINITIALIZE_CONSOLE_TYPE (stream); | |
355 } | |
356 | |
357 void | |
358 vars_of_console_stream (void) | |
359 { | |
360 DEFVAR_LISP ("terminal-console", &Vterminal_console /* | |
444 | 361 The initial console object, which represents XEmacs' stdout. |
428 | 362 */ ); |
363 Vterminal_console = Qnil; | |
364 | |
365 DEFVAR_LISP ("terminal-device", &Vterminal_device /* | |
444 | 366 The initial device object, which represents XEmacs' stdout. |
428 | 367 */ ); |
368 Vterminal_device = Qnil; | |
369 | |
370 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /* | |
444 | 371 The initial frame object, which represents XEmacs' stdout. |
428 | 372 */ ); |
373 Vterminal_frame = Qnil; | |
374 | |
375 /* Moved from console-tty.c */ | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4928
diff
changeset
|
376 Vstdio_str = build_ascstring ("stdio"); |
428 | 377 staticpro (&Vstdio_str); |
378 } | |
379 | |
380 #ifndef PDUMP | |
381 void | |
2342 | 382 init_console_stream (int UNUSED (reinit)) |
428 | 383 { |
384 /* This function can GC */ | |
385 if (!initialized) | |
386 { | |
387 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil); | |
388 Vterminal_console = Fdevice_console (Vterminal_device); | |
389 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device); | |
390 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window; | |
391 } | |
392 else | |
393 { | |
394 /* Re-initialize the FILE fields of the console. */ | |
395 stream_init_console (XCONSOLE (Vterminal_console), Qnil); | |
396 if (noninteractive) | |
397 event_stream_select_console (XCONSOLE (Vterminal_console)); | |
398 } | |
399 } | |
400 | |
401 #else | |
402 | |
403 void | |
442 | 404 init_console_stream (int reinit) |
428 | 405 { |
406 /* This function can GC */ | |
442 | 407 if (!reinit) |
408 { | |
409 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil); | |
410 Vterminal_console = Fdevice_console (Vterminal_device); | |
411 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device); | |
412 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window; | |
413 } | |
428 | 414 if (initialized) |
415 { | |
416 stream_init_console (XCONSOLE (Vterminal_console), Qnil); | |
417 if (noninteractive) | |
418 event_stream_select_console (XCONSOLE (Vterminal_console)); | |
419 } | |
420 } | |
421 #endif |