1 /* Stream device functions.
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Copyright (C) 1996 Ben Wing.
5 This file is part of XEmacs.
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
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
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. */
22 /* Synched up with: Not in FSF. */
24 /* This file has been Mule-ized. */
26 /* Written by Ben Wing. */
31 #include "console-stream.h"
32 #include "console-tty.h"
35 #include "redisplay.h"
40 DEFINE_CONSOLE_TYPE (stream);
42 Lisp_Object Vterminal_console;
43 Lisp_Object Vterminal_device;
44 Lisp_Object Vterminal_frame;
46 Lisp_Object Vstdio_str;
49 stream_init_console (struct console *con, Lisp_Object params)
51 Lisp_Object tty = CONSOLE_CONNECTION (con);
52 struct stream_console *stream_con;
54 if (CONSOLE_STREAM_DATA (con) == NULL)
55 CONSOLE_STREAM_DATA (con) = xnew (struct stream_console);
57 stream_con = CONSOLE_STREAM_DATA (con);
59 stream_con->needs_newline = 0;
61 /* Open the specified console */
62 if (NILP (tty) || internal_equal (tty, Vstdio_str, 0))
64 stream_con->in = stdin;
65 stream_con->out = stdout;
66 stream_con->err = stderr;
71 stream_con->in = stream_con->out = stream_con->err =
72 /* #### We don't currently do coding-system translation on
74 fopen ((char *) XSTRING_DATA (tty), READ_PLUS_TEXT);
76 error ("Unable to open tty %s", XSTRING_DATA (tty));
81 stream_init_device (struct device *d, Lisp_Object params)
83 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
85 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->in);
86 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->out);
92 stream_initially_selected_for_input (struct console *con)
94 return noninteractive && initialized;
97 extern int stdout_needs_newline;
100 stream_delete_console (struct console *con)
102 struct stream_console *stream_con = CONSOLE_STREAM_DATA (con);
105 if (/* stream_con->needs_newline */
106 stdout_needs_newline) /* #### clean this up */
108 fputc ('\n', stream_con->out);
109 fflush (stream_con->out);
111 if (stream_con->in != stdin)
112 fclose (stream_con->in);
115 CONSOLE_STREAM_DATA (con) = NULL;
120 stream_semi_canonicalize_console_connection (Lisp_Object connection,
123 return NILP (connection) ? Vstdio_str : connection;
127 stream_canonicalize_console_connection (Lisp_Object connection,
130 if (NILP (connection) || internal_equal (connection, Vstdio_str, 0))
133 if (!ERRB_EQ (errb, ERROR_ME))
135 if (!STRINGP (connection))
139 CHECK_STRING (connection);
141 return Ffile_truename (connection, Qnil);
145 stream_semi_canonicalize_device_connection (Lisp_Object connection,
148 return stream_semi_canonicalize_console_connection (connection, errb);
152 stream_canonicalize_device_connection (Lisp_Object connection,
155 return stream_canonicalize_console_connection (connection, errb);
160 stream_init_frame_1 (struct frame *f, Lisp_Object props)
163 struct device *d = XDEVICE (FRAME_DEVICE (f));
164 if (!NILP (DEVICE_FRAME_LIST (d)))
165 error ("Only one frame allowed on stream devices");
167 f->name = build_string ("stream");
170 f->visible = 0; /* so redisplay doesn't try to do anything */
175 stream_text_width (struct frame *f, struct face_cachel *cachel,
176 const Charc *str, Charcount len)
182 stream_left_margin_width (struct window *w)
188 stream_right_margin_width (struct window *w)
194 stream_divider_height (void)
200 stream_eol_cursor_width (void)
206 stream_output_display_block (struct window *w, struct display_line *dl,
207 int block, int start, int end,
208 int start_pixpos, int cursor_start,
209 int cursor_width, int cursor_height)
214 stream_clear_region (Lisp_Object window, struct device* d, struct frame * f,
215 face_index findex, int x, int y,
216 int width, int height, Lisp_Object fcolor, Lisp_Object bcolor,
217 Lisp_Object background_pixmap)
222 stream_flash (struct device *d)
224 return 0; /* sorry can't do it */
228 stream_ring_bell (struct device *d, int volume, int pitch, int duration)
230 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
231 fputc (07, CONSOLE_STREAM_DATA (c)->out);
232 fflush (CONSOLE_STREAM_DATA (c)->out);
236 /************************************************************************/
238 /************************************************************************/
241 console_type_create_stream (void)
243 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p");
245 /* console methods */
246 CONSOLE_HAS_METHOD (stream, init_console);
247 CONSOLE_HAS_METHOD (stream, initially_selected_for_input);
248 CONSOLE_HAS_METHOD (stream, delete_console);
249 CONSOLE_HAS_METHOD (stream, canonicalize_console_connection);
250 CONSOLE_HAS_METHOD (stream, canonicalize_device_connection);
251 CONSOLE_HAS_METHOD (stream, semi_canonicalize_console_connection);
252 CONSOLE_HAS_METHOD (stream, semi_canonicalize_device_connection);
255 CONSOLE_HAS_METHOD (stream, init_device);
258 CONSOLE_HAS_METHOD (stream, init_frame_1);
260 /* redisplay methods */
261 CONSOLE_HAS_METHOD (stream, left_margin_width);
262 CONSOLE_HAS_METHOD (stream, right_margin_width);
263 CONSOLE_HAS_METHOD (stream, text_width);
264 CONSOLE_HAS_METHOD (stream, output_display_block);
265 CONSOLE_HAS_METHOD (stream, divider_height);
266 CONSOLE_HAS_METHOD (stream, eol_cursor_width);
267 CONSOLE_HAS_METHOD (stream, clear_region);
268 CONSOLE_HAS_METHOD (stream, flash);
269 CONSOLE_HAS_METHOD (stream, ring_bell);
273 reinit_console_type_create_stream (void)
275 REINITIALIZE_CONSOLE_TYPE (stream);
279 vars_of_console_stream (void)
281 DEFVAR_LISP ("terminal-console", &Vterminal_console /*
282 The initial console object, which represents XEmacs' stdout.
284 Vterminal_console = Qnil;
286 DEFVAR_LISP ("terminal-device", &Vterminal_device /*
287 The initial device object, which represents XEmacs' stdout.
289 Vterminal_device = Qnil;
291 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /*
292 The initial frame object, which represents XEmacs' stdout.
294 Vterminal_frame = Qnil;
296 /* Moved from console-tty.c */
297 Vstdio_str = build_string ("stdio");
298 staticpro (&Vstdio_str);
303 init_console_stream (int reinit)
305 /* This function can GC */
308 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
309 Vterminal_console = Fdevice_console (Vterminal_device);
310 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
311 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
315 /* Re-initialize the FILE fields of the console. */
316 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
318 event_stream_select_console (XCONSOLE (Vterminal_console));
325 init_console_stream (int reinit)
327 /* This function can GC */
330 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
331 Vterminal_console = Fdevice_console (Vterminal_device);
332 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
333 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
337 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
339 event_stream_select_console (XCONSOLE (Vterminal_console));