2 Copyright © 1995-2017, 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 #if defined(__AROSEXEC_SMP__)
22 #include <aros/atomic.h>
24 extern volatile ULONG safedebug
;
27 /* Can't use ctype.h *sigh* */
28 #define isdigit(x) ((x) >= '0' && (x) <= '9')
29 #define isprint(x) (((x) >= ' ' && (x) <= 128) || (x) >= 160)
32 static inline int my_strlen(const char *c
)
40 static inline int atoi(const char *c
)
53 for (i
= 0; *c
&& isdigit(*c
); c
++) {
58 return (isneg
) ? -i
: i
;
61 /*****************************************************************************
64 #include <proto/arossupport.h>
73 Formats fmt with the specified arguments like printf() (and *not*
74 like RawDoFmt()) and uses a secure way to deliver the message to
75 the user; ie. the user *will* see this message no matter what.
78 fmt - printf()-style format string
81 The number of characters output.
84 This function is not part of a library and may thus be called
96 24-12-95 digulla created
98 ******************************************************************************/
104 result
= vkprintf (fmt
, ap
);
112 int vkprintf (const char * fmt
, va_list args
)
115 static const char uhex
[] = "0123456789ABCDEF";
116 static const char lhex
[] = "0123456789abcdef";
123 #if defined(__AROSEXEC_SMP__)
126 while (bit_test_and_set_long((ULONG
*)&safedebug
, 1)) { asm volatile("pause"); };
129 RawPutChars ((const UBYTE
*)"(null)", 6);
130 #if defined(__AROSEXEC_SMP__)
133 __AROS_ATOMIC_AND_L(safedebug
, ~(1 << 1));
140 #if defined(__AROSEXEC_SMP__)
143 while (bit_test_and_set_long((ULONG
*)&safedebug
, 1)) { asm volatile("pause"); };
168 width
= va_arg (args
, int);
175 while (isdigit(*fmt
)) fmt
++;
178 if (*fmt
== '.') fmt
++;
182 precision
= va_arg (args
, int);
187 precision
= atoi (fmt
);
189 while (isdigit(*fmt
) || *fmt
=='.' || *fmt
=='-' || *fmt
=='+')
200 #ifndef AROS_FAST_BPTR
202 char * str
= va_arg (args
, char *);
206 str
= (char *)((unsigned long)str
<< 2);
216 RawPutChars (str
, len
);
223 char * str
= va_arg (args
, char *);
238 len
= my_strlen (str
);
240 RawPutChars ((const UBYTE
*)str
, len
);
253 char puffer
[sizeof (void *)*2];
255 t
= sizeof (void *)*2;
256 val
= va_arg (args
, IPTR
);
260 puffer
[--t
] = lhex
[val
& 0x0F];
264 RawPutChars ((const UBYTE
*)puffer
, sizeof (void *)*2);
271 c
= va_arg (args
, int);
277 RawPutChars ((const UBYTE
*)"'\\0x", 4);
278 RawPutChar (lhex
[c
/ 16]);
279 RawPutChar (lhex
[c
& 15]);
289 if (fmt
[1] == 'u' || fmt
[1] == 'd' || fmt
[1] == 'x' || fmt
[1] == 'X')
294 lval
= va_arg (args
, long);
296 val
= (lval
< 0) ? -lval
: lval
;
300 val
= va_arg (args
, unsigned long);
314 RawPutChars ((const UBYTE
*)fill
, (width
< 8) ? width
: 8);
327 if (*fmt
== 'd' || *fmt
== 'u')
343 puffer
[--t
] = lhex
[val
% 10];
348 else if (*fmt
== 'x')
352 puffer
[--t
] = lhex
[val
& 0x0F];
361 puffer
[--t
] = uhex
[val
& 0x0F];
371 RawPutChars ((const UBYTE
*)fill
, (width
< 8) ? width
: 8);
375 RawPutChars ((const UBYTE
*)&puffer
[t
], 32-t
);
383 lval
= va_arg (args
, int);
385 val
= (lval
< 0) ? -lval
: lval
;
389 val
= va_arg (args
, unsigned int);
403 fmt
++; /* Next char */
404 } /* while (*fmt); */
405 #if defined(__AROSEXEC_SMP__)
408 __AROS_ATOMIC_AND_L(safedebug
, ~(1 << 1));