winhttp/tests: Make sure proxy settings are restored.
[wine] / dlls / msvcrt / printf.h
1 /*
2  * Copyright 2011 Piotr Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #ifdef PRINTF_WIDE
20 #define APICHAR MSVCRT_wchar_t
21 #define CONVCHAR char
22 #define FUNC_NAME(func) func ## _w
23 #else
24 #define APICHAR char
25 #define CONVCHAR MSVCRT_wchar_t
26 #define FUNC_NAME(func) func ## _a
27 #endif
28
29 typedef struct FUNC_NAME(pf_flags_t)
30 {
31     APICHAR Sign, LeftAlign, Alternate, PadZero;
32     int FieldLength, Precision;
33     APICHAR IntegerLength, IntegerDouble;
34     APICHAR WideString;
35     APICHAR Format;
36 } FUNC_NAME(pf_flags);
37
38 struct FUNC_NAME(_str_ctx) {
39     MSVCRT_size_t len;
40     APICHAR *buf;
41 };
42
43 static int FUNC_NAME(puts_clbk_str)(void *ctx, int len, const APICHAR *str)
44 {
45     struct FUNC_NAME(_str_ctx) *out = ctx;
46
47     if(!out->buf)
48         return len;
49
50     if(out->len < len) {
51         memcpy(out->buf, str, out->len);
52         out->buf += out->len;
53         out->len = 0;
54         return -1;
55     }
56
57     memcpy(out->buf, str, len*sizeof(APICHAR));
58     out->buf += len;
59     out->len -= len;
60     return len;
61 }
62
63 static inline const APICHAR* FUNC_NAME(pf_parse_int)(const APICHAR *fmt, int *val)
64 {
65     *val = 0;
66
67     while(isdigit(*fmt)) {
68         *val *= 10;
69         *val += *fmt++ - '0';
70     }
71
72     return fmt;
73 }
74
75 /* pf_fill: takes care of signs, alignment, zero and field padding */
76 static inline int FUNC_NAME(pf_fill)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
77         int len, FUNC_NAME(pf_flags) *flags, BOOL left)
78 {
79     int i, r = 0, written;
80
81     if(flags->Sign && !strchr("diaeEfgG", flags->Format))
82         flags->Sign = 0;
83
84     if(left && flags->Sign) {
85         flags->FieldLength--;
86         if(flags->PadZero)
87             r = pf_puts(puts_ctx, 1, &flags->Sign);
88     }
89     written = r;
90
91     if((!left && flags->LeftAlign) || (left && !flags->LeftAlign)) {
92         APICHAR ch;
93
94         if(left && flags->PadZero)
95             ch = '0';
96         else
97             ch = ' ';
98
99         for(i=0; i<flags->FieldLength-len && r>=0; i++) {
100             r = pf_puts(puts_ctx, 1, &ch);
101             written += r;
102         }
103     }
104
105
106     if(r>=0 && left && flags->Sign && !flags->PadZero) {
107         r = pf_puts(puts_ctx, 1, &flags->Sign);
108         written += r;
109     }
110
111     return r>=0 ? written : r;
112 }
113
114 static inline int FUNC_NAME(pf_output_wstr)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
115         const MSVCRT_wchar_t *str, int len, MSVCRT_pthreadlocinfo locinfo)
116 {
117 #ifdef PRINTF_WIDE
118     return pf_puts(puts_ctx, len, str);
119 #else
120     LPSTR out;
121     int len_a = WideCharToMultiByte(locinfo->lc_codepage, 0, str, len, NULL, 0, NULL, NULL);
122
123     out = HeapAlloc(GetProcessHeap(), 0, len_a);
124     if(!out)
125         return -1;
126
127     WideCharToMultiByte(locinfo->lc_codepage, 0, str, len, out, len_a, NULL, NULL);
128     len = pf_puts(puts_ctx, len_a, out);
129     HeapFree(GetProcessHeap(), 0, out);
130     return len;
131 #endif
132 }
133
134 static inline int FUNC_NAME(pf_output_str)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
135         const char *str, int len, MSVCRT_pthreadlocinfo locinfo)
136 {
137 #ifdef PRINTF_WIDE
138     LPWSTR out;
139     int len_w = MultiByteToWideChar(locinfo->lc_codepage, 0, str, len, NULL, 0);
140
141     out = HeapAlloc(GetProcessHeap(), 0, len_w*sizeof(WCHAR));
142     if(!out)
143         return -1;
144
145     MultiByteToWideChar(locinfo->lc_codepage, 0, str, len, out, len_w);
146     len = pf_puts(puts_ctx, len_w, out);
147     HeapFree(GetProcessHeap(), 0, out);
148     return len;
149 #else
150     return pf_puts(puts_ctx, len, str);
151 #endif
152 }
153
154 static inline int FUNC_NAME(pf_output_format_wstr)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
155         const MSVCRT_wchar_t *str, int len, FUNC_NAME(pf_flags) *flags, MSVCRT_pthreadlocinfo locinfo)
156 {
157     int r, ret;
158
159     if(len < 0)
160         len = strlenW(str);
161
162     if(flags->Precision>=0 && flags->Precision<len)
163         len = flags->Precision;
164
165     r = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, flags, TRUE);
166     ret = r;
167     if(r >= 0) {
168         r = FUNC_NAME(pf_output_wstr)(pf_puts, puts_ctx, str, len, locinfo);
169         ret += r;
170     }
171     if(r >= 0) {
172         r = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, flags, FALSE);
173         ret += r;
174     }
175
176     return r>=0 ? ret : r;
177 }
178
179 static inline int FUNC_NAME(pf_output_format_str)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
180         const char *str, int len, FUNC_NAME(pf_flags) *flags, MSVCRT_pthreadlocinfo locinfo)
181 {
182     int r, ret;
183
184     if(len < 0)
185         len = strlen(str);
186
187     if(flags->Precision>=0 && flags->Precision<len)
188         len = flags->Precision;
189
190     r = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, flags, TRUE);
191     ret = r;
192     if(r >= 0) {
193         r = FUNC_NAME(pf_output_str)(pf_puts, puts_ctx, str, len, locinfo);
194         ret += r;
195     }
196     if(r >= 0) {
197         r = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, flags, FALSE);
198         ret += r;
199     }
200
201     return r>=0 ? ret : r;
202 }
203
204 static inline int FUNC_NAME(pf_handle_string)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx,
205         const void *str, int len, FUNC_NAME(pf_flags) *flags, MSVCRT_pthreadlocinfo locinfo)
206 {
207 #ifdef PRINTF_WIDE
208     static const MSVCRT_wchar_t nullW[] = {'(','n','u','l','l',')',0};
209
210     if(!str)
211         return FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, nullW, 6, flags, locinfo);
212 #else
213     if(!str)
214         return FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, "(null)", 6, flags, locinfo);
215 #endif
216
217     if(flags->WideString || flags->IntegerLength=='l')
218         return FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, str, len, flags, locinfo);
219     if(flags->IntegerLength == 'h')
220         return FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, str, len, flags, locinfo);
221
222     if((flags->Format=='S' || flags->Format=='C') == (sizeof(APICHAR)==sizeof(MSVCRT_wchar_t)))
223         return FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, str, len, flags, locinfo);
224     else
225         return FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, str, len, flags, locinfo);
226 }
227
228 static inline void FUNC_NAME(pf_rebuild_format_string)(char *p, FUNC_NAME(pf_flags) *flags)
229 {
230     *p++ = '%';
231     if(flags->Alternate)
232         *p++ = flags->Alternate;
233     if(flags->Precision >= 0) {
234         sprintf(p, ".%d", flags->Precision);
235         p += strlen(p);
236     }
237     *p++ = flags->Format;
238     *p++ = 0;
239 }
240
241 /* pf_integer_conv:  prints x to buf, including alternate formats and
242    additional precision digits, but not field characters or the sign */
243 static inline void FUNC_NAME(pf_integer_conv)(APICHAR *buf, int buf_len,
244         FUNC_NAME(pf_flags) *flags, LONGLONG x)
245 {
246     unsigned int base;
247     const char *digits;
248     int i, j, k;
249
250     if(flags->Format == 'o')
251         base = 8;
252     else if(flags->Format=='x' || flags->Format=='X')
253         base = 16;
254     else
255         base = 10;
256
257     if(flags->Format == 'X')
258         digits = "0123456789ABCDEFX";
259     else
260         digits = "0123456789abcdefx";
261
262     if(x<0 && (flags->Format=='d' || flags->Format=='i')) {
263         x = -x;
264         flags->Sign = '-';
265     }
266
267     i = 0;
268     if(x==0 && flags->Precision)
269         buf[i++] = '0';
270     else {
271         while(x != 0) {
272             j = (ULONGLONG)x%base;
273             x = (ULONGLONG)x/base;
274             buf[i++] = digits[j];
275         }
276     }
277     k = flags->Precision-i;
278     while(k-- > 0)
279         buf[i++] = '0';
280     if(flags->Alternate) {
281         if(base == 16) {
282             buf[i++] = digits[16];
283             buf[i++] = '0';
284         } else if(base==8 && buf[i-1]!='0')
285             buf[i++] = '0';
286     }
287
288     /* Adjust precision so pf_fill won't truncate the number later */
289     flags->Precision = i;
290
291     buf[i] = '\0';
292     j = 0;
293     while(--i > j) {
294         APICHAR tmp = buf[j];
295         buf[j] = buf[i];
296         buf[i] = tmp;
297         j++;
298     }
299 }
300
301 static inline void FUNC_NAME(pf_fixup_exponent)(char *buf)
302 {
303     char* tmp = buf;
304
305     while(tmp[0] && toupper(tmp[0])!='E')
306         tmp++;
307
308     if(tmp[0] && (tmp[1]=='+' || tmp[1]=='-') &&
309             isdigit(tmp[2]) && isdigit(tmp[3])) {
310         char final;
311
312         if (isdigit(tmp[4]))
313             return; /* Exponent already 3 digits */
314
315         tmp += 2;
316         final = tmp[2];
317         tmp[2] = tmp[1];
318         tmp[1] = tmp[0];
319         tmp[0] = '0';
320
321         if(final == '\0') {
322             tmp[3] = '\0';
323             if(buf[0] == ' ')
324                 memmove(buf, buf + 1, (tmp - buf) + 3);
325         }
326     }
327 }
328
329 int FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk) pf_puts, void *puts_ctx, const APICHAR *fmt,
330         MSVCRT__locale_t locale, BOOL positional_params, BOOL invoke_invalid_param_handler,
331         args_clbk pf_args, void *args_ctx, __ms_va_list *valist)
332 {
333     MSVCRT_pthreadlocinfo locinfo;
334     const APICHAR *q, *p = fmt;
335     APICHAR buf[32];
336     int written = 0, pos, i;
337     FUNC_NAME(pf_flags) flags;
338
339     TRACE("Format is: %s\n", FUNC_NAME(debugstr)(fmt));
340
341     if(!locale)
342         locinfo = get_locinfo();
343     else
344         locinfo = locale->locinfo;
345
346     while(*p) {
347         /* output characters before '%' */
348         for(q=p; *q && *q!='%'; q++);
349         if(p != q) {
350             i = pf_puts(puts_ctx, q-p, p);
351             if(i < 0)
352                 return i;
353
354             written += i;
355             p = q;
356             continue;
357         }
358
359         /* *p == '%' here */
360         p++;
361
362         /* output a single '%' character */
363         if(*p == '%') {
364             i = pf_puts(puts_ctx, 1, p++);
365             if(i < 0)
366                 return i;
367
368             written += i;
369             continue;
370         }
371
372         /* check parameter position */
373         if(positional_params && (q = FUNC_NAME(pf_parse_int)(p, &pos)) && *q=='$')
374             p = q+1;
375         else
376             pos = -1;
377
378         /* parse the flags */
379         memset(&flags, 0, sizeof(flags));
380         while(*p) {
381             if(*p=='+' || *p==' ') {
382                 if(flags.Sign != '+')
383                     flags.Sign = *p;
384             } else if(*p == '-')
385                 flags.LeftAlign = *p;
386             else if(*p == '0')
387                 flags.PadZero = *p;
388             else if(*p == '#')
389                 flags.Alternate = *p;
390             else
391                 break;
392
393             p++;
394         }
395
396         /* parse the widh */
397         if(*p == '*') {
398             p++;
399             if(positional_params && (q = FUNC_NAME(pf_parse_int)(p, &i)) && *q=='$')
400                 p = q+1;
401             else
402                 i = -1;
403
404             flags.FieldLength = pf_args(args_ctx, i, VT_INT, valist).get_int;
405             if(flags.FieldLength < 0) {
406                 flags.LeftAlign = '-';
407                 flags.FieldLength = -flags.FieldLength;
408             }
409         } else while(isdigit(*p)) {
410             flags.FieldLength *= 10;
411             flags.FieldLength += *p++ - '0';
412         }
413
414         /* parse the precision */
415         flags.Precision = -1;
416         if(*p == '.') {
417             flags.Precision = 0;
418             p++;
419             if(*p == '*') {
420                 p++;
421                 if(positional_params && (q = FUNC_NAME(pf_parse_int)(p, &i)) && *q=='$')
422                     p = q+1;
423                 else
424                     i = -1;
425
426                 flags.Precision = pf_args(args_ctx, i, VT_INT, valist).get_int;
427             } else while(isdigit(*p)) {
428                 flags.Precision *= 10;
429                 flags.Precision += *p++ - '0';
430             }
431         }
432
433         /* parse argument size modifier */
434         while(*p) {
435             if(*p=='l' && *(p+1)=='l') {
436                 flags.IntegerDouble++;
437                 p += 2;
438             } else if(*p=='h' || *p=='l' || *p=='L') {
439                 flags.IntegerLength = *p;
440                 p++;
441             } else if(*p == 'I') {
442                 if(*(p+1)=='6' && *(p+2)=='4') {
443                     flags.IntegerDouble++;
444                     p += 3;
445                 } else if(*(p+1)=='3' && *(p+2)=='2')
446                     p += 3;
447                 else if(isdigit(*(p+1)) || !*(p+1))
448                     break;
449                 else
450                     p++;
451             } else if(*p == 'w')
452                 flags.WideString = *p++;
453             else if(*p == 'F')
454                 p++; /* ignore */
455             else
456                 break;
457         }
458
459         flags.Format = *p;
460
461         if(flags.Format == 's' || flags.Format == 'S') {
462             i = FUNC_NAME(pf_handle_string)(pf_puts, puts_ctx,
463                     pf_args(args_ctx, pos, VT_PTR, valist).get_ptr,
464                     -1,  &flags, locinfo);
465         } else if(flags.Format == 'c' || flags.Format == 'C') {
466             int ch = pf_args(args_ctx, pos, VT_INT, valist).get_int;
467
468             if((ch&0xff) != ch)
469                 FIXME("multibyte characters printing not supported\n");
470
471             i = FUNC_NAME(pf_handle_string)(pf_puts, puts_ctx, &ch, 1, &flags, locinfo);
472         } else if(flags.Format == 'p') {
473             flags.Format = 'X';
474             flags.PadZero = '0';
475             i = flags.Precision;
476             flags.Precision = 2*sizeof(void*);
477             FUNC_NAME(pf_integer_conv)(buf, sizeof(buf)/sizeof(APICHAR), &flags,
478                                        (ULONG_PTR)pf_args(args_ctx, pos, VT_PTR, valist).get_ptr);
479             flags.PadZero = 0;
480             flags.Precision = i;
481
482 #ifdef PRINTF_WIDE
483             i = FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, buf, -1, &flags, locinfo);
484 #else
485             i = FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, buf, -1, &flags, locinfo);
486 #endif
487         } else if(flags.Format == 'n') {
488             int *used;
489
490             if(!n_format_enabled) {
491                 MSVCRT_INVALID_PMT("\'n\' format specifier disabled", MSVCRT_EINVAL);
492                 return -1;
493             }
494
495             used = pf_args(args_ctx, pos, VT_PTR, valist).get_ptr;
496             *used = written;
497             i = 0;
498         } else if(flags.Format && strchr("diouxX", flags.Format)) {
499             APICHAR *tmp = buf;
500             int max_len;
501
502             /* 0 padding is added after '0x' if Alternate flag is in use */
503             if((flags.Format=='x' || flags.Format=='X') && flags.PadZero && flags.Alternate
504                     && !flags.LeftAlign && flags.Precision<flags.FieldLength-2)
505                 flags.Precision = flags.FieldLength - 2;
506
507             max_len = (flags.FieldLength>flags.Precision ? flags.FieldLength : flags.Precision) + 10;
508             if(max_len > sizeof(buf)/sizeof(APICHAR))
509                 tmp = HeapAlloc(GetProcessHeap(), 0, max_len);
510             if(!tmp)
511                 return -1;
512
513             if(flags.IntegerDouble)
514                 FUNC_NAME(pf_integer_conv)(tmp, max_len, &flags, pf_args(args_ctx, pos,
515                             VT_I8, valist).get_longlong);
516             else if(flags.Format=='d' || flags.Format=='i')
517                 FUNC_NAME(pf_integer_conv)(tmp, max_len, &flags, flags.IntegerLength!='h' ?
518                         pf_args(args_ctx, pos, VT_INT, valist).get_int :
519                         (short)pf_args(args_ctx, pos, VT_INT, valist).get_int);
520             else
521                 FUNC_NAME(pf_integer_conv)(tmp, max_len, &flags, flags.IntegerLength!='h' ?
522                         (unsigned)pf_args(args_ctx, pos, VT_INT, valist).get_int :
523                         (unsigned short)pf_args(args_ctx, pos, VT_INT, valist).get_int);
524
525 #ifdef PRINTF_WIDE
526             i = FUNC_NAME(pf_output_format_wstr)(pf_puts, puts_ctx, tmp, -1, &flags, locinfo);
527 #else
528             i = FUNC_NAME(pf_output_format_str)(pf_puts, puts_ctx, tmp, -1, &flags, locinfo);
529 #endif
530             if(tmp != buf)
531                 HeapFree(GetProcessHeap(), 0, tmp);
532         } else if(flags.Format && strchr("aeEfgG", flags.Format)) {
533             char float_fmt[20], buf_a[32], *tmp = buf_a, *decimal_point;
534             int len = flags.Precision + 10;
535             double val = pf_args(args_ctx, pos, VT_R8, valist).get_double;
536             int r;
537
538             if(flags.Format=='f') {
539                 if(val>-10.0 && val<10.0)
540                     i = 1;
541                 else
542                     i = 1 + log10(val<0 ? -val : val);
543                 /* Default precision is 6, additional space for sign, separator and nullbyte is required */
544                 i += (flags.Precision==-1 ? 6 : flags.Precision) + 3;
545
546                 if(i > len)
547                     len = i;
548             }
549
550             if(len > sizeof(buf_a))
551                 tmp = HeapAlloc(GetProcessHeap(), 0, len);
552             if(!tmp)
553                 return -1;
554
555             FUNC_NAME(pf_rebuild_format_string)(float_fmt, &flags);
556             if(val < 0) {
557                 flags.Sign = '-';
558                 val = -val;
559             }
560
561             sprintf(tmp, float_fmt, val);
562             if(toupper(flags.Format)=='E' || toupper(flags.Format)=='G')
563                 FUNC_NAME(pf_fixup_exponent)(tmp);
564
565             decimal_point = strchr(tmp, '.');
566             if(decimal_point)
567                 *decimal_point = *locinfo->lconv->decimal_point;
568
569             len = strlen(tmp);
570             i = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, &flags, TRUE);
571             if(i < 0)
572                 return i;
573             r = FUNC_NAME(pf_output_str)(pf_puts, puts_ctx, tmp, len, locinfo);
574             if(r < 0)
575                 return r;
576             i += r;
577             if(tmp != buf_a)
578                 HeapFree(GetProcessHeap(), 0, tmp);
579             r = FUNC_NAME(pf_fill)(pf_puts, puts_ctx, len, &flags, FALSE);
580             if(r < 0)
581                 return r;
582             i += r;
583         } else {
584             if(invoke_invalid_param_handler) {
585                 MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0);
586                 *MSVCRT__errno() = MSVCRT_EINVAL;
587                 return -1;
588             }
589
590             continue;
591         }
592
593         if(i < 0)
594             return i;
595         written += i;
596         p++;
597     }
598
599     return written;
600 }
601
602 #ifndef PRINTF_WIDE
603 enum types_clbk_flags {
604     TYPE_CLBK_VA_LIST = 1,
605     TYPE_CLBK_POSITIONAL = 2,
606     TYPE_CLBK_ERROR_POS = 4,
607     TYPE_CLBK_ERROR_TYPE = 8
608 };
609
610 /* This functions stores types of arguments. It uses args[0] internally */
611 static printf_arg arg_clbk_type(void *ctx, int pos, int type, __ms_va_list *valist)
612 {
613     static const printf_arg ret;
614     printf_arg *args = ctx;
615
616     if(pos == -1) {
617         args[0].get_int |= TYPE_CLBK_VA_LIST;
618         return ret;
619     } else
620         args[0].get_int |= TYPE_CLBK_POSITIONAL;
621
622     if(pos<1 || pos>MSVCRT__ARGMAX)
623         args[0].get_int |= TYPE_CLBK_ERROR_POS;
624     else if(args[pos].get_int && args[pos].get_int!=type)
625         args[0].get_int |= TYPE_CLBK_ERROR_TYPE;
626     else
627         args[pos].get_int = type;
628
629     return ret;
630 }
631 #endif
632
633 static int FUNC_NAME(create_positional_ctx)(void *args_ctx, const APICHAR *format, __ms_va_list valist)
634 {
635     struct FUNC_NAME(_str_ctx) puts_ctx = {INT_MAX, NULL};
636     printf_arg *args = args_ctx;
637     int i, j;
638
639     i = FUNC_NAME(pf_printf)(FUNC_NAME(puts_clbk_str), &puts_ctx, format, NULL, TRUE, FALSE,
640             arg_clbk_type, args_ctx, NULL);
641     if(i < 0)
642         return i;
643
644     if(args[0].get_int==0 || args[0].get_int==TYPE_CLBK_VA_LIST)
645         return 0;
646     if(args[0].get_int != TYPE_CLBK_POSITIONAL)
647         return -1;
648
649     for(i=MSVCRT__ARGMAX; i>0; i--)
650         if(args[i].get_int)
651             break;
652
653     for(j=1; j<=i; j++) {
654         switch(args[j].get_int) {
655         case VT_I8:
656             args[j].get_longlong = va_arg(valist, LONGLONG);
657             break;
658         case VT_INT:
659             args[j].get_int = va_arg(valist, int);
660             break;
661         case VT_R8:
662             args[j].get_double = va_arg(valist, double);
663             break;
664         case VT_PTR:
665             args[j].get_ptr = va_arg(valist, void*);
666             break;
667         default:
668             return -1;
669         }
670     }
671
672     return j;
673 }
674
675 #undef APICHAR
676 #undef CONVCHAR
677 #undef FUNC_NAME