annotate src/print.c @ 167:85ec50267440 r20-3b10

Import from CVS: tag r20-3b10
author cvs
date Mon, 13 Aug 2007 09:45:46 +0200
parents 538048ae2ab8
children 929b76928fce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Lisp object printing and output streams.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1988, 1992-1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995, 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: Not synched with FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* This file has been Mule-ized. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 /* Seriously hacked on by Ben Wing for Mule. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #ifndef standalone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include "backtrace.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include "bytecode.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include "console-tty.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include "console-stream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include "extents.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include "emacsfns.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include "lstream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #endif /* not standalone */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 110
diff changeset
45 static void print_error_message (Lisp_Object data, Lisp_Object stream);
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 110
diff changeset
46
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 Lisp_Object Vstandard_output, Qstandard_output;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 /* The subroutine object for external-debugging-output is kept here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 for the convenience of the debugger. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 Lisp_Object Qexternal_debugging_output;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 Lisp_Object Qalternate_debugging_output;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 /* Avoid actual stack overflow in print. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 static int print_depth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 /* Maximum length of list or vector to print in full; noninteger means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 effectively infinity */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 Lisp_Object Vprint_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 Lisp_Object Qprint_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 /* Maximum length of string to print in full; noninteger means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 effectively infinity */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 Lisp_Object Vprint_string_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 Lisp_Object Qprint_string_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 /* Maximum depth of list to print in full; noninteger means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 effectively infinity. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 Lisp_Object Vprint_level;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 /* Label to use when making echo-area messages. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 Lisp_Object Vprint_message_label;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 /* Nonzero means print newlines in strings as \n. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 int print_escape_newlines;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 int print_readably;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 int print_gensym;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 Lisp_Object Qprint_escape_newlines;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 Lisp_Object Qprint_readably;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 /* Force immediate output of all printed data. Used for debugging. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 int print_unbuffered;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 FILE *termscript; /* Stdio stream being used for copy of all output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 int stdout_needs_newline;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 /* Write a string (in internal format) to stdio stream STREAM. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 write_string_to_stdio_stream (FILE *stream, struct console *con,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 CONST Bufbyte *str,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 Bytecount offset, Bytecount len,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 enum external_data_format fmt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 int extlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 CONST Extbyte *extptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 GET_CHARPTR_EXT_DATA_ALLOCA (str + offset, len, fmt, extptr, extlen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 if (stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 fwrite (extptr, 1, extlen, stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 assert (CONSOLE_TTY_P (con));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 Lstream_write (XLSTREAM (CONSOLE_TTY_DATA (con)->outstream),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 extptr, extlen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 if (stream == stdout || stream == stderr ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (!stream && CONSOLE_TTY_DATA (con)->is_stdio))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 if (termscript)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 fwrite (extptr, 1, extlen, termscript);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 fflush (termscript);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 stdout_needs_newline = (extptr[extlen - 1] != '\n');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 /* Write a string to the output location specified in FUNCTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Arguments NONRELOC, RELOC, OFFSET, and LEN are as in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 buffer_insert_string_1() in insdel.c. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 output_string (Lisp_Object function, CONST Bufbyte *nonreloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 Lisp_Object reloc, Bytecount offset, Bytecount len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 Charcount ccoff, cclen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 /* We change the value of nonreloc (fetching it from reloc as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 necessary), but we don't want to pass this changed value on to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 other functions that take both a nonreloc and a reloc, or things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 may get confused and an assertion failure in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 fixup_internal_substring() may get triggered. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 CONST Bufbyte *newnonreloc = nonreloc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 /* Emacs won't print whilst GCing, but an external debugger might */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 if (gc_in_progress) return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 /* Perhaps not necessary but probably safer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 GCPRO2 (function, reloc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 fixup_internal_substring (newnonreloc, reloc, offset, &len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 if (STRINGP (reloc))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
155 newnonreloc = XSTRING_DATA (reloc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ccoff = bytecount_to_charcount (newnonreloc, offset);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 cclen = bytecount_to_charcount (newnonreloc + offset, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 if (LSTREAMP (function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 /* Lstream_write() could easily cause GC inside of it, if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 stream is a print-stream. (It will call output_string()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 recursively.) This is probably the fastest way to fix this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 problem. (alloca() is very fast on machines that have it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 built-in, and you avoid some nasty problems with recursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 that could result from using a static buffer somewhere.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 The other possibility is to inhibit GC, but that of course
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 would require an unwind-protect, which is usually a lot
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 slower than the small amount of memcpy()ing that happens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 if (STRINGP (reloc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 Bufbyte *copied = (Bufbyte *) alloca (len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 memcpy (copied, newnonreloc + offset, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 Lstream_write (XLSTREAM (function), copied, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 Lstream_write (XLSTREAM (function), newnonreloc + offset, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 if (print_unbuffered)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 Lstream_flush (XLSTREAM (function));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 #ifndef standalone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 else if (BUFFERP (function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 CHECK_LIVE_BUFFER (function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 buffer_insert_string (XBUFFER (function), nonreloc, reloc, offset, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 else if (MARKERP (function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 /* marker_position will err if marker doesn't point anywhere */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 Bufpos spoint = marker_position (function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 buffer_insert_string_1 (XBUFFER (Fmarker_buffer (function)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 spoint, nonreloc, reloc, offset, len,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 Fset_marker (function, make_int (spoint + cclen),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 Fmarker_buffer (function));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 else if (FRAMEP (function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 struct frame *f = XFRAME (function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 if (!EQ (Vprint_message_label, echo_area_status (f)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 clear_echo_area_from_print (f, Qnil, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 echo_area_append (f, nonreloc, reloc, offset, len, Vprint_message_label);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 #endif /* not standalone */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 else if (EQ (function, Qt) || EQ (function, Qnil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 write_string_to_stdio_stream (stdout, 0, newnonreloc, offset, len,
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
214 FORMAT_TERMINAL);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 Charcount iii;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 for (iii = ccoff; iii < cclen + ccoff; iii++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 call1 (function,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 make_char (charptr_emchar_n (newnonreloc, iii)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 if (STRINGP (reloc))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
225 newnonreloc = XSTRING_DATA (reloc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 struct print_stream
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 FILE *file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 Lisp_Object fun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 #define get_print_stream(stream) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ((struct print_stream *) Lstream_data (stream))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 DEFINE_LSTREAM_IMPLEMENTATION ("print", lstream_print,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 sizeof (struct print_stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 make_print_output_stream (FILE *file, Lisp_Object fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 Lstream *str = Lstream_new (lstream_print, "w");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 struct print_stream *ps = get_print_stream (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 Lisp_Object val = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 Lstream_set_character_mode (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ps->file = file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ps->fun = fun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 XSETLSTREAM (val, str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 /* #### This isn't being used anywhere at the moment. Is it supposed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 to be? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 reset_print_stream (Lstream *str, FILE *file, Lisp_Object fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 struct print_stream *ps = get_print_stream (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 Lstream_reopen (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ps->file = file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ps->fun = fun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 print_marker (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 return get_print_stream (XLSTREAM (obj))->fun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 print_writer (Lstream *stream, CONST unsigned char *data, int size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 struct print_stream *ps = get_print_stream (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 if (ps->file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 write_string_to_stdio_stream (ps->file, 0, data, 0, size,
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
286 FORMAT_TERMINAL);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 /* Make sure it really gets written now. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 if (print_unbuffered)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 fflush (ps->file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 output_string (ps->fun, data, Qnil, 0, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 return size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 canonicalize_printcharfun (Lisp_Object printcharfun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 if (NILP (printcharfun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 printcharfun = Vstandard_output;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 if (EQ (printcharfun, Qt) || NILP (printcharfun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 #ifndef standalone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 printcharfun = Fselected_frame (Qnil); /* print to minibuffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 return (printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 print_prepare (Lisp_Object printcharfun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 FILE *stdio_stream = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 /* Emacs won't print whilst GCing, but an external debugger might */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 if (gc_in_progress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 return (Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 printcharfun = canonicalize_printcharfun (printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 if (EQ (printcharfun, Qnil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 stdio_stream = stdout;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 #if 0 /* Don't bother */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 else if (SUBRP (indirect_function (printcharfun, 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 && (XSUBR (indirect_function (printcharfun, 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 == Sexternal_debugging_output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 stdio_stream = stderr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 return make_print_output_stream (stdio_stream, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 print_finish (Lisp_Object stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 /* Emacs won't print whilst GCing, but an external debugger might */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 if (gc_in_progress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 Lstream_delete (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 #if 1 /* Prefer space over "speed" */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 #define write_char_internal(string_of_length_1, stream) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 write_string_1 ((CONST Bufbyte *) (string_of_length_1), 1, (stream))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 #define write_char_internal(string_of_length_1, stream) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 output_string ((stream), (CONST Bufbyte *) (string_of_length_1), Qnil, 0, 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 /* NOTE: Do not call this with the data of a Lisp_String,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 * as printcharfun might cause a GC, which might cause
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 * the string's data to be relocated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 * Use print_object_internal (string, printcharfun, 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 * to princ a Lisp_String
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 * Note: "stream" should be the result of "canonicalize_printcharfun"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 * (ie Qnil means stdout, not Vstandard_output, etc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 write_string_1 (CONST Bufbyte *str, Bytecount size, Lisp_Object stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 assert (size >= 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 output_string (stream, str, Qnil, 0, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 write_c_string (CONST char *str, Lisp_Object stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 write_string_1 ((CONST Bufbyte *) str, strlen (str), stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
380 DEFUN ("write-char", Fwrite_char, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 Output character CH to stream STREAM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 STREAM defaults to the value of `standard-output' (which see).
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
383 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
384 (ch, stream))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 Bufbyte str[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 CHECK_CHAR_COERCE_INT (ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 len = set_charptr_emchar (str, XCHAR (ch));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 return ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 #ifndef standalone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 temp_output_buffer_setup (CONST char *bufname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 struct buffer *old = current_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 Lisp_Object buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 /* #### This function should accept a Lisp_Object instead of a char *,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 so that proper translation on the buffer name can occur. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 Fset_buffer (Fget_buffer_create (build_string (bufname)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 current_buffer->read_only = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 Ferase_buffer (Fcurrent_buffer ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 XSETBUFFER (buf, current_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 specbind (Qstandard_output, buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 set_buffer_internal (old);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 internal_with_output_to_temp_buffer (CONST char *bufname,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 Lisp_Object (*function) (Lisp_Object arg),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 Lisp_Object arg,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 Lisp_Object same_frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 Lisp_Object buf = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 GCPRO3 (buf, arg, same_frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 temp_output_buffer_setup (GETTEXT (bufname));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 buf = Vstandard_output;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 arg = (*function) (arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 temp_output_buffer_show (buf, same_frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 return unbind_to (speccount, arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
444 DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, 1, UNEVALLED, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 The buffer is cleared out initially, and marked as unmodified when done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 All output done by BODY is inserted in that buffer by default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 The buffer is displayed in another window, but not selected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 The value of the last form in BODY is returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 If BODY does not finish normally, the buffer BUFNAME is not displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 If variable `temp-buffer-show-function' is non-nil, call it at the end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 to get the buffer displayed. It gets one argument, the buffer to display.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
454 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
455 (args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 Lisp_Object name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 Lisp_Object buf, val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 /* #### should set the buffer to be translating. See print_internal(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 GCPRO1 (args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 name = Feval (Fcar (args));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 CHECK_STRING (name);
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
472 temp_output_buffer_setup ((char *) XSTRING_DATA (name));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 buf = Vstandard_output;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 val = Fprogn (Fcdr (args));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 temp_output_buffer_show (buf, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 return unbind_to (speccount, val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 #endif /* not standalone */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
483 DEFUN ("terpri", Fterpri, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 Output a newline to STREAM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 If STREAM is omitted or nil, the value of `standard-output' is used.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
486 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
487 (stream))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 Bufbyte str[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 str[0] = '\n';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 output_string (canonicalize_printcharfun (stream), str, Qnil, 0, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
496 DEFUN ("prin1", Fprin1, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 Output the printed representation of OBJECT, any Lisp object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 Quoting characters are printed when needed to make output that `read'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 can handle, whenever this is possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 Output stream is STREAM, or value of `standard-output' (which see).
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
501 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
502 (object, stream))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 Lisp_Object the_stream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 GCPRO3 (object, stream, the_stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 print_depth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 the_stream = print_prepare (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 print_internal (object, the_stream, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 print_finish (the_stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 return object;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 /* a buffer which is used to hold output being built by prin1-to-string */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 Lisp_Object Vprin1_to_string_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
520 DEFUN ("prin1-to-string", Fprin1_to_string, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 Return a string containing the printed representation of OBJECT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 any Lisp object. Quoting characters are used when needed to make output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 that `read' can handle, whenever this is possible, unless the optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 second argument NOESCAPE is non-nil.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
525 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
526 (object, noescape))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 Lisp_Object old = Fcurrent_buffer ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 struct buffer *out = XBUFFER (Vprin1_to_string_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 Lisp_Object stream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 GCPRO3 (object, old, stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 stream = print_prepare (Vprin1_to_string_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 set_buffer_internal (out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 Ferase_buffer (Fcurrent_buffer ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 print_depth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 print_internal (object, stream, NILP (noescape));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 print_finish (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 stream = Qnil; /* No GC surprises! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 object = make_string_from_buffer (out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 BUF_BEG (out),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 BUF_Z (out) - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 Ferase_buffer (Fcurrent_buffer ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 Fset_buffer (old);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 return (object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
551 DEFUN ("princ", Fprinc, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 Output the printed representation of OBJECT, any Lisp object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 No quoting characters are used; no delimiters are printed around
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 the contents of strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 Output stream is STREAM, or value of standard-output (which see).
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
556 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
557 (obj, stream))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 Lisp_Object the_stream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 GCPRO3 (obj, stream, the_stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 the_stream = print_prepare (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 print_depth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 print_internal (obj, the_stream, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 print_finish (the_stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 return (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
572 DEFUN ("print", Fprint, 1, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 Output the printed representation of OBJECT, with newlines around it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 Quoting characters are printed when needed to make output that `read'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 can handle, whenever this is possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 Output stream is STREAM, or value of `standard-output' (which see).
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
577 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
578 (obj, stream))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 Lisp_Object the_stream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 GCPRO3 (obj, stream, the_stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 the_stream = print_prepare (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 print_depth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 write_char_internal ("\n", the_stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 print_internal (obj, the_stream, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 write_char_internal ("\n", the_stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 print_finish (the_stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
595 #include "emacsfns.h"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
596 /* Synched with Emacs 19.34 */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
597 DEFUN ("error-message-string", Ferror_message_string, 1, 1, 0, /*
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
598 Convert an error value (ERROR-SYMBOL . DATA) to an error message.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
599 */
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 149
diff changeset
600 (data))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
601 {
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 149
diff changeset
602 struct buffer *pbuf;
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
603 Lisp_Object original, printcharfun, value;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
604 struct gcpro gcpro1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
605
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 149
diff changeset
606 print_error_message (data, Vprin1_to_string_buffer);
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
607
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 149
diff changeset
608 pbuf = XBUFFER (Vprin1_to_string_buffer);
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 149
diff changeset
609 value = make_string_from_buffer (pbuf,
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 149
diff changeset
610 BUF_BEGV (pbuf),
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 149
diff changeset
611 BUF_ZV (pbuf) - BUF_BEGV (pbuf));
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
612 GCPRO1 (value);
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 149
diff changeset
613 Ferase_buffer (Vprin1_to_string_buffer);
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
614 UNGCPRO;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
615
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
616 return value;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
617 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
618
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
619 /* Print an error message for the error DATA
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
620 onto Lisp output stream STREAM (suitable for the print functions). */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
621
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 110
diff changeset
622 static void print_error_message (Lisp_Object data, Lisp_Object stream)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
623 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
624 Lisp_Object errname, errmsg, file_error, tail;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
625 struct gcpro gcpro1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
626 int i;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
627
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
628 errname = Fcar (data);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
629
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
630 if (EQ (errname, Qerror))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
631 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
632 data = Fcdr (data);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
633 if (!CONSP (data)) data = Qnil;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
634 errmsg = Fcar (data);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
635 file_error = Qnil;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
636 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
637 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
638 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
639 errmsg = Fget (errname, Qerror_message, Qnil);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
640 file_error = Fmemq (Qfile_error,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
641 Fget (errname, Qerror_conditions, Qnil));
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
642 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
643
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
644 /* Print an error message including the data items. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
645
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
646 tail = Fcdr_safe (data);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
647 GCPRO1 (tail);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
648
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
649 /* For file-error, make error message by concatenating
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
650 all the data items. They are all strings. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
651 if (!NILP (file_error) && !NILP (tail))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
652 errmsg = XCONS (tail)->car, tail = XCONS (tail)->cdr;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
653
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
654 if (STRINGP (errmsg))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
655 Fprinc (errmsg, stream);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
656 else
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
657 write_string_1 ((CONST Bufbyte *)"Peculiar error", 14, stream);
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
658
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
659 for (i = 0; CONSP (tail); tail = Fcdr (tail), i++)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
660 {
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
661 write_string_1 ((CONST Bufbyte *)(i ? ", " : ": "), 2, stream);
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
662 if (!NILP (file_error))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
663 Fprinc (Fcar (tail), stream);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
664 else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
665 Fprin1 (Fcar (tail), stream);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
666 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
667 UNGCPRO;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
668 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
669
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 Lisp_Object Vfloat_output_format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 Lisp_Object Qfloat_output_format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 float_to_string (char *buf, double data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 * This buffer should be at least as large as the max string size of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 * largest float, printed in the biggest notation. This is undoubtably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 * 20d float_output_format, with the negative of the C-constant "HUGE"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 * from <math.h>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 * I assume that IEEE-754 format numbers can take 329 bytes for the worst
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 * case of -1e307 in 20d float_output_format. What is one to do (short of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 * re-writing _doprnt to be more sane)?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 * -wsr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 Bufbyte *cp, c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 int width;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 if (NILP (Vfloat_output_format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 || !STRINGP (Vfloat_output_format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 lose:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 sprintf (buf, "%.16g", data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 else /* oink oink */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 /* Check that the spec we have is fully valid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 This means not only valid for printf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 but meant for floats, and reasonable. */
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
703 cp = XSTRING_DATA (Vfloat_output_format);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 if (cp[0] != '%')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 if (cp[1] != '.')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 cp += 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 for (width = 0; (c = *cp, isdigit (c)); cp++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 width *= 10;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 width += c - '0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 if (*cp != 'e' && *cp != 'f' && *cp != 'g' && *cp != 'E' && *cp != 'G')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 if (width < (int) (*cp != 'e' && *cp != 'E') || width > DBL_DIG)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 if (cp[1] != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 goto lose;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
726 sprintf (buf, (char *) XSTRING_DATA (Vfloat_output_format),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 /* added by jwz: don't allow "1.0" to print as "1"; that destroys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 the read-equivalence of lisp objects. (* x 1) and (* x 1.0) do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 not do the same thing, so it's important that the printed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 representation of that form not be corrupted by the printer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 Bufbyte *s = (Bufbyte *) buf; /* don't use signed chars here!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 isdigit() can't hack them! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 if (*s == '-') s++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 for (; *s; s++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 /* if there's a non-digit, then there is a decimal point, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 it's in exponential notation, both of which are ok. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 if (!isdigit (*s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 goto DONE_LABEL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 /* otherwise, we need to hack it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 *s++ = '.';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 *s++ = '0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 *s = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 DONE_LABEL:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 /* Some machines print "0.4" as ".4". I don't like that. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 if (buf [0] == '.' || (buf [0] == '-' && buf [1] == '.'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 for (i = strlen (buf) + 1; i >= 0; i--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 buf [i+1] = buf [i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 buf [(buf [0] == '-' ? 1 : 0)] = '0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 print_vector_internal (CONST char *start, CONST char *end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 Lisp_Object obj,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 int len = vector_length (XVECTOR (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 int last = len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 GCPRO2 (obj, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 if (INTP (Vprint_length))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 int max = XINT (Vprint_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 if (max < len) last = max;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 write_c_string (start, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 for (i = 0; i < last; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 Lisp_Object elt = vector_data (XVECTOR (obj))[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 if (i != 0) write_char_internal (" ", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 print_internal (elt, printcharfun, escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 if (last != len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 write_c_string (" ...", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 write_c_string (end, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 default_object_printer (Lisp_Object obj, Lisp_Object printcharfun,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 struct lcrecord_header *header =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (struct lcrecord_header *) XPNTR (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 char buf[200];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 if (print_readably)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 error ("printing unreadable object #<%s 0x%x>",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 header->lheader.implementation->name, header->uid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 sprintf (buf, "#<%s 0x%x>", header->lheader.implementation->name,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 header->uid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 internal_object_printer (Lisp_Object obj, Lisp_Object printcharfun,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 char buf[200];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 sprintf (buf, "#<INTERNAL OBJECT (XEmacs bug?) (%s) 0x%x>",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 XRECORD_LHEADER (obj)->implementation->name,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (EMACS_INT) XPNTR (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 print_internal (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 char buf[256];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 /* Emacs won't print whilst GCing, but an external debugger might */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 if (gc_in_progress) return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 /* #### Both input and output streams should have a flag associated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 with them indicating whether output to that stream, or strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 read from the stream, get translated using Fgettext(). Such a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 stream is called a "translating stream". For the minibuffer and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 external-debugging-output this is always true on output, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 with-output-to-temp-buffer sets the flag to true for the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 it creates. This flag should also be user-settable. Perhaps it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 should be split up into two flags, one for input and one for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 print_depth++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 if (print_depth > 200)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 error ("Apparently circular structure being printed");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 switch (XTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 case Lisp_Int:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 sprintf (buf, "%d", XINT (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
858 case Lisp_Char:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
859 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
860 /* God intended that this be #\..., you know. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
861 Emchar ch = XCHAR (obj);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
862 write_c_string ("?", printcharfun);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
863 if (ch == '\n')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
864 strcpy (buf, "\\n");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
865 else if (ch == '\r')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
866 strcpy (buf, "\\r");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
867 else if (ch == '\t')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
868 strcpy (buf, "\\t");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
869 else if (ch < 32)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
870 sprintf (buf, "\\^%c", ch + 64);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
871 else if (ch == 127)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
872 strcpy (buf, "\\^?");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
873 else if (ch >= 128 && ch < 160)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
874 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
875 Bytecount i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
876 strcpy (buf, "\\^");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
877 i = set_charptr_emchar ((unsigned char *) (buf + 2), ch + 64);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
878 buf[2+i] = '\0';
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
879 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
880 else if (ch < 127
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
881 && !isdigit (ch)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
882 && !isalpha (ch)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
883 && ch != '^') /* must not backslash this or it will
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
884 be interpreted as the start of a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
885 control char */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
886 sprintf (buf, "\\%c", ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
887 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
888 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
889 Bytecount i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
890 i = set_charptr_emchar ((unsigned char *) buf, ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
891 buf[i] = '\0';
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
892 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
893 write_c_string (buf, printcharfun);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
894 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
895 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
896
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 case Lisp_String:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 {
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
899 Bytecount size = XSTRING_LENGTH (obj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 int max = size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 GCPRO2 (obj, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 if (INTP (Vprint_string_length) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 XINT (Vprint_string_length) < max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 max = XINT (Vprint_string_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 if (max < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 max = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 /* !!#### This handles MAX incorrectly for Mule. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 if (!escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 /* This deals with GC-relocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 output_string (printcharfun, 0, obj, 0, max);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 if (max < size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 write_c_string (" ...", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 Bytecount i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 struct Lisp_String *s = XSTRING (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 Bytecount last = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 write_char_internal ("\"", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 for (i = 0; i < max; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 Bufbyte ch = string_byte (s, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 if (ch == '\"' || ch == '\\'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 || (ch == '\n' && print_escape_newlines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 if (i > last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 output_string (printcharfun, 0, obj, last,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 i - last);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 if (ch == '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 write_c_string ("\\n", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 write_char_internal ("\\", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 /* This is correct for Mule because the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 character is either \ or " */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 write_char_internal ((char *) (string_data (s) + i),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 last = i + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 if (max > last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 output_string (printcharfun, 0, obj, last,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 max - last);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 if (max < size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 write_c_string (" ...", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 write_char_internal ("\"", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 case Lisp_Cons:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 /* If deeper than spec'd depth, print placeholder. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 if (INTP (Vprint_level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 && print_depth > XINT (Vprint_level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 write_c_string ("...", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 /* If print_readably is on, print (quote -foo-) as '-foo-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (Yeah, this should really be what print-pretty does, but we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 don't have the rest of a pretty printer, and this actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 has non-negligible impact on size/speed of .elc files.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 if (print_readably &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 EQ (XCAR (obj), Qquote) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 CONSP (XCDR (obj)) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 NILP (XCDR (XCDR (obj))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 obj = XCAR (XCDR (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 GCPRO2 (obj, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 write_char_internal ("'", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 print_internal (obj, printcharfun, escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 GCPRO2 (obj, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 write_char_internal ("(", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 int i = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 int max = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 if (INTP (Vprint_length))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 max = XINT (Vprint_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 while (CONSP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 if (i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 write_char_internal (" ", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 if (max && i > max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 write_c_string ("...", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 print_internal (Fcar (obj), printcharfun,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 obj = Fcdr (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 if (!NILP (obj) && !CONSP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 write_c_string (" . ", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 print_internal (obj, printcharfun, escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 write_char_internal (")", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 #ifndef LRECORD_VECTOR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 case Lisp_Vector:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 /* If deeper than spec'd depth, print placeholder. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 if (INTP (Vprint_level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 && print_depth > XINT (Vprint_level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 write_c_string ("...", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 /* God intended that this be #(...), you know. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 print_vector_internal ("[", "]", obj, printcharfun, escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 #endif /* !LRECORD_VECTOR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 #ifndef LRECORD_SYMBOL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 case Lisp_Symbol:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 print_symbol (obj, printcharfun, escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 #endif /* !LRECORD_SYMBOL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 case Lisp_Record:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 GCPRO2 (obj, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 if (lheader->implementation->printer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 ((lheader->implementation->printer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (obj, printcharfun, escapeflag));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 default_object_printer (obj, printcharfun, escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 /* We're in trouble if this happens!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 Probably should just abort () */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 if (print_readably)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 error ("printing illegal data type #o%03o",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (int) XTYPE (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 write_c_string ("#<EMACS BUG: ILLEGAL DATATYPE ",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 sprintf (buf, "(#o%3o)", (int) XTYPE (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 write_c_string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (" Save your buffers immediately and please report this bug>",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 print_depth--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 print_compiled_function_internal (CONST char *start, CONST char *end,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 Lisp_Object obj,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 struct Lisp_Compiled_Function *b =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 XCOMPILED_FUNCTION (obj); /* GC doesn't relocate */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 int docp = b->flags.documentationp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 int intp = b->flags.interactivep;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 char buf[100];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 GCPRO2 (obj, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 write_c_string (start, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 if (!print_readably)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 Lisp_Object ann = compiled_function_annotation (b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 if (!NILP (ann))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 write_c_string ("(from ", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 print_internal (ann, printcharfun, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 write_c_string (") ", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 /* COMPILED_ARGLIST = 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 print_internal (b->arglist, printcharfun, escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 /* COMPILED_BYTECODE = 1 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 write_char_internal (" ", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 /* we don't really want to see that junk in the bytecode instructions. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 if (STRINGP (b->bytecodes) && !print_readably)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 {
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
1121 sprintf (buf, "\"...(%ld)\"", (long) XSTRING_LENGTH (b->bytecodes));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 print_internal (b->bytecodes, printcharfun, escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 /* COMPILED_CONSTANTS = 2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 write_char_internal (" ", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 print_internal (b->constants, printcharfun, escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 /* COMPILED_STACK_DEPTH = 3 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 sprintf (buf, " %d", b->maxdepth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 /* COMPILED_DOC_STRING = 4 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 if (docp || intp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 write_char_internal (" ", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 print_internal (compiled_function_documentation (b), printcharfun,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 /* COMPILED_INTERACTIVE = 5 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 if (intp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 write_char_internal (" ", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 print_internal (compiled_function_interactive (b), printcharfun,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 write_c_string (end, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 print_compiled_function (Lisp_Object obj, Lisp_Object printcharfun,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 print_compiled_function_internal (((print_readably) ? "#[" :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 "#<compiled-function "),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 ((print_readably) ? "]" : ">"),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 obj, printcharfun, escapeflag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 print_float (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 char pigbuf[350]; /* see comments in float_to_string */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 float_to_string (pigbuf, float_data (XFLOAT (obj)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 write_c_string (pigbuf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 print_symbol (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 /* #### Bug!! (intern "") isn't printed in some distinguished way */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 /* #### (the reader also loses on it) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 struct Lisp_String *name = XSYMBOL (obj)->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 Bytecount size = string_length (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 if (!escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 /* This deals with GC-relocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 Lisp_Object nameobj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 XSETSTRING (nameobj, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 output_string (printcharfun, 0, nameobj, 0, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 GCPRO2 (obj, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 if (print_gensym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 Lisp_Object tem = oblookup (Vobarray, string_data (name), size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 if (!EQ (tem, obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 /* (read) would return a new symbol with the same name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 This isn't quite correct, because that symbol might not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 really be uninterned (it might be interned in some other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 obarray) but there's no way to win in that case without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 implementing a real package system.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 write_c_string ("#:", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 /* Does it look like an integer or a float? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 Bufbyte *data = string_data (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 Bytecount confusing = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 if (size == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 goto not_yet_confused; /* Really confusing */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 else if (isdigit (data[0]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 confusing = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 else if (size == 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 goto not_yet_confused;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 else if (data[0] == '-' || data[0] == '+')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 confusing = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 goto not_yet_confused;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 for (; confusing < size; confusing++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 if (!isdigit (data[confusing]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 confusing = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 not_yet_confused:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 if (!confusing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 confusing = isfloat_string ((char *) data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 if (confusing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 write_char_internal ("\\", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 Lisp_Object nameobj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 Bytecount i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 Bytecount last = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 XSETSTRING (nameobj, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 for (i = 0; i < size; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 Bufbyte c = string_byte (name, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 if (c == '\"' || c == '\\' || c == '\'' || c == ';' || c == '#' ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 c == '(' || c == ')' || c == ',' || c =='.' || c == '`' ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 c == '[' || c == ']' || c == '?' || c <= 040)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 if (i > last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 output_string (printcharfun, 0, nameobj, last,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 i - last);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 write_char_internal ("\\", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 last = i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 output_string (printcharfun, 0, nameobj, last, size - last);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 int alternate_do_pointer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 char alternate_do_string[5000];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1271 DEFUN ("alternate-debugging-output", Falternate_debugging_output, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 Append CHARACTER to the array `alternate_do_string'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 This can be used in place of `external-debugging-output' as a function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 to be passed to `print'. Before calling `print', set `alternate_do_pointer'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 to 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1277 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1278 (character))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 Bufbyte str[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 int extlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 CONST Extbyte *extptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 CHECK_CHAR_COERCE_INT (character);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 len = set_charptr_emchar (str, XCHAR (character));
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
1287 GET_CHARPTR_EXT_DATA_ALLOCA (str, len, FORMAT_TERMINAL, extptr, extlen);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 memcpy (alternate_do_string + alternate_do_pointer, extptr, extlen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 alternate_do_pointer += extlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 alternate_do_string[alternate_do_pointer] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 return character;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1294 DEFUN ("external-debugging-output", Fexternal_debugging_output, 1, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 Write CHAR-OR-STRING to stderr or stdout.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 If optional arg STDOUT-P is non-nil, write to stdout; otherwise, write
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 to stderr. You can use this function to write directly to the terminal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 This function can be used as the STREAM argument of Fprint() or the like.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 If you have opened a termscript file (using `open-termscript'), then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 the output also will be logged to this file.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1302 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1303 (char_or_string, stdout_p, device))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 FILE *file = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 struct console *con = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 if (NILP (device))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 if (!NILP (stdout_p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 file = stdout;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 file = stderr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 CHECK_LIVE_DEVICE (device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 if (!DEVICE_TTY_P (XDEVICE (device)) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 !DEVICE_STREAM_P (XDEVICE (device)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 signal_simple_error ("Must be tty or stream device", device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 con = XCONSOLE (DEVICE_CONSOLE (XDEVICE (device)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 if (DEVICE_TTY_P (XDEVICE (device)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 file = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 else if (!NILP (stdout_p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 file = CONSOLE_STREAM_DATA (con)->outfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 file = CONSOLE_STREAM_DATA (con)->errfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 if (STRINGP (char_or_string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 write_string_to_stdio_stream (file, con,
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
1332 XSTRING_DATA (char_or_string),
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
1333 0, XSTRING_LENGTH (char_or_string),
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
1334 FORMAT_TERMINAL);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 Bufbyte str[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 CHECK_CHAR_COERCE_INT (char_or_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 len = set_charptr_emchar (str, XCHAR (char_or_string));
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
1342 write_string_to_stdio_stream (file, con, str, 0, len, FORMAT_TERMINAL);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 return char_or_string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1348 DEFUN ("open-termscript", Fopen_termscript, 1, 1, "FOpen termscript file: ", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 Start writing all terminal output to FILE as well as the terminal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 FILE = nil means just close any termscript file currently open.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1351 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1352 (file))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 if (termscript != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 fclose (termscript);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 termscript = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 if (! NILP (file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 file = Fexpand_file_name (file, Qnil);
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
1362 termscript = fopen ((char *) XSTRING_DATA (file), "w");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 if (termscript == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 report_file_error ("Opening termscript", Fcons (file, Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 #if 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 /* Debugging kludge -- unbuffered */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 static int debug_print_length = 50;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 static int debug_print_level = 15;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 Lisp_Object debug_temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 void debug_print_no_newline (Lisp_Object debug_print_obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 debug_print_no_newline (Lisp_Object debug_print_obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 int old_print_readably = print_readably;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 int old_print_depth = print_depth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 Lisp_Object old_print_length = Vprint_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 Lisp_Object old_print_level = Vprint_level;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 Lisp_Object old_inhibit_quit = Vinhibit_quit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 GCPRO3 (old_print_level, old_print_length, old_inhibit_quit);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 if (gc_in_progress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 stderr_out ("** gc-in-progress! Bad idea to print anything! **\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 print_depth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 print_readably = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 print_unbuffered++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 /* Could use unwind-protect, but why bother? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 if (debug_print_length > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 Vprint_length = make_int (debug_print_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 if (debug_print_level > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 Vprint_level = make_int (debug_print_level);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 print_internal (debug_print_obj, Qexternal_debugging_output, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 Vinhibit_quit = old_inhibit_quit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 Vprint_level = old_print_level;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 Vprint_length = old_print_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 print_depth = old_print_depth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 print_readably = old_print_readably;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 print_unbuffered--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 void debug_print (Lisp_Object debug_print_obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 debug_print (Lisp_Object debug_print_obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 debug_print_no_newline (debug_print_obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 stderr_out ("\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 fflush (stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 /* Debugging kludge -- unbuffered */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 debug_backtrace (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 int old_print_readably = print_readably;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 int old_print_depth = print_depth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 Lisp_Object old_print_length = Vprint_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 Lisp_Object old_print_level = Vprint_level;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 Lisp_Object old_inhibit_quit = Vinhibit_quit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 GCPRO3 (old_print_level, old_print_length, old_inhibit_quit);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 if (gc_in_progress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 stderr_out ("** gc-in-progress! Bad idea to print anything! **\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 print_depth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 print_readably = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 print_unbuffered++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 /* Could use unwind-protect, but why bother? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 if (debug_print_length > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 Vprint_length = make_int (debug_print_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 if (debug_print_level > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 Vprint_level = make_int (debug_print_level);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 Fbacktrace (Qexternal_debugging_output, Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 stderr_out ("\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 fflush (stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 Vinhibit_quit = old_inhibit_quit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 Vprint_level = old_print_level;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 Vprint_length = old_print_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 print_depth = old_print_depth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 print_readably = old_print_readably;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 print_unbuffered--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 debug_short_backtrace (int length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 int first = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 struct backtrace *bt = backtrace_list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 stderr_out (" [");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 fflush (stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 while (length > 0 && bt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 if (!first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 stderr_out (", ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 fflush (stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 if (COMPILED_FUNCTIONP (*bt->function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 Lisp_Object ann = Fcompiled_function_annotation (*bt->function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 if (!NILP (ann))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 stderr_out ("<compiled-function from ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 fflush (stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 debug_print_no_newline (ann);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 stderr_out (">");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 fflush (stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 stderr_out ("<compiled-function of unknown origin>");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 fflush (stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 debug_print_no_newline (*bt->function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 first = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 length--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 bt = bt->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 stderr_out ("]\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 fflush (stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 #endif /* debugging kludge */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 syms_of_print (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 defsymbol (&Qprint_escape_newlines, "print-escape-newlines");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 defsymbol (&Qprint_readably, "print-readably");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 defsymbol (&Qstandard_output, "standard-output");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 defsymbol (&Qfloat_output_format, "float-output-format");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 defsymbol (&Qprint_length, "print-length");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 defsymbol (&Qprint_string_length, "print-string-length");
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1512 DEFSUBR (Fprin1);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1513 DEFSUBR (Fprin1_to_string);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1514 DEFSUBR (Fprinc);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1515 DEFSUBR (Fprint);
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 70
diff changeset
1516 DEFSUBR (Ferror_message_string);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1517 DEFSUBR (Fterpri);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1518 DEFSUBR (Fwrite_char);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1519 DEFSUBR (Falternate_debugging_output);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 defsymbol (&Qalternate_debugging_output, "alternate-debugging-output");
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1521 DEFSUBR (Fexternal_debugging_output);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1522 DEFSUBR (Fopen_termscript);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 defsymbol (&Qexternal_debugging_output, "external-debugging-output");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 #ifndef standalone
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1525 DEFSUBR (Fwith_output_to_temp_buffer);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 #endif /* not standalone */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 lstream_type_create_print (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 LSTREAM_HAS_METHOD (print, writer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 LSTREAM_HAS_METHOD (print, marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 vars_of_print (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 alternate_do_pointer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 DEFVAR_LISP ("standard-output", &Vstandard_output /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 Output stream `print' uses by default for outputting a character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 This may be any function of one argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 It may also be a buffer (output is inserted before point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 or a marker (output is inserted and the marker is advanced)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 or the symbol t (output appears in the minibuffer line).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 Vstandard_output = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 DEFVAR_LISP ("float-output-format", &Vfloat_output_format /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 The format descriptor string that lisp uses to print floats.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 This is a %-spec like those accepted by `printf' in C,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 but with some restrictions. It must start with the two characters `%.'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 After that comes an integer precision specification,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 and then a letter which controls the format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 The letters allowed are `e', `f' and `g'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 Use `e' for exponential notation \"DIG.DIGITSeEXPT\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 Use `f' for decimal point notation \"DIGITS.DIGITS\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 Use `g' to choose the shorter of those two formats for the number at hand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 The precision in any of these cases is the number of digits following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 the decimal point. With `f', a precision of 0 means to omit the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 decimal point. 0 is not allowed with `f' or `g'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 A value of nil means to use `%.16g'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 Regardless of the value of `float-output-format', a floating point number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 will never be printed in such a way that it is ambiguous with an integer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 that is, a floating-point number will always be printed with a decimal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 point and/or an exponent, even if the digits following the decimal point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 are all zero. This is to preserve read-equivalence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 Vfloat_output_format = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 DEFVAR_LISP ("print-length", &Vprint_length /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 Maximum length of list or vector to print before abbreviating.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 A value of nil means no limit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 Vprint_length = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 DEFVAR_LISP ("print-string-length", &Vprint_string_length /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 Maximum length of string to print before abbreviating.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 A value of nil means no limit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 Vprint_string_length = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 DEFVAR_LISP ("print-level", &Vprint_level /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 Maximum depth of list nesting to print before abbreviating.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 A value of nil means no limit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 Vprint_level = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 Non-nil means print newlines in strings as backslash-n.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 print_escape_newlines = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 DEFVAR_BOOL ("print-readably", &print_readably /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 If non-nil, then all objects will be printed in a readable form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 If an object has no readable representation, then an error is signalled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 When print-readably is true, compiled-function objects will be written in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 #[...] form instead of in #<compiled-function [...]> form, and two-element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 lists of the form (quote object) will be written as the equivalent 'object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 Do not SET this variable; bind it instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 print_readably = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 DEFVAR_BOOL ("print-gensym", &print_gensym /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 If non-nil, then uninterned symbols will be printed specially.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 Uninterned symbols are those which are not present in `obarray', that is,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 those which were made with `make-symbol' or by calling `intern' with a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 second argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 102
diff changeset
1615 When print-gensym is true, such symbols will be preceded by \"#:\", which
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 causes the reader to create a new symbol instead of interning and returning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 an existing one. Beware: the #: syntax creates a new symbol each time it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 seen, so if you print an object which contains two pointers to the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 uninterned symbol, `read' will not duplicate that structure.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 Also, since XEmacs has no real notion of packages, there is no way for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 printer to distinguish between symbols interned in no obarray, and symbols
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 interned in an alternate obarray.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 print_gensym = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 DEFVAR_LISP ("print-message-label", &Vprint_message_label /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 Label for minibuffer messages created with `print'. This should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 generally be bound with `let' rather than set. (See `display-message'.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 Vprint_message_label = Qprint;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 staticpro (&Vprin1_to_string_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 }