diff --git a/Kconfig b/Kconfig index 3167d3725a1107d218d8184af3f4c4d3a202ca5a..8d1f533e33f933468918d163c2b2b25c269e4f45 100644 --- a/Kconfig +++ b/Kconfig @@ -56,23 +56,9 @@ config STACKSIZE we must also consider the stack, or the program will crash badly at run time. -config MPRINTF - boolean "Use the old mprintf implementation for printf" - depends on !PPSI - default y - help - wrpc-sw has traditionally used mprintf as its printf engine. - Unfortunately, the code base has unclear copyright status, - and we are now able to run pp_printf instead. Such implementation - however has had little testing in wrpc-sw by now. Mprintf - is scheduled to be removed in the future, as soon as pp_printf - is more tested on the field. - - If unsure, say y for the time being. - config PP_PRINTF boolean - default !MPRINTF + default y choice prompt "Implementation of pp_printf" diff --git a/include/wrc.h b/include/wrc.h index 46cbaafcb6291f637a28480e9a1b4c696bad5773..6809ec81ca93f3686bcb37b26de44496bb37b2c4 100644 --- a/include/wrc.h +++ b/include/wrc.h @@ -8,15 +8,10 @@ * Also, this brings in very common and needed headers */ #include <inttypes.h> -#ifdef CONFIG_MPRINTF -int mprintf(char const *format, ...) - __attribute__((format(printf,1,2))); -#else #include <pp-printf.h> #define mprintf pp_printf #define vprintf pp_vprintf #define sprintf pp_sprintf -#endif #undef offsetof #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER) diff --git a/lib/lib.mk b/lib/lib.mk index 18fda18724624b84559cda0d7f8efe548f27e4df..d7f342b414d8120c278b7c925b24f9641fd2431c 100644 --- a/lib/lib.mk +++ b/lib/lib.mk @@ -1,5 +1,3 @@ -obj-$(CONFIG_MPRINTF) += lib/mprintf.o - obj-y += lib/util.o lib/atoi.o obj-y += lib/net.o diff --git a/lib/mprintf.c b/lib/mprintf.c deleted file mode 100644 index d802e6eb1a3c1c502c314ae1ba3095111a524233..0000000000000000000000000000000000000000 --- a/lib/mprintf.c +++ /dev/null @@ -1,230 +0,0 @@ -#include <stdio.h> -#include <stdarg.h> -#include <stdlib.h> - -#include "uart.h" -#include "util.h" - -int vprintf(char const *format, va_list ap) -{ - unsigned char scratch[16]; - unsigned char format_flag; - unsigned int u_val = 0; - unsigned char base; - unsigned char *ptr; - unsigned char width = 0; - unsigned char fill; - - while (1) { - - width = 0; - fill = ' '; - while ((format_flag = *format++) != '%') { - if (!format_flag) { - va_end(ap); - return (0); - } - - uart_write_byte(format_flag); - } - - // check for zero pad - format_flag = *format - '0'; - if (format_flag == 0) // zero pad - { - fill = '0'; - format++; - } - // check for width spec - format_flag = *format - '0'; - if (format_flag > 0 && format_flag <= 9) // width set - { - width = format_flag; - format++; - } - - switch (format_flag = *format++) { - case 'c': - format_flag = va_arg(ap, int); - - //fall through - - default: - uart_write_byte(format_flag); - - continue; - - case 'S': - case 's': - ptr = (unsigned char *)va_arg(ap, char *); - while (*ptr) - uart_write_byte(*ptr++); - continue; - - case 'd': - - base = 10; - goto CONVERSION_LOOP; - - case 'u': - base = 10; - goto CONVERSION_LOOP; - - case 'x': - base = 16; - -CONVERSION_LOOP: - - u_val = va_arg(ap, unsigned int); - if ((format_flag == 'd') && (u_val & 0x80000000)) { - uart_write_byte('-'); - u_val = -u_val; - } - - ptr = scratch + 16; - - *--ptr = 0; - - do { - char ch = (u_val % base) + '0'; - if (ch > '9') - ch += 'a' - '9' - 1; - - *--ptr = ch; - - u_val /= base; - - if (width) - width--; - - } while (u_val > 0); - - while (width--) - *--ptr = fill; - - while (*ptr) - uart_write_byte(*ptr++); - - } - } - return 0; -} - -static int _p_vsprintf(char const *format, va_list ap, char *dst) -{ - unsigned char scratch[16]; - unsigned char format_flag; - unsigned int u_val = 0; - unsigned char base; - unsigned char *ptr; - unsigned char width = 0; - unsigned char fill; - - while (1) { - - width = 0; - fill = ' '; - while ((format_flag = *format++) != '%') { - if (!format_flag) { - va_end(ap); - *dst++ = 0; - return (0); - } - - *dst++ = format_flag; - } - - // check for zero pad - format_flag = *format - '0'; - if (format_flag == 0) // zero pad - { - fill = '0'; - format++; - } - // check for width spec - format_flag = *format - '0'; - if (format_flag > 0 && format_flag <= 9) // width set - { - width = format_flag; - format++; - } - - switch (format_flag = *format++) { - case 'c': - format_flag = va_arg(ap, int); - - //fall through - - default: - *dst++ = format_flag; - - continue; - - case 'S': - case 's': - ptr = (unsigned char *)va_arg(ap, char *); - while (*ptr) - *dst++ = *ptr++; - continue; - - case 'd': - case 'u': - base = 10; - goto CONVERSION_LOOP; - - case 'x': - base = 16; - -CONVERSION_LOOP: - - u_val = va_arg(ap, unsigned int); - - ptr = scratch + 16; - - *--ptr = 0; - - do { - char ch = (u_val % base) + '0'; - if (ch > '9') - ch += 'a' - '9' - 1; - - *--ptr = ch; - - u_val /= base; - - if (width) - width--; - - } while (u_val > 0); - -// while (width--) -// *--ptr = fill; - - while (*ptr) - *dst++ = *ptr++; - - } - } - *dst++ = 0; - return 0; -} - -int mprintf(char const *format, ...) -{ - int rval; - va_list ap; - va_start(ap, format); - rval = vprintf(format, ap); - va_end(ap); - return rval; - -} - -int sprintf(char *dst, char const *format, ...) -{ - va_list ap; - va_start(ap, format); - int r = _p_vsprintf(format, ap, dst); - return r; - -}