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