1 /* Stream device functions.
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Copyright (C) 1996 Ben Wing.
5 This file is part of SXEmacs
7 SXEmacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 SXEmacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* Synched up with: Not in FSF. */
23 /* This file has been Mule-ized. */
25 /* Written by Ben Wing. */
30 #include "console-stream.h"
31 #include "events/events.h"
33 #include "redisplay.h"
38 DEFINE_CONSOLE_TYPE(stream);
40 Lisp_Object Vterminal_console;
41 Lisp_Object Vterminal_device;
42 Lisp_Object Vterminal_frame;
44 Lisp_Object Vstdio_str;
46 static void stream_init_console(struct console *con, Lisp_Object params)
48 Lisp_Object tty = CONSOLE_CONNECTION(con);
49 struct stream_console *stream_con;
51 if (CONSOLE_STREAM_DATA(con) == NULL) {
52 CONSOLE_DATA(con) = xnew(struct stream_console);
54 stream_con = CONSOLE_STREAM_DATA(con);
56 stream_con->needs_newline = 0;
58 /* Open the specified console */
59 if (NILP(tty) || internal_equal(tty, Vstdio_str, 0)) {
60 stream_con->in = stdin;
61 stream_con->out = stdout;
62 stream_con->err = stderr;
65 stream_con->in = stream_con->out = stream_con->err =
66 /* #### We don't currently do coding-system translation on
68 fopen((char *)XSTRING_DATA(tty), READ_PLUS_TEXT);
70 error("Unable to open tty %s", XSTRING_DATA(tty));
74 static void stream_init_device(struct device *d, Lisp_Object params)
76 struct console *con = XCONSOLE(DEVICE_CONSOLE(d));
78 DEVICE_INFD(d) = fileno(CONSOLE_STREAM_DATA(con)->in);
79 DEVICE_OUTFD(d) = fileno(CONSOLE_STREAM_DATA(con)->out);
84 static int stream_initially_selected_for_input(struct console *con)
86 return noninteractive && initialized;
89 extern int stdout_needs_newline;
91 static void stream_delete_console(struct console *con)
93 struct stream_console *stream_con = CONSOLE_STREAM_DATA(con);
95 if ( /* stream_con->needs_newline */
96 stdout_needs_newline) { /* #### clean this up */
97 fputc('\n', stream_con->out);
98 fflush(stream_con->out);
100 if (stream_con->in != stdin)
101 fclose(stream_con->in);
104 CONSOLE_DATA(con) = NULL;
109 stream_semi_canonicalize_console_connection(Lisp_Object connection,
112 return NILP(connection) ? Vstdio_str : connection;
116 stream_canonicalize_console_connection(Lisp_Object connection,
119 if (NILP(connection) || internal_equal(connection, Vstdio_str, 0))
122 if (!ERRB_EQ(errb, ERROR_ME)) {
123 if (!STRINGP(connection))
126 CHECK_STRING(connection);
128 return Ffile_truename(connection, Qnil);
132 stream_semi_canonicalize_device_connection(Lisp_Object connection,
135 return stream_semi_canonicalize_console_connection(connection, errb);
139 stream_canonicalize_device_connection(Lisp_Object connection,
142 return stream_canonicalize_console_connection(connection, errb);
145 static void stream_init_frame_1(struct frame *f, Lisp_Object props)
148 struct device *d = XDEVICE(FRAME_DEVICE(f));
149 if (!NILP(DEVICE_FRAME_LIST(d)))
150 error("Only one frame allowed on stream devices");
152 f->name = build_string("stream");
155 f->visible = 0; /* so redisplay doesn't try to do anything */
159 stream_text_width(struct frame *f, struct face_cachel *cachel,
160 const Emchar * str, Charcount len)
165 static int stream_left_margin_width(struct window *w)
170 static int stream_right_margin_width(struct window *w)
175 static int stream_divider_height(void)
180 static int stream_eol_cursor_width(void)
186 stream_output_display_block(struct window *w, struct display_line *dl,
187 int block, int start, int end,
188 int start_pixpos, int cursor_start,
189 int cursor_width, int cursor_height)
194 stream_clear_region(Lisp_Object window, struct device *d, struct frame *f,
195 face_index findex, int x, int y,
196 int width, int height, Lisp_Object fcolor,
197 Lisp_Object bcolor, Lisp_Object background_pixmap)
201 static int stream_flash(struct device *d)
203 return 0; /* sorry can't do it */
207 stream_ring_bell(struct device *d, int volume, int pitch, int duration)
209 struct console *c = XCONSOLE(DEVICE_CONSOLE(d));
210 fputc(07, CONSOLE_STREAM_DATA(c)->out);
211 fflush(CONSOLE_STREAM_DATA(c)->out);
214 /************************************************************************/
216 /************************************************************************/
218 void console_type_create_stream(void)
220 INITIALIZE_CONSOLE_TYPE(stream, "stream", "console-stream-p");
222 /* console methods */
223 CONSOLE_HAS_METHOD(stream, init_console);
224 CONSOLE_HAS_METHOD(stream, initially_selected_for_input);
225 CONSOLE_HAS_METHOD(stream, delete_console);
226 CONSOLE_HAS_METHOD(stream, canonicalize_console_connection);
227 CONSOLE_HAS_METHOD(stream, canonicalize_device_connection);
228 CONSOLE_HAS_METHOD(stream, semi_canonicalize_console_connection);
229 CONSOLE_HAS_METHOD(stream, semi_canonicalize_device_connection);
232 CONSOLE_HAS_METHOD(stream, init_device);
235 CONSOLE_HAS_METHOD(stream, init_frame_1);
237 /* redisplay methods */
238 CONSOLE_HAS_METHOD(stream, left_margin_width);
239 CONSOLE_HAS_METHOD(stream, right_margin_width);
240 CONSOLE_HAS_METHOD(stream, text_width);
241 CONSOLE_HAS_METHOD(stream, output_display_block);
242 CONSOLE_HAS_METHOD(stream, divider_height);
243 CONSOLE_HAS_METHOD(stream, eol_cursor_width);
244 CONSOLE_HAS_METHOD(stream, clear_region);
245 CONSOLE_HAS_METHOD(stream, flash);
246 CONSOLE_HAS_METHOD(stream, ring_bell);
249 void reinit_console_type_create_stream(void)
251 REINITIALIZE_CONSOLE_TYPE(stream);
254 void vars_of_console_stream(void)
256 DEFVAR_LISP("terminal-console", &Vterminal_console /*
257 The initial console object, which represents SXEmacs' stdout.
259 Vterminal_console = Qnil;
261 DEFVAR_LISP("terminal-device", &Vterminal_device /*
262 The initial device object, which represents SXEmacs' stdout.
264 Vterminal_device = Qnil;
266 DEFVAR_LISP("terminal-frame", &Vterminal_frame /*
267 The initial frame object, which represents SXEmacs' stdout.
269 Vterminal_frame = Qnil;
271 /* Moved from console-tty.c */
272 Vstdio_str = build_string("stdio");
273 staticpro(&Vstdio_str);
277 void init_console_stream(int reinit)
279 /* This function can GC */
281 Vterminal_device = Fmake_device(Qstream, Qnil, Qnil);
282 Vterminal_console = Fdevice_console(Vterminal_device);
283 Vterminal_frame = Fmake_frame(Qnil, Vterminal_device);
284 minibuf_window = XFRAME(Vterminal_frame)->minibuffer_window;
286 /* Re-initialize the FILE fields of the console. */
287 stream_init_console(XCONSOLE(Vterminal_console), Qnil);
289 event_stream_select_console(XCONSOLE
290 (Vterminal_console));
296 void init_console_stream(int reinit)
298 /* This function can GC */
300 Vterminal_device = Fmake_device(Qstream, Qnil, Qnil);
301 Vterminal_console = Fdevice_console(Vterminal_device);
302 Vterminal_frame = Fmake_frame(Qnil, Vterminal_device);
303 minibuf_window = XFRAME(Vterminal_frame)->minibuffer_window;
306 stream_init_console(XCONSOLE(Vterminal_console), Qnil);
308 event_stream_select_console(XCONSOLE
309 (Vterminal_console));