c938192b7add9868eadc30877c5cab2dfa96fb89
[gnulib.git] / lib / printf-args.h
1 /* Decomposed printf argument list.
2    Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
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
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License along
15    with this program; if not, write to the Free Software Foundation,
16    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17
18 #ifndef _PRINTF_ARGS_H
19 #define _PRINTF_ARGS_H
20
21 /* Get wchar_t.  */
22 #ifdef HAVE_WCHAR_T
23 # include <stddef.h>
24 #endif
25
26 /* Get wint_t.  */
27 #ifdef HAVE_WINT_T
28 # include <wchar.h>
29 #endif
30
31 /* Get va_list.  */
32 #include <stdarg.h>
33
34
35 /* Argument types */
36 typedef enum
37 {
38   TYPE_NONE,
39   TYPE_SCHAR,
40   TYPE_UCHAR,
41   TYPE_SHORT,
42   TYPE_USHORT,
43   TYPE_INT,
44   TYPE_UINT,
45   TYPE_LONGINT,
46   TYPE_ULONGINT,
47 #ifdef HAVE_LONG_LONG
48   TYPE_LONGLONGINT,
49   TYPE_ULONGLONGINT,
50 #endif
51   TYPE_DOUBLE,
52 #ifdef HAVE_LONG_DOUBLE
53   TYPE_LONGDOUBLE,
54 #endif
55   TYPE_CHAR,
56 #ifdef HAVE_WINT_T
57   TYPE_WIDE_CHAR,
58 #endif
59   TYPE_STRING,
60 #ifdef HAVE_WCHAR_T
61   TYPE_WIDE_STRING,
62 #endif
63   TYPE_POINTER,
64   TYPE_COUNT_SCHAR_POINTER,
65   TYPE_COUNT_SHORT_POINTER,
66   TYPE_COUNT_INT_POINTER,
67   TYPE_COUNT_LONGINT_POINTER
68 #ifdef HAVE_LONG_LONG
69 , TYPE_COUNT_LONGLONGINT_POINTER
70 #endif
71 } arg_type;
72
73 /* Polymorphic argument */
74 typedef struct
75 {
76   arg_type type;
77   union
78   {
79     signed char                 a_schar;
80     unsigned char               a_uchar;
81     short                       a_short;
82     unsigned short              a_ushort;
83     int                         a_int;
84     unsigned int                a_uint;
85     long int                    a_longint;
86     unsigned long int           a_ulongint;
87 #ifdef HAVE_LONG_LONG
88     long long int               a_longlongint;
89     unsigned long long int      a_ulonglongint;
90 #endif
91     float                       a_float;
92     double                      a_double;
93 #ifdef HAVE_LONG_DOUBLE
94     long double                 a_longdouble;
95 #endif
96     int                         a_char;
97 #ifdef HAVE_WINT_T
98     wint_t                      a_wide_char;
99 #endif
100     const char*                 a_string;
101 #ifdef HAVE_WCHAR_T
102     const wchar_t*              a_wide_string;
103 #endif
104     void*                       a_pointer;
105     signed char *               a_count_schar_pointer;
106     short *                     a_count_short_pointer;
107     int *                       a_count_int_pointer;
108     long int *                  a_count_longint_pointer;
109 #ifdef HAVE_LONG_LONG
110     long long int *             a_count_longlongint_pointer;
111 #endif
112   }
113   a;
114 }
115 argument;
116
117 typedef struct
118 {
119   unsigned int count;
120   argument *arg;
121 }
122 arguments;
123
124
125 /* Fetch the arguments, putting them into a. */
126 #ifdef STATIC
127 STATIC
128 #else
129 extern
130 #endif
131 int printf_fetchargs (va_list args, arguments *a);
132
133 #endif /* _PRINTF_ARGS_H */