Mercurial > hg > xemacs-beta
annotate src/print.c @ 5684:0eb4e96fd261
#'delete-trailing-whitespace needs to work when the region is inactive, too
lisp/ChangeLog addition:
Update its interactive spec to work correctly in XEmacs.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 08 Sep 2012 16:33:48 +0100 |
parents | febc025c4e0c |
children | cd4f5f1f1f4c |
rev | line source |
---|---|
428 | 1 /* Lisp object printing and output streams. |
2 Copyright (C) 1985, 1986, 1988, 1992-1995 Free Software Foundation, Inc. | |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
3 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2003, 2005, 2010 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5243
diff
changeset
|
7 XEmacs is free software: you can redistribute it and/or modify it |
428 | 8 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5243
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5243
diff
changeset
|
10 option) any later version. |
428 | 11 |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5243
diff
changeset
|
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
428 | 19 |
20 /* Synched up with: Not synched with FSF. */ | |
21 | |
22 /* This file has been Mule-ized. */ | |
23 | |
771 | 24 /* Seriously divergent from FSF by this point. |
25 | |
26 Seriously hacked on by Ben Wing for Mule. All stdio code also by Ben, | |
27 as well as the debugging code (initial version of debug_print(), though, | |
28 by Jamie Zawinski) and the _fmt interfaces. Also a fair amount of work | |
29 by Hrvoje, e.g. floating-point code and rewriting to avoid O(N^2) | |
30 consing when outputting to the echo area. Print-circularity code by | |
31 Martin? */ | |
428 | 32 |
33 #include <config.h> | |
34 #include "lisp.h" | |
35 | |
36 #include "backtrace.h" | |
37 #include "buffer.h" | |
38 #include "bytecode.h" | |
872 | 39 #include "device-impl.h" |
428 | 40 #include "extents.h" |
41 #include "frame.h" | |
42 #include "insdel.h" | |
43 #include "lstream.h" | |
771 | 44 #include "opaque.h" |
800 | 45 |
872 | 46 #include "console-tty-impl.h" |
47 #include "console-stream-impl.h" | |
442 | 48 #ifdef WIN32_NATIVE |
49 #include "console-msw.h" | |
50 #endif | |
428 | 51 |
800 | 52 #include "sysfile.h" |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
53 #include "elhash.h" |
800 | 54 |
428 | 55 #include <float.h> |
56 /* Define if not in float.h */ | |
57 #ifndef DBL_DIG | |
58 #define DBL_DIG 16 | |
59 #endif | |
60 | |
61 Lisp_Object Vstandard_output, Qstandard_output; | |
62 | |
63 /* The subroutine object for external-debugging-output is kept here | |
64 for the convenience of the debugger. */ | |
442 | 65 Lisp_Object Qexternal_debugging_output, Qalternate_debugging_output; |
66 | |
67 #ifdef HAVE_MS_WINDOWS | |
68 Lisp_Object Qmswindows_debugging_output; | |
69 #endif | |
428 | 70 |
71 /* Avoid actual stack overflow in print. */ | |
72 static int print_depth; | |
73 | |
74 /* Detect most circularities to print finite output. */ | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
75 #define PRINT_CIRCLE_LIMIT 200 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
76 static Lisp_Object being_printed[PRINT_CIRCLE_LIMIT]; |
428 | 77 |
78 /* Maximum length of list or vector to print in full; noninteger means | |
79 effectively infinity */ | |
80 | |
81 Lisp_Object Vprint_length; | |
82 Lisp_Object Qprint_length; | |
83 | |
84 /* Maximum length of string to print in full; noninteger means | |
85 effectively infinity */ | |
86 | |
87 Lisp_Object Vprint_string_length; | |
88 Lisp_Object Qprint_string_length; | |
89 | |
90 /* Maximum depth of list to print in full; noninteger means | |
91 effectively infinity. */ | |
92 | |
93 Lisp_Object Vprint_level; | |
94 | |
95 /* Label to use when making echo-area messages. */ | |
96 | |
97 Lisp_Object Vprint_message_label; | |
98 | |
99 /* Nonzero means print newlines in strings as \n. */ | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
100 Boolint print_escape_newlines; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
101 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
102 Boolint print_readably; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
103 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
104 /* Non-zero means print #: before uninterned symbols, and use the #n= and |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
105 #n# syntax for them. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
106 Boolint print_gensym; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
107 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
108 /* Non-zero means print recursive structures using #n= and #n# syntax. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
109 Boolint print_circle; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
110 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
111 /* Non-zero means keep continuous numbers for #n= and #n# syntax between |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
112 several print functions. Setting or binding the corresponding Lisp |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
113 variable to a non-nil value silently *clears* Vprint_number_table. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
114 Boolint print_continuous_numbering; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
115 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
116 /* Vprint_number_table is a hash table mapping objects to their statuses for |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
117 this print operation. The statuses are represented by integers. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
118 Lisp_Object Vprint_number_table; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
119 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
120 /* These describe the bit fields of the integers in Vprint_number_table. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
121 enum PRINT_NUMBER_FIELDS { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
122 /* Lowest four bits describe the number of times a given object has |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
123 been seen, allowing entries to be manipulated cheaply by |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
124 inchash_eq() when encountered. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
125 PRINT_NUMBER_SEEN_MASK = 0xF, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
126 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
127 /* The next twenty-five bits give the sequence number for the object, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
128 corresponding to the order in which print_preprocess encountered the |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
129 objects; as such, it's related to print_number_index. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
130 PRINT_NUMBER_ORDINAL_MASK = 0x1FFFFFF0, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
131 PRINT_NUMBER_ORDINAL_SHIFT = 4, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
132 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
133 /* And the next bit describes whether the object has already been printed |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
134 in this print operation (or in these print operations, if |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
135 print-continuous-numbering is relevant). */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
136 PRINT_NUMBER_PRINTED_MASK = 0x20000000, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
137 }; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
138 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
139 /* Reflects the number of repeated or possibly-repeated objects encountered |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
140 by print_preprocess(); reset whenever Vprint_number_table is cleared. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
141 Elemcount print_number_index; |
428 | 142 |
143 Lisp_Object Qdisplay_error; | |
144 Lisp_Object Qprint_message_label; | |
145 | |
146 /* Force immediate output of all printed data. Used for debugging. */ | |
147 int print_unbuffered; | |
148 | |
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
149 /* Non-zero if in debug-printing */ |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
150 int in_debug_print; |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
151 |
428 | 152 FILE *termscript; /* Stdio stream being used for copy of all output. */ |
153 | |
1346 | 154 static void write_string_to_alternate_debugging_output (const Ibyte *str, |
771 | 155 Bytecount len); |
156 | |
1957 | 157 /* To avoid consing in debug_prin1, we package up variables we need to bind |
158 into an opaque object. */ | |
159 struct debug_bindings | |
160 { | |
2367 | 161 int inhibit_non_essential_conversion_operations; |
1957 | 162 int print_depth; |
163 int print_readably; | |
164 int print_unbuffered; | |
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
165 int in_debug_print; |
1957 | 166 int gc_currently_forbidden; |
167 Lisp_Object Vprint_length; | |
168 Lisp_Object Vprint_level; | |
169 Lisp_Object Vinhibit_quit; | |
170 }; | |
171 | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
172 static int begin_inhibit_non_essential_conversion_operations (void); |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
173 |
428 | 174 |
175 | |
176 int stdout_needs_newline; | |
1346 | 177 int stdout_clear_before_next_output; |
428 | 178 |
771 | 179 /* Basic function to actually write to a stdio stream or TTY console. */ |
180 | |
442 | 181 static void |
1346 | 182 write_string_to_stdio_stream_1 (FILE *stream, struct console *con, |
183 const Ibyte *ptr, Bytecount len, | |
184 int must_flush) | |
428 | 185 { |
771 | 186 Extbyte *extptr = 0; |
187 Bytecount extlen = 0; | |
188 int output_is_std_handle = | |
189 stream ? stream == stdout || stream == stderr : | |
190 CONSOLE_TTY_DATA (con)->is_stdio; | |
191 | |
192 if (stream || output_is_std_handle) | |
193 { | |
2367 | 194 if (initialized && !inhibit_non_essential_conversion_operations) |
771 | 195 TO_EXTERNAL_FORMAT (DATA, (ptr, len), |
196 ALLOCA, (extptr, extlen), | |
197 Qterminal); | |
198 else | |
199 { | |
2367 | 200 #ifdef NON_ASCII_INTERNAL_FORMAT |
201 #error Do something here | |
202 #else | |
771 | 203 extptr = (Extbyte *) ptr; |
204 extlen = (Bytecount) len; | |
2367 | 205 #endif |
771 | 206 } |
207 } | |
208 | |
428 | 209 if (stream) |
210 { | |
442 | 211 #ifdef WIN32_NATIVE |
212 HANDLE errhand = GetStdHandle (STD_INPUT_HANDLE); | |
213 int no_useful_stderr = errhand == 0 || errhand == INVALID_HANDLE_VALUE; | |
214 | |
215 if (!no_useful_stderr) | |
216 no_useful_stderr = !PeekNamedPipe (errhand, 0, 0, 0, 0, 0); | |
217 /* we typically have no useful stdout/stderr under windows if we're | |
218 being invoked graphically. */ | |
219 if (no_useful_stderr) | |
771 | 220 mswindows_output_console_string (ptr, len); |
442 | 221 else |
428 | 222 #endif |
442 | 223 { |
771 | 224 retry_fwrite (extptr, 1, extlen, stream); |
442 | 225 #ifdef WIN32_NATIVE |
226 /* Q122442 says that pipes are "treated as files, not as | |
227 devices", and that this is a feature. Before I found that | |
228 article, I thought it was a bug. Thanks MS, I feel much | |
229 better now. - kkm */ | |
230 must_flush = 1; | |
231 #endif | |
232 if (must_flush) | |
233 fflush (stream); | |
234 } | |
428 | 235 } |
236 else | |
771 | 237 /* The stream itself does conversion to external format */ |
238 Lstream_write (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream), ptr, len); | |
442 | 239 |
240 if (output_is_std_handle) | |
428 | 241 { |
242 if (termscript) | |
243 { | |
771 | 244 retry_fwrite (extptr, 1, extlen, termscript); |
428 | 245 fflush (termscript); |
246 } | |
1346 | 247 stdout_needs_newline = (ptr[len - 1] != '\n'); |
428 | 248 } |
249 } | |
250 | |
1346 | 251 /* Write to a stdio stream or TTY console, first clearing the left side |
252 if necessary. */ | |
253 | |
254 static void | |
255 write_string_to_stdio_stream (FILE *stream, struct console *con, | |
256 const Ibyte *ptr, Bytecount len, | |
257 int must_flush) | |
258 { | |
259 if (stdout_clear_before_next_output && | |
260 (stream ? stream == stdout || stream == stderr : | |
261 CONSOLE_TTY_DATA (con)->is_stdio)) | |
262 { | |
263 if (stdout_needs_newline) | |
264 write_string_to_stdio_stream_1 (stream, con, (Ibyte *) "\n", 1, | |
265 must_flush); | |
266 stdout_clear_before_next_output = 0; | |
267 } | |
268 | |
269 write_string_to_stdio_stream_1 (stream, con, ptr, len, must_flush); | |
270 } | |
271 | |
272 /* | |
273 EXT_PRINT_STDOUT = stdout or its equivalent (may be a | |
274 console window under MS Windows) | |
275 EXT_PRINT_STDERR = stderr or its equivalent (may be a | |
276 console window under MS Windows) | |
277 EXT_PRINT_ALTERNATE = an internal character array; see | |
278 `alternate-debugging-output' | |
279 EXT_PRINT_MSWINDOWS = Under MS Windows, the "debugging output" that | |
280 debuggers can hook into; uses OutputDebugString() | |
281 system call | |
282 EXT_PRINT_ALL = all of the above except stdout | |
283 */ | |
284 | |
285 enum ext_print | |
286 { | |
287 EXT_PRINT_STDOUT = 1, | |
288 EXT_PRINT_STDERR = 2, | |
289 EXT_PRINT_ALTERNATE = 4, | |
290 EXT_PRINT_MSWINDOWS = 8, | |
291 EXT_PRINT_ALL = 14 | |
292 }; | |
293 | |
294 static void | |
295 write_string_to_external_output (const Ibyte *ptr, Bytecount len, | |
296 int dest) | |
297 { | |
298 if (dest & EXT_PRINT_STDOUT) | |
299 write_string_to_stdio_stream (stdout, 0, ptr, len, 1); | |
300 if (dest & EXT_PRINT_STDERR) | |
301 write_string_to_stdio_stream (stderr, 0, ptr, len, 1); | |
302 if (dest & EXT_PRINT_ALTERNATE) | |
303 write_string_to_alternate_debugging_output (ptr, len); | |
304 #ifdef WIN32_NATIVE | |
305 if (dest & EXT_PRINT_MSWINDOWS) | |
306 write_string_to_mswindows_debugging_output (ptr, len); | |
307 #endif | |
308 } | |
309 | |
310 /* #### The following function should make use of a call to the | |
311 emacs_vsprintf_*() functions rather than just using vsprintf. This is | |
312 the only way to ensure that I18N3 works properly (many implementations | |
313 of the *printf() functions, including the ones included in glibc, do not | |
314 implement the %###$ argument-positioning syntax). | |
442 | 315 |
316 Note, however, that to do this, we'd have to | |
317 | |
318 1) pre-allocate all the lstreams and do whatever else was necessary | |
319 to make sure that no allocation occurs, since these functions may be | |
320 called from fatal_error_signal(). | |
321 | |
322 2) (to be really correct) make a new lstream that outputs using | |
1346 | 323 mswindows_output_console_string(). |
324 | |
325 3) A reasonable compromise might be to use emacs_vsprintf() when we're | |
326 in a safe state, and when not, use plain vsprintf(). */ | |
442 | 327 |
771 | 328 static void |
1346 | 329 write_string_to_external_output_va (const CIbyte *fmt, va_list args, |
330 int dest) | |
442 | 331 { |
867 | 332 Ibyte kludge[8192]; |
771 | 333 Bytecount kludgelen; |
334 | |
2367 | 335 if (initialized && !inhibit_non_essential_conversion_operations) |
771 | 336 fmt = GETTEXT (fmt); |
867 | 337 vsprintf ((CIbyte *) kludge, fmt, args); |
771 | 338 kludgelen = qxestrlen (kludge); |
1346 | 339 write_string_to_external_output (kludge, kludgelen, dest); |
442 | 340 } |
341 | |
771 | 342 /* Output portably to stderr or its equivalent (i.e. may be a console |
343 window under MS Windows); do external-format conversion and call GETTEXT | |
344 on the format string. Automatically flush when done. | |
442 | 345 |
2731 | 346 NOTE: CIbyte means "internal format" data. This includes the "..." |
347 arguments. For numerical arguments, we have to assume that vsprintf | |
348 will be a good boy and format them as ASCII. For Mule internal coding | |
349 (and UTF-8 internal coding, if/when we get it), it is safe to pass | |
350 string values in internal format to be formatted, because zero octets | |
351 only occur in the NUL character itself. Similarly, it is safe to pass | |
352 pure ASCII literal strings for these functions. *Everything else must | |
353 be converted, including all external data.* | |
354 | |
355 This function is safe to use even when not initialized or when dying -- | |
356 we don't do conversion in such cases. */ | |
771 | 357 |
358 void | |
867 | 359 stderr_out (const CIbyte *fmt, ...) |
442 | 360 { |
361 va_list args; | |
362 va_start (args, fmt); | |
1346 | 363 write_string_to_external_output_va (fmt, args, EXT_PRINT_STDERR); |
442 | 364 va_end (args); |
365 } | |
366 | |
771 | 367 /* Output portably to stdout or its equivalent (i.e. may be a console |
368 window under MS Windows). Works like stderr_out(). */ | |
442 | 369 |
771 | 370 void |
867 | 371 stdout_out (const CIbyte *fmt, ...) |
442 | 372 { |
373 va_list args; | |
374 va_start (args, fmt); | |
1346 | 375 write_string_to_external_output_va (fmt, args, EXT_PRINT_STDOUT); |
376 va_end (args); | |
377 } | |
378 | |
379 /* Output portably to print destination as specified by DEST. */ | |
380 | |
381 void | |
382 external_out (int dest, const CIbyte *fmt, ...) | |
383 { | |
384 va_list args; | |
385 va_start (args, fmt); | |
386 write_string_to_external_output_va (fmt, args, dest); | |
442 | 387 va_end (args); |
771 | 388 } |
389 | |
390 /* Output portably to stderr or its equivalent (i.e. may be a console | |
391 window under MS Windows), as well as alternate-debugging-output and | |
392 (under MS Windows) the C debugging output, i.e. OutputDebugString(). | |
393 Works like stderr_out(). */ | |
394 | |
395 void | |
867 | 396 debug_out (const CIbyte *fmt, ...) |
771 | 397 { |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
398 int depth = begin_inhibit_non_essential_conversion_operations (); |
771 | 399 va_list args; |
400 va_start (args, fmt); | |
1346 | 401 write_string_to_external_output_va (fmt, args, EXT_PRINT_ALL); |
771 | 402 va_end (args); |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
403 unbind_to (depth); |
442 | 404 } |
405 | |
406 DOESNT_RETURN | |
867 | 407 fatal (const CIbyte *fmt, ...) |
442 | 408 { |
409 va_list args; | |
410 va_start (args, fmt); | |
411 | |
771 | 412 stderr_out ("\nXEmacs: fatal error: "); |
1346 | 413 write_string_to_external_output_va (fmt, args, EXT_PRINT_STDERR); |
442 | 414 stderr_out ("\n"); |
415 | |
416 va_end (args); | |
417 exit (1); | |
418 } | |
419 | |
428 | 420 /* Write a string to the output location specified in FUNCTION. |
421 Arguments NONRELOC, RELOC, OFFSET, and LEN are as in | |
771 | 422 buffer_insert_string_1() in insdel.c. |
423 | |
424 FUNCTION is one of | |
425 | |
426 -- an lstream | |
427 -- a buffer (insert at point and advance point) | |
428 -- a marker (insert at marker and advance marker) | |
429 -- a frame (append to echo area; clear echo area first if | |
430 `print-message-label' has changed since the last time) | |
431 -- t or nil (send to stdout) | |
432 -- a Lisp function of one argument (call to get data output) | |
433 | |
434 Use Qexternal_debugging_output to get output to stderr. | |
435 */ | |
428 | 436 |
437 static void | |
867 | 438 output_string (Lisp_Object function, const Ibyte *nonreloc, |
428 | 439 Lisp_Object reloc, Bytecount offset, Bytecount len) |
440 { | |
441 /* This function can GC */ | |
442 Charcount cclen; | |
443 /* We change the value of nonreloc (fetching it from reloc as | |
444 necessary), but we don't want to pass this changed value on to | |
445 other functions that take both a nonreloc and a reloc, or things | |
446 may get confused and an assertion failure in | |
447 fixup_internal_substring() may get triggered. */ | |
867 | 448 const Ibyte *newnonreloc = nonreloc; |
428 | 449 struct gcpro gcpro1, gcpro2; |
450 | |
451 /* Emacs won't print while GCing, but an external debugger might */ | |
771 | 452 #ifdef NO_PRINT_DURING_GC |
428 | 453 if (gc_in_progress) return; |
771 | 454 #endif |
428 | 455 |
456 /* Perhaps not necessary but probably safer. */ | |
457 GCPRO2 (function, reloc); | |
458 | |
459 fixup_internal_substring (newnonreloc, reloc, offset, &len); | |
460 | |
461 if (STRINGP (reloc)) | |
771 | 462 { |
793 | 463 cclen = string_offset_byte_to_char_len (reloc, offset, len); |
771 | 464 newnonreloc = XSTRING_DATA (reloc); |
465 } | |
466 else | |
467 cclen = bytecount_to_charcount (newnonreloc + offset, len); | |
428 | 468 |
469 if (LSTREAMP (function)) | |
470 { | |
471 if (STRINGP (reloc)) | |
472 { | |
473 /* Protect against Lstream_write() causing a GC and | |
474 relocating the string. For small strings, we do it by | |
475 alloc'ing the string and using a copy; for large strings, | |
476 we inhibit GC. */ | |
477 if (len < 65536) | |
478 { | |
2367 | 479 Ibyte *copied = alloca_ibytes (len); |
428 | 480 memcpy (copied, newnonreloc + offset, len); |
481 Lstream_write (XLSTREAM (function), copied, len); | |
482 } | |
1957 | 483 else if (gc_currently_forbidden) |
484 { | |
485 /* Avoid calling begin_gc_forbidden, which conses. We can reach | |
486 this point from the cons debug code, which will get us into | |
487 an infinite loop if we cons again. */ | |
488 Lstream_write (XLSTREAM (function), newnonreloc + offset, len); | |
489 } | |
428 | 490 else |
491 { | |
771 | 492 int speccount = begin_gc_forbidden (); |
428 | 493 Lstream_write (XLSTREAM (function), newnonreloc + offset, len); |
771 | 494 unbind_to (speccount); |
428 | 495 } |
496 } | |
497 else | |
498 Lstream_write (XLSTREAM (function), newnonreloc + offset, len); | |
499 | |
500 if (print_unbuffered) | |
501 Lstream_flush (XLSTREAM (function)); | |
502 } | |
503 else if (BUFFERP (function)) | |
504 { | |
505 CHECK_LIVE_BUFFER (function); | |
506 buffer_insert_string (XBUFFER (function), nonreloc, reloc, offset, len); | |
507 } | |
508 else if (MARKERP (function)) | |
509 { | |
510 /* marker_position() will err if marker doesn't point anywhere. */ | |
665 | 511 Charbpos spoint = marker_position (function); |
428 | 512 |
513 buffer_insert_string_1 (XMARKER (function)->buffer, | |
514 spoint, nonreloc, reloc, offset, len, | |
515 0); | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
516 Fset_marker (function, make_fixnum (spoint + cclen), |
428 | 517 Fmarker_buffer (function)); |
518 } | |
519 else if (FRAMEP (function)) | |
520 { | |
521 /* This gets used by functions not invoking print_prepare(), | |
522 such as Fwrite_char, Fterpri, etc.. */ | |
523 struct frame *f = XFRAME (function); | |
524 CHECK_LIVE_FRAME (function); | |
525 | |
526 if (!EQ (Vprint_message_label, echo_area_status (f))) | |
527 clear_echo_area_from_print (f, Qnil, 1); | |
528 echo_area_append (f, nonreloc, reloc, offset, len, Vprint_message_label); | |
529 } | |
530 else if (EQ (function, Qt) || EQ (function, Qnil)) | |
531 { | |
771 | 532 write_string_to_stdio_stream (stdout, 0, newnonreloc + offset, len, |
533 print_unbuffered); | |
534 } | |
535 else if (EQ (function, Qexternal_debugging_output)) | |
536 { | |
537 /* This is not strictly necessary, and somewhat of a hack, but it | |
538 avoids having each character passed separately to | |
539 `external-debugging-output'. #### Why do we pass each character | |
540 separately, anyway? | |
541 */ | |
542 write_string_to_stdio_stream (stderr, 0, newnonreloc + offset, len, | |
543 print_unbuffered); | |
428 | 544 } |
545 else | |
546 { | |
771 | 547 Charcount ccoff; |
428 | 548 Charcount iii; |
549 | |
771 | 550 if (STRINGP (reloc)) |
793 | 551 ccoff = string_index_byte_to_char (reloc, offset); |
771 | 552 else |
553 ccoff = bytecount_to_charcount (newnonreloc, offset); | |
554 | |
555 if (STRINGP (reloc)) | |
428 | 556 { |
771 | 557 for (iii = ccoff; iii < cclen + ccoff; iii++) |
558 { | |
867 | 559 call1 (function, make_char (string_ichar (reloc, iii))); |
771 | 560 if (STRINGP (reloc)) |
561 newnonreloc = XSTRING_DATA (reloc); | |
562 } | |
563 } | |
564 else | |
565 { | |
566 for (iii = ccoff; iii < cclen + ccoff; iii++) | |
567 { | |
568 call1 (function, | |
867 | 569 make_char (itext_ichar_n (newnonreloc, iii))); |
771 | 570 } |
428 | 571 } |
572 } | |
573 | |
574 UNGCPRO; | |
575 } | |
576 | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
577 static int |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
578 print_continuous_numbering_changed (Lisp_Object UNUSED (sym), |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
579 Lisp_Object *val, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
580 Lisp_Object UNUSED (in_object), |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
581 int UNUSED (flags)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
582 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
583 if (!NILP (*val) && !print_continuous_numbering) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
584 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
585 Fclrhash (Vprint_number_table); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
586 print_number_index = 0; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
587 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
588 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
589 return 0; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
590 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
591 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
592 #define RESET_PRINT_NUMBER_TABLE do { \ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
593 if (!print_continuous_numbering) \ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
594 { \ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
595 Fclrhash (Vprint_number_table); \ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
596 print_number_index = 0; \ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
597 } \ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
598 } while (0) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
599 |
1261 | 600 Lisp_Object |
428 | 601 canonicalize_printcharfun (Lisp_Object printcharfun) |
602 { | |
603 if (NILP (printcharfun)) | |
604 printcharfun = Vstandard_output; | |
605 | |
1261 | 606 if (!noninteractive && (EQ (printcharfun, Qt) || NILP (printcharfun))) |
428 | 607 printcharfun = Fselected_frame (Qnil); /* print to minibuffer */ |
608 | |
609 return printcharfun; | |
610 } | |
611 | |
612 static Lisp_Object | |
613 print_prepare (Lisp_Object printcharfun, Lisp_Object *frame_kludge) | |
614 { | |
615 /* Emacs won't print while GCing, but an external debugger might */ | |
771 | 616 #ifdef NO_PRINT_DURING_GC |
428 | 617 if (gc_in_progress) |
618 return Qnil; | |
771 | 619 #endif |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
620 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
621 RESET_PRINT_NUMBER_TABLE; |
428 | 622 |
623 printcharfun = canonicalize_printcharfun (printcharfun); | |
624 | |
625 /* Here we could safely return the canonicalized PRINTCHARFUN. | |
626 However, if PRINTCHARFUN is a frame, printing of complex | |
627 structures becomes very expensive, because `append-message' | |
628 (called by echo_area_append) gets called as many times as | |
629 output_string() is called (and that's a *lot*). append-message | |
630 tries to keep top of the message-stack in sync with the contents | |
631 of " *Echo Area" buffer, consing a new string for each component | |
632 of the printed structure. For instance, if you print (a a), | |
633 append-message will cons up the following strings: | |
634 | |
635 "(" | |
636 "(a" | |
637 "(a " | |
638 "(a a" | |
639 "(a a)" | |
640 | |
641 and will use only the last one. With larger objects, this turns | |
642 into an O(n^2) consing frenzy that locks up XEmacs in incessant | |
643 garbage collection. | |
644 | |
645 We prevent this by creating a resizing_buffer stream and letting | |
646 the printer write into it. print_finish() will notice this | |
647 stream, and invoke echo_area_append() with the stream's buffer, | |
648 only once. */ | |
649 if (FRAMEP (printcharfun)) | |
650 { | |
651 CHECK_LIVE_FRAME (printcharfun); | |
652 *frame_kludge = printcharfun; | |
653 printcharfun = make_resizing_buffer_output_stream (); | |
654 } | |
655 | |
656 return printcharfun; | |
657 } | |
658 | |
659 static void | |
660 print_finish (Lisp_Object stream, Lisp_Object frame_kludge) | |
661 { | |
662 /* Emacs won't print while GCing, but an external debugger might */ | |
771 | 663 #ifdef NO_PRINT_DURING_GC |
428 | 664 if (gc_in_progress) |
665 return; | |
771 | 666 #endif |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
667 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
668 RESET_PRINT_NUMBER_TABLE; |
428 | 669 |
670 /* See the comment in print_prepare(). */ | |
671 if (FRAMEP (frame_kludge)) | |
672 { | |
673 struct frame *f = XFRAME (frame_kludge); | |
674 Lstream *str = XLSTREAM (stream); | |
675 CHECK_LIVE_FRAME (frame_kludge); | |
676 | |
677 Lstream_flush (str); | |
678 if (!EQ (Vprint_message_label, echo_area_status (f))) | |
679 clear_echo_area_from_print (f, Qnil, 1); | |
680 echo_area_append (f, resizing_buffer_stream_ptr (str), | |
681 Qnil, 0, Lstream_byte_count (str), | |
682 Vprint_message_label); | |
683 Lstream_delete (str); | |
684 } | |
685 } | |
686 | |
687 | |
771 | 688 /* Write internal-format data to STREAM. See output_string() for |
689 interpretation of STREAM. | |
690 | |
691 NOTE: Do not call this with the data of a Lisp_String, as | |
428 | 692 printcharfun might cause a GC, which might cause the string's data |
693 to be relocated. To princ a Lisp string, use: | |
694 | |
695 print_internal (string, printcharfun, 0); | |
696 | |
697 Also note that STREAM should be the result of | |
698 canonicalize_printcharfun() (i.e. Qnil means stdout, not | |
699 Vstandard_output, etc.) */ | |
700 void | |
867 | 701 write_string_1 (Lisp_Object stream, const Ibyte *str, Bytecount size) |
428 | 702 { |
703 /* This function can GC */ | |
800 | 704 #ifdef ERROR_CHECK_TEXT |
428 | 705 assert (size >= 0); |
706 #endif | |
707 output_string (stream, str, Qnil, 0, size); | |
708 } | |
709 | |
710 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
711 write_istring (Lisp_Object stream, const Ibyte *str) |
771 | 712 { |
713 /* This function can GC */ | |
826 | 714 write_string_1 (stream, str, qxestrlen (str)); |
771 | 715 } |
716 | |
717 void | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
718 write_cistring (Lisp_Object stream, const CIbyte *str) |
428 | 719 { |
720 /* This function can GC */ | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
721 write_istring (stream, (const Ibyte *) str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
722 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
723 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
724 void |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
725 write_ascstring (Lisp_Object stream, const Ascbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
726 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
727 /* This function can GC */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
728 ASSERT_ASCTEXT_ASCII (str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
729 write_istring (stream, (const Ibyte *) str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
730 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
731 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
732 void |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
733 write_msg_istring (Lisp_Object stream, const Ibyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
734 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
735 /* This function can GC */ |
4973 | 736 write_istring (stream, IGETTEXT (str)); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
737 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
738 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
739 void |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
740 write_msg_cistring (Lisp_Object stream, const CIbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
741 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
742 /* This function can GC */ |
4973 | 743 write_msg_istring (stream, (const Ibyte *) str); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
744 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
745 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
746 void |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
747 write_msg_ascstring (Lisp_Object stream, const Ascbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
748 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
749 /* This function can GC */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
750 ASSERT_ASCTEXT_ASCII (str); |
4973 | 751 write_msg_istring (stream, (const Ibyte *) str); |
428 | 752 } |
753 | |
793 | 754 void |
826 | 755 write_eistring (Lisp_Object stream, const Eistring *ei) |
793 | 756 { |
826 | 757 write_string_1 (stream, eidata (ei), eilen (ei)); |
793 | 758 } |
759 | |
771 | 760 /* Write a printf-style string to STREAM; see output_string(). */ |
761 | |
762 void | |
867 | 763 write_fmt_string (Lisp_Object stream, const CIbyte *fmt, ...) |
771 | 764 { |
765 va_list va; | |
867 | 766 Ibyte *str; |
771 | 767 Bytecount len; |
768 int count; | |
769 | |
770 va_start (va, fmt); | |
771 str = emacs_vsprintf_malloc (fmt, va, &len); | |
772 va_end (va); | |
773 count = record_unwind_protect_freeing (str); | |
826 | 774 write_string_1 (stream, str, len); |
771 | 775 unbind_to (count); |
776 } | |
777 | |
778 /* Write a printf-style string to STREAM, where the arguments are | |
779 Lisp objects and not C strings or integers; see output_string(). | |
780 | |
781 #### It shouldn't be necessary to specify the number of arguments. | |
782 This would require some rewriting of the doprnt() functions, though. */ | |
783 | |
784 void | |
867 | 785 write_fmt_string_lisp (Lisp_Object stream, const CIbyte *fmt, int nargs, ...) |
771 | 786 { |
787 Lisp_Object *args = alloca_array (Lisp_Object, nargs); | |
788 va_list va; | |
789 int i; | |
867 | 790 Ibyte *str; |
771 | 791 Bytecount len; |
792 int count; | |
793 | |
794 va_start (va, nargs); | |
795 for (i = 0; i < nargs; i++) | |
796 args[i] = va_arg (va, Lisp_Object); | |
797 va_end (va); | |
798 str = emacs_vsprintf_malloc_lisp (fmt, Qnil, nargs, args, &len); | |
799 count = record_unwind_protect_freeing (str); | |
826 | 800 write_string_1 (stream, str, len); |
771 | 801 unbind_to (count); |
802 } | |
803 | |
804 void | |
867 | 805 stderr_out_lisp (const CIbyte *fmt, int nargs, ...) |
771 | 806 { |
807 Lisp_Object *args = alloca_array (Lisp_Object, nargs); | |
808 va_list va; | |
809 int i; | |
867 | 810 Ibyte *str; |
771 | 811 Bytecount len; |
812 int count; | |
813 | |
814 va_start (va, nargs); | |
815 for (i = 0; i < nargs; i++) | |
816 args[i] = va_arg (va, Lisp_Object); | |
817 va_end (va); | |
818 str = emacs_vsprintf_malloc_lisp (fmt, Qnil, nargs, args, &len); | |
819 count = record_unwind_protect_freeing (str); | |
826 | 820 write_string_1 (Qexternal_debugging_output, str, len); |
771 | 821 unbind_to (count); |
822 } | |
823 | |
428 | 824 |
825 DEFUN ("write-char", Fwrite_char, 1, 2, 0, /* | |
444 | 826 Output character CHARACTER to stream STREAM. |
428 | 827 STREAM defaults to the value of `standard-output' (which see). |
828 */ | |
444 | 829 (character, stream)) |
428 | 830 { |
831 /* This function can GC */ | |
867 | 832 Ibyte str[MAX_ICHAR_LEN]; |
428 | 833 Bytecount len; |
834 | |
444 | 835 CHECK_CHAR_COERCE_INT (character); |
867 | 836 len = set_itext_ichar (str, XCHAR (character)); |
428 | 837 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, len); |
444 | 838 return character; |
428 | 839 } |
840 | |
841 void | |
842 temp_output_buffer_setup (Lisp_Object bufname) | |
843 { | |
844 /* This function can GC */ | |
845 struct buffer *old = current_buffer; | |
846 Lisp_Object buf; | |
847 | |
848 #ifdef I18N3 | |
849 /* #### This function should accept a Lisp_Object instead of a char *, | |
850 so that proper translation on the buffer name can occur. */ | |
851 #endif | |
852 | |
853 Fset_buffer (Fget_buffer_create (bufname)); | |
854 | |
855 current_buffer->read_only = Qnil; | |
856 Ferase_buffer (Qnil); | |
857 | |
793 | 858 buf = wrap_buffer (current_buffer); |
428 | 859 specbind (Qstandard_output, buf); |
860 | |
861 set_buffer_internal (old); | |
862 } | |
863 | |
864 Lisp_Object | |
865 internal_with_output_to_temp_buffer (Lisp_Object bufname, | |
866 Lisp_Object (*function) (Lisp_Object arg), | |
867 Lisp_Object arg, | |
868 Lisp_Object same_frame) | |
869 { | |
870 int speccount = specpdl_depth (); | |
871 struct gcpro gcpro1, gcpro2, gcpro3; | |
872 Lisp_Object buf = Qnil; | |
873 | |
874 GCPRO3 (buf, arg, same_frame); | |
875 | |
876 temp_output_buffer_setup (bufname); | |
877 buf = Vstandard_output; | |
878 | |
879 arg = (*function) (arg); | |
880 | |
881 temp_output_buffer_show (buf, same_frame); | |
882 UNGCPRO; | |
883 | |
771 | 884 return unbind_to_1 (speccount, arg); |
428 | 885 } |
886 | |
887 DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, 1, UNEVALLED, 0, /* | |
888 Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer. | |
889 The buffer is cleared out initially, and marked as unmodified when done. | |
890 All output done by BODY is inserted in that buffer by default. | |
891 The buffer is displayed in another window, but not selected. | |
892 The value of the last form in BODY is returned. | |
893 If BODY does not finish normally, the buffer BUFNAME is not displayed. | |
894 | |
895 If variable `temp-buffer-show-function' is non-nil, call it at the end | |
896 to get the buffer displayed. It gets one argument, the buffer to display. | |
4693
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
897 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
898 arguments: (BUFNAME &rest BODY) |
428 | 899 */ |
900 (args)) | |
901 { | |
902 /* This function can GC */ | |
903 Lisp_Object name = Qnil; | |
904 int speccount = specpdl_depth (); | |
905 struct gcpro gcpro1, gcpro2; | |
906 Lisp_Object val = Qnil; | |
907 | |
908 #ifdef I18N3 | |
909 /* #### should set the buffer to be translating. See print_internal(). */ | |
910 #endif | |
911 | |
912 GCPRO2 (name, val); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4528
diff
changeset
|
913 name = IGNORE_MULTIPLE_VALUES (Feval (XCAR (args))); |
428 | 914 |
915 CHECK_STRING (name); | |
916 | |
917 temp_output_buffer_setup (name); | |
918 UNGCPRO; | |
919 | |
920 val = Fprogn (XCDR (args)); | |
921 | |
922 temp_output_buffer_show (Vstandard_output, Qnil); | |
923 | |
771 | 924 return unbind_to_1 (speccount, val); |
428 | 925 } |
926 | |
927 DEFUN ("terpri", Fterpri, 0, 1, 0, /* | |
928 Output a newline to STREAM. | |
929 If STREAM is omitted or nil, the value of `standard-output' is used. | |
930 */ | |
931 (stream)) | |
932 { | |
933 /* This function can GC */ | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
934 write_ascstring (canonicalize_printcharfun (stream), "\n"); |
428 | 935 return Qt; |
936 } | |
937 | |
938 DEFUN ("prin1", Fprin1, 1, 2, 0, /* | |
939 Output the printed representation of OBJECT, any Lisp object. | |
940 Quoting characters are printed when needed to make output that `read' | |
941 can handle, whenever this is possible. | |
942 Output stream is STREAM, or value of `standard-output' (which see). | |
943 */ | |
944 (object, stream)) | |
945 { | |
946 /* This function can GC */ | |
947 Lisp_Object frame = Qnil; | |
948 struct gcpro gcpro1, gcpro2; | |
949 GCPRO2 (object, stream); | |
950 | |
951 stream = print_prepare (stream, &frame); | |
952 print_internal (object, stream, 1); | |
953 print_finish (stream, frame); | |
954 | |
955 UNGCPRO; | |
956 return object; | |
957 } | |
958 | |
4394
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
959 Lisp_Object |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
960 prin1_to_string (Lisp_Object object, int noescape) |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
961 { |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
962 /* This function can GC */ |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
963 Lisp_Object result = Qnil; |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
964 Lisp_Object stream = make_resizing_buffer_output_stream (); |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
965 Lstream *str = XLSTREAM (stream); |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
966 /* gcpro OBJECT in case a caller forgot to do so */ |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
967 struct gcpro gcpro1, gcpro2, gcpro3; |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
968 GCPRO3 (object, stream, result); |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
969 |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
970 print_internal (object, stream, !noescape); |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
971 Lstream_flush (str); |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
972 UNGCPRO; |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
973 result = make_string (resizing_buffer_stream_ptr (str), |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
974 Lstream_byte_count (str)); |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
975 Lstream_delete (str); |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
976 return result; |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
977 } |
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
978 |
428 | 979 DEFUN ("prin1-to-string", Fprin1_to_string, 1, 2, 0, /* |
980 Return a string containing the printed representation of OBJECT, | |
981 any Lisp object. Quoting characters are used when needed to make output | |
982 that `read' can handle, whenever this is possible, unless the optional | |
983 second argument NOESCAPE is non-nil. | |
984 */ | |
985 (object, noescape)) | |
986 { | |
987 /* This function can GC */ | |
988 Lisp_Object result = Qnil; | |
989 | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
990 RESET_PRINT_NUMBER_TABLE; |
4394
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
991 result = prin1_to_string (object, !(EQ(noescape, Qnil))); |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
992 RESET_PRINT_NUMBER_TABLE; |
4394
cacc942c0d0f
Avoid clearing print-gensym-alist inappropriately when printing hash tables.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4329
diff
changeset
|
993 |
428 | 994 return result; |
995 } | |
996 | |
997 DEFUN ("princ", Fprinc, 1, 2, 0, /* | |
998 Output the printed representation of OBJECT, any Lisp object. | |
999 No quoting characters are used; no delimiters are printed around | |
1000 the contents of strings. | |
444 | 1001 Output stream is STREAM, or value of `standard-output' (which see). |
428 | 1002 */ |
1003 (object, stream)) | |
1004 { | |
1005 /* This function can GC */ | |
1006 Lisp_Object frame = Qnil; | |
1007 struct gcpro gcpro1, gcpro2; | |
1008 | |
1009 GCPRO2 (object, stream); | |
1010 stream = print_prepare (stream, &frame); | |
1011 print_internal (object, stream, 0); | |
1012 print_finish (stream, frame); | |
1013 UNGCPRO; | |
1014 return object; | |
1015 } | |
1016 | |
1017 DEFUN ("print", Fprint, 1, 2, 0, /* | |
1018 Output the printed representation of OBJECT, with newlines around it. | |
1019 Quoting characters are printed when needed to make output that `read' | |
1020 can handle, whenever this is possible. | |
1021 Output stream is STREAM, or value of `standard-output' (which see). | |
1022 */ | |
1023 (object, stream)) | |
1024 { | |
1025 /* This function can GC */ | |
1026 Lisp_Object frame = Qnil; | |
1027 struct gcpro gcpro1, gcpro2; | |
1028 | |
1029 GCPRO2 (object, stream); | |
1030 stream = print_prepare (stream, &frame); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1031 write_ascstring (stream, "\n"); |
428 | 1032 print_internal (object, stream, 1); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1033 write_ascstring (stream, "\n"); |
428 | 1034 print_finish (stream, frame); |
1035 UNGCPRO; | |
1036 return object; | |
1037 } | |
1038 | |
1039 /* Print an error message for the error DATA to STREAM. This is a | |
1040 complete implementation of `display-error', which used to be in | |
1041 Lisp (see prim/cmdloop.el). It was ported to C so it can be used | |
1042 efficiently by Ferror_message_string. Fdisplay_error and | |
1043 Ferror_message_string are trivial wrappers around this function. | |
1044 | |
1045 STREAM should be the result of canonicalize_printcharfun(). */ | |
1046 static void | |
1047 print_error_message (Lisp_Object error_object, Lisp_Object stream) | |
1048 { | |
1049 /* This function can GC */ | |
1050 Lisp_Object type = Fcar_safe (error_object); | |
1051 Lisp_Object method = Qnil; | |
1052 Lisp_Object tail; | |
1053 | |
1054 /* No need to GCPRO anything under the assumption that ERROR_OBJECT | |
1055 is GCPRO'd. */ | |
1056 | |
1057 if (! (CONSP (error_object) && SYMBOLP (type) | |
1058 && CONSP (Fget (type, Qerror_conditions, Qnil)))) | |
1059 goto error_throw; | |
1060 | |
1061 tail = XCDR (error_object); | |
1062 while (!NILP (tail)) | |
1063 { | |
1064 if (CONSP (tail)) | |
1065 tail = XCDR (tail); | |
1066 else | |
1067 goto error_throw; | |
1068 } | |
1069 tail = Fget (type, Qerror_conditions, Qnil); | |
1070 while (!NILP (tail)) | |
1071 { | |
1072 if (!(CONSP (tail) && SYMBOLP (XCAR (tail)))) | |
1073 goto error_throw; | |
1074 else if (!NILP (Fget (XCAR (tail), Qdisplay_error, Qnil))) | |
1075 { | |
1076 method = Fget (XCAR (tail), Qdisplay_error, Qnil); | |
1077 goto error_throw; | |
1078 } | |
1079 else | |
1080 tail = XCDR (tail); | |
1081 } | |
1082 /* Default method */ | |
1083 { | |
1084 int first = 1; | |
1085 int speccount = specpdl_depth (); | |
438 | 1086 Lisp_Object frame = Qnil; |
1087 struct gcpro gcpro1; | |
1088 GCPRO1 (stream); | |
428 | 1089 |
1090 specbind (Qprint_message_label, Qerror); | |
438 | 1091 stream = print_prepare (stream, &frame); |
1092 | |
428 | 1093 tail = Fcdr (error_object); |
1094 if (EQ (type, Qerror)) | |
1095 { | |
1096 print_internal (Fcar (tail), stream, 0); | |
1097 tail = Fcdr (tail); | |
1098 } | |
1099 else | |
1100 { | |
1101 Lisp_Object errmsg = Fget (type, Qerror_message, Qnil); | |
1102 if (NILP (errmsg)) | |
1103 print_internal (type, stream, 0); | |
1104 else | |
1105 print_internal (LISP_GETTEXT (errmsg), stream, 0); | |
1106 } | |
1107 while (!NILP (tail)) | |
1108 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1109 write_ascstring (stream, first ? ": " : ", "); |
563 | 1110 /* Most errors have an explanatory string as their first argument, |
1111 and it looks better not to put the quotes around it. */ | |
1112 print_internal (Fcar (tail), stream, | |
1113 !(first && STRINGP (Fcar (tail))) || | |
1114 !NILP (Fget (type, Qerror_lacks_explanatory_string, | |
1115 Qnil))); | |
428 | 1116 tail = Fcdr (tail); |
1117 first = 0; | |
1118 } | |
438 | 1119 print_finish (stream, frame); |
1120 UNGCPRO; | |
771 | 1121 unbind_to (speccount); |
428 | 1122 return; |
1123 /* not reached */ | |
1124 } | |
1125 | |
1126 error_throw: | |
1127 if (NILP (method)) | |
1128 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1129 write_ascstring (stream, GETTEXT ("Peculiar error ")); |
428 | 1130 print_internal (error_object, stream, 1); |
1131 return; | |
1132 } | |
1133 else | |
1134 { | |
1135 call2 (method, error_object, stream); | |
1136 } | |
1137 } | |
1138 | |
1139 DEFUN ("error-message-string", Ferror_message_string, 1, 1, 0, /* | |
1140 Convert ERROR-OBJECT to an error message, and return it. | |
1141 | |
1142 The format of ERROR-OBJECT should be (ERROR-SYMBOL . DATA). The | |
1143 message is equivalent to the one that would be issued by | |
1144 `display-error' with the same argument. | |
1145 */ | |
1146 (error_object)) | |
1147 { | |
1148 /* This function can GC */ | |
1149 Lisp_Object result = Qnil; | |
1150 Lisp_Object stream = make_resizing_buffer_output_stream (); | |
1151 struct gcpro gcpro1; | |
1152 GCPRO1 (stream); | |
1153 | |
1154 print_error_message (error_object, stream); | |
1155 Lstream_flush (XLSTREAM (stream)); | |
1156 result = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)), | |
1157 Lstream_byte_count (XLSTREAM (stream))); | |
1158 Lstream_delete (XLSTREAM (stream)); | |
1159 | |
1160 UNGCPRO; | |
1161 return result; | |
1162 } | |
1163 | |
1164 DEFUN ("display-error", Fdisplay_error, 2, 2, 0, /* | |
1165 Display ERROR-OBJECT on STREAM in a user-friendly way. | |
1166 */ | |
1167 (error_object, stream)) | |
1168 { | |
1169 /* This function can GC */ | |
1170 print_error_message (error_object, canonicalize_printcharfun (stream)); | |
1171 return Qnil; | |
1172 } | |
1173 | |
1174 | |
1175 Lisp_Object Vfloat_output_format; | |
1176 | |
1177 /* | |
1178 * This buffer should be at least as large as the max string size of the | |
440 | 1179 * largest float, printed in the biggest notation. This is undoubtedly |
428 | 1180 * 20d float_output_format, with the negative of the C-constant "HUGE" |
1181 * from <math.h>. | |
1182 * | |
1183 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes. | |
1184 * | |
1185 * I assume that IEEE-754 format numbers can take 329 bytes for the worst | |
1186 * case of -1e307 in 20d float_output_format. What is one to do (short of | |
1187 * re-writing _doprnt to be more sane)? | |
1188 * -wsr | |
1189 */ | |
1190 void | |
1191 float_to_string (char *buf, double data) | |
1192 { | |
867 | 1193 Ibyte *cp, c; |
428 | 1194 int width; |
1195 | |
1196 if (NILP (Vfloat_output_format) | |
1197 || !STRINGP (Vfloat_output_format)) | |
1198 lose: | |
1199 sprintf (buf, "%.16g", data); | |
1200 else /* oink oink */ | |
1201 { | |
1202 /* Check that the spec we have is fully valid. | |
1203 This means not only valid for printf, | |
1204 but meant for floats, and reasonable. */ | |
1205 cp = XSTRING_DATA (Vfloat_output_format); | |
1206 | |
1207 if (cp[0] != '%') | |
1208 goto lose; | |
1209 if (cp[1] != '.') | |
1210 goto lose; | |
1211 | |
1212 cp += 2; | |
1213 for (width = 0; (c = *cp, isdigit (c)); cp++) | |
1214 { | |
1215 width *= 10; | |
1216 width += c - '0'; | |
1217 } | |
1218 | |
1219 if (*cp != 'e' && *cp != 'f' && *cp != 'g' && *cp != 'E' && *cp != 'G') | |
1220 goto lose; | |
1221 | |
1222 if (width < (int) (*cp != 'e' && *cp != 'E') || width > DBL_DIG) | |
1223 goto lose; | |
1224 | |
1225 if (cp[1] != 0) | |
1226 goto lose; | |
1227 | |
1228 sprintf (buf, (char *) XSTRING_DATA (Vfloat_output_format), | |
1229 data); | |
1230 } | |
1231 | |
1232 /* added by jwz: don't allow "1.0" to print as "1"; that destroys | |
1233 the read-equivalence of lisp objects. (* x 1) and (* x 1.0) do | |
1234 not do the same thing, so it's important that the printed | |
1235 representation of that form not be corrupted by the printer. | |
1236 */ | |
1237 { | |
867 | 1238 Ibyte *s = (Ibyte *) buf; /* don't use signed chars here! |
428 | 1239 isdigit() can't hack them! */ |
1240 if (*s == '-') s++; | |
1241 for (; *s; s++) | |
1242 /* if there's a non-digit, then there is a decimal point, or | |
1243 it's in exponential notation, both of which are ok. */ | |
1244 if (!isdigit (*s)) | |
1245 goto DONE_LABEL; | |
1246 /* otherwise, we need to hack it. */ | |
1247 *s++ = '.'; | |
1248 *s++ = '0'; | |
1249 *s = 0; | |
1250 } | |
1251 DONE_LABEL: | |
1252 | |
1253 /* Some machines print "0.4" as ".4". I don't like that. */ | |
1254 if (buf [0] == '.' || (buf [0] == '-' && buf [1] == '.')) | |
1255 { | |
1256 int i; | |
1257 for (i = strlen (buf) + 1; i >= 0; i--) | |
1258 buf [i+1] = buf [i]; | |
1259 buf [(buf [0] == '-' ? 1 : 0)] = '0'; | |
1260 } | |
1261 } | |
1262 | |
2500 | 1263 #define ONE_DIGIT(figure) *p++ = (char) (n / (figure) + '0') |
577 | 1264 #define ONE_DIGIT_ADVANCE(figure) (ONE_DIGIT (figure), n %= (figure)) |
1265 | |
1266 #define DIGITS_1(figure) ONE_DIGIT (figure) | |
1267 #define DIGITS_2(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_1 ((figure) / 10) | |
1268 #define DIGITS_3(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_2 ((figure) / 10) | |
1269 #define DIGITS_4(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_3 ((figure) / 10) | |
1270 #define DIGITS_5(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_4 ((figure) / 10) | |
1271 #define DIGITS_6(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_5 ((figure) / 10) | |
1272 #define DIGITS_7(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_6 ((figure) / 10) | |
1273 #define DIGITS_8(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_7 ((figure) / 10) | |
1274 #define DIGITS_9(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_8 ((figure) / 10) | |
1275 #define DIGITS_10(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_9 ((figure) / 10) | |
1276 | |
1277 /* DIGITS_<11-20> are only used on machines with 64-bit longs. */ | |
428 | 1278 |
577 | 1279 #define DIGITS_11(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_10 ((figure) / 10) |
1280 #define DIGITS_12(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_11 ((figure) / 10) | |
1281 #define DIGITS_13(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_12 ((figure) / 10) | |
1282 #define DIGITS_14(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_13 ((figure) / 10) | |
1283 #define DIGITS_15(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_14 ((figure) / 10) | |
1284 #define DIGITS_16(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_15 ((figure) / 10) | |
1285 #define DIGITS_17(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_16 ((figure) / 10) | |
1286 #define DIGITS_18(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_17 ((figure) / 10) | |
1287 #define DIGITS_19(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_18 ((figure) / 10) | |
1288 | |
1289 /* Print NUMBER to BUFFER in base 10. This is completely equivalent | |
1290 to `sprintf(buffer, "%ld", number)', only much faster. | |
1291 | |
1292 The speedup may make a difference in programs that frequently | |
1293 convert numbers to strings. Some implementations of sprintf, | |
1294 particularly the one in GNU libc, have been known to be extremely | |
1295 slow compared to this function. | |
1296 | |
1297 BUFFER should accept as many bytes as you expect the number to take | |
1298 up. On machines with 64-bit longs the maximum needed size is 24 | |
1299 bytes. That includes the worst-case digits, the optional `-' sign, | |
1300 and the trailing \0. */ | |
1301 | |
1302 void | |
428 | 1303 long_to_string (char *buffer, long number) |
1304 { | |
577 | 1305 char *p = buffer; |
1306 long n = number; | |
1307 | |
428 | 1308 #if (SIZEOF_LONG != 4) && (SIZEOF_LONG != 8) |
577 | 1309 /* We are running in a strange or misconfigured environment. Let |
1310 sprintf cope with it. */ | |
1311 sprintf (buffer, "%ld", n); | |
1312 #else /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */ | |
428 | 1313 |
577 | 1314 if (n < 0) |
428 | 1315 { |
1316 *p++ = '-'; | |
577 | 1317 n = -n; |
428 | 1318 } |
1319 | |
577 | 1320 if (n < 10) { DIGITS_1 (1); } |
1321 else if (n < 100) { DIGITS_2 (10); } | |
1322 else if (n < 1000) { DIGITS_3 (100); } | |
1323 else if (n < 10000) { DIGITS_4 (1000); } | |
1324 else if (n < 100000) { DIGITS_5 (10000); } | |
1325 else if (n < 1000000) { DIGITS_6 (100000); } | |
1326 else if (n < 10000000) { DIGITS_7 (1000000); } | |
1327 else if (n < 100000000) { DIGITS_8 (10000000); } | |
1328 else if (n < 1000000000) { DIGITS_9 (100000000); } | |
1329 #if SIZEOF_LONG == 4 | |
1330 /* ``if (1)'' serves only to preserve editor indentation. */ | |
1331 else if (1) { DIGITS_10 (1000000000); } | |
1332 #else /* SIZEOF_LONG != 4 */ | |
1333 else if (n < 10000000000L) { DIGITS_10 (1000000000L); } | |
1334 else if (n < 100000000000L) { DIGITS_11 (10000000000L); } | |
1335 else if (n < 1000000000000L) { DIGITS_12 (100000000000L); } | |
1336 else if (n < 10000000000000L) { DIGITS_13 (1000000000000L); } | |
1337 else if (n < 100000000000000L) { DIGITS_14 (10000000000000L); } | |
1338 else if (n < 1000000000000000L) { DIGITS_15 (100000000000000L); } | |
1339 else if (n < 10000000000000000L) { DIGITS_16 (1000000000000000L); } | |
1340 else if (n < 100000000000000000L) { DIGITS_17 (10000000000000000L); } | |
1341 else if (n < 1000000000000000000L) { DIGITS_18 (100000000000000000L); } | |
1342 else { DIGITS_19 (1000000000000000000L); } | |
1343 #endif /* SIZEOF_LONG != 4 */ | |
1344 | |
428 | 1345 *p = '\0'; |
1346 #endif /* (SIZEOF_LONG == 4) || (SIZEOF_LONG == 8) */ | |
1347 } | |
577 | 1348 |
1349 #undef ONE_DIGIT | |
1350 #undef ONE_DIGIT_ADVANCE | |
1351 | |
1352 #undef DIGITS_1 | |
1353 #undef DIGITS_2 | |
1354 #undef DIGITS_3 | |
1355 #undef DIGITS_4 | |
1356 #undef DIGITS_5 | |
1357 #undef DIGITS_6 | |
1358 #undef DIGITS_7 | |
1359 #undef DIGITS_8 | |
1360 #undef DIGITS_9 | |
1361 #undef DIGITS_10 | |
1362 #undef DIGITS_11 | |
1363 #undef DIGITS_12 | |
1364 #undef DIGITS_13 | |
1365 #undef DIGITS_14 | |
1366 #undef DIGITS_15 | |
1367 #undef DIGITS_16 | |
1368 #undef DIGITS_17 | |
1369 #undef DIGITS_18 | |
1370 #undef DIGITS_19 | |
428 | 1371 |
4329
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1372 void |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1373 ulong_to_bit_string (char *p, unsigned long number) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1374 { |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1375 int i, seen_high_order = 0;; |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1376 |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1377 for (i = ((SIZEOF_LONG * 8) - 1); i >= 0; --i) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1378 { |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1379 if (number & (unsigned long)1 << i) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1380 { |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1381 seen_high_order = 1; |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1382 *p++ = '1'; |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1383 } |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1384 else |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1385 { |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1386 if (seen_high_order) |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1387 { |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1388 *p++ = '0'; |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1389 } |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1390 } |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1391 } |
5295
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1392 |
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1393 if (!seen_high_order) |
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1394 { |
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1395 *p++ = '0'; |
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1396 } |
2474dce7304e
Make sure (format "%b" 0) is non-zero length, print.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
5243
diff
changeset
|
1397 |
4329
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1398 *p = '\0'; |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1399 } |
d9eb5ea14f65
Provide %b in #'format; use it for converting between ints and bit vectors.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1400 |
428 | 1401 static void |
442 | 1402 print_vector_internal (const char *start, const char *end, |
428 | 1403 Lisp_Object obj, |
1404 Lisp_Object printcharfun, int escapeflag) | |
1405 { | |
1406 /* This function can GC */ | |
1407 int i; | |
1408 int len = XVECTOR_LENGTH (obj); | |
1409 int last = len; | |
1410 struct gcpro gcpro1, gcpro2; | |
1411 GCPRO2 (obj, printcharfun); | |
1412 | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1413 if (FIXNUMP (Vprint_length)) |
428 | 1414 { |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1415 int max = XFIXNUM (Vprint_length); |
428 | 1416 if (max < len) last = max; |
1417 } | |
1418 | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1419 write_cistring (printcharfun, start); |
428 | 1420 for (i = 0; i < last; i++) |
1421 { | |
1422 Lisp_Object elt = XVECTOR_DATA (obj)[i]; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1423 if (i != 0) write_ascstring (printcharfun, " "); |
428 | 1424 print_internal (elt, printcharfun, escapeflag); |
1425 } | |
1426 UNGCPRO; | |
1427 if (last != len) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1428 write_ascstring (printcharfun, " ..."); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1429 write_cistring (printcharfun, end); |
428 | 1430 } |
1431 | |
1432 void | |
1433 print_cons (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
1434 { | |
1435 /* This function can GC */ | |
1436 struct gcpro gcpro1, gcpro2; | |
1437 | |
1438 /* If print_readably is on, print (quote -foo-) as '-foo- | |
1439 (Yeah, this should really be what print-pretty does, but we | |
1440 don't have the rest of a pretty printer, and this actually | |
1441 has non-negligible impact on size/speed of .elc files.) | |
1442 */ | |
1443 if (print_readably && | |
1444 EQ (XCAR (obj), Qquote) && | |
1445 CONSP (XCDR (obj)) && | |
1446 NILP (XCDR (XCDR (obj)))) | |
1447 { | |
1448 obj = XCAR (XCDR (obj)); | |
1449 GCPRO2 (obj, printcharfun); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1450 write_ascstring (printcharfun, "\'"); |
428 | 1451 UNGCPRO; |
1452 print_internal (obj, printcharfun, escapeflag); | |
1453 return; | |
1454 } | |
1455 | |
1456 GCPRO2 (obj, printcharfun); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1457 write_ascstring (printcharfun, "("); |
428 | 1458 |
1459 { | |
1460 int len; | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1461 int max = FIXNUMP (Vprint_length) ? XFIXNUM (Vprint_length) : INT_MAX; |
428 | 1462 Lisp_Object tortoise; |
1463 /* Use tortoise/hare to make sure circular lists don't infloop */ | |
1464 | |
1465 for (tortoise = obj, len = 0; | |
1466 CONSP (obj); | |
1467 obj = XCDR (obj), len++) | |
1468 { | |
1469 if (len > 0) | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1470 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1471 write_ascstring (printcharfun, " "); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1472 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1473 /* Note that print_cons is the only object method that does any |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1474 circularity checking itself, because a cons that is the cdr |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1475 of OBJ is not handed to print_internal in the ordinary course |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1476 of events. All the other possibly-repeated structures always |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1477 hand sub-objects to print_internal(). */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1478 if (print_circle && |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1479 FIXNUMP (Fgethash (obj, Vprint_number_table, Qnil))) |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1480 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1481 write_ascstring (printcharfun, ". "); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1482 print_internal (obj, printcharfun, escapeflag); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1483 /* We have printed the list's tail, print_cons() is done. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1484 break; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1485 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1486 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1487 if (EQ (obj, tortoise)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1488 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1489 if (print_readably) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1490 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1491 printing_unreadable_object_fmt ("circular list"); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1492 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1493 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1494 write_ascstring (printcharfun, "... <circular list>"); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1495 break; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1496 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1497 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1498 if (len & 1) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1499 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1500 tortoise = XCDR (tortoise); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1501 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1502 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1503 if (len > max) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1504 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1505 write_ascstring (printcharfun, "..."); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1506 break; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1507 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1508 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1509 |
428 | 1510 print_internal (XCAR (obj), printcharfun, escapeflag); |
1511 } | |
1512 } | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1513 |
428 | 1514 if (!LISTP (obj)) |
1515 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1516 write_ascstring (printcharfun, " . "); |
428 | 1517 print_internal (obj, printcharfun, escapeflag); |
1518 } | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1519 |
428 | 1520 UNGCPRO; |
1521 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1522 write_ascstring (printcharfun, ")"); |
428 | 1523 return; |
1524 } | |
1525 | |
1526 void | |
1527 print_vector (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
1528 { | |
1529 print_vector_internal ("[", "]", obj, printcharfun, escapeflag); | |
1530 } | |
1531 | |
1532 void | |
1533 print_string (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
1534 { | |
1535 /* We distinguish between Bytecounts and Charcounts, to make | |
1536 Vprint_string_length work correctly under Mule. */ | |
826 | 1537 Charcount size = string_char_length (obj); |
428 | 1538 Charcount max = size; |
793 | 1539 Bytecount bcmax = XSTRING_LENGTH (obj); |
428 | 1540 struct gcpro gcpro1, gcpro2; |
1541 GCPRO2 (obj, printcharfun); | |
1542 | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1543 if (FIXNUMP (Vprint_string_length) && |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1544 XFIXNUM (Vprint_string_length) < max) |
428 | 1545 { |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1546 max = XFIXNUM (Vprint_string_length); |
793 | 1547 bcmax = string_index_char_to_byte (obj, max); |
428 | 1548 } |
1549 if (max < 0) | |
1550 { | |
1551 max = 0; | |
1552 bcmax = 0; | |
1553 } | |
1554 | |
1555 if (!escapeflag) | |
1556 { | |
1557 /* This deals with GC-relocation and Mule. */ | |
1558 output_string (printcharfun, 0, obj, 0, bcmax); | |
1559 if (max < size) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1560 write_ascstring (printcharfun, " ..."); |
428 | 1561 } |
1562 else | |
1563 { | |
1564 Bytecount i, last = 0; | |
1565 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1566 write_ascstring (printcharfun, "\""); |
428 | 1567 for (i = 0; i < bcmax; i++) |
1568 { | |
867 | 1569 Ibyte ch = string_byte (obj, i); |
428 | 1570 if (ch == '\"' || ch == '\\' |
1571 || (ch == '\n' && print_escape_newlines)) | |
1572 { | |
1573 if (i > last) | |
1574 { | |
1575 output_string (printcharfun, 0, obj, last, | |
1576 i - last); | |
1577 } | |
1578 if (ch == '\n') | |
1579 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1580 write_ascstring (printcharfun, "\\n"); |
428 | 1581 } |
1582 else | |
1583 { | |
867 | 1584 Ibyte temp[2]; |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1585 write_ascstring (printcharfun, "\\"); |
428 | 1586 /* This is correct for Mule because the |
1587 character is either \ or " */ | |
826 | 1588 temp[0] = string_byte (obj, i); |
1589 temp[1] = '\0'; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1590 write_istring (printcharfun, temp); |
428 | 1591 } |
1592 last = i + 1; | |
1593 } | |
1594 } | |
1595 if (bcmax > last) | |
1596 { | |
1597 output_string (printcharfun, 0, obj, last, | |
1598 bcmax - last); | |
1599 } | |
1600 if (max < size) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1601 write_ascstring (printcharfun, " ..."); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1602 write_ascstring (printcharfun, "\""); |
428 | 1603 } |
1604 UNGCPRO; | |
1605 } | |
1606 | |
4846 | 1607 DOESNT_RETURN |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1608 printing_unreadable_object_fmt (const Ascbyte *fmt, ...) |
4846 | 1609 { |
1610 Lisp_Object obj; | |
1611 va_list args; | |
1612 | |
1613 va_start (args, fmt); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1614 obj = emacs_vsprintf_string (GETTEXT (fmt), args); |
4846 | 1615 va_end (args); |
1616 | |
1617 /* Fsignal GC-protects its args */ | |
1618 signal_error (Qprinting_unreadable_object, 0, obj); | |
1619 } | |
1620 | |
1621 DOESNT_RETURN | |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1622 printing_unreadable_lisp_object (Lisp_Object obj, const Ibyte *name) |
428 | 1623 { |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1624 struct lrecord_header *header = (struct lrecord_header *) XPNTR (obj); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1625 const struct lrecord_implementation *imp = |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1626 XRECORD_LHEADER_IMPLEMENTATION (obj); |
428 | 1627 |
4846 | 1628 if (name) |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1629 printing_unreadable_object_fmt ("#<%s %s 0x%x>", imp->name, name, header->uid); |
4846 | 1630 else |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1631 printing_unreadable_object_fmt ("#<%s 0x%x>", imp->name, header->uid); |
4846 | 1632 } |
1633 | |
1634 void | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1635 external_object_printer (Lisp_Object obj, Lisp_Object printcharfun, |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1636 int UNUSED (escapeflag)) |
4846 | 1637 { |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1638 struct lrecord_header *header = (struct lrecord_header *) XPNTR (obj); |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1639 const struct lrecord_implementation *imp = |
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1640 XRECORD_LHEADER_IMPLEMENTATION (obj); |
4846 | 1641 |
1642 if (print_readably) | |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1643 printing_unreadable_lisp_object (obj, 0); |
428 | 1644 |
5127
a9c41067dd88
more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents:
5125
diff
changeset
|
1645 write_fmt_string (printcharfun, "#<%s 0x%x>", imp->name, header->uid); |
428 | 1646 } |
1647 | |
1648 void | |
1649 internal_object_printer (Lisp_Object obj, Lisp_Object printcharfun, | |
2286 | 1650 int UNUSED (escapeflag)) |
428 | 1651 { |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1652 if (print_readably) |
5142
f965e31a35f0
reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents:
5127
diff
changeset
|
1653 printing_unreadable_object_fmt |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1654 ("#<INTERNAL OBJECT (XEmacs bug?) (%s) 0x%x>", |
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1655 XRECORD_LHEADER_IMPLEMENTATION (obj)->name, LISP_OBJECT_UID (obj)); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1656 |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1657 /* Internal objects shouldn't normally escape to the Lisp level; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1658 that's why we say "XEmacs bug?". This can happen, however, when |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1659 printing backtraces. */ |
800 | 1660 write_fmt_string (printcharfun, |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1661 "#<INTERNAL OBJECT (XEmacs bug?) (%s) 0x%x>", |
800 | 1662 XRECORD_LHEADER_IMPLEMENTATION (obj)->name, |
5146
88bd4f3ef8e4
make lrecord UID's have a separate UID space for each object, resurrect debug SOE code in extents.c
Ben Wing <ben@xemacs.org>
parents:
5142
diff
changeset
|
1663 LISP_OBJECT_UID (obj)); |
428 | 1664 } |
1665 | |
1204 | 1666 enum printing_badness |
1667 { | |
1668 BADNESS_INTEGER_OBJECT, | |
1669 BADNESS_POINTER_OBJECT, | |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1670 BADNESS_POINTER_OBJECT_WITH_DATA, |
1204 | 1671 BADNESS_NO_TYPE |
1672 }; | |
1673 | |
1674 static void | |
1675 printing_major_badness (Lisp_Object printcharfun, | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1676 const Ascbyte *badness_string, int type, void *val, |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1677 void *val2, enum printing_badness badness) |
1204 | 1678 { |
1679 Ibyte buf[666]; | |
1680 | |
1681 switch (badness) | |
1682 { | |
1683 case BADNESS_INTEGER_OBJECT: | |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1684 qxesprintf (buf, "%s type %d object %ld", badness_string, type, |
1204 | 1685 (EMACS_INT) val); |
1686 break; | |
1687 | |
1688 case BADNESS_POINTER_OBJECT: | |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1689 qxesprintf (buf, "%s type %d object %p", badness_string, type, val); |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1690 break; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1691 |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1692 case BADNESS_POINTER_OBJECT_WITH_DATA: |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1693 qxesprintf (buf, "%s type %d object %p data %p", badness_string, type, |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1694 val, val2); |
1204 | 1695 break; |
1696 | |
1697 case BADNESS_NO_TYPE: | |
1698 qxesprintf (buf, "%s object %p", badness_string, val); | |
1699 break; | |
1700 } | |
1701 | |
1702 /* Don't abort or signal if called from debug_print() or already | |
1703 crashing */ | |
2367 | 1704 if (!inhibit_non_essential_conversion_operations) |
1204 | 1705 { |
1706 #ifdef ERROR_CHECK_TYPES | |
2500 | 1707 ABORT (); |
1204 | 1708 #else /* not ERROR_CHECK_TYPES */ |
1709 if (print_readably) | |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1710 signal_ferror (Qinternal_error, "SERIOUS XEMACS BUG: printing %s; " |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1711 "save your buffers immediately and please report " |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1712 "this bug", buf); |
1204 | 1713 #endif /* not ERROR_CHECK_TYPES */ |
1714 } | |
1715 write_fmt_string (printcharfun, | |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1716 "#<SERIOUS XEMACS BUG: %s Save your buffers immediately " |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1717 "and please report this bug>", buf); |
1204 | 1718 } |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1719 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1720 /* Not static only because of print_preprocess_cons. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1721 Elemcount print_preprocess_inchash_eq (Lisp_Object, Lisp_Object, Elemcount *); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1722 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1723 Elemcount |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1724 print_preprocess_inchash_eq (Lisp_Object obj, Lisp_Object table, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1725 Elemcount *seen_object_count) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1726 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1727 htentry *hte = inchash_eq (obj, table, 1); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1728 Elemcount extracted; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1729 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1730 /* If the hash table had to be resized, hte is NULL. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1731 if (hte == NULL) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1732 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1733 hte = find_htentry (obj, XHASH_TABLE (table)); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1734 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1735 |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1736 extracted = XFIXNUM (hte->value); |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1737 if (1 == extracted) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1738 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1739 *seen_object_count += 1; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1740 hte->value |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1741 = make_fixnum (1 | (*seen_object_count << PRINT_NUMBER_ORDINAL_SHIFT)); |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1742 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1743 else if ((extracted & PRINT_NUMBER_SEEN_MASK) == PRINT_NUMBER_SEEN_MASK) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1744 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1745 /* Avoid the number overflowing the bit field. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1746 extracted = (extracted & ~PRINT_NUMBER_SEEN_MASK) | 2; |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1747 hte->value = make_fixnum (extracted); |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1748 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1749 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1750 return extracted & PRINT_NUMBER_SEEN_MASK; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1751 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1752 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1753 /* Fill in Vprint_number_table according to the structure of OBJ. OBJ itself |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1754 and all its elements will be added to Vprint_number_table recursively if |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1755 its type has the print_preprocess method implemented. Objects with the |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1756 print_preprocess method implemented include cons, vector, compiled |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1757 function, hash table, char table, range table, and symbol. Symbol is an |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1758 exceptional type in that it is impossible to construct a recursive symbol |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1759 structure, but is here for the print-gensym feature. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1760 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1761 void |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1762 print_preprocess (Lisp_Object object, Lisp_Object print_number_table, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1763 Elemcount *seen_object_count) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1764 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1765 if (!LRECORDP (object) || !HAS_OBJECT_METH_P (object, print_preprocess)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1766 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1767 return; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1768 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1769 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1770 if (SYMBOLP (object) && IN_OBARRAY (object)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1771 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1772 /* Handle symbols specially. We do this here rather than in symbols.c |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1773 because we don't want to have all the other print_preprocess methods |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1774 worry about print_preprocess_inchash_eq. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1775 return; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1776 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1777 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1778 if (print_preprocess_inchash_eq (object, print_number_table, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1779 seen_object_count) > 1) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1780 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1781 return; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1782 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1783 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1784 OBJECT_METH (object, print_preprocess, (object, print_number_table, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1785 seen_object_count)); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1786 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1787 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1788 typedef struct { Lisp_Object key; Elemcount count; } preprocess_sort_t; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1789 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1790 static int |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1791 print_seen_once (Lisp_Object UNUSED (key), Lisp_Object value, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1792 void * UNUSED (extra_arg)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1793 { |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1794 return 1 == ((XFIXNUM (value) & PRINT_NUMBER_SEEN_MASK)); |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1795 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1796 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1797 static int |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1798 print_nonsymbol_seen_once (Lisp_Object key, Lisp_Object value, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1799 void * UNUSED (extra_arg)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1800 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1801 /* print_continuous_numbering is used for symbols, so we don't delete them |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1802 from the print info hash table. It's less useful for other objects at |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1803 the moment, though. */ |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1804 return !SYMBOLP (key) && (1 == ((XFIXNUM (value) & PRINT_NUMBER_SEEN_MASK))); |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1805 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1806 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1807 static int |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1808 print_sort_get_numbers (Lisp_Object key, Lisp_Object value, void *extra_arg) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1809 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1810 preprocess_sort_t **preprocess_sort_ptr = (preprocess_sort_t **) extra_arg; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1811 preprocess_sort_t *preprocess_sort = *preprocess_sort_ptr; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1812 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1813 *preprocess_sort_ptr += 1; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1814 preprocess_sort->key = key; |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1815 preprocess_sort->count = XFIXNUM (value); |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1816 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1817 return 0; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1818 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1819 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1820 static int |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1821 print_sort_compare_ordinals (const void *object1, const void *object2) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1822 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1823 Elemcount a = ((preprocess_sort_t *) object1)->count |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1824 & PRINT_NUMBER_ORDINAL_MASK; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1825 Elemcount b = ((preprocess_sort_t *) object2)->count |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1826 & PRINT_NUMBER_ORDINAL_MASK; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1827 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1828 return a - b; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1829 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1830 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1831 enum print_gensym_status |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1832 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1833 PRINT_GENSYM_DONE, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1834 PRINT_GENSYM_PRINT, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1835 PRINT_GENSYM_PRINT_AND_CLEANUP_TABLE, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1836 }; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1837 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1838 /* Check for any circular objects or repeated uninterned symbols. |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1839 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1840 If OBJ is a repeated structure (or symbol) and it has been printed |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1841 already, print it now in the #%d# format, and return 1, to indicate |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1842 print_internal is done. |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1843 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1844 If OBJ is a repeated structure and it has not yet been printed, print |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1845 #%d= before the object, mark it as printed, and return zero, to indicate |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1846 print_internal should continue as usual. |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1847 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1848 If OBJ is not a repeated structure, do nothing, and return zero, to |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1849 indicate print_internal should continue as usual. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1850 static enum print_gensym_status |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1851 print_gensym_or_circle (Lisp_Object obj, Lisp_Object printcharfun) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1852 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1853 Lisp_Object seen = Fgethash (obj, Vprint_number_table, Qnil); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1854 if (NILP (seen)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1855 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1856 Elemcount old_print_number_index = print_number_index; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1857 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1858 print_preprocess (obj, Vprint_number_table, &print_number_index); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1859 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1860 if (old_print_number_index != print_number_index) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1861 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1862 Elemcount new_print_number_index, ii; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1863 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1864 /* We support up to 25 bits' worth of repeated objects, which is |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1865 33 million or so, far more than we support in, say, a |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1866 compiled-function constants vector. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1867 assert (print_number_index <= |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1868 (PRINT_NUMBER_ORDINAL_MASK >> PRINT_NUMBER_ORDINAL_SHIFT)); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1869 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1870 /* If any objects have been seen once and once only, remove them |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1871 from Vprint_number_table. This is a bit of an arbitrary |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1872 decision; we could keep them around for the sake of |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1873 print_continuous_numbering, but there's the reasonable worry |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1874 about Vprint_number_table getting awkwardly large. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1875 elisp_map_remhash (print_continuous_numbering ? |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1876 print_nonsymbol_seen_once : print_seen_once, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1877 Vprint_number_table, NULL); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1878 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1879 new_print_number_index |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1880 = XFIXNUM (Fhash_table_count (Vprint_number_table)); |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1881 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1882 if (new_print_number_index != print_number_index |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1883 && new_print_number_index != old_print_number_index) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1884 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1885 preprocess_sort_t *preprocess_sort |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1886 = alloca_array (preprocess_sort_t, new_print_number_index); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1887 preprocess_sort_t *preprocess_sort_ptr = preprocess_sort; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1888 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1889 /* There are new objects in Vprint_number_table, but their |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1890 ordinal values don't necessarily represent the order they |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1891 were seen in, there will be gaps corresponding to the |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1892 non-symbols that were seen only once. Correct this. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1893 elisp_maphash_unsafe (print_sort_get_numbers, Vprint_number_table, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1894 &preprocess_sort_ptr); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1895 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1896 qsort (preprocess_sort, new_print_number_index, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1897 sizeof (preprocess_sort_t), print_sort_compare_ordinals); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1898 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1899 for (ii = old_print_number_index; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1900 ii < new_print_number_index; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1901 ii++) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1902 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1903 Fputhash (preprocess_sort[ii].key, |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1904 make_fixnum ((preprocess_sort[ii].count |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1905 & ~PRINT_NUMBER_ORDINAL_MASK) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1906 | ((ii + 1) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1907 << PRINT_NUMBER_ORDINAL_SHIFT)), |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1908 Vprint_number_table); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1909 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1910 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1911 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1912 print_number_index = new_print_number_index; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1913 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1914 /* The new objects may include OBJ; update SEEN to reflect |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1915 this. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1916 seen = Fgethash (obj, Vprint_number_table, Qnil); |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1917 if (FIXNUMP (seen)) |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1918 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1919 goto prefix_this; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1920 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1921 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1922 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1923 else |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1924 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1925 prefix_this: |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1926 if ((XFIXNUM (seen) & PRINT_NUMBER_SEEN_MASK) == 1 |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1927 && !(print_continuous_numbering && SYMBOLP (obj))) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1928 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1929 return PRINT_GENSYM_PRINT_AND_CLEANUP_TABLE; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1930 } |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1931 else if (XFIXNUM (seen) & PRINT_NUMBER_PRINTED_MASK) |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1932 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1933 write_fmt_string (printcharfun, "#%d#", |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1934 (XFIXNUM (seen) & PRINT_NUMBER_ORDINAL_MASK) |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1935 >> PRINT_NUMBER_ORDINAL_SHIFT); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1936 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1937 /* We're finished printing this object. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1938 return PRINT_GENSYM_DONE; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1939 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1940 else |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1941 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1942 write_fmt_string (printcharfun, "#%d=", |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1943 (XFIXNUM (seen) & PRINT_NUMBER_ORDINAL_MASK) |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1944 >> PRINT_NUMBER_ORDINAL_SHIFT); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1945 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1946 /* We set PRINT_NUMBER_PRINTED_MASK immediately here, so the |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1947 object itself is written as #%d# when printing its contents. */ |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1948 Fputhash (obj, make_fixnum (XFIXNUM (seen) | PRINT_NUMBER_PRINTED_MASK), |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1949 Vprint_number_table); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1950 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1951 /* This is the first time the object has been seen while |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1952 printing the recursive object; we still have to go ahead |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1953 and do the actual print. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1954 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1955 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1956 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1957 return PRINT_GENSYM_PRINT; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1958 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1959 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1960 Lisp_Object |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1961 nsubst_structures_descend (Lisp_Object new_, Lisp_Object old, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1962 Lisp_Object tree, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1963 Lisp_Object number_table, Boolint test_not_unboundp) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1964 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1965 Lisp_Object seen; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1966 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1967 if (!LRECORDP (tree) || !HAS_OBJECT_METH_P (tree, nsubst_structures_descend)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1968 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1969 return tree; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1970 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1971 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1972 seen = Fgethash (tree, number_table, Qnil); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1973 |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1974 if (FIXNUMP (seen)) |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1975 { |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1976 if (XFIXNUM (seen) & PRINT_NUMBER_PRINTED_MASK) |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1977 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1978 return tree; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1979 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1980 |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
1981 Fputhash (tree, make_fixnum (XFIXNUM (seen) | PRINT_NUMBER_PRINTED_MASK), |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1982 number_table); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1983 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1984 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1985 OBJECT_METH (tree, nsubst_structures_descend, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1986 (new_, old, tree, number_table, test_not_unboundp)); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1987 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1988 return tree; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1989 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1990 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1991 /* Descend TREE, replacing the Lisp object OLD each time it is encountered |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1992 with the Lisp object NEW_. TREE can be recursive or circular, and this is |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1993 handled correctly. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1994 Lisp_Object |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1995 nsubst_structures (Lisp_Object new_, Lisp_Object old, Lisp_Object tree, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1996 check_test_func_t check_test, Boolint test_not_unboundp, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1997 Lisp_Object UNUSED (test), Lisp_Object UNUSED (key)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1998 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
1999 Lisp_Object number_table, result; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2000 Elemcount ordinal = 0; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2001 struct gcpro gcpro1; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2002 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2003 if (check_test != check_eq_nokey || !LRECORDP (old)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2004 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2005 signal_error (Qunimplemented, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2006 ":descend-structures not yet finished, nsubst", |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2007 Qunbound); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2008 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2009 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2010 if (!LRECORDP (tree) || !HAS_OBJECT_METH_P (tree, nsubst_structures_descend)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2011 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2012 return tree; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2013 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2014 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2015 number_table = make_lisp_hash_table (16, HASH_TABLE_NON_WEAK, Qeq); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2016 GCPRO1 (number_table); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2017 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2018 print_preprocess (tree, number_table, &ordinal); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2019 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2020 /* This function can GC by means of the hash table test functions, when |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2021 replacing hash table entries. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2022 result = nsubst_structures_descend (new_, old, tree, number_table, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2023 test_not_unboundp); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2024 Fclrhash (number_table); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2025 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2026 RETURN_UNGCPRO (result); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2027 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2028 |
428 | 2029 void |
2030 print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
2031 { | |
2032 /* This function can GC */ | |
2001 | 2033 int specdepth = 0; |
1204 | 2034 struct gcpro gcpro1, gcpro2; |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2035 Boolint cleanup_table = 0; |
428 | 2036 |
2037 QUIT; | |
2038 | |
771 | 2039 #ifdef NO_PRINT_DURING_GC |
428 | 2040 /* Emacs won't print while GCing, but an external debugger might */ |
2041 if (gc_in_progress) return; | |
771 | 2042 #endif |
2043 | |
1204 | 2044 /* Just to be safe ... */ |
2045 GCPRO2 (obj, printcharfun); | |
428 | 2046 |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2047 /* WARNING WARNING WARNING!!! Don't put anything here that might |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2048 dereference memory. Instead, put it down inside of |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2049 the case Lisp_Type_Record, after the appropriate checks to make sure |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2050 we're not dereferencing bad memory. The idea is that, ideally, |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2051 calling debug_print() should *NEVER* make the program crash, even when |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2052 something very bad has happened. --ben */ |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2053 |
428 | 2054 #ifdef I18N3 |
2055 /* #### Both input and output streams should have a flag associated | |
2056 with them indicating whether output to that stream, or strings | |
2057 read from the stream, get translated using Fgettext(). Such a | |
2058 stream is called a "translating stream". For the minibuffer and | |
2059 external-debugging-output this is always true on output, and | |
2060 with-output-to-temp-buffer sets the flag to true for the buffer | |
2061 it creates. This flag should also be user-settable. Perhaps it | |
2062 should be split up into two flags, one for input and one for | |
2063 output. */ | |
2064 #endif | |
2065 | |
2066 being_printed[print_depth] = obj; | |
2067 | |
1957 | 2068 /* Avoid calling internal_bind_int, which conses, when called from |
2069 debug_prin1. In that case, we have bound print_depth to 0 anyway. */ | |
2367 | 2070 if (!inhibit_non_essential_conversion_operations) |
1957 | 2071 { |
2072 specdepth = internal_bind_int (&print_depth, print_depth + 1); | |
2073 | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2074 if (print_depth > PRINT_CIRCLE_LIMIT) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2075 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2076 signal_error (Qstack_overflow, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2077 "Apparently circular structure being printed", |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2078 Qunbound); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2079 } |
1957 | 2080 } |
428 | 2081 |
2082 switch (XTYPE (obj)) | |
2083 { | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2084 case Lisp_Type_Fixnum_Even: |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2085 case Lisp_Type_Fixnum_Odd: |
428 | 2086 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2087 Ascbyte buf[DECIMAL_PRINT_SIZE (EMACS_INT)]; |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2088 long_to_string (buf, XFIXNUM (obj)); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2089 write_ascstring (printcharfun, buf); |
428 | 2090 break; |
2091 } | |
2092 | |
2093 case Lisp_Type_Char: | |
2094 { | |
2095 /* God intended that this be #\..., you know. */ | |
2096 char buf[16]; | |
867 | 2097 Ichar ch = XCHAR (obj); |
428 | 2098 char *p = buf; |
2099 *p++ = '?'; | |
434 | 2100 if (ch < 32) |
2101 { | |
2102 *p++ = '\\'; | |
2103 switch (ch) | |
2104 { | |
2105 case '\t': *p++ = 't'; break; | |
2106 case '\n': *p++ = 'n'; break; | |
2107 case '\r': *p++ = 'r'; break; | |
2108 default: | |
2109 *p++ = '^'; | |
2110 *p++ = ch + 64; | |
2111 if ((ch + 64) == '\\') | |
2112 *p++ = '\\'; | |
2113 break; | |
2114 } | |
2115 } | |
2116 else if (ch < 127) | |
428 | 2117 { |
434 | 2118 /* syntactically special characters should be escaped. */ |
2119 switch (ch) | |
2120 { | |
2121 case ' ': | |
2122 case '"': | |
2123 case '#': | |
2124 case '\'': | |
2125 case '(': | |
2126 case ')': | |
2127 case ',': | |
2128 case '.': | |
2129 case ';': | |
2130 case '?': | |
2131 case '[': | |
2132 case '\\': | |
2133 case ']': | |
2134 case '`': | |
2135 *p++ = '\\'; | |
2136 } | |
2137 *p++ = ch; | |
428 | 2138 } |
2139 else if (ch == 127) | |
434 | 2140 { |
2141 *p++ = '\\', *p++ = '^', *p++ = '?'; | |
2142 } | |
2143 else if (ch < 160) | |
428 | 2144 { |
2145 *p++ = '\\', *p++ = '^'; | |
867 | 2146 p += set_itext_ichar ((Ibyte *) p, ch + 64); |
428 | 2147 } |
2148 else | |
434 | 2149 { |
867 | 2150 p += set_itext_ichar ((Ibyte *) p, ch); |
434 | 2151 } |
440 | 2152 |
867 | 2153 output_string (printcharfun, (Ibyte *) buf, Qnil, 0, p - buf); |
434 | 2154 |
428 | 2155 break; |
2156 } | |
2157 | |
2158 case Lisp_Type_Record: | |
2159 { | |
2160 struct lrecord_header *lheader = XRECORD_LHEADER (obj); | |
1204 | 2161 |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2162 /* Try to check for various sorts of bogus pointers or bad memory |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2163 if we're in a situation where it may be likely -- i.e. called |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2164 from debug_print() or we're already crashing. In such cases, |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2165 (further) crashing is counterproductive. |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2166 |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2167 We don't normally do these because they may be expensive or |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2168 weird (e.g. under Unix we typically have to set a SIGSEGV |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2169 handler and try to trigger a seg fault). */ |
428 | 2170 |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2171 if (!lheader) |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2172 { |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2173 /* i.e. EQ Qnull_pointer */ |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2174 printing_major_badness (printcharfun, "NULL POINTER LRECORD", 0, |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2175 0, 0, BADNESS_NO_TYPE); |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2176 break; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2177 } |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2178 |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2179 /* First check to see if the lrecord header itself is garbage. */ |
2367 | 2180 if (inhibit_non_essential_conversion_operations && |
1204 | 2181 !debug_can_access_memory (lheader, sizeof (*lheader))) |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2182 { |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2183 printing_major_badness (printcharfun, |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2184 "BAD MEMORY in LRECORD HEADER", 0, |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2185 lheader, 0, BADNESS_NO_TYPE); |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2186 break; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2187 } |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2188 |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2189 /* Check to see if the lrecord type is garbage. */ |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2190 #ifndef NEW_GC |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2191 if (lheader->type == lrecord_type_free) |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2192 { |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2193 printing_major_badness (printcharfun, "FREED LRECORD", 0, |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2194 lheader, 0, BADNESS_NO_TYPE); |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2195 break; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2196 } |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2197 if (lheader->type == lrecord_type_undefined) |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2198 { |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2199 printing_major_badness (printcharfun, "LRECORD_TYPE_UNDEFINED", 0, |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2200 lheader, 0, BADNESS_NO_TYPE); |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2201 break; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2202 } |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2203 #endif /* not NEW_GC */ |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2204 if ((int) (lheader->type) >= lrecord_type_count) |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2205 { |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2206 printing_major_badness (printcharfun, "ILLEGAL LRECORD TYPE", |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2207 (int) (lheader->type), |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2208 lheader, 0, BADNESS_POINTER_OBJECT); |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2209 break; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2210 } |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2211 |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2212 /* Check to see if the lrecord implementation is missing or garbage. */ |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2213 { |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2214 const struct lrecord_implementation *imp = |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2215 LHEADER_IMPLEMENTATION (lheader); |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2216 |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2217 if (!imp) |
1204 | 2218 { |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2219 printing_major_badness |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2220 (printcharfun, "NO IMPLEMENTATION FOR LRECORD TYPE", |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2221 (int) (lheader->type), |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2222 lheader, 0, BADNESS_POINTER_OBJECT); |
1204 | 2223 break; |
2224 } | |
2225 | |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2226 if (inhibit_non_essential_conversion_operations) |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2227 { |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2228 if (!debug_can_access_memory (imp, sizeof (*imp))) |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2229 { |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2230 printing_major_badness |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2231 (printcharfun, "BAD MEMORY IN LRECORD IMPLEMENTATION", |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2232 (int) (lheader->type), |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2233 lheader, 0, BADNESS_POINTER_OBJECT); |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2234 } |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2235 } |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2236 } |
428 | 2237 |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2238 /* Check to see if any of the memory of the lrecord is inaccessible. |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2239 Note that we already checked above to see if the first part of |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2240 the lrecord (the header) is inaccessible, which will catch most |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2241 cases of a totally bad pointer. */ |
1204 | 2242 |
2367 | 2243 if (inhibit_non_essential_conversion_operations) |
1204 | 2244 { |
2245 if (!debug_can_access_memory | |
2246 (lheader, detagged_lisp_object_size (lheader))) | |
2247 { | |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2248 printing_major_badness (printcharfun, |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2249 "BAD MEMORY IN LRECORD", |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2250 (int) (lheader->type), |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2251 lheader, 0, BADNESS_POINTER_OBJECT); |
1204 | 2252 break; |
2253 } | |
2254 | |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2255 /* For strings, also check the data of the string itself. */ |
1204 | 2256 if (STRINGP (obj)) |
2257 { | |
3092 | 2258 #ifdef NEW_GC |
2259 if (!debug_can_access_memory (XSTRING_DATA (obj), | |
2260 XSTRING_LENGTH (obj))) | |
2261 { | |
2262 write_fmt_string | |
2263 (printcharfun, | |
2264 "#<EMACS BUG: %p (BAD STRING DATA %p)>", | |
2265 lheader, XSTRING_DATA (obj)); | |
2266 break; | |
2267 } | |
2268 #else /* not NEW_GC */ | |
1204 | 2269 Lisp_String *l = (Lisp_String *) lheader; |
5191
71ee43b8a74d
Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents:
5189
diff
changeset
|
2270 if (l->size_ && !debug_can_access_memory (l->data_, l->size_)) |
1204 | 2271 { |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2272 printing_major_badness (printcharfun, |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2273 "BAD STRING DATA", (int) (lheader->type), |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2274 lheader, l->data_, |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2275 BADNESS_POINTER_OBJECT_WITH_DATA); |
1204 | 2276 break; |
2277 } | |
3092 | 2278 #endif /* not NEW_GC */ |
1204 | 2279 } |
2280 } | |
2281 | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2282 if (LRECORDP (obj) && |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2283 ((print_circle && HAS_OBJECT_METH_P (obj, print_preprocess)) || |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2284 (print_gensym && SYMBOLP (obj) && !IN_OBARRAY (obj)))) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2285 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2286 enum print_gensym_status status |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2287 = print_gensym_or_circle (obj, printcharfun); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2288 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2289 cleanup_table = (PRINT_GENSYM_PRINT_AND_CLEANUP_TABLE == status); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2290 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2291 if (PRINT_GENSYM_DONE == status) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2292 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2293 break; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2294 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2295 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2296 else if (!print_circle && |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2297 /* Could this structure be recursive? */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2298 LRECORDP (obj) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2299 && HAS_OBJECT_METH_P (obj, nsubst_structures_descend)) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2300 { |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2301 int i; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2302 for (i = 0; i < print_depth - 1; i++) |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2303 if (EQ (obj, being_printed[i])) |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2304 { |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2305 Ascbyte buf[DECIMAL_PRINT_SIZE (long) + 1]; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2306 *buf = '#'; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2307 long_to_string (buf + 1, i); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2308 write_ascstring (printcharfun, buf); |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2309 break; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2310 } |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2311 if (i < print_depth - 1) /* Did we print something? */ |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2312 break; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2313 } |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2314 |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2315 if (CONSP (obj) || VECTORP (obj)) |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2316 { |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2317 /* If deeper than spec'd depth, print placeholder. */ |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2318 if (FIXNUMP (Vprint_level) |
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2319 && print_depth > XFIXNUM (Vprint_level)) |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2320 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2321 write_ascstring (printcharfun, "..."); |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2322 break; |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2323 } |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2324 } |
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2325 |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2326 /* Either use a custom-written printer, or use |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2327 internal_object_printer or external_object_printer, depending on |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2328 whether the object is internal (not visible at Lisp level) or |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2329 external. */ |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2330 assert (LHEADER_IMPLEMENTATION (lheader)->printer); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2331 ((LHEADER_IMPLEMENTATION (lheader)->printer) |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2332 (obj, printcharfun, escapeflag)); |
428 | 2333 break; |
2334 } | |
2335 | |
2336 default: | |
2337 { | |
2338 /* We're in trouble if this happens! */ | |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2339 printing_major_badness (printcharfun, "ILLEGAL LISP OBJECT TAG TYPE", |
5013 | 2340 XTYPE (obj), STORE_LISP_IN_VOID (obj), 0, |
4847
05c519de7353
be more careful when printing to check for bad objects
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2341 BADNESS_INTEGER_OBJECT); |
428 | 2342 break; |
2343 } | |
2344 } | |
2345 | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2346 if (cleanup_table) |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2347 { |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2348 /* If any objects have been seen once and once only, remove them from |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2349 Vprint_number_table. This is a bit of an arbitrary decision; we |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2350 could keep them around for the sake of print_continuous_numbering, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2351 but there's the reasonable worry about Vprint_number_table getting |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2352 awkwardly large. */ |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2353 elisp_map_remhash (print_continuous_numbering ? |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2354 print_nonsymbol_seen_once : print_seen_once, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2355 Vprint_number_table, NULL); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2356 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2357 } |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2358 |
2367 | 2359 if (!inhibit_non_essential_conversion_operations) |
1957 | 2360 unbind_to (specdepth); |
1204 | 2361 UNGCPRO; |
428 | 2362 } |
2363 | |
2364 void | |
2286 | 2365 print_float (Lisp_Object obj, Lisp_Object printcharfun, |
2366 int UNUSED (escapeflag)) | |
428 | 2367 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2368 Ascbyte pigbuf[350]; /* see comments in float_to_string */ |
428 | 2369 |
2370 float_to_string (pigbuf, XFLOAT_DATA (obj)); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2371 write_ascstring (printcharfun, pigbuf); |
428 | 2372 } |
2373 | |
2374 void | |
2375 print_symbol (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | |
2376 { | |
2377 /* This function can GC */ | |
793 | 2378 Lisp_Object name = symbol_name (XSYMBOL (obj)); |
2379 Bytecount size = XSTRING_LENGTH (name); | |
428 | 2380 struct gcpro gcpro1, gcpro2; |
2381 | |
2382 if (!escapeflag) | |
2383 { | |
2384 /* This deals with GC-relocation */ | |
793 | 2385 output_string (printcharfun, 0, name, 0, size); |
428 | 2386 return; |
2387 } | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
2388 |
428 | 2389 GCPRO2 (obj, printcharfun); |
2390 | |
5677
febc025c4e0c
Adopt GNU's ## syntax for the interned symbol with name "".
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
2391 if (print_gensym && !IN_OBARRAY (obj)) |
428 | 2392 { |
5677
febc025c4e0c
Adopt GNU's ## syntax for the interned symbol with name "".
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
2393 write_ascstring (printcharfun, "#:"); |
febc025c4e0c
Adopt GNU's ## syntax for the interned symbol with name "".
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
2394 } |
febc025c4e0c
Adopt GNU's ## syntax for the interned symbol with name "".
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
2395 else if (0 == size) |
febc025c4e0c
Adopt GNU's ## syntax for the interned symbol with name "".
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
2396 { |
febc025c4e0c
Adopt GNU's ## syntax for the interned symbol with name "".
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
2397 /* Compatible with GNU, but not with Common Lisp, where the syntax for |
febc025c4e0c
Adopt GNU's ## syntax for the interned symbol with name "".
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
2398 this symbol is ||. */ |
febc025c4e0c
Adopt GNU's ## syntax for the interned symbol with name "".
Aidan Kehoe <kehoea@parhasard.net>
parents:
5581
diff
changeset
|
2399 write_ascstring (printcharfun, "##"); |
428 | 2400 } |
2401 | |
2402 /* Does it look like an integer or a float? */ | |
2403 { | |
867 | 2404 Ibyte *data = XSTRING_DATA (name); |
428 | 2405 Bytecount confusing = 0; |
2406 | |
2407 if (size == 0) | |
2408 goto not_yet_confused; /* Really confusing */ | |
2409 else if (isdigit (data[0])) | |
2410 confusing = 0; | |
2411 else if (size == 1) | |
2412 goto not_yet_confused; | |
2413 else if (data[0] == '-' || data[0] == '+') | |
2414 confusing = 1; | |
2415 else | |
2416 goto not_yet_confused; | |
2417 | |
2418 for (; confusing < size; confusing++) | |
2419 { | |
5243
808131ba4a57
Print symbols with ratio-like names and the associated ratios distinctly.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2420 if (!isdigit (data[confusing]) && '/' != data[confusing]) |
428 | 2421 { |
2422 confusing = 0; | |
2423 break; | |
2424 } | |
2425 } | |
2426 not_yet_confused: | |
2427 | |
2428 if (!confusing) | |
2429 /* #### Ugh, this is needlessly complex and slow for what we | |
2430 need here. It might be a good idea to copy equivalent code | |
2431 from FSF. --hniksic */ | |
5243
808131ba4a57
Print symbols with ratio-like names and the associated ratios distinctly.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2432 confusing = isfloat_string ((char *) data) |
808131ba4a57
Print symbols with ratio-like names and the associated ratios distinctly.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5191
diff
changeset
|
2433 || isratio_string ((char *) data); |
428 | 2434 if (confusing) |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2435 write_ascstring (printcharfun, "\\"); |
428 | 2436 } |
2437 | |
2438 { | |
2439 Bytecount i; | |
2440 Bytecount last = 0; | |
2441 | |
2442 for (i = 0; i < size; i++) | |
2443 { | |
826 | 2444 switch (string_byte (name, i)) |
428 | 2445 { |
2446 case 0: case 1: case 2: case 3: | |
2447 case 4: case 5: case 6: case 7: | |
2448 case 8: case 9: case 10: case 11: | |
2449 case 12: case 13: case 14: case 15: | |
2450 case 16: case 17: case 18: case 19: | |
2451 case 20: case 21: case 22: case 23: | |
2452 case 24: case 25: case 26: case 27: | |
2453 case 28: case 29: case 30: case 31: | |
2454 case ' ': case '\"': case '\\': case '\'': | |
2455 case ';': case '#' : case '(' : case ')': | |
2456 case ',': case '.' : case '`' : | |
2457 case '[': case ']' : case '?' : | |
2458 if (i > last) | |
793 | 2459 output_string (printcharfun, 0, name, last, i - last); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2460 write_ascstring (printcharfun, "\\"); |
428 | 2461 last = i; |
2462 } | |
2463 } | |
793 | 2464 output_string (printcharfun, 0, name, last, size - last); |
428 | 2465 } |
2466 UNGCPRO; | |
2467 } | |
2468 | |
2469 | |
442 | 2470 /* Useful on systems or in places where writing to stdout is unavailable or |
2471 not working. */ | |
428 | 2472 |
2473 static int alternate_do_pointer; | |
1957 | 2474 static int alternate_do_size; |
2475 static char *alternate_do_string; | |
428 | 2476 |
2477 DEFUN ("alternate-debugging-output", Falternate_debugging_output, 1, 1, 0, /* | |
2478 Append CHARACTER to the array `alternate_do_string'. | |
2479 This can be used in place of `external-debugging-output' as a function | |
2480 to be passed to `print'. Before calling `print', set `alternate_do_pointer' | |
2481 to 0. | |
2482 */ | |
2483 (character)) | |
2484 { | |
867 | 2485 Ibyte str[MAX_ICHAR_LEN]; |
428 | 2486 Bytecount len; |
2487 | |
2488 CHECK_CHAR_COERCE_INT (character); | |
867 | 2489 len = set_itext_ichar (str, XCHAR (character)); |
771 | 2490 write_string_to_alternate_debugging_output (str, len); |
2491 | |
2492 return character; | |
2493 } | |
2494 | |
2495 static void | |
1346 | 2496 write_string_to_alternate_debugging_output (const Ibyte *str, Bytecount len) |
771 | 2497 { |
2498 int extlen; | |
2499 const Extbyte *extptr; | |
2500 #if 0 /* We want to see the internal representation, don't we? */ | |
2367 | 2501 if (initialized && !inhibit_non_essential_conversion_operations) |
771 | 2502 TO_EXTERNAL_FORMAT (DATA, (str, len), |
2503 ALLOCA, (extptr, extlen), | |
2504 Qterminal); | |
2505 else | |
2506 #endif /* 0 */ | |
2507 { | |
2508 extlen = len; | |
2509 extptr = (Extbyte *) str; | |
2510 } | |
1957 | 2511 |
2512 /* If not yet initialized, just skip it. */ | |
2513 if (alternate_do_string == NULL) | |
2514 return; | |
2515 | |
2516 if (alternate_do_pointer + extlen >= alternate_do_size) | |
2517 { | |
2518 alternate_do_size = | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2519 max (alternate_do_size * 2, alternate_do_pointer + extlen + 1); |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2520 XREALLOC_ARRAY (alternate_do_string, CIbyte, alternate_do_size); |
1957 | 2521 } |
428 | 2522 memcpy (alternate_do_string + alternate_do_pointer, extptr, extlen); |
2523 alternate_do_pointer += extlen; | |
2524 alternate_do_string[alternate_do_pointer] = 0; | |
2525 } | |
2526 | |
1346 | 2527 |
2528 DEFUN ("set-device-clear-left-side", Fset_device_clear_left_side, 2, 2, 0, /* | |
2529 Set whether to output a newline before the next output to a stream device. | |
2530 This will happen only if the most recently-outputted character was not | |
2531 a newline -- i.e. it will make sure the left side is "clear" of text. | |
2532 */ | |
2533 (device, value)) | |
2534 { | |
2535 if (!NILP (device)) | |
2536 CHECK_LIVE_DEVICE (device); | |
2537 if (NILP (device) || DEVICE_STREAM_P (XDEVICE (device))) | |
2538 /* #### This should be per-device */ | |
2539 stdout_clear_before_next_output = !NILP (value); | |
2540 return Qnil; | |
2541 } | |
2542 | |
2543 DEFUN ("device-left-side-clear-p", Fdevice_left_side_clear_p, 0, 1, 0, /* | |
2544 For stream devices, true if the most recent-outputted character was a newline. | |
2545 */ | |
2546 (device)) | |
2547 { | |
2548 if (!NILP (device)) | |
2549 CHECK_LIVE_DEVICE (device); | |
2550 if (NILP (device) || DEVICE_STREAM_P (XDEVICE (device))) | |
2551 /* #### This should be per-device */ | |
2552 return stdout_needs_newline ? Qt : Qnil; | |
2553 return Qnil; | |
2554 } | |
2555 | |
428 | 2556 DEFUN ("external-debugging-output", Fexternal_debugging_output, 1, 3, 0, /* |
2557 Write CHAR-OR-STRING to stderr or stdout. | |
2558 If optional arg STDOUT-P is non-nil, write to stdout; otherwise, write | |
2559 to stderr. You can use this function to write directly to the terminal. | |
2560 This function can be used as the STREAM argument of Fprint() or the like. | |
2561 | |
442 | 2562 Under MS Windows, this writes output to the console window (which is |
2563 created, if necessary), unless XEmacs is being run noninteractively | |
2564 \(i.e. using the `-batch' argument). | |
2565 | |
428 | 2566 If you have opened a termscript file (using `open-termscript'), then |
2567 the output also will be logged to this file. | |
2568 */ | |
2569 (char_or_string, stdout_p, device)) | |
2570 { | |
2571 FILE *file = 0; | |
2572 struct console *con = 0; | |
2573 | |
2574 if (NILP (device)) | |
2575 { | |
2576 if (!NILP (stdout_p)) | |
2577 file = stdout; | |
2578 else | |
2579 file = stderr; | |
2580 } | |
2581 else | |
2582 { | |
2583 CHECK_LIVE_DEVICE (device); | |
2584 if (!DEVICE_TTY_P (XDEVICE (device)) && | |
2585 !DEVICE_STREAM_P (XDEVICE (device))) | |
563 | 2586 wtaerror ("Must be tty or stream device", device); |
428 | 2587 con = XCONSOLE (DEVICE_CONSOLE (XDEVICE (device))); |
2588 if (DEVICE_TTY_P (XDEVICE (device))) | |
2589 file = 0; | |
2590 else if (!NILP (stdout_p)) | |
2591 file = CONSOLE_STREAM_DATA (con)->out; | |
2592 else | |
2593 file = CONSOLE_STREAM_DATA (con)->err; | |
2594 } | |
2595 | |
2596 if (STRINGP (char_or_string)) | |
2597 write_string_to_stdio_stream (file, con, | |
2598 XSTRING_DATA (char_or_string), | |
771 | 2599 XSTRING_LENGTH (char_or_string), |
2600 print_unbuffered); | |
428 | 2601 else |
2602 { | |
867 | 2603 Ibyte str[MAX_ICHAR_LEN]; |
428 | 2604 Bytecount len; |
2605 | |
2606 CHECK_CHAR_COERCE_INT (char_or_string); | |
867 | 2607 len = set_itext_ichar (str, XCHAR (char_or_string)); |
771 | 2608 write_string_to_stdio_stream (file, con, str, len, print_unbuffered); |
428 | 2609 } |
2610 | |
2611 return char_or_string; | |
2612 } | |
2613 | |
2614 DEFUN ("open-termscript", Fopen_termscript, 1, 1, "FOpen termscript file: ", /* | |
444 | 2615 Start writing all terminal output to FILENAME as well as the terminal. |
2616 FILENAME = nil means just close any termscript file currently open. | |
428 | 2617 */ |
444 | 2618 (filename)) |
428 | 2619 { |
2620 /* This function can GC */ | |
2621 if (termscript != 0) | |
2622 { | |
771 | 2623 retry_fclose (termscript); |
444 | 2624 termscript = 0; |
2625 } | |
2626 | |
2627 if (! NILP (filename)) | |
2628 { | |
2629 filename = Fexpand_file_name (filename, Qnil); | |
771 | 2630 termscript = qxe_fopen (XSTRING_DATA (filename), "w"); |
428 | 2631 if (termscript == NULL) |
563 | 2632 report_file_error ("Opening termscript", filename); |
428 | 2633 } |
2634 return Qnil; | |
2635 } | |
2636 | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2637 static Lisp_Object |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2638 restore_inhibit_non_essential_conversion_operations (Lisp_Object obj) |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2639 { |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2640 inhibit_non_essential_conversion_operations = XFIXNUM (obj); |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2641 return Qnil; |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2642 } |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2643 |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2644 /* Bind the value of inhibit_non_essential_conversion_operations to 1 |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2645 in a way that involves no consing. */ |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2646 static int |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2647 begin_inhibit_non_essential_conversion_operations (void) |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2648 { |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2649 int depth = |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2650 record_unwind_protect |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2651 (restore_inhibit_non_essential_conversion_operations, |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2652 make_fixnum (inhibit_non_essential_conversion_operations)); |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2653 inhibit_non_essential_conversion_operations = 1; |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2654 return depth; |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2655 } |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2656 |
440 | 2657 static int debug_print_length = 50; |
2658 static int debug_print_level = 15; | |
2659 static int debug_print_readably = -1; | |
428 | 2660 |
1957 | 2661 /* Restore values temporarily bound by debug_prin1. We use this approach to |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2662 avoid consing in debug_prin1. That is verboten, since debug_print can be |
1957 | 2663 called by cons debugging code. */ |
2664 static Lisp_Object | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2665 debug_print_exit (Lisp_Object val) |
1957 | 2666 { |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2667 struct debug_bindings *bindings = |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2668 (struct debug_bindings *) GET_VOID_FROM_LISP (val); |
2367 | 2669 inhibit_non_essential_conversion_operations = |
2670 bindings->inhibit_non_essential_conversion_operations; | |
1957 | 2671 print_depth = bindings->print_depth; |
2672 print_readably = bindings->print_readably; | |
2673 print_unbuffered = bindings->print_unbuffered; | |
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
2674 in_debug_print = bindings->in_debug_print; |
1957 | 2675 gc_currently_forbidden = bindings->gc_currently_forbidden; |
2676 Vprint_length = bindings->Vprint_length; | |
2677 Vprint_level = bindings->Vprint_level; | |
2678 Vinhibit_quit = bindings->Vinhibit_quit; | |
2679 return Qnil; | |
2680 } | |
2681 | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2682 /* Save values and bind them to new values suitable for debug output. We |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2683 try very hard to avoid any Lisp allocation (i.e. consing) during the |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2684 operation of debug printing, since we might be calling it from inside GC |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2685 or other sensitive places. This means we have to be a bit careful with |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2686 record_unwind_protect to not create any temporary Lisp objects. */ |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2687 |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2688 static int |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2689 debug_print_enter (struct debug_bindings *bindings) |
428 | 2690 { |
853 | 2691 /* by doing this, we trick various things that are non-essential |
2692 but might cause crashes into not getting executed. */ | |
1957 | 2693 int specdepth; |
853 | 2694 |
2367 | 2695 bindings->inhibit_non_essential_conversion_operations = |
2696 inhibit_non_essential_conversion_operations; | |
1957 | 2697 bindings->print_depth = print_depth; |
2698 bindings->print_readably = print_readably; | |
2699 bindings->print_unbuffered = print_unbuffered; | |
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
2700 bindings->in_debug_print = in_debug_print; |
1957 | 2701 bindings->gc_currently_forbidden = gc_currently_forbidden; |
2702 bindings->Vprint_length = Vprint_length; | |
2703 bindings->Vprint_level = Vprint_level; | |
2704 bindings->Vinhibit_quit = Vinhibit_quit; | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2705 specdepth = record_unwind_protect (debug_print_exit, |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2706 STORE_VOID_IN_LISP (bindings)); |
1957 | 2707 |
2367 | 2708 inhibit_non_essential_conversion_operations = 1; |
1957 | 2709 print_depth = 0; |
2710 print_readably = debug_print_readably != -1 ? debug_print_readably : 0; | |
2711 print_unbuffered++; | |
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
2712 in_debug_print = 1; |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4847
diff
changeset
|
2713 gc_currently_forbidden = 1; |
428 | 2714 if (debug_print_length > 0) |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2715 Vprint_length = make_fixnum (debug_print_length); |
428 | 2716 if (debug_print_level > 0) |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2717 Vprint_level = make_fixnum (debug_print_level); |
1957 | 2718 Vinhibit_quit = Qt; |
1346 | 2719 |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2720 return specdepth; |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2721 } |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2722 |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2723 /* Print an object, `prin1'-style, to various possible debugging outputs. |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2724 Make sure it's completely unbuffered so that, in the event of a crash |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2725 somewhere, we see as much as possible that happened before it. |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2726 */ |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2727 static void |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2728 debug_prin1 (Lisp_Object debug_print_obj, int flags) |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2729 { |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2730 /* This function cannot GC, since GC is forbidden */ |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2731 struct debug_bindings bindings; |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2732 int specdepth = debug_print_enter (&bindings); |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2733 |
1346 | 2734 if ((flags & EXT_PRINT_STDOUT) || (flags & EXT_PRINT_STDERR)) |
2735 print_internal (debug_print_obj, Qexternal_debugging_output, 1); | |
2736 if (flags & EXT_PRINT_ALTERNATE) | |
2737 print_internal (debug_print_obj, Qalternate_debugging_output, 1); | |
442 | 2738 #ifdef WIN32_NATIVE |
1346 | 2739 if (flags & EXT_PRINT_MSWINDOWS) |
2740 { | |
2741 /* Write out to the debugger, as well */ | |
2742 print_internal (debug_print_obj, Qmswindows_debugging_output, 1); | |
2743 } | |
442 | 2744 #endif |
440 | 2745 |
802 | 2746 unbind_to (specdepth); |
428 | 2747 } |
2748 | |
2749 void | |
1204 | 2750 debug_p4 (Lisp_Object obj) |
2751 { | |
2752 if (STRINGP (obj)) | |
2753 debug_out ("\"%s\"", XSTRING_DATA (obj)); | |
2754 else if (CONSP (obj)) | |
2755 { | |
2756 int first = 1; | |
2757 do { | |
2758 debug_out (first ? "(" : " "); | |
2759 first = 0; | |
2760 debug_p4 (XCAR (obj)); | |
2761 obj = XCDR (obj); | |
2762 } while (CONSP (obj)); | |
2763 if (NILP (obj)) | |
2764 debug_out (")"); | |
2765 else | |
2766 { | |
2767 debug_out (" . "); | |
2768 debug_p4 (obj); | |
2769 debug_out (")"); | |
2770 } | |
2771 } | |
2772 else if (VECTORP (obj)) | |
2773 { | |
2774 int size = XVECTOR_LENGTH (obj); | |
2775 int i; | |
2776 int first = 1; | |
2777 | |
2778 for (i = 0; i < size; i++) | |
2779 { | |
2780 debug_out (first ? "[" : " "); | |
2781 first = 0; | |
2782 debug_p4 (XVECTOR_DATA (obj)[i]); | |
2783 debug_out ("]"); | |
2784 } | |
2785 } | |
2786 else if (SYMBOLP (obj)) | |
2787 { | |
2788 Lisp_Object name = XSYMBOL_NAME (obj); | |
2789 if (!STRINGP (name)) | |
2790 debug_out ("<<bad symbol>>"); | |
2791 else | |
2792 debug_out ("%s", XSTRING_DATA (name)); | |
2793 } | |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2794 else if (FIXNUMP (obj)) |
1204 | 2795 { |
5581
56144c8593a8
Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5560
diff
changeset
|
2796 debug_out ("%ld", XFIXNUM (obj)); |
1204 | 2797 } |
2798 else if (FLOATP (obj)) | |
2799 { | |
2800 debug_out ("%g", XFLOAT_DATA (obj)); | |
2801 } | |
2802 else | |
2803 { | |
2804 struct lrecord_header *header = | |
2805 (struct lrecord_header *) XPNTR (obj); | |
2806 | |
2807 if (header->type >= lrecord_type_last_built_in_type) | |
2808 debug_out ("<< bad object type=%d 0x%lx>>", header->type, | |
2809 (EMACS_INT) header); | |
2810 else | |
3063 | 2811 debug_out ("#<%s addr=0x%lx uid=0x%lx>", |
2720 | 2812 LHEADER_IMPLEMENTATION (header)->name, |
3063 | 2813 (EMACS_INT) header, |
2720 | 2814 (EMACS_INT) ((struct lrecord_header *) header)->uid); |
1204 | 2815 } |
2816 } | |
2817 | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2818 static int |
1346 | 2819 ext_print_begin (int dest) |
2820 { | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2821 int depth = begin_inhibit_non_essential_conversion_operations (); |
1346 | 2822 if (dest & EXT_PRINT_ALTERNATE) |
2823 alternate_do_pointer = 0; | |
2824 if (dest & (EXT_PRINT_STDERR | EXT_PRINT_STDOUT)) | |
2825 stdout_clear_before_next_output = 1; | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2826 return depth; |
1346 | 2827 } |
2828 | |
2829 static void | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2830 ext_print_end (int dest, int depth) |
1346 | 2831 { |
2832 if (dest & (EXT_PRINT_MSWINDOWS | EXT_PRINT_STDERR | EXT_PRINT_STDOUT)) | |
2833 external_out (dest & (EXT_PRINT_MSWINDOWS | EXT_PRINT_STDERR | | |
2834 EXT_PRINT_STDOUT), "\n"); | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2835 unbind_to (depth); |
1346 | 2836 } |
2837 | |
2838 static void | |
2839 external_debug_print (Lisp_Object object, int dest) | |
2840 { | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2841 int depth = ext_print_begin (dest); |
1346 | 2842 debug_prin1 (object, dest); |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2843 ext_print_end (dest, depth); |
1346 | 2844 } |
2845 | |
1204 | 2846 void |
2847 debug_p3 (Lisp_Object obj) | |
2848 { | |
2849 debug_p4 (obj); | |
2850 debug_out ("\n"); | |
2851 } | |
2852 | |
2853 void | |
428 | 2854 debug_print (Lisp_Object debug_print_obj) |
2855 { | |
1346 | 2856 external_debug_print (debug_print_obj, EXT_PRINT_ALL); |
428 | 2857 } |
2858 | |
5189
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2859 /* Printf-style output when the objects being printed are Lisp objects. |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2860 Calling style is e.g. |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2861 |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2862 debug_out_lisp ("Called foo(%s %s)\n", 2, arg0, arg1) |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2863 */ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2864 |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2865 void |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2866 debug_out_lisp (const CIbyte *format, int nargs, ...) |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2867 { |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2868 /* This function cannot GC, since GC is forbidden */ |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2869 struct debug_bindings bindings; |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2870 int specdepth = debug_print_enter (&bindings); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2871 Lisp_Object *args = alloca_array (Lisp_Object, nargs); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2872 va_list va; |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2873 int i; |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2874 Ibyte *msgout; |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2875 |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2876 va_start (va, nargs); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2877 for (i = 0; i < nargs; i++) |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2878 args[i] = va_arg (va, Lisp_Object); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2879 va_end (va); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2880 msgout = emacs_vsprintf_malloc_lisp (format, Qnil, nargs, args, NULL); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2881 debug_out ("%s", msgout); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2882 xfree (msgout); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2883 unbind_to (specdepth); |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2884 } |
b65692aa90d8
Cosmetic XFT-code fixes, some variable renamings
Ben Wing <ben@xemacs.org>
parents:
5146
diff
changeset
|
2885 |
1204 | 2886 /* Getting tired of typing debug_print() ... */ |
2887 void dp (Lisp_Object debug_print_obj); | |
2888 void | |
2889 dp (Lisp_Object debug_print_obj) | |
2890 { | |
2891 debug_print (debug_print_obj); | |
2892 } | |
2893 | |
1346 | 2894 /* Alternate debug printer: Return a char * pointer to the output */ |
2895 char *dpa (Lisp_Object debug_print_obj); | |
2896 char * | |
2897 dpa (Lisp_Object debug_print_obj) | |
2898 { | |
2899 external_debug_print (debug_print_obj, EXT_PRINT_ALTERNATE); | |
2900 | |
2901 return alternate_do_string; | |
2902 } | |
2903 | |
428 | 2904 /* Debugging kludge -- unbuffered */ |
2905 /* This function provided for the benefit of the debugger. */ | |
2906 void | |
2907 debug_backtrace (void) | |
2908 { | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2909 /* This function cannot GC, since GC is forbidden */ |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2910 struct debug_bindings bindings; |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2911 int specdepth = debug_print_enter (&bindings); |
428 | 2912 |
2913 Fbacktrace (Qexternal_debugging_output, Qt); | |
2914 stderr_out ("\n"); | |
2915 | |
802 | 2916 unbind_to (specdepth); |
428 | 2917 } |
2918 | |
1204 | 2919 /* Getting tired of typing debug_backtrace() ... */ |
2920 void db (void); | |
2921 void | |
2922 db (void) | |
2923 { | |
2924 debug_backtrace (); | |
2925 } | |
2926 | |
428 | 2927 void |
2928 debug_short_backtrace (int length) | |
2929 { | |
2930 int first = 1; | |
2931 struct backtrace *bt = backtrace_list; | |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
2932 |
771 | 2933 debug_out (" ["); |
428 | 2934 while (length > 0 && bt) |
2935 { | |
2936 if (!first) | |
2937 { | |
771 | 2938 debug_out (", "); |
428 | 2939 } |
2940 if (COMPILED_FUNCTIONP (*bt->function)) | |
2941 { | |
1346 | 2942 #if defined (COMPILED_FUNCTION_ANNOTATION_HACK) |
428 | 2943 Lisp_Object ann = |
2944 compiled_function_annotation (XCOMPILED_FUNCTION (*bt->function)); | |
2945 #else | |
2946 Lisp_Object ann = Qnil; | |
2947 #endif | |
2948 if (!NILP (ann)) | |
2949 { | |
771 | 2950 debug_out ("<compiled-function from "); |
1346 | 2951 debug_prin1 (ann, EXT_PRINT_ALL); |
771 | 2952 debug_out (">"); |
428 | 2953 } |
2954 else | |
2955 { | |
771 | 2956 debug_out ("<compiled-function of unknown origin>"); |
428 | 2957 } |
2958 } | |
2959 else | |
1346 | 2960 debug_prin1 (*bt->function, EXT_PRINT_ALL); |
428 | 2961 first = 0; |
2962 length--; | |
2963 bt = bt->next; | |
2964 } | |
771 | 2965 debug_out ("]\n"); |
428 | 2966 } |
2967 | |
2968 | |
2969 void | |
2970 syms_of_print (void) | |
2971 { | |
563 | 2972 DEFSYMBOL (Qstandard_output); |
428 | 2973 |
563 | 2974 DEFSYMBOL (Qprint_length); |
428 | 2975 |
563 | 2976 DEFSYMBOL (Qprint_string_length); |
428 | 2977 |
563 | 2978 DEFSYMBOL (Qdisplay_error); |
2979 DEFSYMBOL (Qprint_message_label); | |
428 | 2980 |
2981 DEFSUBR (Fprin1); | |
2982 DEFSUBR (Fprin1_to_string); | |
2983 DEFSUBR (Fprinc); | |
2984 DEFSUBR (Fprint); | |
2985 DEFSUBR (Ferror_message_string); | |
2986 DEFSUBR (Fdisplay_error); | |
2987 DEFSUBR (Fterpri); | |
2988 DEFSUBR (Fwrite_char); | |
2989 DEFSUBR (Falternate_debugging_output); | |
1346 | 2990 DEFSUBR (Fset_device_clear_left_side); |
2991 DEFSUBR (Fdevice_left_side_clear_p); | |
428 | 2992 DEFSUBR (Fexternal_debugging_output); |
2993 DEFSUBR (Fopen_termscript); | |
563 | 2994 DEFSYMBOL (Qexternal_debugging_output); |
2995 DEFSYMBOL (Qalternate_debugging_output); | |
442 | 2996 #ifdef HAVE_MS_WINDOWS |
563 | 2997 DEFSYMBOL (Qmswindows_debugging_output); |
442 | 2998 #endif |
428 | 2999 DEFSUBR (Fwith_output_to_temp_buffer); |
3000 } | |
3001 | |
3002 void | |
3003 reinit_vars_of_print (void) | |
3004 { | |
3005 alternate_do_pointer = 0; | |
3006 } | |
3007 | |
3008 void | |
3009 vars_of_print (void) | |
3010 { | |
3011 DEFVAR_LISP ("standard-output", &Vstandard_output /* | |
3012 Output stream `print' uses by default for outputting a character. | |
3013 This may be any function of one argument. | |
3014 It may also be a buffer (output is inserted before point) | |
3015 or a marker (output is inserted and the marker is advanced) | |
3016 or the symbol t (output appears in the minibuffer line). | |
3017 */ ); | |
3018 Vstandard_output = Qt; | |
3019 | |
3020 DEFVAR_LISP ("float-output-format", &Vfloat_output_format /* | |
3021 The format descriptor string that lisp uses to print floats. | |
3022 This is a %-spec like those accepted by `printf' in C, | |
3023 but with some restrictions. It must start with the two characters `%.'. | |
3024 After that comes an integer precision specification, | |
3025 and then a letter which controls the format. | |
3026 The letters allowed are `e', `f' and `g'. | |
3027 Use `e' for exponential notation "DIG.DIGITSeEXPT" | |
3028 Use `f' for decimal point notation "DIGITS.DIGITS". | |
3029 Use `g' to choose the shorter of those two formats for the number at hand. | |
3030 The precision in any of these cases is the number of digits following | |
3031 the decimal point. With `f', a precision of 0 means to omit the | |
3032 decimal point. 0 is not allowed with `f' or `g'. | |
3033 | |
3034 A value of nil means to use `%.16g'. | |
3035 | |
3036 Regardless of the value of `float-output-format', a floating point number | |
3037 will never be printed in such a way that it is ambiguous with an integer; | |
3038 that is, a floating-point number will always be printed with a decimal | |
3039 point and/or an exponent, even if the digits following the decimal point | |
3040 are all zero. This is to preserve read-equivalence. | |
3041 */ ); | |
3042 Vfloat_output_format = Qnil; | |
3043 | |
3044 DEFVAR_LISP ("print-length", &Vprint_length /* | |
3045 Maximum length of list or vector to print before abbreviating. | |
3046 A value of nil means no limit. | |
3047 */ ); | |
3048 Vprint_length = Qnil; | |
3049 | |
3050 DEFVAR_LISP ("print-string-length", &Vprint_string_length /* | |
3051 Maximum length of string to print before abbreviating. | |
3052 A value of nil means no limit. | |
3053 */ ); | |
3054 Vprint_string_length = Qnil; | |
3055 | |
3056 DEFVAR_LISP ("print-level", &Vprint_level /* | |
3057 Maximum depth of list nesting to print before abbreviating. | |
3058 A value of nil means no limit. | |
3059 */ ); | |
3060 Vprint_level = Qnil; | |
3061 | |
3062 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines /* | |
3063 Non-nil means print newlines in strings as backslash-n. | |
3064 */ ); | |
3065 print_escape_newlines = 0; | |
3066 | |
3067 DEFVAR_BOOL ("print-readably", &print_readably /* | |
3068 If non-nil, then all objects will be printed in a readable form. | |
3069 If an object has no readable representation, then an error is signalled. | |
3070 When print-readably is true, compiled-function objects will be written in | |
3071 #[...] form instead of in #<compiled-function [...]> form, and two-element | |
3072 lists of the form (quote object) will be written as the equivalent 'object. | |
3073 Do not SET this variable; bind it instead. | |
3074 */ ); | |
3075 print_readably = 0; | |
3076 | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3077 DEFVAR_BOOL ("print-gensym", &print_gensym /* |
428 | 3078 If non-nil, then uninterned symbols will be printed specially. |
3079 Uninterned symbols are those which are not present in `obarray', that is, | |
3080 those which were made with `make-symbol' or by calling `intern' with a | |
3081 second argument. | |
3082 | |
3083 When print-gensym is true, such symbols will be preceded by "#:", | |
3084 which causes the reader to create a new symbol instead of interning | |
3085 and returning an existing one. Beware: the #: syntax creates a new | |
3086 symbol each time it is seen, so if you print an object which contains | |
3087 two pointers to the same uninterned symbol, `read' will not duplicate | |
3088 that structure. | |
3089 | |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3090 If the value of `print-continuous-numbering' is non-nil, the table used by |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3091 `print-gensym' and `print-circle' (which see) will not be reset on entry to |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3092 and exit from printing functions, so that the use of #...# and #...= can |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3093 carry over for several separately printed objects. |
428 | 3094 */ ); |
5560
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3095 print_gensym = 1; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3096 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3097 DEFVAR_BOOL ("print-circle", &print_circle /* |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3098 Non-nil means print recursive structures using #N= and #N# syntax. |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3099 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3100 If nil, XEmacs detects recursive structures and truncates them in an |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3101 unreadable fashion. |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3102 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3103 If non-nil, shared substructures anywhere in the structure are printed |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3104 with `#N=' before the first occurrence (in the order of the print |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3105 representation) and `#N#' in place of each subsequent occurrence, |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3106 where N is a positive decimal integer. |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3107 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3108 If the value of `print-continuous-numbering' is non-nil, the table used by |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3109 `print-gensym' (which see) and `print-circle' will not be reset on entry to |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3110 and exit from printing functions, so that the use of #...# and #...= can |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3111 carry over for several separately printed objects. |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3112 */); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3113 print_circle = 0; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3114 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3115 DEFVAR_BOOL_MAGIC ("print-continuous-numbering", |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3116 &print_continuous_numbering /* |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3117 Non-nil means number continuously across print calls, mostly for symbols. |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3118 This affects the numbers printed for #N= labels and #M# references. |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3119 See also `print-circle' and `print-gensym'. |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3120 This variable should not be set with `setq'; bind it with a `let' instead. |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3121 */ , |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3122 print_continuous_numbering_changed); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3123 print_continuous_numbering = 0; |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3124 |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3125 staticpro (&Vprint_number_table); |
58b38d5b32d0
Implement print-circle, allowing recursive and circular structures to be read.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5420
diff
changeset
|
3126 Vprint_number_table = make_lisp_hash_table (16, HASH_TABLE_KEY_WEAK, Qeq); |
428 | 3127 |
3128 DEFVAR_LISP ("print-message-label", &Vprint_message_label /* | |
3129 Label for minibuffer messages created with `print'. This should | |
3130 generally be bound with `let' rather than set. (See `display-message'.) | |
3131 */ ); | |
3132 Vprint_message_label = Qprint; | |
1957 | 3133 |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
3134 /* The exact size doesn't matter since we realloc when necessary. |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
3135 Use CIbyte instead of Ibyte so that debuggers show the associated |
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
3136 string automatically. */ |
1957 | 3137 alternate_do_size = 5000; |
5014
c2e0c3af5fe3
cleanups to debug-print, try harder to make it work during GC
Ben Wing <ben@xemacs.org>
parents:
5013
diff
changeset
|
3138 alternate_do_string = xnew_array (CIbyte, 5000); |
428 | 3139 } |