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
|
12
|
45 Lisp_Object Vstdio_str;
|
0
|
46
|
|
47 static void
|
|
48 allocate_stream_console_struct (struct console *con)
|
|
49 {
|
|
50 con->console_data =
|
|
51 (struct stream_console *) xmalloc (sizeof (struct stream_console));
|
|
52
|
|
53 /* zero out all slots. */
|
|
54 memset (con->console_data, 0, sizeof (struct stream_console));
|
|
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
|
|
65 if (NILP (tty) || !NILP (Fequal (tty, Vstdio_str)))
|
|
66 {
|
|
67 infd = stdin;
|
|
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);
|
|
81 CONSOLE_STREAM_DATA (con)->infd = infd;
|
|
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
|
|
91 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->infd);
|
|
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 {
|
|
106 struct stream_console *tcon = (struct stream_console *) con->console_data;
|
|
107 if (tcon)
|
|
108 xfree (tcon);
|
|
109 }
|
|
110
|
|
111 extern int stdout_needs_newline;
|
|
112
|
|
113 static void
|
|
114 stream_delete_console (struct console *con)
|
|
115 {
|
|
116 if (/* CONSOLE_STREAM_DATA (con)->needs_newline */
|
|
117 stdout_needs_newline) /* #### clean this up */
|
|
118 {
|
|
119 fputc ('\n', CONSOLE_STREAM_DATA (con)->outfd);
|
|
120 fflush (CONSOLE_STREAM_DATA (con)->outfd);
|
|
121 }
|
|
122 if (CONSOLE_STREAM_DATA (con)->infd != stdin)
|
|
123 fclose (CONSOLE_STREAM_DATA (con)->infd);
|
|
124 free_stream_console_struct (con);
|
|
125 }
|
|
126
|
12
|
127 Lisp_Object
|
0
|
128 stream_semi_canonicalize_console_connection (Lisp_Object connection,
|
|
129 Error_behavior errb)
|
|
130 {
|
12
|
131 if (NILP (connection))
|
|
132 return Vstdio_str;
|
|
133
|
|
134 return connection;
|
0
|
135 }
|
|
136
|
12
|
137 Lisp_Object
|
0
|
138 stream_canonicalize_console_connection (Lisp_Object connection,
|
|
139 Error_behavior errb)
|
|
140 {
|
12
|
141 if (NILP (connection) || !NILP (Fequal (connection, Vstdio_str)))
|
|
142 return Vstdio_str;
|
|
143
|
|
144 if (!ERRB_EQ (errb, ERROR_ME))
|
|
145 {
|
|
146 if (!STRINGP (connection))
|
|
147 return Qunbound;
|
|
148 }
|
|
149 else
|
|
150 CHECK_STRING (connection);
|
|
151
|
|
152 return Ffile_truename (connection, Qnil);
|
0
|
153 }
|
|
154
|
12
|
155 Lisp_Object
|
0
|
156 stream_semi_canonicalize_device_connection (Lisp_Object connection,
|
|
157 Error_behavior errb)
|
|
158 {
|
12
|
159 return stream_semi_canonicalize_console_connection (connection, errb);
|
0
|
160 }
|
|
161
|
12
|
162 Lisp_Object
|
0
|
163 stream_canonicalize_device_connection (Lisp_Object connection,
|
|
164 Error_behavior errb)
|
|
165 {
|
12
|
166 return stream_canonicalize_console_connection (connection, errb);
|
0
|
167 }
|
|
168
|
|
169
|
|
170 static void
|
|
171 stream_init_frame_1 (struct frame *f, Lisp_Object props)
|
|
172 {
|
|
173 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
174 if (!NILP (DEVICE_FRAME_LIST (d)))
|
|
175 error ("Only one frame allowed on stream devices");
|
|
176
|
|
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
|
|
185 stream_text_width (struct face_cachel *cachel, CONST Emchar *str,
|
|
186 Charcount len)
|
|
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_width (void)
|
|
205 {
|
|
206 return 1;
|
|
207 }
|
|
208
|
|
209 static int
|
|
210 stream_divider_height (void)
|
|
211 {
|
|
212 return 1;
|
|
213 }
|
|
214
|
|
215 static int
|
|
216 stream_eol_cursor_width (void)
|
|
217 {
|
|
218 return 1;
|
|
219 }
|
|
220
|
|
221 static void
|
|
222 stream_output_begin (struct device *d)
|
|
223 {
|
|
224 }
|
|
225
|
|
226 static void
|
|
227 stream_output_end (struct device *d)
|
|
228 {
|
|
229 }
|
|
230
|
|
231 static void
|
|
232 stream_output_display_block (struct window *w, struct display_line *dl,
|
|
233 int block, int start, int end,
|
|
234 int start_pixpos, int cursor_start,
|
|
235 int cursor_width, int cursor_height)
|
|
236 {
|
|
237 }
|
|
238
|
|
239 static void
|
|
240 stream_output_vertical_divider (struct window *w, int clear)
|
|
241 {
|
|
242 }
|
|
243
|
|
244 static void
|
|
245 stream_clear_to_window_end (struct window *w, int ypos1, int ypos2)
|
|
246 {
|
|
247 }
|
|
248
|
|
249 static void
|
|
250 stream_clear_region (Lisp_Object locale, face_index findex, int x, int y,
|
|
251 int width, int height)
|
|
252 {
|
|
253 }
|
|
254
|
|
255 static void
|
|
256 stream_clear_frame (struct frame *f)
|
|
257 {
|
|
258 }
|
|
259
|
|
260 static int
|
|
261 stream_flash (struct device *d)
|
|
262 {
|
|
263 return 0; /* sorry can't do it */
|
|
264 }
|
|
265
|
|
266 static void
|
|
267 stream_ring_bell (struct device *d, int volume, int pitch, int duration)
|
|
268 {
|
|
269 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
270 fputc (07, CONSOLE_STREAM_DATA (c)->outfd);
|
|
271 fflush (CONSOLE_STREAM_DATA (c)->outfd);
|
|
272 }
|
|
273
|
|
274
|
|
275 /************************************************************************/
|
|
276 /* initialization */
|
|
277 /************************************************************************/
|
|
278
|
|
279 void
|
|
280 console_type_create_stream (void)
|
|
281 {
|
|
282 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p");
|
|
283
|
|
284 /* console methods */
|
|
285 CONSOLE_HAS_METHOD (stream, init_console);
|
|
286 CONSOLE_HAS_METHOD (stream, initially_selected_for_input);
|
|
287 CONSOLE_HAS_METHOD (stream, delete_console);
|
|
288 CONSOLE_HAS_METHOD (stream, canonicalize_console_connection);
|
|
289 CONSOLE_HAS_METHOD (stream, canonicalize_device_connection);
|
|
290 CONSOLE_HAS_METHOD (stream, semi_canonicalize_console_connection);
|
|
291 CONSOLE_HAS_METHOD (stream, semi_canonicalize_device_connection);
|
|
292
|
|
293 /* device methods */
|
|
294 CONSOLE_HAS_METHOD (stream, init_device);
|
|
295
|
|
296 /* frame methods */
|
|
297 CONSOLE_HAS_METHOD (stream, init_frame_1);
|
|
298
|
|
299 /* redisplay methods */
|
|
300 CONSOLE_HAS_METHOD (stream, left_margin_width);
|
|
301 CONSOLE_HAS_METHOD (stream, right_margin_width);
|
|
302 CONSOLE_HAS_METHOD (stream, text_width);
|
|
303 CONSOLE_HAS_METHOD (stream, output_display_block);
|
|
304 CONSOLE_HAS_METHOD (stream, output_vertical_divider);
|
|
305 CONSOLE_HAS_METHOD (stream, divider_width);
|
|
306 CONSOLE_HAS_METHOD (stream, divider_height);
|
|
307 CONSOLE_HAS_METHOD (stream, eol_cursor_width);
|
|
308 CONSOLE_HAS_METHOD (stream, clear_to_window_end);
|
|
309 CONSOLE_HAS_METHOD (stream, clear_region);
|
|
310 CONSOLE_HAS_METHOD (stream, clear_frame);
|
|
311 CONSOLE_HAS_METHOD (stream, output_begin);
|
|
312 CONSOLE_HAS_METHOD (stream, output_end);
|
|
313 CONSOLE_HAS_METHOD (stream, flash);
|
|
314 CONSOLE_HAS_METHOD (stream, ring_bell);
|
|
315 }
|
|
316
|
|
317 void
|
|
318 vars_of_console_stream (void)
|
|
319 {
|
|
320 DEFVAR_LISP ("terminal-console", &Vterminal_console /*
|
|
321 The initial console-object, which represent's Emacs's stdout.
|
|
322 */ );
|
|
323 Vterminal_console = Qnil;
|
|
324
|
|
325 DEFVAR_LISP ("terminal-device", &Vterminal_device /*
|
|
326 The initial device-object, which represent's Emacs's stdout.
|
|
327 */ );
|
|
328 Vterminal_device = Qnil;
|
|
329
|
|
330 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /*
|
|
331 The initial frame-object, which represents Emacs's stdout.
|
|
332 */ );
|
|
333 Vterminal_frame = Qnil;
|
12
|
334
|
|
335 /* Moved from console-tty.c */
|
|
336 Vstdio_str = build_string ("stdio");
|
|
337 staticpro (&Vstdio_str);
|
0
|
338 }
|
|
339
|
|
340 void
|
|
341 init_console_stream (void)
|
|
342 {
|
|
343 /* This function can GC */
|
|
344 if (!initialized)
|
|
345 {
|
|
346 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil);
|
|
347 Vterminal_console = Fdevice_console (Vterminal_device);
|
|
348 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device);
|
|
349 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window;
|
|
350 }
|
|
351 else if (noninteractive)
|
|
352 event_stream_select_console (XCONSOLE (Vterminal_console));
|
|
353 }
|