annotate src/print.c @ 4976:16112448d484

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