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 fopen ((char *) XSTRING_DATA (tty), "r+");
74 error ("Unable to open tty %s", XSTRING_DATA (tty));
79 stream_init_device (struct device *d, Lisp_Object params)
81 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
83 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->in);
84 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->out);
90 stream_initially_selected_for_input (struct console *con)
92 return noninteractive && initialized;
95 extern int stdout_needs_newline;
98 stream_delete_console (struct console *con)
100 struct stream_console *stream_con = CONSOLE_STREAM_DATA (con);
103 if (/* stream_con->needs_newline */
104 stdout_needs_newline) /* #### clean this up */
106 fputc ('\n', stream_con->out);
107 fflush (stream_con->out);
109 if (stream_con->in != stdin)
110 fclose (stream_con->in);
113 CONSOLE_STREAM_DATA (con) = NULL;
118 stream_semi_canonicalize_console_connection (Lisp_Object connection,
121 return NILP (connection) ? Vstdio_str : connection;
125 stream_canonicalize_console_connection (Lisp_Object connection,
128 if (NILP (connection) || internal_equal (connection, Vstdio_str, 0))
131 if (!ERRB_EQ (errb, ERROR_ME))
133 if (!STRINGP (connection))
137 CHECK_STRING (connection);
139 return Ffile_truename (connection, Qnil);
143 stream_semi_canonicalize_device_connection (Lisp_Object connection,
146 return stream_semi_canonicalize_console_connection (connection, errb);
150 stream_canonicalize_device_connection (Lisp_Object connection,
153 return stream_canonicalize_console_connection (connection, errb);
158 stream_init_frame_1 (struct frame *f, Lisp_Object props)
161 struct device *d = XDEVICE (FRAME_DEVICE (f));
162 if (!NILP (DEVICE_FRAME_LIST (d)))
163 error ("Only one frame allowed on stream devices");
165 f->name = build_string ("stream");
168 f->visible = 0; /* so redisplay doesn't try to do anything */
173 stream_text_width (struct frame *f, struct face_cachel *cachel,
174 CONST Emchar *str, Charcount len)
180 stream_left_margin_width (struct window *w)
186 stream_right_margin_width (struct window *w)
192 stream_divider_height (void)
198 stream_eol_cursor_width (void)
204 stream_output_begin (struct device *d)
209 stream_output_end (struct device *d)
214 stream_output_display_block (struct window *w, struct display_line *dl,
215 int block, int start, int end,
216 int start_pixpos, int cursor_start,
217 int cursor_width, int cursor_height)
222 stream_output_vertical_divider (struct window *w, int clear)
227 stream_clear_to_window_end (struct window *w, int ypos1, int ypos2)
232 stream_clear_region (Lisp_Object window, struct device* d, struct frame * f,
233 face_index findex, int x, int y,
234 int width, int height, Lisp_Object fcolor, Lisp_Object bcolor,
235 Lisp_Object background_pixmap)
240 stream_clear_frame (struct frame *f)
245 stream_flash (struct device *d)
247 return 0; /* sorry can't do it */
251 stream_ring_bell (struct device *d, int volume, int pitch, int duration)
253 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
254 fputc (07, CONSOLE_STREAM_DATA (c)->out);
255 fflush (CONSOLE_STREAM_DATA (c)->out);
259 /************************************************************************/
261 /************************************************************************/
264 console_type_create_stream (void)
266 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p");
268 /* console methods */
269 CONSOLE_HAS_METHOD (stream, init_console);
270 CONSOLE_HAS_METHOD (stream, initially_selected_for_input);
271 CONSOLE_HAS_METHOD (stream, delete_console);
272 CONSOLE_HAS_METHOD (stream, canonicalize_console_connection);
273 CONSOLE_HAS_METHOD (stream, canonicalize_device_connection);
274 CONSOLE_HAS_METHOD (stream, semi_canonicalize_console_connection);
275 CONSOLE_HAS_METHOD (stream, semi_canonicalize_device_connection);
278 CONSOLE_HAS_METHOD (stream, init_device);
281 CONSOLE_HAS_METHOD (stream, init_frame_1);
283 /* redisplay methods */
284 CONSOLE_HAS_METHOD (stream, left_margin_width);
285 CONSOLE_HAS_METHOD (stream, right_margin_width);
286 CONSOLE_HAS_METHOD (stream, text_width);
287 CONSOLE_HAS_METHOD (stream, output_display_block);
288 CONSOLE_HAS_METHOD (stream, output_vertical_divider);
289 CONSOLE_HAS_METHOD (stream, divider_height);
290 CONSOLE_HAS_METHOD (stream, eol_cursor_width);
291 CONSOLE_HAS_METHOD (stream, clear_to_window_end);
292 CONSOLE_HAS_METHOD (stream, clear_region);
293 CONSOLE_HAS_METHOD (stream, clear_frame);
294 CONSOLE_HAS_METHOD (stream, output_begin);
295 CONSOLE_HAS_METHOD (stream, output_end);
296 CONSOLE_HAS_METHOD (stream, flash);
297 CONSOLE_HAS_METHOD (stream, ring_bell);
301 reinit_console_type_create_stream (void)
303 REINITIALIZE_CONSOLE_TYPE (stream);
307 vars_of_console_stream (void)
309 DEFVAR_LISP ("terminal-console", &Vterminal_console /*
310 The initial console-object, which represents XEmacs' stdout.
312 Vterminal_console = Qnil;
314 DEFVAR_LISP ("terminal-device", &Vterminal_device /*
315 The initial device-object, which represents XEmacs' stdout.
317 Vterminal_device = Qnil;
319 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /*
320 The initial frame-object, which represents XEmacs' stdout.
322 Vterminal_frame = Qnil;
324 /* Moved from console-tty.c */
325 Vstdio_str = build_string ("stdio");
326 staticpro (&Vstdio_str);
331 init_console_stream (void)
333 /* This function can GC */
336 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
337 Vterminal_console = Fdevice_console (Vterminal_device);
338 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
339 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
343 /* Re-initialize the FILE fields of the console. */
344 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
346 event_stream_select_console (XCONSOLE (Vterminal_console));
353 init_console_stream (void)
355 /* This function can GC */
356 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
357 Vterminal_console = Fdevice_console (Vterminal_device);
358 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
359 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
362 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
364 event_stream_select_console (XCONSOLE (Vterminal_console));