blob: eb90de4d925161b936325c12851eed31f8ebb48c [file] [log] [blame]
drha18c5682000-10-08 22:20:57 +00001/*
2** The "printf" code that follows dates from the 1980's. It is in
3** the public domain. The original comments are included here for
drhe84a3062004-02-02 12:29:25 +00004** completeness. They are very out-of-date but might be useful as
5** an historical reference. Most of the "enhancements" have been backed
6** out so that the functionality is now the same as standard printf().
7**
8**************************************************************************
drha18c5682000-10-08 22:20:57 +00009**
drhe78e8282003-01-19 03:59:45 +000010** The following modules is an enhanced replacement for the "printf" subroutines
11** found in the standard C library. The following enhancements are
drha18c5682000-10-08 22:20:57 +000012** supported:
13**
14** + Additional functions. The standard set of "printf" functions
15** includes printf, fprintf, sprintf, vprintf, vfprintf, and
16** vsprintf. This module adds the following:
17**
18** * snprintf -- Works like sprintf, but has an extra argument
19** which is the size of the buffer written to.
20**
21** * mprintf -- Similar to sprintf. Writes output to memory
22** obtained from malloc.
23**
24** * xprintf -- Calls a function to dispose of output.
25**
26** * nprintf -- No output, but returns the number of characters
27** that would have been output by printf.
28**
29** * A v- version (ex: vsnprintf) of every function is also
30** supplied.
31**
32** + A few extensions to the formatting notation are supported:
33**
34** * The "=" flag (similar to "-") causes the output to be
35** be centered in the appropriately sized field.
36**
37** * The %b field outputs an integer in binary notation.
38**
39** * The %c field now accepts a precision. The character output
40** is repeated by the number of times the precision specifies.
41**
42** * The %' field works like %c, but takes as its character the
43** next character of the format string, instead of the next
44** argument. For example, printf("%.78'-") prints 78 minus
45** signs, the same as printf("%.78c",'-').
46**
47** + When compiled using GCC on a SPARC, this version of printf is
48** faster than the library printf for SUN OS 4.1.
49**
50** + All functions are fully reentrant.
51**
52*/
53#include "sqliteInt.h"
drh7c68d602000-10-11 19:28:51 +000054
drha18c5682000-10-08 22:20:57 +000055/*
drha18c5682000-10-08 22:20:57 +000056** Conversion types fall into various categories as defined by the
57** following enumeration.
58*/
drhe84a3062004-02-02 12:29:25 +000059#define etRADIX 1 /* Integer types. %d, %x, %o, and so forth */
60#define etFLOAT 2 /* Floating point. %f */
61#define etEXP 3 /* Exponentional notation. %e and %E */
62#define etGENERIC 4 /* Floating or exponential, depending on exponent. %g */
63#define etSIZE 5 /* Return number of characters processed so far. %n */
64#define etSTRING 6 /* Strings. %s */
65#define etDYNSTRING 7 /* Dynamically allocated strings. %z */
66#define etPERCENT 8 /* Percent symbol. %% */
67#define etCHARX 9 /* Characters. %c */
drha18c5682000-10-08 22:20:57 +000068/* The rest are extensions, not normally found in printf() */
drh05a82982006-03-19 13:00:25 +000069#define etCHARLIT 10 /* Literal characters. %' */
70#define etSQLESCAPE 11 /* Strings with '\'' doubled. %q */
71#define etSQLESCAPE2 12 /* Strings with '\'' doubled and enclosed in '',
chw0cfcf3f2002-06-16 04:55:48 +000072 NULL pointers replaced by SQL NULL. %Q */
drh05a82982006-03-19 13:00:25 +000073#define etTOKEN 13 /* a pointer to a Token structure */
74#define etSRCLIST 14 /* a pointer to a SrcList */
75#define etPOINTER 15 /* The %p conversion */
danielk1977f3b863e2007-06-24 06:32:17 +000076#define etSQLESCAPE3 16 /* %w -> Strings with '\"' doubled */
drh9a993342007-12-13 02:45:31 +000077#define etORDINAL 17 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
drhe84a3062004-02-02 12:29:25 +000078
79
80/*
81** An "etByte" is an 8-bit unsigned value.
82*/
83typedef unsigned char etByte;
drha18c5682000-10-08 22:20:57 +000084
85/*
86** Each builtin conversion character (ex: the 'd' in "%d") is described
87** by an instance of the following structure
88*/
89typedef struct et_info { /* Information about each format field */
drhe84a3062004-02-02 12:29:25 +000090 char fmttype; /* The format field code letter */
91 etByte base; /* The base for radix conversion */
92 etByte flags; /* One or more of FLAG_ constants below */
93 etByte type; /* Conversion paradigm */
drh76ff3a02004-09-24 22:32:30 +000094 etByte charset; /* Offset into aDigits[] of the digits string */
95 etByte prefix; /* Offset into aPrefix[] of the prefix string */
drha18c5682000-10-08 22:20:57 +000096} et_info;
97
98/*
drhe84a3062004-02-02 12:29:25 +000099** Allowed values for et_info.flags
100*/
101#define FLAG_SIGNED 1 /* True if the value to convert is signed */
102#define FLAG_INTERN 2 /* True if for internal use only */
drh4794f732004-11-05 17:17:50 +0000103#define FLAG_STRING 4 /* Allow infinity precision */
drhe84a3062004-02-02 12:29:25 +0000104
105
106/*
drha18c5682000-10-08 22:20:57 +0000107** The following table is searched linearly, so it is good to put the
108** most frequently used conversion types first.
109*/
drh76ff3a02004-09-24 22:32:30 +0000110static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
111static const char aPrefix[] = "-x0\000X0";
drh57196282004-10-06 15:41:16 +0000112static const et_info fmtinfo[] = {
drh76ff3a02004-09-24 22:32:30 +0000113 { 'd', 10, 1, etRADIX, 0, 0 },
drh4794f732004-11-05 17:17:50 +0000114 { 's', 0, 4, etSTRING, 0, 0 },
drh557cc602005-08-13 12:59:14 +0000115 { 'g', 0, 1, etGENERIC, 30, 0 },
drh153c62c2007-08-24 03:51:33 +0000116 { 'z', 0, 4, etDYNSTRING, 0, 0 },
drh4794f732004-11-05 17:17:50 +0000117 { 'q', 0, 4, etSQLESCAPE, 0, 0 },
118 { 'Q', 0, 4, etSQLESCAPE2, 0, 0 },
danielk1977f3b863e2007-06-24 06:32:17 +0000119 { 'w', 0, 4, etSQLESCAPE3, 0, 0 },
drh76ff3a02004-09-24 22:32:30 +0000120 { 'c', 0, 0, etCHARX, 0, 0 },
121 { 'o', 8, 0, etRADIX, 0, 2 },
122 { 'u', 10, 0, etRADIX, 0, 0 },
123 { 'x', 16, 0, etRADIX, 16, 1 },
124 { 'X', 16, 0, etRADIX, 0, 4 },
drhb37df7b2005-10-13 02:09:49 +0000125#ifndef SQLITE_OMIT_FLOATING_POINT
drh76ff3a02004-09-24 22:32:30 +0000126 { 'f', 0, 1, etFLOAT, 0, 0 },
127 { 'e', 0, 1, etEXP, 30, 0 },
128 { 'E', 0, 1, etEXP, 14, 0 },
drh76ff3a02004-09-24 22:32:30 +0000129 { 'G', 0, 1, etGENERIC, 14, 0 },
drhb37df7b2005-10-13 02:09:49 +0000130#endif
drh76ff3a02004-09-24 22:32:30 +0000131 { 'i', 10, 1, etRADIX, 0, 0 },
132 { 'n', 0, 0, etSIZE, 0, 0 },
133 { '%', 0, 0, etPERCENT, 0, 0 },
134 { 'p', 16, 0, etPOINTER, 0, 1 },
135 { 'T', 0, 2, etTOKEN, 0, 0 },
136 { 'S', 0, 2, etSRCLIST, 0, 0 },
drh9a993342007-12-13 02:45:31 +0000137 { 'r', 10, 3, etORDINAL, 0, 0 },
drha18c5682000-10-08 22:20:57 +0000138};
139#define etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
140
141/*
drhb37df7b2005-10-13 02:09:49 +0000142** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
drha18c5682000-10-08 22:20:57 +0000143** conversions will work.
144*/
drhb37df7b2005-10-13 02:09:49 +0000145#ifndef SQLITE_OMIT_FLOATING_POINT
drha18c5682000-10-08 22:20:57 +0000146/*
147** "*val" is a double such that 0.1 <= *val < 10.0
148** Return the ascii code for the leading digit of *val, then
149** multiply "*val" by 10.0 to renormalize.
150**
151** Example:
152** input: *val = 3.14159
153** output: *val = 1.4159 function return = '3'
154**
155** The counter *cnt is incremented each time. After counter exceeds
156** 16 (the number of significant digits in a 64-bit float) '0' is
157** always returned.
158*/
drh384eef32004-01-07 03:04:27 +0000159static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
drha18c5682000-10-08 22:20:57 +0000160 int digit;
drh384eef32004-01-07 03:04:27 +0000161 LONGDOUBLE_TYPE d;
drha18c5682000-10-08 22:20:57 +0000162 if( (*cnt)++ >= 16 ) return '0';
163 digit = (int)*val;
164 d = digit;
165 digit += '0';
166 *val = (*val - d)*10.0;
167 return digit;
168}
drhb37df7b2005-10-13 02:09:49 +0000169#endif /* SQLITE_OMIT_FLOATING_POINT */
drha18c5682000-10-08 22:20:57 +0000170
drh79158e12005-09-06 21:40:45 +0000171/*
drhade86482007-11-28 22:36:40 +0000172** Append N space characters to the given string buffer.
173*/
174static void appendSpace(StrAccum *pAccum, int N){
175 static const char zSpaces[] = " ";
176 while( N>=sizeof(zSpaces)-1 ){
177 sqlite3StrAccumAppend(pAccum, zSpaces, sizeof(zSpaces)-1);
178 N -= sizeof(zSpaces)-1;
179 }
180 if( N>0 ){
181 sqlite3StrAccumAppend(pAccum, zSpaces, N);
182 }
183}
184
185/*
drh79158e12005-09-06 21:40:45 +0000186** On machines with a small stack size, you can redefine the
187** SQLITE_PRINT_BUF_SIZE to be less than 350. But beware - for
188** smaller values some %f conversions may go into an infinite loop.
189*/
190#ifndef SQLITE_PRINT_BUF_SIZE
191# define SQLITE_PRINT_BUF_SIZE 350
192#endif
193#define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
drha18c5682000-10-08 22:20:57 +0000194
195/*
196** The root program. All variations call this core.
197**
198** INPUTS:
199** func This is a pointer to a function taking three arguments
200** 1. A pointer to anything. Same as the "arg" parameter.
201** 2. A pointer to the list of characters to be output
202** (Note, this list is NOT null terminated.)
203** 3. An integer number of characters to be output.
204** (Note: This number might be zero.)
205**
206** arg This is the pointer to anything which will be passed as the
207** first argument to "func". Use it for whatever you like.
208**
209** fmt This is the format string, as in the usual print.
210**
211** ap This is a pointer to a list of arguments. Same as in
212** vfprint.
213**
214** OUTPUTS:
215** The return value is the total number of characters sent to
216** the function "func". Returns -1 on a error.
217**
218** Note that the order in which automatic variables are declared below
219** seems to make a big difference in determining how fast this beast
220** will run.
221*/
drhade86482007-11-28 22:36:40 +0000222static void vxprintf(
223 StrAccum *pAccum, /* Accumulate results here */
drh5f968432004-02-21 19:02:30 +0000224 int useExtended, /* Allow extended %-conversions */
225 const char *fmt, /* Format string */
226 va_list ap /* arguments */
drha18c5682000-10-08 22:20:57 +0000227){
drhe84a3062004-02-02 12:29:25 +0000228 int c; /* Next character in the format string */
229 char *bufpt; /* Pointer to the conversion buffer */
230 int precision; /* Precision of the current field */
231 int length; /* Length of the field */
232 int idx; /* A general purpose loop counter */
drhe84a3062004-02-02 12:29:25 +0000233 int width; /* Width of the current field */
234 etByte flag_leftjustify; /* True if "-" flag is present */
235 etByte flag_plussign; /* True if "+" flag is present */
236 etByte flag_blanksign; /* True if " " flag is present */
237 etByte flag_alternateform; /* True if "#" flag is present */
drh531fe872005-08-13 13:40:42 +0000238 etByte flag_altform2; /* True if "!" flag is present */
drhe84a3062004-02-02 12:29:25 +0000239 etByte flag_zeropad; /* True if field width constant starts with zero */
240 etByte flag_long; /* True if "l" flag is present */
drha34b6762004-05-07 13:30:42 +0000241 etByte flag_longlong; /* True if the "ll" flag is present */
drh3e9aeec2005-08-13 13:39:02 +0000242 etByte done; /* Loop termination flag */
drh27436af2006-03-28 23:57:17 +0000243 sqlite_uint64 longvalue; /* Value for integer types */
drh384eef32004-01-07 03:04:27 +0000244 LONGDOUBLE_TYPE realvalue; /* Value for real types */
drh57196282004-10-06 15:41:16 +0000245 const et_info *infop; /* Pointer to the appropriate info structure */
drhe84a3062004-02-02 12:29:25 +0000246 char buf[etBUFSIZE]; /* Conversion buffer */
247 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
248 etByte errorflag = 0; /* True if an error is encountered */
249 etByte xtype; /* Conversion paradigm */
250 char *zExtra; /* Extra memory used for etTCLESCAPE conversions */
drhb37df7b2005-10-13 02:09:49 +0000251#ifndef SQLITE_OMIT_FLOATING_POINT
drh557cc602005-08-13 12:59:14 +0000252 int exp, e2; /* exponent of real numbers */
drhe84a3062004-02-02 12:29:25 +0000253 double rounder; /* Used for rounding floating point values */
254 etByte flag_dp; /* True if decimal point should be shown */
255 etByte flag_rtz; /* True if trailing zeros should be removed */
256 etByte flag_exp; /* True to force display of the exponent */
257 int nsd; /* Number of significant digits returned */
drha18c5682000-10-08 22:20:57 +0000258#endif
259
drhade86482007-11-28 22:36:40 +0000260 length = 0;
drha18c5682000-10-08 22:20:57 +0000261 bufpt = 0;
262 for(; (c=(*fmt))!=0; ++fmt){
263 if( c!='%' ){
drhe84a3062004-02-02 12:29:25 +0000264 int amt;
drha18c5682000-10-08 22:20:57 +0000265 bufpt = (char *)fmt;
266 amt = 1;
267 while( (c=(*++fmt))!='%' && c!=0 ) amt++;
drhade86482007-11-28 22:36:40 +0000268 sqlite3StrAccumAppend(pAccum, bufpt, amt);
drha18c5682000-10-08 22:20:57 +0000269 if( c==0 ) break;
270 }
271 if( (c=(*++fmt))==0 ){
272 errorflag = 1;
drhade86482007-11-28 22:36:40 +0000273 sqlite3StrAccumAppend(pAccum, "%", 1);
drha18c5682000-10-08 22:20:57 +0000274 break;
275 }
276 /* Find out what flags are present */
277 flag_leftjustify = flag_plussign = flag_blanksign =
drh557cc602005-08-13 12:59:14 +0000278 flag_alternateform = flag_altform2 = flag_zeropad = 0;
drh3e9aeec2005-08-13 13:39:02 +0000279 done = 0;
drha18c5682000-10-08 22:20:57 +0000280 do{
281 switch( c ){
drh3e9aeec2005-08-13 13:39:02 +0000282 case '-': flag_leftjustify = 1; break;
283 case '+': flag_plussign = 1; break;
284 case ' ': flag_blanksign = 1; break;
285 case '#': flag_alternateform = 1; break;
286 case '!': flag_altform2 = 1; break;
287 case '0': flag_zeropad = 1; break;
288 default: done = 1; break;
drha18c5682000-10-08 22:20:57 +0000289 }
drh3e9aeec2005-08-13 13:39:02 +0000290 }while( !done && (c=(*++fmt))!=0 );
drha18c5682000-10-08 22:20:57 +0000291 /* Get the field width */
292 width = 0;
293 if( c=='*' ){
294 width = va_arg(ap,int);
295 if( width<0 ){
296 flag_leftjustify = 1;
297 width = -width;
298 }
299 c = *++fmt;
300 }else{
drh17a68932001-01-31 13:28:08 +0000301 while( c>='0' && c<='9' ){
drha18c5682000-10-08 22:20:57 +0000302 width = width*10 + c - '0';
303 c = *++fmt;
304 }
305 }
306 if( width > etBUFSIZE-10 ){
307 width = etBUFSIZE-10;
308 }
309 /* Get the precision */
310 if( c=='.' ){
311 precision = 0;
312 c = *++fmt;
313 if( c=='*' ){
314 precision = va_arg(ap,int);
drha18c5682000-10-08 22:20:57 +0000315 if( precision<0 ) precision = -precision;
drha18c5682000-10-08 22:20:57 +0000316 c = *++fmt;
317 }else{
drh17a68932001-01-31 13:28:08 +0000318 while( c>='0' && c<='9' ){
drha18c5682000-10-08 22:20:57 +0000319 precision = precision*10 + c - '0';
320 c = *++fmt;
321 }
322 }
drha18c5682000-10-08 22:20:57 +0000323 }else{
324 precision = -1;
325 }
326 /* Get the conversion type modifier */
327 if( c=='l' ){
328 flag_long = 1;
329 c = *++fmt;
drha34b6762004-05-07 13:30:42 +0000330 if( c=='l' ){
331 flag_longlong = 1;
332 c = *++fmt;
333 }else{
334 flag_longlong = 0;
335 }
drha18c5682000-10-08 22:20:57 +0000336 }else{
drha34b6762004-05-07 13:30:42 +0000337 flag_long = flag_longlong = 0;
drha18c5682000-10-08 22:20:57 +0000338 }
339 /* Fetch the info entry for the field */
340 infop = 0;
341 for(idx=0; idx<etNINFO; idx++){
342 if( c==fmtinfo[idx].fmttype ){
343 infop = &fmtinfo[idx];
drh5f968432004-02-21 19:02:30 +0000344 if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
345 xtype = infop->type;
drhc4413562006-05-22 22:04:00 +0000346 }else{
drhade86482007-11-28 22:36:40 +0000347 return;
drh5f968432004-02-21 19:02:30 +0000348 }
drha18c5682000-10-08 22:20:57 +0000349 break;
350 }
351 }
drha18c5682000-10-08 22:20:57 +0000352 zExtra = 0;
drh43617e92006-03-06 20:55:46 +0000353 if( infop==0 ){
drhade86482007-11-28 22:36:40 +0000354 return;
drh43617e92006-03-06 20:55:46 +0000355 }
356
drha18c5682000-10-08 22:20:57 +0000357
drh4794f732004-11-05 17:17:50 +0000358 /* Limit the precision to prevent overflowing buf[] during conversion */
359 if( precision>etBUFSIZE-40 && (infop->flags & FLAG_STRING)==0 ){
360 precision = etBUFSIZE-40;
361 }
362
drha18c5682000-10-08 22:20:57 +0000363 /*
364 ** At this point, variables are initialized as follows:
365 **
366 ** flag_alternateform TRUE if a '#' is present.
drh3e9aeec2005-08-13 13:39:02 +0000367 ** flag_altform2 TRUE if a '!' is present.
drha18c5682000-10-08 22:20:57 +0000368 ** flag_plussign TRUE if a '+' is present.
369 ** flag_leftjustify TRUE if a '-' is present or if the
370 ** field width was negative.
371 ** flag_zeropad TRUE if the width began with 0.
372 ** flag_long TRUE if the letter 'l' (ell) prefixed
373 ** the conversion character.
drha34b6762004-05-07 13:30:42 +0000374 ** flag_longlong TRUE if the letter 'll' (ell ell) prefixed
375 ** the conversion character.
drha18c5682000-10-08 22:20:57 +0000376 ** flag_blanksign TRUE if a ' ' is present.
377 ** width The specified field width. This is
378 ** always non-negative. Zero is the default.
379 ** precision The specified precision. The default
380 ** is -1.
381 ** xtype The class of the conversion.
382 ** infop Pointer to the appropriate info struct.
383 */
384 switch( xtype ){
drhfe63d1c2004-09-08 20:13:04 +0000385 case etPOINTER:
386 flag_longlong = sizeof(char*)==sizeof(i64);
387 flag_long = sizeof(char*)==sizeof(long int);
388 /* Fall through into the next case */
drh9a993342007-12-13 02:45:31 +0000389 case etORDINAL:
drha18c5682000-10-08 22:20:57 +0000390 case etRADIX:
drhe84a3062004-02-02 12:29:25 +0000391 if( infop->flags & FLAG_SIGNED ){
drhe9707672004-06-25 01:10:48 +0000392 i64 v;
393 if( flag_longlong ) v = va_arg(ap,i64);
394 else if( flag_long ) v = va_arg(ap,long int);
395 else v = va_arg(ap,int);
396 if( v<0 ){
397 longvalue = -v;
398 prefix = '-';
danielk1977cfcdaef2004-05-12 07:33:33 +0000399 }else{
drhe9707672004-06-25 01:10:48 +0000400 longvalue = v;
401 if( flag_plussign ) prefix = '+';
danielk1977cfcdaef2004-05-12 07:33:33 +0000402 else if( flag_blanksign ) prefix = ' ';
403 else prefix = 0;
404 }
drhe9707672004-06-25 01:10:48 +0000405 }else{
406 if( flag_longlong ) longvalue = va_arg(ap,u64);
407 else if( flag_long ) longvalue = va_arg(ap,unsigned long int);
408 else longvalue = va_arg(ap,unsigned int);
409 prefix = 0;
410 }
411 if( longvalue==0 ) flag_alternateform = 0;
drha18c5682000-10-08 22:20:57 +0000412 if( flag_zeropad && precision<width-(prefix!=0) ){
413 precision = width-(prefix!=0);
drh9adf9ac2002-05-15 11:44:13 +0000414 }
drh3039c0a2004-02-29 00:11:30 +0000415 bufpt = &buf[etBUFSIZE-1];
drh9a993342007-12-13 02:45:31 +0000416 if( xtype==etORDINAL ){
drh43f6e062007-12-13 17:50:22 +0000417 static const char zOrd[] = "thstndrd";
418 int x = longvalue % 10;
419 if( x>=4 || (longvalue/10)%10==1 ){
420 x = 0;
421 }
422 buf[etBUFSIZE-3] = zOrd[x*2];
423 buf[etBUFSIZE-2] = zOrd[x*2+1];
drh9a993342007-12-13 02:45:31 +0000424 bufpt -= 2;
425 }
drha18c5682000-10-08 22:20:57 +0000426 {
drh76ff3a02004-09-24 22:32:30 +0000427 register const char *cset; /* Use registers for speed */
drha18c5682000-10-08 22:20:57 +0000428 register int base;
drh76ff3a02004-09-24 22:32:30 +0000429 cset = &aDigits[infop->charset];
drha18c5682000-10-08 22:20:57 +0000430 base = infop->base;
431 do{ /* Convert to ascii */
432 *(--bufpt) = cset[longvalue%base];
433 longvalue = longvalue/base;
434 }while( longvalue>0 );
drh9adf9ac2002-05-15 11:44:13 +0000435 }
drh3039c0a2004-02-29 00:11:30 +0000436 length = &buf[etBUFSIZE-1]-bufpt;
drha18c5682000-10-08 22:20:57 +0000437 for(idx=precision-length; idx>0; idx--){
438 *(--bufpt) = '0'; /* Zero pad */
drh9adf9ac2002-05-15 11:44:13 +0000439 }
drha18c5682000-10-08 22:20:57 +0000440 if( prefix ) *(--bufpt) = prefix; /* Add sign */
441 if( flag_alternateform && infop->prefix ){ /* Add "0" or "0x" */
drh76ff3a02004-09-24 22:32:30 +0000442 const char *pre;
443 char x;
444 pre = &aPrefix[infop->prefix];
drha18c5682000-10-08 22:20:57 +0000445 if( *bufpt!=pre[0] ){
drh76ff3a02004-09-24 22:32:30 +0000446 for(; (x=(*pre))!=0; pre++) *(--bufpt) = x;
drh9adf9ac2002-05-15 11:44:13 +0000447 }
drha18c5682000-10-08 22:20:57 +0000448 }
drh3039c0a2004-02-29 00:11:30 +0000449 length = &buf[etBUFSIZE-1]-bufpt;
drha18c5682000-10-08 22:20:57 +0000450 break;
451 case etFLOAT:
452 case etEXP:
453 case etGENERIC:
454 realvalue = va_arg(ap,double);
drhb37df7b2005-10-13 02:09:49 +0000455#ifndef SQLITE_OMIT_FLOATING_POINT
drha18c5682000-10-08 22:20:57 +0000456 if( precision<0 ) precision = 6; /* Set default precision */
drh5eba8c02005-08-19 02:26:27 +0000457 if( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10;
drha18c5682000-10-08 22:20:57 +0000458 if( realvalue<0.0 ){
459 realvalue = -realvalue;
460 prefix = '-';
drh9adf9ac2002-05-15 11:44:13 +0000461 }else{
drha18c5682000-10-08 22:20:57 +0000462 if( flag_plussign ) prefix = '+';
463 else if( flag_blanksign ) prefix = ' ';
464 else prefix = 0;
drh9adf9ac2002-05-15 11:44:13 +0000465 }
drh3e9aeec2005-08-13 13:39:02 +0000466 if( xtype==etGENERIC && precision>0 ) precision--;
drh5f968432004-02-21 19:02:30 +0000467#if 0
drha18c5682000-10-08 22:20:57 +0000468 /* Rounding works like BSD when the constant 0.4999 is used. Wierd! */
469 for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1);
470#else
471 /* It makes more sense to use 0.5 */
drh74161702006-02-24 02:53:49 +0000472 for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1){}
drha18c5682000-10-08 22:20:57 +0000473#endif
drh3e9aeec2005-08-13 13:39:02 +0000474 if( xtype==etFLOAT ) realvalue += rounder;
drha18c5682000-10-08 22:20:57 +0000475 /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
476 exp = 0;
drh0de3ae92008-04-28 16:55:26 +0000477 if( sqlite3IsNaN(realvalue) ){
drh53c14022007-05-10 17:23:11 +0000478 bufpt = "NaN";
479 length = 3;
480 break;
481 }
drha18c5682000-10-08 22:20:57 +0000482 if( realvalue>0.0 ){
drh63782852005-08-30 19:30:59 +0000483 while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
484 while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
485 while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
drhb621c232004-02-21 19:41:04 +0000486 while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
487 while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
488 if( exp>350 || exp<-350 ){
drh53c14022007-05-10 17:23:11 +0000489 if( prefix=='-' ){
490 bufpt = "-Inf";
491 }else if( prefix=='+' ){
492 bufpt = "+Inf";
493 }else{
494 bufpt = "Inf";
495 }
496 length = strlen(bufpt);
drha18c5682000-10-08 22:20:57 +0000497 break;
498 }
drh9adf9ac2002-05-15 11:44:13 +0000499 }
drha18c5682000-10-08 22:20:57 +0000500 bufpt = buf;
501 /*
502 ** If the field type is etGENERIC, then convert to either etEXP
503 ** or etFLOAT, as appropriate.
504 */
505 flag_exp = xtype==etEXP;
506 if( xtype!=etFLOAT ){
507 realvalue += rounder;
508 if( realvalue>=10.0 ){ realvalue *= 0.1; exp++; }
509 }
510 if( xtype==etGENERIC ){
511 flag_rtz = !flag_alternateform;
512 if( exp<-4 || exp>precision ){
513 xtype = etEXP;
514 }else{
515 precision = precision - exp;
516 xtype = etFLOAT;
517 }
drh9adf9ac2002-05-15 11:44:13 +0000518 }else{
drha18c5682000-10-08 22:20:57 +0000519 flag_rtz = 0;
drh9adf9ac2002-05-15 11:44:13 +0000520 }
drh557cc602005-08-13 12:59:14 +0000521 if( xtype==etEXP ){
522 e2 = 0;
523 }else{
524 e2 = exp;
525 }
drha18c5682000-10-08 22:20:57 +0000526 nsd = 0;
drh557cc602005-08-13 12:59:14 +0000527 flag_dp = (precision>0) | flag_alternateform | flag_altform2;
528 /* The sign in front of the number */
529 if( prefix ){
530 *(bufpt++) = prefix;
531 }
532 /* Digits prior to the decimal point */
533 if( e2<0 ){
534 *(bufpt++) = '0';
535 }else{
536 for(; e2>=0; e2--){
537 *(bufpt++) = et_getdigit(&realvalue,&nsd);
drha18c5682000-10-08 22:20:57 +0000538 }
drh9adf9ac2002-05-15 11:44:13 +0000539 }
drh557cc602005-08-13 12:59:14 +0000540 /* The decimal point */
541 if( flag_dp ){
542 *(bufpt++) = '.';
543 }
544 /* "0" digits after the decimal point but before the first
545 ** significant digit of the number */
546 for(e2++; e2<0 && precision>0; precision--, e2++){
547 *(bufpt++) = '0';
548 }
549 /* Significant digits after the decimal point */
550 while( (precision--)>0 ){
551 *(bufpt++) = et_getdigit(&realvalue,&nsd);
552 }
553 /* Remove trailing zeros and the "." if no digits follow the "." */
554 if( flag_rtz && flag_dp ){
drh3e9aeec2005-08-13 13:39:02 +0000555 while( bufpt[-1]=='0' ) *(--bufpt) = 0;
556 assert( bufpt>buf );
557 if( bufpt[-1]=='.' ){
drh557cc602005-08-13 12:59:14 +0000558 if( flag_altform2 ){
559 *(bufpt++) = '0';
560 }else{
561 *(--bufpt) = 0;
562 }
563 }
564 }
565 /* Add the "eNNN" suffix */
566 if( flag_exp || (xtype==etEXP && exp) ){
567 *(bufpt++) = aDigits[infop->charset];
568 if( exp<0 ){
569 *(bufpt++) = '-'; exp = -exp;
570 }else{
571 *(bufpt++) = '+';
572 }
573 if( exp>=100 ){
574 *(bufpt++) = (exp/100)+'0'; /* 100's digit */
575 exp %= 100;
576 }
577 *(bufpt++) = exp/10+'0'; /* 10's digit */
578 *(bufpt++) = exp%10+'0'; /* 1's digit */
579 }
580 *bufpt = 0;
581
drha18c5682000-10-08 22:20:57 +0000582 /* The converted number is in buf[] and zero terminated. Output it.
583 ** Note that the number is in the usual order, not reversed as with
584 ** integer conversions. */
drh94ce4c12003-06-07 11:29:50 +0000585 length = bufpt-buf;
drha18c5682000-10-08 22:20:57 +0000586 bufpt = buf;
587
588 /* Special case: Add leading zeros if the flag_zeropad flag is
589 ** set and we are not left justified */
590 if( flag_zeropad && !flag_leftjustify && length < width){
591 int i;
592 int nPad = width - length;
593 for(i=width; i>=nPad; i--){
594 bufpt[i] = bufpt[i-nPad];
595 }
596 i = prefix!=0;
597 while( nPad-- ) bufpt[i++] = '0';
598 length = width;
599 }
600#endif
601 break;
602 case etSIZE:
drhade86482007-11-28 22:36:40 +0000603 *(va_arg(ap,int*)) = pAccum->nChar;
drha18c5682000-10-08 22:20:57 +0000604 length = width = 0;
605 break;
606 case etPERCENT:
607 buf[0] = '%';
608 bufpt = buf;
609 length = 1;
610 break;
611 case etCHARLIT:
612 case etCHARX:
613 c = buf[0] = (xtype==etCHARX ? va_arg(ap,int) : *++fmt);
614 if( precision>=0 ){
615 for(idx=1; idx<precision; idx++) buf[idx] = c;
616 length = precision;
drh9adf9ac2002-05-15 11:44:13 +0000617 }else{
drha18c5682000-10-08 22:20:57 +0000618 length =1;
drh9adf9ac2002-05-15 11:44:13 +0000619 }
drha18c5682000-10-08 22:20:57 +0000620 bufpt = buf;
621 break;
622 case etSTRING:
drhd93d8a82003-06-16 03:08:18 +0000623 case etDYNSTRING:
drhcb485882002-08-15 13:50:48 +0000624 bufpt = va_arg(ap,char*);
drhd93d8a82003-06-16 03:08:18 +0000625 if( bufpt==0 ){
626 bufpt = "";
627 }else if( xtype==etDYNSTRING ){
628 zExtra = bufpt;
629 }
drha18c5682000-10-08 22:20:57 +0000630 length = strlen(bufpt);
631 if( precision>=0 && precision<length ) length = precision;
632 break;
633 case etSQLESCAPE:
danielk1977f3b863e2007-06-24 06:32:17 +0000634 case etSQLESCAPE2:
635 case etSQLESCAPE3: {
danielk1977f0113002006-01-24 12:09:17 +0000636 int i, j, n, ch, isnull;
drh5eba8c02005-08-19 02:26:27 +0000637 int needQuote;
danielk1977f3b863e2007-06-24 06:32:17 +0000638 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
danielk1977f0113002006-01-24 12:09:17 +0000639 char *escarg = va_arg(ap,char*);
640 isnull = escarg==0;
641 if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
642 for(i=n=0; (ch=escarg[i])!=0; i++){
danielk1977f3b863e2007-06-24 06:32:17 +0000643 if( ch==q ) n++;
drha18c5682000-10-08 22:20:57 +0000644 }
drh5eba8c02005-08-19 02:26:27 +0000645 needQuote = !isnull && xtype==etSQLESCAPE2;
646 n += i + 1 + needQuote*2;
647 if( n>etBUFSIZE ){
drh17435752007-08-16 04:30:38 +0000648 bufpt = zExtra = sqlite3_malloc( n );
drhade86482007-11-28 22:36:40 +0000649 if( bufpt==0 ) return;
drh5eba8c02005-08-19 02:26:27 +0000650 }else{
651 bufpt = buf;
652 }
653 j = 0;
danielk1977f3b863e2007-06-24 06:32:17 +0000654 if( needQuote ) bufpt[j++] = q;
danielk1977f0113002006-01-24 12:09:17 +0000655 for(i=0; (ch=escarg[i])!=0; i++){
656 bufpt[j++] = ch;
danielk1977f3b863e2007-06-24 06:32:17 +0000657 if( ch==q ) bufpt[j++] = ch;
drh5eba8c02005-08-19 02:26:27 +0000658 }
danielk1977f3b863e2007-06-24 06:32:17 +0000659 if( needQuote ) bufpt[j++] = q;
drh5eba8c02005-08-19 02:26:27 +0000660 bufpt[j] = 0;
661 length = j;
drh05a82982006-03-19 13:00:25 +0000662 /* The precision is ignored on %q and %Q */
663 /* if( precision>=0 && precision<length ) length = precision; */
drha18c5682000-10-08 22:20:57 +0000664 break;
drh5eba8c02005-08-19 02:26:27 +0000665 }
drh5f968432004-02-21 19:02:30 +0000666 case etTOKEN: {
667 Token *pToken = va_arg(ap, Token*);
drhad6d9462004-09-19 02:15:24 +0000668 if( pToken && pToken->z ){
drhade86482007-11-28 22:36:40 +0000669 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
drhad6d9462004-09-19 02:15:24 +0000670 }
drh5f968432004-02-21 19:02:30 +0000671 length = width = 0;
672 break;
673 }
674 case etSRCLIST: {
675 SrcList *pSrc = va_arg(ap, SrcList*);
676 int k = va_arg(ap, int);
677 struct SrcList_item *pItem = &pSrc->a[k];
678 assert( k>=0 && k<pSrc->nSrc );
679 if( pItem->zDatabase && pItem->zDatabase[0] ){
drhade86482007-11-28 22:36:40 +0000680 sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1);
681 sqlite3StrAccumAppend(pAccum, ".", 1);
drh5f968432004-02-21 19:02:30 +0000682 }
drhade86482007-11-28 22:36:40 +0000683 sqlite3StrAccumAppend(pAccum, pItem->zName, -1);
drh5f968432004-02-21 19:02:30 +0000684 length = width = 0;
685 break;
686 }
drha18c5682000-10-08 22:20:57 +0000687 }/* End switch over the format type */
688 /*
689 ** The text of the conversion is pointed to by "bufpt" and is
690 ** "length" characters long. The field width is "width". Do
691 ** the output.
692 */
693 if( !flag_leftjustify ){
694 register int nspace;
695 nspace = width-length;
696 if( nspace>0 ){
drhade86482007-11-28 22:36:40 +0000697 appendSpace(pAccum, nspace);
drha18c5682000-10-08 22:20:57 +0000698 }
699 }
700 if( length>0 ){
drhade86482007-11-28 22:36:40 +0000701 sqlite3StrAccumAppend(pAccum, bufpt, length);
drha18c5682000-10-08 22:20:57 +0000702 }
703 if( flag_leftjustify ){
704 register int nspace;
705 nspace = width-length;
706 if( nspace>0 ){
drhade86482007-11-28 22:36:40 +0000707 appendSpace(pAccum, nspace);
drha18c5682000-10-08 22:20:57 +0000708 }
709 }
710 if( zExtra ){
danielk19771e536952007-08-16 10:09:01 +0000711 sqlite3_free(zExtra);
drha18c5682000-10-08 22:20:57 +0000712 }
713 }/* End for loop over the format string */
drha18c5682000-10-08 22:20:57 +0000714} /* End of function */
715
drhade86482007-11-28 22:36:40 +0000716/*
717** Append N bytes of text from z to the StrAccum object.
drha18c5682000-10-08 22:20:57 +0000718*/
drhade86482007-11-28 22:36:40 +0000719void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
720 if( p->tooBig | p->mallocFailed ){
721 return;
722 }
723 if( N<0 ){
724 N = strlen(z);
725 }
726 if( N==0 ){
727 return;
728 }
729 if( p->nChar+N >= p->nAlloc ){
730 char *zNew;
731 if( !p->useMalloc ){
732 p->tooBig = 1;
733 N = p->nAlloc - p->nChar - 1;
734 if( N<=0 ){
735 return;
736 }
737 }else{
drhb1a6c3c2008-03-20 16:30:17 +0000738 i64 szNew = p->nAlloc;
739 szNew += N + 1;
740 if( szNew > p->mxAlloc ){
drhbb4957f2008-03-20 14:03:29 +0000741 p->nAlloc = p->mxAlloc;
drhb1a6c3c2008-03-20 16:30:17 +0000742 if( ((i64)p->nChar)+((i64)N) >= p->nAlloc ){
drhade86482007-11-28 22:36:40 +0000743 sqlite3StrAccumReset(p);
744 p->tooBig = 1;
745 return;
drh17435752007-08-16 04:30:38 +0000746 }
drhb1a6c3c2008-03-20 16:30:17 +0000747 }else{
748 p->nAlloc = szNew;
drh17435752007-08-16 04:30:38 +0000749 }
drhade86482007-11-28 22:36:40 +0000750 zNew = sqlite3_malloc( p->nAlloc );
drh53f733c2005-09-16 02:38:09 +0000751 if( zNew ){
drhade86482007-11-28 22:36:40 +0000752 memcpy(zNew, p->zText, p->nChar);
753 sqlite3StrAccumReset(p);
754 p->zText = zNew;
755 }else{
756 p->mallocFailed = 1;
757 sqlite3StrAccumReset(p);
758 return;
drh53f733c2005-09-16 02:38:09 +0000759 }
drh5f968432004-02-21 19:02:30 +0000760 }
761 }
drhade86482007-11-28 22:36:40 +0000762 memcpy(&p->zText[p->nChar], z, N);
763 p->nChar += N;
drh483750b2003-01-29 18:46:51 +0000764}
765
766/*
drhade86482007-11-28 22:36:40 +0000767** Finish off a string by making sure it is zero-terminated.
768** Return a pointer to the resulting string. Return a NULL
769** pointer if any kind of error was encountered.
drh5f968432004-02-21 19:02:30 +0000770*/
drhade86482007-11-28 22:36:40 +0000771char *sqlite3StrAccumFinish(StrAccum *p){
772 if( p->zText ){
773 p->zText[p->nChar] = 0;
774 if( p->useMalloc && p->zText==p->zBase ){
775 p->zText = sqlite3_malloc( p->nChar+1 );
776 if( p->zText ){
777 memcpy(p->zText, p->zBase, p->nChar+1);
778 }else{
779 p->mallocFailed = 1;
780 }
781 }
782 }
783 return p->zText;
784}
785
786/*
787** Reset an StrAccum string. Reclaim all malloced memory.
788*/
789void sqlite3StrAccumReset(StrAccum *p){
790 if( p->zText!=p->zBase ){
791 sqlite3_free(p->zText);
792 p->zText = 0;
793 }
794}
795
796/*
797** Initialize a string accumulator
798*/
drhbb4957f2008-03-20 14:03:29 +0000799static void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){
drhade86482007-11-28 22:36:40 +0000800 p->zText = p->zBase = zBase;
801 p->nChar = 0;
802 p->nAlloc = n;
drhbb4957f2008-03-20 14:03:29 +0000803 p->mxAlloc = mx;
drhade86482007-11-28 22:36:40 +0000804 p->useMalloc = 1;
805 p->tooBig = 0;
806 p->mallocFailed = 0;
drh5f968432004-02-21 19:02:30 +0000807}
808
809/*
810** Print into memory obtained from sqliteMalloc(). Use the internal
811** %-conversion extensions.
812*/
drh17435752007-08-16 04:30:38 +0000813char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
814 char *z;
drh79158e12005-09-06 21:40:45 +0000815 char zBase[SQLITE_PRINT_BUF_SIZE];
drhade86482007-11-28 22:36:40 +0000816 StrAccum acc;
drhbb4957f2008-03-20 14:03:29 +0000817 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
818 db ? db->aLimit[SQLITE_LIMIT_LENGTH] : SQLITE_MAX_LENGTH);
drhade86482007-11-28 22:36:40 +0000819 vxprintf(&acc, 1, zFormat, ap);
820 z = sqlite3StrAccumFinish(&acc);
821 if( acc.mallocFailed && db ){
drh17435752007-08-16 04:30:38 +0000822 db->mallocFailed = 1;
823 }
824 return z;
drh5f968432004-02-21 19:02:30 +0000825}
826
827/*
828** Print into memory obtained from sqliteMalloc(). Use the internal
829** %-conversion extensions.
830*/
drh17435752007-08-16 04:30:38 +0000831char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){
drh5f968432004-02-21 19:02:30 +0000832 va_list ap;
833 char *z;
drh5f968432004-02-21 19:02:30 +0000834 va_start(ap, zFormat);
drhade86482007-11-28 22:36:40 +0000835 z = sqlite3VMPrintf(db, zFormat, ap);
drh5f968432004-02-21 19:02:30 +0000836 va_end(ap);
837 return z;
838}
839
840/*
drh28dd4792006-06-26 21:35:44 +0000841** Print into memory obtained from sqlite3_malloc(). Omit the internal
842** %-conversion extensions.
843*/
844char *sqlite3_vmprintf(const char *zFormat, va_list ap){
drhade86482007-11-28 22:36:40 +0000845 char *z;
drh28dd4792006-06-26 21:35:44 +0000846 char zBase[SQLITE_PRINT_BUF_SIZE];
drhade86482007-11-28 22:36:40 +0000847 StrAccum acc;
drhbb4957f2008-03-20 14:03:29 +0000848 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
drhade86482007-11-28 22:36:40 +0000849 vxprintf(&acc, 0, zFormat, ap);
850 z = sqlite3StrAccumFinish(&acc);
851 return z;
drh28dd4792006-06-26 21:35:44 +0000852}
853
854/*
855** Print into memory obtained from sqlite3_malloc()(). Omit the internal
856** %-conversion extensions.
drh483750b2003-01-29 18:46:51 +0000857*/
danielk19776f8a5032004-05-10 10:34:51 +0000858char *sqlite3_mprintf(const char *zFormat, ...){
drha18c5682000-10-08 22:20:57 +0000859 va_list ap;
drh5f968432004-02-21 19:02:30 +0000860 char *z;
drh28dd4792006-06-26 21:35:44 +0000861 va_start(ap, zFormat);
drhb3738b62007-03-31 15:02:49 +0000862 z = sqlite3_vmprintf(zFormat, ap);
drha18c5682000-10-08 22:20:57 +0000863 va_end(ap);
drh5f968432004-02-21 19:02:30 +0000864 return z;
drha18c5682000-10-08 22:20:57 +0000865}
866
drh93a5c6b2003-12-23 02:17:35 +0000867/*
danielk19776f8a5032004-05-10 10:34:51 +0000868** sqlite3_snprintf() works like snprintf() except that it ignores the
drh93a5c6b2003-12-23 02:17:35 +0000869** current locale settings. This is important for SQLite because we
870** are not able to use a "," as the decimal point in place of "." as
871** specified by some locales.
872*/
danielk19776f8a5032004-05-10 10:34:51 +0000873char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
drh5f968432004-02-21 19:02:30 +0000874 char *z;
drh93a5c6b2003-12-23 02:17:35 +0000875 va_list ap;
drhade86482007-11-28 22:36:40 +0000876 StrAccum acc;
drh93a5c6b2003-12-23 02:17:35 +0000877
drh68853902007-05-07 11:24:30 +0000878 if( n<=0 ){
879 return zBuf;
880 }
drhbb4957f2008-03-20 14:03:29 +0000881 sqlite3StrAccumInit(&acc, zBuf, n, 0);
drhade86482007-11-28 22:36:40 +0000882 acc.useMalloc = 0;
drh93a5c6b2003-12-23 02:17:35 +0000883 va_start(ap,zFormat);
drhade86482007-11-28 22:36:40 +0000884 vxprintf(&acc, 0, zFormat, ap);
drh93a5c6b2003-12-23 02:17:35 +0000885 va_end(ap);
drhade86482007-11-28 22:36:40 +0000886 z = sqlite3StrAccumFinish(&acc);
drh5f968432004-02-21 19:02:30 +0000887 return z;
drh93a5c6b2003-12-23 02:17:35 +0000888}
889
drh7d7f17b2007-06-15 20:29:20 +0000890#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) || defined(SQLITE_MEMDEBUG)
drhe54ca3f2004-06-07 01:52:14 +0000891/*
892** A version of printf() that understands %lld. Used for debugging.
893** The printf() built into some versions of windows does not understand %lld
894** and segfaults if you give it a long long int.
895*/
896void sqlite3DebugPrintf(const char *zFormat, ...){
897 va_list ap;
drhade86482007-11-28 22:36:40 +0000898 StrAccum acc;
drhe54ca3f2004-06-07 01:52:14 +0000899 char zBuf[500];
drhbb4957f2008-03-20 14:03:29 +0000900 sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
drhade86482007-11-28 22:36:40 +0000901 acc.useMalloc = 0;
902 va_start(ap,zFormat);
903 vxprintf(&acc, 0, zFormat, ap);
drhe54ca3f2004-06-07 01:52:14 +0000904 va_end(ap);
drhbed8e7e2007-12-08 17:55:35 +0000905 sqlite3StrAccumFinish(&acc);
drh485f0032007-01-26 19:23:33 +0000906 fprintf(stdout,"%s", zBuf);
drh2ac3ee92004-06-07 16:27:46 +0000907 fflush(stdout);
drhe54ca3f2004-06-07 01:52:14 +0000908}
909#endif