Mercurial > hg > xemacs-beta
annotate src/console-stream.c @ 5781:0853e1ec8529
Use alloca_{rawbytes,ibytes} in #'copy-file, #'insert-file-contents-internal
src/ChangeLog addition:
2014-01-20 Aidan Kehoe <kehoea@parhasard.net>
* fileio.c (Fcopy_file, Finsert_file_contents_internal):
Use alloca_{rawbytes,ibytes} here instead of the implicit alloca
on the stack; doesn't change where the buffers are allocated for
these two functions, but does mean that decisions about alloca
vs. malloc based on buffer size are made in the same place
(ultimately, the ALLOCA() macro).
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Mon, 20 Jan 2014 17:53:07 +0000 |
parents | 81fee4aee9b6 |
children |
rev | line source |
---|---|
428 | 1 /* Stream device functions. |
2 Copyright (C) 1995 Free Software Foundation, Inc. | |
1279 | 3 Copyright (C) 1996, 2001, 2002, 2003 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5128
diff
changeset
|
7 XEmacs is free software: you can redistribute it and/or modify it |
428 | 8 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5128
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5128
diff
changeset
|
10 option) any later version. |
428 | 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 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5128
diff
changeset
|
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 19 |
20 /* Synched up with: Not in FSF. */ | |
21 | |
22 /* This file has been Mule-ized. */ | |
23 | |
24 /* Written by Ben Wing. */ | |
25 | |
26 #include <config.h> | |
27 #include "lisp.h" | |
28 | |
872 | 29 #include "device-impl.h" |
428 | 30 #include "events.h" |
872 | 31 #include "frame-impl.h" |
428 | 32 #include "redisplay.h" |
33 #include "sysdep.h" | |
800 | 34 #include "window.h" |
35 | |
872 | 36 #include "console-stream-impl.h" |
800 | 37 #include "console-tty.h" |
38 | |
428 | 39 #include "sysfile.h" |
40 | |
41 DEFINE_CONSOLE_TYPE (stream); | |
42 | |
43 Lisp_Object Vterminal_console; | |
44 Lisp_Object Vterminal_device; | |
45 Lisp_Object Vterminal_frame; | |
46 | |
47 Lisp_Object Vstdio_str; | |
48 | |
1204 | 49 static const struct memory_description stream_console_data_description_1 [] = { |
50 { XD_LISP_OBJECT, offsetof (struct stream_console, instream) }, | |
51 { XD_END } | |
52 }; | |
53 | |
3092 | 54 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
55 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("stream-console", stream_console, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
56 0, stream_console_data_description_1, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents:
3263
diff
changeset
|
57 Lisp_Stream_Console); |
3092 | 58 #else /* not NEW_GC */ |
1204 | 59 const struct sized_memory_description stream_console_data_description = { |
60 sizeof (struct stream_console), stream_console_data_description_1 | |
61 }; | |
3092 | 62 #endif /* not NEW_GC */ |
1204 | 63 |
428 | 64 static void |
2286 | 65 stream_init_console (struct console *con, Lisp_Object UNUSED (params)) |
428 | 66 { |
67 Lisp_Object tty = CONSOLE_CONNECTION (con); | |
68 struct stream_console *stream_con; | |
69 | |
3092 | 70 #ifdef NEW_GC |
71 if (CONSOLE_STREAM_DATA (con) == NULL) | |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
72 CONSOLE_STREAM_DATA (con) = |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
73 XSTREAM_CONSOLE (ALLOC_NORMAL_LISP_OBJECT (stream_console)); |
3092 | 74 #else /* not NEW_GC */ |
428 | 75 if (CONSOLE_STREAM_DATA (con) == NULL) |
1204 | 76 CONSOLE_STREAM_DATA (con) = xnew_and_zero (struct stream_console); |
3092 | 77 #endif /* not NEW_GC */ |
428 | 78 |
79 stream_con = CONSOLE_STREAM_DATA (con); | |
80 | |
1204 | 81 stream_con->instream = Qnil; |
428 | 82 |
83 /* Open the specified console */ | |
84 if (NILP (tty) || internal_equal (tty, Vstdio_str, 0)) | |
85 { | |
86 stream_con->in = stdin; | |
87 stream_con->out = stdout; | |
88 stream_con->err = stderr; | |
89 } | |
90 else | |
91 { | |
92 CHECK_STRING (tty); | |
93 stream_con->in = stream_con->out = stream_con->err = | |
442 | 94 /* #### We don't currently do coding-system translation on |
95 this descriptor. */ | |
771 | 96 qxe_fopen (XSTRING_DATA (tty), READ_PLUS_TEXT); |
428 | 97 if (!stream_con->in) |
563 | 98 signal_error (Qio_error, "Unable to open tty", tty); |
428 | 99 } |
100 } | |
101 | |
102 static void | |
2286 | 103 stream_init_device (struct device *d, Lisp_Object UNUSED (params)) |
428 | 104 { |
105 struct console *con = XCONSOLE (DEVICE_CONSOLE (d)); | |
106 | |
107 DEVICE_INFD (d) = fileno (CONSOLE_STREAM_DATA (con)->in); | |
108 DEVICE_OUTFD (d) = fileno (CONSOLE_STREAM_DATA (con)->out); | |
109 init_baud_rate (d); | |
110 init_one_device (d); | |
111 } | |
112 | |
113 static int | |
2286 | 114 stream_initially_selected_for_input (struct console *UNUSED (con)) |
428 | 115 { |
116 return noninteractive && initialized; | |
117 } | |
118 | |
119 extern int stdout_needs_newline; | |
120 | |
121 static void | |
122 stream_delete_console (struct console *con) | |
123 { | |
124 struct stream_console *stream_con = CONSOLE_STREAM_DATA (con); | |
125 if (stream_con) | |
126 { | |
127 if (/* stream_con->needs_newline */ | |
128 stdout_needs_newline) /* #### clean this up */ | |
129 { | |
130 fputc ('\n', stream_con->out); | |
131 fflush (stream_con->out); | |
132 } | |
133 if (stream_con->in != stdin) | |
771 | 134 retry_fclose (stream_con->in); |
428 | 135 |
3263 | 136 #ifndef NEW_GC |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
137 xfree (stream_con); |
3092 | 138 #endif /* not NEW_GC */ |
428 | 139 CONSOLE_STREAM_DATA (con) = NULL; |
140 } | |
141 } | |
142 | |
143 Lisp_Object | |
144 stream_semi_canonicalize_console_connection (Lisp_Object connection, | |
2286 | 145 Error_Behavior UNUSED (errb)) |
428 | 146 { |
147 return NILP (connection) ? Vstdio_str : connection; | |
148 } | |
149 | |
150 Lisp_Object | |
151 stream_canonicalize_console_connection (Lisp_Object connection, | |
578 | 152 Error_Behavior errb) |
428 | 153 { |
154 if (NILP (connection) || internal_equal (connection, Vstdio_str, 0)) | |
155 return Vstdio_str; | |
156 | |
157 if (!ERRB_EQ (errb, ERROR_ME)) | |
158 { | |
159 if (!STRINGP (connection)) | |
160 return Qunbound; | |
161 } | |
162 else | |
163 CHECK_STRING (connection); | |
164 | |
165 return Ffile_truename (connection, Qnil); | |
166 } | |
167 | |
168 Lisp_Object | |
169 stream_semi_canonicalize_device_connection (Lisp_Object connection, | |
578 | 170 Error_Behavior errb) |
428 | 171 { |
172 return stream_semi_canonicalize_console_connection (connection, errb); | |
173 } | |
174 | |
175 Lisp_Object | |
176 stream_canonicalize_device_connection (Lisp_Object connection, | |
578 | 177 Error_Behavior errb) |
428 | 178 { |
179 return stream_canonicalize_console_connection (connection, errb); | |
180 } | |
181 | |
182 | |
183 static void | |
2286 | 184 stream_init_frame_1 (struct frame *f, Lisp_Object UNUSED (props), |
771 | 185 int frame_name_is_defaulted) |
428 | 186 { |
187 #if 0 | |
188 struct device *d = XDEVICE (FRAME_DEVICE (f)); | |
189 if (!NILP (DEVICE_FRAME_LIST (d))) | |
563 | 190 invalid_operation ("Only one frame allowed on stream devices", Qunbound); |
428 | 191 #endif |
771 | 192 if (frame_name_is_defaulted) |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4928
diff
changeset
|
193 f->name = build_ascstring ("stream"); |
428 | 194 f->height = 80; |
195 f->width = 24; | |
196 f->visible = 0; /* so redisplay doesn't try to do anything */ | |
197 } | |
198 | |
199 | |
200 static int | |
5628
81fee4aee9b6
text_width methods interface cleanup.
Didier Verna <didier@xemacs.org>
parents:
5515
diff
changeset
|
201 stream_text_width (struct frame *UNUSED (f), |
2286 | 202 struct face_cachel *UNUSED (cachel), |
203 const Ichar *UNUSED (str), Charcount len) | |
428 | 204 { |
205 return len; | |
206 } | |
207 | |
208 static int | |
2286 | 209 stream_left_margin_width (struct window *UNUSED (w)) |
428 | 210 { |
211 return 0; | |
212 } | |
213 | |
214 static int | |
2286 | 215 stream_right_margin_width (struct window *UNUSED (w)) |
428 | 216 { |
217 return 0; | |
218 } | |
219 | |
220 static int | |
221 stream_divider_height (void) | |
222 { | |
223 return 1; | |
224 } | |
225 | |
226 static int | |
227 stream_eol_cursor_width (void) | |
228 { | |
229 return 1; | |
230 } | |
231 | |
1279 | 232 /* We used to try and check for redisplaying on stream devices (e.g. in |
233 redisplay_device(), and beg out if so. However, we didn't always manage | |
234 completely. Now we do manage completely, and to verify this we abort if | |
235 we try to display a stream device. This might fix some crashes I've | |
236 been getting in pdump -- the only difference between crash and non-crash | |
237 is a few changes to the redisplay critical-section handling. */ | |
238 | |
239 static void | |
2286 | 240 stream_window_output_begin (struct window *UNUSED (w)) |
1279 | 241 { |
2500 | 242 ABORT (); |
1279 | 243 } |
244 | |
245 static void | |
2286 | 246 stream_window_output_end (struct window *UNUSED (w)) |
1279 | 247 { |
2500 | 248 ABORT (); |
1279 | 249 } |
250 | |
251 static void | |
2286 | 252 stream_frame_output_begin (struct frame *UNUSED (f)) |
1279 | 253 { |
2500 | 254 ABORT (); |
1279 | 255 } |
256 | |
257 static void | |
2286 | 258 stream_frame_output_end (struct frame *UNUSED (f)) |
1279 | 259 { |
2500 | 260 ABORT (); |
1279 | 261 } |
262 | |
428 | 263 static void |
2286 | 264 stream_output_display_block (struct window *UNUSED (w), |
265 struct display_line *UNUSED (dl), | |
266 int UNUSED (block), int UNUSED (start), | |
267 int UNUSED (end), int UNUSED (start_pixpos), | |
268 int UNUSED (cursor_start), | |
269 int UNUSED (cursor_width), | |
270 int UNUSED (cursor_height)) | |
428 | 271 { |
2500 | 272 ABORT (); |
428 | 273 } |
274 | |
275 static void | |
5515
f87be7ddd60d
Simplify clear_region interface.
Didier Verna <didier@lrde.epita.fr>
parents:
5402
diff
changeset
|
276 stream_clear_region (Lisp_Object UNUSED (window), struct frame *UNUSED (f), |
f87be7ddd60d
Simplify clear_region interface.
Didier Verna <didier@lrde.epita.fr>
parents:
5402
diff
changeset
|
277 face_index UNUSED (findex), |
f87be7ddd60d
Simplify clear_region interface.
Didier Verna <didier@lrde.epita.fr>
parents:
5402
diff
changeset
|
278 int UNUSED (x), int UNUSED (y), |
f87be7ddd60d
Simplify clear_region interface.
Didier Verna <didier@lrde.epita.fr>
parents:
5402
diff
changeset
|
279 int UNUSED (width), int UNUSED (height), |
f87be7ddd60d
Simplify clear_region interface.
Didier Verna <didier@lrde.epita.fr>
parents:
5402
diff
changeset
|
280 Lisp_Object UNUSED (fcolor), |
2286 | 281 Lisp_Object UNUSED (bcolor), |
5080
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4976
diff
changeset
|
282 Lisp_Object UNUSED (background_pixmap), |
5502045ec510
The background-placement face property.
Didier Verna <didier@lrde.epita.fr>
parents:
4976
diff
changeset
|
283 Lisp_Object UNUSED (background_placement)) |
428 | 284 { |
2500 | 285 ABORT (); |
428 | 286 } |
287 | |
288 static int | |
2286 | 289 stream_flash (struct device *UNUSED (d)) |
428 | 290 { |
291 return 0; /* sorry can't do it */ | |
292 } | |
293 | |
294 static void | |
2286 | 295 stream_ring_bell (struct device *d, int UNUSED (volume), int UNUSED (pitch), |
296 int UNUSED (duration)) | |
428 | 297 { |
298 struct console *c = XCONSOLE (DEVICE_CONSOLE (d)); | |
826 | 299 /* Don't output ^G when not a TTY -- in particular, under MS Windows, ^G |
300 is interpreted as bell by the console, but not when running under | |
301 VC++. Probably this would be the same under Unix. */ | |
302 if (isatty (fileno (CONSOLE_STREAM_DATA (c)->out))) | |
303 { | |
304 fputc (07, CONSOLE_STREAM_DATA (c)->out); | |
305 fflush (CONSOLE_STREAM_DATA (c)->out); | |
306 } | |
428 | 307 } |
308 | |
309 | |
310 /************************************************************************/ | |
311 /* initialization */ | |
312 /************************************************************************/ | |
313 | |
314 void | |
315 console_type_create_stream (void) | |
316 { | |
317 INITIALIZE_CONSOLE_TYPE (stream, "stream", "console-stream-p"); | |
318 | |
319 /* console methods */ | |
320 CONSOLE_HAS_METHOD (stream, init_console); | |
321 CONSOLE_HAS_METHOD (stream, initially_selected_for_input); | |
322 CONSOLE_HAS_METHOD (stream, delete_console); | |
323 CONSOLE_HAS_METHOD (stream, canonicalize_console_connection); | |
324 CONSOLE_HAS_METHOD (stream, canonicalize_device_connection); | |
325 CONSOLE_HAS_METHOD (stream, semi_canonicalize_console_connection); | |
326 CONSOLE_HAS_METHOD (stream, semi_canonicalize_device_connection); | |
327 | |
328 /* device methods */ | |
329 CONSOLE_HAS_METHOD (stream, init_device); | |
330 | |
331 /* frame methods */ | |
332 CONSOLE_HAS_METHOD (stream, init_frame_1); | |
333 | |
334 /* redisplay methods */ | |
1279 | 335 CONSOLE_HAS_METHOD (stream, text_width); |
428 | 336 CONSOLE_HAS_METHOD (stream, left_margin_width); |
337 CONSOLE_HAS_METHOD (stream, right_margin_width); | |
338 CONSOLE_HAS_METHOD (stream, divider_height); | |
339 CONSOLE_HAS_METHOD (stream, eol_cursor_width); | |
1279 | 340 CONSOLE_HAS_METHOD (stream, window_output_begin); |
341 CONSOLE_HAS_METHOD (stream, window_output_end); | |
342 CONSOLE_HAS_METHOD (stream, frame_output_begin); | |
343 CONSOLE_HAS_METHOD (stream, frame_output_end); | |
344 CONSOLE_HAS_METHOD (stream, output_display_block); | |
428 | 345 CONSOLE_HAS_METHOD (stream, clear_region); |
346 CONSOLE_HAS_METHOD (stream, flash); | |
347 CONSOLE_HAS_METHOD (stream, ring_bell); | |
348 } | |
349 | |
350 void | |
351 reinit_console_type_create_stream (void) | |
352 { | |
353 REINITIALIZE_CONSOLE_TYPE (stream); | |
354 } | |
355 | |
356 void | |
357 vars_of_console_stream (void) | |
358 { | |
359 DEFVAR_LISP ("terminal-console", &Vterminal_console /* | |
444 | 360 The initial console object, which represents XEmacs' stdout. |
428 | 361 */ ); |
362 Vterminal_console = Qnil; | |
363 | |
364 DEFVAR_LISP ("terminal-device", &Vterminal_device /* | |
444 | 365 The initial device object, which represents XEmacs' stdout. |
428 | 366 */ ); |
367 Vterminal_device = Qnil; | |
368 | |
369 DEFVAR_LISP ("terminal-frame", &Vterminal_frame /* | |
444 | 370 The initial frame object, which represents XEmacs' stdout. |
428 | 371 */ ); |
372 Vterminal_frame = Qnil; | |
373 | |
374 /* Moved from console-tty.c */ | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4928
diff
changeset
|
375 Vstdio_str = build_ascstring ("stdio"); |
428 | 376 staticpro (&Vstdio_str); |
377 } | |
378 | |
379 #ifndef PDUMP | |
380 void | |
2342 | 381 init_console_stream (int UNUSED (reinit)) |
428 | 382 { |
383 /* This function can GC */ | |
384 if (!initialized) | |
385 { | |
386 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil); | |
387 Vterminal_console = Fdevice_console (Vterminal_device); | |
388 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device); | |
389 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window; | |
390 } | |
391 else | |
392 { | |
393 /* Re-initialize the FILE fields of the console. */ | |
394 stream_init_console (XCONSOLE (Vterminal_console), Qnil); | |
395 if (noninteractive) | |
396 event_stream_select_console (XCONSOLE (Vterminal_console)); | |
397 } | |
398 } | |
399 | |
400 #else | |
401 | |
402 void | |
442 | 403 init_console_stream (int reinit) |
428 | 404 { |
405 /* This function can GC */ | |
442 | 406 if (!reinit) |
407 { | |
408 Vterminal_device = Fmake_device (Qstream, Qnil, Qnil); | |
409 Vterminal_console = Fdevice_console (Vterminal_device); | |
410 Vterminal_frame = Fmake_frame (Qnil, Vterminal_device); | |
411 minibuf_window = XFRAME (Vterminal_frame)->minibuffer_window; | |
412 } | |
428 | 413 if (initialized) |
414 { | |
415 stream_init_console (XCONSOLE (Vterminal_console), Qnil); | |
416 if (noninteractive) | |
417 event_stream_select_console (XCONSOLE (Vterminal_console)); | |
418 } | |
419 } | |
420 #endif |