engine/sqlite/src/printf.cpp
author skip
Thu, 25 Feb 2010 14:29:19 +0000
changeset 2 29cda98b007e
permissions -rw-r--r--
Initial import of Podcatcher from the Bergamot project
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     1
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     2
** The "printf" code that follows dates from the 1980's.  It is in
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     3
** the public domain.  The original comments are included here for
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     4
** completeness.  They are very out-of-date but might be useful as
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     5
** an historical reference.  Most of the "enhancements" have been backed
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     6
** out so that the functionality is now the same as standard printf().
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     7
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     8
**************************************************************************
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     9
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    10
** The following modules is an enhanced replacement for the "printf" subroutines
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    11
** found in the standard C library.  The following enhancements are
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    12
** supported:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    13
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
**      +  Additional functions.  The standard set of "printf" functions
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    15
**         includes printf, fprintf, sprintf, vprintf, vfprintf, and
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    16
**         vsprintf.  This module adds the following:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    17
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    18
**           *  snprintf -- Works like sprintf, but has an extra argument
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    19
**                          which is the size of the buffer written to.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    20
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
**           *  mprintf --  Similar to sprintf.  Writes output to memory
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
**                          obtained from malloc.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
**           *  xprintf --  Calls a function to dispose of output.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
**           *  nprintf --  No output, but returns the number of characters
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    27
**                          that would have been output by printf.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
**           *  A v- version (ex: vsnprintf) of every function is also
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
**              supplied.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
**      +  A few extensions to the formatting notation are supported:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
**           *  The "=" flag (similar to "-") causes the output to be
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
**              be centered in the appropriately sized field.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
**           *  The %b field outputs an integer in binary notation.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
**           *  The %c field now accepts a precision.  The character output
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
**              is repeated by the number of times the precision specifies.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
**           *  The %' field works like %c, but takes as its character the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
**              next character of the format string, instead of the next
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
**              argument.  For example,  printf("%.78'-")  prints 78 minus
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
**              signs, the same as  printf("%.78c",'-').
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
**      +  When compiled using GCC on a SPARC, this version of printf is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
**         faster than the library printf for SUN OS 4.1.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
**      +  All functions are fully reentrant.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
#include "sqliteInt.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
** Conversion types fall into various categories as defined by the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
** following enumeration.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
#define etRADIX       1 /* Integer types.  %d, %x, %o, and so forth */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
#define etFLOAT       2 /* Floating point.  %f */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
#define etEXP         3 /* Exponentional notation. %e and %E */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
#define etGENERIC     4 /* Floating or exponential, depending on exponent. %g */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
#define etSIZE        5 /* Return number of characters processed so far. %n */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
#define etSTRING      6 /* Strings. %s */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
#define etDYNSTRING   7 /* Dynamically allocated strings. %z */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
#define etPERCENT     8 /* Percent symbol. %% */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
#define etCHARX       9 /* Characters. %c */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
/* The rest are extensions, not normally found in printf() */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
#define etCHARLIT    10 /* Literal characters.  %' */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
#define etSQLESCAPE  11 /* Strings with '\'' doubled.  %q */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
#define etSQLESCAPE2 12 /* Strings with '\'' doubled and enclosed in '',
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
                          NULL pointers replaced by SQL NULL.  %Q */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
#define etTOKEN      13 /* a pointer to a Token structure */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
#define etSRCLIST    14 /* a pointer to a SrcList */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
#define etPOINTER    15 /* The %p conversion */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    76
#define etSQLESCAPE3 16 /* %w -> Strings with '\"' doubled */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
#define etORDINAL    17 /* %r -> 1st, 2nd, 3rd, 4th, etc.  English only */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
** An "etByte" is an 8-bit unsigned value.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
typedef unsigned char etByte;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
** Each builtin conversion character (ex: the 'd' in "%d") is described
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
** by an instance of the following structure
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
typedef struct et_info {   /* Information about each format field */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
  char fmttype;            /* The format field code letter */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
  etByte base;             /* The base for radix conversion */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
  etByte flags;            /* One or more of FLAG_ constants below */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
  etByte type;             /* Conversion paradigm */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
  etByte charset;          /* Offset into aDigits[] of the digits string */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
  etByte prefix;           /* Offset into aPrefix[] of the prefix string */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
} et_info;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
** Allowed values for et_info.flags
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
#define FLAG_SIGNED  1     /* True if the value to convert is signed */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
#define FLAG_INTERN  2     /* True if for internal use only */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
#define FLAG_STRING  4     /* Allow infinity precision */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
** The following table is searched linearly, so it is good to put the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
** most frequently used conversion types first.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
static const char aDigits[] = "0123456789ABCDEF0123456789abcdef";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
static const char aPrefix[] = "-x0\000X0";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
static const et_info fmtinfo[] = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
  {  'd', 10, 1, etRADIX,      0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
  {  's',  0, 4, etSTRING,     0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
  {  'g',  0, 1, etGENERIC,    30, 0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
  {  'z',  0, 4, etDYNSTRING,  0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
  {  'q',  0, 4, etSQLESCAPE,  0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
  {  'Q',  0, 4, etSQLESCAPE2, 0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
  {  'w',  0, 4, etSQLESCAPE3, 0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
  {  'c',  0, 0, etCHARX,      0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
  {  'o',  8, 0, etRADIX,      0,  2 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
  {  'u', 10, 0, etRADIX,      0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
  {  'x', 16, 0, etRADIX,      16, 1 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
  {  'X', 16, 0, etRADIX,      0,  4 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
#ifndef SQLITE_OMIT_FLOATING_POINT
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
  {  'f',  0, 1, etFLOAT,      0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
  {  'e',  0, 1, etEXP,        30, 0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
  {  'E',  0, 1, etEXP,        14, 0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
  {  'G',  0, 1, etGENERIC,    14, 0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
  {  'i', 10, 1, etRADIX,      0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
  {  'n',  0, 0, etSIZE,       0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
  {  '%',  0, 0, etPERCENT,    0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
  {  'p', 16, 0, etPOINTER,    0,  1 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
  {  'T',  0, 2, etTOKEN,      0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
  {  'S',  0, 2, etSRCLIST,    0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
  {  'r', 10, 3, etORDINAL,    0,  0 },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
};
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
#define etNINFO  (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   140
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
** conversions will work.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   145
#ifndef SQLITE_OMIT_FLOATING_POINT
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
** "*val" is a double such that 0.1 <= *val < 10.0
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
** Return the ascii code for the leading digit of *val, then
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   149
** multiply "*val" by 10.0 to renormalize.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
** Example:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
**     input:     *val = 3.14159
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
**     output:    *val = 1.4159    function return = '3'
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
** The counter *cnt is incremented each time.  After counter exceeds
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
** 16 (the number of significant digits in a 64-bit float) '0' is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
** always returned.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
static int et_getdigit(LONGDOUBLE_TYPE *val, int *cnt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   160
  int digit;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
  LONGDOUBLE_TYPE d;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
  if( (*cnt)++ >= 16 ) return '0';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
  digit = (int)*val;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
  d = digit;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
  digit += '0';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
  *val = (*val - d)*10.0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
  return digit;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
#endif /* SQLITE_OMIT_FLOATING_POINT */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
** Append N space characters to the given string buffer.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
static void appendSpace(StrAccum *pAccum, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
  static const char zSpaces[] = "                             ";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
  while( N>=sizeof(zSpaces)-1 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
    sqlite3StrAccumAppend(pAccum, zSpaces, sizeof(zSpaces)-1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
    N -= sizeof(zSpaces)-1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
  if( N>0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
    sqlite3StrAccumAppend(pAccum, zSpaces, N);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
** On machines with a small stack size, you can redefine the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   187
** SQLITE_PRINT_BUF_SIZE to be less than 350.  But beware - for
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   188
** smaller values some %f conversions may go into an infinite loop.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   189
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
#ifndef SQLITE_PRINT_BUF_SIZE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
# define SQLITE_PRINT_BUF_SIZE 350
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
#define etBUFSIZE SQLITE_PRINT_BUF_SIZE  /* Size of the output buffer */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
** The root program.  All variations call this core.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
** INPUTS:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
**   func   This is a pointer to a function taking three arguments
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
**            1. A pointer to anything.  Same as the "arg" parameter.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
**            2. A pointer to the list of characters to be output
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   202
**               (Note, this list is NOT null terminated.)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   203
**            3. An integer number of characters to be output.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   204
**               (Note: This number might be zero.)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
**   arg    This is the pointer to anything which will be passed as the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
**          first argument to "func".  Use it for whatever you like.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
**   fmt    This is the format string, as in the usual print.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   211
**   ap     This is a pointer to a list of arguments.  Same as in
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   212
**          vfprint.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
** OUTPUTS:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
**          The return value is the total number of characters sent to
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
**          the function "func".  Returns -1 on a error.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
** Note that the order in which automatic variables are declared below
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
** seems to make a big difference in determining how fast this beast
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
** will run.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
static void vxprintf(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
  StrAccum *pAccum,                  /* Accumulate results here */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
  int useExtended,                   /* Allow extended %-conversions */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
  const char *fmt,                   /* Format string */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
  va_list ap                         /* arguments */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
  int c;                     /* Next character in the format string */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
  char *bufpt;               /* Pointer to the conversion buffer */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
  int precision;             /* Precision of the current field */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
  int length;                /* Length of the field */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
  int idx;                   /* A general purpose loop counter */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
  int width;                 /* Width of the current field */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
  etByte flag_leftjustify;   /* True if "-" flag is present */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
  etByte flag_plussign;      /* True if "+" flag is present */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
  etByte flag_blanksign;     /* True if " " flag is present */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
  etByte flag_alternateform; /* True if "#" flag is present */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
  etByte flag_altform2;      /* True if "!" flag is present */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
  etByte flag_zeropad;       /* True if field width constant starts with zero */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
  etByte flag_long;          /* True if "l" flag is present */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
  etByte flag_longlong;      /* True if the "ll" flag is present */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
  etByte done;               /* Loop termination flag */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
  sqlite_uint64 longvalue;   /* Value for integer types */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
  LONGDOUBLE_TYPE realvalue; /* Value for real types */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
  const et_info *infop;      /* Pointer to the appropriate info structure */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
  char buf[etBUFSIZE];       /* Conversion buffer */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
  char prefix;               /* Prefix character.  "+" or "-" or " " or '\0'. */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
  etByte errorflag = 0;      /* True if an error is encountered */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
  etByte xtype;              /* Conversion paradigm */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
  char *zExtra;              /* Extra memory used for etTCLESCAPE conversions */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
#ifndef SQLITE_OMIT_FLOATING_POINT
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
  int  exp, e2;              /* exponent of real numbers */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
  double rounder;            /* Used for rounding floating point values */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
  etByte flag_dp;            /* True if decimal point should be shown */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
  etByte flag_rtz;           /* True if trailing zeros should be removed */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
  etByte flag_exp;           /* True to force display of the exponent */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
  int nsd;                   /* Number of significant digits returned */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
  length = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
  bufpt = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
  for(; (c=(*fmt))!=0; ++fmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
    if( c!='%' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
      int amt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
      bufpt = (char *)fmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
      amt = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
      while( (c=(*++fmt))!='%' && c!=0 ) amt++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
      sqlite3StrAccumAppend(pAccum, bufpt, amt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
      if( c==0 ) break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
    if( (c=(*++fmt))==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
      errorflag = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
      sqlite3StrAccumAppend(pAccum, "%", 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
      break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
    /* Find out what flags are present */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
    flag_leftjustify = flag_plussign = flag_blanksign = 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
     flag_alternateform = flag_altform2 = flag_zeropad = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
    done = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
    do{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
      switch( c ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
        case '-':   flag_leftjustify = 1;     break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
        case '+':   flag_plussign = 1;        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   284
        case ' ':   flag_blanksign = 1;       break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   285
        case '#':   flag_alternateform = 1;   break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   286
        case '!':   flag_altform2 = 1;        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
        case '0':   flag_zeropad = 1;         break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
        default:    done = 1;                 break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
    }while( !done && (c=(*++fmt))!=0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
    /* Get the field width */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
    width = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
    if( c=='*' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
      width = va_arg(ap,int);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
      if( width<0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
        flag_leftjustify = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
        width = -width;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
      c = *++fmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
      while( c>='0' && c<='9' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
        width = width*10 + c - '0';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
        c = *++fmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   306
    if( width > etBUFSIZE-10 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   307
      width = etBUFSIZE-10;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   309
    /* Get the precision */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
    if( c=='.' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   311
      precision = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
      c = *++fmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
      if( c=='*' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
        precision = va_arg(ap,int);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   315
        if( precision<0 ) precision = -precision;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
        c = *++fmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
      }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   318
        while( c>='0' && c<='9' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   319
          precision = precision*10 + c - '0';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   320
          c = *++fmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   321
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   322
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   323
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
      precision = -1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
    /* Get the conversion type modifier */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   327
    if( c=='l' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   328
      flag_long = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   329
      c = *++fmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   330
      if( c=='l' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   331
        flag_longlong = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   332
        c = *++fmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   333
      }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   334
        flag_longlong = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   335
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   336
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
      flag_long = flag_longlong = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   338
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   339
    /* Fetch the info entry for the field */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   340
    infop = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   341
    for(idx=0; idx<etNINFO; idx++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   342
      if( c==fmtinfo[idx].fmttype ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   343
        infop = &fmtinfo[idx];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   344
        if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   345
          xtype = infop->type;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   346
        }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   347
          return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   348
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   349
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   350
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   351
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   352
    zExtra = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   353
    if( infop==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   354
      return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   355
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   356
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   357
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   358
    /* Limit the precision to prevent overflowing buf[] during conversion */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   359
    if( precision>etBUFSIZE-40 && (infop->flags & FLAG_STRING)==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
      precision = etBUFSIZE-40;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   361
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   363
    /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   364
    ** At this point, variables are initialized as follows:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   365
    **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   366
    **   flag_alternateform          TRUE if a '#' is present.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   367
    **   flag_altform2               TRUE if a '!' is present.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   368
    **   flag_plussign               TRUE if a '+' is present.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   369
    **   flag_leftjustify            TRUE if a '-' is present or if the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   370
    **                               field width was negative.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   371
    **   flag_zeropad                TRUE if the width began with 0.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   372
    **   flag_long                   TRUE if the letter 'l' (ell) prefixed
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   373
    **                               the conversion character.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
    **   flag_longlong               TRUE if the letter 'll' (ell ell) prefixed
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
    **                               the conversion character.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   376
    **   flag_blanksign              TRUE if a ' ' is present.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   377
    **   width                       The specified field width.  This is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   378
    **                               always non-negative.  Zero is the default.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   379
    **   precision                   The specified precision.  The default
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   380
    **                               is -1.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   381
    **   xtype                       The class of the conversion.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   382
    **   infop                       Pointer to the appropriate info struct.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   383
    */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   384
    switch( xtype ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   385
      case etPOINTER:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   386
        flag_longlong = sizeof(char*)==sizeof(i64);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   387
        flag_long = sizeof(char*)==sizeof(long int);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   388
        /* Fall through into the next case */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   389
      case etORDINAL:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   390
      case etRADIX:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   391
        if( infop->flags & FLAG_SIGNED ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   392
          i64 v;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   393
          if( flag_longlong )   v = va_arg(ap,i64);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   394
          else if( flag_long )  v = va_arg(ap,long int);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   395
          else                  v = va_arg(ap,int);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   396
          if( v<0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   397
            longvalue = -v;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   398
            prefix = '-';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   399
          }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   400
            longvalue = v;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   401
            if( flag_plussign )        prefix = '+';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
            else if( flag_blanksign )  prefix = ' ';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   403
            else                       prefix = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   405
        }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   406
          if( flag_longlong )   longvalue = va_arg(ap,u64);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   407
          else if( flag_long )  longvalue = va_arg(ap,unsigned long int);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   408
          else                  longvalue = va_arg(ap,unsigned int);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   409
          prefix = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   410
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   411
        if( longvalue==0 ) flag_alternateform = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   412
        if( flag_zeropad && precision<width-(prefix!=0) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   413
          precision = width-(prefix!=0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   414
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   415
        bufpt = &buf[etBUFSIZE-1];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   416
        if( xtype==etORDINAL ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   417
          static const char zOrd[] = "thstndrd";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   418
          int x = longvalue % 10;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   419
          if( x>=4 || (longvalue/10)%10==1 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
            x = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   422
          buf[etBUFSIZE-3] = zOrd[x*2];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   423
          buf[etBUFSIZE-2] = zOrd[x*2+1];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   424
          bufpt -= 2;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   425
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   426
        {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   427
          register const char *cset;      /* Use registers for speed */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   428
          register int base;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   429
          cset = &aDigits[infop->charset];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   430
          base = infop->base;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   431
          do{                                           /* Convert to ascii */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   432
            *(--bufpt) = cset[longvalue%base];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   433
            longvalue = longvalue/base;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   434
          }while( longvalue>0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   435
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
        length = &buf[etBUFSIZE-1]-bufpt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   437
        for(idx=precision-length; idx>0; idx--){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   438
          *(--bufpt) = '0';                             /* Zero pad */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   439
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   440
        if( prefix ) *(--bufpt) = prefix;               /* Add sign */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   441
        if( flag_alternateform && infop->prefix ){      /* Add "0" or "0x" */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
          const char *pre;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   443
          char x;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   444
          pre = &aPrefix[infop->prefix];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   445
          if( *bufpt!=pre[0] ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   446
            for(; (x=(*pre))!=0; pre++) *(--bufpt) = x;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   447
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   449
        length = &buf[etBUFSIZE-1]-bufpt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   450
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   451
      case etFLOAT:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   452
      case etEXP:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   453
      case etGENERIC:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   454
        realvalue = va_arg(ap,double);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   455
#ifndef SQLITE_OMIT_FLOATING_POINT
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   456
        if( precision<0 ) precision = 6;         /* Set default precision */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   457
        if( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   458
        if( realvalue<0.0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   459
          realvalue = -realvalue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   460
          prefix = '-';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   461
        }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   462
          if( flag_plussign )          prefix = '+';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   463
          else if( flag_blanksign )    prefix = ' ';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   464
          else                         prefix = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   465
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   466
        if( xtype==etGENERIC && precision>0 ) precision--;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   467
#if 0
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   468
        /* Rounding works like BSD when the constant 0.4999 is used.  Wierd! */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   469
        for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   470
#else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   471
        /* It makes more sense to use 0.5 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   472
        for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1){}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   473
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   474
        if( xtype==etFLOAT ) realvalue += rounder;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   475
        /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   476
        exp = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   477
        if( sqlite3_isnan(realvalue) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   478
          bufpt = "NaN";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   479
          length = 3;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   480
          break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   481
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   482
        if( realvalue>0.0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   483
          while( realvalue>=1e32 && exp<=350 ){ realvalue *= 1e-32; exp+=32; }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   484
          while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   485
          while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   486
          while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   487
          while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   488
          if( exp>350 || exp<-350 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   489
            if( prefix=='-' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   490
              bufpt = "-Inf";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   491
            }else if( prefix=='+' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   492
              bufpt = "+Inf";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   493
            }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   494
              bufpt = "Inf";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   495
            }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   496
            length = strlen(bufpt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   497
            break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   498
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   499
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   500
        bufpt = buf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   501
        /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   502
        ** If the field type is etGENERIC, then convert to either etEXP
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   503
        ** or etFLOAT, as appropriate.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   504
        */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   505
        flag_exp = xtype==etEXP;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   506
        if( xtype!=etFLOAT ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   507
          realvalue += rounder;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   508
          if( realvalue>=10.0 ){ realvalue *= 0.1; exp++; }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   509
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   510
        if( xtype==etGENERIC ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   511
          flag_rtz = !flag_alternateform;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   512
          if( exp<-4 || exp>precision ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   513
            xtype = etEXP;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   514
          }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   515
            precision = precision - exp;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   516
            xtype = etFLOAT;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   517
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   518
        }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   519
          flag_rtz = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   520
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   521
        if( xtype==etEXP ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   522
          e2 = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   523
        }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   524
          e2 = exp;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   525
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   526
        nsd = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   527
        flag_dp = (precision>0) | flag_alternateform | flag_altform2;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   528
        /* The sign in front of the number */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   529
        if( prefix ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   530
          *(bufpt++) = prefix;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   531
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   532
        /* Digits prior to the decimal point */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   533
        if( e2<0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   534
          *(bufpt++) = '0';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   535
        }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   536
          for(; e2>=0; e2--){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   537
            *(bufpt++) = et_getdigit(&realvalue,&nsd);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   538
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   539
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   540
        /* The decimal point */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   541
        if( flag_dp ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   542
          *(bufpt++) = '.';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   543
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   544
        /* "0" digits after the decimal point but before the first
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   545
        ** significant digit of the number */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   546
        for(e2++; e2<0 && precision>0; precision--, e2++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   547
          *(bufpt++) = '0';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   548
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   549
        /* Significant digits after the decimal point */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   550
        while( (precision--)>0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   551
          *(bufpt++) = et_getdigit(&realvalue,&nsd);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   552
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   553
        /* Remove trailing zeros and the "." if no digits follow the "." */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   554
        if( flag_rtz && flag_dp ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   555
          while( bufpt[-1]=='0' ) *(--bufpt) = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   556
          assert( bufpt>buf );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   557
          if( bufpt[-1]=='.' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   558
            if( flag_altform2 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   559
              *(bufpt++) = '0';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   560
            }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   561
              *(--bufpt) = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   562
            }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   563
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   564
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   565
        /* Add the "eNNN" suffix */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   566
        if( flag_exp || (xtype==etEXP && exp) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   567
          *(bufpt++) = aDigits[infop->charset];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   568
          if( exp<0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   569
            *(bufpt++) = '-'; exp = -exp;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   570
          }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   571
            *(bufpt++) = '+';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   572
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   573
          if( exp>=100 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   574
            *(bufpt++) = (exp/100)+'0';                /* 100's digit */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   575
            exp %= 100;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   576
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   577
          *(bufpt++) = exp/10+'0';                     /* 10's digit */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   578
          *(bufpt++) = exp%10+'0';                     /* 1's digit */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   579
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   580
        *bufpt = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   581
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   582
        /* The converted number is in buf[] and zero terminated. Output it.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   583
        ** Note that the number is in the usual order, not reversed as with
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   584
        ** integer conversions. */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   585
        length = bufpt-buf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   586
        bufpt = buf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   587
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   588
        /* Special case:  Add leading zeros if the flag_zeropad flag is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   589
        ** set and we are not left justified */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   590
        if( flag_zeropad && !flag_leftjustify && length < width){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   591
          int i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   592
          int nPad = width - length;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   593
          for(i=width; i>=nPad; i--){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   594
            bufpt[i] = bufpt[i-nPad];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   595
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   596
          i = prefix!=0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   597
          while( nPad-- ) bufpt[i++] = '0';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   598
          length = width;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   599
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   600
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   601
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   602
      case etSIZE:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   603
        *(va_arg(ap,int*)) = pAccum->nChar;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   604
        length = width = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   605
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   606
      case etPERCENT:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   607
        buf[0] = '%';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   608
        bufpt = buf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   609
        length = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   610
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   611
      case etCHARLIT:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   612
      case etCHARX:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   613
        c = buf[0] = (xtype==etCHARX ? va_arg(ap,int) : *++fmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   614
        if( precision>=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   615
          for(idx=1; idx<precision; idx++) buf[idx] = c;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   616
          length = precision;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   617
        }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   618
          length =1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   619
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   620
        bufpt = buf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   621
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   622
      case etSTRING:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   623
      case etDYNSTRING:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   624
        bufpt = va_arg(ap,char*);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   625
        if( bufpt==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   626
          bufpt = "";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   627
        }else if( xtype==etDYNSTRING ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   628
          zExtra = bufpt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   629
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   630
        length = strlen(bufpt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   631
        if( precision>=0 && precision<length ) length = precision;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   632
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   633
      case etSQLESCAPE:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   634
      case etSQLESCAPE2:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   635
      case etSQLESCAPE3: {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   636
        int i, j, n, ch, isnull;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   637
        int needQuote;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   638
        char q = ((xtype==etSQLESCAPE3)?'"':'\'');   /* Quote character */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   639
        char *escarg = va_arg(ap,char*);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   640
        isnull = escarg==0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   641
        if( isnull ) escarg = (char*)(xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   642
        for(i=n=0; (ch=escarg[i])!=0; i++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   643
          if( ch==q )  n++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   644
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   645
        needQuote = !isnull && xtype==etSQLESCAPE2;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   646
        n += i + 1 + needQuote*2;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   647
        if( n>etBUFSIZE ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   648
          bufpt = zExtra = (char*)sqlite3_malloc( n );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   649
          if( bufpt==0 ) return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   650
        }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   651
          bufpt = buf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   652
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   653
        j = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   654
        if( needQuote ) bufpt[j++] = q;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   655
        for(i=0; (ch=escarg[i])!=0; i++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   656
          bufpt[j++] = ch;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   657
          if( ch==q ) bufpt[j++] = ch;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   658
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   659
        if( needQuote ) bufpt[j++] = q;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   660
        bufpt[j] = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   661
        length = j;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   662
        /* The precision is ignored on %q and %Q */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   663
        /* if( precision>=0 && precision<length ) length = precision; */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   664
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   665
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   666
      case etTOKEN: {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   667
        Token *pToken = va_arg(ap, Token*);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   668
        if( pToken && pToken->z ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   669
          sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   670
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   671
        length = width = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   672
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   673
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   674
      case etSRCLIST: {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   675
        SrcList *pSrc = va_arg(ap, SrcList*);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   676
        int k = va_arg(ap, int);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   677
		SrcList::SrcList_item *pItem = &pSrc->a[k];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   678
        assert( k>=0 && k<pSrc->nSrc );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   679
        if( pItem->zDatabase && pItem->zDatabase[0] ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   680
          sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   681
          sqlite3StrAccumAppend(pAccum, ".", 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   682
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   683
        sqlite3StrAccumAppend(pAccum, pItem->zName, -1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   684
        length = width = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   685
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   686
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   687
    }/* End switch over the format type */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   688
    /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   689
    ** The text of the conversion is pointed to by "bufpt" and is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   690
    ** "length" characters long.  The field width is "width".  Do
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   691
    ** the output.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   692
    */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   693
    if( !flag_leftjustify ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   694
      register int nspace;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   695
      nspace = width-length;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   696
      if( nspace>0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   697
        appendSpace(pAccum, nspace);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   698
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   699
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   700
    if( length>0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   701
      sqlite3StrAccumAppend(pAccum, bufpt, length);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   702
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   703
    if( flag_leftjustify ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   704
      register int nspace;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   705
      nspace = width-length;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   706
      if( nspace>0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   707
        appendSpace(pAccum, nspace);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   708
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   709
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   710
    if( zExtra ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   711
      sqlite3_free(zExtra);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   712
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   713
  }/* End for loop over the format string */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   714
} /* End of function */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   715
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   716
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   717
** Append N bytes of text from z to the StrAccum object.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   718
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   719
void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   720
  if( p->tooBig | p->mallocFailed ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   721
    return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   722
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   723
  if( N<0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   724
    N = strlen(z);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   725
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   726
  if( N==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   727
    return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   728
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   729
  if( p->nChar+N >= p->nAlloc ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   730
    char *zNew;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   731
    if( !p->useMalloc ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   732
      p->tooBig = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   733
      N = p->nAlloc - p->nChar - 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   734
      if( N<=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   735
        return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   736
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   737
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   738
      p->nAlloc += p->nAlloc + N + 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   739
      if( p->nAlloc > SQLITE_MAX_LENGTH ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   740
        p->nAlloc = SQLITE_MAX_LENGTH;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   741
        if( p->nChar+N >= p->nAlloc ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   742
          sqlite3StrAccumReset(p);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   743
          p->tooBig = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   744
          return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   745
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   746
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   747
      zNew = (char*)sqlite3_malloc( p->nAlloc );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   748
      if( zNew ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   749
        memcpy(zNew, p->zText, p->nChar);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   750
        sqlite3StrAccumReset(p);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   751
        p->zText = zNew;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   752
      }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   753
        p->mallocFailed = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   754
        sqlite3StrAccumReset(p);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   755
        return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   756
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   757
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   758
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   759
  memcpy(&p->zText[p->nChar], z, N);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   760
  p->nChar += N;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   761
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   762
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   763
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   764
** Finish off a string by making sure it is zero-terminated.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   765
** Return a pointer to the resulting string.  Return a NULL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   766
** pointer if any kind of error was encountered.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   767
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   768
char *sqlite3StrAccumFinish(StrAccum *p){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   769
  if( p->zText ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   770
    p->zText[p->nChar] = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   771
    if( p->useMalloc && p->zText==p->zBase ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   772
      p->zText = (char*)sqlite3_malloc( p->nChar+1 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   773
      if( p->zText ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   774
        memcpy(p->zText, p->zBase, p->nChar+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   775
      }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   776
        p->mallocFailed = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   777
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   778
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   779
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   780
  return p->zText;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   781
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   782
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   783
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   784
** Reset an StrAccum string.  Reclaim all malloced memory.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   785
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   786
void sqlite3StrAccumReset(StrAccum *p){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   787
  if( p->zText!=p->zBase ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   788
    sqlite3_free(p->zText);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   789
    p->zText = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   790
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   791
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   792
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   793
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   794
** Initialize a string accumulator
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   795
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   796
static void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   797
  p->zText = p->zBase = zBase;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   798
  p->nChar = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   799
  p->nAlloc = n;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   800
  p->useMalloc = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   801
  p->tooBig = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   802
  p->mallocFailed = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   803
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   804
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   805
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   806
** Print into memory obtained from sqliteMalloc().  Use the internal
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   807
** %-conversion extensions.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   808
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   809
char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   810
  char *z;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   811
  char zBase[SQLITE_PRINT_BUF_SIZE];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   812
  StrAccum acc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   813
  sqlite3StrAccumInit(&acc, zBase, sizeof(zBase));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   814
  vxprintf(&acc, 1, zFormat, ap);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   815
  z = sqlite3StrAccumFinish(&acc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   816
  if( acc.mallocFailed && db ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   817
    db->mallocFailed = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   818
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   819
  return z;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   820
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   821
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   822
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   823
** Print into memory obtained from sqliteMalloc().  Use the internal
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   824
** %-conversion extensions.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   825
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   826
char *sqlite3MPrintf(sqlite3 *db, const char *zFormat, ...){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   827
  va_list ap;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   828
  char *z;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   829
  va_start(ap, zFormat);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   830
  z = sqlite3VMPrintf(db, zFormat, ap);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   831
  va_end(ap);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   832
  return z;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   833
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   834
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   835
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   836
** Print into memory obtained from sqlite3_malloc().  Omit the internal
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   837
** %-conversion extensions.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   838
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   839
EXPORT_C char *sqlite3_vmprintf(const char *zFormat, va_list ap){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   840
  char *z;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   841
  char zBase[SQLITE_PRINT_BUF_SIZE];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   842
  StrAccum acc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   843
  sqlite3StrAccumInit(&acc, zBase, sizeof(zBase));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   844
  vxprintf(&acc, 0, zFormat, ap);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   845
  z = sqlite3StrAccumFinish(&acc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   846
  return z;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   847
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   848
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   849
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   850
** Print into memory obtained from sqlite3_malloc()().  Omit the internal
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   851
** %-conversion extensions.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   852
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   853
EXPORT_C char *sqlite3_mprintf(const char *zFormat, ...){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   854
  va_list ap;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   855
  char *z;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   856
  va_start(ap, zFormat);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   857
  z = sqlite3_vmprintf(zFormat, ap);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   858
  va_end(ap);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   859
  return z;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   860
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   861
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   862
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   863
** sqlite3_snprintf() works like snprintf() except that it ignores the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   864
** current locale settings.  This is important for SQLite because we
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   865
** are not able to use a "," as the decimal point in place of "." as
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   866
** specified by some locales.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   867
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   868
EXPORT_C char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   869
  char *z;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   870
  va_list ap;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   871
  StrAccum acc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   872
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   873
  if( n<=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   874
    return zBuf;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   875
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   876
  sqlite3StrAccumInit(&acc, zBuf, n);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   877
  acc.useMalloc = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   878
  va_start(ap,zFormat);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   879
  vxprintf(&acc, 0, zFormat, ap);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   880
  va_end(ap);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   881
  z = sqlite3StrAccumFinish(&acc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   882
  return z;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   883
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   884
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   885
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) || defined(SQLITE_MEMDEBUG)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   886
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   887
** A version of printf() that understands %lld.  Used for debugging.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   888
** The printf() built into some versions of windows does not understand %lld
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   889
** and segfaults if you give it a long long int.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   890
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   891
void sqlite3DebugPrintf(const char *zFormat, ...){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   892
  va_list ap;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   893
  StrAccum acc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   894
  char zBuf[500];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   895
  sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   896
  acc.useMalloc = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   897
  va_start(ap,zFormat);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   898
  vxprintf(&acc, 0, zFormat, ap);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   899
  va_end(ap);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   900
  sqlite3StrAccumFinish(&acc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   901
  fprintf(stdout,"%s", zBuf);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   902
  fflush(stdout);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   903
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   904
#endif