* po/*.po: remerge.
[lyx.git] / intl / printf-args.c
blobee0faba16ba7fc1f87737c1cbb5c7f43e4ad35cb
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 #include <config.h>
21 /* Specification. */
22 #include "printf-args.h"
24 #ifdef STATIC
25 STATIC
26 #endif
27 int
28 printf_fetchargs (va_list args, arguments *a)
30 size_t i;
31 argument *ap;
33 for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
34 switch (ap->type)
36 case TYPE_SCHAR:
37 ap->a.a_schar = va_arg (args, /*signed char*/ int);
38 break;
39 case TYPE_UCHAR:
40 ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
41 break;
42 case TYPE_SHORT:
43 ap->a.a_short = va_arg (args, /*short*/ int);
44 break;
45 case TYPE_USHORT:
46 ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
47 break;
48 case TYPE_INT:
49 ap->a.a_int = va_arg (args, int);
50 break;
51 case TYPE_UINT:
52 ap->a.a_uint = va_arg (args, unsigned int);
53 break;
54 case TYPE_LONGINT:
55 ap->a.a_longint = va_arg (args, long int);
56 break;
57 case TYPE_ULONGINT:
58 ap->a.a_ulongint = va_arg (args, unsigned long int);
59 break;
60 #ifdef HAVE_LONG_LONG_INT
61 case TYPE_LONGLONGINT:
62 ap->a.a_longlongint = va_arg (args, long long int);
63 break;
64 case TYPE_ULONGLONGINT:
65 ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
66 break;
67 #endif
68 case TYPE_DOUBLE:
69 ap->a.a_double = va_arg (args, double);
70 break;
71 #ifdef HAVE_LONG_DOUBLE
72 case TYPE_LONGDOUBLE:
73 ap->a.a_longdouble = va_arg (args, long double);
74 break;
75 #endif
76 case TYPE_CHAR:
77 ap->a.a_char = va_arg (args, int);
78 break;
79 #ifdef HAVE_WINT_T
80 case TYPE_WIDE_CHAR:
81 /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by
82 default argument promotions", this is not the case in mingw32,
83 where wint_t is 'unsigned short'. */
84 ap->a.a_wide_char =
85 (sizeof (wint_t) < sizeof (int)
86 ? va_arg (args, int)
87 : va_arg (args, wint_t));
88 break;
89 #endif
90 case TYPE_STRING:
91 ap->a.a_string = va_arg (args, const char *);
92 /* A null pointer is an invalid argument for "%s", but in practice
93 it occurs quite frequently in printf statements that produce
94 debug output. Use a fallback in this case. */
95 if (ap->a.a_string == NULL)
96 ap->a.a_string = "(NULL)";
97 break;
98 #ifdef HAVE_WCHAR_T
99 case TYPE_WIDE_STRING:
100 ap->a.a_wide_string = va_arg (args, const wchar_t *);
101 /* A null pointer is an invalid argument for "%ls", but in practice
102 it occurs quite frequently in printf statements that produce
103 debug output. Use a fallback in this case. */
104 if (ap->a.a_wide_string == NULL)
106 static const wchar_t wide_null_string[] =
108 (wchar_t)'(',
109 (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L',
110 (wchar_t)')',
111 (wchar_t)0
113 ap->a.a_wide_string = wide_null_string;
115 break;
116 #endif
117 case TYPE_POINTER:
118 ap->a.a_pointer = va_arg (args, void *);
119 break;
120 case TYPE_COUNT_SCHAR_POINTER:
121 ap->a.a_count_schar_pointer = va_arg (args, signed char *);
122 break;
123 case TYPE_COUNT_SHORT_POINTER:
124 ap->a.a_count_short_pointer = va_arg (args, short *);
125 break;
126 case TYPE_COUNT_INT_POINTER:
127 ap->a.a_count_int_pointer = va_arg (args, int *);
128 break;
129 case TYPE_COUNT_LONGINT_POINTER:
130 ap->a.a_count_longint_pointer = va_arg (args, long int *);
131 break;
132 #ifdef HAVE_LONG_LONG_INT
133 case TYPE_COUNT_LONGLONGINT_POINTER:
134 ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
135 break;
136 #endif
137 default:
138 /* Unknown type. */
139 return -1;
141 return 0;