mescc: Implement fflush, sscanf, vsscanf.
* lib/libc+tcc.c (vsscanf): New function. (sscanf): Use it. (fflush): Remove stub notice; we have no buffering. * include/stdarg.h: Declare it. * scaffold/tests/87-sscanf.c: Test it. * build-aux/check-mescc.sh (tests): Run it.
This commit is contained in:
parent
272b522962
commit
a3a3654d54
|
@ -133,6 +133,7 @@ t
|
||||||
84-struct-field-list
|
84-struct-field-list
|
||||||
85-sizeof
|
85-sizeof
|
||||||
86-strncpy
|
86-strncpy
|
||||||
|
87-sscanf
|
||||||
"
|
"
|
||||||
|
|
||||||
broken="$broken
|
broken="$broken
|
||||||
|
|
|
@ -46,6 +46,7 @@ typedef int va_list;
|
||||||
int vprintf (char const* format, va_list ap);
|
int vprintf (char const* format, va_list ap);
|
||||||
int vsprintf (char *str, char const *format, va_list ap);
|
int vsprintf (char *str, char const *format, va_list ap);
|
||||||
int vsnprintf (char *str, size_t size, char const *format, va_list ap);
|
int vsnprintf (char *str, size_t size, char const *format, va_list ap);
|
||||||
|
int vsscanf (char const *s, char const *template, va_list ap);
|
||||||
|
|
||||||
#endif // ! (__GNUC__ && POSIX)
|
#endif // ! (__GNUC__ && POSIX)
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,6 @@ ferror (FILE *stream)
|
||||||
int
|
int
|
||||||
fflush (FILE *stream)
|
fflush (FILE *stream)
|
||||||
{
|
{
|
||||||
eputs ("fflush stub\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,9 +253,13 @@ snprintf(char *str, size_t size, char const *format, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
sscanf (char const *str, const char *format, ...)
|
sscanf (char const *str, const char *template, ...)
|
||||||
{
|
{
|
||||||
eputs ("sscanf stub\n");
|
va_list ap;
|
||||||
|
va_start (ap, template);
|
||||||
|
int r = vsscanf (str, template, ap);
|
||||||
|
va_end (ap);
|
||||||
|
return r;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,3 +452,38 @@ vfprintf (FILE* f, char const* format, va_list ap)
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
vsscanf (char const *s, char const *template, va_list ap)
|
||||||
|
{
|
||||||
|
char const *p = s;
|
||||||
|
char const *t = template;
|
||||||
|
while (*t && *p)
|
||||||
|
if (*t != '%')
|
||||||
|
{
|
||||||
|
t++;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t++;
|
||||||
|
char c = *t;
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '%': {p++; break;}
|
||||||
|
case 'c': {char *c = va_arg (ap, char*); *c = *p++; break;}
|
||||||
|
case 'd': {int *d = va_arg (ap, int*); *d = abtoi (&p, 10); break;}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
eputs ("vsscanf: not supported: %");
|
||||||
|
eputc (c);
|
||||||
|
eputs ("\n");
|
||||||
|
t++;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t++;
|
||||||
|
}
|
||||||
|
va_end (ap);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
42
scaffold/tests/87-sscanf.c
Normal file
42
scaffold/tests/87-sscanf.c
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* Mes is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Mes is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "30-test.i"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
test ()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int r = sscanf ("42", "%d", &i);
|
||||||
|
if (r)
|
||||||
|
return 1;
|
||||||
|
if (i != 42)
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
char c;
|
||||||
|
r = sscanf ("foo bar", "foo%cbar", &c);
|
||||||
|
if (r)
|
||||||
|
return 3;
|
||||||
|
if (c != ' ')
|
||||||
|
return 4;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue