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
|
2286
|
61 stream_init_console (struct console *con, Lisp_Object UNUSED (params))
|
428
|
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
|
2286
|
93 stream_init_device (struct device *d, Lisp_Object UNUSED (params))
|
428
|
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
|
2286
|
104 stream_initially_selected_for_input (struct console *UNUSED (con))
|
428
|
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
|
1726
|
126 xfree (stream_con, struct stream_console *);
|
428
|
127 CONSOLE_STREAM_DATA (con) = NULL;
|
|
128 }
|
|
129 }
|
|
130
|
|
131 Lisp_Object
|
|
132 stream_semi_canonicalize_console_connection (Lisp_Object connection,
|
2286
|
133 Error_Behavior UNUSED (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
|
2286
|
172 stream_init_frame_1 (struct frame *f, Lisp_Object UNUSED (props),
|
771
|
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
|
2286
|
189 stream_text_width (struct frame *UNUSED (f),
|
|
190 struct face_cachel *UNUSED (cachel),
|
|
191 const Ichar *UNUSED (str), Charcount len)
|
428
|
192 {
|
|
193 return len;
|
|
194 }
|
|
195
|
|
196 static int
|
2286
|
197 stream_left_margin_width (struct window *UNUSED (w))
|
428
|
198 {
|
|
199 return 0;
|
|
200 }
|
|
201
|
|
202 static int
|
2286
|
203 stream_right_margin_width (struct window *UNUSED (w))
|
428
|
204 {
|
|
205 return 0;
|
|
206 }
|
|
207
|
|
208 static int
|
|
209 stream_divider_height (void)
|
|
210 {
|
|
211 return 1;
|
|
212 }
|
|
213
|
|
214 static int
|
|
215 stream_eol_cursor_width (void)
|
|
216 {
|
|
217 return 1;
|
|
218 }
|
|
219
|
1279
|
220 /* We used to try and check for redisplaying on stream devices (e.g. in
|
|
221 redisplay_device(), and beg out if so. However, we didn't always manage
|
|
222 completely. Now we do manage completely, and to verify this we abort if
|
|
223 we try to display a stream device. This might fix some crashes I've
|
|
224 been getting in pdump -- the only difference between crash and non-crash
|
|
225 is a few changes to the redisplay critical-section handling. */
|
|
226
|
|
227 static void
|
2286
|
228 stream_window_output_begin (struct window *UNUSED (w))
|
1279
|
229 {
|
2500
|
230 ABORT ();
|
1279
|
231 }
|
|
232
|
|
233 static void
|
2286
|
234 stream_window_output_end (struct window *UNUSED (w))
|
1279
|
235 {
|
2500
|
236 ABORT ();
|
1279
|
237 }
|
|
238
|
|
239 static void
|
2286
|
240 stream_frame_output_begin (struct frame *UNUSED (f))
|
1279
|
241 {
|
2500
|
242 ABORT ();
|
1279
|
243 }
|
|
244
|
|
245 static void
|
2286
|
246 stream_frame_output_end (struct frame *UNUSED (f))
|
1279
|
247 {
|
2500
|
248 ABORT ();
|
1279
|
249 }
|
|
250
|
428
|
251 static void
|
2286
|
252 stream_output_display_block (struct window *UNUSED (w),
|
|
253 struct display_line *UNUSED (dl),
|
|
254 int UNUSED (block), int UNUSED (start),
|
|
255 int UNUSED (end), int UNUSED (start_pixpos),
|
|
256 int UNUSED (cursor_start),
|
|
257 int UNUSED (cursor_width),
|
|
258 int UNUSED (cursor_height))
|
428
|
259 {
|
2500
|
260 ABORT ();
|
428
|
261 }
|
|
262
|
|
263 static void
|
2286
|
264 stream_clear_region (Lisp_Object UNUSED (window), struct device* UNUSED (d),
|
|
265 struct frame *UNUSED (f), face_index UNUSED (findex),
|
|
266 int UNUSED (x), int UNUSED (y), int UNUSED (width),
|
|
267 int UNUSED (height), Lisp_Object UNUSED (fcolor),
|
|
268 Lisp_Object UNUSED (bcolor),
|
|
269 Lisp_Object UNUSED (background_pixmap))
|
428
|
270 {
|
2500
|
271 ABORT ();
|
428
|
272 }
|
|
273
|
|
274 static int
|
2286
|
275 stream_flash (struct device *UNUSED (d))
|
428
|
276 {
|
|
277 return 0; /* sorry can't do it */
|
|
278 }
|
|
279
|
|
280 static void
|
2286
|
281 stream_ring_bell (struct device *d, int UNUSED (volume), int UNUSED (pitch),
|
|
282 int UNUSED (duration))
|
428
|
283 {
|
|
284 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
826
|
285 /* Don't output ^G when not a TTY -- in particular, under MS Windows, ^G
|
|
286 is interpreted as bell by the console, but not when running under
|
|
287 VC++. Probably this would be the same under Unix. */
|
|
288 if (isatty (fileno (CONSOLE_STREAM_DATA (c)->out)))
|
|
289 {
|
|
290 fputc (07, CONSOLE_STREAM_DATA (c)->out);
|
|
291 fflush (CONSOLE_STREAM_DATA (c)->out);
|
|
292 }
|
428
|
293 }
|
|
294
|
|
295
|
|
296 /************************************************************************/
|
|
297 /* initialization */
|
|
298 /************************************************************************/
|
|
299
|
|
300 void
|
|
301 console_type_create_stream (void)
|
|
302 {
|
|
303 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p");
|
|
304
|
|
305 /* console methods */
|
|
306 CONSOLE_HAS_METHOD (stream, init_console);
|
|
307 CONSOLE_HAS_METHOD (stream, initially_selected_for_input);
|
|
308 CONSOLE_HAS_METHOD (stream, delete_console);
|
|
309 CONSOLE_HAS_METHOD (stream, canonicalize_console_connection);
|
|
310 CONSOLE_HAS_METHOD (stream, canonicalize_device_connection);
|
|
311 CONSOLE_HAS_METHOD (stream, semi_canonicalize_console_connection);
|
|
312 CONSOLE_HAS_METHOD (stream, semi_canonicalize_device_connection);
|
|
313
|
|
314 /* device methods */
|
|
315 CONSOLE_HAS_METHOD (stream, init_device);
|
|
316
|
|
317 /* frame methods */
|
|
318 CONSOLE_HAS_METHOD (stream, init_frame_1);
|
|
319
|
|
320 /* redisplay methods */
|
1279
|
321 CONSOLE_HAS_METHOD (stream, text_width);
|
428
|
322 CONSOLE_HAS_METHOD (stream, left_margin_width);
|
|
323 CONSOLE_HAS_METHOD (stream, right_margin_width);
|
|
324 CONSOLE_HAS_METHOD (stream, divider_height);
|
|
325 CONSOLE_HAS_METHOD (stream, eol_cursor_width);
|
1279
|
326 CONSOLE_HAS_METHOD (stream, window_output_begin);
|
|
327 CONSOLE_HAS_METHOD (stream, window_output_end);
|
|
328 CONSOLE_HAS_METHOD (stream, frame_output_begin);
|
|
329 CONSOLE_HAS_METHOD (stream, frame_output_end);
|
|
330 CONSOLE_HAS_METHOD (stream, output_display_block);
|
428
|
331 CONSOLE_HAS_METHOD (stream, clear_region);
|
|
332 CONSOLE_HAS_METHOD (stream, flash);
|
|
333 CONSOLE_HAS_METHOD (stream, ring_bell);
|
|
334 }
|
|
335
|
|
336 void
|
|
337 reinit_console_type_create_stream (void)
|
|
338 {
|
|
339 REINITIALIZE_CONSOLE_TYPE (stream);
|
|
340 }
|
|
341
|
|
342 void
|
|
343 vars_of_console_stream (void)
|
|
344 {
|
|
345 DEFVAR_LISP ("terminal-console", &Vterminal_console /*
|
444
|
346 The initial console object, which represents XEmacs' stdout.
|
428
|
347 */ );
|
|
348 Vterminal_console = Qnil;
|
|
349
|
|
350 DEFVAR_LISP ("terminal-device", &Vterminal_device /*
|
444
|
351 The initial device object, which represents XEmacs' stdout.
|
428
|
352 */ );
|
|
353 Vterminal_device = Qnil;
|
|
354
|
|
355 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /*
|
444
|
356 The initial frame object, which represents XEmacs' stdout.
|
428
|
357 */ );
|
|
358 Vterminal_frame = Qnil;
|
|
359
|
|
360 /* Moved from console-tty.c */
|
|
361 Vstdio_str = build_string ("stdio");
|
|
362 staticpro (&Vstdio_str);
|
|
363 }
|
|
364
|
|
365 #ifndef PDUMP
|
|
366 void
|
2342
|
367 init_console_stream (int UNUSED (reinit))
|
428
|
368 {
|
|
369 /* This function can GC */
|
|
370 if (!initialized)
|
|
371 {
|
|
372 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
|
|
373 Vterminal_console = Fdevice_console (Vterminal_device);
|
|
374 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
|
|
375 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
|
|
376 }
|
|
377 else
|
|
378 {
|
|
379 /* Re-initialize the FILE fields of the console. */
|
|
380 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
|
|
381 if (noninteractive)
|
|
382 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
383 }
|
|
384 }
|
|
385
|
|
386 #else
|
|
387
|
|
388 void
|
442
|
389 init_console_stream (int reinit)
|
428
|
390 {
|
|
391 /* This function can GC */
|
442
|
392 if (!reinit)
|
|
393 {
|
|
394 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
|
|
395 Vterminal_console = Fdevice_console (Vterminal_device);
|
|
396 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
|
|
397 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
|
|
398 }
|
428
|
399 if (initialized)
|
|
400 {
|
|
401 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
|
|
402 if (noninteractive)
|
|
403 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
404 }
|
|
405 }
|
|
406 #endif
|