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
|
|
56 const struct sized_memory_description stream_console_data_description = {
|
|
57 sizeof (struct stream_console), stream_console_data_description_1
|
|
58 };
|
|
59
|
428
|
60 static void
|
|
61 stream_init_console (struct console *con, Lisp_Object params)
|
|
62 {
|
|
63 Lisp_Object tty = CONSOLE_CONNECTION (con);
|
|
64 struct stream_console *stream_con;
|
|
65
|
|
66 if (CONSOLE_STREAM_DATA (con) == NULL)
|
1204
|
67 CONSOLE_STREAM_DATA (con) = xnew_and_zero (struct stream_console);
|
428
|
68
|
|
69 stream_con = CONSOLE_STREAM_DATA (con);
|
|
70
|
1204
|
71 stream_con->instream = Qnil;
|
428
|
72
|
|
73 /* Open the specified console */
|
|
74 if (NILP (tty) || internal_equal (tty, Vstdio_str, 0))
|
|
75 {
|
|
76 stream_con->in = stdin;
|
|
77 stream_con->out = stdout;
|
|
78 stream_con->err = stderr;
|
|
79 }
|
|
80 else
|
|
81 {
|
|
82 CHECK_STRING (tty);
|
|
83 stream_con->in = stream_con->out = stream_con->err =
|
442
|
84 /* #### We don't currently do coding-system translation on
|
|
85 this descriptor. */
|
771
|
86 qxe_fopen (XSTRING_DATA (tty), READ_PLUS_TEXT);
|
428
|
87 if (!stream_con->in)
|
563
|
88 signal_error (Qio_error, "Unable to open tty", tty);
|
428
|
89 }
|
|
90 }
|
|
91
|
|
92 static void
|
|
93 stream_init_device (struct device *d, Lisp_Object params)
|
|
94 {
|
|
95 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
96
|
|
97 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->in);
|
|
98 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->out);
|
|
99 init_baud_rate (d);
|
|
100 init_one_device (d);
|
|
101 }
|
|
102
|
|
103 static int
|
|
104 stream_initially_selected_for_input (struct console *con)
|
|
105 {
|
|
106 return noninteractive && initialized;
|
|
107 }
|
|
108
|
|
109 extern int stdout_needs_newline;
|
|
110
|
|
111 static void
|
|
112 stream_delete_console (struct console *con)
|
|
113 {
|
|
114 struct stream_console *stream_con = CONSOLE_STREAM_DATA (con);
|
|
115 if (stream_con)
|
|
116 {
|
|
117 if (/* stream_con->needs_newline */
|
|
118 stdout_needs_newline) /* #### clean this up */
|
|
119 {
|
|
120 fputc ('\n', stream_con->out);
|
|
121 fflush (stream_con->out);
|
|
122 }
|
|
123 if (stream_con->in != stdin)
|
771
|
124 retry_fclose (stream_con->in);
|
428
|
125
|
|
126 xfree (stream_con);
|
|
127 CONSOLE_STREAM_DATA (con) = NULL;
|
|
128 }
|
|
129 }
|
|
130
|
|
131 Lisp_Object
|
|
132 stream_semi_canonicalize_console_connection (Lisp_Object connection,
|
578
|
133 Error_Behavior errb)
|
428
|
134 {
|
|
135 return NILP (connection) ? Vstdio_str : connection;
|
|
136 }
|
|
137
|
|
138 Lisp_Object
|
|
139 stream_canonicalize_console_connection (Lisp_Object connection,
|
578
|
140 Error_Behavior errb)
|
428
|
141 {
|
|
142 if (NILP (connection) || internal_equal (connection, Vstdio_str, 0))
|
|
143 return Vstdio_str;
|
|
144
|
|
145 if (!ERRB_EQ (errb, ERROR_ME))
|
|
146 {
|
|
147 if (!STRINGP (connection))
|
|
148 return Qunbound;
|
|
149 }
|
|
150 else
|
|
151 CHECK_STRING (connection);
|
|
152
|
|
153 return Ffile_truename (connection, Qnil);
|
|
154 }
|
|
155
|
|
156 Lisp_Object
|
|
157 stream_semi_canonicalize_device_connection (Lisp_Object connection,
|
578
|
158 Error_Behavior errb)
|
428
|
159 {
|
|
160 return stream_semi_canonicalize_console_connection (connection, errb);
|
|
161 }
|
|
162
|
|
163 Lisp_Object
|
|
164 stream_canonicalize_device_connection (Lisp_Object connection,
|
578
|
165 Error_Behavior errb)
|
428
|
166 {
|
|
167 return stream_canonicalize_console_connection (connection, errb);
|
|
168 }
|
|
169
|
|
170
|
|
171 static void
|
771
|
172 stream_init_frame_1 (struct frame *f, Lisp_Object props,
|
|
173 int frame_name_is_defaulted)
|
428
|
174 {
|
|
175 #if 0
|
|
176 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
177 if (!NILP (DEVICE_FRAME_LIST (d)))
|
563
|
178 invalid_operation ("Only one frame allowed on stream devices", Qunbound);
|
428
|
179 #endif
|
771
|
180 if (frame_name_is_defaulted)
|
|
181 f->name = build_string ("stream");
|
428
|
182 f->height = 80;
|
|
183 f->width = 24;
|
|
184 f->visible = 0; /* so redisplay doesn't try to do anything */
|
|
185 }
|
|
186
|
|
187
|
|
188 static int
|
|
189 stream_text_width (struct frame *f, struct face_cachel *cachel,
|
867
|
190 const Ichar *str, Charcount len)
|
428
|
191 {
|
|
192 return len;
|
|
193 }
|
|
194
|
|
195 static int
|
|
196 stream_left_margin_width (struct window *w)
|
|
197 {
|
|
198 return 0;
|
|
199 }
|
|
200
|
|
201 static int
|
|
202 stream_right_margin_width (struct window *w)
|
|
203 {
|
|
204 return 0;
|
|
205 }
|
|
206
|
|
207 static int
|
|
208 stream_divider_height (void)
|
|
209 {
|
|
210 return 1;
|
|
211 }
|
|
212
|
|
213 static int
|
|
214 stream_eol_cursor_width (void)
|
|
215 {
|
|
216 return 1;
|
|
217 }
|
|
218
|
1279
|
219 /* We used to try and check for redisplaying on stream devices (e.g. in
|
|
220 redisplay_device(), and beg out if so. However, we didn't always manage
|
|
221 completely. Now we do manage completely, and to verify this we abort if
|
|
222 we try to display a stream device. This might fix some crashes I've
|
|
223 been getting in pdump -- the only difference between crash and non-crash
|
|
224 is a few changes to the redisplay critical-section handling. */
|
|
225
|
|
226 static void
|
|
227 stream_window_output_begin (struct window *w)
|
|
228 {
|
|
229 abort ();
|
|
230 }
|
|
231
|
|
232 static void
|
|
233 stream_window_output_end (struct window *w)
|
|
234 {
|
|
235 abort ();
|
|
236 }
|
|
237
|
|
238 static void
|
|
239 stream_frame_output_begin (struct frame *f)
|
|
240 {
|
|
241 abort ();
|
|
242 }
|
|
243
|
|
244 static void
|
|
245 stream_frame_output_end (struct frame *f)
|
|
246 {
|
|
247 abort ();
|
|
248 }
|
|
249
|
428
|
250 static void
|
|
251 stream_output_display_block (struct window *w, struct display_line *dl,
|
|
252 int block, int start, int end,
|
|
253 int start_pixpos, int cursor_start,
|
|
254 int cursor_width, int cursor_height)
|
|
255 {
|
1279
|
256 abort ();
|
428
|
257 }
|
|
258
|
|
259 static void
|
|
260 stream_clear_region (Lisp_Object window, struct device* d, struct frame * f,
|
826
|
261 face_index findex, int x, int y,
|
|
262 int width, int height, Lisp_Object fcolor,
|
|
263 Lisp_Object bcolor, Lisp_Object background_pixmap)
|
428
|
264 {
|
1279
|
265 abort ();
|
428
|
266 }
|
|
267
|
|
268 static int
|
|
269 stream_flash (struct device *d)
|
|
270 {
|
|
271 return 0; /* sorry can't do it */
|
|
272 }
|
|
273
|
|
274 static void
|
|
275 stream_ring_bell (struct device *d, int volume, int pitch, int duration)
|
|
276 {
|
|
277 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
826
|
278 /* Don't output ^G when not a TTY -- in particular, under MS Windows, ^G
|
|
279 is interpreted as bell by the console, but not when running under
|
|
280 VC++. Probably this would be the same under Unix. */
|
|
281 if (isatty (fileno (CONSOLE_STREAM_DATA (c)->out)))
|
|
282 {
|
|
283 fputc (07, CONSOLE_STREAM_DATA (c)->out);
|
|
284 fflush (CONSOLE_STREAM_DATA (c)->out);
|
|
285 }
|
428
|
286 }
|
|
287
|
|
288
|
|
289 /************************************************************************/
|
|
290 /* initialization */
|
|
291 /************************************************************************/
|
|
292
|
|
293 void
|
|
294 console_type_create_stream (void)
|
|
295 {
|
|
296 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p");
|
|
297
|
|
298 /* console methods */
|
|
299 CONSOLE_HAS_METHOD (stream, init_console);
|
|
300 CONSOLE_HAS_METHOD (stream, initially_selected_for_input);
|
|
301 CONSOLE_HAS_METHOD (stream, delete_console);
|
|
302 CONSOLE_HAS_METHOD (stream, canonicalize_console_connection);
|
|
303 CONSOLE_HAS_METHOD (stream, canonicalize_device_connection);
|
|
304 CONSOLE_HAS_METHOD (stream, semi_canonicalize_console_connection);
|
|
305 CONSOLE_HAS_METHOD (stream, semi_canonicalize_device_connection);
|
|
306
|
|
307 /* device methods */
|
|
308 CONSOLE_HAS_METHOD (stream, init_device);
|
|
309
|
|
310 /* frame methods */
|
|
311 CONSOLE_HAS_METHOD (stream, init_frame_1);
|
|
312
|
|
313 /* redisplay methods */
|
1279
|
314 CONSOLE_HAS_METHOD (stream, text_width);
|
428
|
315 CONSOLE_HAS_METHOD (stream, left_margin_width);
|
|
316 CONSOLE_HAS_METHOD (stream, right_margin_width);
|
|
317 CONSOLE_HAS_METHOD (stream, divider_height);
|
|
318 CONSOLE_HAS_METHOD (stream, eol_cursor_width);
|
1279
|
319 CONSOLE_HAS_METHOD (stream, window_output_begin);
|
|
320 CONSOLE_HAS_METHOD (stream, window_output_end);
|
|
321 CONSOLE_HAS_METHOD (stream, frame_output_begin);
|
|
322 CONSOLE_HAS_METHOD (stream, frame_output_end);
|
|
323 CONSOLE_HAS_METHOD (stream, output_display_block);
|
428
|
324 CONSOLE_HAS_METHOD (stream, clear_region);
|
|
325 CONSOLE_HAS_METHOD (stream, flash);
|
|
326 CONSOLE_HAS_METHOD (stream, ring_bell);
|
|
327 }
|
|
328
|
|
329 void
|
|
330 reinit_console_type_create_stream (void)
|
|
331 {
|
|
332 REINITIALIZE_CONSOLE_TYPE (stream);
|
|
333 }
|
|
334
|
|
335 void
|
|
336 vars_of_console_stream (void)
|
|
337 {
|
|
338 DEFVAR_LISP ("terminal-console", &Vterminal_console /*
|
444
|
339 The initial console object, which represents XEmacs' stdout.
|
428
|
340 */ );
|
|
341 Vterminal_console = Qnil;
|
|
342
|
|
343 DEFVAR_LISP ("terminal-device", &Vterminal_device /*
|
444
|
344 The initial device object, which represents XEmacs' stdout.
|
428
|
345 */ );
|
|
346 Vterminal_device = Qnil;
|
|
347
|
|
348 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /*
|
444
|
349 The initial frame object, which represents XEmacs' stdout.
|
428
|
350 */ );
|
|
351 Vterminal_frame = Qnil;
|
|
352
|
|
353 /* Moved from console-tty.c */
|
|
354 Vstdio_str = build_string ("stdio");
|
|
355 staticpro (&Vstdio_str);
|
|
356 }
|
|
357
|
|
358 #ifndef PDUMP
|
|
359 void
|
442
|
360 init_console_stream (int reinit)
|
428
|
361 {
|
|
362 /* This function can GC */
|
|
363 if (!initialized)
|
|
364 {
|
|
365 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
|
|
366 Vterminal_console = Fdevice_console (Vterminal_device);
|
|
367 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
|
|
368 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
|
|
369 }
|
|
370 else
|
|
371 {
|
|
372 /* Re-initialize the FILE fields of the console. */
|
|
373 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
|
|
374 if (noninteractive)
|
|
375 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
376 }
|
|
377 }
|
|
378
|
|
379 #else
|
|
380
|
|
381 void
|
442
|
382 init_console_stream (int reinit)
|
428
|
383 {
|
|
384 /* This function can GC */
|
442
|
385 if (!reinit)
|
|
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 }
|
428
|
392 if (initialized)
|
|
393 {
|
|
394 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
|
|
395 if (noninteractive)
|
|
396 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
397 }
|
|
398 }
|
|
399 #endif
|