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 allocate_stream_console_struct (struct console *con)
51 if (!CONSOLE_STREAM_DATA (con))
52 CONSOLE_STREAM_DATA (con) = xnew_and_zero (struct stream_console);
54 xzero (*CONSOLE_STREAM_DATA (con));
58 stream_init_console (struct console *con, Lisp_Object params)
60 Lisp_Object tty = CONSOLE_CONNECTION (con);
61 FILE *infd, *outfd, *errfd;
63 /* Open the specified console */
65 if (NILP (tty) || internal_equal (tty, Vstdio_str, 0))
74 infd = outfd = errfd =
75 fopen ((char *) XSTRING_DATA (tty), "r+");
77 error ("Unable to open tty %s", XSTRING_DATA (tty));
80 allocate_stream_console_struct (con);
81 CONSOLE_STREAM_DATA (con)->infd = infd;
82 CONSOLE_STREAM_DATA (con)->outfd = outfd;
83 CONSOLE_STREAM_DATA (con)->errfd = errfd;
87 stream_init_device (struct device *d, Lisp_Object params)
89 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
91 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->infd);
92 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->outfd);
98 stream_initially_selected_for_input (struct console *con)
100 return noninteractive && initialized;
104 free_stream_console_struct (struct console *con)
106 if (CONSOLE_STREAM_DATA (con))
108 xfree (CONSOLE_STREAM_DATA (con));
109 CONSOLE_STREAM_DATA (con) = NULL;
113 extern int stdout_needs_newline;
116 stream_delete_console (struct console *con)
118 if (/* CONSOLE_STREAM_DATA (con)->needs_newline */
119 stdout_needs_newline) /* #### clean this up */
121 fputc ('\n', CONSOLE_STREAM_DATA (con)->outfd);
122 fflush (CONSOLE_STREAM_DATA (con)->outfd);
124 if (CONSOLE_STREAM_DATA (con)->infd != stdin)
125 fclose (CONSOLE_STREAM_DATA (con)->infd);
126 free_stream_console_struct (con);
130 stream_semi_canonicalize_console_connection (Lisp_Object connection,
133 return NILP (connection) ? Vstdio_str : connection;
137 stream_canonicalize_console_connection (Lisp_Object connection,
140 if (NILP (connection) || internal_equal (connection, Vstdio_str, 0))
143 if (!ERRB_EQ (errb, ERROR_ME))
145 if (!STRINGP (connection))
149 CHECK_STRING (connection);
151 return Ffile_truename (connection, Qnil);
155 stream_semi_canonicalize_device_connection (Lisp_Object connection,
158 return stream_semi_canonicalize_console_connection (connection, errb);
162 stream_canonicalize_device_connection (Lisp_Object connection,
165 return stream_canonicalize_console_connection (connection, errb);
170 stream_init_frame_1 (struct frame *f, Lisp_Object props)
173 struct device *d = XDEVICE (FRAME_DEVICE (f));
174 if (!NILP (DEVICE_FRAME_LIST (d)))
175 error ("Only one frame allowed on stream devices");
177 f->name = build_string ("stream");
180 f->visible = 0; /* so redisplay doesn't try to do anything */
185 stream_text_width (struct frame *f, struct face_cachel *cachel,
186 CONST Emchar *str, Charcount len)
192 stream_left_margin_width (struct window *w)
198 stream_right_margin_width (struct window *w)
204 stream_divider_height (void)
210 stream_eol_cursor_width (void)
216 stream_output_begin (struct device *d)
221 stream_output_end (struct device *d)
226 stream_output_display_block (struct window *w, struct display_line *dl,
227 int block, int start, int end,
228 int start_pixpos, int cursor_start,
229 int cursor_width, int cursor_height)
234 stream_output_vertical_divider (struct window *w, int clear)
239 stream_clear_to_window_end (struct window *w, int ypos1, int ypos2)
244 stream_clear_region (Lisp_Object window, struct device* d, struct frame * f,
245 face_index findex, int x, int y,
246 int width, int height, Lisp_Object fcolor, Lisp_Object bcolor,
247 Lisp_Object background_pixmap)
252 stream_clear_frame (struct frame *f)
257 stream_flash (struct device *d)
259 return 0; /* sorry can't do it */
263 stream_ring_bell (struct device *d, int volume, int pitch, int duration)
265 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
266 fputc (07, CONSOLE_STREAM_DATA (c)->outfd);
267 fflush (CONSOLE_STREAM_DATA (c)->outfd);
271 /************************************************************************/
273 /************************************************************************/
276 console_type_create_stream (void)
278 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p");
280 /* console methods */
281 CONSOLE_HAS_METHOD (stream, init_console);
282 CONSOLE_HAS_METHOD (stream, initially_selected_for_input);
283 CONSOLE_HAS_METHOD (stream, delete_console);
284 CONSOLE_HAS_METHOD (stream, canonicalize_console_connection);
285 CONSOLE_HAS_METHOD (stream, canonicalize_device_connection);
286 CONSOLE_HAS_METHOD (stream, semi_canonicalize_console_connection);
287 CONSOLE_HAS_METHOD (stream, semi_canonicalize_device_connection);
290 CONSOLE_HAS_METHOD (stream, init_device);
293 CONSOLE_HAS_METHOD (stream, init_frame_1);
295 /* redisplay methods */
296 CONSOLE_HAS_METHOD (stream, left_margin_width);
297 CONSOLE_HAS_METHOD (stream, right_margin_width);
298 CONSOLE_HAS_METHOD (stream, text_width);
299 CONSOLE_HAS_METHOD (stream, output_display_block);
300 CONSOLE_HAS_METHOD (stream, output_vertical_divider);
301 CONSOLE_HAS_METHOD (stream, divider_height);
302 CONSOLE_HAS_METHOD (stream, eol_cursor_width);
303 CONSOLE_HAS_METHOD (stream, clear_to_window_end);
304 CONSOLE_HAS_METHOD (stream, clear_region);
305 CONSOLE_HAS_METHOD (stream, clear_frame);
306 CONSOLE_HAS_METHOD (stream, output_begin);
307 CONSOLE_HAS_METHOD (stream, output_end);
308 CONSOLE_HAS_METHOD (stream, flash);
309 CONSOLE_HAS_METHOD (stream, ring_bell);
313 vars_of_console_stream (void)
315 DEFVAR_LISP ("terminal-console", &Vterminal_console /*
316 The initial console-object, which represents XEmacs' stdout.
318 Vterminal_console = Qnil;
320 DEFVAR_LISP ("terminal-device", &Vterminal_device /*
321 The initial device-object, which represents XEmacs' stdout.
323 Vterminal_device = Qnil;
325 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /*
326 The initial frame-object, which represents XEmacs' stdout.
328 Vterminal_frame = Qnil;
330 /* Moved from console-tty.c */
331 Vstdio_str = build_string ("stdio");
332 staticpro (&Vstdio_str);
336 init_console_stream (void)
338 /* This function can GC */
341 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
342 Vterminal_console = Fdevice_console (Vterminal_device);
343 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
344 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
348 /* Re-initialize the FILE fields of the console. */
349 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
351 event_stream_select_console (XCONSOLE (Vterminal_console));