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"
|
272
|
37 #include "sysfile.h"
|
0
|
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
|
78
|
46 Lisp_Object Vstdio_str;
|
0
|
47
|
|
48 static void
|
|
49 allocate_stream_console_struct (struct console *con)
|
|
50 {
|
272
|
51 if (!CONSOLE_STREAM_DATA (con))
|
|
52 CONSOLE_STREAM_DATA (con) = xnew_and_zero (struct stream_console);
|
267
|
53 else
|
272
|
54 xzero (*CONSOLE_STREAM_DATA (con));
|
0
|
55 }
|
|
56
|
|
57 static void
|
|
58 stream_init_console (struct console *con, Lisp_Object params)
|
|
59 {
|
|
60 Lisp_Object tty = CONSOLE_CONNECTION (con);
|
|
61 FILE *infd, *outfd, *errfd;
|
|
62
|
|
63 /* Open the specified console */
|
|
64
|
195
|
65 if (NILP (tty) || internal_equal (tty, Vstdio_str, 0))
|
0
|
66 {
|
272
|
67 infd = stdin;
|
0
|
68 outfd = stdout;
|
|
69 errfd = stderr;
|
|
70 }
|
|
71 else
|
|
72 {
|
|
73 CHECK_STRING (tty);
|
|
74 infd = outfd = errfd =
|
16
|
75 fopen ((char *) XSTRING_DATA (tty), "r+");
|
0
|
76 if (!infd)
|
16
|
77 error ("Unable to open tty %s", XSTRING_DATA (tty));
|
0
|
78 }
|
|
79
|
|
80 allocate_stream_console_struct (con);
|
272
|
81 CONSOLE_STREAM_DATA (con)->infd = infd;
|
0
|
82 CONSOLE_STREAM_DATA (con)->outfd = outfd;
|
|
83 CONSOLE_STREAM_DATA (con)->errfd = errfd;
|
|
84 }
|
|
85
|
|
86 static void
|
|
87 stream_init_device (struct device *d, Lisp_Object params)
|
|
88 {
|
|
89 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
90
|
272
|
91 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->infd);
|
0
|
92 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->outfd);
|
|
93 init_baud_rate (d);
|
|
94 init_one_device (d);
|
|
95 }
|
|
96
|
|
97 static int
|
|
98 stream_initially_selected_for_input (struct console *con)
|
|
99 {
|
|
100 return noninteractive && initialized;
|
|
101 }
|
|
102
|
|
103 static void
|
|
104 free_stream_console_struct (struct console *con)
|
|
105 {
|
272
|
106 if (CONSOLE_STREAM_DATA (con))
|
267
|
107 {
|
272
|
108 xfree (CONSOLE_STREAM_DATA (con));
|
|
109 CONSOLE_STREAM_DATA (con) = NULL;
|
267
|
110 }
|
0
|
111 }
|
|
112
|
|
113 extern int stdout_needs_newline;
|
|
114
|
|
115 static void
|
|
116 stream_delete_console (struct console *con)
|
|
117 {
|
|
118 if (/* CONSOLE_STREAM_DATA (con)->needs_newline */
|
185
|
119 stdout_needs_newline) /* #### clean this up */
|
0
|
120 {
|
|
121 fputc ('\n', CONSOLE_STREAM_DATA (con)->outfd);
|
|
122 fflush (CONSOLE_STREAM_DATA (con)->outfd);
|
|
123 }
|
|
124 if (CONSOLE_STREAM_DATA (con)->infd != stdin)
|
|
125 fclose (CONSOLE_STREAM_DATA (con)->infd);
|
|
126 free_stream_console_struct (con);
|
|
127 }
|
|
128
|
78
|
129 Lisp_Object
|
0
|
130 stream_semi_canonicalize_console_connection (Lisp_Object connection,
|
|
131 Error_behavior errb)
|
|
132 {
|
272
|
133 return NILP (connection) ? Vstdio_str : connection;
|
0
|
134 }
|
|
135
|
78
|
136 Lisp_Object
|
0
|
137 stream_canonicalize_console_connection (Lisp_Object connection,
|
|
138 Error_behavior errb)
|
|
139 {
|
195
|
140 if (NILP (connection) || internal_equal (connection, Vstdio_str, 0))
|
78
|
141 return Vstdio_str;
|
|
142
|
|
143 if (!ERRB_EQ (errb, ERROR_ME))
|
|
144 {
|
|
145 if (!STRINGP (connection))
|
|
146 return Qunbound;
|
|
147 }
|
|
148 else
|
|
149 CHECK_STRING (connection);
|
|
150
|
|
151 return Ffile_truename (connection, Qnil);
|
0
|
152 }
|
|
153
|
78
|
154 Lisp_Object
|
0
|
155 stream_semi_canonicalize_device_connection (Lisp_Object connection,
|
|
156 Error_behavior errb)
|
|
157 {
|
78
|
158 return stream_semi_canonicalize_console_connection (connection, errb);
|
0
|
159 }
|
|
160
|
78
|
161 Lisp_Object
|
0
|
162 stream_canonicalize_device_connection (Lisp_Object connection,
|
|
163 Error_behavior errb)
|
|
164 {
|
78
|
165 return stream_canonicalize_console_connection (connection, errb);
|
0
|
166 }
|
|
167
|
|
168
|
|
169 static void
|
|
170 stream_init_frame_1 (struct frame *f, Lisp_Object props)
|
|
171 {
|
272
|
172 #if 0
|
0
|
173 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
174 if (!NILP (DEVICE_FRAME_LIST (d)))
|
|
175 error ("Only one frame allowed on stream devices");
|
267
|
176 #endif
|
0
|
177 f->name = build_string ("stream");
|
|
178 f->height = 80;
|
|
179 f->width = 24;
|
|
180 f->visible = 0; /* so redisplay doesn't try to do anything */
|
|
181 }
|
|
182
|
|
183
|
|
184 static int
|
251
|
185 stream_text_width (struct frame *f, struct face_cachel *cachel,
|
|
186 CONST Emchar *str, Charcount len)
|
0
|
187 {
|
|
188 return len;
|
|
189 }
|
|
190
|
|
191 static int
|
|
192 stream_left_margin_width (struct window *w)
|
|
193 {
|
|
194 return 0;
|
|
195 }
|
|
196
|
|
197 static int
|
|
198 stream_right_margin_width (struct window *w)
|
|
199 {
|
|
200 return 0;
|
|
201 }
|
|
202
|
|
203 static int
|
|
204 stream_divider_height (void)
|
|
205 {
|
|
206 return 1;
|
|
207 }
|
|
208
|
|
209 static int
|
|
210 stream_eol_cursor_width (void)
|
|
211 {
|
|
212 return 1;
|
|
213 }
|
|
214
|
|
215 static void
|
|
216 stream_output_begin (struct device *d)
|
|
217 {
|
|
218 }
|
|
219
|
|
220 static void
|
|
221 stream_output_end (struct device *d)
|
|
222 {
|
|
223 }
|
|
224
|
|
225 static void
|
|
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)
|
|
230 {
|
|
231 }
|
|
232
|
|
233 static void
|
|
234 stream_output_vertical_divider (struct window *w, int clear)
|
|
235 {
|
|
236 }
|
|
237
|
|
238 static void
|
|
239 stream_clear_to_window_end (struct window *w, int ypos1, int ypos2)
|
|
240 {
|
|
241 }
|
|
242
|
|
243 static void
|
384
|
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)
|
0
|
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_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);
|
|
310 }
|
|
311
|
|
312 void
|
|
313 vars_of_console_stream (void)
|
|
314 {
|
|
315 DEFVAR_LISP ("terminal-console", &Vterminal_console /*
|
110
|
316 The initial console-object, which represents XEmacs' stdout.
|
0
|
317 */ );
|
|
318 Vterminal_console = Qnil;
|
|
319
|
|
320 DEFVAR_LISP ("terminal-device", &Vterminal_device /*
|
110
|
321 The initial device-object, which represents XEmacs' stdout.
|
0
|
322 */ );
|
|
323 Vterminal_device = Qnil;
|
|
324
|
|
325 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /*
|
110
|
326 The initial frame-object, which represents XEmacs' stdout.
|
0
|
327 */ );
|
|
328 Vterminal_frame = Qnil;
|
78
|
329
|
|
330 /* Moved from console-tty.c */
|
|
331 Vstdio_str = build_string ("stdio");
|
|
332 staticpro (&Vstdio_str);
|
0
|
333 }
|
|
334
|
|
335 void
|
|
336 init_console_stream (void)
|
|
337 {
|
|
338 /* This function can GC */
|
|
339 if (!initialized)
|
|
340 {
|
|
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;
|
|
345 }
|
272
|
346 else
|
|
347 {
|
|
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 }
|