428
|
1 /* Lisp object printing and output streams.
|
|
2 Copyright (C) 1985, 1986, 1988, 1992-1995 Free Software Foundation, Inc.
|
1261
|
3 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2003 Ben Wing.
|
428
|
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 synched with FSF. */
|
|
23
|
|
24 /* This file has been Mule-ized. */
|
|
25
|
771
|
26 /* Seriously divergent from FSF by this point.
|
|
27
|
|
28 Seriously hacked on by Ben Wing for Mule. All stdio code also by Ben,
|
|
29 as well as the debugging code (initial version of debug_print(), though,
|
|
30 by Jamie Zawinski) and the _fmt interfaces. Also a fair amount of work
|
|
31 by Hrvoje, e.g. floating-point code and rewriting to avoid O(N^2)
|
|
32 consing when outputting to the echo area. Print-circularity code by
|
|
33 Martin? */
|
428
|
34
|
|
35 #include <config.h>
|
|
36 #include "lisp.h"
|
|
37
|
|
38 #include "backtrace.h"
|
|
39 #include "buffer.h"
|
|
40 #include "bytecode.h"
|
872
|
41 #include "device-impl.h"
|
428
|
42 #include "extents.h"
|
|
43 #include "frame.h"
|
|
44 #include "insdel.h"
|
|
45 #include "lstream.h"
|
771
|
46 #include "opaque.h"
|
800
|
47
|
872
|
48 #include "console-tty-impl.h"
|
|
49 #include "console-stream-impl.h"
|
442
|
50 #ifdef WIN32_NATIVE
|
|
51 #include "console-msw.h"
|
|
52 #endif
|
428
|
53
|
800
|
54 #include "sysfile.h"
|
|
55
|
428
|
56 #include <float.h>
|
|
57 /* Define if not in float.h */
|
|
58 #ifndef DBL_DIG
|
|
59 #define DBL_DIG 16
|
|
60 #endif
|
|
61
|
|
62 Lisp_Object Vstandard_output, Qstandard_output;
|
|
63
|
|
64 /* The subroutine object for external-debugging-output is kept here
|
|
65 for the convenience of the debugger. */
|
442
|
66 Lisp_Object Qexternal_debugging_output, Qalternate_debugging_output;
|
|
67
|
|
68 #ifdef HAVE_MS_WINDOWS
|
|
69 Lisp_Object Qmswindows_debugging_output;
|
|
70 #endif
|
428
|
71
|
|
72 /* Avoid actual stack overflow in print. */
|
|
73 static int print_depth;
|
|
74
|
|
75 /* Detect most circularities to print finite output. */
|
|
76 #define PRINT_CIRCLE 200
|
|
77 static Lisp_Object being_printed[PRINT_CIRCLE];
|
|
78
|
|
79 /* Maximum length of list or vector to print in full; noninteger means
|
|
80 effectively infinity */
|
|
81
|
|
82 Lisp_Object Vprint_length;
|
|
83 Lisp_Object Qprint_length;
|
|
84
|
|
85 /* Maximum length of string to print in full; noninteger means
|
|
86 effectively infinity */
|
|
87
|
|
88 Lisp_Object Vprint_string_length;
|
|
89 Lisp_Object Qprint_string_length;
|
|
90
|
|
91 /* Maximum depth of list to print in full; noninteger means
|
|
92 effectively infinity. */
|
|
93
|
|
94 Lisp_Object Vprint_level;
|
|
95
|
|
96 /* Label to use when making echo-area messages. */
|
|
97
|
|
98 Lisp_Object Vprint_message_label;
|
|
99
|
|
100 /* Nonzero means print newlines in strings as \n. */
|
|
101
|
|
102 int print_escape_newlines;
|
|
103 int print_readably;
|
|
104
|
|
105 /* Non-nil means print #: before uninterned symbols.
|
|
106 Neither t nor nil means so that and don't clear Vprint_gensym_alist
|
|
107 on entry to and exit from print functions. */
|
|
108 Lisp_Object Vprint_gensym;
|
|
109 Lisp_Object Vprint_gensym_alist;
|
|
110
|
|
111 Lisp_Object Qdisplay_error;
|
|
112 Lisp_Object Qprint_message_label;
|
|
113
|
|
114 /* Force immediate output of all printed data. Used for debugging. */
|
|
115 int print_unbuffered;
|
|
116
|
|
117 FILE *termscript; /* Stdio stream being used for copy of all output. */
|
|
118
|
1346
|
119 static void write_string_to_alternate_debugging_output (const Ibyte *str,
|
771
|
120 Bytecount len);
|
|
121
|
1957
|
122 /* To avoid consing in debug_prin1, we package up variables we need to bind
|
|
123 into an opaque object. */
|
|
124 struct debug_bindings
|
|
125 {
|
2367
|
126 int inhibit_non_essential_conversion_operations;
|
1957
|
127 int print_depth;
|
|
128 int print_readably;
|
|
129 int print_unbuffered;
|
|
130 int gc_currently_forbidden;
|
|
131 Lisp_Object Vprint_length;
|
|
132 Lisp_Object Vprint_level;
|
|
133 Lisp_Object Vinhibit_quit;
|
|
134 };
|
|
135
|
|
136 static Lisp_Object debug_prin1_bindings;
|
428
|
137
|
|
138
|
|
139 int stdout_needs_newline;
|
1346
|
140 int stdout_clear_before_next_output;
|
428
|
141
|
771
|
142 /* Basic function to actually write to a stdio stream or TTY console. */
|
|
143
|
442
|
144 static void
|
1346
|
145 write_string_to_stdio_stream_1 (FILE *stream, struct console *con,
|
|
146 const Ibyte *ptr, Bytecount len,
|
|
147 int must_flush)
|
428
|
148 {
|
771
|
149 Extbyte *extptr = 0;
|
|
150 Bytecount extlen = 0;
|
|
151 int output_is_std_handle =
|
|
152 stream ? stream == stdout || stream == stderr :
|
|
153 CONSOLE_TTY_DATA (con)->is_stdio;
|
|
154
|
|
155 if (stream || output_is_std_handle)
|
|
156 {
|
2367
|
157 if (initialized && !inhibit_non_essential_conversion_operations)
|
771
|
158 TO_EXTERNAL_FORMAT (DATA, (ptr, len),
|
|
159 ALLOCA, (extptr, extlen),
|
|
160 Qterminal);
|
|
161 else
|
|
162 {
|
2367
|
163 #ifdef NON_ASCII_INTERNAL_FORMAT
|
|
164 #error Do something here
|
|
165 #else
|
771
|
166 extptr = (Extbyte *) ptr;
|
|
167 extlen = (Bytecount) len;
|
2367
|
168 #endif
|
771
|
169 }
|
|
170 }
|
|
171
|
428
|
172 if (stream)
|
|
173 {
|
442
|
174 #ifdef WIN32_NATIVE
|
|
175 HANDLE errhand = GetStdHandle (STD_INPUT_HANDLE);
|
|
176 int no_useful_stderr = errhand == 0 || errhand == INVALID_HANDLE_VALUE;
|
|
177
|
|
178 if (!no_useful_stderr)
|
|
179 no_useful_stderr = !PeekNamedPipe (errhand, 0, 0, 0, 0, 0);
|
|
180 /* we typically have no useful stdout/stderr under windows if we're
|
|
181 being invoked graphically. */
|
|
182 if (no_useful_stderr)
|
771
|
183 mswindows_output_console_string (ptr, len);
|
442
|
184 else
|
428
|
185 #endif
|
442
|
186 {
|
771
|
187 retry_fwrite (extptr, 1, extlen, stream);
|
442
|
188 #ifdef WIN32_NATIVE
|
|
189 /* Q122442 says that pipes are "treated as files, not as
|
|
190 devices", and that this is a feature. Before I found that
|
|
191 article, I thought it was a bug. Thanks MS, I feel much
|
|
192 better now. - kkm */
|
|
193 must_flush = 1;
|
|
194 #endif
|
|
195 if (must_flush)
|
|
196 fflush (stream);
|
|
197 }
|
428
|
198 }
|
|
199 else
|
771
|
200 /* The stream itself does conversion to external format */
|
|
201 Lstream_write (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream), ptr, len);
|
442
|
202
|
|
203 if (output_is_std_handle)
|
428
|
204 {
|
|
205 if (termscript)
|
|
206 {
|
771
|
207 retry_fwrite (extptr, 1, extlen, termscript);
|
428
|
208 fflush (termscript);
|
|
209 }
|
1346
|
210 stdout_needs_newline = (ptr[len - 1] != '\n');
|
428
|
211 }
|
|
212 }
|
|
213
|
1346
|
214 /* Write to a stdio stream or TTY console, first clearing the left side
|
|
215 if necessary. */
|
|
216
|
|
217 static void
|
|
218 write_string_to_stdio_stream (FILE *stream, struct console *con,
|
|
219 const Ibyte *ptr, Bytecount len,
|
|
220 int must_flush)
|
|
221 {
|
|
222 if (stdout_clear_before_next_output &&
|
|
223 (stream ? stream == stdout || stream == stderr :
|
|
224 CONSOLE_TTY_DATA (con)->is_stdio))
|
|
225 {
|
|
226 if (stdout_needs_newline)
|
|
227 write_string_to_stdio_stream_1 (stream, con, (Ibyte *) "\n", 1,
|
|
228 must_flush);
|
|
229 stdout_clear_before_next_output = 0;
|
|
230 }
|
|
231
|
|
232 write_string_to_stdio_stream_1 (stream, con, ptr, len, must_flush);
|
|
233 }
|
|
234
|
|
235 /*
|
|
236 EXT_PRINT_STDOUT = stdout or its equivalent (may be a
|
|
237 console window under MS Windows)
|
|
238 EXT_PRINT_STDERR = stderr or its equivalent (may be a
|
|
239 console window under MS Windows)
|
|
240 EXT_PRINT_ALTERNATE = an internal character array; see
|
|
241 `alternate-debugging-output'
|
|
242 EXT_PRINT_MSWINDOWS = Under MS Windows, the "debugging output" that
|
|
243 debuggers can hook into; uses OutputDebugString()
|
|
244 system call
|
|
245 EXT_PRINT_ALL = all of the above except stdout
|
|
246 */
|
|
247
|
|
248 enum ext_print
|
|
249 {
|
|
250 EXT_PRINT_STDOUT = 1,
|
|
251 EXT_PRINT_STDERR = 2,
|
|
252 EXT_PRINT_ALTERNATE = 4,
|
|
253 EXT_PRINT_MSWINDOWS = 8,
|
|
254 EXT_PRINT_ALL = 14
|
|
255 };
|
|
256
|
|
257 static void
|
|
258 write_string_to_external_output (const Ibyte *ptr, Bytecount len,
|
|
259 int dest)
|
|
260 {
|
|
261 if (dest & EXT_PRINT_STDOUT)
|
|
262 write_string_to_stdio_stream (stdout, 0, ptr, len, 1);
|
|
263 if (dest & EXT_PRINT_STDERR)
|
|
264 write_string_to_stdio_stream (stderr, 0, ptr, len, 1);
|
|
265 if (dest & EXT_PRINT_ALTERNATE)
|
|
266 write_string_to_alternate_debugging_output (ptr, len);
|
|
267 #ifdef WIN32_NATIVE
|
|
268 if (dest & EXT_PRINT_MSWINDOWS)
|
|
269 write_string_to_mswindows_debugging_output (ptr, len);
|
|
270 #endif
|
|
271 }
|
|
272
|
|
273 /* #### The following function should make use of a call to the
|
|
274 emacs_vsprintf_*() functions rather than just using vsprintf. This is
|
|
275 the only way to ensure that I18N3 works properly (many implementations
|
|
276 of the *printf() functions, including the ones included in glibc, do not
|
|
277 implement the %###$ argument-positioning syntax).
|
442
|
278
|
|
279 Note, however, that to do this, we'd have to
|
|
280
|
|
281 1) pre-allocate all the lstreams and do whatever else was necessary
|
|
282 to make sure that no allocation occurs, since these functions may be
|
|
283 called from fatal_error_signal().
|
|
284
|
|
285 2) (to be really correct) make a new lstream that outputs using
|
1346
|
286 mswindows_output_console_string().
|
|
287
|
|
288 3) A reasonable compromise might be to use emacs_vsprintf() when we're
|
|
289 in a safe state, and when not, use plain vsprintf(). */
|
442
|
290
|
771
|
291 static void
|
1346
|
292 write_string_to_external_output_va (const CIbyte *fmt, va_list args,
|
|
293 int dest)
|
442
|
294 {
|
867
|
295 Ibyte kludge[8192];
|
771
|
296 Bytecount kludgelen;
|
|
297
|
2367
|
298 if (initialized && !inhibit_non_essential_conversion_operations)
|
771
|
299 fmt = GETTEXT (fmt);
|
867
|
300 vsprintf ((CIbyte *) kludge, fmt, args);
|
771
|
301 kludgelen = qxestrlen (kludge);
|
1346
|
302 write_string_to_external_output (kludge, kludgelen, dest);
|
442
|
303 }
|
|
304
|
771
|
305 /* Output portably to stderr or its equivalent (i.e. may be a console
|
|
306 window under MS Windows); do external-format conversion and call GETTEXT
|
|
307 on the format string. Automatically flush when done.
|
442
|
308
|
771
|
309 This is safe even when not initialized or when dying -- we don't do
|
|
310 conversion in such cases. */
|
|
311
|
|
312 void
|
867
|
313 stderr_out (const CIbyte *fmt, ...)
|
442
|
314 {
|
|
315 va_list args;
|
|
316 va_start (args, fmt);
|
1346
|
317 write_string_to_external_output_va (fmt, args, EXT_PRINT_STDERR);
|
442
|
318 va_end (args);
|
|
319 }
|
|
320
|
771
|
321 /* Output portably to stdout or its equivalent (i.e. may be a console
|
|
322 window under MS Windows). Works like stderr_out(). */
|
442
|
323
|
771
|
324 void
|
867
|
325 stdout_out (const CIbyte *fmt, ...)
|
442
|
326 {
|
|
327 va_list args;
|
|
328 va_start (args, fmt);
|
1346
|
329 write_string_to_external_output_va (fmt, args, EXT_PRINT_STDOUT);
|
|
330 va_end (args);
|
|
331 }
|
|
332
|
|
333 /* Output portably to print destination as specified by DEST. */
|
|
334
|
|
335 void
|
|
336 external_out (int dest, const CIbyte *fmt, ...)
|
|
337 {
|
|
338 va_list args;
|
|
339 va_start (args, fmt);
|
|
340 write_string_to_external_output_va (fmt, args, dest);
|
442
|
341 va_end (args);
|
771
|
342 }
|
|
343
|
|
344 /* Output portably to stderr or its equivalent (i.e. may be a console
|
|
345 window under MS Windows), as well as alternate-debugging-output and
|
|
346 (under MS Windows) the C debugging output, i.e. OutputDebugString().
|
|
347 Works like stderr_out(). */
|
|
348
|
|
349 void
|
867
|
350 debug_out (const CIbyte *fmt, ...)
|
771
|
351 {
|
|
352 va_list args;
|
|
353 va_start (args, fmt);
|
1346
|
354 write_string_to_external_output_va (fmt, args, EXT_PRINT_ALL);
|
771
|
355 va_end (args);
|
442
|
356 }
|
|
357
|
|
358 DOESNT_RETURN
|
867
|
359 fatal (const CIbyte *fmt, ...)
|
442
|
360 {
|
|
361 va_list args;
|
|
362 va_start (args, fmt);
|
|
363
|
771
|
364 stderr_out ("\nXEmacs: fatal error: ");
|
1346
|
365 write_string_to_external_output_va (fmt, args, EXT_PRINT_STDERR);
|
442
|
366 stderr_out ("\n");
|
|
367
|
|
368 va_end (args);
|
|
369 exit (1);
|
|
370 }
|
|
371
|
428
|
372 /* Write a string to the output location specified in FUNCTION.
|
|
373 Arguments NONRELOC, RELOC, OFFSET, and LEN are as in
|
771
|
374 buffer_insert_string_1() in insdel.c.
|
|
375
|
|
376 FUNCTION is one of
|
|
377
|
|
378 -- an lstream
|
|
379 -- a buffer (insert at point and advance point)
|
|
380 -- a marker (insert at marker and advance marker)
|
|
381 -- a frame (append to echo area; clear echo area first if
|
|
382 `print-message-label' has changed since the last time)
|
|
383 -- t or nil (send to stdout)
|
|
384 -- a Lisp function of one argument (call to get data output)
|
|
385
|
|
386 Use Qexternal_debugging_output to get output to stderr.
|
|
387 */
|
428
|
388
|
|
389 static void
|
867
|
390 output_string (Lisp_Object function, const Ibyte *nonreloc,
|
428
|
391 Lisp_Object reloc, Bytecount offset, Bytecount len)
|
|
392 {
|
|
393 /* This function can GC */
|
|
394 Charcount cclen;
|
|
395 /* We change the value of nonreloc (fetching it from reloc as
|
|
396 necessary), but we don't want to pass this changed value on to
|
|
397 other functions that take both a nonreloc and a reloc, or things
|
|
398 may get confused and an assertion failure in
|
|
399 fixup_internal_substring() may get triggered. */
|
867
|
400 const Ibyte *newnonreloc = nonreloc;
|
428
|
401 struct gcpro gcpro1, gcpro2;
|
|
402
|
|
403 /* Emacs won't print while GCing, but an external debugger might */
|
771
|
404 #ifdef NO_PRINT_DURING_GC
|
428
|
405 if (gc_in_progress) return;
|
771
|
406 #endif
|
428
|
407
|
|
408 /* Perhaps not necessary but probably safer. */
|
|
409 GCPRO2 (function, reloc);
|
|
410
|
|
411 fixup_internal_substring (newnonreloc, reloc, offset, &len);
|
|
412
|
|
413 if (STRINGP (reloc))
|
771
|
414 {
|
793
|
415 cclen = string_offset_byte_to_char_len (reloc, offset, len);
|
771
|
416 newnonreloc = XSTRING_DATA (reloc);
|
|
417 }
|
|
418 else
|
|
419 cclen = bytecount_to_charcount (newnonreloc + offset, len);
|
428
|
420
|
|
421 if (LSTREAMP (function))
|
|
422 {
|
|
423 if (STRINGP (reloc))
|
|
424 {
|
|
425 /* Protect against Lstream_write() causing a GC and
|
|
426 relocating the string. For small strings, we do it by
|
|
427 alloc'ing the string and using a copy; for large strings,
|
|
428 we inhibit GC. */
|
|
429 if (len < 65536)
|
|
430 {
|
2367
|
431 Ibyte *copied = alloca_ibytes (len);
|
428
|
432 memcpy (copied, newnonreloc + offset, len);
|
|
433 Lstream_write (XLSTREAM (function), copied, len);
|
|
434 }
|
1957
|
435 else if (gc_currently_forbidden)
|
|
436 {
|
|
437 /* Avoid calling begin_gc_forbidden, which conses. We can reach
|
|
438 this point from the cons debug code, which will get us into
|
|
439 an infinite loop if we cons again. */
|
|
440 Lstream_write (XLSTREAM (function), newnonreloc + offset, len);
|
|
441 }
|
428
|
442 else
|
|
443 {
|
771
|
444 int speccount = begin_gc_forbidden ();
|
428
|
445 Lstream_write (XLSTREAM (function), newnonreloc + offset, len);
|
771
|
446 unbind_to (speccount);
|
428
|
447 }
|
|
448 }
|
|
449 else
|
|
450 Lstream_write (XLSTREAM (function), newnonreloc + offset, len);
|
|
451
|
|
452 if (print_unbuffered)
|
|
453 Lstream_flush (XLSTREAM (function));
|
|
454 }
|
|
455 else if (BUFFERP (function))
|
|
456 {
|
|
457 CHECK_LIVE_BUFFER (function);
|
|
458 buffer_insert_string (XBUFFER (function), nonreloc, reloc, offset, len);
|
|
459 }
|
|
460 else if (MARKERP (function))
|
|
461 {
|
|
462 /* marker_position() will err if marker doesn't point anywhere. */
|
665
|
463 Charbpos spoint = marker_position (function);
|
428
|
464
|
|
465 buffer_insert_string_1 (XMARKER (function)->buffer,
|
|
466 spoint, nonreloc, reloc, offset, len,
|
|
467 0);
|
|
468 Fset_marker (function, make_int (spoint + cclen),
|
|
469 Fmarker_buffer (function));
|
|
470 }
|
|
471 else if (FRAMEP (function))
|
|
472 {
|
|
473 /* This gets used by functions not invoking print_prepare(),
|
|
474 such as Fwrite_char, Fterpri, etc.. */
|
|
475 struct frame *f = XFRAME (function);
|
|
476 CHECK_LIVE_FRAME (function);
|
|
477
|
|
478 if (!EQ (Vprint_message_label, echo_area_status (f)))
|
|
479 clear_echo_area_from_print (f, Qnil, 1);
|
|
480 echo_area_append (f, nonreloc, reloc, offset, len, Vprint_message_label);
|
|
481 }
|
|
482 else if (EQ (function, Qt) || EQ (function, Qnil))
|
|
483 {
|
771
|
484 write_string_to_stdio_stream (stdout, 0, newnonreloc + offset, len,
|
|
485 print_unbuffered);
|
|
486 }
|
|
487 else if (EQ (function, Qexternal_debugging_output))
|
|
488 {
|
|
489 /* This is not strictly necessary, and somewhat of a hack, but it
|
|
490 avoids having each character passed separately to
|
|
491 `external-debugging-output'. #### Why do we pass each character
|
|
492 separately, anyway?
|
|
493 */
|
|
494 write_string_to_stdio_stream (stderr, 0, newnonreloc + offset, len,
|
|
495 print_unbuffered);
|
428
|
496 }
|
|
497 else
|
|
498 {
|
771
|
499 Charcount ccoff;
|
428
|
500 Charcount iii;
|
|
501
|
771
|
502 if (STRINGP (reloc))
|
793
|
503 ccoff = string_index_byte_to_char (reloc, offset);
|
771
|
504 else
|
|
505 ccoff = bytecount_to_charcount (newnonreloc, offset);
|
|
506
|
|
507 if (STRINGP (reloc))
|
428
|
508 {
|
771
|
509 for (iii = ccoff; iii < cclen + ccoff; iii++)
|
|
510 {
|
867
|
511 call1 (function, make_char (string_ichar (reloc, iii)));
|
771
|
512 if (STRINGP (reloc))
|
|
513 newnonreloc = XSTRING_DATA (reloc);
|
|
514 }
|
|
515 }
|
|
516 else
|
|
517 {
|
|
518 for (iii = ccoff; iii < cclen + ccoff; iii++)
|
|
519 {
|
|
520 call1 (function,
|
867
|
521 make_char (itext_ichar_n (newnonreloc, iii)));
|
771
|
522 }
|
428
|
523 }
|
|
524 }
|
|
525
|
|
526 UNGCPRO;
|
|
527 }
|
|
528
|
|
529 #define RESET_PRINT_GENSYM do { \
|
|
530 if (!CONSP (Vprint_gensym)) \
|
|
531 Vprint_gensym_alist = Qnil; \
|
|
532 } while (0)
|
|
533
|
1261
|
534 Lisp_Object
|
428
|
535 canonicalize_printcharfun (Lisp_Object printcharfun)
|
|
536 {
|
|
537 if (NILP (printcharfun))
|
|
538 printcharfun = Vstandard_output;
|
|
539
|
1261
|
540 if (!noninteractive && (EQ (printcharfun, Qt) || NILP (printcharfun)))
|
428
|
541 printcharfun = Fselected_frame (Qnil); /* print to minibuffer */
|
|
542
|
|
543 return printcharfun;
|
|
544 }
|
|
545
|
|
546 static Lisp_Object
|
|
547 print_prepare (Lisp_Object printcharfun, Lisp_Object *frame_kludge)
|
|
548 {
|
|
549 /* Emacs won't print while GCing, but an external debugger might */
|
771
|
550 #ifdef NO_PRINT_DURING_GC
|
428
|
551 if (gc_in_progress)
|
|
552 return Qnil;
|
771
|
553 #endif
|
|
554
|
428
|
555 RESET_PRINT_GENSYM;
|
|
556
|
|
557 printcharfun = canonicalize_printcharfun (printcharfun);
|
|
558
|
|
559 /* Here we could safely return the canonicalized PRINTCHARFUN.
|
|
560 However, if PRINTCHARFUN is a frame, printing of complex
|
|
561 structures becomes very expensive, because `append-message'
|
|
562 (called by echo_area_append) gets called as many times as
|
|
563 output_string() is called (and that's a *lot*). append-message
|
|
564 tries to keep top of the message-stack in sync with the contents
|
|
565 of " *Echo Area" buffer, consing a new string for each component
|
|
566 of the printed structure. For instance, if you print (a a),
|
|
567 append-message will cons up the following strings:
|
|
568
|
|
569 "("
|
|
570 "(a"
|
|
571 "(a "
|
|
572 "(a a"
|
|
573 "(a a)"
|
|
574
|
|
575 and will use only the last one. With larger objects, this turns
|
|
576 into an O(n^2) consing frenzy that locks up XEmacs in incessant
|
|
577 garbage collection.
|
|
578
|
|
579 We prevent this by creating a resizing_buffer stream and letting
|
|
580 the printer write into it. print_finish() will notice this
|
|
581 stream, and invoke echo_area_append() with the stream's buffer,
|
|
582 only once. */
|
|
583 if (FRAMEP (printcharfun))
|
|
584 {
|
|
585 CHECK_LIVE_FRAME (printcharfun);
|
|
586 *frame_kludge = printcharfun;
|
|
587 printcharfun = make_resizing_buffer_output_stream ();
|
|
588 }
|
|
589
|
|
590 return printcharfun;
|
|
591 }
|
|
592
|
|
593 static void
|
|
594 print_finish (Lisp_Object stream, Lisp_Object frame_kludge)
|
|
595 {
|
|
596 /* Emacs won't print while GCing, but an external debugger might */
|
771
|
597 #ifdef NO_PRINT_DURING_GC
|
428
|
598 if (gc_in_progress)
|
|
599 return;
|
771
|
600 #endif
|
|
601
|
428
|
602 RESET_PRINT_GENSYM;
|
|
603
|
|
604 /* See the comment in print_prepare(). */
|
|
605 if (FRAMEP (frame_kludge))
|
|
606 {
|
|
607 struct frame *f = XFRAME (frame_kludge);
|
|
608 Lstream *str = XLSTREAM (stream);
|
|
609 CHECK_LIVE_FRAME (frame_kludge);
|
|
610
|
|
611 Lstream_flush (str);
|
|
612 if (!EQ (Vprint_message_label, echo_area_status (f)))
|
|
613 clear_echo_area_from_print (f, Qnil, 1);
|
|
614 echo_area_append (f, resizing_buffer_stream_ptr (str),
|
|
615 Qnil, 0, Lstream_byte_count (str),
|
|
616 Vprint_message_label);
|
|
617 Lstream_delete (str);
|
|
618 }
|
|
619 }
|
|
620
|
|
621
|
771
|
622 /* Write internal-format data to STREAM. See output_string() for
|
|
623 interpretation of STREAM.
|
|
624
|
|
625 NOTE: Do not call this with the data of a Lisp_String, as
|
428
|
626 printcharfun might cause a GC, which might cause the string's data
|
|
627 to be relocated. To princ a Lisp string, use:
|
|
628
|
|
629 print_internal (string, printcharfun, 0);
|
|
630
|
|
631 Also note that STREAM should be the result of
|
|
632 canonicalize_printcharfun() (i.e. Qnil means stdout, not
|
|
633 Vstandard_output, etc.) */
|
|
634 void
|
867
|
635 write_string_1 (Lisp_Object stream, const Ibyte *str, Bytecount size)
|
428
|
636 {
|
|
637 /* This function can GC */
|
800
|
638 #ifdef ERROR_CHECK_TEXT
|
428
|
639 assert (size >= 0);
|
|
640 #endif
|
|
641 output_string (stream, str, Qnil, 0, size);
|
|
642 }
|
|
643
|
|
644 void
|
867
|
645 write_string (Lisp_Object stream, const Ibyte *str)
|
771
|
646 {
|
|
647 /* This function can GC */
|
826
|
648 write_string_1 (stream, str, qxestrlen (str));
|
771
|
649 }
|
|
650
|
|
651 void
|
867
|
652 write_c_string (Lisp_Object stream, const CIbyte *str)
|
428
|
653 {
|
|
654 /* This function can GC */
|
867
|
655 write_string_1 (stream, (const Ibyte *) str, strlen (str));
|
428
|
656 }
|
|
657
|
793
|
658 void
|
826
|
659 write_eistring (Lisp_Object stream, const Eistring *ei)
|
793
|
660 {
|
826
|
661 write_string_1 (stream, eidata (ei), eilen (ei));
|
793
|
662 }
|
|
663
|
771
|
664 /* Write a printf-style string to STREAM; see output_string(). */
|
|
665
|
|
666 void
|
867
|
667 write_fmt_string (Lisp_Object stream, const CIbyte *fmt, ...)
|
771
|
668 {
|
|
669 va_list va;
|
867
|
670 Ibyte *str;
|
771
|
671 Bytecount len;
|
|
672 int count;
|
|
673
|
|
674 va_start (va, fmt);
|
|
675 str = emacs_vsprintf_malloc (fmt, va, &len);
|
|
676 va_end (va);
|
|
677 count = record_unwind_protect_freeing (str);
|
826
|
678 write_string_1 (stream, str, len);
|
771
|
679 unbind_to (count);
|
|
680 }
|
|
681
|
|
682 /* Write a printf-style string to STREAM, where the arguments are
|
|
683 Lisp objects and not C strings or integers; see output_string().
|
|
684
|
|
685 #### It shouldn't be necessary to specify the number of arguments.
|
|
686 This would require some rewriting of the doprnt() functions, though. */
|
|
687
|
|
688 void
|
867
|
689 write_fmt_string_lisp (Lisp_Object stream, const CIbyte *fmt, int nargs, ...)
|
771
|
690 {
|
|
691 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
|
|
692 va_list va;
|
|
693 int i;
|
867
|
694 Ibyte *str;
|
771
|
695 Bytecount len;
|
|
696 int count;
|
|
697
|
|
698 va_start (va, nargs);
|
|
699 for (i = 0; i < nargs; i++)
|
|
700 args[i] = va_arg (va, Lisp_Object);
|
|
701 va_end (va);
|
|
702 str = emacs_vsprintf_malloc_lisp (fmt, Qnil, nargs, args, &len);
|
|
703 count = record_unwind_protect_freeing (str);
|
826
|
704 write_string_1 (stream, str, len);
|
771
|
705 unbind_to (count);
|
|
706 }
|
|
707
|
|
708 void
|
867
|
709 stderr_out_lisp (const CIbyte *fmt, int nargs, ...)
|
771
|
710 {
|
|
711 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
|
|
712 va_list va;
|
|
713 int i;
|
867
|
714 Ibyte *str;
|
771
|
715 Bytecount len;
|
|
716 int count;
|
|
717
|
|
718 va_start (va, nargs);
|
|
719 for (i = 0; i < nargs; i++)
|
|
720 args[i] = va_arg (va, Lisp_Object);
|
|
721 va_end (va);
|
|
722 str = emacs_vsprintf_malloc_lisp (fmt, Qnil, nargs, args, &len);
|
|
723 count = record_unwind_protect_freeing (str);
|
826
|
724 write_string_1 (Qexternal_debugging_output, str, len);
|
771
|
725 unbind_to (count);
|
|
726 }
|
|
727
|
428
|
728
|
|
729 DEFUN ("write-char", Fwrite_char, 1, 2, 0, /*
|
444
|
730 Output character CHARACTER to stream STREAM.
|
428
|
731 STREAM defaults to the value of `standard-output' (which see).
|
|
732 */
|
444
|
733 (character, stream))
|
428
|
734 {
|
|
735 /* This function can GC */
|
867
|
736 Ibyte str[MAX_ICHAR_LEN];
|
428
|
737 Bytecount len;
|
|
738
|
444
|
739 CHECK_CHAR_COERCE_INT (character);
|
867
|
740 len = set_itext_ichar (str, XCHAR (character));
|
428
|
741 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, len);
|
444
|
742 return character;
|
428
|
743 }
|
|
744
|
|
745 void
|
|
746 temp_output_buffer_setup (Lisp_Object bufname)
|
|
747 {
|
|
748 /* This function can GC */
|
|
749 struct buffer *old = current_buffer;
|
|
750 Lisp_Object buf;
|
|
751
|
|
752 #ifdef I18N3
|
|
753 /* #### This function should accept a Lisp_Object instead of a char *,
|
|
754 so that proper translation on the buffer name can occur. */
|
|
755 #endif
|
|
756
|
|
757 Fset_buffer (Fget_buffer_create (bufname));
|
|
758
|
|
759 current_buffer->read_only = Qnil;
|
|
760 Ferase_buffer (Qnil);
|
|
761
|
793
|
762 buf = wrap_buffer (current_buffer);
|
428
|
763 specbind (Qstandard_output, buf);
|
|
764
|
|
765 set_buffer_internal (old);
|
|
766 }
|
|
767
|
|
768 Lisp_Object
|
|
769 internal_with_output_to_temp_buffer (Lisp_Object bufname,
|
|
770 Lisp_Object (*function) (Lisp_Object arg),
|
|
771 Lisp_Object arg,
|
|
772 Lisp_Object same_frame)
|
|
773 {
|
|
774 int speccount = specpdl_depth ();
|
|
775 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
776 Lisp_Object buf = Qnil;
|
|
777
|
|
778 GCPRO3 (buf, arg, same_frame);
|
|
779
|
|
780 temp_output_buffer_setup (bufname);
|
|
781 buf = Vstandard_output;
|
|
782
|
|
783 arg = (*function) (arg);
|
|
784
|
|
785 temp_output_buffer_show (buf, same_frame);
|
|
786 UNGCPRO;
|
|
787
|
771
|
788 return unbind_to_1 (speccount, arg);
|
428
|
789 }
|
|
790
|
|
791 DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, 1, UNEVALLED, 0, /*
|
|
792 Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.
|
|
793 The buffer is cleared out initially, and marked as unmodified when done.
|
|
794 All output done by BODY is inserted in that buffer by default.
|
|
795 The buffer is displayed in another window, but not selected.
|
|
796 The value of the last form in BODY is returned.
|
|
797 If BODY does not finish normally, the buffer BUFNAME is not displayed.
|
|
798
|
|
799 If variable `temp-buffer-show-function' is non-nil, call it at the end
|
|
800 to get the buffer displayed. It gets one argument, the buffer to display.
|
|
801 */
|
|
802 (args))
|
|
803 {
|
|
804 /* This function can GC */
|
|
805 Lisp_Object name = Qnil;
|
|
806 int speccount = specpdl_depth ();
|
|
807 struct gcpro gcpro1, gcpro2;
|
|
808 Lisp_Object val = Qnil;
|
|
809
|
|
810 #ifdef I18N3
|
|
811 /* #### should set the buffer to be translating. See print_internal(). */
|
|
812 #endif
|
|
813
|
|
814 GCPRO2 (name, val);
|
|
815 name = Feval (XCAR (args));
|
|
816
|
|
817 CHECK_STRING (name);
|
|
818
|
|
819 temp_output_buffer_setup (name);
|
|
820 UNGCPRO;
|
|
821
|
|
822 val = Fprogn (XCDR (args));
|
|
823
|
|
824 temp_output_buffer_show (Vstandard_output, Qnil);
|
|
825
|
771
|
826 return unbind_to_1 (speccount, val);
|
428
|
827 }
|
|
828
|
|
829 DEFUN ("terpri", Fterpri, 0, 1, 0, /*
|
|
830 Output a newline to STREAM.
|
|
831 If STREAM is omitted or nil, the value of `standard-output' is used.
|
|
832 */
|
|
833 (stream))
|
|
834 {
|
|
835 /* This function can GC */
|
826
|
836 write_c_string (canonicalize_printcharfun (stream), "\n");
|
428
|
837 return Qt;
|
|
838 }
|
|
839
|
|
840 DEFUN ("prin1", Fprin1, 1, 2, 0, /*
|
|
841 Output the printed representation of OBJECT, any Lisp object.
|
|
842 Quoting characters are printed when needed to make output that `read'
|
|
843 can handle, whenever this is possible.
|
|
844 Output stream is STREAM, or value of `standard-output' (which see).
|
|
845 */
|
|
846 (object, stream))
|
|
847 {
|
|
848 /* This function can GC */
|
|
849 Lisp_Object frame = Qnil;
|
|
850 struct gcpro gcpro1, gcpro2;
|
|
851 GCPRO2 (object, stream);
|
|
852
|
|
853 stream = print_prepare (stream, &frame);
|
|
854 print_internal (object, stream, 1);
|
|
855 print_finish (stream, frame);
|
|
856
|
|
857 UNGCPRO;
|
|
858 return object;
|
|
859 }
|
|
860
|
|
861 DEFUN ("prin1-to-string", Fprin1_to_string, 1, 2, 0, /*
|
|
862 Return a string containing the printed representation of OBJECT,
|
|
863 any Lisp object. Quoting characters are used when needed to make output
|
|
864 that `read' can handle, whenever this is possible, unless the optional
|
|
865 second argument NOESCAPE is non-nil.
|
|
866 */
|
|
867 (object, noescape))
|
|
868 {
|
|
869 /* This function can GC */
|
|
870 Lisp_Object result = Qnil;
|
|
871 Lisp_Object stream = make_resizing_buffer_output_stream ();
|
|
872 Lstream *str = XLSTREAM (stream);
|
|
873 /* gcpro OBJECT in case a caller forgot to do so */
|
|
874 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
875 GCPRO3 (object, stream, result);
|
|
876
|
|
877 RESET_PRINT_GENSYM;
|
|
878 print_internal (object, stream, NILP (noescape));
|
|
879 RESET_PRINT_GENSYM;
|
|
880 Lstream_flush (str);
|
|
881 UNGCPRO;
|
|
882 result = make_string (resizing_buffer_stream_ptr (str),
|
|
883 Lstream_byte_count (str));
|
|
884 Lstream_delete (str);
|
|
885 return result;
|
|
886 }
|
|
887
|
|
888 DEFUN ("princ", Fprinc, 1, 2, 0, /*
|
|
889 Output the printed representation of OBJECT, any Lisp object.
|
|
890 No quoting characters are used; no delimiters are printed around
|
|
891 the contents of strings.
|
444
|
892 Output stream is STREAM, or value of `standard-output' (which see).
|
428
|
893 */
|
|
894 (object, stream))
|
|
895 {
|
|
896 /* This function can GC */
|
|
897 Lisp_Object frame = Qnil;
|
|
898 struct gcpro gcpro1, gcpro2;
|
|
899
|
|
900 GCPRO2 (object, stream);
|
|
901 stream = print_prepare (stream, &frame);
|
|
902 print_internal (object, stream, 0);
|
|
903 print_finish (stream, frame);
|
|
904 UNGCPRO;
|
|
905 return object;
|
|
906 }
|
|
907
|
|
908 DEFUN ("print", Fprint, 1, 2, 0, /*
|
|
909 Output the printed representation of OBJECT, with newlines around it.
|
|
910 Quoting characters are printed when needed to make output that `read'
|
|
911 can handle, whenever this is possible.
|
|
912 Output stream is STREAM, or value of `standard-output' (which see).
|
|
913 */
|
|
914 (object, stream))
|
|
915 {
|
|
916 /* This function can GC */
|
|
917 Lisp_Object frame = Qnil;
|
|
918 struct gcpro gcpro1, gcpro2;
|
|
919
|
|
920 GCPRO2 (object, stream);
|
|
921 stream = print_prepare (stream, &frame);
|
826
|
922 write_c_string (stream, "\n");
|
428
|
923 print_internal (object, stream, 1);
|
826
|
924 write_c_string (stream, "\n");
|
428
|
925 print_finish (stream, frame);
|
|
926 UNGCPRO;
|
|
927 return object;
|
|
928 }
|
|
929
|
|
930 /* Print an error message for the error DATA to STREAM. This is a
|
|
931 complete implementation of `display-error', which used to be in
|
|
932 Lisp (see prim/cmdloop.el). It was ported to C so it can be used
|
|
933 efficiently by Ferror_message_string. Fdisplay_error and
|
|
934 Ferror_message_string are trivial wrappers around this function.
|
|
935
|
|
936 STREAM should be the result of canonicalize_printcharfun(). */
|
|
937 static void
|
|
938 print_error_message (Lisp_Object error_object, Lisp_Object stream)
|
|
939 {
|
|
940 /* This function can GC */
|
|
941 Lisp_Object type = Fcar_safe (error_object);
|
|
942 Lisp_Object method = Qnil;
|
|
943 Lisp_Object tail;
|
|
944
|
|
945 /* No need to GCPRO anything under the assumption that ERROR_OBJECT
|
|
946 is GCPRO'd. */
|
|
947
|
|
948 if (! (CONSP (error_object) && SYMBOLP (type)
|
|
949 && CONSP (Fget (type, Qerror_conditions, Qnil))))
|
|
950 goto error_throw;
|
|
951
|
|
952 tail = XCDR (error_object);
|
|
953 while (!NILP (tail))
|
|
954 {
|
|
955 if (CONSP (tail))
|
|
956 tail = XCDR (tail);
|
|
957 else
|
|
958 goto error_throw;
|
|
959 }
|
|
960 tail = Fget (type, Qerror_conditions, Qnil);
|
|
961 while (!NILP (tail))
|
|
962 {
|
|
963 if (!(CONSP (tail) && SYMBOLP (XCAR (tail))))
|
|
964 goto error_throw;
|
|
965 else if (!NILP (Fget (XCAR (tail), Qdisplay_error, Qnil)))
|
|
966 {
|
|
967 method = Fget (XCAR (tail), Qdisplay_error, Qnil);
|
|
968 goto error_throw;
|
|
969 }
|
|
970 else
|
|
971 tail = XCDR (tail);
|
|
972 }
|
|
973 /* Default method */
|
|
974 {
|
|
975 int first = 1;
|
|
976 int speccount = specpdl_depth ();
|
438
|
977 Lisp_Object frame = Qnil;
|
|
978 struct gcpro gcpro1;
|
|
979 GCPRO1 (stream);
|
428
|
980
|
|
981 specbind (Qprint_message_label, Qerror);
|
438
|
982 stream = print_prepare (stream, &frame);
|
|
983
|
428
|
984 tail = Fcdr (error_object);
|
|
985 if (EQ (type, Qerror))
|
|
986 {
|
|
987 print_internal (Fcar (tail), stream, 0);
|
|
988 tail = Fcdr (tail);
|
|
989 }
|
|
990 else
|
|
991 {
|
|
992 Lisp_Object errmsg = Fget (type, Qerror_message, Qnil);
|
|
993 if (NILP (errmsg))
|
|
994 print_internal (type, stream, 0);
|
|
995 else
|
|
996 print_internal (LISP_GETTEXT (errmsg), stream, 0);
|
|
997 }
|
|
998 while (!NILP (tail))
|
|
999 {
|
826
|
1000 write_c_string (stream, first ? ": " : ", ");
|
563
|
1001 /* Most errors have an explanatory string as their first argument,
|
|
1002 and it looks better not to put the quotes around it. */
|
|
1003 print_internal (Fcar (tail), stream,
|
|
1004 !(first && STRINGP (Fcar (tail))) ||
|
|
1005 !NILP (Fget (type, Qerror_lacks_explanatory_string,
|
|
1006 Qnil)));
|
428
|
1007 tail = Fcdr (tail);
|
|
1008 first = 0;
|
|
1009 }
|
438
|
1010 print_finish (stream, frame);
|
|
1011 UNGCPRO;
|
771
|
1012 unbind_to (speccount);
|
428
|
1013 return;
|
|
1014 /* not reached */
|
|
1015 }
|
|
1016
|
|
1017 error_throw:
|
|
1018 if (NILP (method))
|
|
1019 {
|
826
|
1020 write_c_string (stream, GETTEXT ("Peculiar error "));
|
428
|
1021 print_internal (error_object, stream, 1);
|
|
1022 return;
|
|
1023 }
|
|
1024 else
|
|
1025 {
|
|
1026 call2 (method, error_object, stream);
|
|
1027 }
|
|
1028 }
|
|
1029
|
|
1030 DEFUN ("error-message-string", Ferror_message_string, 1, 1, 0, /*
|
|
1031 Convert ERROR-OBJECT to an error message, and return it.
|
|
1032
|
|
1033 The format of ERROR-OBJECT should be (ERROR-SYMBOL . DATA). The
|
|
1034 message is equivalent to the one that would be issued by
|
|
1035 `display-error' with the same argument.
|
|
1036 */
|
|
1037 (error_object))
|
|
1038 {
|
|
1039 /* This function can GC */
|
|
1040 Lisp_Object result = Qnil;
|
|
1041 Lisp_Object stream = make_resizing_buffer_output_stream ();
|
|
1042 struct gcpro gcpro1;
|
|
1043 GCPRO1 (stream);
|
|
1044
|
|
1045 print_error_message (error_object, stream);
|
|
1046 Lstream_flush (XLSTREAM (stream));
|
|
1047 result = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
|
|
1048 Lstream_byte_count (XLSTREAM (stream)));
|
|
1049 Lstream_delete (XLSTREAM (stream));
|
|
1050
|
|
1051 UNGCPRO;
|
|
1052 return result;
|
|
1053 }
|
|
1054
|
|
1055 DEFUN ("display-error", Fdisplay_error, 2, 2, 0, /*
|
|
1056 Display ERROR-OBJECT on STREAM in a user-friendly way.
|
|
1057 */
|
|
1058 (error_object, stream))
|
|
1059 {
|
|
1060 /* This function can GC */
|
|
1061 print_error_message (error_object, canonicalize_printcharfun (stream));
|
|
1062 return Qnil;
|
|
1063 }
|
|
1064
|
|
1065
|
|
1066 Lisp_Object Vfloat_output_format;
|
|
1067
|
|
1068 /*
|
|
1069 * This buffer should be at least as large as the max string size of the
|
440
|
1070 * largest float, printed in the biggest notation. This is undoubtedly
|
428
|
1071 * 20d float_output_format, with the negative of the C-constant "HUGE"
|
|
1072 * from <math.h>.
|
|
1073 *
|
|
1074 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
|
|
1075 *
|
|
1076 * I assume that IEEE-754 format numbers can take 329 bytes for the worst
|
|
1077 * case of -1e307 in 20d float_output_format. What is one to do (short of
|
|
1078 * re-writing _doprnt to be more sane)?
|
|
1079 * -wsr
|
|
1080 */
|
|
1081 void
|
|
1082 float_to_string (char *buf, double data)
|
|
1083 {
|
867
|
1084 Ibyte *cp, c;
|
428
|
1085 int width;
|
|
1086
|
|
1087 if (NILP (Vfloat_output_format)
|
|
1088 || !STRINGP (Vfloat_output_format))
|
|
1089 lose:
|
|
1090 sprintf (buf, "%.16g", data);
|
|
1091 else /* oink oink */
|
|
1092 {
|
|
1093 /* Check that the spec we have is fully valid.
|
|
1094 This means not only valid for printf,
|
|
1095 but meant for floats, and reasonable. */
|
|
1096 cp = XSTRING_DATA (Vfloat_output_format);
|
|
1097
|
|
1098 if (cp[0] != '%')
|
|
1099 goto lose;
|
|
1100 if (cp[1] != '.')
|
|
1101 goto lose;
|
|
1102
|
|
1103 cp += 2;
|
|
1104 for (width = 0; (c = *cp, isdigit (c)); cp++)
|
|
1105 {
|
|
1106 width *= 10;
|
|
1107 width += c - '0';
|
|
1108 }
|
|
1109
|
|
1110 if (*cp != 'e' && *cp != 'f' && *cp != 'g' && *cp != 'E' && *cp != 'G')
|
|
1111 goto lose;
|
|
1112
|
|
1113 if (width < (int) (*cp != 'e' && *cp != 'E') || width > DBL_DIG)
|
|
1114 goto lose;
|
|
1115
|
|
1116 if (cp[1] != 0)
|
|
1117 goto lose;
|
|
1118
|
|
1119 sprintf (buf, (char *) XSTRING_DATA (Vfloat_output_format),
|
|
1120 data);
|
|
1121 }
|
|
1122
|
|
1123 /* added by jwz: don't allow "1.0" to print as "1"; that destroys
|
|
1124 the read-equivalence of lisp objects. (* x 1) and (* x 1.0) do
|
|
1125 not do the same thing, so it's important that the printed
|
|
1126 representation of that form not be corrupted by the printer.
|
|
1127 */
|
|
1128 {
|
867
|
1129 Ibyte *s = (Ibyte *) buf; /* don't use signed chars here!
|
428
|
1130 isdigit() can't hack them! */
|
|
1131 if (*s == '-') s++;
|
|
1132 for (; *s; s++)
|
|
1133 /* if there's a non-digit, then there is a decimal point, or
|
|
1134 it's in exponential notation, both of which are ok. */
|
|
1135 if (!isdigit (*s))
|
|
1136 goto DONE_LABEL;
|
|
1137 /* otherwise, we need to hack it. */
|
|
1138 *s++ = '.';
|
|
1139 *s++ = '0';
|
|
1140 *s = 0;
|
|
1141 }
|
|
1142 DONE_LABEL:
|
|
1143
|
|
1144 /* Some machines print "0.4" as ".4". I don't like that. */
|
|
1145 if (buf [0] == '.' || (buf [0] == '-' && buf [1] == '.'))
|
|
1146 {
|
|
1147 int i;
|
|
1148 for (i = strlen (buf) + 1; i >= 0; i--)
|
|
1149 buf [i+1] = buf [i];
|
|
1150 buf [(buf [0] == '-' ? 1 : 0)] = '0';
|
|
1151 }
|
|
1152 }
|
|
1153
|
2500
|
1154 #define ONE_DIGIT(figure) *p++ = (char) (n / (figure) + '0')
|
577
|
1155 #define ONE_DIGIT_ADVANCE(figure) (ONE_DIGIT (figure), n %= (figure))
|
|
1156
|
|
1157 #define DIGITS_1(figure) ONE_DIGIT (figure)
|
|
1158 #define DIGITS_2(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_1 ((figure) / 10)
|
|
1159 #define DIGITS_3(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_2 ((figure) / 10)
|
|
1160 #define DIGITS_4(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_3 ((figure) / 10)
|
|
1161 #define DIGITS_5(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_4 ((figure) / 10)
|
|
1162 #define DIGITS_6(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_5 ((figure) / 10)
|
|
1163 #define DIGITS_7(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_6 ((figure) / 10)
|
|
1164 #define DIGITS_8(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_7 ((figure) / 10)
|
|
1165 #define DIGITS_9(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_8 ((figure) / 10)
|
|
1166 #define DIGITS_10(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_9 ((figure) / 10)
|
|
1167
|
|
1168 /* DIGITS_<11-20> are only used on machines with 64-bit longs. */
|
428
|
1169
|
577
|
1170 #define DIGITS_11(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_10 ((figure) / 10)
|
|
1171 #define DIGITS_12(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_11 ((figure) / 10)
|
|
1172 #define DIGITS_13(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_12 ((figure) / 10)
|
|
1173 #define DIGITS_14(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_13 ((figure) / 10)
|
|
1174 #define DIGITS_15(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_14 ((figure) / 10)
|
|
1175 #define DIGITS_16(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_15 ((figure) / 10)
|
|
1176 #define DIGITS_17(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_16 ((figure) / 10)
|
|
1177 #define DIGITS_18(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_17 ((figure) / 10)
|
|
1178 #define DIGITS_19(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_18 ((figure) / 10)
|
|
1179
|
|
1180 /* Print NUMBER to BUFFER in base 10. This is completely equivalent
|
|
1181 to `sprintf(buffer, "%ld", number)', only much faster.
|
|
1182
|
|
1183 The speedup may make a difference in programs that frequently
|
|
1184 convert numbers to strings. Some implementations of sprintf,
|
|
1185 particularly the one in GNU libc, have been known to be extremely
|
|
1186 slow compared to this function.
|
|
1187
|
|
1188 BUFFER should accept as many bytes as you expect the number to take
|
|
1189 up. On machines with 64-bit longs the maximum needed size is 24
|
|
1190 bytes. That includes the worst-case digits, the optional `-' sign,
|
|
1191 and the trailing \0. */
|
|
1192
|
|
1193 void
|
428
|
1194 long_to_string (char *buffer, long number)
|
|
1195 {
|
577
|
1196 char *p = buffer;
|
|
1197 long n = number;
|
|
1198
|
428
|
1199 #if (SIZEOF_LONG != 4) && (SIZEOF_LONG != 8)
|
577
|
1200 /* We are running in a strange or misconfigured environment. Let
|
|
1201 sprintf cope with it. */
|
|
1202 sprintf (buffer, "%ld", n);
|
|
1203 #else /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */
|
428
|
1204
|
577
|
1205 if (n < 0)
|
428
|
1206 {
|
|
1207 *p++ = '-';
|
577
|
1208 n = -n;
|
428
|
1209 }
|
|
1210
|
577
|
1211 if (n < 10) { DIGITS_1 (1); }
|
|
1212 else if (n < 100) { DIGITS_2 (10); }
|
|
1213 else if (n < 1000) { DIGITS_3 (100); }
|
|
1214 else if (n < 10000) { DIGITS_4 (1000); }
|
|
1215 else if (n < 100000) { DIGITS_5 (10000); }
|
|
1216 else if (n < 1000000) { DIGITS_6 (100000); }
|
|
1217 else if (n < 10000000) { DIGITS_7 (1000000); }
|
|
1218 else if (n < 100000000) { DIGITS_8 (10000000); }
|
|
1219 else if (n < 1000000000) { DIGITS_9 (100000000); }
|
|
1220 #if SIZEOF_LONG == 4
|
|
1221 /* ``if (1)'' serves only to preserve editor indentation. */
|
|
1222 else if (1) { DIGITS_10 (1000000000); }
|
|
1223 #else /* SIZEOF_LONG != 4 */
|
|
1224 else if (n < 10000000000L) { DIGITS_10 (1000000000L); }
|
|
1225 else if (n < 100000000000L) { DIGITS_11 (10000000000L); }
|
|
1226 else if (n < 1000000000000L) { DIGITS_12 (100000000000L); }
|
|
1227 else if (n < 10000000000000L) { DIGITS_13 (1000000000000L); }
|
|
1228 else if (n < 100000000000000L) { DIGITS_14 (10000000000000L); }
|
|
1229 else if (n < 1000000000000000L) { DIGITS_15 (100000000000000L); }
|
|
1230 else if (n < 10000000000000000L) { DIGITS_16 (1000000000000000L); }
|
|
1231 else if (n < 100000000000000000L) { DIGITS_17 (10000000000000000L); }
|
|
1232 else if (n < 1000000000000000000L) { DIGITS_18 (100000000000000000L); }
|
|
1233 else { DIGITS_19 (1000000000000000000L); }
|
|
1234 #endif /* SIZEOF_LONG != 4 */
|
|
1235
|
428
|
1236 *p = '\0';
|
|
1237 #endif /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */
|
|
1238 }
|
577
|
1239
|
|
1240 #undef ONE_DIGIT
|
|
1241 #undef ONE_DIGIT_ADVANCE
|
|
1242
|
|
1243 #undef DIGITS_1
|
|
1244 #undef DIGITS_2
|
|
1245 #undef DIGITS_3
|
|
1246 #undef DIGITS_4
|
|
1247 #undef DIGITS_5
|
|
1248 #undef DIGITS_6
|
|
1249 #undef DIGITS_7
|
|
1250 #undef DIGITS_8
|
|
1251 #undef DIGITS_9
|
|
1252 #undef DIGITS_10
|
|
1253 #undef DIGITS_11
|
|
1254 #undef DIGITS_12
|
|
1255 #undef DIGITS_13
|
|
1256 #undef DIGITS_14
|
|
1257 #undef DIGITS_15
|
|
1258 #undef DIGITS_16
|
|
1259 #undef DIGITS_17
|
|
1260 #undef DIGITS_18
|
|
1261 #undef DIGITS_19
|
428
|
1262
|
|
1263 static void
|
442
|
1264 print_vector_internal (const char *start, const char *end,
|
428
|
1265 Lisp_Object obj,
|
|
1266 Lisp_Object printcharfun, int escapeflag)
|
|
1267 {
|
|
1268 /* This function can GC */
|
|
1269 int i;
|
|
1270 int len = XVECTOR_LENGTH (obj);
|
|
1271 int last = len;
|
|
1272 struct gcpro gcpro1, gcpro2;
|
|
1273 GCPRO2 (obj, printcharfun);
|
|
1274
|
|
1275 if (INTP (Vprint_length))
|
|
1276 {
|
|
1277 int max = XINT (Vprint_length);
|
|
1278 if (max < len) last = max;
|
|
1279 }
|
|
1280
|
826
|
1281 write_c_string (printcharfun, start);
|
428
|
1282 for (i = 0; i < last; i++)
|
|
1283 {
|
|
1284 Lisp_Object elt = XVECTOR_DATA (obj)[i];
|
826
|
1285 if (i != 0) write_c_string (printcharfun, " ");
|
428
|
1286 print_internal (elt, printcharfun, escapeflag);
|
|
1287 }
|
|
1288 UNGCPRO;
|
|
1289 if (last != len)
|
826
|
1290 write_c_string (printcharfun, " ...");
|
|
1291 write_c_string (printcharfun, end);
|
428
|
1292 }
|
|
1293
|
|
1294 void
|
|
1295 print_cons (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1296 {
|
|
1297 /* This function can GC */
|
|
1298 struct gcpro gcpro1, gcpro2;
|
|
1299
|
|
1300 /* If print_readably is on, print (quote -foo-) as '-foo-
|
|
1301 (Yeah, this should really be what print-pretty does, but we
|
|
1302 don't have the rest of a pretty printer, and this actually
|
|
1303 has non-negligible impact on size/speed of .elc files.)
|
|
1304 */
|
|
1305 if (print_readably &&
|
|
1306 EQ (XCAR (obj), Qquote) &&
|
|
1307 CONSP (XCDR (obj)) &&
|
|
1308 NILP (XCDR (XCDR (obj))))
|
|
1309 {
|
|
1310 obj = XCAR (XCDR (obj));
|
|
1311 GCPRO2 (obj, printcharfun);
|
826
|
1312 write_c_string (printcharfun, "\'");
|
428
|
1313 UNGCPRO;
|
|
1314 print_internal (obj, printcharfun, escapeflag);
|
|
1315 return;
|
|
1316 }
|
|
1317
|
|
1318 GCPRO2 (obj, printcharfun);
|
826
|
1319 write_c_string (printcharfun, "(");
|
428
|
1320
|
|
1321 {
|
|
1322 int len;
|
|
1323 int max = INTP (Vprint_length) ? XINT (Vprint_length) : INT_MAX;
|
|
1324 Lisp_Object tortoise;
|
|
1325 /* Use tortoise/hare to make sure circular lists don't infloop */
|
|
1326
|
|
1327 for (tortoise = obj, len = 0;
|
|
1328 CONSP (obj);
|
|
1329 obj = XCDR (obj), len++)
|
|
1330 {
|
|
1331 if (len > 0)
|
826
|
1332 write_c_string (printcharfun, " ");
|
428
|
1333 if (EQ (obj, tortoise) && len > 0)
|
|
1334 {
|
|
1335 if (print_readably)
|
563
|
1336 printing_unreadable_object ("circular list");
|
428
|
1337 else
|
826
|
1338 write_c_string (printcharfun, "... <circular list>");
|
428
|
1339 break;
|
|
1340 }
|
|
1341 if (len & 1)
|
|
1342 tortoise = XCDR (tortoise);
|
|
1343 if (len > max)
|
|
1344 {
|
826
|
1345 write_c_string (printcharfun, "...");
|
428
|
1346 break;
|
|
1347 }
|
|
1348 print_internal (XCAR (obj), printcharfun, escapeflag);
|
|
1349 }
|
|
1350 }
|
|
1351 if (!LISTP (obj))
|
|
1352 {
|
826
|
1353 write_c_string (printcharfun, " . ");
|
428
|
1354 print_internal (obj, printcharfun, escapeflag);
|
|
1355 }
|
|
1356 UNGCPRO;
|
|
1357
|
826
|
1358 write_c_string (printcharfun, ")");
|
428
|
1359 return;
|
|
1360 }
|
|
1361
|
|
1362 void
|
|
1363 print_vector (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1364 {
|
|
1365 print_vector_internal ("[", "]", obj, printcharfun, escapeflag);
|
|
1366 }
|
|
1367
|
|
1368 void
|
|
1369 print_string (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1370 {
|
|
1371 /* We distinguish between Bytecounts and Charcounts, to make
|
|
1372 Vprint_string_length work correctly under Mule. */
|
826
|
1373 Charcount size = string_char_length (obj);
|
428
|
1374 Charcount max = size;
|
793
|
1375 Bytecount bcmax = XSTRING_LENGTH (obj);
|
428
|
1376 struct gcpro gcpro1, gcpro2;
|
|
1377 GCPRO2 (obj, printcharfun);
|
|
1378
|
|
1379 if (INTP (Vprint_string_length) &&
|
|
1380 XINT (Vprint_string_length) < max)
|
|
1381 {
|
|
1382 max = XINT (Vprint_string_length);
|
793
|
1383 bcmax = string_index_char_to_byte (obj, max);
|
428
|
1384 }
|
|
1385 if (max < 0)
|
|
1386 {
|
|
1387 max = 0;
|
|
1388 bcmax = 0;
|
|
1389 }
|
|
1390
|
|
1391 if (!escapeflag)
|
|
1392 {
|
|
1393 /* This deals with GC-relocation and Mule. */
|
|
1394 output_string (printcharfun, 0, obj, 0, bcmax);
|
|
1395 if (max < size)
|
826
|
1396 write_c_string (printcharfun, " ...");
|
428
|
1397 }
|
|
1398 else
|
|
1399 {
|
|
1400 Bytecount i, last = 0;
|
|
1401
|
826
|
1402 write_c_string (printcharfun, "\"");
|
428
|
1403 for (i = 0; i < bcmax; i++)
|
|
1404 {
|
867
|
1405 Ibyte ch = string_byte (obj, i);
|
428
|
1406 if (ch == '\"' || ch == '\\'
|
|
1407 || (ch == '\n' && print_escape_newlines))
|
|
1408 {
|
|
1409 if (i > last)
|
|
1410 {
|
|
1411 output_string (printcharfun, 0, obj, last,
|
|
1412 i - last);
|
|
1413 }
|
|
1414 if (ch == '\n')
|
|
1415 {
|
826
|
1416 write_c_string (printcharfun, "\\n");
|
428
|
1417 }
|
|
1418 else
|
|
1419 {
|
867
|
1420 Ibyte temp[2];
|
826
|
1421 write_c_string (printcharfun, "\\");
|
428
|
1422 /* This is correct for Mule because the
|
|
1423 character is either \ or " */
|
826
|
1424 temp[0] = string_byte (obj, i);
|
|
1425 temp[1] = '\0';
|
|
1426 write_string (printcharfun, temp);
|
428
|
1427 }
|
|
1428 last = i + 1;
|
|
1429 }
|
|
1430 }
|
|
1431 if (bcmax > last)
|
|
1432 {
|
|
1433 output_string (printcharfun, 0, obj, last,
|
|
1434 bcmax - last);
|
|
1435 }
|
|
1436 if (max < size)
|
826
|
1437 write_c_string (printcharfun, " ...");
|
|
1438 write_c_string (printcharfun, "\"");
|
428
|
1439 }
|
|
1440 UNGCPRO;
|
|
1441 }
|
|
1442
|
|
1443 static void
|
|
1444 default_object_printer (Lisp_Object obj, Lisp_Object printcharfun,
|
2286
|
1445 int UNUSED (escapeflag))
|
428
|
1446 {
|
|
1447 struct lcrecord_header *header =
|
|
1448 (struct lcrecord_header *) XPNTR (obj);
|
|
1449
|
|
1450 if (print_readably)
|
563
|
1451 printing_unreadable_object
|
|
1452 ("#<%s 0x%x>",
|
|
1453 LHEADER_IMPLEMENTATION (&header->lheader)->name,
|
|
1454 header->uid);
|
428
|
1455
|
800
|
1456 write_fmt_string (printcharfun, "#<%s 0x%x>",
|
|
1457 LHEADER_IMPLEMENTATION (&header->lheader)->name,
|
|
1458 header->uid);
|
428
|
1459 }
|
|
1460
|
|
1461 void
|
|
1462 internal_object_printer (Lisp_Object obj, Lisp_Object printcharfun,
|
2286
|
1463 int UNUSED (escapeflag))
|
428
|
1464 {
|
800
|
1465 write_fmt_string (printcharfun,
|
|
1466 "#<INTERNAL OBJECT (XEmacs bug?) (%s) 0x%lx>",
|
|
1467 XRECORD_LHEADER_IMPLEMENTATION (obj)->name,
|
|
1468 (unsigned long) XPNTR (obj));
|
428
|
1469 }
|
|
1470
|
1204
|
1471 enum printing_badness
|
|
1472 {
|
|
1473 BADNESS_INTEGER_OBJECT,
|
|
1474 BADNESS_POINTER_OBJECT,
|
|
1475 BADNESS_NO_TYPE
|
|
1476 };
|
|
1477
|
|
1478 static void
|
|
1479 printing_major_badness (Lisp_Object printcharfun,
|
2367
|
1480 Ascbyte *badness_string, int type, void *val,
|
1204
|
1481 enum printing_badness badness)
|
|
1482 {
|
|
1483 Ibyte buf[666];
|
|
1484
|
|
1485 switch (badness)
|
|
1486 {
|
|
1487 case BADNESS_INTEGER_OBJECT:
|
|
1488 qxesprintf (buf, "%s %d object %ld", badness_string, type,
|
|
1489 (EMACS_INT) val);
|
|
1490 break;
|
|
1491
|
|
1492 case BADNESS_POINTER_OBJECT:
|
|
1493 qxesprintf (buf, "%s %d object %p", badness_string, type, val);
|
|
1494 break;
|
|
1495
|
|
1496 case BADNESS_NO_TYPE:
|
|
1497 qxesprintf (buf, "%s object %p", badness_string, val);
|
|
1498 break;
|
|
1499 }
|
|
1500
|
|
1501 /* Don't abort or signal if called from debug_print() or already
|
|
1502 crashing */
|
2367
|
1503 if (!inhibit_non_essential_conversion_operations)
|
1204
|
1504 {
|
|
1505 #ifdef ERROR_CHECK_TYPES
|
2500
|
1506 ABORT ();
|
1204
|
1507 #else /* not ERROR_CHECK_TYPES */
|
|
1508 if (print_readably)
|
|
1509 signal_ferror (Qinternal_error, "printing %s", buf);
|
|
1510 #endif /* not ERROR_CHECK_TYPES */
|
|
1511 }
|
|
1512 write_fmt_string (printcharfun,
|
|
1513 "#<EMACS BUG: %s Save your buffers immediately and "
|
|
1514 "please report this bug>", buf);
|
|
1515 }
|
|
1516
|
428
|
1517 void
|
|
1518 print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1519 {
|
|
1520 /* This function can GC */
|
2001
|
1521 int specdepth = 0;
|
1204
|
1522 struct gcpro gcpro1, gcpro2;
|
428
|
1523
|
|
1524 QUIT;
|
|
1525
|
771
|
1526 #ifdef NO_PRINT_DURING_GC
|
428
|
1527 /* Emacs won't print while GCing, but an external debugger might */
|
|
1528 if (gc_in_progress) return;
|
771
|
1529 #endif
|
|
1530
|
1204
|
1531 /* Just to be safe ... */
|
|
1532 GCPRO2 (obj, printcharfun);
|
428
|
1533
|
|
1534 #ifdef I18N3
|
|
1535 /* #### Both input and output streams should have a flag associated
|
|
1536 with them indicating whether output to that stream, or strings
|
|
1537 read from the stream, get translated using Fgettext(). Such a
|
|
1538 stream is called a "translating stream". For the minibuffer and
|
|
1539 external-debugging-output this is always true on output, and
|
|
1540 with-output-to-temp-buffer sets the flag to true for the buffer
|
|
1541 it creates. This flag should also be user-settable. Perhaps it
|
|
1542 should be split up into two flags, one for input and one for
|
|
1543 output. */
|
|
1544 #endif
|
|
1545
|
|
1546 /* Detect circularities and truncate them.
|
|
1547 No need to offer any alternative--this is better than an error. */
|
|
1548 if (CONSP (obj) || VECTORP (obj) || COMPILED_FUNCTIONP (obj))
|
|
1549 {
|
|
1550 int i;
|
|
1551 for (i = 0; i < print_depth; i++)
|
|
1552 if (EQ (obj, being_printed[i]))
|
|
1553 {
|
603
|
1554 char buf[DECIMAL_PRINT_SIZE (long) + 1];
|
428
|
1555 *buf = '#';
|
|
1556 long_to_string (buf + 1, i);
|
826
|
1557 write_c_string (printcharfun, buf);
|
1204
|
1558 UNGCPRO;
|
428
|
1559 return;
|
|
1560 }
|
|
1561 }
|
|
1562
|
|
1563 being_printed[print_depth] = obj;
|
|
1564
|
1957
|
1565 /* Avoid calling internal_bind_int, which conses, when called from
|
|
1566 debug_prin1. In that case, we have bound print_depth to 0 anyway. */
|
2367
|
1567 if (!inhibit_non_essential_conversion_operations)
|
1957
|
1568 {
|
|
1569 specdepth = internal_bind_int (&print_depth, print_depth + 1);
|
|
1570
|
|
1571 if (print_depth > PRINT_CIRCLE)
|
|
1572 signal_error (Qstack_overflow, "Apparently circular structure being printed", Qunbound);
|
|
1573 }
|
428
|
1574
|
|
1575 switch (XTYPE (obj))
|
|
1576 {
|
|
1577 case Lisp_Type_Int_Even:
|
|
1578 case Lisp_Type_Int_Odd:
|
|
1579 {
|
603
|
1580 char buf[DECIMAL_PRINT_SIZE (EMACS_INT)];
|
428
|
1581 long_to_string (buf, XINT (obj));
|
826
|
1582 write_c_string (printcharfun, buf);
|
428
|
1583 break;
|
|
1584 }
|
|
1585
|
|
1586 case Lisp_Type_Char:
|
|
1587 {
|
|
1588 /* God intended that this be #\..., you know. */
|
|
1589 char buf[16];
|
867
|
1590 Ichar ch = XCHAR (obj);
|
428
|
1591 char *p = buf;
|
|
1592 *p++ = '?';
|
434
|
1593 if (ch < 32)
|
|
1594 {
|
|
1595 *p++ = '\\';
|
|
1596 switch (ch)
|
|
1597 {
|
|
1598 case '\t': *p++ = 't'; break;
|
|
1599 case '\n': *p++ = 'n'; break;
|
|
1600 case '\r': *p++ = 'r'; break;
|
|
1601 default:
|
|
1602 *p++ = '^';
|
|
1603 *p++ = ch + 64;
|
|
1604 if ((ch + 64) == '\\')
|
|
1605 *p++ = '\\';
|
|
1606 break;
|
|
1607 }
|
|
1608 }
|
|
1609 else if (ch < 127)
|
428
|
1610 {
|
434
|
1611 /* syntactically special characters should be escaped. */
|
|
1612 switch (ch)
|
|
1613 {
|
|
1614 case ' ':
|
|
1615 case '"':
|
|
1616 case '#':
|
|
1617 case '\'':
|
|
1618 case '(':
|
|
1619 case ')':
|
|
1620 case ',':
|
|
1621 case '.':
|
|
1622 case ';':
|
|
1623 case '?':
|
|
1624 case '[':
|
|
1625 case '\\':
|
|
1626 case ']':
|
|
1627 case '`':
|
|
1628 *p++ = '\\';
|
|
1629 }
|
|
1630 *p++ = ch;
|
428
|
1631 }
|
|
1632 else if (ch == 127)
|
434
|
1633 {
|
|
1634 *p++ = '\\', *p++ = '^', *p++ = '?';
|
|
1635 }
|
|
1636 else if (ch < 160)
|
428
|
1637 {
|
|
1638 *p++ = '\\', *p++ = '^';
|
867
|
1639 p += set_itext_ichar ((Ibyte *) p, ch + 64);
|
428
|
1640 }
|
|
1641 else
|
434
|
1642 {
|
867
|
1643 p += set_itext_ichar ((Ibyte *) p, ch);
|
434
|
1644 }
|
440
|
1645
|
867
|
1646 output_string (printcharfun, (Ibyte *) buf, Qnil, 0, p - buf);
|
434
|
1647
|
428
|
1648 break;
|
|
1649 }
|
|
1650
|
|
1651 case Lisp_Type_Record:
|
|
1652 {
|
|
1653 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
|
1204
|
1654
|
|
1655 /* Try to check for various sorts of bogus pointers if we're in a
|
|
1656 situation where it may be likely -- i.e. called from
|
|
1657 debug_print() or we're already crashing. In such cases,
|
|
1658 (further) crashing is counterproductive. */
|
428
|
1659
|
2367
|
1660 if (inhibit_non_essential_conversion_operations &&
|
1204
|
1661 !debug_can_access_memory (lheader, sizeof (*lheader)))
|
|
1662 {
|
|
1663 write_fmt_string (printcharfun, "#<EMACS BUG: BAD MEMORY %p>",
|
|
1664 lheader);
|
|
1665 break;
|
|
1666 }
|
|
1667
|
|
1668 if (CONSP (obj) || VECTORP (obj))
|
428
|
1669 {
|
|
1670 /* If deeper than spec'd depth, print placeholder. */
|
|
1671 if (INTP (Vprint_level)
|
|
1672 && print_depth > XINT (Vprint_level))
|
|
1673 {
|
826
|
1674 write_c_string (printcharfun, "...");
|
428
|
1675 break;
|
|
1676 }
|
|
1677 }
|
|
1678
|
1204
|
1679 if (lheader->type == lrecord_type_free)
|
|
1680 {
|
|
1681 printing_major_badness (printcharfun, "freed lrecord", 0,
|
|
1682 lheader, BADNESS_NO_TYPE);
|
|
1683 break;
|
|
1684 }
|
|
1685 else if (lheader->type == lrecord_type_undefined)
|
|
1686 {
|
|
1687 printing_major_badness (printcharfun, "lrecord_type_undefined", 0,
|
|
1688 lheader, BADNESS_NO_TYPE);
|
|
1689 break;
|
|
1690 }
|
|
1691 else if ((int) (lheader->type) >= lrecord_type_count)
|
|
1692 {
|
|
1693 printing_major_badness (printcharfun, "illegal lrecord type",
|
|
1694 (int) (lheader->type),
|
|
1695 lheader, BADNESS_POINTER_OBJECT);
|
|
1696 break;
|
|
1697 }
|
|
1698
|
|
1699 /* Further checks for bad memory in critical situations. We don't
|
|
1700 normally do these because they may be expensive or weird
|
|
1701 (e.g. under Unix we typically have to set a SIGSEGV handler and
|
|
1702 try to trigger a seg fault). */
|
|
1703
|
2367
|
1704 if (inhibit_non_essential_conversion_operations)
|
1204
|
1705 {
|
|
1706 if (!debug_can_access_memory
|
|
1707 (lheader, detagged_lisp_object_size (lheader)))
|
|
1708 {
|
|
1709 write_fmt_string (printcharfun,
|
|
1710 "#<EMACS BUG: type %s BAD MEMORY %p>",
|
|
1711 LHEADER_IMPLEMENTATION (lheader)->name,
|
|
1712 lheader);
|
|
1713 break;
|
|
1714 }
|
|
1715
|
|
1716 if (STRINGP (obj))
|
|
1717 {
|
|
1718 Lisp_String *l = (Lisp_String *) lheader;
|
|
1719 if (!debug_can_access_memory (l->data_, l->size_))
|
|
1720 {
|
|
1721 write_fmt_string
|
|
1722 (printcharfun,
|
|
1723 "#<EMACS BUG: %p (BAD STRING DATA %p)>",
|
|
1724 lheader, l->data_);
|
|
1725 break;
|
|
1726 }
|
|
1727 }
|
|
1728 }
|
|
1729
|
428
|
1730 if (LHEADER_IMPLEMENTATION (lheader)->printer)
|
|
1731 ((LHEADER_IMPLEMENTATION (lheader)->printer)
|
|
1732 (obj, printcharfun, escapeflag));
|
|
1733 else
|
|
1734 default_object_printer (obj, printcharfun, escapeflag);
|
|
1735 break;
|
|
1736 }
|
|
1737
|
|
1738 default:
|
|
1739 {
|
|
1740 /* We're in trouble if this happens! */
|
1204
|
1741 printing_major_badness (printcharfun, "illegal data type", XTYPE (obj),
|
|
1742 LISP_TO_VOID (obj), BADNESS_INTEGER_OBJECT);
|
428
|
1743 break;
|
|
1744 }
|
|
1745 }
|
|
1746
|
2367
|
1747 if (!inhibit_non_essential_conversion_operations)
|
1957
|
1748 unbind_to (specdepth);
|
1204
|
1749 UNGCPRO;
|
428
|
1750 }
|
|
1751
|
|
1752 void
|
2286
|
1753 print_float (Lisp_Object obj, Lisp_Object printcharfun,
|
|
1754 int UNUSED (escapeflag))
|
428
|
1755 {
|
|
1756 char pigbuf[350]; /* see comments in float_to_string */
|
|
1757
|
|
1758 float_to_string (pigbuf, XFLOAT_DATA (obj));
|
826
|
1759 write_c_string (printcharfun, pigbuf);
|
428
|
1760 }
|
|
1761
|
|
1762 void
|
|
1763 print_symbol (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1764 {
|
|
1765 /* This function can GC */
|
|
1766 /* #### Bug!! (intern "") isn't printed in some distinguished way */
|
|
1767 /* #### (the reader also loses on it) */
|
793
|
1768 Lisp_Object name = symbol_name (XSYMBOL (obj));
|
|
1769 Bytecount size = XSTRING_LENGTH (name);
|
428
|
1770 struct gcpro gcpro1, gcpro2;
|
|
1771
|
|
1772 if (!escapeflag)
|
|
1773 {
|
|
1774 /* This deals with GC-relocation */
|
793
|
1775 output_string (printcharfun, 0, name, 0, size);
|
428
|
1776 return;
|
|
1777 }
|
|
1778 GCPRO2 (obj, printcharfun);
|
|
1779
|
|
1780 /* If we print an uninterned symbol as part of a complex object and
|
|
1781 the flag print-gensym is non-nil, prefix it with #n= to read the
|
|
1782 object back with the #n# reader syntax later if needed. */
|
|
1783 if (!NILP (Vprint_gensym)
|
442
|
1784 /* #### Test whether this produces a noticeable slow-down for
|
428
|
1785 printing when print-gensym is non-nil. */
|
|
1786 && !EQ (obj, oblookup (Vobarray,
|
793
|
1787 XSTRING_DATA (symbol_name (XSYMBOL (obj))),
|
|
1788 XSTRING_LENGTH (symbol_name (XSYMBOL (obj))))))
|
428
|
1789 {
|
|
1790 if (print_depth > 1)
|
|
1791 {
|
|
1792 Lisp_Object tem = Fassq (obj, Vprint_gensym_alist);
|
|
1793 if (CONSP (tem))
|
|
1794 {
|
826
|
1795 write_c_string (printcharfun, "#");
|
428
|
1796 print_internal (XCDR (tem), printcharfun, escapeflag);
|
826
|
1797 write_c_string (printcharfun, "#");
|
446
|
1798 UNGCPRO;
|
428
|
1799 return;
|
|
1800 }
|
|
1801 else
|
|
1802 {
|
|
1803 if (CONSP (Vprint_gensym_alist))
|
|
1804 {
|
|
1805 /* Vprint_gensym_alist is exposed to Lisp, so we
|
|
1806 have to be careful. */
|
|
1807 CHECK_CONS (XCAR (Vprint_gensym_alist));
|
|
1808 CHECK_INT (XCDR (XCAR (Vprint_gensym_alist)));
|
793
|
1809 tem = make_int (XINT (XCDR (XCAR (Vprint_gensym_alist))) + 1);
|
428
|
1810 }
|
|
1811 else
|
793
|
1812 tem = make_int (1);
|
428
|
1813 Vprint_gensym_alist = Fcons (Fcons (obj, tem), Vprint_gensym_alist);
|
|
1814
|
826
|
1815 write_c_string (printcharfun, "#");
|
428
|
1816 print_internal (tem, printcharfun, escapeflag);
|
826
|
1817 write_c_string (printcharfun, "=");
|
428
|
1818 }
|
|
1819 }
|
826
|
1820 write_c_string (printcharfun, "#:");
|
428
|
1821 }
|
|
1822
|
|
1823 /* Does it look like an integer or a float? */
|
|
1824 {
|
867
|
1825 Ibyte *data = XSTRING_DATA (name);
|
428
|
1826 Bytecount confusing = 0;
|
|
1827
|
|
1828 if (size == 0)
|
|
1829 goto not_yet_confused; /* Really confusing */
|
|
1830 else if (isdigit (data[0]))
|
|
1831 confusing = 0;
|
|
1832 else if (size == 1)
|
|
1833 goto not_yet_confused;
|
|
1834 else if (data[0] == '-' || data[0] == '+')
|
|
1835 confusing = 1;
|
|
1836 else
|
|
1837 goto not_yet_confused;
|
|
1838
|
|
1839 for (; confusing < size; confusing++)
|
|
1840 {
|
|
1841 if (!isdigit (data[confusing]))
|
|
1842 {
|
|
1843 confusing = 0;
|
|
1844 break;
|
|
1845 }
|
|
1846 }
|
|
1847 not_yet_confused:
|
|
1848
|
|
1849 if (!confusing)
|
|
1850 /* #### Ugh, this is needlessly complex and slow for what we
|
|
1851 need here. It might be a good idea to copy equivalent code
|
|
1852 from FSF. --hniksic */
|
|
1853 confusing = isfloat_string ((char *) data);
|
|
1854 if (confusing)
|
826
|
1855 write_c_string (printcharfun, "\\");
|
428
|
1856 }
|
|
1857
|
|
1858 {
|
|
1859 Bytecount i;
|
|
1860 Bytecount last = 0;
|
|
1861
|
|
1862 for (i = 0; i < size; i++)
|
|
1863 {
|
826
|
1864 switch (string_byte (name, i))
|
428
|
1865 {
|
|
1866 case 0: case 1: case 2: case 3:
|
|
1867 case 4: case 5: case 6: case 7:
|
|
1868 case 8: case 9: case 10: case 11:
|
|
1869 case 12: case 13: case 14: case 15:
|
|
1870 case 16: case 17: case 18: case 19:
|
|
1871 case 20: case 21: case 22: case 23:
|
|
1872 case 24: case 25: case 26: case 27:
|
|
1873 case 28: case 29: case 30: case 31:
|
|
1874 case ' ': case '\"': case '\\': case '\'':
|
|
1875 case ';': case '#' : case '(' : case ')':
|
|
1876 case ',': case '.' : case '`' :
|
|
1877 case '[': case ']' : case '?' :
|
|
1878 if (i > last)
|
793
|
1879 output_string (printcharfun, 0, name, last, i - last);
|
826
|
1880 write_c_string (printcharfun, "\\");
|
428
|
1881 last = i;
|
|
1882 }
|
|
1883 }
|
793
|
1884 output_string (printcharfun, 0, name, last, size - last);
|
428
|
1885 }
|
|
1886 UNGCPRO;
|
|
1887 }
|
|
1888
|
|
1889
|
442
|
1890 /* Useful on systems or in places where writing to stdout is unavailable or
|
|
1891 not working. */
|
428
|
1892
|
|
1893 static int alternate_do_pointer;
|
1957
|
1894 static int alternate_do_size;
|
|
1895 static char *alternate_do_string;
|
428
|
1896
|
|
1897 DEFUN ("alternate-debugging-output", Falternate_debugging_output, 1, 1, 0, /*
|
|
1898 Append CHARACTER to the array `alternate_do_string'.
|
|
1899 This can be used in place of `external-debugging-output' as a function
|
|
1900 to be passed to `print'. Before calling `print', set `alternate_do_pointer'
|
|
1901 to 0.
|
|
1902 */
|
|
1903 (character))
|
|
1904 {
|
867
|
1905 Ibyte str[MAX_ICHAR_LEN];
|
428
|
1906 Bytecount len;
|
|
1907
|
|
1908 CHECK_CHAR_COERCE_INT (character);
|
867
|
1909 len = set_itext_ichar (str, XCHAR (character));
|
771
|
1910 write_string_to_alternate_debugging_output (str, len);
|
|
1911
|
|
1912 return character;
|
|
1913 }
|
|
1914
|
|
1915 static void
|
1346
|
1916 write_string_to_alternate_debugging_output (const Ibyte *str, Bytecount len)
|
771
|
1917 {
|
|
1918 int extlen;
|
|
1919 const Extbyte *extptr;
|
|
1920 #if 0 /* We want to see the internal representation, don't we? */
|
2367
|
1921 if (initialized && !inhibit_non_essential_conversion_operations)
|
771
|
1922 TO_EXTERNAL_FORMAT (DATA, (str, len),
|
|
1923 ALLOCA, (extptr, extlen),
|
|
1924 Qterminal);
|
|
1925 else
|
|
1926 #endif /* 0 */
|
|
1927 {
|
|
1928 extlen = len;
|
|
1929 extptr = (Extbyte *) str;
|
|
1930 }
|
1957
|
1931
|
|
1932 /* If not yet initialized, just skip it. */
|
|
1933 if (alternate_do_string == NULL)
|
|
1934 return;
|
|
1935
|
|
1936 if (alternate_do_pointer + extlen >= alternate_do_size)
|
|
1937 {
|
|
1938 alternate_do_size =
|
|
1939 max(alternate_do_size * 2, alternate_do_pointer + extlen + 1);
|
|
1940 XREALLOC_ARRAY (alternate_do_string, char, alternate_do_size);
|
|
1941 }
|
428
|
1942 memcpy (alternate_do_string + alternate_do_pointer, extptr, extlen);
|
|
1943 alternate_do_pointer += extlen;
|
|
1944 alternate_do_string[alternate_do_pointer] = 0;
|
|
1945 }
|
|
1946
|
1346
|
1947
|
|
1948 DEFUN ("set-device-clear-left-side", Fset_device_clear_left_side, 2, 2, 0, /*
|
|
1949 Set whether to output a newline before the next output to a stream device.
|
|
1950 This will happen only if the most recently-outputted character was not
|
|
1951 a newline -- i.e. it will make sure the left side is "clear" of text.
|
|
1952 */
|
|
1953 (device, value))
|
|
1954 {
|
|
1955 if (!NILP (device))
|
|
1956 CHECK_LIVE_DEVICE (device);
|
|
1957 if (NILP (device) || DEVICE_STREAM_P (XDEVICE (device)))
|
|
1958 /* #### This should be per-device */
|
|
1959 stdout_clear_before_next_output = !NILP (value);
|
|
1960 return Qnil;
|
|
1961 }
|
|
1962
|
|
1963 DEFUN ("device-left-side-clear-p", Fdevice_left_side_clear_p, 0, 1, 0, /*
|
|
1964 For stream devices, true if the most recent-outputted character was a newline.
|
|
1965 */
|
|
1966 (device))
|
|
1967 {
|
|
1968 if (!NILP (device))
|
|
1969 CHECK_LIVE_DEVICE (device);
|
|
1970 if (NILP (device) || DEVICE_STREAM_P (XDEVICE (device)))
|
|
1971 /* #### This should be per-device */
|
|
1972 return stdout_needs_newline ? Qt : Qnil;
|
|
1973 return Qnil;
|
|
1974 }
|
|
1975
|
428
|
1976 DEFUN ("external-debugging-output", Fexternal_debugging_output, 1, 3, 0, /*
|
|
1977 Write CHAR-OR-STRING to stderr or stdout.
|
|
1978 If optional arg STDOUT-P is non-nil, write to stdout; otherwise, write
|
|
1979 to stderr. You can use this function to write directly to the terminal.
|
|
1980 This function can be used as the STREAM argument of Fprint() or the like.
|
|
1981
|
442
|
1982 Under MS Windows, this writes output to the console window (which is
|
|
1983 created, if necessary), unless XEmacs is being run noninteractively
|
|
1984 \(i.e. using the `-batch' argument).
|
|
1985
|
428
|
1986 If you have opened a termscript file (using `open-termscript'), then
|
|
1987 the output also will be logged to this file.
|
|
1988 */
|
|
1989 (char_or_string, stdout_p, device))
|
|
1990 {
|
|
1991 FILE *file = 0;
|
|
1992 struct console *con = 0;
|
|
1993
|
|
1994 if (NILP (device))
|
|
1995 {
|
|
1996 if (!NILP (stdout_p))
|
|
1997 file = stdout;
|
|
1998 else
|
|
1999 file = stderr;
|
|
2000 }
|
|
2001 else
|
|
2002 {
|
|
2003 CHECK_LIVE_DEVICE (device);
|
|
2004 if (!DEVICE_TTY_P (XDEVICE (device)) &&
|
|
2005 !DEVICE_STREAM_P (XDEVICE (device)))
|
563
|
2006 wtaerror ("Must be tty or stream device", device);
|
428
|
2007 con = XCONSOLE (DEVICE_CONSOLE (XDEVICE (device)));
|
|
2008 if (DEVICE_TTY_P (XDEVICE (device)))
|
|
2009 file = 0;
|
|
2010 else if (!NILP (stdout_p))
|
|
2011 file = CONSOLE_STREAM_DATA (con)->out;
|
|
2012 else
|
|
2013 file = CONSOLE_STREAM_DATA (con)->err;
|
|
2014 }
|
|
2015
|
|
2016 if (STRINGP (char_or_string))
|
|
2017 write_string_to_stdio_stream (file, con,
|
|
2018 XSTRING_DATA (char_or_string),
|
771
|
2019 XSTRING_LENGTH (char_or_string),
|
|
2020 print_unbuffered);
|
428
|
2021 else
|
|
2022 {
|
867
|
2023 Ibyte str[MAX_ICHAR_LEN];
|
428
|
2024 Bytecount len;
|
|
2025
|
|
2026 CHECK_CHAR_COERCE_INT (char_or_string);
|
867
|
2027 len = set_itext_ichar (str, XCHAR (char_or_string));
|
771
|
2028 write_string_to_stdio_stream (file, con, str, len, print_unbuffered);
|
428
|
2029 }
|
|
2030
|
|
2031 return char_or_string;
|
|
2032 }
|
|
2033
|
|
2034 DEFUN ("open-termscript", Fopen_termscript, 1, 1, "FOpen termscript file: ", /*
|
444
|
2035 Start writing all terminal output to FILENAME as well as the terminal.
|
|
2036 FILENAME = nil means just close any termscript file currently open.
|
428
|
2037 */
|
444
|
2038 (filename))
|
428
|
2039 {
|
|
2040 /* This function can GC */
|
|
2041 if (termscript != 0)
|
|
2042 {
|
771
|
2043 retry_fclose (termscript);
|
444
|
2044 termscript = 0;
|
|
2045 }
|
|
2046
|
|
2047 if (! NILP (filename))
|
|
2048 {
|
|
2049 filename = Fexpand_file_name (filename, Qnil);
|
771
|
2050 termscript = qxe_fopen (XSTRING_DATA (filename), "w");
|
428
|
2051 if (termscript == NULL)
|
563
|
2052 report_file_error ("Opening termscript", filename);
|
428
|
2053 }
|
|
2054 return Qnil;
|
|
2055 }
|
|
2056
|
440
|
2057 static int debug_print_length = 50;
|
|
2058 static int debug_print_level = 15;
|
|
2059 static int debug_print_readably = -1;
|
428
|
2060
|
1957
|
2061 /* Restore values temporarily bound by debug_prin1. We use this approach to
|
|
2062 avoid consing in debug_prin1. That is verboten, since debug_prin1 can be
|
|
2063 called by cons debugging code. */
|
|
2064 static Lisp_Object
|
2286
|
2065 debug_prin1_exit (Lisp_Object UNUSED (ignored))
|
1957
|
2066 {
|
|
2067 struct debug_bindings *bindings =
|
|
2068 (struct debug_bindings *) XOPAQUE (debug_prin1_bindings)->data;
|
2367
|
2069 inhibit_non_essential_conversion_operations =
|
|
2070 bindings->inhibit_non_essential_conversion_operations;
|
1957
|
2071 print_depth = bindings->print_depth;
|
|
2072 print_readably = bindings->print_readably;
|
|
2073 print_unbuffered = bindings->print_unbuffered;
|
|
2074 gc_currently_forbidden = bindings->gc_currently_forbidden;
|
|
2075 Vprint_length = bindings->Vprint_length;
|
|
2076 Vprint_level = bindings->Vprint_level;
|
|
2077 Vinhibit_quit = bindings->Vinhibit_quit;
|
|
2078 return Qnil;
|
|
2079 }
|
|
2080
|
1346
|
2081 /* Print an object, `prin1'-style, to various possible debugging outputs.
|
|
2082 Make sure it's completely unbuffered so that, in the event of a crash
|
|
2083 somewhere, we see as much as possible that happened before it.
|
|
2084 */
|
428
|
2085 static void
|
1346
|
2086 debug_prin1 (Lisp_Object debug_print_obj, int flags)
|
428
|
2087 {
|
|
2088 /* This function can GC */
|
853
|
2089
|
|
2090 /* by doing this, we trick various things that are non-essential
|
|
2091 but might cause crashes into not getting executed. */
|
1957
|
2092 int specdepth;
|
|
2093 struct debug_bindings *bindings =
|
|
2094 (struct debug_bindings *) XOPAQUE (debug_prin1_bindings)->data;
|
853
|
2095
|
2367
|
2096 bindings->inhibit_non_essential_conversion_operations =
|
|
2097 inhibit_non_essential_conversion_operations;
|
1957
|
2098 bindings->print_depth = print_depth;
|
|
2099 bindings->print_readably = print_readably;
|
|
2100 bindings->print_unbuffered = print_unbuffered;
|
|
2101 bindings->gc_currently_forbidden = gc_currently_forbidden;
|
|
2102 bindings->Vprint_length = Vprint_length;
|
|
2103 bindings->Vprint_level = Vprint_level;
|
|
2104 bindings->Vinhibit_quit = Vinhibit_quit;
|
|
2105 specdepth = record_unwind_protect (debug_prin1_exit, Qnil);
|
|
2106
|
2367
|
2107 inhibit_non_essential_conversion_operations = 1;
|
1957
|
2108 print_depth = 0;
|
|
2109 print_readably = debug_print_readably != -1 ? debug_print_readably : 0;
|
|
2110 print_unbuffered++;
|
428
|
2111 if (debug_print_length > 0)
|
1957
|
2112 Vprint_length = make_int (debug_print_length);
|
428
|
2113 if (debug_print_level > 0)
|
1957
|
2114 Vprint_level = make_int (debug_print_level);
|
|
2115 Vinhibit_quit = Qt;
|
1346
|
2116
|
|
2117 if ((flags & EXT_PRINT_STDOUT) || (flags & EXT_PRINT_STDERR))
|
|
2118 print_internal (debug_print_obj, Qexternal_debugging_output, 1);
|
|
2119 if (flags & EXT_PRINT_ALTERNATE)
|
|
2120 print_internal (debug_print_obj, Qalternate_debugging_output, 1);
|
442
|
2121 #ifdef WIN32_NATIVE
|
1346
|
2122 if (flags & EXT_PRINT_MSWINDOWS)
|
|
2123 {
|
|
2124 /* Write out to the debugger, as well */
|
|
2125 print_internal (debug_print_obj, Qmswindows_debugging_output, 1);
|
|
2126 }
|
442
|
2127 #endif
|
440
|
2128
|
802
|
2129 unbind_to (specdepth);
|
428
|
2130 }
|
|
2131
|
|
2132 void
|
1204
|
2133 debug_p4 (Lisp_Object obj)
|
|
2134 {
|
2367
|
2135 inhibit_non_essential_conversion_operations = 1;
|
1204
|
2136 if (STRINGP (obj))
|
|
2137 debug_out ("\"%s\"", XSTRING_DATA (obj));
|
|
2138 else if (CONSP (obj))
|
|
2139 {
|
|
2140 int first = 1;
|
|
2141 do {
|
|
2142 debug_out (first ? "(" : " ");
|
|
2143 first = 0;
|
|
2144 debug_p4 (XCAR (obj));
|
|
2145 obj = XCDR (obj);
|
|
2146 } while (CONSP (obj));
|
|
2147 if (NILP (obj))
|
|
2148 debug_out (")");
|
|
2149 else
|
|
2150 {
|
|
2151 debug_out (" . ");
|
|
2152 debug_p4 (obj);
|
|
2153 debug_out (")");
|
|
2154 }
|
|
2155 }
|
|
2156 else if (VECTORP (obj))
|
|
2157 {
|
|
2158 int size = XVECTOR_LENGTH (obj);
|
|
2159 int i;
|
|
2160 int first = 1;
|
|
2161
|
|
2162 for (i = 0; i < size; i++)
|
|
2163 {
|
|
2164 debug_out (first ? "[" : " ");
|
|
2165 first = 0;
|
|
2166 debug_p4 (XVECTOR_DATA (obj)[i]);
|
|
2167 debug_out ("]");
|
|
2168 }
|
|
2169 }
|
|
2170 else if (SYMBOLP (obj))
|
|
2171 {
|
|
2172 Lisp_Object name = XSYMBOL_NAME (obj);
|
|
2173 if (!STRINGP (name))
|
|
2174 debug_out ("<<bad symbol>>");
|
|
2175 else
|
|
2176 debug_out ("%s", XSTRING_DATA (name));
|
|
2177 }
|
|
2178 else if (INTP (obj))
|
|
2179 {
|
|
2180 debug_out ("%ld", XINT (obj));
|
|
2181 }
|
|
2182 else if (FLOATP (obj))
|
|
2183 {
|
|
2184 debug_out ("%g", XFLOAT_DATA (obj));
|
|
2185 }
|
|
2186 else
|
|
2187 {
|
|
2188 struct lrecord_header *header =
|
|
2189 (struct lrecord_header *) XPNTR (obj);
|
|
2190
|
|
2191 if (header->type >= lrecord_type_last_built_in_type)
|
|
2192 debug_out ("<< bad object type=%d 0x%lx>>", header->type,
|
|
2193 (EMACS_INT) header);
|
|
2194 else
|
|
2195 debug_out ("#<%s 0x%lx>",
|
|
2196 LHEADER_IMPLEMENTATION (header)->name,
|
|
2197 LHEADER_IMPLEMENTATION (header)->basic_p ?
|
|
2198 (EMACS_INT) header :
|
|
2199 ((struct lcrecord_header *) header)->uid);
|
|
2200 }
|
|
2201
|
2367
|
2202 inhibit_non_essential_conversion_operations = 0;
|
1204
|
2203 }
|
|
2204
|
1346
|
2205 static void
|
|
2206 ext_print_begin (int dest)
|
|
2207 {
|
|
2208 if (dest & EXT_PRINT_ALTERNATE)
|
|
2209 alternate_do_pointer = 0;
|
|
2210 if (dest & (EXT_PRINT_STDERR | EXT_PRINT_STDOUT))
|
|
2211 stdout_clear_before_next_output = 1;
|
|
2212 }
|
|
2213
|
|
2214 static void
|
|
2215 ext_print_end (int dest)
|
|
2216 {
|
|
2217 if (dest & (EXT_PRINT_MSWINDOWS | EXT_PRINT_STDERR | EXT_PRINT_STDOUT))
|
|
2218 external_out (dest & (EXT_PRINT_MSWINDOWS | EXT_PRINT_STDERR |
|
|
2219 EXT_PRINT_STDOUT), "\n");
|
|
2220 }
|
|
2221
|
|
2222 static void
|
|
2223 external_debug_print (Lisp_Object object, int dest)
|
|
2224 {
|
|
2225 ext_print_begin (dest);
|
|
2226 debug_prin1 (object, dest);
|
|
2227 ext_print_end (dest);
|
|
2228 }
|
|
2229
|
1204
|
2230 void
|
|
2231 debug_p3 (Lisp_Object obj)
|
|
2232 {
|
|
2233 debug_p4 (obj);
|
2367
|
2234 inhibit_non_essential_conversion_operations = 1;
|
1204
|
2235 debug_out ("\n");
|
2367
|
2236 inhibit_non_essential_conversion_operations = 0;
|
1204
|
2237 }
|
|
2238
|
|
2239 void
|
428
|
2240 debug_print (Lisp_Object debug_print_obj)
|
|
2241 {
|
1346
|
2242 external_debug_print (debug_print_obj, EXT_PRINT_ALL);
|
428
|
2243 }
|
|
2244
|
1204
|
2245 /* Getting tired of typing debug_print() ... */
|
|
2246 void dp (Lisp_Object debug_print_obj);
|
|
2247 void
|
|
2248 dp (Lisp_Object debug_print_obj)
|
|
2249 {
|
|
2250 debug_print (debug_print_obj);
|
|
2251 }
|
|
2252
|
1346
|
2253 /* Alternate debug printer: Return a char * pointer to the output */
|
|
2254 char *dpa (Lisp_Object debug_print_obj);
|
|
2255 char *
|
|
2256 dpa (Lisp_Object debug_print_obj)
|
|
2257 {
|
|
2258 external_debug_print (debug_print_obj, EXT_PRINT_ALTERNATE);
|
|
2259
|
|
2260 return alternate_do_string;
|
|
2261 }
|
|
2262
|
428
|
2263 /* Debugging kludge -- unbuffered */
|
|
2264 /* This function provided for the benefit of the debugger. */
|
|
2265 void
|
|
2266 debug_backtrace (void)
|
|
2267 {
|
|
2268 /* This function can GC */
|
853
|
2269
|
|
2270 /* by doing this, we trick various things that are non-essential
|
|
2271 but might cause crashes into not getting executed. */
|
|
2272 int specdepth =
|
2367
|
2273 internal_bind_int (&inhibit_non_essential_conversion_operations, 1);
|
853
|
2274
|
|
2275 internal_bind_int (&print_depth, 0);
|
802
|
2276 internal_bind_int (&print_readably, 0);
|
|
2277 internal_bind_int (&print_unbuffered, print_unbuffered + 1);
|
428
|
2278 if (debug_print_length > 0)
|
802
|
2279 internal_bind_lisp_object (&Vprint_length, make_int (debug_print_length));
|
428
|
2280 if (debug_print_level > 0)
|
802
|
2281 internal_bind_lisp_object (&Vprint_level, make_int (debug_print_level));
|
|
2282 /* #### Do we need this? It was in the old code. */
|
|
2283 internal_bind_lisp_object (&Vinhibit_quit, Vinhibit_quit);
|
428
|
2284
|
|
2285 Fbacktrace (Qexternal_debugging_output, Qt);
|
|
2286 stderr_out ("\n");
|
|
2287
|
802
|
2288 unbind_to (specdepth);
|
428
|
2289 }
|
|
2290
|
1204
|
2291 /* Getting tired of typing debug_backtrace() ... */
|
|
2292 void db (void);
|
|
2293 void
|
|
2294 db (void)
|
|
2295 {
|
|
2296 debug_backtrace ();
|
|
2297 }
|
|
2298
|
428
|
2299 void
|
|
2300 debug_short_backtrace (int length)
|
|
2301 {
|
|
2302 int first = 1;
|
|
2303 struct backtrace *bt = backtrace_list;
|
771
|
2304 debug_out (" [");
|
428
|
2305 while (length > 0 && bt)
|
|
2306 {
|
|
2307 if (!first)
|
|
2308 {
|
771
|
2309 debug_out (", ");
|
428
|
2310 }
|
|
2311 if (COMPILED_FUNCTIONP (*bt->function))
|
|
2312 {
|
1346
|
2313 #if defined (COMPILED_FUNCTION_ANNOTATION_HACK)
|
428
|
2314 Lisp_Object ann =
|
|
2315 compiled_function_annotation (XCOMPILED_FUNCTION (*bt->function));
|
|
2316 #else
|
|
2317 Lisp_Object ann = Qnil;
|
|
2318 #endif
|
|
2319 if (!NILP (ann))
|
|
2320 {
|
771
|
2321 debug_out ("<compiled-function from ");
|
1346
|
2322 debug_prin1 (ann, EXT_PRINT_ALL);
|
771
|
2323 debug_out (">");
|
428
|
2324 }
|
|
2325 else
|
|
2326 {
|
771
|
2327 debug_out ("<compiled-function of unknown origin>");
|
428
|
2328 }
|
|
2329 }
|
|
2330 else
|
1346
|
2331 debug_prin1 (*bt->function, EXT_PRINT_ALL);
|
428
|
2332 first = 0;
|
|
2333 length--;
|
|
2334 bt = bt->next;
|
|
2335 }
|
771
|
2336 debug_out ("]\n");
|
428
|
2337 }
|
|
2338
|
|
2339
|
|
2340 void
|
|
2341 syms_of_print (void)
|
|
2342 {
|
563
|
2343 DEFSYMBOL (Qstandard_output);
|
428
|
2344
|
563
|
2345 DEFSYMBOL (Qprint_length);
|
428
|
2346
|
563
|
2347 DEFSYMBOL (Qprint_string_length);
|
428
|
2348
|
563
|
2349 DEFSYMBOL (Qdisplay_error);
|
|
2350 DEFSYMBOL (Qprint_message_label);
|
428
|
2351
|
|
2352 DEFSUBR (Fprin1);
|
|
2353 DEFSUBR (Fprin1_to_string);
|
|
2354 DEFSUBR (Fprinc);
|
|
2355 DEFSUBR (Fprint);
|
|
2356 DEFSUBR (Ferror_message_string);
|
|
2357 DEFSUBR (Fdisplay_error);
|
|
2358 DEFSUBR (Fterpri);
|
|
2359 DEFSUBR (Fwrite_char);
|
|
2360 DEFSUBR (Falternate_debugging_output);
|
1346
|
2361 DEFSUBR (Fset_device_clear_left_side);
|
|
2362 DEFSUBR (Fdevice_left_side_clear_p);
|
428
|
2363 DEFSUBR (Fexternal_debugging_output);
|
|
2364 DEFSUBR (Fopen_termscript);
|
563
|
2365 DEFSYMBOL (Qexternal_debugging_output);
|
|
2366 DEFSYMBOL (Qalternate_debugging_output);
|
442
|
2367 #ifdef HAVE_MS_WINDOWS
|
563
|
2368 DEFSYMBOL (Qmswindows_debugging_output);
|
442
|
2369 #endif
|
428
|
2370 DEFSUBR (Fwith_output_to_temp_buffer);
|
|
2371 }
|
|
2372
|
|
2373 void
|
|
2374 reinit_vars_of_print (void)
|
|
2375 {
|
|
2376 alternate_do_pointer = 0;
|
|
2377 }
|
|
2378
|
|
2379 void
|
|
2380 vars_of_print (void)
|
|
2381 {
|
|
2382 DEFVAR_LISP ("standard-output", &Vstandard_output /*
|
|
2383 Output stream `print' uses by default for outputting a character.
|
|
2384 This may be any function of one argument.
|
|
2385 It may also be a buffer (output is inserted before point)
|
|
2386 or a marker (output is inserted and the marker is advanced)
|
|
2387 or the symbol t (output appears in the minibuffer line).
|
|
2388 */ );
|
|
2389 Vstandard_output = Qt;
|
|
2390
|
|
2391 DEFVAR_LISP ("float-output-format", &Vfloat_output_format /*
|
|
2392 The format descriptor string that lisp uses to print floats.
|
|
2393 This is a %-spec like those accepted by `printf' in C,
|
|
2394 but with some restrictions. It must start with the two characters `%.'.
|
|
2395 After that comes an integer precision specification,
|
|
2396 and then a letter which controls the format.
|
|
2397 The letters allowed are `e', `f' and `g'.
|
|
2398 Use `e' for exponential notation "DIG.DIGITSeEXPT"
|
|
2399 Use `f' for decimal point notation "DIGITS.DIGITS".
|
|
2400 Use `g' to choose the shorter of those two formats for the number at hand.
|
|
2401 The precision in any of these cases is the number of digits following
|
|
2402 the decimal point. With `f', a precision of 0 means to omit the
|
|
2403 decimal point. 0 is not allowed with `f' or `g'.
|
|
2404
|
|
2405 A value of nil means to use `%.16g'.
|
|
2406
|
|
2407 Regardless of the value of `float-output-format', a floating point number
|
|
2408 will never be printed in such a way that it is ambiguous with an integer;
|
|
2409 that is, a floating-point number will always be printed with a decimal
|
|
2410 point and/or an exponent, even if the digits following the decimal point
|
|
2411 are all zero. This is to preserve read-equivalence.
|
|
2412 */ );
|
|
2413 Vfloat_output_format = Qnil;
|
|
2414
|
|
2415 DEFVAR_LISP ("print-length", &Vprint_length /*
|
|
2416 Maximum length of list or vector to print before abbreviating.
|
|
2417 A value of nil means no limit.
|
|
2418 */ );
|
|
2419 Vprint_length = Qnil;
|
|
2420
|
|
2421 DEFVAR_LISP ("print-string-length", &Vprint_string_length /*
|
|
2422 Maximum length of string to print before abbreviating.
|
|
2423 A value of nil means no limit.
|
|
2424 */ );
|
|
2425 Vprint_string_length = Qnil;
|
|
2426
|
|
2427 DEFVAR_LISP ("print-level", &Vprint_level /*
|
|
2428 Maximum depth of list nesting to print before abbreviating.
|
|
2429 A value of nil means no limit.
|
|
2430 */ );
|
|
2431 Vprint_level = Qnil;
|
|
2432
|
|
2433 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines /*
|
|
2434 Non-nil means print newlines in strings as backslash-n.
|
|
2435 */ );
|
|
2436 print_escape_newlines = 0;
|
|
2437
|
|
2438 DEFVAR_BOOL ("print-readably", &print_readably /*
|
|
2439 If non-nil, then all objects will be printed in a readable form.
|
|
2440 If an object has no readable representation, then an error is signalled.
|
|
2441 When print-readably is true, compiled-function objects will be written in
|
|
2442 #[...] form instead of in #<compiled-function [...]> form, and two-element
|
|
2443 lists of the form (quote object) will be written as the equivalent 'object.
|
|
2444 Do not SET this variable; bind it instead.
|
|
2445 */ );
|
|
2446 print_readably = 0;
|
|
2447
|
|
2448 /* #### I think this should default to t. But we'd better wait
|
|
2449 until we see that it works out. */
|
|
2450 DEFVAR_LISP ("print-gensym", &Vprint_gensym /*
|
|
2451 If non-nil, then uninterned symbols will be printed specially.
|
|
2452 Uninterned symbols are those which are not present in `obarray', that is,
|
|
2453 those which were made with `make-symbol' or by calling `intern' with a
|
|
2454 second argument.
|
|
2455
|
|
2456 When print-gensym is true, such symbols will be preceded by "#:",
|
|
2457 which causes the reader to create a new symbol instead of interning
|
|
2458 and returning an existing one. Beware: the #: syntax creates a new
|
|
2459 symbol each time it is seen, so if you print an object which contains
|
|
2460 two pointers to the same uninterned symbol, `read' will not duplicate
|
|
2461 that structure.
|
|
2462
|
|
2463 If the value of `print-gensym' is a cons cell, then in addition
|
|
2464 refrain from clearing `print-gensym-alist' on entry to and exit from
|
|
2465 printing functions, so that the use of #...# and #...= can carry over
|
|
2466 for several separately printed objects.
|
|
2467 */ );
|
|
2468 Vprint_gensym = Qnil;
|
|
2469
|
|
2470 DEFVAR_LISP ("print-gensym-alist", &Vprint_gensym_alist /*
|
|
2471 Association list of elements (GENSYM . N) to guide use of #N# and #N=.
|
|
2472 In each element, GENSYM is an uninterned symbol that has been associated
|
|
2473 with #N= for the specified value of N.
|
|
2474 */ );
|
|
2475 Vprint_gensym_alist = Qnil;
|
|
2476
|
|
2477 DEFVAR_LISP ("print-message-label", &Vprint_message_label /*
|
|
2478 Label for minibuffer messages created with `print'. This should
|
|
2479 generally be bound with `let' rather than set. (See `display-message'.)
|
|
2480 */ );
|
|
2481 Vprint_message_label = Qprint;
|
1957
|
2482
|
|
2483 debug_prin1_bindings =
|
|
2484 make_opaque (OPAQUE_UNINIT, sizeof (struct debug_bindings));
|
|
2485 staticpro (&debug_prin1_bindings);
|
|
2486
|
|
2487 alternate_do_size = 5000;
|
|
2488 alternate_do_string = xnew_array(char, 5000);
|
428
|
2489 }
|