diff options
author | Ulrich Drepper <drepper@redhat.com> | 2001-08-09 19:10:37 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2001-08-09 19:10:37 +0000 |
commit | cc7f258f32352916d508a6f034f51f14abfc7efe (patch) | |
tree | 334b195b585e4d24e70a4731da630552a8c8e198 | |
parent | 3926e63db245e06807988a1fe4129dde072d1154 (diff) | |
download | glibc-cc7f258f32352916d508a6f034f51f14abfc7efe.zip glibc-cc7f258f32352916d508a6f034f51f14abfc7efe.tar.gz glibc-cc7f258f32352916d508a6f034f51f14abfc7efe.tar.bz2 |
Update.
2001-08-09 Ulrich Drepper <drepper@redhat.com>
* stdio-common/vfscanf.c: Fix handling of %[] for COMPILE_WSCANF.
* libio/Makefile (tests): Add tst-swscanf.
* libio/tst-swscanf.c: New file.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | libio/Makefile | 3 | ||||
-rw-r--r-- | libio/tst-swscanf.c | 100 | ||||
-rw-r--r-- | stdio-common/vfscanf.c | 50 |
4 files changed, 141 insertions, 18 deletions
@@ -1,3 +1,9 @@ +2001-08-09 Ulrich Drepper <drepper@redhat.com> + + * stdio-common/vfscanf.c: Fix handling of %[] for COMPILE_WSCANF. + * libio/Makefile (tests): Add tst-swscanf. + * libio/tst-swscanf.c: New file. + 2001-08-09 Jakub Jelinek <jakub@redhat.com> * posix/globtest.sh: Robustify tilde tests. diff --git a/libio/Makefile b/libio/Makefile index 14eaefc..ced5c93 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -48,7 +48,7 @@ routines := \ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \ tst_wprintf2 tst-widetext test-fmemopen tst-ext tst-fopenloc \ - tst-fgetws tst-ungetwc1 tst-ungetwc2 + tst-fgetws tst-ungetwc1 tst-ungetwc2 tst-swscanf test-srcs = test-freopen all: # Make this the default target; it will be defined in Rules. @@ -86,6 +86,7 @@ tst-fopenloc-ENV = LOCPATH=$(common-objpfx)localedata \ tst-fgetws-ENV = LOCPATH=$(common-objpfx)localedata tst-ungetwc1-ENV = LOCPATH=$(common-objpfx)localedata tst-ungetwc2-ENV = LOCPATH=$(common-objpfx)localedata +tst-swscanf-ENV = LOCPATH=$(common-objpfx)localedata generated = tst-fopenloc.mtrace tst-fopenloc.check diff --git a/libio/tst-swscanf.c b/libio/tst-swscanf.c new file mode 100644 index 0000000..86472de --- /dev/null +++ b/libio/tst-swscanf.c @@ -0,0 +1,100 @@ +#include <locale.h> +#include <stdio.h> +#include <string.h> +#include <wchar.h> + + +static int do_test (const char *loc); + + +int +main (void) +{ + int result; + + result = do_test ("C"); + result |= do_test ("de_DE.ISO-8859-1"); + result |= do_test ("de_DE.UTF-8"); + result |= do_test ("ja_JP.EUC-JP"); + + return result; +} + + +static const struct +{ + const wchar_t *fmt; + const wchar_t *wfmt; + const wchar_t *arg; + const char *res; + const wchar_t *wres; + int only_C_locale; +} tests[] = + { + { L"%[abc]", L"%l[abc]", L"aabbccddaabb", "aabbcc", L"aabbcc", 0 }, + { L"%[^def]", L"%l[^def]", L"aabbccddaabb", "aabbcc", L"aabbcc", 0 }, + { L"%[^abc]", L"%l[^abc]", L"aabbccddaabb", "", L"", 0 }, + { L"%[a-c]", L"%l[a-c]", L"aabbccddaabb", "aabbcc", L"aabbcc", 1 }, + { L"%[^d-f]", L"%l[^d-f]", L"aabbccddaabb", "aabbcc", L"aabbcc", 1 }, + { L"%[^a-c]", L"%l[^a-c]", L"aabbccddaabb", "", L"", 1 }, + { L"%[^a-c]", L"%l[^a-c]", L"bbccddaabb", "", L"", 1 } + }; + + +static int +do_test (const char *loc) +{ + size_t n; + int result = 0; + + if (setlocale (LC_ALL, loc) == NULL) + { + printf ("cannot set locale \"%s\": %m\n", loc); + return 1; + } + + printf ("\nnew locale: \"%s\"\n", loc); + + for (n = 0; n < sizeof (tests) / sizeof (tests[0]); ++n) + { + char buf[100]; + wchar_t wbuf[100]; + + if (tests[n].only_C_locale && strcmp (loc, "C") != 0) + continue; + + if (swscanf (tests[n].arg, tests[n].fmt, buf) != 1) + { + printf ("swscanf (\"%S\", \"%S\", ...) failed\n", + tests[n].arg, tests[n].fmt); + result = 1; + } + else if (strcmp (buf, tests[n].res) != 0) + { + printf ("swscanf (\"%S\", \"%S\", ...) return \"%s\", expected \"%s\"\n", + tests[n].arg, tests[n].fmt, buf, tests[n].res); + result = 1; + } + else + printf ("swscanf (\"%S\", \"%S\", ...) OK\n", + tests[n].arg, tests[n].fmt); + + if (swscanf (tests[n].arg, tests[n].wfmt, wbuf) != 1) + { + printf ("swscanf (\"%S\", \"%S\", ...) failed\n", + tests[n].arg, tests[n].wfmt); + result = 1; + } + else if (wcscmp (wbuf, tests[n].wres) != 0) + { + printf ("swscanf (\"%S\", \"%S\", ...) return \"%S\", expected \"%S\"\n", + tests[n].arg, tests[n].wfmt, wbuf, tests[n].wres); + result = 1; + } + else + printf ("swscanf (\"%S\", \"%S\", ...) OK\n", + tests[n].arg, tests[n].wfmt); + } + + return result; +} diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c index aa0f091..29d96e4 100644 --- a/stdio-common/vfscanf.c +++ b/stdio-common/vfscanf.c @@ -1925,7 +1925,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr) be punished. */ tw = (wchar_t *) f; /* Marks the beginning. */ - if (*f == ']' || *f == '-') + if (*f == L']') ++f; while ((fc = *f++) != L'\0' && fc != L']'); @@ -1985,7 +1985,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr) runp = tw; while (runp < wp) { - if (runp[0] == L'-' && runp[1] != '\0' && runp[1] != ']' + if (runp[0] == L'-' && runp[1] != '\0' && runp + 1 != wp && runp != tw && (unsigned int) runp[-1] <= (unsigned int) runp[1]) { @@ -1993,32 +1993,40 @@ __vfscanf (FILE *s, const char *format, va_list argptr) first and last character of the sequence. */ wchar_t wc; - for (wc = runp[-1] + 1; wc < runp[1]; ++wc) + for (wc = runp[-1] + 1; wc <= runp[1]; ++wc) if (wc == c) break; - if (wc == runp[1] && !not_in) + if (wc <= runp[1] && !not_in) break; - if (wc == runp[1] && not_in) + if (wc <= runp[1] && not_in) { /* The current character is not in the scanset. */ ungetwc (c, s); goto out; } + + runp += 2; } else { - if (*runp == runp[1] && !not_in) + if (*runp == c && !not_in) break; - if (*runp != runp[1] && not_in) + if (*runp == c && not_in) { - ungetwc (c ,s); + ungetwc (c, s); goto out; } + + ++runp; } + } - ++runp; + if (runp == wp && !not_in) + { + ungetwc (c, s); + goto out; } if (!(flags & SUPPRESS)) @@ -2195,7 +2203,7 @@ __vfscanf (FILE *s, const char *format, va_list argptr) runp = tw; while (runp < wp) { - if (runp[0] == L'-' && runp[1] != '\0' && runp[1] != ']' + if (runp[0] == L'-' && runp[1] != '\0' && runp + 1 != wp && runp != tw && (unsigned int) runp[-1] <= (unsigned int) runp[1]) { @@ -2203,32 +2211,40 @@ __vfscanf (FILE *s, const char *format, va_list argptr) first and last character of the sequence. */ wchar_t wc; - for (wc = runp[-1] + 1; wc < runp[1]; ++wc) + for (wc = runp[-1] + 1; wc <= runp[1]; ++wc) if (wc == c) break; - if (wc == runp[1] && !not_in) + if (wc <= runp[1] && !not_in) break; - if (wc == runp[1] && not_in) + if (wc <= runp[1] && not_in) { /* The current character is not in the scanset. */ ungetwc (c, s); goto out2; } + + runp += 2; } else { - if (*runp == runp[1] && !not_in) + if (*runp == c && !not_in) break; - if (*runp != runp[1] && not_in) + if (*runp == c && not_in) { - ungetwc (c ,s); + ungetwc (c, s); goto out2; } + + ++runp; } + } - ++runp; + if (runp == wp && !not_in) + { + ungetwc (c, s); + goto out2; } if (!(flags & SUPPRESS)) |