adds ehrenberg platform

This commit is contained in:
2024-01-13 23:06:01 +01:00
parent 1d55083a55
commit 13cd5cc76d
17 changed files with 829 additions and 71 deletions

View File

@@ -21,6 +21,10 @@ size_t strnlen (const char *str, size_t n)
return str - start;
}
static void fprintf_putch(int ch, void** data)
{
putchar(ch);
}
static void sprintf_putch(int ch, void** data)
{
char** pstr = (char**)data;
@@ -100,13 +104,13 @@ static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt
{
register const char* p;
const char* last_fmt;
register int ch, err;
register int ch;
unsigned long num;
int base, lflag, width, precision, altflag;
int base, lflag, width, precision;
char padc;
while (1) {
while ((ch = *(unsigned char *) fmt) != '%') {
while ((ch = *(const char *) fmt) != '%') {
if (ch == '\0')
return;
fmt++;
@@ -120,9 +124,8 @@ static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt
width = -1;
precision = -1;
lflag = 0;
altflag = 0;
reswitch:
switch (ch = *(unsigned char *) fmt++) {
switch (ch = *(const char *) fmt++) {
// flag to pad on the right
case '-':
@@ -162,7 +165,6 @@ static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt
goto reswitch;
case '#':
altflag = 1;
goto reswitch;
process_precision:
@@ -170,24 +172,17 @@ static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt
width = precision, precision = -1;
goto reswitch;
// long flag
case 'l':
case 'l': // long flag
if (lflag)
goto bad;
goto reswitch;
// character
case 'c':
case 'c': // character
putch(va_arg(ap, int), putdat);
break;
// double
case 'f':
case 'f': // double
print_double(putch, putdat, va_arg(ap, double), width, precision);
break;
// string
case 's':
case 's': // string
if ((p = va_arg(ap, char *)) == NULL)
p = "(null)";
if (width > 0 && padc != '-')
@@ -200,9 +195,7 @@ static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt
for (; width > 0; width--)
putch(' ', putdat);
break;
// (signed) decimal
case 'd':
case 'd': // (signed) decimal
num = getint(&ap, lflag);
if ((long) num < 0) {
putch('-', putdat);
@@ -210,41 +203,30 @@ static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt
}
base = 10;
goto signed_number;
// unsigned decimal
case 'u':
case 'u': // unsigned decimal
base = 10;
goto unsigned_number;
// (unsigned) octal
case 'o':
case 'o': // (unsigned) octal
// should do something with padding so it's always 3 octits
base = 8;
goto unsigned_number;
// pointer
case 'p':
case 'p':// pointer
lflag = 1;
putch('0', putdat);
putch('x', putdat);
/* fall through to 'x' */
// (unsigned) hexadecimal
case 'x':
__attribute__((fallthrough));
case 'x': // (unsigned) hexadecimal
base = 16;
unsigned_number:
unsigned_number:
num = getuint(&ap, lflag);
signed_number:
signed_number:
printnum(putch, putdat, num, base, width, padc);
break;
// escaped '%' character
case '%':
case '%': // escaped '%' character
putch(ch, putdat);
break;
// unrecognized escape sequence - just print it literally
default:
default: // unrecognized escape sequence - just print it literally
bad:
putch('%', putdat);
fmt = last_fmt;
@@ -258,7 +240,7 @@ int __wrap_printf(const char* fmt, ...)
va_list ap;
va_start(ap, fmt);
vprintfmt((void*)putchar, 0, fmt, ap);
vprintfmt(fprintf_putch, 0, fmt, ap);
va_end(ap);
return 0; // incorrect return value, but who cares, anyway?