func(arg,"",0);
static int vxprintf(  void (*func)(void*,const char*,int),     /* Consumer of text */  void *arg,                         /* First argument to the consumer */  int useExtended,                   /* Allow extended %-conversions */  const char *fmt,                   /* Format string */  va_list ap                         /* arguments */){  int c;                     /* Next character in the format string */  char *bufpt;               /* Pointer to the conversion buffer */  int precision;             /* Precision of the current field */  int length;                /* Length of the field */  int idx;                   /* A general purpose loop counter */  int count;                 /* Total number of characters output */  int width;                 /* Width of the current field */  etByte flag_leftjustify;   /* True if "-" flag is present */  etByte flag_plussign;      /* True if "+" flag is present */  etByte flag_blanksign;     /* True if " " flag is present */  etByte flag_alternateform; /* True if "#" flag is present */  etByte flag_zeropad;       /* True if field width constant starts with zero */  etByte flag_long;          /* True if "l" flag is present */  unsigned long longvalue;   /* Value for integer types */  LONGDOUBLE_TYPE realvalue; /* Value for real types */  et_info *infop;            /* Pointer to the appropriate info structure */  char buf[etBUFSIZE];       /* Conversion buffer */  char prefix;               /* Prefix character.  "+" or "-" or " " or '\0'. */  etByte errorflag = 0;      /* True if an error is encountered */  etByte xtype;              /* Conversion paradigm */  char *zExtra;              /* Extra memory used for etTCLESCAPE conversions */  static char spaces[] = "                                                  ";#define etSPACESIZE (sizeof(spaces)-1)#ifndef etNOFLOATINGPOINT  int  exp;                  /* exponent of real numbers */  double rounder;            /* Used for rounding floating point values */  etByte flag_dp;            /* True if decimal point should be shown */  etByte flag_rtz;           /* True if trailing zeros should be removed */  etByte flag_exp;           /* True to force display of the exponent */  int nsd;                   /* Number of significant digits returned */#endif  count = length = 0;  bufpt = 0;  for(; (c=(*fmt))!=0; ++fmt){    if( c!='%' ){      int amt;      bufpt = (char *)fmt;      amt = 1;      while( (c=(*++fmt))!='%' && c!=0 ) amt++;      (*func)(arg,bufpt,amt);      count += amt;      if( c==0 ) break;    }    if( (c=(*++fmt))==0 ){      errorflag = 1;      (*func)(arg,"%",1);      count++;      break;    }    /* Find out what flags are present */    flag_leftjustify = flag_plussign = flag_blanksign =      flag_alternateform = flag_zeropad = 0;    do{      switch( c ){        case '-':   flag_leftjustify = 1;     c = 0;   break;        case '+':   flag_plussign = 1;        c = 0;   break;        case ' ':   flag_blanksign = 1;       c = 0;   break;        case '#':   flag_alternateform = 1;   c = 0;   break;        case '0':   flag_zeropad = 1;         c = 0;   break;        default:                                       break;      }    }while( c==0 && (c=(*++fmt))!=0 );    /* Get the field width */    width = 0;    if( c=='*' ){      width = va_arg(ap,int);      if( width<0 ){        flag_leftjustify = 1;        width = -width;      }      c = *++fmt;    }else{      while( c>='0' && c<='9' ){        width = width*10 + c - '0';        c = *++fmt;      }    }    if( width > etBUFSIZE-10 ){      width = etBUFSIZE-10;    }    /* Get the precision */    if( c=='.' ){      precision = 0;      c = *++fmt;      if( c=='*' ){        precision = va_arg(ap,int);        if( precision<0 ) precision = -precision;        c = *++fmt;      }else{        while( c>='0' && c<='9' ){          precision = precision*10 + c - '0';          c = *++fmt;        }      }      /* Limit the precision to prevent overflowing buf[] during conversion */      if( precision>etBUFSIZE-40 ) precision = etBUFSIZE-40;    }else{      precision = -1;    }    /* Get the conversion type modifier */    if( c=='l' ){      flag_long = 1;      c = *++fmt;    }else{      flag_long = 0;    }    /* Fetch the info entry for the field */    infop = 0;    xtype = etERROR;    for(idx=0; idx<etNINFO; idx++){      if( c==fmtinfo[idx].fmttype ){        infop = &fmtinfo[idx];        if( useExtended || (infop->flags & FLAG_INTERN)==0 ){          xtype = infop->type;        }        break;      }    }    zExtra = 0;    /*    ** At this point, variables are initialized as follows:    **    **   flag_alternateform          TRUE if a '#' is present.    **   flag_plussign               TRUE if a '+' is present.    **   flag_leftjustify            TRUE if a '-' is present or if the    **                               field width was negative.    **   flag_zeropad                TRUE if the width began with 0.    **   flag_long                   TRUE if the letter 'l' (ell) prefixed    **                               the conversion character.    **   flag_blanksign              TRUE if a ' ' is present.    **   width                       The specified field width.  This is    **                               always non-negative.  Zero is the default.    **   precision                   The specified precision.  The default    **                               is -1.    **   xtype                       The class of the conversion.    **   infop                       Pointer to the appropriate info struct.    */    switch( xtype ){      case etRADIX:        if( flag_long )  longvalue = va_arg(ap,long);        else             longvalue = va_arg(ap,int);#if 1        /* For the format %#x, the value zero is printed "0" not "0x0".        ** I think this is stupid. */        if( longvalue==0 ) flag_alternateform = 0;#else        /* More sensible: turn off the prefix for octal (to prevent "00"),        ** but leave the prefix for hex. */        if( longvalue==0 && infop->base==8 ) flag_alternateform = 0;#endif        if( infop->flags & FLAG_SIGNED ){          if( *(long*)&longvalue<0 ){            longvalue = -*(long*)&longvalue;            prefix = '-';          }else if( flag_plussign )  prefix = '+';          else if( flag_blanksign )  prefix = ' ';          else                       prefix = 0;        }else                        prefix = 0;        if( flag_zeropad && precision<width-(prefix!=0) ){          precision = width-(prefix!=0);        }        bufpt = &buf[etBUFSIZE-1];        {          register char *cset;      /* Use registers for speed */          register int base;          cset = infop->charset;          base = infop->base;          do{                                           /* Convert to ascii */            *(--bufpt) = cset[longvalue%base];            longvalue = longvalue/base;          }while( longvalue>0 );        }        length = &buf[etBUFSIZE-1]-bufpt;        for(idx=precision-length; idx>0; idx--){          *(--bufpt) = '0';                             /* Zero pad */        }        if( prefix ) *(--bufpt) = prefix;               /* Add sign */        if( flag_alternateform && infop->prefix ){      /* Add "0" or "0x" */          char *pre, x;          pre = infop->prefix;          if( *bufpt!=pre[0] ){            for(pre=infop->prefix; (x=(*pre))!=0; pre++) *(--bufpt) = x;          }        }        length = &buf[etBUFSIZE-1]-bufpt;        break;      case etFLOAT:      case etEXP:      case etGENERIC:        realvalue = va_arg(ap,double);#ifndef etNOFLOATINGPOINT        if( precision<0 ) precision = 6;         /* Set default precision */        if( precision>etBUFSIZE-10 ) precision = etBUFSIZE-10;        if( realvalue<0.0 ){          realvalue = -realvalue;          prefix = '-';        }else{          if( flag_plussign )          prefix = '+';          else if( flag_blanksign )    prefix = ' ';          else                         prefix = 0;        }        if( infop->type==etGENERIC && precision>0 ) precision--;        rounder = 0.0;#if 0        /* Rounding works like BSD when the constant 0.4999 is used.  Wierd! */        for(idx=precision, rounder=0.4999; idx>0; idx--, rounder*=0.1);#else        /* It makes more sense to use 0.5 */        for(idx=precision, rounder=0.5; idx>0; idx--, rounder*=0.1);#endif        if( infop->type==etFLOAT ) realvalue += rounder;        /* Normalize realvalue to within 10.0 > realvalue >= 1.0 */        exp = 0;        if( realvalue>0.0 ){          while( realvalue>=1e8 && exp<=350 ){ realvalue *= 1e-8; exp+=8; }          while( realvalue>=10.0 && exp<=350 ){ realvalue *= 0.1; exp++; }          while( realvalue<1e-8 && exp>=-350 ){ realvalue *= 1e8; exp-=8; }          while( realvalue<1.0 && exp>=-350 ){ realvalue *= 10.0; exp--; }          if( exp>350 || exp<-350 ){            bufpt = "NaN";            length = 3;            break;          }        }        bufpt = buf;        /*        ** If the field type is etGENERIC, then convert to either etEXP        ** or etFLOAT, as appropriate.        */        flag_exp = xtype==etEXP;        if( xtype!=etFLOAT ){          realvalue += rounder;          if( realvalue>=10.0 ){ realvalue *= 0.1; exp++; }        }        if( xtype==etGENERIC ){          flag_rtz = !flag_alternateform;          if( exp<-4 || exp>precision ){            xtype = etEXP;          }else{            precision = precision - exp;            xtype = etFLOAT;          }        }else{          flag_rtz = 0;        }        /*        ** The "exp+precision" test causes output to be of type etEXP if        ** the precision is too large to fit in buf[].        */        nsd = 0;        if( xtype==etFLOAT && exp+precision<etBUFSIZE-30 ){          flag_dp = (precision>0 || flag_alternateform);          if( prefix ) *(bufpt++) = prefix;         /* Sign */          if( exp<0 )  *(bufpt++) = '0';            /* Digits before "." */          else for(; exp>=0; exp--) *(bufpt++) = et_getdigit(&realvalue,&nsd);          if( flag_dp ) *(bufpt++) = '.';           /* The decimal point */          for(exp++; exp<0 && precision>0; precision--, exp++){            *(bufpt++) = '0';          }          while( (precision--)>0 ) *(bufpt++) = et_getdigit(&realvalue,&nsd);          *(bufpt--) = 0;                           /* Null terminate */          if( flag_rtz && flag_dp ){     /* Remove trailing zeros and "." */            while( bufpt>=buf && *bufpt=='0' ) *(bufpt--) = 0;            if( bufpt>=buf && *bufpt=='.' ) *(bufpt--) = 0;          }          bufpt++;                            /* point to next free slot */        }else{    /* etEXP or etGENERIC */          flag_dp = (precision>0 || flag_alternateform);          if( prefix ) *(bufpt++) = prefix;   /* Sign */          *(bufpt++) = et_getdigit(&realvalue,&nsd);  /* First digit */          if( flag_dp ) *(bufpt++) = '.';     /* Decimal point */          while( (precision--)>0 ) *(bufpt++) = et_getdigit(&realvalue,&nsd);          bufpt--;                            /* point to last digit */          if( flag_rtz && flag_dp ){          /* Remove tail zeros */            while( bufpt>=buf && *bufpt=='0' ) *(bufpt--) = 0;            if( bufpt>=buf && *bufpt=='.' ) *(bufpt--) = 0;          }          bufpt++;                            /* point to next free slot */          if( exp || flag_exp ){            *(bufpt++) = infop->charset[0];            if( exp<0 ){ *(bufpt++) = '-'; exp = -exp; } /* sign of exp */            else       { *(bufpt++) = '+'; }            if( exp>=100 ){              *(bufpt++) = (exp/100)+'0';                /* 100's digit */              exp %= 100;            }            *(bufpt++) = exp/10+'0';                     /* 10's digit */            *(bufpt++) = exp%10+'0';                     /* 1's digit */          }        }        /* The converted number is in buf[] and zero terminated. Output it.        ** Note that the number is in the usual order, not reversed as with        ** integer conversions. */        length = bufpt-buf;        bufpt = buf;        /* Special case:  Add leading zeros if the flag_zeropad flag is        ** set and we are not left justified */        if( flag_zeropad && !flag_leftjustify && length < width){          int i;          int nPad = width - length;          for(i=width; i>=nPad; i--){            bufpt[i] = bufpt[i-nPad];          }          i = prefix!=0;          while( nPad-- ) bufpt[i++] = '0';          length = width;        }#endif        break;      case etSIZE:        *(va_arg(ap,int*)) = count;        length = width = 0;        break;      case etPERCENT:        buf[0] = '%';        bufpt = buf;        length = 1;        break;      case etCHARLIT:      case etCHARX:        c = buf[0] = (xtype==etCHARX ? va_arg(ap,int) : *++fmt);        if( precision>=0 ){          for(idx=1; idx<precision; idx++) buf[idx] = c;          length = precision;        }else{          length =1;        }        bufpt = buf;        break;      case etSTRING:      case etDYNSTRING:        bufpt = va_arg(ap,char*);        if( bufpt==0 ){          bufpt = "";        }else if( xtype==etDYNSTRING ){          zExtra = bufpt;        }        length = strlen(bufpt);        if( precision>=0 && precision<length ) length = precision;        break;      case etSQLESCAPE:      case etSQLESCAPE2:        {          int i, j, n, c, isnull;          char *arg = va_arg(ap,char*);          isnull = arg==0;          if( isnull ) arg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");          for(i=n=0; (c=arg[i])!=0; i++){            if( c=='\'' )  n++;          }          n += i + 1 + ((!isnull && xtype==etSQLESCAPE2) ? 2 : 0);          if( n>etBUFSIZE ){            bufpt = zExtra = sqliteMalloc( n );            if( bufpt==0 ) return -1;          }else{            bufpt = buf;          }          j = 0;          if( !isnull && xtype==etSQLESCAPE2 ) bufpt[j++] = '\'';          for(i=0; (c=arg[i])!=0; i++){            bufpt[j++] = c;            if( c=='\'' ) bufpt[j++] = c;          }          if( !isnull && xtype==etSQLESCAPE2 ) bufpt[j++] = '\'';          bufpt[j] = 0;          length = j;          if( precision>=0 && precision<length ) length = precision;        }        break;      case etTOKEN: {        Token *pToken = va_arg(ap, Token*);        (*func)(arg, pToken->z, pToken->n);        length = width = 0;        break;      }      case etSRCLIST: {        SrcList *pSrc = va_arg(ap, SrcList*);        int k = va_arg(ap, int);        struct SrcList_item *pItem = &pSrc->a[k];        assert( k>=0 && k<pSrc->nSrc );        if( pItem->zDatabase && pItem->zDatabase[0] ){          (*func)(arg, pItem->zDatabase, strlen(pItem->zDatabase));          (*func)(arg, ".", 1);        }        (*func)(arg, pItem->zName, strlen(pItem->zName));        length = width = 0;        break;      }      case etERROR:        buf[0] = '%';        buf[1] = c;        errorflag = 0;        idx = 1+(c!=0);        (*func)(arg,"%",idx);        count += idx;        if( c==0 ) fmt--;        break;    }/* End switch over the format type */    /*    ** The text of the conversion is pointed to by "bufpt" and is    ** "length" characters long.  The field width is "width".  Do    ** the output.    */    if( !flag_leftjustify ){      register int nspace;      nspace = width-length;      if( nspace>0 ){        count += nspace;        while( nspace>=etSPACESIZE ){          (*func)(arg,spaces,etSPACESIZE);          nspace -= etSPACESIZE;        }        if( nspace>0 ) (*func)(arg,spaces,nspace);      }    }    if( length>0 ){      (*func)(arg,bufpt,length);      count += length;    }    if( flag_leftjustify ){      register int nspace;      nspace = width-length;      if( nspace>0 ){        count += nspace;        while( nspace>=etSPACESIZE ){          (*func)(arg,spaces,etSPACESIZE);          nspace -= etSPACESIZE;        }        if( nspace>0 ) (*func)(arg,spaces,nspace);      }    }    if( zExtra ){      sqliteFree(zExtra);    }  }/* End for loop over the format string */  return errorflag ? -1 : count;} /* End of function */