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