annotate src/print.c @ 440:8de8e3f6228a r21-2-28

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