428
|
1 /* Stream device functions.
|
|
2 Copyright (C) 1995 Free Software Foundation, Inc.
|
1204
|
3 Copyright (C) 1996, 2001, 2002 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
|
|
219 static void
|
|
220 stream_output_display_block (struct window *w, struct display_line *dl,
|
|
221 int block, int start, int end,
|
|
222 int start_pixpos, int cursor_start,
|
|
223 int cursor_width, int cursor_height)
|
|
224 {
|
|
225 }
|
|
226
|
|
227 static void
|
|
228 stream_clear_region (Lisp_Object window, struct device* d, struct frame * f,
|
826
|
229 face_index findex, int x, int y,
|
|
230 int width, int height, Lisp_Object fcolor,
|
|
231 Lisp_Object bcolor, Lisp_Object background_pixmap)
|
428
|
232 {
|
|
233 }
|
|
234
|
|
235 static int
|
|
236 stream_flash (struct device *d)
|
|
237 {
|
|
238 return 0; /* sorry can't do it */
|
|
239 }
|
|
240
|
|
241 static void
|
|
242 stream_ring_bell (struct device *d, int volume, int pitch, int duration)
|
|
243 {
|
|
244 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
826
|
245 /* Don't output ^G when not a TTY -- in particular, under MS Windows, ^G
|
|
246 is interpreted as bell by the console, but not when running under
|
|
247 VC++. Probably this would be the same under Unix. */
|
|
248 if (isatty (fileno (CONSOLE_STREAM_DATA (c)->out)))
|
|
249 {
|
|
250 fputc (07, CONSOLE_STREAM_DATA (c)->out);
|
|
251 fflush (CONSOLE_STREAM_DATA (c)->out);
|
|
252 }
|
428
|
253 }
|
|
254
|
|
255
|
|
256 /************************************************************************/
|
|
257 /* initialization */
|
|
258 /************************************************************************/
|
|
259
|
|
260 void
|
|
261 console_type_create_stream (void)
|
|
262 {
|
|
263 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p");
|
|
264
|
|
265 /* console methods */
|
|
266 CONSOLE_HAS_METHOD (stream, init_console);
|
|
267 CONSOLE_HAS_METHOD (stream, initially_selected_for_input);
|
|
268 CONSOLE_HAS_METHOD (stream, delete_console);
|
|
269 CONSOLE_HAS_METHOD (stream, canonicalize_console_connection);
|
|
270 CONSOLE_HAS_METHOD (stream, canonicalize_device_connection);
|
|
271 CONSOLE_HAS_METHOD (stream, semi_canonicalize_console_connection);
|
|
272 CONSOLE_HAS_METHOD (stream, semi_canonicalize_device_connection);
|
|
273
|
|
274 /* device methods */
|
|
275 CONSOLE_HAS_METHOD (stream, init_device);
|
|
276
|
|
277 /* frame methods */
|
|
278 CONSOLE_HAS_METHOD (stream, init_frame_1);
|
|
279
|
|
280 /* redisplay methods */
|
|
281 CONSOLE_HAS_METHOD (stream, left_margin_width);
|
|
282 CONSOLE_HAS_METHOD (stream, right_margin_width);
|
|
283 CONSOLE_HAS_METHOD (stream, text_width);
|
|
284 CONSOLE_HAS_METHOD (stream, output_display_block);
|
|
285 CONSOLE_HAS_METHOD (stream, divider_height);
|
|
286 CONSOLE_HAS_METHOD (stream, eol_cursor_width);
|
|
287 CONSOLE_HAS_METHOD (stream, clear_region);
|
|
288 CONSOLE_HAS_METHOD (stream, flash);
|
|
289 CONSOLE_HAS_METHOD (stream, ring_bell);
|
|
290 }
|
|
291
|
|
292 void
|
|
293 reinit_console_type_create_stream (void)
|
|
294 {
|
|
295 REINITIALIZE_CONSOLE_TYPE (stream);
|
|
296 }
|
|
297
|
|
298 void
|
|
299 vars_of_console_stream (void)
|
|
300 {
|
|
301 DEFVAR_LISP ("terminal-console", &Vterminal_console /*
|
444
|
302 The initial console object, which represents XEmacs' stdout.
|
428
|
303 */ );
|
|
304 Vterminal_console = Qnil;
|
|
305
|
|
306 DEFVAR_LISP ("terminal-device", &Vterminal_device /*
|
444
|
307 The initial device object, which represents XEmacs' stdout.
|
428
|
308 */ );
|
|
309 Vterminal_device = Qnil;
|
|
310
|
|
311 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /*
|
444
|
312 The initial frame object, which represents XEmacs' stdout.
|
428
|
313 */ );
|
|
314 Vterminal_frame = Qnil;
|
|
315
|
|
316 /* Moved from console-tty.c */
|
|
317 Vstdio_str = build_string ("stdio");
|
|
318 staticpro (&Vstdio_str);
|
|
319 }
|
|
320
|
|
321 #ifndef PDUMP
|
|
322 void
|
442
|
323 init_console_stream (int reinit)
|
428
|
324 {
|
|
325 /* This function can GC */
|
|
326 if (!initialized)
|
|
327 {
|
|
328 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
|
|
329 Vterminal_console = Fdevice_console (Vterminal_device);
|
|
330 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
|
|
331 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
|
|
332 }
|
|
333 else
|
|
334 {
|
|
335 /* Re-initialize the FILE fields of the console. */
|
|
336 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
|
|
337 if (noninteractive)
|
|
338 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
339 }
|
|
340 }
|
|
341
|
|
342 #else
|
|
343
|
|
344 void
|
442
|
345 init_console_stream (int reinit)
|
428
|
346 {
|
|
347 /* This function can GC */
|
442
|
348 if (!reinit)
|
|
349 {
|
|
350 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
|
|
351 Vterminal_console = Fdevice_console (Vterminal_device);
|
|
352 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
|
|
353 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
|
|
354 }
|
428
|
355 if (initialized)
|
|
356 {
|
|
357 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
|
|
358 if (noninteractive)
|
|
359 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
360 }
|
|
361 }
|
|
362 #endif
|