Mercurial > hg > xemacs-beta
comparison src/console-stream.c @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | bcdc7deadc19 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
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 | |
45 extern Lisp_Object Vstdio_str; /* in console-tty.c */ | |
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 = | |
75 fopen ((char *) string_data (XSTRING (tty)), "r+"); | |
76 if (!infd) | |
77 error ("Unable to open tty %s", string_data (XSTRING (tty))); | |
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 | |
127 static Lisp_Object | |
128 stream_semi_canonicalize_console_connection (Lisp_Object connection, | |
129 Error_behavior errb) | |
130 { | |
131 return tty_semi_canonicalize_console_connection (connection, errb); | |
132 } | |
133 | |
134 static Lisp_Object | |
135 stream_canonicalize_console_connection (Lisp_Object connection, | |
136 Error_behavior errb) | |
137 { | |
138 return tty_canonicalize_console_connection (connection, errb); | |
139 } | |
140 | |
141 static Lisp_Object | |
142 stream_semi_canonicalize_device_connection (Lisp_Object connection, | |
143 Error_behavior errb) | |
144 { | |
145 return tty_semi_canonicalize_device_connection (connection, errb); | |
146 } | |
147 | |
148 static Lisp_Object | |
149 stream_canonicalize_device_connection (Lisp_Object connection, | |
150 Error_behavior errb) | |
151 { | |
152 return tty_canonicalize_device_connection (connection, errb); | |
153 } | |
154 | |
155 | |
156 static void | |
157 stream_init_frame_1 (struct frame *f, Lisp_Object props) | |
158 { | |
159 struct device *d = XDEVICE (FRAME_DEVICE (f)); | |
160 if (!NILP (DEVICE_FRAME_LIST (d))) | |
161 error ("Only one frame allowed on stream devices"); | |
162 | |
163 f->name = build_string ("stream"); | |
164 f->height = 80; | |
165 f->width = 24; | |
166 f->visible = 0; /* so redisplay doesn't try to do anything */ | |
167 } | |
168 | |
169 | |
170 static int | |
171 stream_text_width (struct face_cachel *cachel, CONST Emchar *str, | |
172 Charcount len) | |
173 { | |
174 return len; | |
175 } | |
176 | |
177 static int | |
178 stream_left_margin_width (struct window *w) | |
179 { | |
180 return 0; | |
181 } | |
182 | |
183 static int | |
184 stream_right_margin_width (struct window *w) | |
185 { | |
186 return 0; | |
187 } | |
188 | |
189 static int | |
190 stream_divider_width (void) | |
191 { | |
192 return 1; | |
193 } | |
194 | |
195 static int | |
196 stream_divider_height (void) | |
197 { | |
198 return 1; | |
199 } | |
200 | |
201 static int | |
202 stream_eol_cursor_width (void) | |
203 { | |
204 return 1; | |
205 } | |
206 | |
207 static void | |
208 stream_output_begin (struct device *d) | |
209 { | |
210 } | |
211 | |
212 static void | |
213 stream_output_end (struct device *d) | |
214 { | |
215 } | |
216 | |
217 static void | |
218 stream_output_display_block (struct window *w, struct display_line *dl, | |
219 int block, int start, int end, | |
220 int start_pixpos, int cursor_start, | |
221 int cursor_width, int cursor_height) | |
222 { | |
223 } | |
224 | |
225 static void | |
226 stream_output_vertical_divider (struct window *w, int clear) | |
227 { | |
228 } | |
229 | |
230 static void | |
231 stream_clear_to_window_end (struct window *w, int ypos1, int ypos2) | |
232 { | |
233 } | |
234 | |
235 static void | |
236 stream_clear_region (Lisp_Object locale, face_index findex, int x, int y, | |
237 int width, int height) | |
238 { | |
239 } | |
240 | |
241 static void | |
242 stream_clear_frame (struct frame *f) | |
243 { | |
244 } | |
245 | |
246 static int | |
247 stream_flash (struct device *d) | |
248 { | |
249 return 0; /* sorry can't do it */ | |
250 } | |
251 | |
252 static void | |
253 stream_ring_bell (struct device *d, int volume, int pitch, int duration) | |
254 { | |
255 struct console *c = XCONSOLE (DEVICE_CONSOLE (d)); | |
256 fputc (07, CONSOLE_STREAM_DATA (c)->outfd); | |
257 fflush (CONSOLE_STREAM_DATA (c)->outfd); | |
258 } | |
259 | |
260 | |
261 /************************************************************************/ | |
262 /* initialization */ | |
263 /************************************************************************/ | |
264 | |
265 void | |
266 console_type_create_stream (void) | |
267 { | |
268 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p"); | |
269 | |
270 /* console methods */ | |
271 CONSOLE_HAS_METHOD (stream, init_console); | |
272 CONSOLE_HAS_METHOD (stream, initially_selected_for_input); | |
273 CONSOLE_HAS_METHOD (stream, delete_console); | |
274 CONSOLE_HAS_METHOD (stream, canonicalize_console_connection); | |
275 CONSOLE_HAS_METHOD (stream, canonicalize_device_connection); | |
276 CONSOLE_HAS_METHOD (stream, semi_canonicalize_console_connection); | |
277 CONSOLE_HAS_METHOD (stream, semi_canonicalize_device_connection); | |
278 | |
279 /* device methods */ | |
280 CONSOLE_HAS_METHOD (stream, init_device); | |
281 | |
282 /* frame methods */ | |
283 CONSOLE_HAS_METHOD (stream, init_frame_1); | |
284 | |
285 /* redisplay methods */ | |
286 CONSOLE_HAS_METHOD (stream, left_margin_width); | |
287 CONSOLE_HAS_METHOD (stream, right_margin_width); | |
288 CONSOLE_HAS_METHOD (stream, text_width); | |
289 CONSOLE_HAS_METHOD (stream, output_display_block); | |
290 CONSOLE_HAS_METHOD (stream, output_vertical_divider); | |
291 CONSOLE_HAS_METHOD (stream, divider_width); | |
292 CONSOLE_HAS_METHOD (stream, divider_height); | |
293 CONSOLE_HAS_METHOD (stream, eol_cursor_width); | |
294 CONSOLE_HAS_METHOD (stream, clear_to_window_end); | |
295 CONSOLE_HAS_METHOD (stream, clear_region); | |
296 CONSOLE_HAS_METHOD (stream, clear_frame); | |
297 CONSOLE_HAS_METHOD (stream, output_begin); | |
298 CONSOLE_HAS_METHOD (stream, output_end); | |
299 CONSOLE_HAS_METHOD (stream, flash); | |
300 CONSOLE_HAS_METHOD (stream, ring_bell); | |
301 } | |
302 | |
303 void | |
304 vars_of_console_stream (void) | |
305 { | |
306 DEFVAR_LISP ("terminal-console", &Vterminal_console /* | |
307 The initial console-object, which represent's Emacs's stdout. | |
308 */ ); | |
309 Vterminal_console = Qnil; | |
310 | |
311 DEFVAR_LISP ("terminal-device", &Vterminal_device /* | |
312 The initial device-object, which represent's Emacs's stdout. | |
313 */ ); | |
314 Vterminal_device = Qnil; | |
315 | |
316 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /* | |
317 The initial frame-object, which represents Emacs's stdout. | |
318 */ ); | |
319 Vterminal_frame = Qnil; | |
320 } | |
321 | |
322 void | |
323 init_console_stream (void) | |
324 { | |
325 /* This function can GC */ | |
326 if (!initialized) | |
327 { | |
328 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil); | |
329 Vterminal_console = Fdevice_console (Vterminal_device); | |
330 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device); | |
331 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window; | |
332 } | |
333 else if (noninteractive) | |
334 event_stream_select_console (XCONSOLE (Vterminal_console)); | |
335 } |