xref: /netbsd-src/external/gpl2/xcvs/dist/lib/printf-args.c (revision 5a6c14c844c4c665da5632061aebde7bb2cb5766)
1a7c91847Schristos /* Decomposed printf argument list.
2a7c91847Schristos    Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc.
3a7c91847Schristos 
4a7c91847Schristos    This program is free software; you can redistribute it and/or modify
5a7c91847Schristos    it under the terms of the GNU General Public License as published by
6a7c91847Schristos    the Free Software Foundation; either version 2, or (at your option)
7a7c91847Schristos    any later version.
8a7c91847Schristos 
9a7c91847Schristos    This program is distributed in the hope that it will be useful,
10a7c91847Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
11a7c91847Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12a7c91847Schristos    GNU General Public License for more details.
13a7c91847Schristos 
14a7c91847Schristos    You should have received a copy of the GNU General Public License along
15a7c91847Schristos    with this program; if not, write to the Free Software Foundation,
16a7c91847Schristos    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17*5a6c14c8Schristos #include <sys/cdefs.h>
18*5a6c14c8Schristos __RCSID("$NetBSD: printf-args.c,v 1.2 2016/05/17 14:00:09 christos Exp $");
19*5a6c14c8Schristos 
20a7c91847Schristos 
21a7c91847Schristos #ifdef HAVE_CONFIG_H
22a7c91847Schristos # include <config.h>
23a7c91847Schristos #endif
24a7c91847Schristos 
25a7c91847Schristos /* Specification.  */
26a7c91847Schristos #include "printf-args.h"
27a7c91847Schristos 
28a7c91847Schristos #ifdef STATIC
29a7c91847Schristos STATIC
30a7c91847Schristos #endif
31a7c91847Schristos int
printf_fetchargs(va_list args,arguments * a)32a7c91847Schristos printf_fetchargs (va_list args, arguments *a)
33a7c91847Schristos {
34a7c91847Schristos   size_t i;
35a7c91847Schristos   argument *ap;
36a7c91847Schristos 
37a7c91847Schristos   for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
38a7c91847Schristos     switch (ap->type)
39a7c91847Schristos       {
40a7c91847Schristos       case TYPE_SCHAR:
41a7c91847Schristos 	ap->a.a_schar = va_arg (args, /*signed char*/ int);
42a7c91847Schristos 	break;
43a7c91847Schristos       case TYPE_UCHAR:
44a7c91847Schristos 	ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
45a7c91847Schristos 	break;
46a7c91847Schristos       case TYPE_SHORT:
47a7c91847Schristos 	ap->a.a_short = va_arg (args, /*short*/ int);
48a7c91847Schristos 	break;
49a7c91847Schristos       case TYPE_USHORT:
50a7c91847Schristos 	ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
51a7c91847Schristos 	break;
52a7c91847Schristos       case TYPE_INT:
53a7c91847Schristos 	ap->a.a_int = va_arg (args, int);
54a7c91847Schristos 	break;
55a7c91847Schristos       case TYPE_UINT:
56a7c91847Schristos 	ap->a.a_uint = va_arg (args, unsigned int);
57a7c91847Schristos 	break;
58a7c91847Schristos       case TYPE_LONGINT:
59a7c91847Schristos 	ap->a.a_longint = va_arg (args, long int);
60a7c91847Schristos 	break;
61a7c91847Schristos       case TYPE_ULONGINT:
62a7c91847Schristos 	ap->a.a_ulongint = va_arg (args, unsigned long int);
63a7c91847Schristos 	break;
64a7c91847Schristos #ifdef HAVE_LONG_LONG
65a7c91847Schristos       case TYPE_LONGLONGINT:
66a7c91847Schristos 	ap->a.a_longlongint = va_arg (args, long long int);
67a7c91847Schristos 	break;
68a7c91847Schristos       case TYPE_ULONGLONGINT:
69a7c91847Schristos 	ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
70a7c91847Schristos 	break;
71a7c91847Schristos #endif
72a7c91847Schristos       case TYPE_DOUBLE:
73a7c91847Schristos 	ap->a.a_double = va_arg (args, double);
74a7c91847Schristos 	break;
75a7c91847Schristos #ifdef HAVE_LONG_DOUBLE
76a7c91847Schristos       case TYPE_LONGDOUBLE:
77a7c91847Schristos 	ap->a.a_longdouble = va_arg (args, long double);
78a7c91847Schristos 	break;
79a7c91847Schristos #endif
80a7c91847Schristos       case TYPE_CHAR:
81a7c91847Schristos 	ap->a.a_char = va_arg (args, int);
82a7c91847Schristos 	break;
83a7c91847Schristos #ifdef HAVE_WINT_T
84a7c91847Schristos       case TYPE_WIDE_CHAR:
85a7c91847Schristos 	ap->a.a_wide_char = va_arg (args, wint_t);
86a7c91847Schristos 	break;
87a7c91847Schristos #endif
88a7c91847Schristos       case TYPE_STRING:
89a7c91847Schristos 	ap->a.a_string = va_arg (args, const char *);
90a7c91847Schristos 	break;
91a7c91847Schristos #ifdef HAVE_WCHAR_T
92a7c91847Schristos       case TYPE_WIDE_STRING:
93a7c91847Schristos 	ap->a.a_wide_string = va_arg (args, const wchar_t *);
94a7c91847Schristos 	break;
95a7c91847Schristos #endif
96a7c91847Schristos       case TYPE_POINTER:
97a7c91847Schristos 	ap->a.a_pointer = va_arg (args, void *);
98a7c91847Schristos 	break;
99a7c91847Schristos       case TYPE_COUNT_SCHAR_POINTER:
100a7c91847Schristos 	ap->a.a_count_schar_pointer = va_arg (args, signed char *);
101a7c91847Schristos 	break;
102a7c91847Schristos       case TYPE_COUNT_SHORT_POINTER:
103a7c91847Schristos 	ap->a.a_count_short_pointer = va_arg (args, short *);
104a7c91847Schristos 	break;
105a7c91847Schristos       case TYPE_COUNT_INT_POINTER:
106a7c91847Schristos 	ap->a.a_count_int_pointer = va_arg (args, int *);
107a7c91847Schristos 	break;
108a7c91847Schristos       case TYPE_COUNT_LONGINT_POINTER:
109a7c91847Schristos 	ap->a.a_count_longint_pointer = va_arg (args, long int *);
110a7c91847Schristos 	break;
111a7c91847Schristos #ifdef HAVE_LONG_LONG
112a7c91847Schristos       case TYPE_COUNT_LONGLONGINT_POINTER:
113a7c91847Schristos 	ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
114a7c91847Schristos 	break;
115a7c91847Schristos #endif
116a7c91847Schristos       default:
117a7c91847Schristos 	/* Unknown type.  */
118a7c91847Schristos 	return -1;
119a7c91847Schristos       }
120a7c91847Schristos   return 0;
121a7c91847Schristos }
122