Mercurial > hg > xemacs-beta
comparison src/print.c @ 280:7df0dd720c89 r21-0b38
Import from CVS: tag r21-0b38
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:32:22 +0200 |
parents | 90d73dddcdc4 |
children | c42ec1d1cded |
comparison
equal
deleted
inserted
replaced
279:c20b2fb5bb0a | 280:7df0dd720c89 |
---|---|
42 #include <float.h> | 42 #include <float.h> |
43 /* Define if not in float.h */ | 43 /* Define if not in float.h */ |
44 #ifndef DBL_DIG | 44 #ifndef DBL_DIG |
45 #define DBL_DIG 16 | 45 #define DBL_DIG 16 |
46 #endif | 46 #endif |
47 | |
48 static void print_error_message (Lisp_Object data, Lisp_Object stream); | |
49 | 47 |
50 Lisp_Object Vstandard_output, Qstandard_output; | 48 Lisp_Object Vstandard_output, Qstandard_output; |
51 | 49 |
52 /* The subroutine object for external-debugging-output is kept here | 50 /* The subroutine object for external-debugging-output is kept here |
53 for the convenience of the debugger. */ | 51 for the convenience of the debugger. */ |
218 Fmarker_buffer (function)); | 216 Fmarker_buffer (function)); |
219 } | 217 } |
220 else if (FRAMEP (function)) | 218 else if (FRAMEP (function)) |
221 { | 219 { |
222 /* This gets used by functions not invoking print_prepare(), | 220 /* This gets used by functions not invoking print_prepare(), |
223 such as Fwrite_char. */ | 221 such as Fwrite_char, Fterpri, etc.. */ |
224 struct frame *f = XFRAME (function); | 222 struct frame *f = XFRAME (function); |
225 CHECK_LIVE_FRAME (function); | 223 CHECK_LIVE_FRAME (function); |
226 | 224 |
227 if (!EQ (Vprint_message_label, echo_area_status (f))) | 225 if (!EQ (Vprint_message_label, echo_area_status (f))) |
228 clear_echo_area_from_print (f, Qnil, 1); | 226 clear_echo_area_from_print (f, Qnil, 1); |
335 Qnil, 0, Lstream_byte_count (str), | 333 Qnil, 0, Lstream_byte_count (str), |
336 Vprint_message_label); | 334 Vprint_message_label); |
337 Lstream_delete (str); | 335 Lstream_delete (str); |
338 } | 336 } |
339 } | 337 } |
340 | 338 |
341 /* Used for printing a character. STRING_OF_LENGTH_1 must contain a | 339 /* Used for printing a single-byte character (*not* any Emchar). */ |
342 single-byte character, not just any emchar. */ | |
343 #define write_char_internal(string_of_length_1, stream) \ | 340 #define write_char_internal(string_of_length_1, stream) \ |
344 output_string ((stream), (CONST Bufbyte *) (string_of_length_1), \ | 341 output_string (stream, (CONST Bufbyte *) (string_of_length_1), \ |
345 Qnil, 0, 1) | 342 Qnil, 0, 1) |
346 | 343 |
347 /* NOTE: Do not call this with the data of a Lisp_String, | 344 /* NOTE: Do not call this with the data of a Lisp_String, as |
348 * as printcharfun might cause a GC, which might cause | 345 printcharfun might cause a GC, which might cause the string's data |
349 * the string's data to be relocated. | 346 to be relocated. To princ a Lisp string, use: |
350 * Use print_internal (string, printcharfun, 0) | 347 |
351 * to princ a Lisp_String | 348 print_internal (string, printcharfun, 0); |
352 * Note: "stream" should be the result of "canonicalize_printcharfun" | 349 |
353 * (ie Qnil means stdout, not Vstandard_output, etc) | 350 Also note that STREAM should be the result of |
354 */ | 351 canonicalize_printcharfun() (i.e. Qnil means stdout, not |
352 Vstandard_output, etc.) */ | |
355 void | 353 void |
356 write_string_1 (CONST Bufbyte *str, Bytecount size, Lisp_Object stream) | 354 write_string_1 (CONST Bufbyte *str, Bytecount size, Lisp_Object stream) |
357 { | 355 { |
358 /* This function can GC */ | 356 /* This function can GC */ |
359 #ifdef ERROR_CHECK_BUFPOS | 357 #ifdef ERROR_CHECK_BUFPOS |
379 /* This function can GC */ | 377 /* This function can GC */ |
380 Bufbyte str[MAX_EMCHAR_LEN]; | 378 Bufbyte str[MAX_EMCHAR_LEN]; |
381 Bytecount len; | 379 Bytecount len; |
382 | 380 |
383 CHECK_CHAR_COERCE_INT (ch); | 381 CHECK_CHAR_COERCE_INT (ch); |
384 RESET_PRINT_GENSYM; | |
385 len = set_charptr_emchar (str, XCHAR (ch)); | 382 len = set_charptr_emchar (str, XCHAR (ch)); |
386 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, len); | 383 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, len); |
387 RESET_PRINT_GENSYM; | |
388 return ch; | 384 return ch; |
389 } | 385 } |
390 | 386 |
391 void | 387 void |
392 temp_output_buffer_setup (CONST char *bufname) | 388 temp_output_buffer_setup (CONST char *bufname) |
476 If STREAM is omitted or nil, the value of `standard-output' is used. | 472 If STREAM is omitted or nil, the value of `standard-output' is used. |
477 */ | 473 */ |
478 (stream)) | 474 (stream)) |
479 { | 475 { |
480 /* This function can GC */ | 476 /* This function can GC */ |
481 Bufbyte str[1]; | 477 write_char_internal ("\n", canonicalize_printcharfun (stream)); |
482 str[0] = '\n'; | |
483 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, 1); | |
484 return Qt; | 478 return Qt; |
485 } | 479 } |
486 | 480 |
487 DEFUN ("prin1", Fprin1, 1, 2, 0, /* | 481 DEFUN ("prin1", Fprin1, 1, 2, 0, /* |
488 Output the printed representation of OBJECT, any Lisp object. | 482 Output the printed representation of OBJECT, any Lisp object. |
491 Output stream is STREAM, or value of `standard-output' (which see). | 485 Output stream is STREAM, or value of `standard-output' (which see). |
492 */ | 486 */ |
493 (object, stream)) | 487 (object, stream)) |
494 { | 488 { |
495 /* This function can GC */ | 489 /* This function can GC */ |
496 Lisp_Object the_stream = Qnil, frame = Qnil; | 490 Lisp_Object frame = Qnil; |
497 struct gcpro gcpro1, gcpro2, gcpro3; | 491 struct gcpro gcpro1, gcpro2; |
498 | 492 GCPRO2 (object, stream); |
499 GCPRO3 (object, stream, the_stream); | 493 |
500 print_depth = 0; | 494 print_depth = 0; |
501 the_stream = print_prepare (stream, &frame); | 495 stream = print_prepare (stream, &frame); |
502 print_internal (object, the_stream, 1); | 496 print_internal (object, stream, 1); |
503 print_finish (the_stream, frame); | 497 print_finish (stream, frame); |
498 | |
504 UNGCPRO; | 499 UNGCPRO; |
505 return object; | 500 return object; |
506 } | 501 } |
507 | 502 |
508 DEFUN ("prin1-to-string", Fprin1_to_string, 1, 2, 0, /* | 503 DEFUN ("prin1-to-string", Fprin1_to_string, 1, 2, 0, /* |
512 second argument NOESCAPE is non-nil. | 507 second argument NOESCAPE is non-nil. |
513 */ | 508 */ |
514 (object, noescape)) | 509 (object, noescape)) |
515 { | 510 { |
516 /* This function can GC */ | 511 /* This function can GC */ |
517 Lisp_Object stream; | 512 Lisp_Object result = Qnil; |
518 Lstream *str; | 513 Lisp_Object stream = make_resizing_buffer_output_stream (); |
519 struct gcpro gcpro1, gcpro2; | 514 Lstream *str = XLSTREAM (stream); |
520 | 515 /* gcpro OBJECT in case a caller forgot to do so */ |
521 stream = make_resizing_buffer_output_stream (); | 516 struct gcpro gcpro1, gcpro2, gcpro3; |
522 str = XLSTREAM (stream); | 517 GCPRO3 (object, stream, result); |
523 | 518 |
524 /* Protect OBJECT, in case a caller forgot to protect. */ | |
525 GCPRO2 (object, stream); | |
526 print_depth = 0; | 519 print_depth = 0; |
527 RESET_PRINT_GENSYM; | 520 RESET_PRINT_GENSYM; |
528 print_internal (object, stream, NILP (noescape)); | 521 print_internal (object, stream, NILP (noescape)); |
529 RESET_PRINT_GENSYM; | 522 RESET_PRINT_GENSYM; |
530 Lstream_flush (str); | 523 Lstream_flush (str); |
531 UNGCPRO; | 524 UNGCPRO; |
532 return make_string (resizing_buffer_stream_ptr (str), | 525 result = make_string (resizing_buffer_stream_ptr (str), |
533 Lstream_byte_count (str)); | 526 Lstream_byte_count (str)); |
527 Lstream_delete (str); | |
528 return result; | |
534 } | 529 } |
535 | 530 |
536 DEFUN ("princ", Fprinc, 1, 2, 0, /* | 531 DEFUN ("princ", Fprinc, 1, 2, 0, /* |
537 Output the printed representation of OBJECT, any Lisp object. | 532 Output the printed representation of OBJECT, any Lisp object. |
538 No quoting characters are used; no delimiters are printed around | 533 No quoting characters are used; no delimiters are printed around |
539 the contents of strings. | 534 the contents of strings. |
540 Output stream is STREAM, or value of standard-output (which see). | 535 Output stream is STREAM, or value of standard-output (which see). |
541 */ | 536 */ |
542 (obj, stream)) | 537 (object, stream)) |
543 { | 538 { |
544 /* This function can GC */ | 539 /* This function can GC */ |
545 Lisp_Object the_stream = Qnil, frame = Qnil; | 540 Lisp_Object frame = Qnil; |
546 struct gcpro gcpro1, gcpro2, gcpro3; | 541 struct gcpro gcpro1, gcpro2; |
547 | 542 |
548 GCPRO3 (obj, stream, the_stream); | 543 GCPRO2 (object, stream); |
549 the_stream = print_prepare (stream, &frame); | 544 stream = print_prepare (stream, &frame); |
550 print_depth = 0; | 545 print_depth = 0; |
551 print_internal (obj, the_stream, 0); | 546 print_internal (object, stream, 0); |
552 print_finish (the_stream, frame); | 547 print_finish (stream, frame); |
553 UNGCPRO; | 548 UNGCPRO; |
554 return obj; | 549 return object; |
555 } | 550 } |
556 | 551 |
557 DEFUN ("print", Fprint, 1, 2, 0, /* | 552 DEFUN ("print", Fprint, 1, 2, 0, /* |
558 Output the printed representation of OBJECT, with newlines around it. | 553 Output the printed representation of OBJECT, with newlines around it. |
559 Quoting characters are printed when needed to make output that `read' | 554 Quoting characters are printed when needed to make output that `read' |
560 can handle, whenever this is possible. | 555 can handle, whenever this is possible. |
561 Output stream is STREAM, or value of `standard-output' (which see). | 556 Output stream is STREAM, or value of `standard-output' (which see). |
562 */ | 557 */ |
563 (obj, stream)) | 558 (object, stream)) |
564 { | 559 { |
565 /* This function can GC */ | 560 /* This function can GC */ |
566 Lisp_Object the_stream = Qnil, frame = Qnil; | 561 Lisp_Object frame = Qnil; |
567 struct gcpro gcpro1, gcpro2, gcpro3; | 562 struct gcpro gcpro1, gcpro2; |
568 | 563 |
569 GCPRO3 (obj, stream, the_stream); | 564 GCPRO2 (object, stream); |
570 the_stream = print_prepare (stream, &frame); | 565 stream = print_prepare (stream, &frame); |
571 print_depth = 0; | 566 print_depth = 0; |
572 write_char_internal ("\n", the_stream); | 567 write_char_internal ("\n", stream); |
573 print_internal (obj, the_stream, 1); | 568 print_internal (object, stream, 1); |
574 write_char_internal ("\n", the_stream); | 569 write_char_internal ("\n", stream); |
575 print_finish (the_stream, frame); | 570 print_finish (stream, frame); |
576 UNGCPRO; | 571 UNGCPRO; |
577 return obj; | 572 return object; |
578 } | 573 } |
579 | 574 |
580 | 575 /* Print an error message for the error DATA to STREAM. This is a |
581 /* Synched with Emacs 19.34 -- underlying implementation (incarnated | 576 complete implementation of `display-error', which used to be in |
582 in print_error_message) is completely divergent, though. */ | 577 Lisp (see prim/cmdloop.el). It was ported to C so it can be used |
583 DEFUN ("error-message-string", Ferror_message_string, 1, 1, 0, /* | 578 efficiently by Ferror_message_string. Fdisplay_error and |
584 Convert an error value (ERROR-SYMBOL . DATA) to an error message. | 579 Ferror_message_string are trivial wrappers around this function. |
585 */ | 580 |
586 (data)) | 581 STREAM should be the result of canonicalize_printcharfun(). */ |
587 { | |
588 /* This function can GC */ | |
589 Lisp_Object stream = make_resizing_buffer_output_stream (); | |
590 struct gcpro gcpro1; | |
591 GCPRO1 (stream); | |
592 | |
593 print_error_message (data, stream); | |
594 Lstream_flush (XLSTREAM (stream)); | |
595 UNGCPRO; | |
596 return make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)), | |
597 Lstream_byte_count (XLSTREAM (stream))); | |
598 } | |
599 | |
600 /* Print an error message for the error DATA onto Lisp output stream | |
601 STREAM (suitable for the print functions). | |
602 | |
603 This is a complete implementation of `display-error', which used to | |
604 be in Lisp (see prim/cmdloop.el). It was ported to C so we can use | |
605 it in Ferror_message_string. Fdisplay_error and | |
606 Ferror_message_string are trivial wrappers to this function. */ | |
607 static void | 582 static void |
608 print_error_message (Lisp_Object error_object, Lisp_Object stream) | 583 print_error_message (Lisp_Object error_object, Lisp_Object stream) |
609 { | 584 { |
610 /* This function can GC */ | 585 /* This function can GC */ |
611 Lisp_Object type; | 586 Lisp_Object type = Fcar_safe (error_object); |
612 Lisp_Object method = Qnil; | 587 Lisp_Object method = Qnil; |
613 Lisp_Object tail = Qnil; | 588 Lisp_Object tail; |
614 struct gcpro gcpro1; | 589 |
615 | 590 /* No need to GCPRO anything under the assumption that ERROR_OBJECT |
616 GCPRO1 (tail); | 591 is GCPRO'd. */ |
617 | |
618 type = Fcar_safe (error_object); | |
619 | 592 |
620 if (! (CONSP (error_object) && SYMBOLP (type) | 593 if (! (CONSP (error_object) && SYMBOLP (type) |
621 && CONSP (Fget (type, Qerror_conditions, Qnil)))) | 594 && CONSP (Fget (type, Qerror_conditions, Qnil)))) |
622 goto error_throw; | 595 goto error_throw; |
623 | 596 |
643 tail = XCDR (tail); | 616 tail = XCDR (tail); |
644 } | 617 } |
645 /* Default method */ | 618 /* Default method */ |
646 { | 619 { |
647 int first = 1; | 620 int first = 1; |
648 Lisp_Object printcharfun = canonicalize_printcharfun (stream); | |
649 int speccount = specpdl_depth (); | 621 int speccount = specpdl_depth (); |
650 | 622 |
651 specbind (Qprint_message_label, Qerror); | 623 specbind (Qprint_message_label, Qerror); |
652 tail = Fcdr (error_object); | 624 tail = Fcdr (error_object); |
653 if (EQ (type, Qerror)) | 625 if (EQ (type, Qerror)) |
654 { | 626 { |
655 Fprinc (Fcar (tail), stream); | 627 print_internal (Fcar (tail), stream, 0); |
656 tail = Fcdr (tail); | 628 tail = Fcdr (tail); |
657 } | 629 } |
658 else | 630 else |
659 { | 631 { |
660 Lisp_Object errmsg = Fget (type, Qerror_message, Qnil); | 632 Lisp_Object errmsg = Fget (type, Qerror_message, Qnil); |
661 if (NILP (errmsg)) | 633 if (NILP (errmsg)) |
662 Fprinc (type, stream); | 634 print_internal (type, stream, 0); |
663 else | 635 else |
664 Fprinc (errmsg, stream); | 636 print_internal (LISP_GETTEXT (errmsg), stream, 0); |
665 } | 637 } |
666 while (!NILP (tail)) | 638 while (!NILP (tail)) |
667 { | 639 { |
668 write_c_string (first ? ": " : ", ", printcharfun); | 640 write_c_string (first ? ": " : ", ", stream); |
669 Fprin1 (Fcar (tail), stream); | 641 print_internal (Fcar (tail), stream, 1); |
670 tail = Fcdr (tail); | 642 tail = Fcdr (tail); |
671 first = 0; | 643 first = 0; |
672 } | 644 } |
673 unbind_to (speccount, Qnil); | 645 unbind_to (speccount, Qnil); |
674 UNGCPRO; | |
675 return; | 646 return; |
676 /* Unreached */ | 647 /* not reached */ |
677 } | 648 } |
678 | 649 |
679 error_throw: | 650 error_throw: |
651 if (NILP (method)) | |
652 { | |
653 write_c_string (GETTEXT ("Peculiar error "), stream); | |
654 print_internal (error_object, stream, 1); | |
655 return; | |
656 } | |
657 else | |
658 { | |
659 call2 (method, error_object, stream); | |
660 } | |
661 } | |
662 | |
663 DEFUN ("error-message-string", Ferror_message_string, 1, 1, 0, /* | |
664 Convert ERROR-OBJECT to an error message, and return it. | |
665 | |
666 The format of ERROR-OBJECT should be (ERROR-SYMBOL . DATA). The | |
667 message is equivalent to the one that would be issued by | |
668 `display-error' with the same argument. | |
669 */ | |
670 (error_object)) | |
671 { | |
672 /* This function can GC */ | |
673 Lisp_Object result = Qnil; | |
674 Lisp_Object stream = make_resizing_buffer_output_stream (); | |
675 struct gcpro gcpro1; | |
676 GCPRO1 (stream); | |
677 | |
678 print_error_message (error_object, stream); | |
679 Lstream_flush (XLSTREAM (stream)); | |
680 result = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)), | |
681 Lstream_byte_count (XLSTREAM (stream))); | |
682 Lstream_delete (XLSTREAM (stream)); | |
683 | |
680 UNGCPRO; | 684 UNGCPRO; |
681 if (NILP (method)) | 685 return result; |
682 { | |
683 write_c_string ("Peculiar error ", | |
684 canonicalize_printcharfun (stream)); | |
685 Fprin1 (error_object, stream); | |
686 return; | |
687 } | |
688 else | |
689 { | |
690 call2 (method, error_object, stream); | |
691 } | |
692 } | 686 } |
693 | 687 |
694 DEFUN ("display-error", Fdisplay_error, 2, 2, 0, /* | 688 DEFUN ("display-error", Fdisplay_error, 2, 2, 0, /* |
695 Display an error message for ERROR-OBJECT to STREAM. | 689 Display ERROR-OBJECT on STREAM in a user-friendly way. |
696 */ | 690 */ |
697 (error_object, stream)) | 691 (error_object, stream)) |
698 { | 692 { |
699 /* This function can GC */ | 693 /* This function can GC */ |
700 print_error_message (error_object, stream); | 694 print_error_message (error_object, canonicalize_printcharfun (stream)); |
701 return Qnil; | 695 return Qnil; |
702 } | 696 } |
703 | 697 |
704 | 698 |
705 #ifdef LISP_FLOAT_TYPE | 699 #ifdef LISP_FLOAT_TYPE |
706 | 700 |
707 Lisp_Object Vfloat_output_format; | 701 Lisp_Object Vfloat_output_format; |
708 Lisp_Object Qfloat_output_format; | 702 Lisp_Object Qfloat_output_format; |
709 | 703 |
710 void | |
711 float_to_string (char *buf, double data) | |
712 /* | 704 /* |
713 * This buffer should be at least as large as the max string size of the | 705 * This buffer should be at least as large as the max string size of the |
714 * largest float, printed in the biggest notation. This is undoubtably | 706 * largest float, printed in the biggest notation. This is undoubtably |
715 * 20d float_output_format, with the negative of the C-constant "HUGE" | 707 * 20d float_output_format, with the negative of the C-constant "HUGE" |
716 * from <math.h>. | 708 * from <math.h>. |
720 * I assume that IEEE-754 format numbers can take 329 bytes for the worst | 712 * I assume that IEEE-754 format numbers can take 329 bytes for the worst |
721 * case of -1e307 in 20d float_output_format. What is one to do (short of | 713 * case of -1e307 in 20d float_output_format. What is one to do (short of |
722 * re-writing _doprnt to be more sane)? | 714 * re-writing _doprnt to be more sane)? |
723 * -wsr | 715 * -wsr |
724 */ | 716 */ |
717 void | |
718 float_to_string (char *buf, double data) | |
725 { | 719 { |
726 Bufbyte *cp, c; | 720 Bufbyte *cp, c; |
727 int width; | 721 int width; |
728 | 722 |
729 if (NILP (Vfloat_output_format) | 723 if (NILP (Vfloat_output_format) |
795 #endif /* LISP_FLOAT_TYPE */ | 789 #endif /* LISP_FLOAT_TYPE */ |
796 | 790 |
797 /* Print NUMBER to BUFFER. The digits are first written in reverse | 791 /* Print NUMBER to BUFFER. The digits are first written in reverse |
798 order (the least significant digit first), and are then reversed. | 792 order (the least significant digit first), and are then reversed. |
799 This is equivalent to sprintf(buffer, "%ld", number), only much | 793 This is equivalent to sprintf(buffer, "%ld", number), only much |
800 faster. */ | 794 faster. |
795 | |
796 BUFFER should accept 24 bytes. This should suffice for the longest | |
797 numbers on 64-bit machines. */ | |
801 void | 798 void |
802 long_to_string (char *buffer, long number) | 799 long_to_string (char *buffer, long number) |
803 { | 800 { |
804 char *p; | 801 char *p; |
805 int i, l; | 802 int i, len; |
806 | 803 |
807 if (number < 0) | 804 if (number < 0) |
808 { | 805 { |
809 *buffer++ = '-'; | 806 *buffer++ = '-'; |
810 number = -number; | 807 number = -number; |
811 } | 808 } |
812 p = buffer; | 809 p = buffer; |
810 | |
813 /* Print the digits to the string. */ | 811 /* Print the digits to the string. */ |
814 do | 812 do |
815 { | 813 { |
816 *p++ = number % 10 + '0'; | 814 *p++ = number % 10 + '0'; |
817 number /= 10; | 815 number /= 10; |
818 } | 816 } |
819 while (number); | 817 while (number); |
818 | |
820 /* And reverse them. */ | 819 /* And reverse them. */ |
821 l = p - buffer - 1; | 820 len = p - buffer - 1; |
822 for (i = l/2; i >= 0; i--) | 821 for (i = len / 2; i >= 0; i--) |
823 { | 822 { |
824 char c = buffer[i]; | 823 char c = buffer[i]; |
825 buffer[i] = buffer[l - i]; | 824 buffer[i] = buffer[len - i]; |
826 buffer[l - i] = c; | 825 buffer[len - i] = c; |
827 } | 826 } |
828 buffer[l + 1] = '\0'; | 827 buffer[len + 1] = '\0'; |
829 } | 828 } |
830 | 829 |
831 static void | 830 static void |
832 print_vector_internal (CONST char *start, CONST char *end, | 831 print_vector_internal (CONST char *start, CONST char *end, |
833 Lisp_Object obj, | 832 Lisp_Object obj, |
875 CONSP (XCDR (obj)) && | 874 CONSP (XCDR (obj)) && |
876 NILP (XCDR (XCDR (obj)))) | 875 NILP (XCDR (XCDR (obj)))) |
877 { | 876 { |
878 obj = XCAR (XCDR (obj)); | 877 obj = XCAR (XCDR (obj)); |
879 GCPRO2 (obj, printcharfun); | 878 GCPRO2 (obj, printcharfun); |
880 write_char_internal ("'", printcharfun); | 879 write_char_internal ("\'", printcharfun); |
881 UNGCPRO; | 880 UNGCPRO; |
882 print_internal (obj, printcharfun, escapeflag); | 881 print_internal (obj, printcharfun, escapeflag); |
883 return; | 882 return; |
884 } | 883 } |
885 | 884 |
886 GCPRO2 (obj, printcharfun); | 885 GCPRO2 (obj, printcharfun); |
887 write_char_internal ("(", printcharfun); | 886 write_char_internal ("(", printcharfun); |
887 | |
888 { | 888 { |
889 int i = 0; | 889 int i = 0; |
890 int max = 0; | 890 int max = 0; |
891 | 891 |
892 if (INTP (Vprint_length)) | 892 if (INTP (Vprint_length)) |
1026 | 1026 |
1027 void | 1027 void |
1028 print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | 1028 print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) |
1029 { | 1029 { |
1030 /* This function can GC */ | 1030 /* This function can GC */ |
1031 char buf[256]; | |
1032 | 1031 |
1033 QUIT; | 1032 QUIT; |
1034 | 1033 |
1035 /* Emacs won't print whilst GCing, but an external debugger might */ | 1034 /* Emacs won't print whilst GCing, but an external debugger might */ |
1036 if (gc_in_progress) return; | 1035 if (gc_in_progress) return; |
1053 { | 1052 { |
1054 int i; | 1053 int i; |
1055 for (i = 0; i < print_depth; i++) | 1054 for (i = 0; i < print_depth; i++) |
1056 if (EQ (obj, being_printed[i])) | 1055 if (EQ (obj, being_printed[i])) |
1057 { | 1056 { |
1058 sprintf (buf, "#%d", i); | 1057 char buf[32]; |
1058 *buf = '#'; | |
1059 long_to_string (buf + 1, i); | |
1059 write_c_string (buf, printcharfun); | 1060 write_c_string (buf, printcharfun); |
1060 return; | 1061 return; |
1061 } | 1062 } |
1062 } | 1063 } |
1063 | |
1064 | 1064 |
1065 being_printed[print_depth] = obj; | 1065 being_printed[print_depth] = obj; |
1066 print_depth++; | 1066 print_depth++; |
1067 | 1067 |
1068 if (print_depth > PRINT_CIRCLE) | 1068 if (print_depth > PRINT_CIRCLE) |
1075 case Lisp_Type_Int_Odd: | 1075 case Lisp_Type_Int_Odd: |
1076 #else | 1076 #else |
1077 case Lisp_Type_Int: | 1077 case Lisp_Type_Int: |
1078 #endif | 1078 #endif |
1079 { | 1079 { |
1080 char buf[24]; | |
1080 long_to_string (buf, XINT (obj)); | 1081 long_to_string (buf, XINT (obj)); |
1081 write_c_string (buf, printcharfun); | 1082 write_c_string (buf, printcharfun); |
1082 break; | 1083 break; |
1083 } | 1084 } |
1084 | 1085 |
1085 case Lisp_Type_Char: | 1086 case Lisp_Type_Char: |
1086 { | 1087 { |
1087 /* God intended that this be #\..., you know. */ | 1088 /* God intended that this be #\..., you know. */ |
1089 char buf[16]; | |
1088 Emchar ch = XCHAR (obj); | 1090 Emchar ch = XCHAR (obj); |
1089 char *p = buf; | 1091 char *p = buf; |
1090 *p++ = '?'; | 1092 *p++ = '?'; |
1091 if (ch == '\n') | 1093 if (ch == '\n') |
1092 *p++ = '\\', *p++ = 'n'; | 1094 *p++ = '\\', *p++ = 'n'; |
1207 break; | 1209 break; |
1208 } | 1210 } |
1209 | 1211 |
1210 default: | 1212 default: |
1211 { | 1213 { |
1212 /* We're in trouble if this happens! | 1214 char buf[128]; |
1213 Probably should just abort () */ | 1215 /* We're in trouble if this happens! Probably should just |
1216 abort () */ | |
1214 if (print_readably) | 1217 if (print_readably) |
1215 error ("printing illegal data type #o%03o", | 1218 error ("printing illegal data type #o%03o", |
1216 (int) XTYPE (obj)); | 1219 (int) XTYPE (obj)); |
1217 write_c_string ("#<EMACS BUG: ILLEGAL DATATYPE ", | 1220 write_c_string ("#<EMACS BUG: ILLEGAL DATATYPE ", |
1218 printcharfun); | 1221 printcharfun); |
1434 } | 1437 } |
1435 UNGCPRO; | 1438 UNGCPRO; |
1436 } | 1439 } |
1437 | 1440 |
1438 /* #ifdef DEBUG_XEMACS */ | 1441 /* #ifdef DEBUG_XEMACS */ |
1439 /* I don't like seeing `Note: Strange doc (not fboundp) for function */ | 1442 |
1440 /* alternate-debugging-output @ 429542' -slb */ | 1443 /* I don't like seeing `Note: Strange doc (not fboundp) for function |
1444 alternate-debugging-output @ 429542' -slb */ | |
1445 /* #### Eek! Any clue how to get rid of it? In fact, how about | |
1446 getting rid of this function altogether? Does anything actually | |
1447 *use* it? --hniksic */ | |
1448 | |
1441 int alternate_do_pointer; | 1449 int alternate_do_pointer; |
1442 char alternate_do_string[5000]; | 1450 char alternate_do_string[5000]; |
1443 | 1451 |
1444 DEFUN ("alternate-debugging-output", Falternate_debugging_output, 1, 1, 0, /* | 1452 DEFUN ("alternate-debugging-output", Falternate_debugging_output, 1, 1, 0, /* |
1445 Append CHARACTER to the array `alternate_do_string'. | 1453 Append CHARACTER to the array `alternate_do_string'. |
1460 memcpy (alternate_do_string + alternate_do_pointer, extptr, extlen); | 1468 memcpy (alternate_do_string + alternate_do_pointer, extptr, extlen); |
1461 alternate_do_pointer += extlen; | 1469 alternate_do_pointer += extlen; |
1462 alternate_do_string[alternate_do_pointer] = 0; | 1470 alternate_do_string[alternate_do_pointer] = 0; |
1463 return character; | 1471 return character; |
1464 } | 1472 } |
1465 /* #endif /* DEBUG_XEMACS */ | 1473 /* #endif / * DEBUG_XEMACS */ |
1466 | 1474 |
1467 DEFUN ("external-debugging-output", Fexternal_debugging_output, 1, 3, 0, /* | 1475 DEFUN ("external-debugging-output", Fexternal_debugging_output, 1, 3, 0, /* |
1468 Write CHAR-OR-STRING to stderr or stdout. | 1476 Write CHAR-OR-STRING to stderr or stdout. |
1469 If optional arg STDOUT-P is non-nil, write to stdout; otherwise, write | 1477 If optional arg STDOUT-P is non-nil, write to stdout; otherwise, write |
1470 to stderr. You can use this function to write directly to the terminal. | 1478 to stderr. You can use this function to write directly to the terminal. |