From 1387c8713bc85333d4a30fe63a1078e78d9d02e5 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 15 Jun 2019 13:53:20 +0200 Subject: [PATCH] Now that printf and scanf contain no FILE*-specific code, we can move them into core (and split them up). --- lang/cem/libcc.ansi/build.lua | 3 +- .../{sys/stdio => core/printf}/doprnt.c | 30 ++++---- .../stdio/loc_incl.h => core/printf/doprnt.h} | 40 ++++------ .../{sys/stdio => core/printf}/fltpr.c | 2 +- .../{sys/stdio => core/printf}/fprintf.c | 1 - .../{sys/stdio => core/printf}/icompute.c | 2 +- .../{sys/stdio => core/printf}/printf.c | 1 - lang/cem/libcc.ansi/core/printf/snprintf.c | 23 ++++++ .../{sys/stdio => core/printf}/sprintf.c | 1 - .../{sys/stdio => core/printf}/vfprintf.c | 8 +- .../{sys/stdio => core/printf}/vprintf.c | 1 - .../{sys/stdio => core/printf}/vsnprintf.c | 8 +- .../{sys/stdio => core/printf}/vsprintf.c | 1 - .../{sys/stdio => core/scanf}/doscan.c | 77 ++++++++++--------- lang/cem/libcc.ansi/core/scanf/doscan.h | 23 ++++++ .../{sys/stdio => core/scanf}/fscanf.c | 1 - .../{sys/stdio => core/scanf}/scanf.c | 1 - .../{sys/stdio => core/scanf}/sscanf.c | 6 +- .../{sys/stdio => core/scanf}/vfscanf.c | 6 +- lang/cem/libcc.ansi/headers/ack/emufile.h | 3 + lang/cem/libcc.ansi/headers/stdio.h | 3 + lang/cem/libcc.ansi/sys/stdio/fclose.c | 1 - lang/cem/libcc.ansi/sys/stdio/fdopen.c | 1 - lang/cem/libcc.ansi/sys/stdio/fflush.c | 1 - lang/cem/libcc.ansi/sys/stdio/fillbuf.c | 1 - lang/cem/libcc.ansi/sys/stdio/flushbuf.c | 1 - lang/cem/libcc.ansi/sys/stdio/fopen.c | 1 - lang/cem/libcc.ansi/sys/stdio/freopen.c | 1 - lang/cem/libcc.ansi/sys/stdio/fseek.c | 1 - lang/cem/libcc.ansi/sys/stdio/ftell.c | 1 - lang/cem/libcc.ansi/sys/stdio/setbuf.c | 1 - lang/cem/libcc.ansi/sys/stdio/setvbuf.c | 1 - lang/cem/libcc.ansi/sys/stdio/snprintf.c | 41 ---------- lang/cem/libcc.ansi/sys/stdio/tmpfile.c | 1 - lang/cem/libcc.ansi/sys/stdio/tmpnam.c | 1 - lang/cem/libcc.ansi/sys/stdio/ungetc.c | 1 - 36 files changed, 141 insertions(+), 155 deletions(-) rename lang/cem/libcc.ansi/{sys/stdio => core/printf}/doprnt.c (94%) rename lang/cem/libcc.ansi/{sys/stdio/loc_incl.h => core/printf/doprnt.h} (57%) rename lang/cem/libcc.ansi/{sys/stdio => core/printf}/fltpr.c (99%) rename lang/cem/libcc.ansi/{sys/stdio => core/printf}/fprintf.c (93%) rename lang/cem/libcc.ansi/{sys/stdio => core/printf}/icompute.c (94%) rename lang/cem/libcc.ansi/{sys/stdio => core/printf}/printf.c (93%) create mode 100644 lang/cem/libcc.ansi/core/printf/snprintf.c rename lang/cem/libcc.ansi/{sys/stdio => core/printf}/sprintf.c (93%) rename lang/cem/libcc.ansi/{sys/stdio => core/printf}/vfprintf.c (66%) rename lang/cem/libcc.ansi/{sys/stdio => core/printf}/vprintf.c (92%) rename lang/cem/libcc.ansi/{sys/stdio => core/printf}/vsnprintf.c (79%) rename lang/cem/libcc.ansi/{sys/stdio => core/printf}/vsprintf.c (92%) rename lang/cem/libcc.ansi/{sys/stdio => core/scanf}/doscan.c (90%) create mode 100644 lang/cem/libcc.ansi/core/scanf/doscan.h rename lang/cem/libcc.ansi/{sys/stdio => core/scanf}/fscanf.c (93%) rename lang/cem/libcc.ansi/{sys/stdio => core/scanf}/scanf.c (93%) rename lang/cem/libcc.ansi/{sys/stdio => core/scanf}/sscanf.c (83%) rename lang/cem/libcc.ansi/{sys/stdio => core/scanf}/vfscanf.c (77%) delete mode 100644 lang/cem/libcc.ansi/sys/stdio/snprintf.c diff --git a/lang/cem/libcc.ansi/build.lua b/lang/cem/libcc.ansi/build.lua index ee1049d66..4cb90e05b 100644 --- a/lang/cem/libcc.ansi/build.lua +++ b/lang/cem/libcc.ansi/build.lua @@ -39,6 +39,8 @@ for _, plat in ipairs(vars.plats) do "./core/math/*.c", "./core/math/*.e", "./core/misc/*.c", + "./core/printf/*.c", + "./core/scanf/*.c", "./core/setjmp/*.c", "./core/setjmp/*.e", "./core/stdlib/*.c", @@ -57,7 +59,6 @@ for _, plat in ipairs(vars.plats) do "./core/stdlib/ext_fmt.h", "./core/time/loc_time.h", "./sys/malloc/malloc.h", - "./sys/stdio/loc_incl.h", }, vars = { plat = plat } } diff --git a/lang/cem/libcc.ansi/sys/stdio/doprnt.c b/lang/cem/libcc.ansi/core/printf/doprnt.c similarity index 94% rename from lang/cem/libcc.ansi/sys/stdio/doprnt.c rename to lang/cem/libcc.ansi/core/printf/doprnt.c index 8c97fb5a4..3eae73f0c 100644 --- a/lang/cem/libcc.ansi/sys/stdio/doprnt.c +++ b/lang/cem/libcc.ansi/core/printf/doprnt.c @@ -7,7 +7,7 @@ #include #include #include -#include "loc_incl.h" +#include "doprnt.h" #if ACKCONF_WANT_STDIO @@ -44,15 +44,13 @@ gnum(register const char* f, int* ip, va_list* app) #define set_pointer(flags) /* compilation might continue */ #endif +int (*_doprnt_put)(int c); + #define PUTC(c) \ do \ { \ - int i = putc(c, stream); \ - if (i == EOF) \ - { \ - if (ferror(stream)) \ - return -1; \ - } \ + if (_doprnt_put(c)) \ + return -1; \ } while (0) /* print an ordinal number */ @@ -157,7 +155,7 @@ o_print(va_list* ap, int flags, char* s, char c, int precision, int is_signed) return s; } -int _doprnt(register const char* fmt, va_list ap, void (*put)(int)) +int _doprnt(register const char* fmt, va_list ap) { register char* s; register int j; @@ -176,7 +174,7 @@ int _doprnt(register const char* fmt, va_list ap, void (*put)(int)) PUTC('\r'); } #endif - put(c); + PUTC(c); nrchars++; continue; } @@ -263,7 +261,7 @@ int _doprnt(register const char* fmt, va_list ap, void (*put)(int)) nrchars++; } #endif - put(c); + PUTC(c); nrchars++; continue; case 'n': @@ -366,32 +364,32 @@ int _doprnt(register const char* fmt, va_list ap, void (*put)(int)) { j--; nrchars++; - put(*s1++); + PUTC(*s1++); } else { j -= 2; nrchars += 2; - put(*s1++); - put(*s1++); + PUTC(*s1++); + PUTC(*s1++); } } do { - put(zfill); + PUTC(zfill); } while (--i); } nrchars += j; while (--j >= 0) { - put(*s1++); + PUTC(*s1++); } if (i > 0) nrchars += i; while (--i >= 0) - put(zfill); + PUTC(zfill); } return nrchars; } diff --git a/lang/cem/libcc.ansi/sys/stdio/loc_incl.h b/lang/cem/libcc.ansi/core/printf/doprnt.h similarity index 57% rename from lang/cem/libcc.ansi/sys/stdio/loc_incl.h rename to lang/cem/libcc.ansi/core/printf/doprnt.h index 4d21923a2..efb056d86 100644 --- a/lang/cem/libcc.ansi/sys/stdio/loc_incl.h +++ b/lang/cem/libcc.ansi/core/printf/doprnt.h @@ -1,29 +1,5 @@ -/* - * loc_incl.h - local include file for stdio library - */ -/* $Id$ */ - -#include -#include - -#define fileno(p) ((p)->_fd) -#define io_testflag(p,x) ((p)->_flags & (x)) - -#include -int _doprnt(const char *format, va_list ap, void (*put)(int c)); -int _doscan(const char *format, va_list ap, int (*get)(void), void (*unget)(int c)); -char *_i_compute(unsigned long val, int base, char *s, int nrdigits); -char *_f_print(va_list *ap, int flags, char *s, char c, int precision); - -extern void __register_stdio_cleanup(void); - -FILE *popen(const char *command, const char *type); -FILE *fdopen(int fd, const char *mode); - -#if ACKCONF_WANT_STDIO_FLOAT -char *_ecvt(long double value, int ndigit, int *decpt, int *sign); -char *_fcvt(long double value, int ndigit, int *decpt, int *sign); -#endif +#ifndef DOPRNT_H +#define DOPRNT_H #define FL_LJUST 0x0001 /* left-justify field */ #define FL_SIGN 0x0002 /* sign in signed conversions */ @@ -38,3 +14,15 @@ char *_fcvt(long double value, int ndigit, int *decpt, int *sign); #define FL_SIGNEDCONV 0x0400 /* may contain a sign */ #define FL_NOASSIGN 0x0800 /* do not assign (in scanf) */ #define FL_NOMORE 0x1000 /* all flags collected */ + +extern int (*_doprnt_put)(int c); + +extern int _doprnt(register const char* fmt, va_list ap); +extern char* _f_print(va_list* ap, int flags, char* s, char c, int precision); + +#if ACKCONF_WANT_STDIO_FLOAT +char *_ecvt(long double value, int ndigit, int *decpt, int *sign); +char *_fcvt(long double value, int ndigit, int *decpt, int *sign); +#endif + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/fltpr.c b/lang/cem/libcc.ansi/core/printf/fltpr.c similarity index 99% rename from lang/cem/libcc.ansi/sys/stdio/fltpr.c rename to lang/cem/libcc.ansi/core/printf/fltpr.c index 3fdc80852..7b9f28a69 100644 --- a/lang/cem/libcc.ansi/sys/stdio/fltpr.c +++ b/lang/cem/libcc.ansi/core/printf/fltpr.c @@ -5,7 +5,7 @@ #include #include -#include "loc_incl.h" +#include "doprnt.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_STDIO_FLOAT diff --git a/lang/cem/libcc.ansi/sys/stdio/fprintf.c b/lang/cem/libcc.ansi/core/printf/fprintf.c similarity index 93% rename from lang/cem/libcc.ansi/sys/stdio/fprintf.c rename to lang/cem/libcc.ansi/core/printf/fprintf.c index 9db8b74ee..3be0ea66b 100644 --- a/lang/cem/libcc.ansi/sys/stdio/fprintf.c +++ b/lang/cem/libcc.ansi/core/printf/fprintf.c @@ -5,7 +5,6 @@ #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO diff --git a/lang/cem/libcc.ansi/sys/stdio/icompute.c b/lang/cem/libcc.ansi/core/printf/icompute.c similarity index 94% rename from lang/cem/libcc.ansi/sys/stdio/icompute.c rename to lang/cem/libcc.ansi/core/printf/icompute.c index 9b48d51a4..7f497d107 100644 --- a/lang/cem/libcc.ansi/sys/stdio/icompute.c +++ b/lang/cem/libcc.ansi/core/printf/icompute.c @@ -3,7 +3,7 @@ */ /* $Id$ */ -#include "loc_incl.h" +#include #if ACKCONF_WANT_STDIO diff --git a/lang/cem/libcc.ansi/sys/stdio/printf.c b/lang/cem/libcc.ansi/core/printf/printf.c similarity index 93% rename from lang/cem/libcc.ansi/sys/stdio/printf.c rename to lang/cem/libcc.ansi/core/printf/printf.c index 2042983e7..7f282456a 100644 --- a/lang/cem/libcc.ansi/sys/stdio/printf.c +++ b/lang/cem/libcc.ansi/core/printf/printf.c @@ -5,7 +5,6 @@ #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO diff --git a/lang/cem/libcc.ansi/core/printf/snprintf.c b/lang/cem/libcc.ansi/core/printf/snprintf.c new file mode 100644 index 000000000..5342785ab --- /dev/null +++ b/lang/cem/libcc.ansi/core/printf/snprintf.c @@ -0,0 +1,23 @@ +/* + * sprintf - print formatted output on an array + */ +/* $Id$ */ + +#include +#include + +#if ACKCONF_WANT_STDIO + +int snprintf(char* s, size_t len, const char* format, ...) +{ + va_list ap; + int retval; + + va_start(ap, format); + retval = vsnprintf(s, len, format, ap); + va_end(ap); + + return retval; +} + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/sprintf.c b/lang/cem/libcc.ansi/core/printf/sprintf.c similarity index 93% rename from lang/cem/libcc.ansi/sys/stdio/sprintf.c rename to lang/cem/libcc.ansi/core/printf/sprintf.c index e57d63ac1..86e81e4a4 100644 --- a/lang/cem/libcc.ansi/sys/stdio/sprintf.c +++ b/lang/cem/libcc.ansi/core/printf/sprintf.c @@ -5,7 +5,6 @@ #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO diff --git a/lang/cem/libcc.ansi/sys/stdio/vfprintf.c b/lang/cem/libcc.ansi/core/printf/vfprintf.c similarity index 66% rename from lang/cem/libcc.ansi/sys/stdio/vfprintf.c rename to lang/cem/libcc.ansi/core/printf/vfprintf.c index 8f7008aae..7e665a22f 100644 --- a/lang/cem/libcc.ansi/sys/stdio/vfprintf.c +++ b/lang/cem/libcc.ansi/core/printf/vfprintf.c @@ -5,21 +5,23 @@ #include #include -#include "loc_incl.h" +#include "doprnt.h" #if ACKCONF_WANT_STDIO static FILE* vfprintf_stream; -static void vfprintf_putc(int c) +static int vfprintf_putc(int c) { putc(c, vfprintf_stream); + return ferror(vfprintf_stream); } int vfprintf(FILE* stream, const char* format, va_list arg) { vfprintf_stream = stream; - return _doprnt(format, arg, vfprintf_putc); + _doprnt_put = vfprintf_putc; + return _doprnt(format, arg); } #endif diff --git a/lang/cem/libcc.ansi/sys/stdio/vprintf.c b/lang/cem/libcc.ansi/core/printf/vprintf.c similarity index 92% rename from lang/cem/libcc.ansi/sys/stdio/vprintf.c rename to lang/cem/libcc.ansi/core/printf/vprintf.c index 192601cc8..999fdaa4d 100644 --- a/lang/cem/libcc.ansi/sys/stdio/vprintf.c +++ b/lang/cem/libcc.ansi/core/printf/vprintf.c @@ -5,7 +5,6 @@ #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO diff --git a/lang/cem/libcc.ansi/sys/stdio/vsnprintf.c b/lang/cem/libcc.ansi/core/printf/vsnprintf.c similarity index 79% rename from lang/cem/libcc.ansi/sys/stdio/vsnprintf.c rename to lang/cem/libcc.ansi/core/printf/vsnprintf.c index 94348d70c..af97b5351 100644 --- a/lang/cem/libcc.ansi/sys/stdio/vsnprintf.c +++ b/lang/cem/libcc.ansi/core/printf/vsnprintf.c @@ -5,20 +5,21 @@ #include #include -#include "loc_incl.h" +#include "doprnt.h" #if ACKCONF_WANT_STDIO static char* output_buffer; static size_t output_buffer_len; -static void snprintf_putc(int c) +static int snprintf_putc(int c) { if (output_buffer_len) { *output_buffer++ = c; output_buffer_len--; } + return 0; } int vsnprintf(char* s, size_t len, const char* format, va_list ap) @@ -27,7 +28,8 @@ int vsnprintf(char* s, size_t len, const char* format, va_list ap) output_buffer = s; output_buffer_len = len; - retval = _doprnt(format, ap, snprintf_putc); + _doprnt_put = snprintf_putc; + retval = _doprnt(format, ap); snprintf_putc('\0'); return retval; diff --git a/lang/cem/libcc.ansi/sys/stdio/vsprintf.c b/lang/cem/libcc.ansi/core/printf/vsprintf.c similarity index 92% rename from lang/cem/libcc.ansi/sys/stdio/vsprintf.c rename to lang/cem/libcc.ansi/core/printf/vsprintf.c index 81147591f..c8da509ab 100644 --- a/lang/cem/libcc.ansi/sys/stdio/vsprintf.c +++ b/lang/cem/libcc.ansi/core/printf/vsprintf.c @@ -5,7 +5,6 @@ #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO diff --git a/lang/cem/libcc.ansi/sys/stdio/doscan.c b/lang/cem/libcc.ansi/core/scanf/doscan.c similarity index 90% rename from lang/cem/libcc.ansi/sys/stdio/doscan.c rename to lang/cem/libcc.ansi/core/scanf/doscan.c index 45748427e..97cf777a2 100644 --- a/lang/cem/libcc.ansi/sys/stdio/doscan.c +++ b/lang/cem/libcc.ansi/core/scanf/doscan.c @@ -7,7 +7,7 @@ #include #include #include -#include "loc_incl.h" +#include "doscan.h" #if ACKCONF_WANT_STDIO @@ -26,14 +26,16 @@ static char Xtable[NR_CHARS]; static char inp_buf[NUMLEN]; +int (*_doscan_get)(void); +void (*_doscan_unget)(int c); + /* Collect a number of characters which constitite an ordinal number. * When the type is 'i', the base can be 8, 10, or 16, depending on the * first 1 or 2 characters. This means that the base must be adjusted * according to the format of the number. At the end of the function, base * is then set to 0, so strtol() will get the right argument. */ -static char* -o_collect(register int c, char type, int width, int* basep, int (*get)(void), void (*unget)(int c)) +static char* o_collect(register int c, char type, int width, int* basep) { register char* bufp = inp_buf; register int base; @@ -62,14 +64,14 @@ o_collect(register int c, char type, int width, int* basep, int (*get)(void), vo { *bufp++ = c; if (--width) - c = get(); + c = _doscan_get(); } if (width && c == '0' && base == 16) { *bufp++ = c; if (--width) - c = get(); + c = _doscan_get(); if (c != 'x' && c != 'X') { if (type == 'i') @@ -79,7 +81,7 @@ o_collect(register int c, char type, int width, int* basep, int (*get)(void), vo { *bufp++ = c; if (--width) - c = get(); + c = _doscan_get(); } } else if (type == 'i') @@ -94,14 +96,14 @@ o_collect(register int c, char type, int width, int* basep, int (*get)(void), vo { *bufp++ = c; if (--width) - c = get(); + c = _doscan_get(); } else break; } if (width && c != EOF) - unget(c); + _doscan_unget(c); if (type == 'i') base = 0; *basep = base; @@ -118,8 +120,7 @@ o_collect(register int c, char type, int width, int* basep, int (*get)(void), vo * not necessary, although the use of the width field can cause incomplete * numbers to be passed to strtod(). (e.g. 1.3e+) */ -static char* -f_collect(register int c, register int width, int (*get)(void), void (*unget)(int c)) +static char* f_collect(register int c, register int width) { register char* bufp = inp_buf; int digit_seen = 0; @@ -128,7 +129,7 @@ f_collect(register int c, register int width, int (*get)(void), void (*unget)(in { *bufp++ = c; if (--width) - c = get(); + c = _doscan_get(); } while (width && isdigit(c)) @@ -136,26 +137,26 @@ f_collect(register int c, register int width, int (*get)(void), void (*unget)(in digit_seen++; *bufp++ = c; if (--width) - c = get(); + c = _doscan_get(); } if (width && c == '.') { *bufp++ = c; if (--width) - c = get(); + c = _doscan_get(); while (width && isdigit(c)) { digit_seen++; *bufp++ = c; if (--width) - c = get(); + c = _doscan_get(); } } if (!digit_seen) { if (width && c != EOF) - unget(c); + _doscan_unget(c); return inp_buf - 1; } else @@ -165,30 +166,30 @@ f_collect(register int c, register int width, int (*get)(void), void (*unget)(in { *bufp++ = c; if (--width) - c = get(); + c = _doscan_get(); if (width && (c == '+' || c == '-')) { *bufp++ = c; if (--width) - c = get(); + c = _doscan_get(); } while (width && isdigit(c)) { digit_seen++; *bufp++ = c; if (--width) - c = get(); + c = _doscan_get(); } if (!digit_seen) { if (width && c != EOF) - unget(c); + _doscan_unget(c); return inp_buf - 1; } } if (width && c != EOF) - unget(c); + _doscan_unget(c); *bufp = '\0'; return bufp - 1; } @@ -198,7 +199,7 @@ f_collect(register int c, register int width, int (*get)(void), void (*unget)(in * the routine that does the scanning */ -int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int c)) +int _doscan(const char* format, va_list ap) { int done = 0; /* number of items done */ int nrchars = 0; /* number of characters read */ @@ -225,15 +226,15 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int { while (isspace(*format)) format++; /* skip whitespace */ - ic = get(); + ic = _doscan_get(); nrchars++; while (isspace(ic)) { - ic = get(); + ic = _doscan_get(); nrchars++; } if (ic != EOF) - unget(ic); + _doscan_unget(ic); nrchars--; } if (!*format) @@ -241,12 +242,12 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int if (*format != '%') { - ic = get(); + ic = _doscan_get(); nrchars++; if (ic != *format++) { if (ic != EOF) - unget(ic); + _doscan_unget(ic); nrchars--; break; /* error */ } @@ -255,7 +256,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int format++; if (*format == '%') { - ic = get(); + ic = _doscan_get(); nrchars++; if (ic == '%') { @@ -298,7 +299,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int { do { - ic = get(); + ic = _doscan_get(); nrchars++; } while (isspace(ic)); if (ic == EOF) @@ -306,7 +307,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int } else if (kind != 'n') { /* %c or %[ */ - ic = get(); + ic = _doscan_get(); if (ic == EOF) break; /* outer while */ nrchars++; @@ -343,7 +344,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int if (!width) return done; - str = o_collect(ic, kind, width, &base, get, unget); + str = o_collect(ic, kind, width, &base); if (str < inp_buf || (str == inp_buf && (*str == '-' @@ -384,7 +385,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int *str++ = (char)ic; if (--width) { - ic = get(); + ic = _doscan_get(); nrchars++; } } @@ -392,7 +393,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int if (width) { if (ic != EOF) - unget(ic); + _doscan_unget(ic); nrchars--; } break; @@ -410,7 +411,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int *str++ = (char)ic; if (--width) { - ic = get(); + ic = _doscan_get(); nrchars++; } } @@ -420,7 +421,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int if (width) { if (ic != EOF) - unget(ic); + _doscan_unget(ic); nrchars--; } break; @@ -467,7 +468,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int if (!*format || !(Xtable[ic] ^ reverse)) { if (ic != EOF) - unget(ic); + _doscan_unget(ic); return done; } @@ -480,7 +481,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int *str++ = (char)ic; if (--width) { - ic = get(); + ic = _doscan_get(); nrchars++; } } while (width && ic != EOF && (Xtable[ic] ^ reverse)); @@ -488,7 +489,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int if (width) { if (ic != EOF) - unget(ic); + _doscan_unget(ic); nrchars--; } if (!(flags & FL_NOASSIGN)) @@ -507,7 +508,7 @@ int _doscan(const char* format, va_list ap, int (*get)(void), void (*unget)(int if (!width) return done; - str = f_collect(ic, width, get, unget); + str = f_collect(ic, width); if (str < inp_buf || (str == inp_buf diff --git a/lang/cem/libcc.ansi/core/scanf/doscan.h b/lang/cem/libcc.ansi/core/scanf/doscan.h new file mode 100644 index 000000000..2502ea8e8 --- /dev/null +++ b/lang/cem/libcc.ansi/core/scanf/doscan.h @@ -0,0 +1,23 @@ +#ifndef DOSCAN_H +#define DOSCAN_H + +#define FL_LJUST 0x0001 /* left-justify field */ +#define FL_SIGN 0x0002 /* sign in signed conversions */ +#define FL_SPACE 0x0004 /* space in signed conversions */ +#define FL_ALT 0x0008 /* alternate form */ +#define FL_ZEROFILL 0x0010 /* fill with zero's */ +#define FL_SHORT 0x0020 /* optional h */ +#define FL_LONG 0x0040 /* optional l */ +#define FL_LONGDOUBLE 0x0080 /* optional L */ +#define FL_WIDTHSPEC 0x0100 /* field width is specified */ +#define FL_PRECSPEC 0x0200 /* precision is specified */ +#define FL_SIGNEDCONV 0x0400 /* may contain a sign */ +#define FL_NOASSIGN 0x0800 /* do not assign (in scanf) */ +#define FL_NOMORE 0x1000 /* all flags collected */ + +extern int (*_doscan_get)(void); +extern void (*_doscan_unget)(int c); + +extern int _doscan(const char* format, va_list ap); + +#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/fscanf.c b/lang/cem/libcc.ansi/core/scanf/fscanf.c similarity index 93% rename from lang/cem/libcc.ansi/sys/stdio/fscanf.c rename to lang/cem/libcc.ansi/core/scanf/fscanf.c index 8c006c85c..21fd6c8ee 100644 --- a/lang/cem/libcc.ansi/sys/stdio/fscanf.c +++ b/lang/cem/libcc.ansi/core/scanf/fscanf.c @@ -5,7 +5,6 @@ #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO diff --git a/lang/cem/libcc.ansi/sys/stdio/scanf.c b/lang/cem/libcc.ansi/core/scanf/scanf.c similarity index 93% rename from lang/cem/libcc.ansi/sys/stdio/scanf.c rename to lang/cem/libcc.ansi/core/scanf/scanf.c index 3fb9875fc..6796013cf 100644 --- a/lang/cem/libcc.ansi/sys/stdio/scanf.c +++ b/lang/cem/libcc.ansi/core/scanf/scanf.c @@ -5,7 +5,6 @@ #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO diff --git a/lang/cem/libcc.ansi/sys/stdio/sscanf.c b/lang/cem/libcc.ansi/core/scanf/sscanf.c similarity index 83% rename from lang/cem/libcc.ansi/sys/stdio/sscanf.c rename to lang/cem/libcc.ansi/core/scanf/sscanf.c index 76e96aa7b..eb972eeb2 100644 --- a/lang/cem/libcc.ansi/sys/stdio/sscanf.c +++ b/lang/cem/libcc.ansi/core/scanf/sscanf.c @@ -6,7 +6,7 @@ #include #include #include -#include "loc_incl.h" +#include "doscan.h" #if ACKCONF_WANT_STDIO @@ -35,7 +35,9 @@ int sscanf(const char* s, const char* format, ...) va_start(ap, format); input_buffer = s; - retval = _doscan(format, ap, sscanf_getc, sscanf_ungetc); + _doscan_get = sscanf_getc; + _doscan_unget = sscanf_ungetc; + retval = _doscan(format, ap); va_end(ap); diff --git a/lang/cem/libcc.ansi/sys/stdio/vfscanf.c b/lang/cem/libcc.ansi/core/scanf/vfscanf.c similarity index 77% rename from lang/cem/libcc.ansi/sys/stdio/vfscanf.c rename to lang/cem/libcc.ansi/core/scanf/vfscanf.c index 9411b65c6..c5a562049 100644 --- a/lang/cem/libcc.ansi/sys/stdio/vfscanf.c +++ b/lang/cem/libcc.ansi/core/scanf/vfscanf.c @@ -5,7 +5,7 @@ #include #include -#include "loc_incl.h" +#include "doscan.h" #if ACKCONF_WANT_STDIO @@ -24,7 +24,9 @@ static void vfscanf_ungetc(int c) int vfscanf(FILE* stream, const char* format, va_list ap) { vfscanf_stream = stream; - return _doscan(format, ap, vfscanf_getc, vfscanf_ungetc); + _doscan_get = vfscanf_getc; + _doscan_unget = vfscanf_ungetc; + return _doscan(format, ap); } #endif diff --git a/lang/cem/libcc.ansi/headers/ack/emufile.h b/lang/cem/libcc.ansi/headers/ack/emufile.h index 6e799b47b..3eeae2eae 100644 --- a/lang/cem/libcc.ansi/headers/ack/emufile.h +++ b/lang/cem/libcc.ansi/headers/ack/emufile.h @@ -56,4 +56,7 @@ extern int fileno(FILE *_stream); extern FILE* fdopen(int fildes, const char *type); #define fileno(stream) ((stream)->_fd) +#define io_testflag(p,x) ((p)->_flags & (x)) +extern void __register_stdio_cleanup(void); + #endif diff --git a/lang/cem/libcc.ansi/headers/stdio.h b/lang/cem/libcc.ansi/headers/stdio.h index 7988c397d..093258fe6 100644 --- a/lang/cem/libcc.ansi/headers/stdio.h +++ b/lang/cem/libcc.ansi/headers/stdio.h @@ -76,6 +76,9 @@ extern int feof(FILE *_stream); extern int ferror(FILE *_stream); extern void perror(const char *_s); +/* Internal function used by several places which is approximately itoa(). */ +extern char *_i_compute(unsigned long val, int base, char *s, int nrdigits); + #if ACKCONF_WANT_EMULATED_FILE #include #else diff --git a/lang/cem/libcc.ansi/sys/stdio/fclose.c b/lang/cem/libcc.ansi/sys/stdio/fclose.c index 2410220be..a805a6e84 100644 --- a/lang/cem/libcc.ansi/sys/stdio/fclose.c +++ b/lang/cem/libcc.ansi/sys/stdio/fclose.c @@ -6,7 +6,6 @@ #include #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE diff --git a/lang/cem/libcc.ansi/sys/stdio/fdopen.c b/lang/cem/libcc.ansi/sys/stdio/fdopen.c index 20fabd5fb..aff7d248e 100644 --- a/lang/cem/libcc.ansi/sys/stdio/fdopen.c +++ b/lang/cem/libcc.ansi/sys/stdio/fdopen.c @@ -5,7 +5,6 @@ #include #include -#include "../stdio/loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE diff --git a/lang/cem/libcc.ansi/sys/stdio/fflush.c b/lang/cem/libcc.ansi/sys/stdio/fflush.c index f38be1bd1..7746ef0fb 100644 --- a/lang/cem/libcc.ansi/sys/stdio/fflush.c +++ b/lang/cem/libcc.ansi/sys/stdio/fflush.c @@ -6,7 +6,6 @@ #include #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE diff --git a/lang/cem/libcc.ansi/sys/stdio/fillbuf.c b/lang/cem/libcc.ansi/sys/stdio/fillbuf.c index 019d138fc..09cc5cfc6 100644 --- a/lang/cem/libcc.ansi/sys/stdio/fillbuf.c +++ b/lang/cem/libcc.ansi/sys/stdio/fillbuf.c @@ -6,7 +6,6 @@ #include #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE diff --git a/lang/cem/libcc.ansi/sys/stdio/flushbuf.c b/lang/cem/libcc.ansi/sys/stdio/flushbuf.c index aba0a7c4c..0cf271704 100644 --- a/lang/cem/libcc.ansi/sys/stdio/flushbuf.c +++ b/lang/cem/libcc.ansi/sys/stdio/flushbuf.c @@ -6,7 +6,6 @@ #include #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE diff --git a/lang/cem/libcc.ansi/sys/stdio/fopen.c b/lang/cem/libcc.ansi/sys/stdio/fopen.c index 24e1537b9..f2189ee8f 100644 --- a/lang/cem/libcc.ansi/sys/stdio/fopen.c +++ b/lang/cem/libcc.ansi/sys/stdio/fopen.c @@ -8,7 +8,6 @@ #include #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE diff --git a/lang/cem/libcc.ansi/sys/stdio/freopen.c b/lang/cem/libcc.ansi/sys/stdio/freopen.c index d4bb4abf8..846208420 100644 --- a/lang/cem/libcc.ansi/sys/stdio/freopen.c +++ b/lang/cem/libcc.ansi/sys/stdio/freopen.c @@ -7,7 +7,6 @@ #include #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE diff --git a/lang/cem/libcc.ansi/sys/stdio/fseek.c b/lang/cem/libcc.ansi/sys/stdio/fseek.c index 5b87a9b30..4ab5c10e3 100644 --- a/lang/cem/libcc.ansi/sys/stdio/fseek.c +++ b/lang/cem/libcc.ansi/sys/stdio/fseek.c @@ -6,7 +6,6 @@ #include #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE diff --git a/lang/cem/libcc.ansi/sys/stdio/ftell.c b/lang/cem/libcc.ansi/sys/stdio/ftell.c index 4728b201b..d69202bd3 100644 --- a/lang/cem/libcc.ansi/sys/stdio/ftell.c +++ b/lang/cem/libcc.ansi/sys/stdio/ftell.c @@ -6,7 +6,6 @@ #include #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE diff --git a/lang/cem/libcc.ansi/sys/stdio/setbuf.c b/lang/cem/libcc.ansi/sys/stdio/setbuf.c index 866b2516d..58a99ecad 100644 --- a/lang/cem/libcc.ansi/sys/stdio/setbuf.c +++ b/lang/cem/libcc.ansi/sys/stdio/setbuf.c @@ -4,7 +4,6 @@ /* $Id$ */ #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE diff --git a/lang/cem/libcc.ansi/sys/stdio/setvbuf.c b/lang/cem/libcc.ansi/sys/stdio/setvbuf.c index af203ef51..439d12dd4 100644 --- a/lang/cem/libcc.ansi/sys/stdio/setvbuf.c +++ b/lang/cem/libcc.ansi/sys/stdio/setvbuf.c @@ -5,7 +5,6 @@ #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE diff --git a/lang/cem/libcc.ansi/sys/stdio/snprintf.c b/lang/cem/libcc.ansi/sys/stdio/snprintf.c deleted file mode 100644 index 99128e3d7..000000000 --- a/lang/cem/libcc.ansi/sys/stdio/snprintf.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * sprintf - print formatted output on an array - */ -/* $Id$ */ - -#include -#include -#include "loc_incl.h" - -#if ACKCONF_WANT_STDIO - -static char* output_buffer; -static size_t output_buffer_len; - -static void snprintf_putc(int c) -{ - if (output_buffer_len) - { - *output_buffer++ = c; - output_buffer_len--; - } -} - -int snprintf(char* s, size_t len, const char* format, ...) -{ - va_list ap; - int retval; - - va_start(ap, format); - - output_buffer = s; - output_buffer_len = len; - retval = _doprnt(format, ap, snprintf_putc); - snprintf_putc('\0'); - - va_end(ap); - - return retval; -} - -#endif diff --git a/lang/cem/libcc.ansi/sys/stdio/tmpfile.c b/lang/cem/libcc.ansi/sys/stdio/tmpfile.c index 384007aaa..d6aa31825 100644 --- a/lang/cem/libcc.ansi/sys/stdio/tmpfile.c +++ b/lang/cem/libcc.ansi/sys/stdio/tmpfile.c @@ -7,7 +7,6 @@ #include #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO diff --git a/lang/cem/libcc.ansi/sys/stdio/tmpnam.c b/lang/cem/libcc.ansi/sys/stdio/tmpnam.c index e67276545..2f40ce716 100644 --- a/lang/cem/libcc.ansi/sys/stdio/tmpnam.c +++ b/lang/cem/libcc.ansi/sys/stdio/tmpnam.c @@ -7,7 +7,6 @@ #include #include #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO diff --git a/lang/cem/libcc.ansi/sys/stdio/ungetc.c b/lang/cem/libcc.ansi/sys/stdio/ungetc.c index 6097e5104..f00447e27 100644 --- a/lang/cem/libcc.ansi/sys/stdio/ungetc.c +++ b/lang/cem/libcc.ansi/sys/stdio/ungetc.c @@ -4,7 +4,6 @@ /* $Id$ */ #include -#include "loc_incl.h" #if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE