fxlibc/src/libc/stdio/internal/printf_common.c

49 lines
1.0 KiB
C
Raw Normal View History

2021-05-09 17:34:00 +02:00
#include <stdio.h>
2020-09-17 19:27:01 +02:00
2020-10-14 12:07:29 +02:00
// internal depency
#include "printf.h"
2020-10-14 12:07:29 +02:00
2020-09-17 19:27:01 +02:00
//TODO: precision handling
int printf_common(struct printf_opt *opt, const char *restrict format)
{
extern int printf_get_options(struct printf_opt *opt,
const char *restrict format);
2020-09-17 19:27:01 +02:00
int saved_p;
char tmp;
2020-09-17 19:27:01 +02:00
int p;
p = -1;
opt->counter = 0;
opt->buffer_cursor = 0;
while (format[++p] != '\0') {
2020-09-17 19:27:01 +02:00
// Check printable char
if (format[p] != '%' || format[p + 1] == '%') {
tmp = format[p];
if (format[p] == '%')
p = p + 1;
(*opt->disp_char)(opt,tmp);
2020-09-17 19:27:01 +02:00
continue;
}
// Get options
saved_p = p;
p = p + printf_get_options(opt, &format[p + 1]);
// Check arg validity
if (((format[p + 1] >= 'a' && format[p + 1] <= 'z') ||
(format[p + 1] >= 'A' && format[p + 1] <= 'Z')) &&
action[(format[p + 1] | 0x20) - 'a'] != NULL) {
tmp = (format[p + 1] | 0x20) - 'a';
(*action[(int)tmp]) (opt,tmp);
2020-09-17 19:27:01 +02:00
p = p + 1;
continue;
}
// Default, print the %
(*opt->disp_char)(opt, '%');
p = saved_p;
}
(*opt->disp_fflush)(opt);
return (opt->counter);
}