18 #if defined (POK_NEEDS_DEBUG) || defined (POK_NEEDS_INSTRUMENTATION) || defined (POK_NEEDS_COVERAGE_INFOS)
25 static const char digits[] =
"0123456789abcdef";
27 #define INT_UNSIGNED 1
33 #define MY_BUF_SIZE 8192
41 char buff[MY_BUF_SIZE];
53 typedef int (*t_fmtfun)(
union u_arg *arg,
struct s_file *file,
int flags);
66 static void my_fflush(
struct s_file *file)
72 static struct s_file* init_buffered_output(
void)
74 static struct s_file res;
80 static void my_putc(
char c,
struct s_file *file)
82 file->buff[file->pos++] = c;
84 if (file->pos == MY_BUF_SIZE)
90 static void close_buffered_output(
struct s_file *file)
99 static int conv(
unsigned int n,
int base,
int dig[])
114 static int my_printnbr_base (
unsigned int n,
129 count = i = conv (n, card, digits);
133 my_putc(base[digits[i]], file);
139 static int print_int (
union u_arg* value,
147 if (value->sint == 0)
153 if (flags == INT_SIGNED)
158 value->uint = -value->sint;
163 value->uint = value->sint;
167 return my_printnbr_base (value->uint, digits, 10, file) + sh;
170 static int print_str (
union u_arg* value,
struct s_file* file,
int flags)
180 for (; *s; ++count, ++s)
188 static int print_char(
union u_arg* value,
struct s_file* file,
int flags)
200 static int print_base(
union u_arg* value,
struct s_file* file,
int flags)
202 return my_printnbr_base (value->uint, digits, flags, file);
205 static const struct s_format formats[] =
207 {
'd', print_int, INT_SIGNED },
208 {
'i', print_int, INT_SIGNED },
209 {
'u', print_int, INT_UNSIGNED },
210 {
's', print_str, 0 },
211 {
'c', print_char, 0 },
212 {
'o', print_base, BASE_OCT },
213 {
'x', print_base, BASE_HEX },
217 static int special_char (
char fmt,
223 for (i = 0; formats[i].fun; ++i)
225 if (formats[i].ch == fmt)
233 return formats[i].fun(value, file, formats[i].flags);
244 return 1 + (fmt !=
'%');
252 int vprintf (
const char* format, va_list args)
260 for (file = init_buffered_output();
262 format += (*format ==
'%' ? 2 : 1))
271 if (*(format + 1) !=
'%')
273 arg.value = va_arg(args,
unsigned long);
276 count += special_char(*(format + 1), &arg, file);
280 my_putc(*format, file);
285 close_buffered_output(file);
289 int printf (
const char *format, ...)
294 va_start (args, format);
295 res = vprintf (format, args);