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