Added vorbis-tools.
[vorbis-lancer-gcc.git] / vorbis-tools-1.2.0 / intl / printf-args.c
blob47b73d2c1dee4d8676d26a7b2063cbb39bb14330
1 /* Decomposed printf argument list.
2 Copyright (C) 1999, 2002-2003, 2005-2006 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 USA. */
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 /* Specification. */
24 #include "printf-args.h"
26 #ifdef STATIC
27 STATIC
28 #endif
29 int
30 printf_fetchargs (va_list args, arguments *a)
32 size_t i;
33 argument *ap;
35 for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
36 switch (ap->type)
38 case TYPE_SCHAR:
39 ap->a.a_schar = va_arg (args, /*signed char*/ int);
40 break;
41 case TYPE_UCHAR:
42 ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
43 break;
44 case TYPE_SHORT:
45 ap->a.a_short = va_arg (args, /*short*/ int);
46 break;
47 case TYPE_USHORT:
48 ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
49 break;
50 case TYPE_INT:
51 ap->a.a_int = va_arg (args, int);
52 break;
53 case TYPE_UINT:
54 ap->a.a_uint = va_arg (args, unsigned int);
55 break;
56 case TYPE_LONGINT:
57 ap->a.a_longint = va_arg (args, long int);
58 break;
59 case TYPE_ULONGINT:
60 ap->a.a_ulongint = va_arg (args, unsigned long int);
61 break;
62 #ifdef HAVE_LONG_LONG
63 case TYPE_LONGLONGINT:
64 ap->a.a_longlongint = va_arg (args, long long int);
65 break;
66 case TYPE_ULONGLONGINT:
67 ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
68 break;
69 #endif
70 case TYPE_DOUBLE:
71 ap->a.a_double = va_arg (args, double);
72 break;
73 #ifdef HAVE_LONG_DOUBLE
74 case TYPE_LONGDOUBLE:
75 ap->a.a_longdouble = va_arg (args, long double);
76 break;
77 #endif
78 case TYPE_CHAR:
79 ap->a.a_char = va_arg (args, int);
80 break;
81 #ifdef HAVE_WINT_T
82 case TYPE_WIDE_CHAR:
83 /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by
84 default argument promotions", this is not the case in mingw32,
85 where wint_t is 'unsigned short'. */
86 ap->a.a_wide_char =
87 (sizeof (wint_t) < sizeof (int)
88 ? va_arg (args, int)
89 : va_arg (args, wint_t));
90 break;
91 #endif
92 case TYPE_STRING:
93 ap->a.a_string = va_arg (args, const char *);
94 /* A null pointer is an invalid argument for "%s", but in practice
95 it occurs quite frequently in printf statements that produce
96 debug output. Use a fallback in this case. */
97 if (ap->a.a_string == NULL)
98 ap->a.a_string = "(NULL)";
99 break;
100 #ifdef HAVE_WCHAR_T
101 case TYPE_WIDE_STRING:
102 ap->a.a_wide_string = va_arg (args, const wchar_t *);
103 /* A null pointer is an invalid argument for "%ls", but in practice
104 it occurs quite frequently in printf statements that produce
105 debug output. Use a fallback in this case. */
106 if (ap->a.a_wide_string == NULL)
108 static const wchar_t wide_null_string[] =
110 (wchar_t)'(',
111 (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L',
112 (wchar_t)')',
113 (wchar_t)0
115 ap->a.a_wide_string = wide_null_string;
117 break;
118 #endif
119 case TYPE_POINTER:
120 ap->a.a_pointer = va_arg (args, void *);
121 break;
122 case TYPE_COUNT_SCHAR_POINTER:
123 ap->a.a_count_schar_pointer = va_arg (args, signed char *);
124 break;
125 case TYPE_COUNT_SHORT_POINTER:
126 ap->a.a_count_short_pointer = va_arg (args, short *);
127 break;
128 case TYPE_COUNT_INT_POINTER:
129 ap->a.a_count_int_pointer = va_arg (args, int *);
130 break;
131 case TYPE_COUNT_LONGINT_POINTER:
132 ap->a.a_count_longint_pointer = va_arg (args, long int *);
133 break;
134 #ifdef HAVE_LONG_LONG
135 case TYPE_COUNT_LONGLONGINT_POINTER:
136 ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
137 break;
138 #endif
139 default:
140 /* Unknown type. */
141 return -1;
143 return 0;