Commit 634b29f2 authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Grzegorz Daniluk

kill mprintf, since pp_printf is better and solid

mprintf is of uncertain copyright status, and that's why
we added pp_printf (actually, that's why I picked pp_printf
fro ptp-proposal and made it a standalone thing).

Now that everyone involved confirms pp_printf is well tested,
let's remove mprintf.  We still accept mprintf in the callers,
because the name is used by our ptp-noposix submodule, and I'm
sure people has it in their fingers and it will appear again.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 8c636817
......@@ -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"
......
......@@ -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)
......
obj-$(CONFIG_MPRINTF) += lib/mprintf.o
obj-y += lib/util.o lib/atoi.o
obj-y += lib/net.o
......
#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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment