annotate src/doprnt.c @ 410:de805c49cfc1 r21-2-35

Import from CVS: tag r21-2-35
author cvs
date Mon, 13 Aug 2007 11:19:21 +0200
parents 74fd4e045ea6
children 697ef44129c6
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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
34 static const char *valid_flags = "-+ #0";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
36 static const char *valid_converters = "diouxXfeEgGcsS";
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
37 static const char *int_converters = "dic";
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
38 static const char *unsigned_int_converters = "ouxX";
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
39 static const char *double_converters = "feEgG";
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
40 static const char *string_converters = "sS";
0
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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
102 doprnt_1 (Lisp_Object stream, const Bufbyte *string, Bytecount len,
0
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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
143 static const Bufbyte *
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
144 parse_off_posnum (const Bufbyte *start, const Bufbyte *end, int *returned_num)
0
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 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 205
diff changeset
152 if ((size_t) (arg_ptr - arg_convert) >= sizeof (arg_convert) - 1)
0
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 *
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
181 parse_doprnt_spec (const Bufbyte *format, Bytecount format_length)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
183 const Bufbyte *fmt = format;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
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;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
191 const Bufbyte *text_end;
0
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
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 205
diff changeset
194 xzero (spec);
0
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 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
219 const Bufbyte *ptr;
0
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);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 205
diff changeset
264 xzero (spec);
203
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);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 205
diff changeset
292 xzero (spec);
203
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
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 205
diff changeset
364 xzero (arg);
0
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)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
389 arg.i = va_arg (vargs, int /* short */);
0
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)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
398 arg.ui = va_arg (vargs, unsigned int /* unsigned short */);
0
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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
426 emacs_doprnt_1 (Lisp_Object stream, const Bufbyte *format_nonreloc,
0
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 */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
430 const Lisp_Object *largs, va_list vargs)
0
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)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
443 format_length = (Bytecount) strlen ((const char *) format_nonreloc);
0
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
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 205
diff changeset
483 /* The char '*' as converter means the field width, precision
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 205
diff changeset
484 was specified as an argument. Extract the data and forward
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 205
diff changeset
485 it to the next spec, to which it will apply. */
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
486 if (ch == '*')
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 struct printf_spec *nextspec = Dynarr_atp (specs, i + 1);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
489 Lisp_Object obj = largs[spec->argnum - 1];
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
490
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
491 if (INTP (obj))
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 (spec->forwarding_precision)
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 nextspec->precision = XINT (obj);
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
496 nextspec->minwidth = spec->minwidth;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
497 }
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
498 else
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 nextspec->minwidth = XINT (obj);
205
92f8ad5d0d3f Import from CVS: tag r20-4b1
cvs
parents: 203
diff changeset
501 if (XINT(obj) < 0)
92f8ad5d0d3f Import from CVS: tag r20-4b1
cvs
parents: 203
diff changeset
502 {
92f8ad5d0d3f Import from CVS: tag r20-4b1
cvs
parents: 203
diff changeset
503 spec->minus_flag = 1;
92f8ad5d0d3f Import from CVS: tag r20-4b1
cvs
parents: 203
diff changeset
504 nextspec->minwidth = - nextspec->minwidth;
92f8ad5d0d3f Import from CVS: tag r20-4b1
cvs
parents: 203
diff changeset
505 }
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
506 }
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
507 nextspec->minus_flag = spec->minus_flag;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
508 nextspec->plus_flag = spec->plus_flag;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
509 nextspec->space_flag = spec->space_flag;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
510 nextspec->number_flag = spec->number_flag;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
511 nextspec->zero_flag = spec->zero_flag;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
512 }
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
513 continue;
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
514 }
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
515
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 if (largs && (spec->argnum < 1 || spec->argnum > nargs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 error ("Invalid repositioning argument %d", spec->argnum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 else if (ch == 'S' || ch == 's')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 Bufbyte *string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 Bytecount string_len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 if (!largs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 string = Dynarr_at (args, spec->argnum - 1).bp;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
527 /* error() can be called with null string arguments.
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
528 E.g., in fileio.c, the return value of strerror()
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
529 is never checked. We'll print (null), like some
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
530 printf implementations do. Would it be better (and safe)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 205
diff changeset
531 to signal an error instead? Or should we just use the
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
532 empty string? -dkindred@cs.cmu.edu 8/1997
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
533 */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
534 if (!string)
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
535 string = (Bufbyte *) "(null)";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 string_len = strlen ((char *) string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 Lisp_Object obj = largs[spec->argnum - 1];
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
541 Lisp_String *ls;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 if (ch == 'S')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 /* For `S', prin1 the argument and then treat like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 a string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ls = XSTRING (Fprin1_to_string (obj, Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 else if (STRINGP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ls = XSTRING (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 else if (SYMBOLP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ls = XSYMBOL (obj)->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 /* convert to string using princ. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 ls = XSTRING (Fprin1_to_string (obj, Qt));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 string = string_data (ls);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 string_len = string_length (ls);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 doprnt_1 (stream, string, string_len, spec->minwidth,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 spec->precision, spec->minus_flag, spec->zero_flag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 /* Must be a number. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 union printf_arg arg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 if (!largs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 arg = Dynarr_at (args, spec->argnum - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 Lisp_Object obj = largs[spec->argnum - 1];
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 58
diff changeset
578 if (CHARP (obj))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
579 obj = make_int (XCHAR (obj));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 if (!INT_OR_FLOATP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 error ("format specifier %%%c doesn't match argument type",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 else if (strchr (double_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 arg.d = XFLOATINT (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 int val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 if (FLOATP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 val = XINT (Ftruncate (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 val = XINT (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 if (strchr (unsigned_int_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 arg.ul = (unsigned long) val;
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 arg.ui = (unsigned int) val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 arg.l = (long) val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 arg.i = val;
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 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 if (ch == 'c')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 Emchar a;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 Bytecount charlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 Bufbyte charbuf[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 a = (Emchar) arg.l;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 a = (Emchar) arg.i;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
623
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 if (!valid_char_p (a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 error ("invalid character value %d to %%c spec", a);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 charlen = set_charptr_emchar (charbuf, a);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 doprnt_1 (stream, charbuf, charlen, spec->minwidth,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 -1, spec->minus_flag, spec->zero_flag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 char text_to_print[500];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 char constructed_spec[100];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 /* Partially reconstruct the spec and use sprintf() to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 format the string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 /* Make sure nothing stupid happens */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 /* DO NOT REMOVE THE (int) CAST! Incorrect results will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 follow! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 spec->precision = min (spec->precision,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (int) (sizeof (text_to_print) - 50));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 constructed_spec[0] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 strcat (constructed_spec, "%");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 if (spec->plus_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 strcat (constructed_spec, "+");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 if (spec->space_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 strcat (constructed_spec, " ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 if (spec->number_flag)
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 if (spec->precision >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 strcat (constructed_spec, ".");
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
657 long_to_string (constructed_spec + strlen (constructed_spec),
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
658 spec->precision);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 /* sprintf the mofo */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 /* we have to use separate calls to sprintf(), rather than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 a single big conditional, because of the different types
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 of the arguments */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 if (strchr (double_converters, ch))
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
666 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
667 sprintf (constructed_spec + strlen (constructed_spec),
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
668 "%c", ch);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
669 sprintf (text_to_print, constructed_spec, arg.d);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
670 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 else if (strchr (unsigned_int_converters, ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 {
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
673 sprintf (constructed_spec + strlen (constructed_spec),
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
674 "%c", ch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 sprintf (text_to_print, constructed_spec, arg.ul);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 sprintf (text_to_print, constructed_spec, arg.ui);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 {
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
682 if (spec->zero_flag && spec->minwidth)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
683 sprintf (constructed_spec + strlen (constructed_spec),
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
684 "0%d%c", spec->minwidth, ch);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
685 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
686 sprintf (constructed_spec + strlen (constructed_spec),
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
687 "%c", ch);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 if (spec->l_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 sprintf (text_to_print, constructed_spec, arg.l);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 sprintf (text_to_print, constructed_spec, arg.i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 doprnt_1 (stream, (Bufbyte *) text_to_print,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 strlen (text_to_print),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 spec->minwidth, -1, spec->minus_flag, spec->zero_flag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 /* #### will not get freed if error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 if (specs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 Dynarr_free (specs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 if (args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 Dynarr_free (args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 return Lstream_byte_count (XLSTREAM (stream)) - init_byte_count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 /* You really don't want to know why this is necessary... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 static Bytecount
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
711 emacs_doprnt_2 (Lisp_Object stream, const Bufbyte *format_nonreloc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 Lisp_Object format_reloc, Bytecount format_length, int nargs,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
713 const Lisp_Object *largs, ...)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 va_list vargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 Bytecount val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 va_start (vargs, largs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 val = emacs_doprnt_1 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 format_length, nargs, largs, vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 va_end (vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 /*********************** external entry points ***********************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 /* A note about I18N3 translating: the format string should get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 translated, but not under all circumstances. When the format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 string is a Lisp string, what should happen is that Fformat()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 should format the untranslated args[0] and return that, and also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 call Fgettext() on args[0] and, if that is different, format it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 and store it in the `string-translatable' property of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 the returned string. See Fgettext(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 /* Send formatted output to STREAM. The format string comes from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 either FORMAT_NONRELOC (of length FORMAT_LENGTH; -1 means use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 strlen() to determine the length) or from FORMAT_RELOC, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 should be a Lisp string. Return the number of bytes written
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 to the stream.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 DO NOT pass the data from a Lisp string as the FORMAT_NONRELOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 parameter, because this function can cause GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 Bytecount
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
746 emacs_doprnt_c (Lisp_Object stream, const Bufbyte *format_nonreloc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 int val;
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 va_start (vargs, format_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 val = emacs_doprnt_1 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 format_length, 0, 0, vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 va_end (vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 return val;
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 /* Like emacs_doprnt_c but the args come in va_list format. */
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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
763 emacs_doprnt_va (Lisp_Object stream, const Bufbyte *format_nonreloc,
0
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 va_list vargs)
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_1 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 format_length, 0, 0, vargs);
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 emacs_doprnt_c but the args are Lisp objects instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 C arguments. This causes somewhat different behavior from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 the above two functions (which should act like printf).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 See `format' for a description of this behavior. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 Bytecount
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
777 emacs_doprnt_lisp (Lisp_Object stream, const Bufbyte *format_nonreloc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 Lisp_Object format_reloc, Bytecount format_length,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
779 int nargs, const Lisp_Object *largs)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 return emacs_doprnt_2 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 format_length, nargs, largs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 /* Like the previous function but takes a variable number of arguments. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 Bytecount
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
788 emacs_doprnt_lisp_2 (Lisp_Object stream, const Bufbyte *format_nonreloc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 int nargs, ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 va_list vargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 int i;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
794 Lisp_Object *foo = alloca_array (Lisp_Object, nargs);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 va_start (vargs, nargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 for (i = 0; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 foo[i] = va_arg (vargs, Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 va_end (vargs);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
800
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 return emacs_doprnt_2 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 format_length, nargs, foo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 /* The following four functions work like the above three but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 return their output as a Lisp string instead of sending it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 to a stream. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
810 emacs_doprnt_string_c (const Bufbyte *format_nonreloc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 va_list vargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 Lisp_Object stream = make_resizing_buffer_output_stream ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 GCPRO1 (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 va_start (vargs, format_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 emacs_doprnt_1 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 format_length, 0, 0, vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 va_end (vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 Lstream_flush (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 obj = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 Lstream_byte_count (XLSTREAM (stream)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 Lstream_delete (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
833 emacs_doprnt_string_va (const Bufbyte *format_nonreloc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 va_list vargs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 /* I'm fairly sure that this function cannot actually GC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 That can only happen when the arguments to emacs_doprnt_1() are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 Lisp objects rather than C args. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 Lisp_Object stream = make_resizing_buffer_output_stream ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 GCPRO1 (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 emacs_doprnt_1 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 format_length, 0, 0, vargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 Lstream_flush (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 obj = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 Lstream_byte_count (XLSTREAM (stream)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 Lstream_delete (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
856 emacs_doprnt_string_lisp (const Bufbyte *format_nonreloc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 Lisp_Object format_reloc, Bytecount format_length,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
858 int nargs, const Lisp_Object *largs)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 Lisp_Object stream = make_resizing_buffer_output_stream ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 GCPRO1 (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 emacs_doprnt_2 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 format_length, nargs, largs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 Lstream_flush (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 obj = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 Lstream_byte_count (XLSTREAM (stream)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 Lstream_delete (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
876 emacs_doprnt_string_lisp_2 (const Bufbyte *format_nonreloc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 Lisp_Object format_reloc, Bytecount format_length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 int nargs, ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 Lisp_Object stream = make_resizing_buffer_output_stream ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 va_list vargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 int i;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
885 Lisp_Object *foo = alloca_array (Lisp_Object, nargs);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 va_start (vargs, nargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 for (i = 0; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 foo[i] = va_arg (vargs, Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 va_end (vargs);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 74
diff changeset
891
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 GCPRO1 (stream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 emacs_doprnt_2 (stream, format_nonreloc, format_reloc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 format_length, nargs, foo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 Lstream_flush (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 obj = make_string (resizing_buffer_stream_ptr (XLSTREAM (stream)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 Lstream_byte_count (XLSTREAM (stream)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 Lstream_delete (XLSTREAM (stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 }