428
|
1 /* Stream device functions.
|
|
2 Copyright (C) 1995 Free Software Foundation, Inc.
|
771
|
3 Copyright (C) 1996, 2001 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
|
|
31 #include "console-stream.h"
|
|
32 #include "console-tty.h"
|
|
33 #include "events.h"
|
|
34 #include "frame.h"
|
|
35 #include "redisplay.h"
|
|
36 #include "sysdep.h"
|
|
37 #include "sysfile.h"
|
|
38 #include "window.h"
|
|
39
|
|
40 DEFINE_CONSOLE_TYPE (stream);
|
|
41
|
|
42 Lisp_Object Vterminal_console;
|
|
43 Lisp_Object Vterminal_device;
|
|
44 Lisp_Object Vterminal_frame;
|
|
45
|
|
46 Lisp_Object Vstdio_str;
|
|
47
|
|
48 static void
|
|
49 stream_init_console (struct console *con, Lisp_Object params)
|
|
50 {
|
|
51 Lisp_Object tty = CONSOLE_CONNECTION (con);
|
|
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 }
|
|
68 else
|
|
69 {
|
|
70 CHECK_STRING (tty);
|
|
71 stream_con->in = stream_con->out = stream_con->err =
|
442
|
72 /* #### We don't currently do coding-system translation on
|
|
73 this descriptor. */
|
771
|
74 qxe_fopen (XSTRING_DATA (tty), READ_PLUS_TEXT);
|
428
|
75 if (!stream_con->in)
|
563
|
76 signal_error (Qio_error, "Unable to open tty", tty);
|
428
|
77 }
|
|
78 }
|
|
79
|
|
80 static void
|
|
81 stream_init_device (struct device *d, Lisp_Object params)
|
|
82 {
|
|
83 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
84
|
|
85 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->in);
|
|
86 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->out);
|
|
87 init_baud_rate (d);
|
|
88 init_one_device (d);
|
|
89 }
|
|
90
|
|
91 static int
|
|
92 stream_initially_selected_for_input (struct console *con)
|
|
93 {
|
|
94 return noninteractive && initialized;
|
|
95 }
|
|
96
|
|
97 extern int stdout_needs_newline;
|
|
98
|
|
99 static void
|
|
100 stream_delete_console (struct console *con)
|
|
101 {
|
|
102 struct stream_console *stream_con = CONSOLE_STREAM_DATA (con);
|
|
103 if (stream_con)
|
|
104 {
|
|
105 if (/* stream_con->needs_newline */
|
|
106 stdout_needs_newline) /* #### clean this up */
|
|
107 {
|
|
108 fputc ('\n', stream_con->out);
|
|
109 fflush (stream_con->out);
|
|
110 }
|
|
111 if (stream_con->in != stdin)
|
771
|
112 retry_fclose (stream_con->in);
|
428
|
113
|
|
114 xfree (stream_con);
|
|
115 CONSOLE_STREAM_DATA (con) = NULL;
|
|
116 }
|
|
117 }
|
|
118
|
|
119 Lisp_Object
|
|
120 stream_semi_canonicalize_console_connection (Lisp_Object connection,
|
578
|
121 Error_Behavior errb)
|
428
|
122 {
|
|
123 return NILP (connection) ? Vstdio_str : connection;
|
|
124 }
|
|
125
|
|
126 Lisp_Object
|
|
127 stream_canonicalize_console_connection (Lisp_Object connection,
|
578
|
128 Error_Behavior errb)
|
428
|
129 {
|
|
130 if (NILP (connection) || internal_equal (connection, Vstdio_str, 0))
|
|
131 return Vstdio_str;
|
|
132
|
|
133 if (!ERRB_EQ (errb, ERROR_ME))
|
|
134 {
|
|
135 if (!STRINGP (connection))
|
|
136 return Qunbound;
|
|
137 }
|
|
138 else
|
|
139 CHECK_STRING (connection);
|
|
140
|
|
141 return Ffile_truename (connection, Qnil);
|
|
142 }
|
|
143
|
|
144 Lisp_Object
|
|
145 stream_semi_canonicalize_device_connection (Lisp_Object connection,
|
578
|
146 Error_Behavior errb)
|
428
|
147 {
|
|
148 return stream_semi_canonicalize_console_connection (connection, errb);
|
|
149 }
|
|
150
|
|
151 Lisp_Object
|
|
152 stream_canonicalize_device_connection (Lisp_Object connection,
|
578
|
153 Error_Behavior errb)
|
428
|
154 {
|
|
155 return stream_canonicalize_console_connection (connection, errb);
|
|
156 }
|
|
157
|
|
158
|
|
159 static void
|
771
|
160 stream_init_frame_1 (struct frame *f, Lisp_Object props,
|
|
161 int frame_name_is_defaulted)
|
428
|
162 {
|
|
163 #if 0
|
|
164 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
165 if (!NILP (DEVICE_FRAME_LIST (d)))
|
563
|
166 invalid_operation ("Only one frame allowed on stream devices", Qunbound);
|
428
|
167 #endif
|
771
|
168 if (frame_name_is_defaulted)
|
|
169 f->name = build_string ("stream");
|
428
|
170 f->height = 80;
|
|
171 f->width = 24;
|
|
172 f->visible = 0; /* so redisplay doesn't try to do anything */
|
|
173 }
|
|
174
|
|
175
|
|
176 static int
|
|
177 stream_text_width (struct frame *f, struct face_cachel *cachel,
|
442
|
178 const Emchar *str, Charcount len)
|
428
|
179 {
|
|
180 return len;
|
|
181 }
|
|
182
|
|
183 static int
|
|
184 stream_left_margin_width (struct window *w)
|
|
185 {
|
|
186 return 0;
|
|
187 }
|
|
188
|
|
189 static int
|
|
190 stream_right_margin_width (struct window *w)
|
|
191 {
|
|
192 return 0;
|
|
193 }
|
|
194
|
|
195 static int
|
|
196 stream_divider_height (void)
|
|
197 {
|
|
198 return 1;
|
|
199 }
|
|
200
|
|
201 static int
|
|
202 stream_eol_cursor_width (void)
|
|
203 {
|
|
204 return 1;
|
|
205 }
|
|
206
|
|
207 static void
|
|
208 stream_output_display_block (struct window *w, struct display_line *dl,
|
|
209 int block, int start, int end,
|
|
210 int start_pixpos, int cursor_start,
|
|
211 int cursor_width, int cursor_height)
|
|
212 {
|
|
213 }
|
|
214
|
|
215 static void
|
|
216 stream_clear_region (Lisp_Object window, struct device* d, struct frame * f,
|
|
217 face_index findex, int x, int y,
|
|
218 int width, int height, Lisp_Object fcolor, Lisp_Object bcolor,
|
|
219 Lisp_Object background_pixmap)
|
|
220 {
|
|
221 }
|
|
222
|
|
223 static int
|
|
224 stream_flash (struct device *d)
|
|
225 {
|
|
226 return 0; /* sorry can't do it */
|
|
227 }
|
|
228
|
|
229 static void
|
|
230 stream_ring_bell (struct device *d, int volume, int pitch, int duration)
|
|
231 {
|
|
232 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
233 fputc (07, CONSOLE_STREAM_DATA (c)->out);
|
|
234 fflush (CONSOLE_STREAM_DATA (c)->out);
|
|
235 }
|
|
236
|
|
237
|
|
238 /************************************************************************/
|
|
239 /* initialization */
|
|
240 /************************************************************************/
|
|
241
|
|
242 void
|
|
243 console_type_create_stream (void)
|
|
244 {
|
|
245 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p");
|
|
246
|
|
247 /* console methods */
|
|
248 CONSOLE_HAS_METHOD (stream, init_console);
|
|
249 CONSOLE_HAS_METHOD (stream, initially_selected_for_input);
|
|
250 CONSOLE_HAS_METHOD (stream, delete_console);
|
|
251 CONSOLE_HAS_METHOD (stream, canonicalize_console_connection);
|
|
252 CONSOLE_HAS_METHOD (stream, canonicalize_device_connection);
|
|
253 CONSOLE_HAS_METHOD (stream, semi_canonicalize_console_connection);
|
|
254 CONSOLE_HAS_METHOD (stream, semi_canonicalize_device_connection);
|
|
255
|
|
256 /* device methods */
|
|
257 CONSOLE_HAS_METHOD (stream, init_device);
|
|
258
|
|
259 /* frame methods */
|
|
260 CONSOLE_HAS_METHOD (stream, init_frame_1);
|
|
261
|
|
262 /* redisplay methods */
|
|
263 CONSOLE_HAS_METHOD (stream, left_margin_width);
|
|
264 CONSOLE_HAS_METHOD (stream, right_margin_width);
|
|
265 CONSOLE_HAS_METHOD (stream, text_width);
|
|
266 CONSOLE_HAS_METHOD (stream, output_display_block);
|
|
267 CONSOLE_HAS_METHOD (stream, divider_height);
|
|
268 CONSOLE_HAS_METHOD (stream, eol_cursor_width);
|
|
269 CONSOLE_HAS_METHOD (stream, clear_region);
|
|
270 CONSOLE_HAS_METHOD (stream, flash);
|
|
271 CONSOLE_HAS_METHOD (stream, ring_bell);
|
|
272 }
|
|
273
|
|
274 void
|
|
275 reinit_console_type_create_stream (void)
|
|
276 {
|
|
277 REINITIALIZE_CONSOLE_TYPE (stream);
|
|
278 }
|
|
279
|
|
280 void
|
|
281 vars_of_console_stream (void)
|
|
282 {
|
|
283 DEFVAR_LISP ("terminal-console", &Vterminal_console /*
|
444
|
284 The initial console object, which represents XEmacs' stdout.
|
428
|
285 */ );
|
|
286 Vterminal_console = Qnil;
|
|
287
|
|
288 DEFVAR_LISP ("terminal-device", &Vterminal_device /*
|
444
|
289 The initial device object, which represents XEmacs' stdout.
|
428
|
290 */ );
|
|
291 Vterminal_device = Qnil;
|
|
292
|
|
293 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /*
|
444
|
294 The initial frame object, which represents XEmacs' stdout.
|
428
|
295 */ );
|
|
296 Vterminal_frame = Qnil;
|
|
297
|
|
298 /* Moved from console-tty.c */
|
|
299 Vstdio_str = build_string ("stdio");
|
|
300 staticpro (&Vstdio_str);
|
|
301 }
|
|
302
|
|
303 #ifndef PDUMP
|
|
304 void
|
442
|
305 init_console_stream (int reinit)
|
428
|
306 {
|
|
307 /* This function can GC */
|
|
308 if (!initialized)
|
|
309 {
|
|
310 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
|
|
311 Vterminal_console = Fdevice_console (Vterminal_device);
|
|
312 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
|
|
313 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
|
|
314 }
|
|
315 else
|
|
316 {
|
|
317 /* Re-initialize the FILE fields of the console. */
|
|
318 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
|
|
319 if (noninteractive)
|
|
320 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
321 }
|
|
322 }
|
|
323
|
|
324 #else
|
|
325
|
|
326 void
|
442
|
327 init_console_stream (int reinit)
|
428
|
328 {
|
|
329 /* This function can GC */
|
442
|
330 if (!reinit)
|
|
331 {
|
|
332 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
|
|
333 Vterminal_console = Fdevice_console (Vterminal_device);
|
|
334 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
|
|
335 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
|
|
336 }
|
428
|
337 if (initialized)
|
|
338 {
|
|
339 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
|
|
340 if (noninteractive)
|
|
341 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
342 }
|
|
343 }
|
|
344 #endif
|