18 |
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 |
Boston, MA 02111-1307, USA. */ |
Boston, MA 02111-1307, USA. */ |
20 |
|
|
21 |
#ifdef __STDC__ |
#ifdef HAVE_CONFIG_H |
22 |
|
#include "config.h" |
23 |
|
#endif |
24 |
|
#include <ansidecl.h> |
25 |
|
#ifdef ANSI_PROTOTYPES |
26 |
#include <stdarg.h> |
#include <stdarg.h> |
27 |
#else |
#else |
28 |
#include <varargs.h> |
#include <varargs.h> |
29 |
#endif |
#endif |
30 |
#include <stdio.h> |
#include <stdio.h> |
31 |
#include <string.h> |
#include <string.h> |
32 |
#include <ansidecl.h> |
#ifdef HAVE_STDLIB_H |
33 |
|
#include <stdlib.h> |
34 |
|
#else |
35 |
|
extern unsigned long strtoul (); |
36 |
|
extern PTR malloc (); |
37 |
|
#endif |
38 |
|
#include "libiberty.h" |
39 |
|
|
40 |
#ifdef TEST |
#ifdef TEST |
41 |
int global_total_width; |
int global_total_width; |
42 |
#endif |
#endif |
43 |
|
|
44 |
unsigned long strtoul (); |
|
45 |
char *malloc (); |
static int int_vasprintf PARAMS ((char **, const char *, va_list *)); |
46 |
|
|
47 |
static int |
static int |
48 |
int_vasprintf (result, format, args) |
int_vasprintf (result, format, args) |
70 |
total_width += abs (va_arg (ap, int)); |
total_width += abs (va_arg (ap, int)); |
71 |
} |
} |
72 |
else |
else |
73 |
total_width += strtoul (p, &p, 10); |
total_width += strtoul (p, (char **) &p, 10); |
74 |
if (*p == '.') |
if (*p == '.') |
75 |
{ |
{ |
76 |
++p; |
++p; |
80 |
total_width += abs (va_arg (ap, int)); |
total_width += abs (va_arg (ap, int)); |
81 |
} |
} |
82 |
else |
else |
83 |
total_width += strtoul (p, &p, 10); |
total_width += strtoul (p, (char **) &p, 10); |
84 |
} |
} |
85 |
while (strchr ("hlL", *p)) |
while (strchr ("hlL", *p)) |
86 |
++p; |
++p; |
115 |
(void) va_arg (ap, char *); |
(void) va_arg (ap, char *); |
116 |
break; |
break; |
117 |
} |
} |
118 |
|
p++; |
119 |
} |
} |
120 |
} |
} |
121 |
#ifdef TEST |
#ifdef TEST |
142 |
} |
} |
143 |
|
|
144 |
#ifdef TEST |
#ifdef TEST |
145 |
void |
static void checkit PARAMS ((const char *, ...)); |
146 |
checkit |
|
147 |
#ifdef __STDC__ |
static void |
148 |
(const char* format, ...) |
checkit VPARAMS ((const char* format, ...)) |
|
#else |
|
|
(va_alist) |
|
|
va_dcl |
|
|
#endif |
|
149 |
{ |
{ |
150 |
va_list args; |
va_list args; |
151 |
char *result; |
char *result; |
152 |
|
#ifndef ANSI_PROTOTYPES |
153 |
|
const char *format; |
154 |
|
#endif |
155 |
|
|
156 |
#ifdef __STDC__ |
VA_START (args, format); |
157 |
va_start (args, format); |
|
158 |
#else |
#ifndef ANSI_PROTOTYPES |
159 |
char *format; |
format = va_arg (args, const char *); |
|
va_start (args); |
|
|
format = va_arg (args, char *); |
|
160 |
#endif |
#endif |
161 |
|
|
162 |
vasprintf (&result, format, args); |
vasprintf (&result, format, args); |
163 |
if (strlen (result) < global_total_width) |
if (strlen (result) < (size_t) global_total_width) |
164 |
printf ("PASS: "); |
printf ("PASS: "); |
165 |
else |
else |
166 |
printf ("FAIL: "); |
printf ("FAIL: "); |
167 |
printf ("%d %s\n", global_total_width, result); |
printf ("%d %s\n", global_total_width, result); |
168 |
} |
} |
169 |
|
|
170 |
|
extern int main PARAMS ((void)); |
171 |
|
|
172 |
int |
int |
173 |
main () |
main () |
174 |
{ |
{ |
179 |
checkit ("%s", "jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\ |
checkit ("%s", "jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\ |
180 |
777777777777777777333333333333366666666666622222222222777777777777733333"); |
777777777777777777333333333333366666666666622222222222777777777777733333"); |
181 |
checkit ("%f%s%d%s", 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx"); |
checkit ("%f%s%d%s", 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx"); |
182 |
|
|
183 |
|
return 0; |
184 |
} |
} |
185 |
#endif /* TEST */ |
#endif /* TEST */ |