428
|
1 /* Stream device functions.
|
|
2 Copyright (C) 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1996 Ben Wing.
|
|
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
|
|
31 #include "console-stream.h"
|
|
32 #include "console-tty.h"
|
|
33 #include "events.h"
|
|
34 #include "frame.h"
|
|
35 #include "redisplay.h"
|
|
36 #include "sysdep.h"
|
|
37 #include "sysfile.h"
|
|
38 #include "window.h"
|
|
39
|
|
40 DEFINE_CONSOLE_TYPE (stream);
|
|
41
|
|
42 Lisp_Object Vterminal_console;
|
|
43 Lisp_Object Vterminal_device;
|
|
44 Lisp_Object Vterminal_frame;
|
|
45
|
|
46 Lisp_Object Vstdio_str;
|
|
47
|
|
48 static void
|
|
49 stream_init_console (struct console *con, Lisp_Object params)
|
|
50 {
|
|
51 Lisp_Object tty = CONSOLE_CONNECTION (con);
|
|
52 struct stream_console *stream_con;
|
|
53
|
|
54 if (CONSOLE_STREAM_DATA (con) == NULL)
|
|
55 CONSOLE_STREAM_DATA (con) = xnew (struct stream_console);
|
|
56
|
|
57 stream_con = CONSOLE_STREAM_DATA (con);
|
|
58
|
|
59 stream_con->needs_newline = 0;
|
|
60
|
|
61 /* Open the specified console */
|
|
62 if (NILP (tty) || internal_equal (tty, Vstdio_str, 0))
|
|
63 {
|
|
64 stream_con->in = stdin;
|
|
65 stream_con->out = stdout;
|
|
66 stream_con->err = stderr;
|
|
67 }
|
|
68 else
|
|
69 {
|
|
70 CHECK_STRING (tty);
|
|
71 stream_con->in = stream_con->out = stream_con->err =
|
|
72 fopen ((char *) XSTRING_DATA (tty), "r+");
|
|
73 if (!stream_con->in)
|
|
74 error ("Unable to open tty %s", XSTRING_DATA (tty));
|
|
75 }
|
|
76 }
|
|
77
|
|
78 static void
|
|
79 stream_init_device (struct device *d, Lisp_Object params)
|
|
80 {
|
|
81 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
82
|
|
83 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->in);
|
|
84 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->out);
|
|
85 init_baud_rate (d);
|
|
86 init_one_device (d);
|
|
87 }
|
|
88
|
|
89 static int
|
|
90 stream_initially_selected_for_input (struct console *con)
|
|
91 {
|
|
92 return noninteractive && initialized;
|
|
93 }
|
|
94
|
|
95 extern int stdout_needs_newline;
|
|
96
|
|
97 static void
|
|
98 stream_delete_console (struct console *con)
|
|
99 {
|
|
100 struct stream_console *stream_con = CONSOLE_STREAM_DATA (con);
|
|
101 if (stream_con)
|
|
102 {
|
|
103 if (/* stream_con->needs_newline */
|
|
104 stdout_needs_newline) /* #### clean this up */
|
|
105 {
|
|
106 fputc ('\n', stream_con->out);
|
|
107 fflush (stream_con->out);
|
|
108 }
|
|
109 if (stream_con->in != stdin)
|
|
110 fclose (stream_con->in);
|
|
111
|
|
112 xfree (stream_con);
|
|
113 CONSOLE_STREAM_DATA (con) = NULL;
|
|
114 }
|
|
115 }
|
|
116
|
|
117 Lisp_Object
|
|
118 stream_semi_canonicalize_console_connection (Lisp_Object connection,
|
|
119 Error_behavior errb)
|
|
120 {
|
|
121 return NILP (connection) ? Vstdio_str : connection;
|
|
122 }
|
|
123
|
|
124 Lisp_Object
|
|
125 stream_canonicalize_console_connection (Lisp_Object connection,
|
|
126 Error_behavior errb)
|
|
127 {
|
|
128 if (NILP (connection) || internal_equal (connection, Vstdio_str, 0))
|
|
129 return Vstdio_str;
|
|
130
|
|
131 if (!ERRB_EQ (errb, ERROR_ME))
|
|
132 {
|
|
133 if (!STRINGP (connection))
|
|
134 return Qunbound;
|
|
135 }
|
|
136 else
|
|
137 CHECK_STRING (connection);
|
|
138
|
|
139 return Ffile_truename (connection, Qnil);
|
|
140 }
|
|
141
|
|
142 Lisp_Object
|
|
143 stream_semi_canonicalize_device_connection (Lisp_Object connection,
|
|
144 Error_behavior errb)
|
|
145 {
|
|
146 return stream_semi_canonicalize_console_connection (connection, errb);
|
|
147 }
|
|
148
|
|
149 Lisp_Object
|
|
150 stream_canonicalize_device_connection (Lisp_Object connection,
|
|
151 Error_behavior errb)
|
|
152 {
|
|
153 return stream_canonicalize_console_connection (connection, errb);
|
|
154 }
|
|
155
|
|
156
|
|
157 static void
|
|
158 stream_init_frame_1 (struct frame *f, Lisp_Object props)
|
|
159 {
|
|
160 #if 0
|
|
161 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
162 if (!NILP (DEVICE_FRAME_LIST (d)))
|
|
163 error ("Only one frame allowed on stream devices");
|
|
164 #endif
|
|
165 f->name = build_string ("stream");
|
|
166 f->height = 80;
|
|
167 f->width = 24;
|
|
168 f->visible = 0; /* so redisplay doesn't try to do anything */
|
|
169 }
|
|
170
|
|
171
|
|
172 static int
|
|
173 stream_text_width (struct frame *f, struct face_cachel *cachel,
|
|
174 CONST Emchar *str, Charcount len)
|
|
175 {
|
|
176 return len;
|
|
177 }
|
|
178
|
|
179 static int
|
|
180 stream_left_margin_width (struct window *w)
|
|
181 {
|
|
182 return 0;
|
|
183 }
|
|
184
|
|
185 static int
|
|
186 stream_right_margin_width (struct window *w)
|
|
187 {
|
|
188 return 0;
|
|
189 }
|
|
190
|
|
191 static int
|
|
192 stream_divider_height (void)
|
|
193 {
|
|
194 return 1;
|
|
195 }
|
|
196
|
|
197 static int
|
|
198 stream_eol_cursor_width (void)
|
|
199 {
|
|
200 return 1;
|
|
201 }
|
|
202
|
|
203 static void
|
|
204 stream_output_begin (struct device *d)
|
|
205 {
|
|
206 }
|
|
207
|
|
208 static void
|
|
209 stream_output_end (struct device *d)
|
|
210 {
|
|
211 }
|
|
212
|
|
213 static void
|
|
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)
|
|
218 {
|
|
219 }
|
|
220
|
|
221 static void
|
|
222 stream_output_vertical_divider (struct window *w, int clear)
|
|
223 {
|
|
224 }
|
|
225
|
|
226 static void
|
|
227 stream_clear_to_window_end (struct window *w, int ypos1, int ypos2)
|
|
228 {
|
|
229 }
|
|
230
|
|
231 static void
|
|
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)
|
|
236 {
|
|
237 }
|
|
238
|
|
239 static void
|
|
240 stream_clear_frame (struct frame *f)
|
|
241 {
|
|
242 }
|
|
243
|
|
244 static int
|
|
245 stream_flash (struct device *d)
|
|
246 {
|
|
247 return 0; /* sorry can't do it */
|
|
248 }
|
|
249
|
|
250 static void
|
|
251 stream_ring_bell (struct device *d, int volume, int pitch, int duration)
|
|
252 {
|
|
253 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
254 fputc (07, CONSOLE_STREAM_DATA (c)->out);
|
|
255 fflush (CONSOLE_STREAM_DATA (c)->out);
|
|
256 }
|
|
257
|
|
258
|
|
259 /************************************************************************/
|
|
260 /* initialization */
|
|
261 /************************************************************************/
|
|
262
|
|
263 void
|
|
264 console_type_create_stream (void)
|
|
265 {
|
|
266 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p");
|
|
267
|
|
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);
|
|
276
|
|
277 /* device methods */
|
|
278 CONSOLE_HAS_METHOD (stream, init_device);
|
|
279
|
|
280 /* frame methods */
|
|
281 CONSOLE_HAS_METHOD (stream, init_frame_1);
|
|
282
|
|
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);
|
|
298 }
|
|
299
|
|
300 void
|
|
301 reinit_console_type_create_stream (void)
|
|
302 {
|
|
303 REINITIALIZE_CONSOLE_TYPE (stream);
|
|
304 }
|
|
305
|
|
306 void
|
|
307 vars_of_console_stream (void)
|
|
308 {
|
|
309 DEFVAR_LISP ("terminal-console", &Vterminal_console /*
|
|
310 The initial console-object, which represents XEmacs' stdout.
|
|
311 */ );
|
|
312 Vterminal_console = Qnil;
|
|
313
|
|
314 DEFVAR_LISP ("terminal-device", &Vterminal_device /*
|
|
315 The initial device-object, which represents XEmacs' stdout.
|
|
316 */ );
|
|
317 Vterminal_device = Qnil;
|
|
318
|
|
319 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /*
|
|
320 The initial frame-object, which represents XEmacs' stdout.
|
|
321 */ );
|
|
322 Vterminal_frame = Qnil;
|
|
323
|
|
324 /* Moved from console-tty.c */
|
|
325 Vstdio_str = build_string ("stdio");
|
|
326 staticpro (&Vstdio_str);
|
|
327 }
|
|
328
|
|
329 #ifndef PDUMP
|
|
330 void
|
|
331 init_console_stream (void)
|
|
332 {
|
|
333 /* This function can GC */
|
|
334 if (!initialized)
|
|
335 {
|
|
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;
|
|
340 }
|
|
341 else
|
|
342 {
|
|
343 /* Re-initialize the FILE fields of the console. */
|
|
344 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
|
|
345 if (noninteractive)
|
|
346 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
347 }
|
|
348 }
|
|
349
|
|
350 #else
|
|
351
|
|
352 void
|
|
353 init_console_stream (void)
|
|
354 {
|
|
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;
|
|
360 if (initialized)
|
|
361 {
|
|
362 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
|
|
363 if (noninteractive)
|
|
364 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
365 }
|
|
366 }
|
|
367 #endif
|