34 #include <sys/types.h>
43 #ifndef SIZEOF_LONG_DOUBLE
44 #define SIZEOF_LONG_DOUBLE 0
49 #define LONG_LONG long long
59 #define MAX_PARAMETERS 128
69 # define TRUE ((char)(1 == 1))
70 # define FALSE ((char)(0 == 1))
76 static const char lower_digits[] =
"0123456789abcdefghijklmnopqrstuvwxyz";
79 static const char upper_digits[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
81 #define OUTCHAR(x) done+=(stream(x, (FILE *)data)==-1?0:1)
155 static long dprintf_DollarString(
char *
input,
char **
end)
158 while(isdigit((
int)*input)) {
160 number += *input-
'0';
163 if(number && (
'$'==*input++)) {
170 static BOOL dprintf_IsQualifierNoDollar(
char c)
173 case '-':
case '+':
case ' ':
case '#':
case '.':
174 case '0':
case '1':
case '2':
case '3':
case '4':
175 case '5':
case '6':
case '7':
case '8':
case '9':
176 case 'h':
case 'l':
case 'L':
case 'z':
case 'q':
184 #ifdef DPRINTF_DEBUG2
192 for(i=0; i<
max; i++) {
194 switch(vto[i].type) {
217 type =
"long double";
224 for(bit=0; bit<31; bit++) {
225 flags = vto[
i].
flags & (1<<bit);
228 strcat(buffer,
"space ");
230 strcat(buffer,
"plus ");
232 strcat(buffer,
"left ");
234 strcat(buffer,
"alt ");
236 strcat(buffer,
"short ");
238 strcat(buffer,
"long ");
240 strcat(buffer,
"longlong ");
242 strcat(buffer,
"longdouble ");
244 strcat(buffer,
"padnil ");
246 strcat(buffer,
"unsigned ");
248 strcat(buffer,
"octal ");
250 strcat(buffer,
"hex ");
252 strcat(buffer,
"upper ");
254 strcat(buffer,
"width ");
256 strcat(buffer,
"widthparam ");
258 strcat(buffer,
"precision ");
260 strcat(buffer,
"precparam ");
262 strcat(buffer,
"char ");
264 strcat(buffer,
"floate ");
266 strcat(buffer,
"floatg ");
268 printf(
"REPORT: %d. %s [%s]\n", i, type, buffer);
284 static int dprintf_Pass1(
char *
format,
va_stack_t *vto,
char **endpos, va_list arglist)
308 this_param = dprintf_DollarString(fmt, &fmt);
311 this_param = param_num;
313 if (this_param > max_param)
314 max_param = this_param;
327 while (dprintf_IsQualifierNoDollar(*fmt)) {
337 flags &= ~FLAGS_PAD_NIL;
351 i = dprintf_DollarString(fmt, &fmt);
355 precision = param_num;
357 if (precision > max_param)
358 max_param = precision;
362 precision = strtol(fmt, &fmt, 10);
369 if (flags & FLAGS_LONG)
383 if (
sizeof(
size_t) >
sizeof(
unsigned long))
385 if (
sizeof(
size_t) >
sizeof(
unsigned int))
389 #if SIZEOF_CURL_OFF_T > 4
396 if (!(flags & FLAGS_LEFT))
399 case '1':
case '2':
case '3':
case '4':
400 case '5':
case '6':
case '7':
case '8':
case '9':
402 width = strtol(fmt-1, &fmt, 10);
408 i = dprintf_DollarString(fmt, &fmt);
413 if(width > max_param)
489 if (flags & FLAGS_WIDTHPARAM) {
499 if (flags & FLAGS_PRECPARAM) {
513 #ifdef DPRINTF_DEBUG2
514 dprintf_Pass1Report(vto, max_param);
518 for (i=0; i<max_param; i++) {
519 if ((i + 1 < max_param) && (vto[i + 1].type ==
FORMAT_WIDTH))
524 vto[i + 1].
data.
num = va_arg(arglist,
int);
530 vto[
i].
data.
str = va_arg(arglist,
char *);
536 vto[
i].
data.
ptr = va_arg(arglist,
void *);
541 if(vto[i].flags & FLAGS_LONGLONG)
542 vto[
i].
data.lnum = va_arg(arglist, LONG_LONG);
545 if(vto[i].flags & FLAGS_LONG)
546 vto[
i].
data.
num = va_arg(arglist,
long);
548 vto[
i].
data.
num = va_arg(arglist,
int);
553 if(vto[i].flags & FLAGS_LONG)
554 vto[
i].
data.ldnum = va_arg(arglist,
long double);
557 vto[
i].
data.
dnum = va_arg(arglist,
double);
576 static int dprintf_formatf(
579 int (*stream)(
int, FILE *),
585 const char *digits = lower_digits;
605 dprintf_Pass1((
char *)format, vto, endpos, ap_save);
629 unsigned LONG_LONG
num;
640 }
while(*++f && (
'%' != *f));
658 param=dprintf_DollarString(f, &f);
671 if(p->
flags & FLAGS_WIDTHPARAM)
677 if(p->
flags & FLAGS_PRECPARAM)
679 else if(p->
flags & FLAGS_PREC)
691 if (!(p->
flags & FLAGS_LEFT))
695 if (p->
flags & FLAGS_LEFT)
700 if(p->
flags & FLAGS_UNSIGNED) {
703 goto unsigned_number;
705 if(p->
flags & FLAGS_OCTAL) {
708 goto unsigned_number;
710 if(p->
flags & FLAGS_HEX) {
715 goto unsigned_number;
722 if(p->
flags & FLAGS_LONGLONG) {
724 is_neg = p->
data.lnum < 0;
725 num = is_neg ? (- p->
data.lnum) : p->
data.lnum;
730 signed_num = (long) num;
732 is_neg = signed_num < 0;
733 num = is_neg ? (- signed_num) : signed_num;
744 char *workend = &work[
sizeof(work) - 1];
754 *w-- = digits[num % base];
757 width -= workend -
w;
760 if (alt && base == 8 && prec <= 0) {
771 if (alt && base == 16)
783 else if (p->
flags & FLAGS_SHOWSIGN)
785 else if (p->
flags & FLAGS_SPACE)
788 if (alt && base == 16) {
790 if(p->
flags & FLAGS_UPPER)
796 if (!(p->
flags & FLAGS_LEFT) && (p->
flags & FLAGS_PAD_NIL))
801 while (++w <= workend) {
805 if (p->
flags & FLAGS_LEFT)
814 static char null[] =
"(nil)";
821 if (prec == -1 || prec >= (
long)
sizeof(null) - 1) {
823 len =
sizeof(null) - 1;
825 p->
flags &= (~FLAGS_ALT);
835 if (prec != -1 && (
size_t) prec < len)
839 if (p->
flags & FLAGS_ALT)
842 if (!(p->
flags&FLAGS_LEFT))
848 if (p->
flags&FLAGS_LEFT)
852 if (p->
flags & FLAGS_ALT)
867 num = (
unsigned long) ptr;
873 static char strnil[] =
"(nil)";
876 width -=
sizeof(strnil) - 1;
877 if (p->
flags & FLAGS_LEFT)
880 for (point = strnil; *point !=
'\0'; ++point)
882 if (! (p->
flags & FLAGS_LEFT))
891 char formatbuf[32]=
"%";
895 if (p->
flags & FLAGS_WIDTH)
897 else if (p->
flags & FLAGS_WIDTHPARAM)
901 if (p->
flags & FLAGS_PREC)
903 else if (p->
flags & FLAGS_PRECPARAM)
906 if (p->
flags & FLAGS_LEFT)
907 strcat(formatbuf,
"-");
908 if (p->
flags & FLAGS_SHOWSIGN)
909 strcat(formatbuf,
"+");
910 if (p->
flags & FLAGS_SPACE)
911 strcat(formatbuf,
" ");
912 if (p->
flags & FLAGS_ALT)
913 strcat(formatbuf,
"#");
915 fptr=&formatbuf[strlen(formatbuf)];
925 if (p->
flags & FLAGS_LONG)
929 strcat(fptr, p->
flags&FLAGS_UPPER?
"E":
"e");
931 strcat(fptr, (p->
flags & FLAGS_UPPER) ?
"G" :
"g");
938 if (p->
flags & FLAGS_LONG)
945 for(fptr=work; *fptr; fptr++)
953 if (p->
flags & FLAGS_LONGLONG)
954 *(LONG_LONG *) p->
data.
ptr = (LONG_LONG)done;
957 if (p->
flags & FLAGS_LONG)
958 *(
long *) p->
data.
ptr = (
long)done;
959 else if (!(p->
flags & FLAGS_SHORT))
962 *(
short *) p->
data.
ptr = (
short)done;
975 static int addbyter(
int output, FILE *data)
981 infop->
buffer[0] = (char)output;
997 info.
max = maxlength;
999 retcode = dprintf_formatf(&info, addbyter, format, ap_save);
1015 va_start(ap_save, format);
1022 static int alloc_addbyter(
int output, FILE *data)
1027 infop->
buffer=(
char *)malloc(32);
1033 else if(infop->
len+1 >= infop->
alloc) {
1036 newptr = (
char *)realloc(infop->
buffer, infop->
alloc*2);
1062 va_start(ap_save, format);
1063 retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
1087 retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
1102 static int storebuffer(
int output, FILE *data)
1104 char **buffer = (
char **)data;
1105 **buffer = (char)output;
1114 va_start(ap_save, format);
1115 retcode = dprintf_formatf(&buffer, storebuffer, format, ap_save);
1122 extern int fputc(
int, FILE *);
1129 va_start(ap_save, format);
1130 retcode = dprintf_formatf(stdout,
fputc, format, ap_save);
1139 va_start(ap_save, format);
1140 retcode = dprintf_formatf(whereto,
fputc, format, ap_save);
1148 retcode = dprintf_formatf(&buffer, storebuffer, format, ap_save);
1155 return dprintf_formatf(stdout,
fputc, format, ap_save);
1160 return dprintf_formatf(whereto,
fputc, format, ap_save);
1163 #ifdef DPRINTF_DEBUG
1171 long long test = 0x1000000000
LL;
1177 ptr=
curl_maprintf(
"test this then baby %s%s%s%s%s%s %d %d %d loser baby get a hit in yer face now!",
"",
"pretty long string pretty long string pretty long string pretty long string pretty long string",
"/",
"/",
"/",
"pretty long string", 1998, 1999, 2001);
1181 memset(ptr, 55, strlen(ptr)+1);
1186 curl_mprintf(buffer,
"%s %s %d",
"daniel",
"stenberg", 19988);
1191 printf(
"%s %#08x\n",
"dummy", 65);
1193 double tryout = 3.14156592;
1194 curl_mprintf(buffer,
"%.2g %G %f %e %E", tryout, tryout, tryout, tryout, tryout);
1196 printf(
"%.2g %G %f %e %E\n", tryout, tryout, tryout, tryout, tryout);
int curl_mvsnprintf(char *buffer, size_t maxlength, const char *format, va_list ap_save)
char * curl_mvaprintf(const char *format, va_list ap_save)
GLenum GLsizei GLenum format
GLuint GLuint GLsizei GLenum type
int curl_mvprintf(const char *format, va_list ap_save)
union va_stack_t::@6 data
int curl_mvsprintf(char *buffer, const char *format, va_list ap_save)
GLubyte GLubyte GLubyte GLubyte w
GLsizei GLsizei GLenum GLenum const GLvoid * data
int curl_msnprintf(char *buffer, size_t maxlength, const char *format,...)
char * curl_maprintf(const char *format,...)
int curl_mvfprintf(FILE *whereto, const char *format, va_list ap_save)
GLenum GLenum GLenum input
int curl_mfprintf(FILE *whereto, const char *format,...)
if(!ValidDisplayID(prefInfo.prefDisplayID)) prefInfo.prefDisplayID
int curl_msprintf(char *buffer, const char *format,...)
int sprintf(idStr &string, const char *fmt,...)
int curl_mprintf(const char *format,...)