0
|
1 /* Lisp object printing and output streams.
|
|
2 Copyright (C) 1985, 1986, 1988, 1992-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995, 1996 Ben Wing.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not synched with FSF. */
|
|
23
|
|
24 /* This file has been Mule-ized. */
|
|
25
|
|
26 /* Seriously hacked on by Ben Wing for Mule. */
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #ifndef standalone
|
|
32 #include "backtrace.h"
|
|
33 #include "buffer.h"
|
|
34 #include "bytecode.h"
|
|
35 #include "console-tty.h"
|
|
36 #include "console-stream.h"
|
|
37 #include "extents.h"
|
|
38 #include "frame.h"
|
|
39 #include "insdel.h"
|
|
40 #include "lstream.h"
|
272
|
41 #include "sysfile.h"
|
0
|
42
|
|
43 #endif /* not standalone */
|
|
44
|
272
|
45 #include <float.h>
|
|
46 /* Define if not in float.h */
|
|
47 #ifndef DBL_DIG
|
|
48 #define DBL_DIG 16
|
|
49 #endif
|
|
50
|
149
|
51 static void print_error_message (Lisp_Object data, Lisp_Object stream);
|
|
52
|
0
|
53 Lisp_Object Vstandard_output, Qstandard_output;
|
|
54
|
|
55 /* The subroutine object for external-debugging-output is kept here
|
|
56 for the convenience of the debugger. */
|
|
57 Lisp_Object Qexternal_debugging_output;
|
|
58 Lisp_Object Qalternate_debugging_output;
|
173
|
59
|
0
|
60 /* Avoid actual stack overflow in print. */
|
|
61 static int print_depth;
|
|
62
|
177
|
63 /* Detect most circularities to print finite output. */
|
|
64 #define PRINT_CIRCLE 200
|
|
65 Lisp_Object being_printed[PRINT_CIRCLE];
|
|
66
|
0
|
67 /* Maximum length of list or vector to print in full; noninteger means
|
|
68 effectively infinity */
|
|
69
|
|
70 Lisp_Object Vprint_length;
|
|
71 Lisp_Object Qprint_length;
|
|
72
|
|
73 /* Maximum length of string to print in full; noninteger means
|
|
74 effectively infinity */
|
|
75
|
|
76 Lisp_Object Vprint_string_length;
|
|
77 Lisp_Object Qprint_string_length;
|
|
78
|
|
79 /* Maximum depth of list to print in full; noninteger means
|
|
80 effectively infinity. */
|
|
81
|
|
82 Lisp_Object Vprint_level;
|
|
83
|
|
84 /* Label to use when making echo-area messages. */
|
|
85
|
|
86 Lisp_Object Vprint_message_label;
|
|
87
|
|
88 /* Nonzero means print newlines in strings as \n. */
|
|
89
|
|
90 int print_escape_newlines;
|
|
91 int print_readably;
|
245
|
92
|
|
93 /* Non-nil means print #: before uninterned symbols.
|
|
94 Neither t nor nil means so that and don't clear Vprint_gensym_alist
|
|
95 on entry to and exit from print functions. */
|
|
96 Lisp_Object Vprint_gensym;
|
|
97 Lisp_Object Vprint_gensym_alist;
|
0
|
98
|
|
99 Lisp_Object Qprint_escape_newlines;
|
|
100 Lisp_Object Qprint_readably;
|
|
101
|
171
|
102 Lisp_Object Qdisplay_error;
|
|
103 Lisp_Object Qprint_message_label;
|
|
104
|
0
|
105 /* Force immediate output of all printed data. Used for debugging. */
|
|
106 int print_unbuffered;
|
|
107
|
|
108 FILE *termscript; /* Stdio stream being used for copy of all output. */
|
|
109
|
|
110
|
|
111
|
|
112 int stdout_needs_newline;
|
|
113
|
|
114 /* Write a string (in internal format) to stdio stream STREAM. */
|
173
|
115
|
0
|
116 void
|
|
117 write_string_to_stdio_stream (FILE *stream, struct console *con,
|
|
118 CONST Bufbyte *str,
|
|
119 Bytecount offset, Bytecount len,
|
|
120 enum external_data_format fmt)
|
|
121 {
|
|
122 int extlen;
|
|
123 CONST Extbyte *extptr;
|
|
124
|
|
125 GET_CHARPTR_EXT_DATA_ALLOCA (str + offset, len, fmt, extptr, extlen);
|
|
126 if (stream)
|
|
127 fwrite (extptr, 1, extlen, stream);
|
|
128 else
|
|
129 {
|
|
130 assert (CONSOLE_TTY_P (con));
|
|
131 Lstream_write (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream),
|
|
132 extptr, extlen);
|
|
133 }
|
|
134 if (stream == stdout || stream == stderr ||
|
|
135 (!stream && CONSOLE_TTY_DATA (con)->is_stdio))
|
|
136 {
|
|
137 if (termscript)
|
|
138 {
|
|
139 fwrite (extptr, 1, extlen, termscript);
|
|
140 fflush (termscript);
|
|
141 }
|
|
142 stdout_needs_newline = (extptr[extlen - 1] != '\n');
|
|
143 }
|
|
144 }
|
|
145
|
|
146 /* Write a string to the output location specified in FUNCTION.
|
|
147 Arguments NONRELOC, RELOC, OFFSET, and LEN are as in
|
|
148 buffer_insert_string_1() in insdel.c. */
|
|
149
|
|
150 static void
|
|
151 output_string (Lisp_Object function, CONST Bufbyte *nonreloc,
|
|
152 Lisp_Object reloc, Bytecount offset, Bytecount len)
|
|
153 {
|
|
154 /* This function can GC */
|
|
155 Charcount ccoff, cclen;
|
|
156 /* We change the value of nonreloc (fetching it from reloc as
|
|
157 necessary), but we don't want to pass this changed value on to
|
|
158 other functions that take both a nonreloc and a reloc, or things
|
|
159 may get confused and an assertion failure in
|
|
160 fixup_internal_substring() may get triggered. */
|
|
161 CONST Bufbyte *newnonreloc = nonreloc;
|
|
162 struct gcpro gcpro1, gcpro2;
|
|
163
|
|
164 /* Emacs won't print whilst GCing, but an external debugger might */
|
|
165 if (gc_in_progress) return;
|
|
166
|
|
167 /* Perhaps not necessary but probably safer. */
|
|
168 GCPRO2 (function, reloc);
|
|
169
|
|
170 fixup_internal_substring (newnonreloc, reloc, offset, &len);
|
|
171
|
|
172 if (STRINGP (reloc))
|
16
|
173 newnonreloc = XSTRING_DATA (reloc);
|
0
|
174
|
|
175 ccoff = bytecount_to_charcount (newnonreloc, offset);
|
|
176 cclen = bytecount_to_charcount (newnonreloc + offset, len);
|
|
177
|
|
178 if (LSTREAMP (function))
|
|
179 {
|
|
180 /* Lstream_write() could easily cause GC inside of it, if the
|
|
181 stream is a print-stream. (It will call output_string()
|
|
182 recursively.) This is probably the fastest way to fix this
|
|
183 problem. (alloca() is very fast on machines that have it
|
|
184 built-in, and you avoid some nasty problems with recursion
|
|
185 that could result from using a static buffer somewhere.)
|
|
186
|
|
187 The other possibility is to inhibit GC, but that of course
|
|
188 would require an unwind-protect, which is usually a lot
|
|
189 slower than the small amount of memcpy()ing that happens
|
|
190 here. */
|
|
191 if (STRINGP (reloc))
|
|
192 {
|
|
193 Bufbyte *copied = (Bufbyte *) alloca (len);
|
|
194 memcpy (copied, newnonreloc + offset, len);
|
|
195 Lstream_write (XLSTREAM (function), copied, len);
|
|
196 }
|
|
197 else
|
|
198 Lstream_write (XLSTREAM (function), newnonreloc + offset, len);
|
|
199
|
|
200 if (print_unbuffered)
|
|
201 Lstream_flush (XLSTREAM (function));
|
|
202 }
|
|
203
|
|
204 #ifndef standalone
|
|
205 else if (BUFFERP (function))
|
|
206 {
|
|
207 CHECK_LIVE_BUFFER (function);
|
|
208 buffer_insert_string (XBUFFER (function), nonreloc, reloc, offset, len);
|
|
209 }
|
|
210 else if (MARKERP (function))
|
|
211 {
|
|
212 /* marker_position will err if marker doesn't point anywhere */
|
|
213 Bufpos spoint = marker_position (function);
|
|
214
|
|
215 buffer_insert_string_1 (XBUFFER (Fmarker_buffer (function)),
|
|
216 spoint, nonreloc, reloc, offset, len,
|
|
217 0);
|
|
218 Fset_marker (function, make_int (spoint + cclen),
|
|
219 Fmarker_buffer (function));
|
|
220 }
|
|
221 else if (FRAMEP (function))
|
|
222 {
|
|
223 struct frame *f = XFRAME (function);
|
|
224 if (!EQ (Vprint_message_label, echo_area_status (f)))
|
|
225 clear_echo_area_from_print (f, Qnil, 1);
|
|
226 echo_area_append (f, nonreloc, reloc, offset, len, Vprint_message_label);
|
|
227 }
|
|
228 #endif /* not standalone */
|
|
229 else if (EQ (function, Qt) || EQ (function, Qnil))
|
|
230 {
|
|
231 write_string_to_stdio_stream (stdout, 0, newnonreloc, offset, len,
|
16
|
232 FORMAT_TERMINAL);
|
0
|
233 }
|
|
234 else
|
|
235 {
|
|
236 Charcount iii;
|
|
237
|
|
238 for (iii = ccoff; iii < cclen + ccoff; iii++)
|
|
239 {
|
|
240 call1 (function,
|
|
241 make_char (charptr_emchar_n (newnonreloc, iii)));
|
|
242 if (STRINGP (reloc))
|
16
|
243 newnonreloc = XSTRING_DATA (reloc);
|
0
|
244 }
|
|
245 }
|
|
246
|
|
247 UNGCPRO;
|
|
248 }
|
|
249
|
|
250 struct print_stream
|
|
251 {
|
|
252 FILE *file;
|
|
253 Lisp_Object fun;
|
|
254 };
|
|
255
|
|
256 #define get_print_stream(stream) \
|
|
257 ((struct print_stream *) Lstream_data (stream))
|
|
258
|
|
259 DEFINE_LSTREAM_IMPLEMENTATION ("print", lstream_print,
|
|
260 sizeof (struct print_stream));
|
|
261
|
|
262 static Lisp_Object
|
|
263 make_print_output_stream (FILE *file, Lisp_Object fun)
|
|
264 {
|
|
265 Lstream *str = Lstream_new (lstream_print, "w");
|
|
266 struct print_stream *ps = get_print_stream (str);
|
272
|
267 Lisp_Object val;
|
0
|
268
|
|
269 Lstream_set_character_mode (str);
|
|
270 ps->file = file;
|
|
271 ps->fun = fun;
|
|
272 XSETLSTREAM (val, str);
|
|
273 return val;
|
|
274 }
|
|
275
|
|
276 /* #### This isn't being used anywhere at the moment. Is it supposed
|
|
277 to be? */
|
|
278 #if 0
|
|
279 static void
|
|
280 reset_print_stream (Lstream *str, FILE *file, Lisp_Object fun)
|
|
281 {
|
|
282 struct print_stream *ps = get_print_stream (str);
|
|
283
|
|
284 Lstream_reopen (str);
|
|
285 ps->file = file;
|
|
286 ps->fun = fun;
|
|
287 }
|
|
288 #endif
|
|
289
|
|
290 static Lisp_Object
|
|
291 print_marker (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
292 {
|
|
293 return get_print_stream (XLSTREAM (obj))->fun;
|
|
294 }
|
|
295
|
|
296 static int
|
272
|
297 print_writer (Lstream *stream, CONST unsigned char *data, size_t size)
|
0
|
298 {
|
|
299 struct print_stream *ps = get_print_stream (stream);
|
|
300
|
|
301 if (ps->file)
|
|
302 {
|
|
303 write_string_to_stdio_stream (ps->file, 0, data, 0, size,
|
16
|
304 FORMAT_TERMINAL);
|
0
|
305 /* Make sure it really gets written now. */
|
|
306 if (print_unbuffered)
|
|
307 fflush (ps->file);
|
|
308 }
|
|
309 else
|
|
310 output_string (ps->fun, data, Qnil, 0, size);
|
|
311 return size;
|
|
312 }
|
|
313
|
|
314 static Lisp_Object
|
|
315 canonicalize_printcharfun (Lisp_Object printcharfun)
|
|
316 {
|
|
317 if (NILP (printcharfun))
|
|
318 printcharfun = Vstandard_output;
|
|
319
|
|
320 if (EQ (printcharfun, Qt) || NILP (printcharfun))
|
|
321 {
|
|
322 #ifndef standalone
|
|
323 printcharfun = Fselected_frame (Qnil); /* print to minibuffer */
|
|
324 #endif
|
|
325 }
|
173
|
326 return printcharfun;
|
0
|
327 }
|
|
328
|
|
329
|
|
330 static Lisp_Object
|
|
331 print_prepare (Lisp_Object printcharfun)
|
|
332 {
|
|
333 FILE *stdio_stream = 0;
|
|
334
|
|
335 /* Emacs won't print whilst GCing, but an external debugger might */
|
|
336 if (gc_in_progress)
|
173
|
337 return Qnil;
|
0
|
338
|
|
339 printcharfun = canonicalize_printcharfun (printcharfun);
|
272
|
340 if (NILP (printcharfun))
|
0
|
341 {
|
|
342 stdio_stream = stdout;
|
|
343 }
|
|
344 #if 0 /* Don't bother */
|
|
345 else if (SUBRP (indirect_function (printcharfun, 0))
|
173
|
346 && (XSUBR (indirect_function (printcharfun, 0))
|
0
|
347 == Sexternal_debugging_output))
|
|
348 {
|
|
349 stdio_stream = stderr;
|
|
350 }
|
|
351 #endif
|
245
|
352 if (!CONSP (Vprint_gensym))
|
|
353 Vprint_gensym_alist = Qnil;
|
173
|
354
|
0
|
355 return make_print_output_stream (stdio_stream, printcharfun);
|
|
356 }
|
|
357
|
|
358 static void
|
|
359 print_finish (Lisp_Object stream)
|
|
360 {
|
|
361 /* Emacs won't print whilst GCing, but an external debugger might */
|
|
362 if (gc_in_progress)
|
|
363 return;
|
|
364
|
245
|
365 if (!CONSP (Vprint_gensym))
|
|
366 Vprint_gensym_alist = Qnil;
|
|
367
|
0
|
368 Lstream_delete (XLSTREAM (stream));
|
|
369 }
|
|
370
|
|
371 #if 1 /* Prefer space over "speed" */
|
|
372 #define write_char_internal(string_of_length_1, stream) \
|
|
373 write_string_1 ((CONST Bufbyte *) (string_of_length_1), 1, (stream))
|
|
374 #else
|
|
375 #define write_char_internal(string_of_length_1, stream) \
|
|
376 output_string ((stream), (CONST Bufbyte *) (string_of_length_1), Qnil, 0, 1)
|
|
377 #endif
|
|
378
|
|
379 /* NOTE: Do not call this with the data of a Lisp_String,
|
|
380 * as printcharfun might cause a GC, which might cause
|
|
381 * the string's data to be relocated.
|
|
382 * Use print_object_internal (string, printcharfun, 0)
|
|
383 * to princ a Lisp_String
|
|
384 * Note: "stream" should be the result of "canonicalize_printcharfun"
|
|
385 * (ie Qnil means stdout, not Vstandard_output, etc)
|
|
386 */
|
|
387 void
|
|
388 write_string_1 (CONST Bufbyte *str, Bytecount size, Lisp_Object stream)
|
|
389 {
|
|
390 /* This function can GC */
|
|
391 assert (size >= 0);
|
|
392 output_string (stream, str, Qnil, 0, size);
|
|
393 }
|
|
394
|
|
395 void
|
|
396 write_c_string (CONST char *str, Lisp_Object stream)
|
|
397 {
|
|
398 /* This function can GC */
|
|
399 write_string_1 ((CONST Bufbyte *) str, strlen (str), stream);
|
|
400 }
|
|
401
|
|
402
|
20
|
403 DEFUN ("write-char", Fwrite_char, 1, 2, 0, /*
|
0
|
404 Output character CH to stream STREAM.
|
|
405 STREAM defaults to the value of `standard-output' (which see).
|
20
|
406 */
|
|
407 (ch, stream))
|
0
|
408 {
|
|
409 /* This function can GC */
|
|
410 Bufbyte str[MAX_EMCHAR_LEN];
|
|
411 Bytecount len;
|
|
412
|
|
413 CHECK_CHAR_COERCE_INT (ch);
|
|
414 len = set_charptr_emchar (str, XCHAR (ch));
|
|
415 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, len);
|
|
416 return ch;
|
|
417 }
|
|
418
|
|
419 #ifndef standalone
|
|
420
|
|
421 void
|
|
422 temp_output_buffer_setup (CONST char *bufname)
|
|
423 {
|
|
424 /* This function can GC */
|
|
425 struct buffer *old = current_buffer;
|
|
426 Lisp_Object buf;
|
|
427
|
|
428 #ifdef I18N3
|
|
429 /* #### This function should accept a Lisp_Object instead of a char *,
|
|
430 so that proper translation on the buffer name can occur. */
|
|
431 #endif
|
|
432
|
|
433 Fset_buffer (Fget_buffer_create (build_string (bufname)));
|
|
434
|
|
435 current_buffer->read_only = Qnil;
|
223
|
436 Ferase_buffer (Qnil);
|
0
|
437
|
|
438 XSETBUFFER (buf, current_buffer);
|
|
439 specbind (Qstandard_output, buf);
|
|
440
|
|
441 set_buffer_internal (old);
|
|
442 }
|
|
443
|
|
444 Lisp_Object
|
173
|
445 internal_with_output_to_temp_buffer (CONST char *bufname,
|
0
|
446 Lisp_Object (*function) (Lisp_Object arg),
|
173
|
447 Lisp_Object arg,
|
0
|
448 Lisp_Object same_frame)
|
|
449 {
|
|
450 int speccount = specpdl_depth ();
|
|
451 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
452 Lisp_Object buf = Qnil;
|
|
453
|
|
454 GCPRO3 (buf, arg, same_frame);
|
|
455
|
|
456 temp_output_buffer_setup (GETTEXT (bufname));
|
|
457 buf = Vstandard_output;
|
|
458
|
|
459 arg = (*function) (arg);
|
|
460
|
|
461 temp_output_buffer_show (buf, same_frame);
|
|
462 UNGCPRO;
|
|
463
|
|
464 return unbind_to (speccount, arg);
|
|
465 }
|
|
466
|
20
|
467 DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, 1, UNEVALLED, 0, /*
|
0
|
468 Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.
|
|
469 The buffer is cleared out initially, and marked as unmodified when done.
|
|
470 All output done by BODY is inserted in that buffer by default.
|
|
471 The buffer is displayed in another window, but not selected.
|
|
472 The value of the last form in BODY is returned.
|
|
473 If BODY does not finish normally, the buffer BUFNAME is not displayed.
|
|
474
|
|
475 If variable `temp-buffer-show-function' is non-nil, call it at the end
|
|
476 to get the buffer displayed. It gets one argument, the buffer to display.
|
20
|
477 */
|
|
478 (args))
|
0
|
479 {
|
|
480 /* This function can GC */
|
|
481 struct gcpro gcpro1;
|
|
482 Lisp_Object name;
|
|
483 int speccount = specpdl_depth ();
|
272
|
484 Lisp_Object val;
|
0
|
485
|
|
486 #ifdef I18N3
|
|
487 /* #### should set the buffer to be translating. See print_internal(). */
|
|
488 #endif
|
|
489
|
|
490 GCPRO1 (args);
|
272
|
491 name = Feval (XCAR (args));
|
0
|
492 UNGCPRO;
|
|
493
|
|
494 CHECK_STRING (name);
|
16
|
495 temp_output_buffer_setup ((char *) XSTRING_DATA (name));
|
0
|
496
|
272
|
497 val = Fprogn (XCDR (args));
|
0
|
498
|
272
|
499 temp_output_buffer_show (Vstandard_output, Qnil);
|
0
|
500
|
|
501 return unbind_to (speccount, val);
|
|
502 }
|
|
503 #endif /* not standalone */
|
|
504
|
20
|
505 DEFUN ("terpri", Fterpri, 0, 1, 0, /*
|
0
|
506 Output a newline to STREAM.
|
|
507 If STREAM is omitted or nil, the value of `standard-output' is used.
|
20
|
508 */
|
|
509 (stream))
|
0
|
510 {
|
|
511 /* This function can GC */
|
|
512 Bufbyte str[1];
|
|
513 str[0] = '\n';
|
|
514 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, 1);
|
|
515 return Qt;
|
|
516 }
|
|
517
|
20
|
518 DEFUN ("prin1", Fprin1, 1, 2, 0, /*
|
0
|
519 Output the printed representation of OBJECT, any Lisp object.
|
|
520 Quoting characters are printed when needed to make output that `read'
|
|
521 can handle, whenever this is possible.
|
|
522 Output stream is STREAM, or value of `standard-output' (which see).
|
20
|
523 */
|
|
524 (object, stream))
|
0
|
525 {
|
|
526 /* This function can GC */
|
|
527 Lisp_Object the_stream = Qnil;
|
|
528 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
529
|
|
530 GCPRO3 (object, stream, the_stream);
|
|
531 print_depth = 0;
|
|
532 the_stream = print_prepare (stream);
|
|
533 print_internal (object, the_stream, 1);
|
|
534 print_finish (the_stream);
|
|
535 UNGCPRO;
|
|
536 return object;
|
|
537 }
|
|
538
|
219
|
539 /* Stream to which prin1-to-string prints. */
|
|
540 static Lisp_Object Vprin1_to_string_stream;
|
0
|
541
|
20
|
542 DEFUN ("prin1-to-string", Fprin1_to_string, 1, 2, 0, /*
|
0
|
543 Return a string containing the printed representation of OBJECT,
|
|
544 any Lisp object. Quoting characters are used when needed to make output
|
|
545 that `read' can handle, whenever this is possible, unless the optional
|
|
546 second argument NOESCAPE is non-nil.
|
20
|
547 */
|
|
548 (object, noescape))
|
0
|
549 {
|
|
550 /* This function can GC */
|
219
|
551 Lisp_Object result = Qnil;
|
|
552 Lstream *stream;
|
|
553 struct gcpro gcpro1;
|
|
554
|
|
555 /* We avoid creating a new stream for every invocation of
|
|
556 prin1_to_string, for better memory usage. */
|
0
|
557
|
219
|
558 if (NILP (Vprin1_to_string_stream))
|
|
559 Vprin1_to_string_stream = make_resizing_buffer_output_stream ();
|
|
560 stream = XLSTREAM (Vprin1_to_string_stream);
|
|
561 Lstream_rewind (stream);
|
|
562
|
|
563 /* In case a caller forgot to protect. */
|
|
564 GCPRO1 (object);
|
0
|
565 print_depth = 0;
|
219
|
566 print_internal (object, Vprin1_to_string_stream, NILP (noescape));
|
|
567 Lstream_flush (stream);
|
0
|
568 UNGCPRO;
|
219
|
569 result = make_string (resizing_buffer_stream_ptr (stream),
|
|
570 Lstream_byte_count (stream));
|
|
571 return result;
|
0
|
572 }
|
|
573
|
20
|
574 DEFUN ("princ", Fprinc, 1, 2, 0, /*
|
0
|
575 Output the printed representation of OBJECT, any Lisp object.
|
|
576 No quoting characters are used; no delimiters are printed around
|
|
577 the contents of strings.
|
|
578 Output stream is STREAM, or value of standard-output (which see).
|
20
|
579 */
|
|
580 (obj, stream))
|
0
|
581 {
|
|
582 /* This function can GC */
|
|
583 Lisp_Object the_stream = Qnil;
|
|
584 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
585
|
|
586 GCPRO3 (obj, stream, the_stream);
|
|
587 the_stream = print_prepare (stream);
|
|
588 print_depth = 0;
|
|
589 print_internal (obj, the_stream, 0);
|
|
590 print_finish (the_stream);
|
|
591 UNGCPRO;
|
173
|
592 return obj;
|
0
|
593 }
|
|
594
|
20
|
595 DEFUN ("print", Fprint, 1, 2, 0, /*
|
0
|
596 Output the printed representation of OBJECT, with newlines around it.
|
|
597 Quoting characters are printed when needed to make output that `read'
|
|
598 can handle, whenever this is possible.
|
|
599 Output stream is STREAM, or value of `standard-output' (which see).
|
20
|
600 */
|
|
601 (obj, stream))
|
0
|
602 {
|
|
603 /* This function can GC */
|
|
604 Lisp_Object the_stream = Qnil;
|
|
605 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
606
|
|
607 GCPRO3 (obj, stream, the_stream);
|
|
608 the_stream = print_prepare (stream);
|
|
609 print_depth = 0;
|
|
610 write_char_internal ("\n", the_stream);
|
|
611 print_internal (obj, the_stream, 1);
|
|
612 write_char_internal ("\n", the_stream);
|
|
613 print_finish (the_stream);
|
|
614 UNGCPRO;
|
|
615 return obj;
|
|
616 }
|
|
617
|
171
|
618
|
|
619 /* Synched with Emacs 19.34 -- underlying implementation (incarnated
|
|
620 in print_error_message) is completely divergent, though. */
|
100
|
621 DEFUN ("error-message-string", Ferror_message_string, 1, 1, 0, /*
|
|
622 Convert an error value (ERROR-SYMBOL . DATA) to an error message.
|
|
623 */
|
167
|
624 (data))
|
100
|
625 {
|
171
|
626 /* This function can GC */
|
100
|
627
|
219
|
628 /* This should maybe use Vprin1_to_string_stream... However, it's
|
|
629 called sufficiently rarely, so I don't think it should matter. */
|
|
630 Lisp_Object stream = make_resizing_buffer_output_stream ();
|
|
631 struct gcpro gcpro1;
|
|
632 GCPRO1 (stream);
|
|
633
|
|
634 print_error_message (data, stream);
|
|
635 Lstream_flush (XLSTREAM (stream));
|
100
|
636 UNGCPRO;
|
219
|
637 return make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
|
|
638 Lstream_byte_count (XLSTREAM (stream)));
|
100
|
639 }
|
|
640
|
171
|
641 /* Print an error message for the error DATA onto Lisp output stream
|
|
642 STREAM (suitable for the print functions).
|
100
|
643
|
171
|
644 This is a complete implementation of `display-error', which used to
|
|
645 be in Lisp (see prim/cmdloop.el). It was ported to C so we can use
|
|
646 it in Ferror_message_string. Fdisplay_error and
|
|
647 Ferror_message_string are trivial wrappers to this function. */
|
|
648 static void
|
|
649 print_error_message (Lisp_Object error_object, Lisp_Object stream)
|
100
|
650 {
|
171
|
651 /* This function can GC */
|
|
652 Lisp_Object type;
|
|
653 Lisp_Object method = Qnil;
|
|
654 Lisp_Object tail = Qnil;
|
100
|
655 struct gcpro gcpro1;
|
171
|
656
|
|
657 GCPRO1 (tail);
|
|
658
|
|
659 type = Fcar_safe (error_object);
|
|
660
|
|
661 if (! (CONSP (error_object) && SYMBOLP (type)
|
|
662 && CONSP (Fget (type, Qerror_conditions, Qnil))))
|
|
663 goto error_throw;
|
100
|
664
|
171
|
665 tail = XCDR (error_object);
|
|
666 while (!NILP (tail))
|
|
667 {
|
|
668 if (CONSP (tail))
|
|
669 tail = XCDR (tail);
|
|
670 else
|
|
671 goto error_throw;
|
|
672 }
|
|
673 tail = Fget (type, Qerror_conditions, Qnil);
|
|
674 while (!NILP (tail))
|
100
|
675 {
|
171
|
676 if (!(CONSP (tail) && SYMBOLP (XCAR (tail))))
|
|
677 goto error_throw;
|
|
678 else if (!NILP (Fget (XCAR (tail), Qdisplay_error, Qnil)))
|
|
679 {
|
|
680 method = Fget (XCAR (tail), Qdisplay_error, Qnil);
|
|
681 goto error_throw;
|
|
682 }
|
|
683 else
|
|
684 tail = XCDR (tail);
|
|
685 }
|
|
686 /* Default method */
|
|
687 {
|
|
688 int first = 1;
|
|
689 Lisp_Object printcharfun = canonicalize_printcharfun (stream);
|
|
690 int speccount = specpdl_depth ();
|
|
691
|
|
692 specbind (Qprint_message_label, Qerror);
|
|
693 tail = Fcdr (error_object);
|
|
694 if (EQ (type, Qerror))
|
|
695 {
|
|
696 Fprinc (Fcar (tail), stream);
|
|
697 tail = Fcdr (tail);
|
|
698 }
|
|
699 else
|
|
700 {
|
|
701 Lisp_Object errmsg = Fget (type, Qerror_message, Qnil);
|
|
702 if (NILP (errmsg))
|
|
703 Fprinc (type, stream);
|
|
704 else
|
|
705 Fprinc (errmsg, stream);
|
|
706 }
|
|
707 while (!NILP (tail))
|
|
708 {
|
|
709 write_c_string (first ? ": " : ", ", printcharfun);
|
|
710 Fprin1 (Fcar (tail), stream);
|
|
711 tail = Fcdr (tail);
|
|
712 first = 0;
|
|
713 }
|
|
714 unbind_to (speccount, Qnil);
|
|
715 UNGCPRO;
|
|
716 return;
|
|
717 /* Unreached */
|
|
718 }
|
|
719
|
|
720 error_throw:
|
|
721 UNGCPRO;
|
|
722 if (NILP (method))
|
|
723 {
|
|
724 write_c_string ("Peculiar error ",
|
|
725 canonicalize_printcharfun (stream));
|
|
726 Fprin1 (error_object, stream);
|
|
727 return;
|
100
|
728 }
|
|
729 else
|
|
730 {
|
171
|
731 call2 (method, error_object, stream);
|
100
|
732 }
|
171
|
733 }
|
100
|
734
|
171
|
735 DEFUN ("display-error", Fdisplay_error, 2, 2, 0, /*
|
|
736 Display an error message for ERROR-OBJECT to STREAM.
|
|
737 */
|
|
738 (error_object, stream))
|
|
739 {
|
|
740 /* This function can GC */
|
|
741 print_error_message (error_object, stream);
|
|
742 return Qnil;
|
|
743 }
|
100
|
744
|
|
745
|
0
|
746 #ifdef LISP_FLOAT_TYPE
|
|
747
|
|
748 Lisp_Object Vfloat_output_format;
|
|
749 Lisp_Object Qfloat_output_format;
|
|
750
|
|
751 void
|
|
752 float_to_string (char *buf, double data)
|
|
753 /*
|
|
754 * This buffer should be at least as large as the max string size of the
|
|
755 * largest float, printed in the biggest notation. This is undoubtably
|
|
756 * 20d float_output_format, with the negative of the C-constant "HUGE"
|
|
757 * from <math.h>.
|
173
|
758 *
|
0
|
759 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
|
173
|
760 *
|
0
|
761 * I assume that IEEE-754 format numbers can take 329 bytes for the worst
|
|
762 * case of -1e307 in 20d float_output_format. What is one to do (short of
|
|
763 * re-writing _doprnt to be more sane)?
|
|
764 * -wsr
|
|
765 */
|
|
766 {
|
|
767 Bufbyte *cp, c;
|
|
768 int width;
|
173
|
769
|
0
|
770 if (NILP (Vfloat_output_format)
|
|
771 || !STRINGP (Vfloat_output_format))
|
|
772 lose:
|
|
773 sprintf (buf, "%.16g", data);
|
|
774 else /* oink oink */
|
|
775 {
|
|
776 /* Check that the spec we have is fully valid.
|
|
777 This means not only valid for printf,
|
|
778 but meant for floats, and reasonable. */
|
16
|
779 cp = XSTRING_DATA (Vfloat_output_format);
|
0
|
780
|
|
781 if (cp[0] != '%')
|
|
782 goto lose;
|
|
783 if (cp[1] != '.')
|
|
784 goto lose;
|
|
785
|
|
786 cp += 2;
|
|
787 for (width = 0; (c = *cp, isdigit (c)); cp++)
|
|
788 {
|
|
789 width *= 10;
|
|
790 width += c - '0';
|
|
791 }
|
|
792
|
173
|
793 if (*cp != 'e' && *cp != 'f' && *cp != 'g' && *cp != 'E' && *cp != 'G')
|
0
|
794 goto lose;
|
|
795
|
|
796 if (width < (int) (*cp != 'e' && *cp != 'E') || width > DBL_DIG)
|
|
797 goto lose;
|
|
798
|
|
799 if (cp[1] != 0)
|
|
800 goto lose;
|
|
801
|
16
|
802 sprintf (buf, (char *) XSTRING_DATA (Vfloat_output_format),
|
0
|
803 data);
|
|
804 }
|
|
805
|
|
806 /* added by jwz: don't allow "1.0" to print as "1"; that destroys
|
|
807 the read-equivalence of lisp objects. (* x 1) and (* x 1.0) do
|
|
808 not do the same thing, so it's important that the printed
|
|
809 representation of that form not be corrupted by the printer.
|
|
810 */
|
|
811 {
|
|
812 Bufbyte *s = (Bufbyte *) buf; /* don't use signed chars here!
|
|
813 isdigit() can't hack them! */
|
|
814 if (*s == '-') s++;
|
|
815 for (; *s; s++)
|
|
816 /* if there's a non-digit, then there is a decimal point, or
|
|
817 it's in exponential notation, both of which are ok. */
|
|
818 if (!isdigit (*s))
|
|
819 goto DONE_LABEL;
|
|
820 /* otherwise, we need to hack it. */
|
|
821 *s++ = '.';
|
|
822 *s++ = '0';
|
|
823 *s = 0;
|
|
824 }
|
|
825 DONE_LABEL:
|
|
826
|
|
827 /* Some machines print "0.4" as ".4". I don't like that. */
|
|
828 if (buf [0] == '.' || (buf [0] == '-' && buf [1] == '.'))
|
|
829 {
|
|
830 int i;
|
|
831 for (i = strlen (buf) + 1; i >= 0; i--)
|
|
832 buf [i+1] = buf [i];
|
|
833 buf [(buf [0] == '-' ? 1 : 0)] = '0';
|
|
834 }
|
|
835 }
|
|
836 #endif /* LISP_FLOAT_TYPE */
|
|
837
|
|
838 static void
|
|
839 print_vector_internal (CONST char *start, CONST char *end,
|
173
|
840 Lisp_Object obj,
|
0
|
841 Lisp_Object printcharfun, int escapeflag)
|
|
842 {
|
|
843 /* This function can GC */
|
|
844 int i;
|
173
|
845 int len = XVECTOR_LENGTH (obj);
|
0
|
846 int last = len;
|
|
847 struct gcpro gcpro1, gcpro2;
|
|
848 GCPRO2 (obj, printcharfun);
|
|
849
|
|
850 if (INTP (Vprint_length))
|
|
851 {
|
|
852 int max = XINT (Vprint_length);
|
|
853 if (max < len) last = max;
|
|
854 }
|
|
855
|
|
856 write_c_string (start, printcharfun);
|
|
857 for (i = 0; i < last; i++)
|
|
858 {
|
173
|
859 Lisp_Object elt = XVECTOR_DATA (obj)[i];
|
0
|
860 if (i != 0) write_char_internal (" ", printcharfun);
|
|
861 print_internal (elt, printcharfun, escapeflag);
|
|
862 }
|
|
863 UNGCPRO;
|
|
864 if (last != len)
|
|
865 write_c_string (" ...", printcharfun);
|
|
866 write_c_string (end, printcharfun);
|
|
867 }
|
|
868
|
207
|
869 void
|
|
870 print_cons (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
871 {
|
|
872 /* This function can GC */
|
|
873 struct gcpro gcpro1, gcpro2;
|
|
874
|
|
875 /* If print_readably is on, print (quote -foo-) as '-foo-
|
|
876 (Yeah, this should really be what print-pretty does, but we
|
|
877 don't have the rest of a pretty printer, and this actually
|
|
878 has non-negligible impact on size/speed of .elc files.)
|
|
879 */
|
|
880 if (print_readably &&
|
|
881 EQ (XCAR (obj), Qquote) &&
|
|
882 CONSP (XCDR (obj)) &&
|
|
883 NILP (XCDR (XCDR (obj))))
|
|
884 {
|
|
885 obj = XCAR (XCDR (obj));
|
|
886 GCPRO2 (obj, printcharfun);
|
|
887 write_char_internal ("'", printcharfun);
|
|
888 UNGCPRO;
|
|
889 print_internal (obj, printcharfun, escapeflag);
|
|
890 return;
|
|
891 }
|
|
892
|
|
893 GCPRO2 (obj, printcharfun);
|
|
894 write_char_internal ("(", printcharfun);
|
|
895 {
|
|
896 int i = 0;
|
|
897 int max = 0;
|
|
898
|
|
899 if (INTP (Vprint_length))
|
|
900 max = XINT (Vprint_length);
|
|
901 while (CONSP (obj))
|
|
902 {
|
|
903 if (i++)
|
|
904 write_char_internal (" ", printcharfun);
|
|
905 if (max && i > max)
|
|
906 {
|
|
907 write_c_string ("...", printcharfun);
|
|
908 break;
|
|
909 }
|
245
|
910 print_internal (XCAR (obj), printcharfun,
|
207
|
911 escapeflag);
|
245
|
912 obj = XCDR (obj);
|
207
|
913 }
|
|
914 }
|
272
|
915 if (!LISTP (obj))
|
207
|
916 {
|
|
917 write_c_string (" . ", printcharfun);
|
|
918 print_internal (obj, printcharfun, escapeflag);
|
|
919 }
|
|
920 UNGCPRO;
|
|
921 write_char_internal (")", printcharfun);
|
|
922 return;
|
|
923 }
|
|
924
|
|
925 void
|
|
926 print_vector (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
927 {
|
|
928 print_vector_internal ("[", "]", obj, printcharfun, escapeflag);
|
|
929 }
|
|
930
|
|
931 void
|
|
932 print_string (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
933 {
|
245
|
934 struct Lisp_String *s = XSTRING (obj);
|
|
935 /* We distinguish between Bytecounts and Charcounts, to make
|
|
936 Vprint_string_length work correctly under Mule. */
|
|
937 Charcount size = string_char_length (s);
|
|
938 Charcount max = size;
|
|
939 Bytecount bcmax = string_length (s);
|
207
|
940 struct gcpro gcpro1, gcpro2;
|
|
941 GCPRO2 (obj, printcharfun);
|
|
942
|
|
943 if (INTP (Vprint_string_length) &&
|
|
944 XINT (Vprint_string_length) < max)
|
245
|
945 {
|
|
946 max = XINT (Vprint_string_length);
|
|
947 bcmax = charcount_to_bytecount (string_data (s), max);
|
|
948 }
|
207
|
949 if (max < 0)
|
245
|
950 {
|
|
951 max = 0;
|
|
952 bcmax = 0;
|
|
953 }
|
207
|
954
|
|
955 if (!escapeflag)
|
|
956 {
|
245
|
957 /* This deals with GC-relocation and Mule. */
|
|
958 output_string (printcharfun, 0, obj, 0, bcmax);
|
207
|
959 if (max < size)
|
|
960 write_c_string (" ...", printcharfun);
|
|
961 }
|
|
962 else
|
|
963 {
|
245
|
964 Bytecount i, last = 0;
|
207
|
965
|
|
966 write_char_internal ("\"", printcharfun);
|
245
|
967 for (i = 0; i < bcmax; i++)
|
207
|
968 {
|
|
969 Bufbyte ch = string_byte (s, i);
|
|
970 if (ch == '\"' || ch == '\\'
|
|
971 || (ch == '\n' && print_escape_newlines))
|
|
972 {
|
|
973 if (i > last)
|
|
974 {
|
|
975 output_string (printcharfun, 0, obj, last,
|
|
976 i - last);
|
|
977 }
|
|
978 if (ch == '\n')
|
|
979 {
|
|
980 write_c_string ("\\n", printcharfun);
|
|
981 }
|
|
982 else
|
|
983 {
|
|
984 write_char_internal ("\\", printcharfun);
|
|
985 /* This is correct for Mule because the
|
|
986 character is either \ or " */
|
|
987 write_char_internal ((char *) (string_data (s) + i),
|
|
988 printcharfun);
|
|
989 }
|
|
990 last = i + 1;
|
|
991 }
|
|
992 }
|
245
|
993 if (bcmax > last)
|
207
|
994 {
|
|
995 output_string (printcharfun, 0, obj, last,
|
245
|
996 bcmax - last);
|
207
|
997 }
|
|
998 if (max < size)
|
|
999 write_c_string (" ...", printcharfun);
|
|
1000 write_char_internal ("\"", printcharfun);
|
|
1001 }
|
|
1002 UNGCPRO;
|
|
1003 return;
|
|
1004 }
|
|
1005
|
|
1006
|
0
|
1007 static void
|
|
1008 default_object_printer (Lisp_Object obj, Lisp_Object printcharfun,
|
|
1009 int escapeflag)
|
|
1010 {
|
|
1011 struct lcrecord_header *header =
|
|
1012 (struct lcrecord_header *) XPNTR (obj);
|
|
1013 char buf[200];
|
|
1014
|
|
1015 if (print_readably)
|
|
1016 error ("printing unreadable object #<%s 0x%x>",
|
211
|
1017 LHEADER_IMPLEMENTATION (&header->lheader)->name,
|
|
1018 header->uid);
|
0
|
1019
|
211
|
1020 sprintf (buf, "#<%s 0x%x>",
|
|
1021 LHEADER_IMPLEMENTATION (&header->lheader)->name,
|
0
|
1022 header->uid);
|
|
1023 write_c_string (buf, printcharfun);
|
|
1024 }
|
|
1025
|
|
1026 void
|
|
1027 internal_object_printer (Lisp_Object obj, Lisp_Object printcharfun,
|
|
1028 int escapeflag)
|
|
1029 {
|
|
1030 char buf[200];
|
173
|
1031 sprintf (buf, "#<INTERNAL OBJECT (XEmacs bug?) (%s) 0x%p>",
|
211
|
1032 XRECORD_LHEADER_IMPLEMENTATION (obj)->name,
|
173
|
1033 (void *) XPNTR (obj));
|
0
|
1034 write_c_string (buf, printcharfun);
|
|
1035 }
|
|
1036
|
|
1037 void
|
|
1038 print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1039 {
|
|
1040 /* This function can GC */
|
|
1041 char buf[256];
|
|
1042
|
|
1043 QUIT;
|
|
1044
|
|
1045 /* Emacs won't print whilst GCing, but an external debugger might */
|
|
1046 if (gc_in_progress) return;
|
|
1047
|
|
1048 #ifdef I18N3
|
|
1049 /* #### Both input and output streams should have a flag associated
|
|
1050 with them indicating whether output to that stream, or strings
|
|
1051 read from the stream, get translated using Fgettext(). Such a
|
|
1052 stream is called a "translating stream". For the minibuffer and
|
|
1053 external-debugging-output this is always true on output, and
|
|
1054 with-output-to-temp-buffer sets the flag to true for the buffer
|
|
1055 it creates. This flag should also be user-settable. Perhaps it
|
|
1056 should be split up into two flags, one for input and one for
|
|
1057 output. */
|
|
1058 #endif
|
|
1059
|
177
|
1060 /* Detect circularities and truncate them.
|
|
1061 No need to offer any alternative--this is better than an error. */
|
|
1062 if (CONSP (obj) || VECTORP (obj) || COMPILED_FUNCTIONP (obj))
|
|
1063 {
|
|
1064 int i;
|
|
1065 for (i = 0; i < print_depth; i++)
|
|
1066 if (EQ (obj, being_printed[i]))
|
|
1067 {
|
|
1068 sprintf (buf, "#%d", i);
|
|
1069 write_c_string (buf, printcharfun);
|
|
1070 return;
|
|
1071 }
|
|
1072 }
|
|
1073
|
|
1074
|
|
1075 being_printed[print_depth] = obj;
|
0
|
1076 print_depth++;
|
|
1077
|
177
|
1078 if (print_depth > PRINT_CIRCLE)
|
0
|
1079 error ("Apparently circular structure being printed");
|
|
1080
|
|
1081 switch (XTYPE (obj))
|
|
1082 {
|
207
|
1083 #ifdef USE_MINIMAL_TAGBITS
|
|
1084 case Lisp_Type_Int_Even:
|
|
1085 case Lisp_Type_Int_Odd:
|
|
1086 #else
|
185
|
1087 case Lisp_Type_Int:
|
207
|
1088 #endif
|
0
|
1089 {
|
173
|
1090 sprintf (buf, "%ld", (long) XINT (obj));
|
0
|
1091 write_c_string (buf, printcharfun);
|
|
1092 break;
|
|
1093 }
|
|
1094
|
185
|
1095 case Lisp_Type_Char:
|
70
|
1096 {
|
|
1097 /* God intended that this be #\..., you know. */
|
|
1098 Emchar ch = XCHAR (obj);
|
|
1099 write_c_string ("?", printcharfun);
|
|
1100 if (ch == '\n')
|
|
1101 strcpy (buf, "\\n");
|
|
1102 else if (ch == '\r')
|
|
1103 strcpy (buf, "\\r");
|
|
1104 else if (ch == '\t')
|
|
1105 strcpy (buf, "\\t");
|
187
|
1106 else if (ch < 32) {
|
70
|
1107 sprintf (buf, "\\^%c", ch + 64);
|
187
|
1108 if ((ch + 64) == '\\') {
|
|
1109 strcat(buf, "\\");
|
|
1110 }
|
|
1111 } else if (ch == 127)
|
70
|
1112 strcpy (buf, "\\^?");
|
|
1113 else if (ch >= 128 && ch < 160)
|
|
1114 {
|
|
1115 Bytecount i;
|
|
1116 strcpy (buf, "\\^");
|
|
1117 i = set_charptr_emchar ((unsigned char *) (buf + 2), ch + 64);
|
|
1118 buf[2+i] = '\0';
|
|
1119 }
|
|
1120 else if (ch < 127
|
|
1121 && !isdigit (ch)
|
|
1122 && !isalpha (ch)
|
|
1123 && ch != '^') /* must not backslash this or it will
|
|
1124 be interpreted as the start of a
|
|
1125 control char */
|
|
1126 sprintf (buf, "\\%c", ch);
|
|
1127 else
|
|
1128 {
|
|
1129 Bytecount i;
|
|
1130 i = set_charptr_emchar ((unsigned char *) buf, ch);
|
|
1131 buf[i] = '\0';
|
|
1132 }
|
|
1133 write_c_string (buf, printcharfun);
|
|
1134 break;
|
|
1135 }
|
|
1136
|
207
|
1137 #ifndef LRECORD_STRING
|
185
|
1138 case Lisp_Type_String:
|
0
|
1139 {
|
207
|
1140 print_string(obj, printcharfun, escapeflag);
|
0
|
1141 break;
|
|
1142 }
|
207
|
1143 #endif /* ! LRECORD_STRING */
|
0
|
1144
|
207
|
1145 #ifndef LRECORD_CONS
|
185
|
1146 case Lisp_Type_Cons:
|
0
|
1147 {
|
|
1148 struct gcpro gcpro1, gcpro2;
|
|
1149
|
|
1150 /* If deeper than spec'd depth, print placeholder. */
|
|
1151 if (INTP (Vprint_level)
|
|
1152 && print_depth > XINT (Vprint_level))
|
|
1153 {
|
207
|
1154 GCPRO2 (obj, printcharfun);
|
0
|
1155 write_c_string ("...", printcharfun);
|
|
1156 UNGCPRO;
|
|
1157 break;
|
|
1158 }
|
|
1159
|
207
|
1160 print_cons (obj, printcharfun, escapeflag);
|
0
|
1161 break;
|
|
1162 }
|
207
|
1163 #endif /* ! LRECORD_CONS */
|
0
|
1164
|
|
1165 #ifndef LRECORD_VECTOR
|
185
|
1166 case Lisp_Type_Vector:
|
0
|
1167 {
|
207
|
1168 struct gcpro gcpro1, gcpro2;
|
|
1169
|
0
|
1170 /* If deeper than spec'd depth, print placeholder. */
|
|
1171 if (INTP (Vprint_level)
|
|
1172 && print_depth > XINT (Vprint_level))
|
|
1173 {
|
207
|
1174 GCPRO2 (obj, printcharfun);
|
0
|
1175 write_c_string ("...", printcharfun);
|
207
|
1176 UNGCPRO;
|
0
|
1177 break;
|
|
1178 }
|
|
1179
|
|
1180 /* God intended that this be #(...), you know. */
|
|
1181 print_vector_internal ("[", "]", obj, printcharfun, escapeflag);
|
|
1182 break;
|
|
1183 }
|
|
1184 #endif /* !LRECORD_VECTOR */
|
|
1185
|
|
1186 #ifndef LRECORD_SYMBOL
|
185
|
1187 case Lisp_Type_Symbol:
|
0
|
1188 {
|
|
1189 print_symbol (obj, printcharfun, escapeflag);
|
|
1190 break;
|
|
1191 }
|
|
1192 #endif /* !LRECORD_SYMBOL */
|
|
1193
|
185
|
1194 case Lisp_Type_Record:
|
0
|
1195 {
|
|
1196 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
|
|
1197 struct gcpro gcpro1, gcpro2;
|
|
1198
|
207
|
1199 #if defined(LRECORD_CONS) || defined(LRECORD_VECTOR)
|
|
1200 if (CONSP (obj) || VECTORP(obj))
|
|
1201 {
|
|
1202 /* If deeper than spec'd depth, print placeholder. */
|
|
1203 if (INTP (Vprint_level)
|
|
1204 && print_depth > XINT (Vprint_level))
|
|
1205 {
|
|
1206 GCPRO2 (obj, printcharfun);
|
|
1207 write_c_string ("...", printcharfun);
|
|
1208 UNGCPRO;
|
|
1209 break;
|
|
1210 }
|
|
1211 }
|
|
1212 #endif
|
|
1213
|
0
|
1214 GCPRO2 (obj, printcharfun);
|
211
|
1215 if (LHEADER_IMPLEMENTATION (lheader)->printer)
|
|
1216 ((LHEADER_IMPLEMENTATION (lheader)->printer)
|
0
|
1217 (obj, printcharfun, escapeflag));
|
|
1218 else
|
|
1219 default_object_printer (obj, printcharfun, escapeflag);
|
|
1220 UNGCPRO;
|
|
1221 break;
|
|
1222 }
|
|
1223
|
|
1224 default:
|
|
1225 {
|
|
1226 /* We're in trouble if this happens!
|
|
1227 Probably should just abort () */
|
|
1228 if (print_readably)
|
|
1229 error ("printing illegal data type #o%03o",
|
|
1230 (int) XTYPE (obj));
|
|
1231 write_c_string ("#<EMACS BUG: ILLEGAL DATATYPE ",
|
|
1232 printcharfun);
|
|
1233 sprintf (buf, "(#o%3o)", (int) XTYPE (obj));
|
|
1234 write_c_string (buf, printcharfun);
|
|
1235 write_c_string
|
|
1236 (" Save your buffers immediately and please report this bug>",
|
|
1237 printcharfun);
|
|
1238 break;
|
|
1239 }
|
|
1240 }
|
|
1241
|
|
1242 print_depth--;
|
|
1243 }
|
|
1244
|
|
1245 static void
|
|
1246 print_compiled_function_internal (CONST char *start, CONST char *end,
|
173
|
1247 Lisp_Object obj,
|
0
|
1248 Lisp_Object printcharfun, int escapeflag)
|
|
1249 {
|
|
1250 /* This function can GC */
|
|
1251 struct Lisp_Compiled_Function *b =
|
|
1252 XCOMPILED_FUNCTION (obj); /* GC doesn't relocate */
|
|
1253 int docp = b->flags.documentationp;
|
|
1254 int intp = b->flags.interactivep;
|
|
1255 struct gcpro gcpro1, gcpro2;
|
|
1256 char buf[100];
|
|
1257 GCPRO2 (obj, printcharfun);
|
|
1258
|
|
1259 write_c_string (start, printcharfun);
|
|
1260 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1261 if (!print_readably)
|
|
1262 {
|
|
1263 Lisp_Object ann = compiled_function_annotation (b);
|
|
1264 if (!NILP (ann))
|
|
1265 {
|
|
1266 write_c_string ("(from ", printcharfun);
|
|
1267 print_internal (ann, printcharfun, 1);
|
|
1268 write_c_string (") ", printcharfun);
|
|
1269 }
|
|
1270 }
|
|
1271 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */
|
|
1272 /* COMPILED_ARGLIST = 0 */
|
|
1273 print_internal (b->arglist, printcharfun, escapeflag);
|
|
1274 /* COMPILED_BYTECODE = 1 */
|
|
1275 write_char_internal (" ", printcharfun);
|
|
1276 /* we don't really want to see that junk in the bytecode instructions. */
|
|
1277 if (STRINGP (b->bytecodes) && !print_readably)
|
|
1278 {
|
16
|
1279 sprintf (buf, "\"...(%ld)\"", (long) XSTRING_LENGTH (b->bytecodes));
|
0
|
1280 write_c_string (buf, printcharfun);
|
|
1281 }
|
|
1282 else
|
|
1283 print_internal (b->bytecodes, printcharfun, escapeflag);
|
|
1284 /* COMPILED_CONSTANTS = 2 */
|
|
1285 write_char_internal (" ", printcharfun);
|
|
1286 print_internal (b->constants, printcharfun, escapeflag);
|
|
1287 /* COMPILED_STACK_DEPTH = 3 */
|
|
1288 sprintf (buf, " %d", b->maxdepth);
|
|
1289 write_c_string (buf, printcharfun);
|
|
1290 /* COMPILED_DOC_STRING = 4 */
|
|
1291 if (docp || intp)
|
|
1292 {
|
|
1293 write_char_internal (" ", printcharfun);
|
|
1294 print_internal (compiled_function_documentation (b), printcharfun,
|
|
1295 escapeflag);
|
|
1296 }
|
|
1297 /* COMPILED_INTERACTIVE = 5 */
|
|
1298 if (intp)
|
|
1299 {
|
|
1300 write_char_internal (" ", printcharfun);
|
|
1301 print_internal (compiled_function_interactive (b), printcharfun,
|
|
1302 escapeflag);
|
|
1303 }
|
|
1304 UNGCPRO;
|
|
1305 write_c_string (end, printcharfun);
|
|
1306 }
|
|
1307
|
|
1308 void
|
|
1309 print_compiled_function (Lisp_Object obj, Lisp_Object printcharfun,
|
|
1310 int escapeflag)
|
|
1311 {
|
|
1312 /* This function can GC */
|
|
1313 print_compiled_function_internal (((print_readably) ? "#[" :
|
|
1314 "#<compiled-function "),
|
|
1315 ((print_readably) ? "]" : ">"),
|
|
1316 obj, printcharfun, escapeflag);
|
|
1317 }
|
|
1318
|
|
1319 #ifdef LISP_FLOAT_TYPE
|
|
1320 void
|
|
1321 print_float (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1322 {
|
|
1323 char pigbuf[350]; /* see comments in float_to_string */
|
|
1324
|
|
1325 float_to_string (pigbuf, float_data (XFLOAT (obj)));
|
|
1326 write_c_string (pigbuf, printcharfun);
|
|
1327 }
|
|
1328 #endif /* LISP_FLOAT_TYPE */
|
|
1329
|
|
1330 void
|
|
1331 print_symbol (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1332 {
|
|
1333 /* This function can GC */
|
|
1334 /* #### Bug!! (intern "") isn't printed in some distinguished way */
|
|
1335 /* #### (the reader also loses on it) */
|
|
1336 struct Lisp_String *name = XSYMBOL (obj)->name;
|
|
1337 Bytecount size = string_length (name);
|
|
1338 struct gcpro gcpro1, gcpro2;
|
|
1339
|
|
1340 if (!escapeflag)
|
|
1341 {
|
|
1342 /* This deals with GC-relocation */
|
|
1343 Lisp_Object nameobj;
|
|
1344 XSETSTRING (nameobj, name);
|
|
1345 output_string (printcharfun, 0, nameobj, 0, size);
|
|
1346 return;
|
|
1347 }
|
|
1348 GCPRO2 (obj, printcharfun);
|
|
1349
|
245
|
1350 /* If we print an uninterned symbol as part of a complex object and
|
|
1351 the flag print-gensym is non-nil, prefix it with #n= to read the
|
|
1352 object back with the #n# reader syntax later if needed. */
|
|
1353 if (!NILP (Vprint_gensym) && NILP (XSYMBOL (obj)->obarray))
|
0
|
1354 {
|
245
|
1355 if (print_depth > 1)
|
|
1356 {
|
|
1357 Lisp_Object tem = Fassq (obj, Vprint_gensym_alist);
|
|
1358 if (CONSP (tem))
|
|
1359 {
|
|
1360 write_char_internal ("#", printcharfun);
|
|
1361 print_internal (XCDR (tem), printcharfun, escapeflag);
|
|
1362 write_char_internal ("#", printcharfun);
|
|
1363 return;
|
|
1364 }
|
|
1365 else
|
|
1366 {
|
|
1367 if (CONSP (Vprint_gensym_alist))
|
251
|
1368 {
|
|
1369 /* Vprint_gensym_alist is exposed to Lisp, so we
|
|
1370 have to be careful. */
|
|
1371 CHECK_CONS (XCAR (Vprint_gensym_alist));
|
|
1372 CHECK_INT (XCDR (XCAR (Vprint_gensym_alist)));
|
|
1373 XSETINT (tem, XINT (XCDR (XCAR (Vprint_gensym_alist))) + 1);
|
|
1374 }
|
245
|
1375 else
|
|
1376 XSETINT (tem, 1);
|
|
1377 Vprint_gensym_alist = Fcons (Fcons (obj, tem), Vprint_gensym_alist);
|
|
1378
|
|
1379 write_char_internal ("#", printcharfun);
|
|
1380 print_internal (tem, printcharfun, escapeflag);
|
|
1381 write_char_internal ("=", printcharfun);
|
|
1382 }
|
|
1383 }
|
|
1384 write_c_string ("#:", printcharfun);
|
0
|
1385 }
|
|
1386
|
|
1387 /* Does it look like an integer or a float? */
|
|
1388 {
|
|
1389 Bufbyte *data = string_data (name);
|
|
1390 Bytecount confusing = 0;
|
|
1391
|
|
1392 if (size == 0)
|
|
1393 goto not_yet_confused; /* Really confusing */
|
|
1394 else if (isdigit (data[0]))
|
|
1395 confusing = 0;
|
|
1396 else if (size == 1)
|
|
1397 goto not_yet_confused;
|
|
1398 else if (data[0] == '-' || data[0] == '+')
|
|
1399 confusing = 1;
|
|
1400 else
|
|
1401 goto not_yet_confused;
|
|
1402
|
|
1403 for (; confusing < size; confusing++)
|
173
|
1404 {
|
0
|
1405 if (!isdigit (data[confusing]))
|
|
1406 {
|
|
1407 confusing = 0;
|
|
1408 break;
|
|
1409 }
|
|
1410 }
|
|
1411 not_yet_confused:
|
|
1412
|
|
1413 #ifdef LISP_FLOAT_TYPE
|
|
1414 if (!confusing)
|
|
1415 confusing = isfloat_string ((char *) data);
|
|
1416 #endif
|
|
1417 if (confusing)
|
|
1418 write_char_internal ("\\", printcharfun);
|
|
1419 }
|
|
1420
|
|
1421 {
|
|
1422 Lisp_Object nameobj;
|
|
1423 Bytecount i;
|
|
1424 Bytecount last = 0;
|
173
|
1425
|
0
|
1426 XSETSTRING (nameobj, name);
|
|
1427 for (i = 0; i < size; i++)
|
|
1428 {
|
|
1429 Bufbyte c = string_byte (name, i);
|
|
1430
|
|
1431 if (c == '\"' || c == '\\' || c == '\'' || c == ';' || c == '#' ||
|
|
1432 c == '(' || c == ')' || c == ',' || c =='.' || c == '`' ||
|
|
1433 c == '[' || c == ']' || c == '?' || c <= 040)
|
|
1434 {
|
|
1435 if (i > last)
|
|
1436 {
|
|
1437 output_string (printcharfun, 0, nameobj, last,
|
|
1438 i - last);
|
|
1439 }
|
|
1440 write_char_internal ("\\", printcharfun);
|
|
1441 last = i;
|
|
1442 }
|
|
1443 }
|
|
1444 output_string (printcharfun, 0, nameobj, last, size - last);
|
|
1445 }
|
|
1446 UNGCPRO;
|
|
1447 }
|
|
1448
|
|
1449 int alternate_do_pointer;
|
|
1450 char alternate_do_string[5000];
|
|
1451
|
20
|
1452 DEFUN ("alternate-debugging-output", Falternate_debugging_output, 1, 1, 0, /*
|
0
|
1453 Append CHARACTER to the array `alternate_do_string'.
|
|
1454 This can be used in place of `external-debugging-output' as a function
|
|
1455 to be passed to `print'. Before calling `print', set `alternate_do_pointer'
|
|
1456 to 0.
|
|
1457
|
20
|
1458 */
|
|
1459 (character))
|
0
|
1460 {
|
|
1461 Bufbyte str[MAX_EMCHAR_LEN];
|
|
1462 Bytecount len;
|
|
1463 int extlen;
|
|
1464 CONST Extbyte *extptr;
|
|
1465
|
|
1466 CHECK_CHAR_COERCE_INT (character);
|
|
1467 len = set_charptr_emchar (str, XCHAR (character));
|
16
|
1468 GET_CHARPTR_EXT_DATA_ALLOCA (str, len, FORMAT_TERMINAL, extptr, extlen);
|
0
|
1469 memcpy (alternate_do_string + alternate_do_pointer, extptr, extlen);
|
|
1470 alternate_do_pointer += extlen;
|
|
1471 alternate_do_string[alternate_do_pointer] = 0;
|
|
1472 return character;
|
|
1473 }
|
|
1474
|
20
|
1475 DEFUN ("external-debugging-output", Fexternal_debugging_output, 1, 3, 0, /*
|
0
|
1476 Write CHAR-OR-STRING to stderr or stdout.
|
|
1477 If optional arg STDOUT-P is non-nil, write to stdout; otherwise, write
|
|
1478 to stderr. You can use this function to write directly to the terminal.
|
|
1479 This function can be used as the STREAM argument of Fprint() or the like.
|
|
1480
|
|
1481 If you have opened a termscript file (using `open-termscript'), then
|
|
1482 the output also will be logged to this file.
|
20
|
1483 */
|
|
1484 (char_or_string, stdout_p, device))
|
0
|
1485 {
|
|
1486 FILE *file = 0;
|
|
1487 struct console *con = 0;
|
|
1488
|
|
1489 if (NILP (device))
|
|
1490 {
|
|
1491 if (!NILP (stdout_p))
|
|
1492 file = stdout;
|
|
1493 else
|
|
1494 file = stderr;
|
|
1495 }
|
|
1496 else
|
|
1497 {
|
|
1498 CHECK_LIVE_DEVICE (device);
|
|
1499 if (!DEVICE_TTY_P (XDEVICE (device)) &&
|
|
1500 !DEVICE_STREAM_P (XDEVICE (device)))
|
|
1501 signal_simple_error ("Must be tty or stream device", device);
|
|
1502 con = XCONSOLE (DEVICE_CONSOLE (XDEVICE (device)));
|
|
1503 if (DEVICE_TTY_P (XDEVICE (device)))
|
|
1504 file = 0;
|
|
1505 else if (!NILP (stdout_p))
|
|
1506 file = CONSOLE_STREAM_DATA (con)->outfd;
|
|
1507 else
|
|
1508 file = CONSOLE_STREAM_DATA (con)->errfd;
|
|
1509 }
|
|
1510
|
|
1511 if (STRINGP (char_or_string))
|
|
1512 write_string_to_stdio_stream (file, con,
|
16
|
1513 XSTRING_DATA (char_or_string),
|
|
1514 0, XSTRING_LENGTH (char_or_string),
|
|
1515 FORMAT_TERMINAL);
|
0
|
1516 else
|
|
1517 {
|
|
1518 Bufbyte str[MAX_EMCHAR_LEN];
|
|
1519 Bytecount len;
|
|
1520
|
|
1521 CHECK_CHAR_COERCE_INT (char_or_string);
|
|
1522 len = set_charptr_emchar (str, XCHAR (char_or_string));
|
16
|
1523 write_string_to_stdio_stream (file, con, str, 0, len, FORMAT_TERMINAL);
|
0
|
1524 }
|
|
1525
|
|
1526 return char_or_string;
|
|
1527 }
|
|
1528
|
20
|
1529 DEFUN ("open-termscript", Fopen_termscript, 1, 1, "FOpen termscript file: ", /*
|
0
|
1530 Start writing all terminal output to FILE as well as the terminal.
|
|
1531 FILE = nil means just close any termscript file currently open.
|
20
|
1532 */
|
|
1533 (file))
|
0
|
1534 {
|
|
1535 /* This function can GC */
|
|
1536 if (termscript != 0)
|
|
1537 fclose (termscript);
|
|
1538 termscript = 0;
|
|
1539
|
|
1540 if (! NILP (file))
|
|
1541 {
|
|
1542 file = Fexpand_file_name (file, Qnil);
|
16
|
1543 termscript = fopen ((char *) XSTRING_DATA (file), "w");
|
183
|
1544 if (termscript == NULL)
|
0
|
1545 report_file_error ("Opening termscript", Fcons (file, Qnil));
|
|
1546 }
|
|
1547 return Qnil;
|
|
1548 }
|
|
1549
|
|
1550 #if 1
|
|
1551 /* Debugging kludge -- unbuffered */
|
|
1552 static int debug_print_length = 50;
|
|
1553 static int debug_print_level = 15;
|
|
1554 Lisp_Object debug_temp;
|
272
|
1555
|
|
1556 static void
|
0
|
1557 debug_print_no_newline (Lisp_Object debug_print_obj)
|
|
1558 {
|
|
1559 /* This function can GC */
|
|
1560 int old_print_readably = print_readably;
|
|
1561 int old_print_depth = print_depth;
|
|
1562 Lisp_Object old_print_length = Vprint_length;
|
|
1563 Lisp_Object old_print_level = Vprint_level;
|
|
1564 Lisp_Object old_inhibit_quit = Vinhibit_quit;
|
|
1565 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1566 GCPRO3 (old_print_level, old_print_length, old_inhibit_quit);
|
|
1567
|
|
1568 if (gc_in_progress)
|
|
1569 stderr_out ("** gc-in-progress! Bad idea to print anything! **\n");
|
|
1570
|
|
1571 print_depth = 0;
|
|
1572 print_readably = 0;
|
|
1573 print_unbuffered++;
|
|
1574 /* Could use unwind-protect, but why bother? */
|
|
1575 if (debug_print_length > 0)
|
|
1576 Vprint_length = make_int (debug_print_length);
|
|
1577 if (debug_print_level > 0)
|
|
1578 Vprint_level = make_int (debug_print_level);
|
|
1579 print_internal (debug_print_obj, Qexternal_debugging_output, 1);
|
|
1580 Vinhibit_quit = old_inhibit_quit;
|
|
1581 Vprint_level = old_print_level;
|
|
1582 Vprint_length = old_print_length;
|
|
1583 print_depth = old_print_depth;
|
|
1584 print_readably = old_print_readably;
|
|
1585 print_unbuffered--;
|
|
1586 UNGCPRO;
|
|
1587 }
|
|
1588
|
|
1589 void
|
|
1590 debug_print (Lisp_Object debug_print_obj)
|
|
1591 {
|
|
1592 debug_print_no_newline (debug_print_obj);
|
272
|
1593 stderr_out ("\n");
|
0
|
1594 fflush (stderr);
|
|
1595 }
|
|
1596
|
|
1597 /* Debugging kludge -- unbuffered */
|
272
|
1598 /* This function provided for the benefit of the debugger. */
|
|
1599 void debug_backtrace (void);
|
0
|
1600 void
|
|
1601 debug_backtrace (void)
|
|
1602 {
|
|
1603 /* This function can GC */
|
|
1604 int old_print_readably = print_readably;
|
|
1605 int old_print_depth = print_depth;
|
|
1606 Lisp_Object old_print_length = Vprint_length;
|
|
1607 Lisp_Object old_print_level = Vprint_level;
|
|
1608 Lisp_Object old_inhibit_quit = Vinhibit_quit;
|
|
1609 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
1610 GCPRO3 (old_print_level, old_print_length, old_inhibit_quit);
|
|
1611
|
|
1612 if (gc_in_progress)
|
|
1613 stderr_out ("** gc-in-progress! Bad idea to print anything! **\n");
|
|
1614
|
|
1615 print_depth = 0;
|
|
1616 print_readably = 0;
|
|
1617 print_unbuffered++;
|
|
1618 /* Could use unwind-protect, but why bother? */
|
|
1619 if (debug_print_length > 0)
|
|
1620 Vprint_length = make_int (debug_print_length);
|
|
1621 if (debug_print_level > 0)
|
|
1622 Vprint_level = make_int (debug_print_level);
|
|
1623 Fbacktrace (Qexternal_debugging_output, Qt);
|
|
1624 stderr_out ("\n");
|
|
1625 fflush (stderr);
|
|
1626 Vinhibit_quit = old_inhibit_quit;
|
|
1627 Vprint_level = old_print_level;
|
|
1628 Vprint_length = old_print_length;
|
|
1629 print_depth = old_print_depth;
|
|
1630 print_readably = old_print_readably;
|
|
1631 print_unbuffered--;
|
|
1632 UNGCPRO;
|
|
1633 }
|
|
1634
|
|
1635 void
|
|
1636 debug_short_backtrace (int length)
|
|
1637 {
|
|
1638 int first = 1;
|
|
1639 struct backtrace *bt = backtrace_list;
|
|
1640 stderr_out (" [");
|
|
1641 fflush (stderr);
|
|
1642 while (length > 0 && bt)
|
|
1643 {
|
|
1644 if (!first)
|
|
1645 {
|
|
1646 stderr_out (", ");
|
|
1647 fflush (stderr);
|
|
1648 }
|
|
1649 if (COMPILED_FUNCTIONP (*bt->function))
|
|
1650 {
|
233
|
1651 #if defined(COMPILED_FUNCTION_ANNOTATION_HACK)
|
0
|
1652 Lisp_Object ann = Fcompiled_function_annotation (*bt->function);
|
233
|
1653 #else
|
|
1654 Lisp_Object ann = Qnil;
|
|
1655 #endif
|
0
|
1656 if (!NILP (ann))
|
|
1657 {
|
|
1658 stderr_out ("<compiled-function from ");
|
|
1659 fflush (stderr);
|
|
1660 debug_print_no_newline (ann);
|
|
1661 stderr_out (">");
|
|
1662 fflush (stderr);
|
|
1663 }
|
|
1664 else
|
|
1665 {
|
|
1666 stderr_out ("<compiled-function of unknown origin>");
|
|
1667 fflush (stderr);
|
|
1668 }
|
|
1669 }
|
|
1670 else
|
|
1671 debug_print_no_newline (*bt->function);
|
|
1672 first = 0;
|
|
1673 length--;
|
|
1674 bt = bt->next;
|
|
1675 }
|
|
1676 stderr_out ("]\n");
|
|
1677 fflush (stderr);
|
|
1678 }
|
|
1679
|
|
1680 #endif /* debugging kludge */
|
|
1681
|
|
1682
|
|
1683 void
|
|
1684 syms_of_print (void)
|
|
1685 {
|
|
1686 defsymbol (&Qprint_escape_newlines, "print-escape-newlines");
|
|
1687 defsymbol (&Qprint_readably, "print-readably");
|
|
1688
|
|
1689 defsymbol (&Qstandard_output, "standard-output");
|
|
1690
|
|
1691 #ifdef LISP_FLOAT_TYPE
|
|
1692 defsymbol (&Qfloat_output_format, "float-output-format");
|
|
1693 #endif
|
|
1694
|
|
1695 defsymbol (&Qprint_length, "print-length");
|
|
1696
|
|
1697 defsymbol (&Qprint_string_length, "print-string-length");
|
171
|
1698
|
|
1699 defsymbol (&Qdisplay_error, "display-error");
|
|
1700 defsymbol (&Qprint_message_label, "print-message-label");
|
|
1701
|
20
|
1702 DEFSUBR (Fprin1);
|
|
1703 DEFSUBR (Fprin1_to_string);
|
|
1704 DEFSUBR (Fprinc);
|
|
1705 DEFSUBR (Fprint);
|
100
|
1706 DEFSUBR (Ferror_message_string);
|
171
|
1707 DEFSUBR (Fdisplay_error);
|
20
|
1708 DEFSUBR (Fterpri);
|
|
1709 DEFSUBR (Fwrite_char);
|
|
1710 DEFSUBR (Falternate_debugging_output);
|
0
|
1711 defsymbol (&Qalternate_debugging_output, "alternate-debugging-output");
|
20
|
1712 DEFSUBR (Fexternal_debugging_output);
|
|
1713 DEFSUBR (Fopen_termscript);
|
0
|
1714 defsymbol (&Qexternal_debugging_output, "external-debugging-output");
|
|
1715 #ifndef standalone
|
20
|
1716 DEFSUBR (Fwith_output_to_temp_buffer);
|
0
|
1717 #endif /* not standalone */
|
|
1718 }
|
|
1719
|
|
1720 void
|
|
1721 lstream_type_create_print (void)
|
|
1722 {
|
|
1723 LSTREAM_HAS_METHOD (print, writer);
|
|
1724 LSTREAM_HAS_METHOD (print, marker);
|
|
1725 }
|
|
1726
|
|
1727 void
|
|
1728 vars_of_print (void)
|
|
1729 {
|
|
1730 alternate_do_pointer = 0;
|
|
1731
|
|
1732 DEFVAR_LISP ("standard-output", &Vstandard_output /*
|
|
1733 Output stream `print' uses by default for outputting a character.
|
|
1734 This may be any function of one argument.
|
|
1735 It may also be a buffer (output is inserted before point)
|
|
1736 or a marker (output is inserted and the marker is advanced)
|
|
1737 or the symbol t (output appears in the minibuffer line).
|
|
1738 */ );
|
|
1739 Vstandard_output = Qt;
|
|
1740
|
|
1741 #ifdef LISP_FLOAT_TYPE
|
|
1742 DEFVAR_LISP ("float-output-format", &Vfloat_output_format /*
|
|
1743 The format descriptor string that lisp uses to print floats.
|
|
1744 This is a %-spec like those accepted by `printf' in C,
|
|
1745 but with some restrictions. It must start with the two characters `%.'.
|
|
1746 After that comes an integer precision specification,
|
|
1747 and then a letter which controls the format.
|
|
1748 The letters allowed are `e', `f' and `g'.
|
185
|
1749 Use `e' for exponential notation "DIG.DIGITSeEXPT"
|
|
1750 Use `f' for decimal point notation "DIGITS.DIGITS".
|
0
|
1751 Use `g' to choose the shorter of those two formats for the number at hand.
|
|
1752 The precision in any of these cases is the number of digits following
|
|
1753 the decimal point. With `f', a precision of 0 means to omit the
|
|
1754 decimal point. 0 is not allowed with `f' or `g'.
|
|
1755
|
|
1756 A value of nil means to use `%.16g'.
|
|
1757
|
|
1758 Regardless of the value of `float-output-format', a floating point number
|
|
1759 will never be printed in such a way that it is ambiguous with an integer;
|
|
1760 that is, a floating-point number will always be printed with a decimal
|
|
1761 point and/or an exponent, even if the digits following the decimal point
|
|
1762 are all zero. This is to preserve read-equivalence.
|
|
1763 */ );
|
|
1764 Vfloat_output_format = Qnil;
|
|
1765 #endif /* LISP_FLOAT_TYPE */
|
|
1766
|
|
1767 DEFVAR_LISP ("print-length", &Vprint_length /*
|
|
1768 Maximum length of list or vector to print before abbreviating.
|
|
1769 A value of nil means no limit.
|
|
1770 */ );
|
|
1771 Vprint_length = Qnil;
|
|
1772
|
|
1773 DEFVAR_LISP ("print-string-length", &Vprint_string_length /*
|
|
1774 Maximum length of string to print before abbreviating.
|
|
1775 A value of nil means no limit.
|
|
1776 */ );
|
|
1777 Vprint_string_length = Qnil;
|
|
1778
|
|
1779 DEFVAR_LISP ("print-level", &Vprint_level /*
|
|
1780 Maximum depth of list nesting to print before abbreviating.
|
|
1781 A value of nil means no limit.
|
|
1782 */ );
|
|
1783 Vprint_level = Qnil;
|
|
1784
|
|
1785 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines /*
|
|
1786 Non-nil means print newlines in strings as backslash-n.
|
|
1787 */ );
|
|
1788 print_escape_newlines = 0;
|
|
1789
|
|
1790 DEFVAR_BOOL ("print-readably", &print_readably /*
|
|
1791 If non-nil, then all objects will be printed in a readable form.
|
|
1792 If an object has no readable representation, then an error is signalled.
|
|
1793 When print-readably is true, compiled-function objects will be written in
|
|
1794 #[...] form instead of in #<compiled-function [...]> form, and two-element
|
|
1795 lists of the form (quote object) will be written as the equivalent 'object.
|
|
1796 Do not SET this variable; bind it instead.
|
|
1797 */ );
|
|
1798 print_readably = 0;
|
|
1799
|
245
|
1800 /* #### I think this should default to t. But we'd better wait
|
|
1801 until we see that it works out. */
|
|
1802 DEFVAR_LISP ("print-gensym", &Vprint_gensym /*
|
0
|
1803 If non-nil, then uninterned symbols will be printed specially.
|
|
1804 Uninterned symbols are those which are not present in `obarray', that is,
|
|
1805 those which were made with `make-symbol' or by calling `intern' with a
|
|
1806 second argument.
|
|
1807
|
245
|
1808 When print-gensym is true, such symbols will be preceded by "#:",
|
|
1809 which causes the reader to create a new symbol instead of interning
|
|
1810 and returning an existing one. Beware: the #: syntax creates a new
|
|
1811 symbol each time it is seen, so if you print an object which contains
|
|
1812 two pointers to the same uninterned symbol, `read' will not duplicate
|
|
1813 that structure.
|
0
|
1814
|
245
|
1815 If the value of `print-gensym' is a cons cell, then in addition
|
|
1816 refrain from clearing `print-gensym-alist' on entry to and exit from
|
|
1817 printing functions, so that the use of #...# and #...= can carry over
|
|
1818 for several separately printed objects.
|
0
|
1819 */ );
|
245
|
1820 Vprint_gensym = Qnil;
|
|
1821
|
|
1822 DEFVAR_LISP ("print-gensym-alist", &Vprint_gensym_alist /*
|
|
1823 Association list of elements (GENSYM . N) to guide use of #N# and #N=.
|
|
1824 In each element, GENSYM is an uninterned symbol that has been associated
|
|
1825 with #N= for the specified value of N.
|
|
1826 */ );
|
|
1827 Vprint_gensym_alist = Qnil;
|
0
|
1828
|
|
1829 DEFVAR_LISP ("print-message-label", &Vprint_message_label /*
|
|
1830 Label for minibuffer messages created with `print'. This should
|
|
1831 generally be bound with `let' rather than set. (See `display-message'.)
|
|
1832 */ );
|
|
1833 Vprint_message_label = Qprint;
|
|
1834
|
219
|
1835 Vprin1_to_string_stream = Qnil;
|
|
1836 staticpro (&Vprin1_to_string_stream);
|
0
|
1837 }
|