0
|
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 "window.h"
|
|
38
|
|
39 DEFINE_CONSOLE_TYPE (stream);
|
|
40
|
|
41 Lisp_Object Vterminal_console;
|
|
42 Lisp_Object Vterminal_device;
|
|
43 Lisp_Object Vterminal_frame;
|
|
44
|
78
|
45 Lisp_Object Vstdio_str;
|
0
|
46
|
|
47 static void
|
|
48 allocate_stream_console_struct (struct console *con)
|
|
49 {
|
185
|
50 con->console_data = xnew_and_zero (struct stream_console);
|
0
|
51 }
|
|
52
|
|
53 static void
|
|
54 stream_init_console (struct console *con, Lisp_Object params)
|
|
55 {
|
|
56 Lisp_Object tty = CONSOLE_CONNECTION (con);
|
|
57 FILE *infd, *outfd, *errfd;
|
|
58
|
|
59 /* Open the specified console */
|
|
60
|
195
|
61 if (NILP (tty) || internal_equal (tty, Vstdio_str, 0))
|
0
|
62 {
|
|
63 infd = stdin;
|
|
64 outfd = stdout;
|
|
65 errfd = stderr;
|
|
66 }
|
|
67 else
|
|
68 {
|
|
69 CHECK_STRING (tty);
|
|
70 infd = outfd = errfd =
|
16
|
71 fopen ((char *) XSTRING_DATA (tty), "r+");
|
0
|
72 if (!infd)
|
16
|
73 error ("Unable to open tty %s", XSTRING_DATA (tty));
|
0
|
74 }
|
|
75
|
|
76 allocate_stream_console_struct (con);
|
|
77 CONSOLE_STREAM_DATA (con)->infd = infd;
|
|
78 CONSOLE_STREAM_DATA (con)->outfd = outfd;
|
|
79 CONSOLE_STREAM_DATA (con)->errfd = errfd;
|
|
80 }
|
|
81
|
|
82 static void
|
|
83 stream_init_device (struct device *d, Lisp_Object params)
|
|
84 {
|
|
85 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
86
|
|
87 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->infd);
|
|
88 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->outfd);
|
|
89 init_baud_rate (d);
|
|
90 init_one_device (d);
|
|
91 }
|
|
92
|
|
93 static int
|
|
94 stream_initially_selected_for_input (struct console *con)
|
|
95 {
|
|
96 return noninteractive && initialized;
|
|
97 }
|
|
98
|
|
99 static void
|
|
100 free_stream_console_struct (struct console *con)
|
|
101 {
|
|
102 struct stream_console *tcon = (struct stream_console *) con->console_data;
|
|
103 if (tcon)
|
|
104 xfree (tcon);
|
|
105 }
|
|
106
|
|
107 extern int stdout_needs_newline;
|
|
108
|
|
109 static void
|
|
110 stream_delete_console (struct console *con)
|
|
111 {
|
|
112 if (/* CONSOLE_STREAM_DATA (con)->needs_newline */
|
185
|
113 stdout_needs_newline) /* #### clean this up */
|
0
|
114 {
|
|
115 fputc ('\n', CONSOLE_STREAM_DATA (con)->outfd);
|
|
116 fflush (CONSOLE_STREAM_DATA (con)->outfd);
|
|
117 }
|
|
118 if (CONSOLE_STREAM_DATA (con)->infd != stdin)
|
|
119 fclose (CONSOLE_STREAM_DATA (con)->infd);
|
|
120 free_stream_console_struct (con);
|
|
121 }
|
|
122
|
78
|
123 Lisp_Object
|
0
|
124 stream_semi_canonicalize_console_connection (Lisp_Object connection,
|
|
125 Error_behavior errb)
|
|
126 {
|
78
|
127 if (NILP (connection))
|
|
128 return Vstdio_str;
|
|
129
|
|
130 return connection;
|
0
|
131 }
|
|
132
|
78
|
133 Lisp_Object
|
0
|
134 stream_canonicalize_console_connection (Lisp_Object connection,
|
|
135 Error_behavior errb)
|
|
136 {
|
195
|
137 if (NILP (connection) || internal_equal (connection, Vstdio_str, 0))
|
78
|
138 return Vstdio_str;
|
|
139
|
|
140 if (!ERRB_EQ (errb, ERROR_ME))
|
|
141 {
|
|
142 if (!STRINGP (connection))
|
|
143 return Qunbound;
|
|
144 }
|
|
145 else
|
|
146 CHECK_STRING (connection);
|
|
147
|
|
148 return Ffile_truename (connection, Qnil);
|
0
|
149 }
|
|
150
|
78
|
151 Lisp_Object
|
0
|
152 stream_semi_canonicalize_device_connection (Lisp_Object connection,
|
|
153 Error_behavior errb)
|
|
154 {
|
78
|
155 return stream_semi_canonicalize_console_connection (connection, errb);
|
0
|
156 }
|
|
157
|
78
|
158 Lisp_Object
|
0
|
159 stream_canonicalize_device_connection (Lisp_Object connection,
|
|
160 Error_behavior errb)
|
|
161 {
|
78
|
162 return stream_canonicalize_console_connection (connection, errb);
|
0
|
163 }
|
|
164
|
|
165
|
|
166 static void
|
|
167 stream_init_frame_1 (struct frame *f, Lisp_Object props)
|
|
168 {
|
|
169 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
170 if (!NILP (DEVICE_FRAME_LIST (d)))
|
|
171 error ("Only one frame allowed on stream devices");
|
|
172
|
|
173 f->name = build_string ("stream");
|
|
174 f->height = 80;
|
|
175 f->width = 24;
|
|
176 f->visible = 0; /* so redisplay doesn't try to do anything */
|
|
177 }
|
|
178
|
|
179
|
|
180 static int
|
251
|
181 stream_text_width (struct frame *f, struct face_cachel *cachel,
|
|
182 CONST Emchar *str, Charcount len)
|
0
|
183 {
|
|
184 return len;
|
|
185 }
|
|
186
|
|
187 static int
|
|
188 stream_left_margin_width (struct window *w)
|
|
189 {
|
|
190 return 0;
|
|
191 }
|
|
192
|
|
193 static int
|
|
194 stream_right_margin_width (struct window *w)
|
|
195 {
|
|
196 return 0;
|
|
197 }
|
|
198
|
|
199 static int
|
|
200 stream_divider_width (void)
|
|
201 {
|
|
202 return 1;
|
|
203 }
|
|
204
|
|
205 static int
|
|
206 stream_divider_height (void)
|
|
207 {
|
|
208 return 1;
|
|
209 }
|
|
210
|
|
211 static int
|
|
212 stream_eol_cursor_width (void)
|
|
213 {
|
|
214 return 1;
|
|
215 }
|
|
216
|
|
217 static void
|
|
218 stream_output_begin (struct device *d)
|
|
219 {
|
|
220 }
|
|
221
|
|
222 static void
|
|
223 stream_output_end (struct device *d)
|
|
224 {
|
|
225 }
|
|
226
|
|
227 static void
|
|
228 stream_output_display_block (struct window *w, struct display_line *dl,
|
|
229 int block, int start, int end,
|
|
230 int start_pixpos, int cursor_start,
|
|
231 int cursor_width, int cursor_height)
|
|
232 {
|
|
233 }
|
|
234
|
|
235 static void
|
|
236 stream_output_vertical_divider (struct window *w, int clear)
|
|
237 {
|
|
238 }
|
|
239
|
|
240 static void
|
|
241 stream_clear_to_window_end (struct window *w, int ypos1, int ypos2)
|
|
242 {
|
|
243 }
|
|
244
|
|
245 static void
|
|
246 stream_clear_region (Lisp_Object locale, face_index findex, int x, int y,
|
|
247 int width, int height)
|
|
248 {
|
|
249 }
|
|
250
|
|
251 static void
|
|
252 stream_clear_frame (struct frame *f)
|
|
253 {
|
|
254 }
|
|
255
|
|
256 static int
|
|
257 stream_flash (struct device *d)
|
|
258 {
|
|
259 return 0; /* sorry can't do it */
|
|
260 }
|
|
261
|
|
262 static void
|
|
263 stream_ring_bell (struct device *d, int volume, int pitch, int duration)
|
|
264 {
|
|
265 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
266 fputc (07, CONSOLE_STREAM_DATA (c)->outfd);
|
|
267 fflush (CONSOLE_STREAM_DATA (c)->outfd);
|
|
268 }
|
|
269
|
|
270
|
|
271 /************************************************************************/
|
|
272 /* initialization */
|
|
273 /************************************************************************/
|
|
274
|
|
275 void
|
|
276 console_type_create_stream (void)
|
|
277 {
|
|
278 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p");
|
|
279
|
|
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);
|
|
288
|
|
289 /* device methods */
|
|
290 CONSOLE_HAS_METHOD (stream, init_device);
|
|
291
|
|
292 /* frame methods */
|
|
293 CONSOLE_HAS_METHOD (stream, init_frame_1);
|
|
294
|
|
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_width);
|
|
302 CONSOLE_HAS_METHOD (stream, divider_height);
|
|
303 CONSOLE_HAS_METHOD (stream, eol_cursor_width);
|
|
304 CONSOLE_HAS_METHOD (stream, clear_to_window_end);
|
|
305 CONSOLE_HAS_METHOD (stream, clear_region);
|
|
306 CONSOLE_HAS_METHOD (stream, clear_frame);
|
|
307 CONSOLE_HAS_METHOD (stream, output_begin);
|
|
308 CONSOLE_HAS_METHOD (stream, output_end);
|
|
309 CONSOLE_HAS_METHOD (stream, flash);
|
|
310 CONSOLE_HAS_METHOD (stream, ring_bell);
|
|
311 }
|
|
312
|
|
313 void
|
|
314 vars_of_console_stream (void)
|
|
315 {
|
|
316 DEFVAR_LISP ("terminal-console", &Vterminal_console /*
|
110
|
317 The initial console-object, which represents XEmacs' stdout.
|
0
|
318 */ );
|
|
319 Vterminal_console = Qnil;
|
|
320
|
|
321 DEFVAR_LISP ("terminal-device", &Vterminal_device /*
|
110
|
322 The initial device-object, which represents XEmacs' stdout.
|
0
|
323 */ );
|
|
324 Vterminal_device = Qnil;
|
|
325
|
|
326 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /*
|
110
|
327 The initial frame-object, which represents XEmacs' stdout.
|
0
|
328 */ );
|
|
329 Vterminal_frame = Qnil;
|
78
|
330
|
|
331 /* Moved from console-tty.c */
|
|
332 Vstdio_str = build_string ("stdio");
|
|
333 staticpro (&Vstdio_str);
|
0
|
334 }
|
|
335
|
|
336 void
|
|
337 init_console_stream (void)
|
|
338 {
|
|
339 /* This function can GC */
|
|
340 if (!initialized)
|
|
341 {
|
|
342 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
|
|
343 Vterminal_console = Fdevice_console (Vterminal_device);
|
|
344 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
|
|
345 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
|
|
346 }
|
207
|
347 else {
|
|
348 /* Re-initialize the FILE fields of the console. */
|
|
349 stream_init_console (XCONSOLE (Vterminal_console), Qnil);
|
|
350 if (noninteractive)
|
|
351 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
352 }
|
0
|
353 }
|