Mercurial > hg > xemacs-beta
comparison src/print.c @ 173:8eaf7971accc r20-3b13
Import from CVS: tag r20-3b13
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:49:09 +0200 |
parents | 929b76928fce |
children | 6075d714658b |
comparison
equal
deleted
inserted
replaced
172:a38aed19690b | 173:8eaf7971accc |
---|---|
48 | 48 |
49 /* The subroutine object for external-debugging-output is kept here | 49 /* The subroutine object for external-debugging-output is kept here |
50 for the convenience of the debugger. */ | 50 for the convenience of the debugger. */ |
51 Lisp_Object Qexternal_debugging_output; | 51 Lisp_Object Qexternal_debugging_output; |
52 Lisp_Object Qalternate_debugging_output; | 52 Lisp_Object Qalternate_debugging_output; |
53 | 53 |
54 /* Avoid actual stack overflow in print. */ | 54 /* Avoid actual stack overflow in print. */ |
55 static int print_depth; | 55 static int print_depth; |
56 | 56 |
57 /* Maximum length of list or vector to print in full; noninteger means | 57 /* Maximum length of list or vector to print in full; noninteger means |
58 effectively infinity */ | 58 effectively infinity */ |
95 | 95 |
96 | 96 |
97 int stdout_needs_newline; | 97 int stdout_needs_newline; |
98 | 98 |
99 /* Write a string (in internal format) to stdio stream STREAM. */ | 99 /* Write a string (in internal format) to stdio stream STREAM. */ |
100 | 100 |
101 void | 101 void |
102 write_string_to_stdio_stream (FILE *stream, struct console *con, | 102 write_string_to_stdio_stream (FILE *stream, struct console *con, |
103 CONST Bufbyte *str, | 103 CONST Bufbyte *str, |
104 Bytecount offset, Bytecount len, | 104 Bytecount offset, Bytecount len, |
105 enum external_data_format fmt) | 105 enum external_data_format fmt) |
306 { | 306 { |
307 #ifndef standalone | 307 #ifndef standalone |
308 printcharfun = Fselected_frame (Qnil); /* print to minibuffer */ | 308 printcharfun = Fselected_frame (Qnil); /* print to minibuffer */ |
309 #endif | 309 #endif |
310 } | 310 } |
311 return (printcharfun); | 311 return printcharfun; |
312 } | 312 } |
313 | 313 |
314 | 314 |
315 static Lisp_Object | 315 static Lisp_Object |
316 print_prepare (Lisp_Object printcharfun) | 316 print_prepare (Lisp_Object printcharfun) |
317 { | 317 { |
318 FILE *stdio_stream = 0; | 318 FILE *stdio_stream = 0; |
319 | 319 |
320 /* Emacs won't print whilst GCing, but an external debugger might */ | 320 /* Emacs won't print whilst GCing, but an external debugger might */ |
321 if (gc_in_progress) | 321 if (gc_in_progress) |
322 return (Qnil); | 322 return Qnil; |
323 | 323 |
324 printcharfun = canonicalize_printcharfun (printcharfun); | 324 printcharfun = canonicalize_printcharfun (printcharfun); |
325 if (EQ (printcharfun, Qnil)) | 325 if (EQ (printcharfun, Qnil)) |
326 { | 326 { |
327 stdio_stream = stdout; | 327 stdio_stream = stdout; |
328 } | 328 } |
329 #if 0 /* Don't bother */ | 329 #if 0 /* Don't bother */ |
330 else if (SUBRP (indirect_function (printcharfun, 0)) | 330 else if (SUBRP (indirect_function (printcharfun, 0)) |
331 && (XSUBR (indirect_function (printcharfun, 0)) | 331 && (XSUBR (indirect_function (printcharfun, 0)) |
332 == Sexternal_debugging_output)) | 332 == Sexternal_debugging_output)) |
333 { | 333 { |
334 stdio_stream = stderr; | 334 stdio_stream = stderr; |
335 } | 335 } |
336 #endif | 336 #endif |
337 | 337 |
338 return make_print_output_stream (stdio_stream, printcharfun); | 338 return make_print_output_stream (stdio_stream, printcharfun); |
339 } | 339 } |
340 | 340 |
341 static void | 341 static void |
342 print_finish (Lisp_Object stream) | 342 print_finish (Lisp_Object stream) |
420 | 420 |
421 set_buffer_internal (old); | 421 set_buffer_internal (old); |
422 } | 422 } |
423 | 423 |
424 Lisp_Object | 424 Lisp_Object |
425 internal_with_output_to_temp_buffer (CONST char *bufname, | 425 internal_with_output_to_temp_buffer (CONST char *bufname, |
426 Lisp_Object (*function) (Lisp_Object arg), | 426 Lisp_Object (*function) (Lisp_Object arg), |
427 Lisp_Object arg, | 427 Lisp_Object arg, |
428 Lisp_Object same_frame) | 428 Lisp_Object same_frame) |
429 { | 429 { |
430 int speccount = specpdl_depth (); | 430 int speccount = specpdl_depth (); |
431 struct gcpro gcpro1, gcpro2, gcpro3; | 431 struct gcpro gcpro1, gcpro2, gcpro3; |
432 Lisp_Object buf = Qnil; | 432 Lisp_Object buf = Qnil; |
540 Ferase_buffer (Fcurrent_buffer ()); | 540 Ferase_buffer (Fcurrent_buffer ()); |
541 print_depth = 0; | 541 print_depth = 0; |
542 print_internal (object, stream, NILP (noescape)); | 542 print_internal (object, stream, NILP (noescape)); |
543 print_finish (stream); | 543 print_finish (stream); |
544 stream = Qnil; /* No GC surprises! */ | 544 stream = Qnil; /* No GC surprises! */ |
545 object = make_string_from_buffer (out, | 545 object = make_string_from_buffer (out, |
546 BUF_BEG (out), | 546 BUF_BEG (out), |
547 BUF_Z (out) - 1); | 547 BUF_Z (out) - 1); |
548 Ferase_buffer (Fcurrent_buffer ()); | 548 Ferase_buffer (Fcurrent_buffer ()); |
549 Fset_buffer (old); | 549 Fset_buffer (old); |
550 UNGCPRO; | 550 UNGCPRO; |
551 return (object); | 551 return object; |
552 } | 552 } |
553 | 553 |
554 DEFUN ("princ", Fprinc, 1, 2, 0, /* | 554 DEFUN ("princ", Fprinc, 1, 2, 0, /* |
555 Output the printed representation of OBJECT, any Lisp object. | 555 Output the printed representation of OBJECT, any Lisp object. |
556 No quoting characters are used; no delimiters are printed around | 556 No quoting characters are used; no delimiters are printed around |
567 the_stream = print_prepare (stream); | 567 the_stream = print_prepare (stream); |
568 print_depth = 0; | 568 print_depth = 0; |
569 print_internal (obj, the_stream, 0); | 569 print_internal (obj, the_stream, 0); |
570 print_finish (the_stream); | 570 print_finish (the_stream); |
571 UNGCPRO; | 571 UNGCPRO; |
572 return (obj); | 572 return obj; |
573 } | 573 } |
574 | 574 |
575 DEFUN ("print", Fprint, 1, 2, 0, /* | 575 DEFUN ("print", Fprint, 1, 2, 0, /* |
576 Output the printed representation of OBJECT, with newlines around it. | 576 Output the printed representation of OBJECT, with newlines around it. |
577 Quoting characters are printed when needed to make output that `read' | 577 Quoting characters are printed when needed to make output that `read' |
737 /* | 737 /* |
738 * This buffer should be at least as large as the max string size of the | 738 * This buffer should be at least as large as the max string size of the |
739 * largest float, printed in the biggest notation. This is undoubtably | 739 * largest float, printed in the biggest notation. This is undoubtably |
740 * 20d float_output_format, with the negative of the C-constant "HUGE" | 740 * 20d float_output_format, with the negative of the C-constant "HUGE" |
741 * from <math.h>. | 741 * from <math.h>. |
742 * | 742 * |
743 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes. | 743 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes. |
744 * | 744 * |
745 * I assume that IEEE-754 format numbers can take 329 bytes for the worst | 745 * I assume that IEEE-754 format numbers can take 329 bytes for the worst |
746 * case of -1e307 in 20d float_output_format. What is one to do (short of | 746 * case of -1e307 in 20d float_output_format. What is one to do (short of |
747 * re-writing _doprnt to be more sane)? | 747 * re-writing _doprnt to be more sane)? |
748 * -wsr | 748 * -wsr |
749 */ | 749 */ |
750 { | 750 { |
751 Bufbyte *cp, c; | 751 Bufbyte *cp, c; |
752 int width; | 752 int width; |
753 | 753 |
754 if (NILP (Vfloat_output_format) | 754 if (NILP (Vfloat_output_format) |
755 || !STRINGP (Vfloat_output_format)) | 755 || !STRINGP (Vfloat_output_format)) |
756 lose: | 756 lose: |
757 sprintf (buf, "%.16g", data); | 757 sprintf (buf, "%.16g", data); |
758 else /* oink oink */ | 758 else /* oink oink */ |
772 { | 772 { |
773 width *= 10; | 773 width *= 10; |
774 width += c - '0'; | 774 width += c - '0'; |
775 } | 775 } |
776 | 776 |
777 if (*cp != 'e' && *cp != 'f' && *cp != 'g' && *cp != 'E' && *cp != 'G') | 777 if (*cp != 'e' && *cp != 'f' && *cp != 'g' && *cp != 'E' && *cp != 'G') |
778 goto lose; | 778 goto lose; |
779 | 779 |
780 if (width < (int) (*cp != 'e' && *cp != 'E') || width > DBL_DIG) | 780 if (width < (int) (*cp != 'e' && *cp != 'E') || width > DBL_DIG) |
781 goto lose; | 781 goto lose; |
782 | 782 |
819 } | 819 } |
820 #endif /* LISP_FLOAT_TYPE */ | 820 #endif /* LISP_FLOAT_TYPE */ |
821 | 821 |
822 static void | 822 static void |
823 print_vector_internal (CONST char *start, CONST char *end, | 823 print_vector_internal (CONST char *start, CONST char *end, |
824 Lisp_Object obj, | 824 Lisp_Object obj, |
825 Lisp_Object printcharfun, int escapeflag) | 825 Lisp_Object printcharfun, int escapeflag) |
826 { | 826 { |
827 /* This function can GC */ | 827 /* This function can GC */ |
828 int i; | 828 int i; |
829 int len = vector_length (XVECTOR (obj)); | 829 int len = XVECTOR_LENGTH (obj); |
830 int last = len; | 830 int last = len; |
831 struct gcpro gcpro1, gcpro2; | 831 struct gcpro gcpro1, gcpro2; |
832 GCPRO2 (obj, printcharfun); | 832 GCPRO2 (obj, printcharfun); |
833 | 833 |
834 if (INTP (Vprint_length)) | 834 if (INTP (Vprint_length)) |
838 } | 838 } |
839 | 839 |
840 write_c_string (start, printcharfun); | 840 write_c_string (start, printcharfun); |
841 for (i = 0; i < last; i++) | 841 for (i = 0; i < last; i++) |
842 { | 842 { |
843 Lisp_Object elt = vector_data (XVECTOR (obj))[i]; | 843 Lisp_Object elt = XVECTOR_DATA (obj)[i]; |
844 if (i != 0) write_char_internal (" ", printcharfun); | 844 if (i != 0) write_char_internal (" ", printcharfun); |
845 print_internal (elt, printcharfun, escapeflag); | 845 print_internal (elt, printcharfun, escapeflag); |
846 } | 846 } |
847 UNGCPRO; | 847 UNGCPRO; |
848 if (last != len) | 848 if (last != len) |
870 void | 870 void |
871 internal_object_printer (Lisp_Object obj, Lisp_Object printcharfun, | 871 internal_object_printer (Lisp_Object obj, Lisp_Object printcharfun, |
872 int escapeflag) | 872 int escapeflag) |
873 { | 873 { |
874 char buf[200]; | 874 char buf[200]; |
875 sprintf (buf, "#<INTERNAL OBJECT (XEmacs bug?) (%s) 0x%x>", | 875 sprintf (buf, "#<INTERNAL OBJECT (XEmacs bug?) (%s) 0x%p>", |
876 XRECORD_LHEADER (obj)->implementation->name, | 876 XRECORD_LHEADER (obj)->implementation->name, |
877 (EMACS_INT) XPNTR (obj)); | 877 (void *) XPNTR (obj)); |
878 write_c_string (buf, printcharfun); | 878 write_c_string (buf, printcharfun); |
879 } | 879 } |
880 | 880 |
881 void | 881 void |
882 print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) | 882 print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) |
908 | 908 |
909 switch (XTYPE (obj)) | 909 switch (XTYPE (obj)) |
910 { | 910 { |
911 case Lisp_Int: | 911 case Lisp_Int: |
912 { | 912 { |
913 sprintf (buf, "%d", XINT (obj)); | 913 sprintf (buf, "%ld", (long) XINT (obj)); |
914 write_c_string (buf, printcharfun); | 914 write_c_string (buf, printcharfun); |
915 break; | 915 break; |
916 } | 916 } |
917 | 917 |
918 case Lisp_Char: | 918 case Lisp_Char: |
983 | 983 |
984 write_char_internal ("\"", printcharfun); | 984 write_char_internal ("\"", printcharfun); |
985 for (i = 0; i < max; i++) | 985 for (i = 0; i < max; i++) |
986 { | 986 { |
987 Bufbyte ch = string_byte (s, i); | 987 Bufbyte ch = string_byte (s, i); |
988 if (ch == '\"' || ch == '\\' | 988 if (ch == '\"' || ch == '\\' |
989 || (ch == '\n' && print_escape_newlines)) | 989 || (ch == '\n' && print_escape_newlines)) |
990 { | 990 { |
991 if (i > last) | 991 if (i > last) |
992 { | 992 { |
993 output_string (printcharfun, 0, obj, last, | 993 output_string (printcharfun, 0, obj, last, |
1144 print_depth--; | 1144 print_depth--; |
1145 } | 1145 } |
1146 | 1146 |
1147 static void | 1147 static void |
1148 print_compiled_function_internal (CONST char *start, CONST char *end, | 1148 print_compiled_function_internal (CONST char *start, CONST char *end, |
1149 Lisp_Object obj, | 1149 Lisp_Object obj, |
1150 Lisp_Object printcharfun, int escapeflag) | 1150 Lisp_Object printcharfun, int escapeflag) |
1151 { | 1151 { |
1152 /* This function can GC */ | 1152 /* This function can GC */ |
1153 struct Lisp_Compiled_Function *b = | 1153 struct Lisp_Compiled_Function *b = |
1154 XCOMPILED_FUNCTION (obj); /* GC doesn't relocate */ | 1154 XCOMPILED_FUNCTION (obj); /* GC doesn't relocate */ |
1247 output_string (printcharfun, 0, nameobj, 0, size); | 1247 output_string (printcharfun, 0, nameobj, 0, size); |
1248 return; | 1248 return; |
1249 } | 1249 } |
1250 GCPRO2 (obj, printcharfun); | 1250 GCPRO2 (obj, printcharfun); |
1251 | 1251 |
1252 if (print_gensym) | 1252 if (print_gensym) |
1253 { | 1253 { |
1254 Lisp_Object tem = oblookup (Vobarray, string_data (name), size); | 1254 Lisp_Object tem = oblookup (Vobarray, string_data (name), size); |
1255 if (!EQ (tem, obj)) | 1255 if (!EQ (tem, obj)) |
1256 /* (read) would return a new symbol with the same name. | 1256 /* (read) would return a new symbol with the same name. |
1257 This isn't quite correct, because that symbol might not | 1257 This isn't quite correct, because that symbol might not |
1277 confusing = 1; | 1277 confusing = 1; |
1278 else | 1278 else |
1279 goto not_yet_confused; | 1279 goto not_yet_confused; |
1280 | 1280 |
1281 for (; confusing < size; confusing++) | 1281 for (; confusing < size; confusing++) |
1282 { | 1282 { |
1283 if (!isdigit (data[confusing])) | 1283 if (!isdigit (data[confusing])) |
1284 { | 1284 { |
1285 confusing = 0; | 1285 confusing = 0; |
1286 break; | 1286 break; |
1287 } | 1287 } |
1298 | 1298 |
1299 { | 1299 { |
1300 Lisp_Object nameobj; | 1300 Lisp_Object nameobj; |
1301 Bytecount i; | 1301 Bytecount i; |
1302 Bytecount last = 0; | 1302 Bytecount last = 0; |
1303 | 1303 |
1304 XSETSTRING (nameobj, name); | 1304 XSETSTRING (nameobj, name); |
1305 for (i = 0; i < size; i++) | 1305 for (i = 0; i < size; i++) |
1306 { | 1306 { |
1307 Bufbyte c = string_byte (name, i); | 1307 Bufbyte c = string_byte (name, i); |
1308 | 1308 |