44 #define PG_NL_ARGMAX 31
253 target.
bufend = buffer +
sizeof(buffer);
306 if (!target->
failed && nc > 0)
311 target->
nchars += written;
321 static void fmtstr(
const char *
value,
int leftjust,
int minlen,
int maxwidth,
325 int leftjust,
int minlen,
int zpad,
int precision,
int pointflag,
329 int leftjust,
int minlen,
int zpad,
int precision,
int pointflag,
334 static int adjust_sign(
int is_negative,
int forcesign,
int *signvalue);
336 static void leading_pad(
int zpad,
int signvalue,
int *padlen,
347 #ifndef HAVE_STRCHRNUL
349 static inline const char *
352 while (*s !=
'\0' && *s !=
c)
378 int save_errno = errno;
379 const char *first_pct = NULL;
397 const char *strvalue;
421 if (*next_pct ==
'\0')
431 if (first_pct == NULL)
441 strvalue = va_arg(
args,
char *);
442 if (strvalue == NULL)
444 dostr(strvalue, strlen(strvalue), target);
450 fieldwidth = precision = zpad = leftjust = forcesign = 0;
451 longflag = longlongflag = pointflag = 0;
453 have_star = afterstar =
false;
466 if (accum == 0 && !pointflag)
478 accum = accum * 10 + (ch -
'0');
501 int starval = va_arg(
args,
int);
514 fieldwidth = starval;
518 fieldwidth = -fieldwidth;
537 int starval = argvalues[accum].
i;
550 fieldwidth = starval;
554 fieldwidth = -fieldwidth;
570 #if SIZEOF_SIZE_T == 8
571 #ifdef HAVE_LONG_INT_64
573 #elif defined(HAVE_LONG_LONG_INT_64)
576 #error "Don't know how to print 64bit integers"
598 numvalue = argvalues[fmtpos].
ll;
600 numvalue = argvalues[fmtpos].
l;
602 numvalue = argvalues[fmtpos].
i;
607 numvalue = va_arg(
args,
long long);
609 numvalue = va_arg(
args,
long);
611 numvalue = va_arg(
args,
int);
613 fmtint(numvalue, ch, forcesign, leftjust, fieldwidth, zpad,
614 precision, pointflag, target);
630 numvalue = (
unsigned long long) argvalues[fmtpos].ll;
632 numvalue = (
unsigned long) argvalues[fmtpos].l;
634 numvalue = (
unsigned int) argvalues[fmtpos].
i;
639 numvalue = (
unsigned long long) va_arg(
args,
long long);
641 numvalue = (
unsigned long) va_arg(
args,
long);
643 numvalue = (
unsigned int) va_arg(
args,
int);
645 fmtint(numvalue, ch, forcesign, leftjust, fieldwidth, zpad,
646 precision, pointflag, target);
657 cvalue = (
unsigned char) argvalues[fmtpos].
i;
659 cvalue = (
unsigned char) va_arg(
args,
int);
660 fmtchar(cvalue, leftjust, fieldwidth, target);
671 strvalue = argvalues[fmtpos].
cptr;
673 strvalue = va_arg(
args,
char *);
675 if (strvalue == NULL)
677 fmtstr(strvalue, leftjust, fieldwidth, precision, pointflag,
683 strvalue = argvalues[fmtpos].
cptr;
685 strvalue = va_arg(
args,
char *);
686 fmtptr((
const void *) strvalue, target);
701 fvalue = argvalues[fmtpos].
d;
703 fvalue = va_arg(
args,
double);
704 fmtfloat(fvalue, ch, forcesign, leftjust,
706 precision, pointflag,
713 errbuf,
sizeof(errbuf));
715 dostr(errm, strlen(errm), target);
783 longflag = longlongflag = 0;
803 accum = accum * 10 + (ch -
'0');
819 if (argtypes[accum] &&
823 last_dollar =
Max(last_dollar, accum);
837 #if SIZEOF_SIZE_T == 8
838 #ifdef HAVE_LONG_INT_64
840 #elif defined(HAVE_LONG_LONG_INT_64)
843 #error "Don't know how to print 64bit integers"
869 if (argtypes[fmtpos] &&
870 argtypes[fmtpos] != atype)
872 argtypes[fmtpos] = atype;
873 last_dollar =
Max(last_dollar, fmtpos);
881 if (argtypes[fmtpos] &&
885 last_dollar =
Max(last_dollar, fmtpos);
894 if (argtypes[fmtpos] &&
898 last_dollar =
Max(last_dollar, fmtpos);
910 if (argtypes[fmtpos] &&
914 last_dollar =
Max(last_dollar, fmtpos);
939 for (
i = 1;
i <= last_dollar;
i++)
946 argvalues[
i].
i = va_arg(
args,
int);
949 argvalues[
i].
l = va_arg(
args,
long);
952 argvalues[
i].
ll = va_arg(
args,
long long);
955 argvalues[
i].
d = va_arg(
args,
double);
958 argvalues[
i].
cptr = va_arg(
args,
char *);
980 vallen = strlen(
value);
1011 int minlen,
int zpad,
int precision,
int pointflag,
1014 unsigned long long uvalue;
1017 const char *cvt =
"0123456789abcdef";
1044 cvt =
"0123456789ABCDEF";
1054 #pragma warning(push)
1055 #pragma warning(disable: 4146)
1059 uvalue = -(
unsigned long long)
value;
1061 uvalue = (
unsigned long long)
value;
1063 #pragma warning(pop)
1070 if (
value == 0 && pointflag && precision == 0)
1085 uvalue = uvalue / 10;
1088 else if (base == 16)
1093 uvalue = uvalue / 16;
1101 uvalue = uvalue / 8;
1106 zeropad =
Max(0, precision - vallen);
1140 int minlen,
int zpad,
int precision,
int pointflag,
1170 prec =
Min(precision, 350);
1186 static const double dzero = 0.0;
1190 memcmp(&
value, &dzero,
sizeof(
double)) != 0)),
1191 forcesign, &signvalue))
1202 zeropadlen = precision - prec;
1244 char *epos = strrchr(
convert,
'e');
1308 else if (precision > 32)
1322 static const double dzero = 0.0;
1326 memcmp(&
value, &dzero,
sizeof(
double)) != 0))
1390 if (target->
bufend != NULL)
1397 if (target->
stream == NULL)
1405 avail =
Min(avail, slen);
1419 if (target->
stream == NULL)
1443 if (target->
bufend != NULL)
1450 if (target->
stream == NULL)
1458 avail =
Min(avail, slen);
1459 memset(target->
bufptr,
c, avail);
1485 padlen = minlen - vallen;
1499 if (*padlen > 0 && zpad)
1513 maxpad = (signvalue != 0);
1514 if (*padlen > maxpad)
1524 else if (*padlen < 0)
#define Assert(condition)
static void const char * fmt
#define PG_STRERROR_R_BUFLEN
size_t strnlen(const char *str, size_t maxlen)
static void dostr(const char *str, int slen, PrintfTarget *target)
static void dopr_outch(int c, PrintfTarget *target)
static void fmtint(long long value, char type, int forcesign, int leftjust, int minlen, int zpad, int precision, int pointflag, PrintfTarget *target)
static void leading_pad(int zpad, int signvalue, int *padlen, PrintfTarget *target)
int pg_strfromd(char *str, size_t count, int precision, double value)
static void fmtptr(const void *value, PrintfTarget *target)
static void flushbuffer(PrintfTarget *target)
int pg_printf(const char *fmt,...)
static void fmtchar(int value, int leftjust, int minlen, PrintfTarget *target)
static void fmtstr(const char *value, int leftjust, int minlen, int maxwidth, int pointflag, PrintfTarget *target)
int pg_vprintf(const char *fmt, va_list args)
int pg_snprintf(char *str, size_t count, const char *fmt,...)
static int compute_padlen(int minlen, int vallen, int leftjust)
int pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
static void trailing_pad(int padlen, PrintfTarget *target)
static void fmtfloat(double value, char type, int forcesign, int leftjust, int minlen, int zpad, int precision, int pointflag, PrintfTarget *target)
int pg_sprintf(char *str, const char *fmt,...)
static bool find_arguments(const char *format, va_list args, PrintfArgValue *argvalues)
int pg_vsprintf(char *str, const char *fmt, va_list args)
static void dopr(PrintfTarget *target, const char *format, va_list args)
static const char * strchrnul(const char *s, int c)
static void dopr_outchmulti(int c, int slen, PrintfTarget *target)
int pg_fprintf(FILE *stream, const char *fmt,...)
int pg_vfprintf(FILE *stream, const char *fmt, va_list args)
static int adjust_sign(int is_negative, int forcesign, int *signvalue)
static void convert(const int32 val, char *const buf)