| OLD | NEW | 
|---|
| 1 #include "shgetc.h" | 1 #include "shgetc.h" | 
| 2 #include "floatscan.h" | 2 #include "floatscan.h" | 
| 3 #include "stdio_impl.h" | 3 #include "stdio_impl.h" | 
| 4 #include <wchar.h> | 4 #include <wchar.h> | 
| 5 #include <wctype.h> | 5 #include <wctype.h> | 
| 6 | 6 | 
| 7 /* This read function heavily cheats. It knows: | 7 /* This read function heavily cheats. It knows: | 
| 8  *  (1) len will always be 1 | 8  *  (1) len will always be 1 | 
| 9  *  (2) non-ascii characters don't matter */ | 9  *  (2) non-ascii characters don't matter */ | 
| 10 | 10 | 
| 11 static size_t do_read(FILE *f, unsigned char *buf, size_t len) | 11 static size_t do_read(FILE* f, unsigned char* buf, size_t len) { | 
| 12 { | 12   size_t i; | 
| 13 »       size_t i; | 13   const wchar_t* wcs = f->cookie; | 
| 14 »       const wchar_t *wcs = f->cookie; |  | 
| 15 | 14 | 
| 16 »       if (!wcs[0]) wcs=L"@"; | 15   if (!wcs[0]) | 
| 17 »       for (i=0; i<f->buf_size && wcs[i]; i++) | 16     wcs = L"@"; | 
| 18 »       »       f->buf[i] = wcs[i] < 128 ? wcs[i] : '@'; | 17   for (i = 0; i < f->buf_size && wcs[i]; i++) | 
| 19 »       f->rpos = f->buf; | 18     f->buf[i] = wcs[i] < 128 ? wcs[i] : '@'; | 
| 20 »       f->rend = f->buf + i; | 19   f->rpos = f->buf; | 
| 21 »       f->cookie = (void *)(wcs+i); | 20   f->rend = f->buf + i; | 
|  | 21   f->cookie = (void*)(wcs + i); | 
| 22 | 22 | 
| 23 »       if (i && len) { | 23   if (i && len) { | 
| 24 »       »       *buf = *f->rpos++; | 24     *buf = *f->rpos++; | 
| 25 »       »       return 1; | 25     return 1; | 
| 26 »       } | 26   } | 
| 27 »       return 0; | 27   return 0; | 
| 28 } | 28 } | 
| 29 | 29 | 
| 30 static long double wcstox(const wchar_t *s, wchar_t **p, int prec) | 30 static long double wcstox(const wchar_t* s, wchar_t** p, int prec) { | 
| 31 { | 31   wchar_t* t = (wchar_t*)s; | 
| 32 »       wchar_t *t = (wchar_t *)s; | 32   unsigned char buf[64]; | 
| 33 »       unsigned char buf[64]; | 33   FILE f = {0}; | 
| 34 »       FILE f = {0}; | 34   f.flags = 0; | 
| 35 »       f.flags = 0; | 35   f.rpos = f.rend = 0; | 
| 36 »       f.rpos = f.rend = 0; | 36   f.buf = buf + 4; | 
| 37 »       f.buf = buf + 4; | 37   f.buf_size = sizeof buf - 4; | 
| 38 »       f.buf_size = sizeof buf - 4; | 38   f.lock = -1; | 
| 39 »       f.lock = -1; | 39   f.read = do_read; | 
| 40 »       f.read = do_read; | 40   while (iswspace(*t)) | 
| 41 »       while (iswspace(*t)) t++; | 41     t++; | 
| 42 »       f.cookie = (void *)t; | 42   f.cookie = (void*)t; | 
| 43 »       shlim(&f, 0); | 43   shlim(&f, 0); | 
| 44 »       long double y = __floatscan(&f, prec, 1); | 44   long double y = __floatscan(&f, prec, 1); | 
| 45 »       if (p) { | 45   if (p) { | 
| 46 »       »       size_t cnt = shcnt(&f); | 46     size_t cnt = shcnt(&f); | 
| 47 »       »       *p = cnt ? t + cnt : (wchar_t *)s; | 47     *p = cnt ? t + cnt : (wchar_t*)s; | 
| 48 »       } | 48   } | 
| 49 »       return y; | 49   return y; | 
| 50 } | 50 } | 
| 51 | 51 | 
| 52 float wcstof(const wchar_t *restrict s, wchar_t **restrict p) | 52 float wcstof(const wchar_t* restrict s, wchar_t** restrict p) { | 
| 53 { | 53   return wcstox(s, p, 0); | 
| 54 »       return wcstox(s, p, 0); |  | 
| 55 } | 54 } | 
| 56 | 55 | 
| 57 double wcstod(const wchar_t *restrict s, wchar_t **restrict p) | 56 double wcstod(const wchar_t* restrict s, wchar_t** restrict p) { | 
| 58 { | 57   return wcstox(s, p, 1); | 
| 59 »       return wcstox(s, p, 1); |  | 
| 60 } | 58 } | 
| 61 | 59 | 
| 62 long double wcstold(const wchar_t *restrict s, wchar_t **restrict p) | 60 long double wcstold(const wchar_t* restrict s, wchar_t** restrict p) { | 
| 63 { | 61   return wcstox(s, p, 2); | 
| 64 »       return wcstox(s, p, 2); |  | 
| 65 } | 62 } | 
| OLD | NEW | 
|---|