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