annotate src/doprnt.c @ 203:850242ba4a81 r20-3b28

Import from CVS: tag r20-3b28
author cvs
date Mon, 13 Aug 2007 10:02:21 +0200
parents b405438285a2
children 92f8ad5d0d3f
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 /* Output like sprintf to a buffer of specified size.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Also takes args differently: pass one pointer to an array of strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 in addition to the format string which is separate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 Copyright (C) 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 Rewritten by mly to use varargs.h.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 Rewritten from scratch by Ben Wing (February 1995) for Mule; expanded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 to full printf spec.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 /* Synched up with: Rewritten. Not in FSF. */
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 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include "lstream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 static CONST char *valid_flags = "-+ #0";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 static CONST char *valid_converters = "diouxXfeEgGcsS";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 static CONST char *int_converters = "dic";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 static CONST char *unsigned_int_converters = "ouxX";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 static CONST char *double_converters = "feEgG";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 static CONST char *string_converters = "sS";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
42 typedef struct printf_spec printf_spec;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 struct printf_spec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 int argnum; /* which argument does this spec want? This is one-based:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 The first argument given is numbered 1, the second
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 is 2, etc. This is to handle %##$x-type specs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 int minwidth;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 int precision;
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
50 unsigned int minus_flag:1;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
51 unsigned int plus_flag:1;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
52 unsigned int space_flag:1;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
53 unsigned int number_flag:1;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
54 unsigned int zero_flag:1;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
55 unsigned int h_flag:1;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
56 unsigned int l_flag:1;
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
57 unsigned int forwarding_precision:1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 char converter; /* converter character or 0 for dummy marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 indicating literal text at the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 specification */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 Bytecount text_before; /* position of the first character of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 block of literal text before this spec */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 Bytecount text_before_len; /* length of that text */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
66 typedef union printf_arg printf_arg;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 union printf_arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 unsigned int ui;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 long l;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 unsigned long ul;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 double d;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 Bufbyte *bp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 /* We maintain a list of all the % specs in the specification,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 along with the offset and length of the block of literal text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 before each spec. In addition, we have a "dummy" spec that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 represents all the literal text at the end of the specification.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 Its converter is 0. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 typedef struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 Dynarr_declare (struct printf_spec);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 } printf_spec_dynarr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 typedef struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 Dynarr_declare (union printf_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 } printf_arg_dynarr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 /* Append STRING (of length LEN) to STREAM. MINLEN is the minimum field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 width. If MINUS_FLAG is set, left-justify the string in its field;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 otherwise, right-justify. If ZERO_FLAG is set, pad with 0's; otherwise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 pad with spaces. If MAXLEN is non-negative, the string is first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 truncated to that many character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 Note that MINLEN and MAXLEN are Charcounts but LEN is a Bytecount. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 doprnt_1 (Lisp_Object stream, CONST Bufbyte *string, Bytecount len,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 Charcount minlen, Charcount maxlen, int minus_flag, int zero_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 Charcount cclen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 Bufbyte pad;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 Lstream *lstr = XLSTREAM (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 cclen = bytecount_to_charcount (string, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 if (zero_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 pad = '0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 pad = ' ';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 /* Padding at beginning to right-justify ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 if (minlen > cclen && !minus_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 int to_add = minlen - cclen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 while (to_add > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 Lstream_putc (lstr, pad);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 to_add--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
126
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 if (maxlen >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 len = charcount_to_bytecount (string, min (maxlen, cclen));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Lstream_write (lstr, string, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 /* Padding at end to left-justify ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 if (minlen > cclen && minus_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 int to_add = minlen - cclen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 while (to_add > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 Lstream_putc (lstr, pad);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 to_add--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 static CONST Bufbyte *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 parse_off_posnum (CONST Bufbyte *start, CONST Bufbyte *end, int *returned_num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 Bufbyte arg_convert[100];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 REGISTER Bufbyte *arg_ptr = arg_convert;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
148
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 *returned_num = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 while (start != end && isdigit (*start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 if (arg_ptr - arg_convert >= sizeof (arg_convert) - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 error ("Format converter number too large");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 *arg_ptr++ = *start++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 *arg_ptr = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 if (arg_convert != arg_ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 *returned_num = atoi ((char *) arg_convert);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 return start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 #define NEXT_ASCII_BYTE(ch) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 if (fmt == fmt_end) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 error ("Premature end of format string"); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ch = *fmt; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 if (ch >= 0200) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 error ("Non-ASCII character in format converter spec"); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 fmt++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
172 #define RESOLVE_FLAG_CONFLICTS(spec) \
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
173 do { \
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
174 if (spec.space_flag && spec.plus_flag) \
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
175 spec.space_flag = 0; \
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
176 if (spec.zero_flag && spec.space_flag) \
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
177 spec.zero_flag = 0; \
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
178 } while (0)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
179
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 static printf_spec_dynarr *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 parse_doprnt_spec (CONST Bufbyte *format, Bytecount format_length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 CONST Bufbyte *fmt = format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 CONST Bufbyte *fmt_end = format + format_length;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
185 printf_spec_dynarr *specs = Dynarr_new (printf_spec);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 int prev_argnum = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 struct printf_spec spec;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 CONST Bufbyte *text_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 Bufbyte ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 memset (&spec, 0, sizeof (spec));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 if (fmt == fmt_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 return specs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 text_end = (Bufbyte *) memchr (fmt, '%', fmt_end - fmt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 if (!text_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 text_end = fmt_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 spec.text_before = fmt - format;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 spec.text_before_len = text_end - fmt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 fmt = text_end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 if (fmt != fmt_end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 fmt++; /* skip over % */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 /* A % is special -- no arg number. According to ANSI specs,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 field width does not apply to %% conversion. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 if (fmt != fmt_end && *fmt == '%')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 spec.converter = '%';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 Dynarr_add (specs, spec);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 fmt++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 /* Is there a field number specifier? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 CONST Bufbyte *ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 int fieldspec;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ptr = parse_off_posnum (fmt, fmt_end, &fieldspec);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 if (fieldspec > 0 && ptr != fmt_end && *ptr == '$')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 /* There is a format specifier */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 prev_argnum = fieldspec;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 fmt = ptr + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 prev_argnum++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 spec.argnum = prev_argnum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 /* Parse off any flags */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 NEXT_ASCII_BYTE (ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 while (strchr (valid_flags, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 switch (ch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 case '-': spec.minus_flag = 1; break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 case '+': spec.plus_flag = 1; break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 case ' ': spec.space_flag = 1; break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 case '#': spec.number_flag = 1; break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 case '0': spec.zero_flag = 1; break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 default: abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 NEXT_ASCII_BYTE (ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
249
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 /* Parse off the minimum field width */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 fmt--; /* back up */
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
252
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
253 /*
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
254 * * means the field width was passed as an argument.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
255 * Mark the current spec as one that forwards its
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
256 * field width and flags to the next spec in the array.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
257 * Then create a new spec and continue with the parsing.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
258 */
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
259 if (fmt != fmt_end && *fmt == '*')
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
260 {
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
261 spec.converter = '*';
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
262 RESOLVE_FLAG_CONFLICTS(spec);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
263 Dynarr_add (specs, spec);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
264 memset (&spec, 0, sizeof (spec));
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
265 spec.argnum = ++prev_argnum;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
266 fmt++;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
267 }
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
268 else
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
269 {
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
270 fmt = parse_off_posnum (fmt, fmt_end, &spec.minwidth);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
271 if (spec.minwidth == -1)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
272 spec.minwidth = 0;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
273 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 /* Parse off any precision specified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 NEXT_ASCII_BYTE (ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 if (ch == '.')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 {
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
279 /*
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
280 * * means the precision was passed as an argument.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
281 * Mark the current spec as one that forwards its
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
282 * fieldwidth, flags and precision to the next spec in
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
283 * the array. Then create a new spec and continue
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
284 * with the parse.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
285 */
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
286 if (fmt != fmt_end && *fmt == '*')
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
287 {
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
288 spec.converter = '*';
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
289 spec.forwarding_precision = 1;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
290 RESOLVE_FLAG_CONFLICTS(spec);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
291 Dynarr_add (specs, spec);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
292 memset (&spec, 0, sizeof (spec));
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
293 spec.argnum = ++prev_argnum;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
294 fmt++;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
295 }
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
296 else
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
297 {
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
298 fmt = parse_off_posnum (fmt, fmt_end, &spec.precision);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
299 if (spec.precision == -1)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
300 spec.precision = 0;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
301 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 NEXT_ASCII_BYTE (ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 /* No precision specified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 spec.precision = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 /* Parse off h or l flag */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 if (ch == 'h' || ch == 'l')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 if (ch == 'h')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 spec.h_flag = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 spec.l_flag = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 NEXT_ASCII_BYTE (ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 if (!strchr (valid_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 error ("Invalid converter character %c", ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 spec.converter = ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
323 RESOLVE_FLAG_CONFLICTS(spec);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 Dynarr_add (specs, spec);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 RETURN_NOT_REACHED(specs) /* suppress compiler warning */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 get_args_needed (printf_spec_dynarr *specs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 int args_needed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 REGISTER int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 /* Figure out how many args are needed. This may be less than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 the number of specs because a spec could be %% or could be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 missing (literal text at end of format string) or there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 could be specs where the field number is explicitly given.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 We just look for the maximum argument number that's referenced. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 for (i = 0; i < Dynarr_length (specs); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 char ch = Dynarr_at (specs, i).converter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 if (ch && ch != '%')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 int argnum = Dynarr_at (specs, i).argnum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 if (argnum > args_needed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 args_needed = argnum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 return args_needed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 static printf_arg_dynarr *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 get_doprnt_args (printf_spec_dynarr *specs, va_list vargs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
359 printf_arg_dynarr *args = Dynarr_new (printf_arg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 union printf_arg arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 REGISTER int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 int args_needed = get_args_needed (specs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 memset (&arg, 0, sizeof (union printf_arg));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 for (i = 1; i <= args_needed; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 int j;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 char ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 struct printf_spec *spec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 for (j = 0; j < Dynarr_length (specs); j++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 spec = Dynarr_atp (specs, j);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 if (spec->argnum == i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 if (j == Dynarr_length (specs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 error ("No conversion spec for argument %d", i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 ch = spec->converter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 /* int even if ch == 'c': "the type used in va_arg is supposed to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 match the actual type **after default promotions**." */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 if (strchr (int_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 if (spec->h_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 arg.i = va_arg (vargs, short);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 else if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 arg.l = va_arg (vargs, long);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 arg.i = va_arg (vargs, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 else if (strchr (unsigned_int_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 if (spec->h_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 arg.ui = va_arg (vargs, unsigned short);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 else if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 arg.ul = va_arg (vargs, unsigned long);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 arg.ui = va_arg (vargs, unsigned int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 else if (strchr (double_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 arg.d = va_arg (vargs, double);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 else if (strchr (string_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 arg.bp = va_arg (vargs, Bufbyte *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 else abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 Dynarr_add (args, arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 return args;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 /* Generate output from a format-spec FORMAT, of length FORMAT_LENGTH.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 Output goes in BUFFER, which has room for BUFSIZE bytes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 If the output does not fit, truncate it to fit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 Returns the number of bytes stored into BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 LARGS or VARGS points to the arguments, and NARGS says how many.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 if LARGS is non-zero, it should be a pointer to NARGS worth of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 Lisp arguments. Otherwise, VARGS should be a va_list referring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 to the arguments. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 static Bytecount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 emacs_doprnt_1 (Lisp_Object stream, CONST Bufbyte *format_nonreloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 Lisp_Object format_reloc, Bytecount format_length,
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
428 int nargs,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 /* #### Gag me, gag me, gag me */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 CONST Lisp_Object *largs, va_list vargs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 printf_spec_dynarr *specs = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 printf_arg_dynarr *args = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 REGISTER int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 int init_byte_count = Lstream_byte_count (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 if (!NILP (format_reloc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 {
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
439 format_nonreloc = XSTRING_DATA (format_reloc);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
440 format_length = XSTRING_LENGTH (format_reloc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 if (format_length < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 format_length = (Bytecount) strlen ((CONST char *) format_nonreloc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 specs = parse_doprnt_spec (format_nonreloc, format_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 if (largs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 /* allow too many args for string, but not too few */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 if (nargs < get_args_needed (specs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 signal_error (Qwrong_number_of_arguments,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 list3 (Qformat,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 make_int (nargs),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 !NILP (format_reloc) ? format_reloc :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 make_string (format_nonreloc, format_length)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 args = get_doprnt_args (specs, vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 for (i = 0; i < Dynarr_length (specs); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 struct printf_spec *spec = Dynarr_atp (specs, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 char ch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 /* Copy the text before */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 if (!NILP (format_reloc)) /* refetch in case of GC below */
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
468 format_nonreloc = XSTRING_DATA (format_reloc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 doprnt_1 (stream, format_nonreloc + spec->text_before,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 spec->text_before_len, 0, -1, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ch = spec->converter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 if (!ch)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 if (ch == '%')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 doprnt_1 (stream, (Bufbyte *) &ch, 1, 0, -1, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
483 /*
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
484 * * as converter means the field width, precision was specified
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
485 * as an argument. Extract the data and forward it to the
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
486 * next spec, to which it will apply.
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
487 */
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
488 if (ch == '*')
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
489 {
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
490 struct printf_spec *nextspec = Dynarr_atp (specs, i + 1);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
491 Lisp_Object obj = largs[spec->argnum - 1];
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
492
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
493 if (INTP (obj))
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
494 {
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
495 if (spec->forwarding_precision)
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
496 {
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
497 nextspec->precision = XINT (obj);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
498 nextspec->minwidth = spec->minwidth;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
499 }
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
500 else
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
501 {
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
502 nextspec->minwidth = XINT (obj);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
503 }
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
504 nextspec->minus_flag = spec->minus_flag;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
505 nextspec->plus_flag = spec->plus_flag;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
506 nextspec->space_flag = spec->space_flag;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
507 nextspec->number_flag = spec->number_flag;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
508 nextspec->zero_flag = spec->zero_flag;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
509 }
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
510 continue;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
511 }
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
512
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 if (largs && (spec->argnum < 1 || spec->argnum > nargs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 error ("Invalid repositioning argument %d", spec->argnum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 else if (ch == 'S' || ch == 's')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 Bufbyte *string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 Bytecount string_len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 if (!largs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 string = Dynarr_at (args, spec->argnum - 1).bp;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
524 /* error() can be called with null string arguments.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
525 E.g., in fileio.c, the return value of strerror()
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
526 is never checked. We'll print (null), like some
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
527 printf implementations do. Would it be better (and safe)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
528 to signal an error instead? Or should we just use the
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
529 empty string? -dkindred@cs.cmu.edu 8/1997
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
530 */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
531 if (!string)
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
532 string = (Bufbyte *) "(null)";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 string_len = strlen ((char *) string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 Lisp_Object obj = largs[spec->argnum - 1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 struct Lisp_String *ls;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 if (ch == 'S')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 /* For `S', prin1 the argument and then treat like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 a string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ls = XSTRING (Fprin1_to_string (obj, Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 else if (STRINGP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ls = XSTRING (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 else if (SYMBOLP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ls = XSYMBOL (obj)->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 /* convert to string using princ. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ls = XSTRING (Fprin1_to_string (obj, Qt));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 string = string_data (ls);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 string_len = string_length (ls);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 doprnt_1 (stream, string, string_len, spec->minwidth,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 spec->precision, spec->minus_flag, spec->zero_flag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 /* Must be a number. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 union printf_arg arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 if (!largs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 arg = Dynarr_at (args, spec->argnum - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 Lisp_Object obj = largs[spec->argnum - 1];
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 58
diff changeset
575 if (CHARP (obj))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 58
diff changeset
576 CHECK_INT_COERCE_CHAR (obj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 if (!INT_OR_FLOATP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 error ("format specifier %%%c doesn't match argument type",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 else if (strchr (double_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 arg.d = XFLOATINT (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 int val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 if (FLOATP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 val = XINT (Ftruncate (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 val = XINT (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 if (strchr (unsigned_int_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 arg.ul = (unsigned long) val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 arg.ui = (unsigned int) val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 arg.l = (long) val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 arg.i = val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 if (ch == 'c')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 Emchar a;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 Bytecount charlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 Bufbyte charbuf[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 a = (Emchar) arg.l;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 a = (Emchar) arg.i;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
620
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 if (!valid_char_p (a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 error ("invalid character value %d to %%c spec", a);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 charlen = set_charptr_emchar (charbuf, a);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 doprnt_1 (stream, charbuf, charlen, spec->minwidth,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 -1, spec->minus_flag, spec->zero_flag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 char text_to_print[500];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 char constructed_spec[100];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 /* Partially reconstruct the spec and use sprintf() to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 format the string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 /* Make sure nothing stupid happens */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 /* DO NOT REMOVE THE (int) CAST! Incorrect results will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 follow! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 spec->precision = min (spec->precision,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (int) (sizeof (text_to_print) - 50));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 constructed_spec[0] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 strcat (constructed_spec, "%");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 if (spec->plus_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 strcat (constructed_spec, "+");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 if (spec->space_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 strcat (constructed_spec, " ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 if (spec->number_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 strcat (constructed_spec, "#");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 if (spec->precision >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 strcat (constructed_spec, ".");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 sprintf (constructed_spec + strlen (constructed_spec), "%d",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 spec->precision);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 sprintf (constructed_spec + strlen (constructed_spec), "%c", ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 /* sprintf the mofo */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 /* we have to use separate calls to sprintf(), rather than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 a single big conditional, because of the different types
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 of the arguments */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 if (strchr (double_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 sprintf (text_to_print, constructed_spec, arg.d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 else if (strchr (unsigned_int_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 sprintf (text_to_print, constructed_spec, arg.ul);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 sprintf (text_to_print, constructed_spec, arg.ui);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 sprintf (text_to_print, constructed_spec, arg.l);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 sprintf (text_to_print, constructed_spec, arg.i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 doprnt_1 (stream, (Bufbyte *) text_to_print,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 strlen (text_to_print),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 spec->minwidth, -1, spec->minus_flag, spec->zero_flag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 /* #### will not get freed if error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 if (specs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 Dynarr_free (specs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 if (args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 Dynarr_free (args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 return Lstream_byte_count (XLSTREAM (stream)) - init_byte_count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 /* You really don't want to know why this is necessary... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 static Bytecount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 emacs_doprnt_2 (Lisp_Object stream, CONST Bufbyte *format_nonreloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 Lisp_Object format_reloc, Bytecount format_length, int nargs,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 CONST Lisp_Object *largs, ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 va_list vargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 Bytecount val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 va_start (vargs, largs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 val = emacs_doprnt_1 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 format_length, nargs, largs, vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 va_end (vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 /*********************** external entry points ***********************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 /* A note about I18N3 translating: the format string should get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 translated, but not under all circumstances. When the format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 string is a Lisp string, what should happen is that Fformat()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 should format the untranslated args[0] and return that, and also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 call Fgettext() on args[0] and, if that is different, format it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 and store it in the `string-translatable' property of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 the returned string. See Fgettext(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 /* Send formatted output to STREAM. The format string comes from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 either FORMAT_NONRELOC (of length FORMAT_LENGTH; -1 means use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 strlen() to determine the length) or from FORMAT_RELOC, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 should be a Lisp string. Return the number of bytes written
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 to the stream.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 DO NOT pass the data from a Lisp string as the FORMAT_NONRELOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 parameter, because this function can cause GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 Bytecount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 emacs_doprnt_c (Lisp_Object stream, CONST Bufbyte *format_nonreloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 Lisp_Object format_reloc, Bytecount format_length,
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 int val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 va_list vargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 va_start (vargs, format_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 val = emacs_doprnt_1 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 format_length, 0, 0, vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 va_end (vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 /* Like emacs_doprnt_c but the args come in va_list format. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 Bytecount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 emacs_doprnt_va (Lisp_Object stream, CONST Bufbyte *format_nonreloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 va_list vargs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 return emacs_doprnt_1 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 format_length, 0, 0, vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 /* Like emacs_doprnt_c but the args are Lisp objects instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 C arguments. This causes somewhat different behavior from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 the above two functions (which should act like printf).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 See `format' for a description of this behavior. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 Bytecount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 emacs_doprnt_lisp (Lisp_Object stream, CONST Bufbyte *format_nonreloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 int nargs, CONST Lisp_Object *largs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 return emacs_doprnt_2 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 format_length, nargs, largs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 /* Like the previous function but takes a variable number of arguments. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 Bytecount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 emacs_doprnt_lisp_2 (Lisp_Object stream, CONST Bufbyte *format_nonreloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 int nargs, ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 va_list vargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 int i;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
780 Lisp_Object *foo = alloca_array (Lisp_Object, nargs);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 va_start (vargs, nargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 for (i = 0; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 foo[i] = va_arg (vargs, Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 va_end (vargs);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
786
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 return emacs_doprnt_2 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 format_length, nargs, foo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 /* The following four functions work like the above three but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 return their output as a Lisp string instead of sending it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 to a stream. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 emacs_doprnt_string_c (CONST Bufbyte *format_nonreloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 va_list vargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 Lisp_Object stream = make_resizing_buffer_output_stream ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 GCPRO1 (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 va_start (vargs, format_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 emacs_doprnt_1 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 format_length, 0, 0, vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 va_end (vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 Lstream_flush (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 obj = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 Lstream_byte_count (XLSTREAM (stream)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 Lstream_delete (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 emacs_doprnt_string_va (CONST Bufbyte *format_nonreloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 va_list vargs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 /* I'm fairly sure that this function cannot actually GC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 That can only happen when the arguments to emacs_doprnt_1() are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 Lisp objects rather than C args. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 Lisp_Object stream = make_resizing_buffer_output_stream ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 GCPRO1 (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 emacs_doprnt_1 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 format_length, 0, 0, vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 Lstream_flush (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 obj = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 Lstream_byte_count (XLSTREAM (stream)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 Lstream_delete (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 emacs_doprnt_string_lisp (CONST Bufbyte *format_nonreloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 int nargs, CONST Lisp_Object *largs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 Lisp_Object stream = make_resizing_buffer_output_stream ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 GCPRO1 (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 emacs_doprnt_2 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 format_length, nargs, largs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 Lstream_flush (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 obj = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 Lstream_byte_count (XLSTREAM (stream)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 Lstream_delete (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 emacs_doprnt_string_lisp_2 (CONST Bufbyte *format_nonreloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 int nargs, ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 Lisp_Object stream = make_resizing_buffer_output_stream ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 va_list vargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 int i;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
871 Lisp_Object *foo = alloca_array (Lisp_Object, nargs);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 va_start (vargs, nargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 for (i = 0; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 foo[i] = va_arg (vargs, Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 va_end (vargs);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
877
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 GCPRO1 (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 emacs_doprnt_2 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 format_length, nargs, foo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 Lstream_flush (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 obj = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 Lstream_byte_count (XLSTREAM (stream)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 Lstream_delete (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 }