2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Formats a message and makes sure the user will see it.
9 #include <aros/config.h>
10 #include <aros/arossupportbase.h>
13 #include <aros/system.h>
15 #include <proto/exec.h>
16 #include <proto/arossupport.h>
19 #include <exec/execbase.h>
21 /* Can't use ctype.h *sigh* */
22 #define isdigit(x) ((x) >= '0' && (x) <= '9')
23 #define isprint(x) (((x) >= ' ' && (x) <= 128) || (x) >= 160)
26 static inline int my_strlen(const char *c
)
34 static inline int atoi(const char *c
)
47 for (i
= 0; *c
&& isdigit(*c
); c
++) {
52 return (isneg
) ? -i
: i
;
55 /*****************************************************************************
58 #include <proto/arossupport.h>
67 Formats fmt with the specified arguments like printf() (and *not*
68 like RawDoFmt()) and uses a secure way to deliver the message to
69 the user; ie. the user *will* see this message no matter what.
72 fmt - printf()-style format string
75 The number of characters output.
78 This function is not part of a library and may thus be called
90 24-12-95 digulla created
92 ******************************************************************************/
98 result
= vkprintf (fmt
, ap
);
106 int vkprintf (const char * fmt
, va_list args
)
109 static const char uhex
[] = "0123456789ABCDEF";
110 static const char lhex
[] = "0123456789abcdef";
117 RawPutChars ("(null)", 6);
144 width
= va_arg (args
, int);
151 while (isdigit(*fmt
)) fmt
++;
154 if (*fmt
== '.') fmt
++;
158 precision
= va_arg (args
, int);
163 precision
= atoi (fmt
);
165 while (isdigit(*fmt
) || *fmt
=='.' || *fmt
=='-' || *fmt
=='+')
176 #ifndef AROS_FAST_BPTR
178 char * str
= va_arg (args
, char *);
182 str
= (char *)((unsigned long)str
<< 2);
192 RawPutChars (str
, len
);
199 char * str
= va_arg (args
, char *);
214 len
= my_strlen (str
);
216 RawPutChars (str
, len
);
229 char puffer
[sizeof (void *)*2];
231 t
= sizeof (void *)*2;
232 val
= va_arg (args
, IPTR
);
236 puffer
[--t
] = lhex
[val
& 0x0F];
240 RawPutChars (puffer
, sizeof (void *)*2);
247 c
= va_arg (args
, int);
253 RawPutChars ("'\\0x", 4);
254 RawPutChar (lhex
[c
/ 16]);
255 RawPutChar (lhex
[c
& 15]);
265 if (fmt
[1] == 'u' || fmt
[1] == 'd' || fmt
[1] == 'x' || fmt
[1] == 'X')
270 lval
= va_arg (args
, long);
272 val
= (lval
< 0) ? -lval
: lval
;
276 val
= va_arg (args
, unsigned long);
290 RawPutChars (fill
, (width
< 8) ? width
: 8);
303 if (*fmt
== 'd' || *fmt
== 'u')
319 puffer
[--t
] = lhex
[val
% 10];
324 else if (*fmt
== 'x')
328 puffer
[--t
] = lhex
[val
& 0x0F];
337 puffer
[--t
] = uhex
[val
& 0x0F];
347 RawPutChars (fill
, (width
< 8) ? width
: 8);
351 RawPutChars (&puffer
[t
], 32-t
);
359 lval
= va_arg (args
, int);
361 val
= (lval
< 0) ? -lval
: lval
;
365 val
= va_arg (args
, unsigned int);
379 fmt
++; /* Next char */
380 } /* while (*fmt); */