msvcrt: Add support for locales in scanf helper functions.

This commit is contained in:
Piotr Caban 2010-04-22 13:48:49 +02:00 committed by Alexandre Julliard
parent 93f970ce7b
commit 231fc11457
2 changed files with 22 additions and 19 deletions

View File

@ -57,31 +57,31 @@ static int wchar2digit(MSVCRT_wchar_t c, int base) {
return -1; return -1;
} }
/* vfscanf */ /* vfscanf_l */
#undef WIDE_SCANF #undef WIDE_SCANF
#undef CONSOLE #undef CONSOLE
#undef STRING #undef STRING
#include "scanf.h" #include "scanf.h"
/* vfwscanf */ /* vfwscanf_l */
#define WIDE_SCANF 1 #define WIDE_SCANF 1
#undef CONSOLE #undef CONSOLE
#undef STRING #undef STRING
#include "scanf.h" #include "scanf.h"
/* vsscanf */ /* vsscanf_l */
#undef WIDE_SCANF #undef WIDE_SCANF
#undef CONSOLE #undef CONSOLE
#define STRING 1 #define STRING 1
#include "scanf.h" #include "scanf.h"
/* vswscanf */ /* vswscanf_l */
#define WIDE_SCANF 1 #define WIDE_SCANF 1
#undef CONSOLE #undef CONSOLE
#define STRING 1 #define STRING 1
#include "scanf.h" #include "scanf.h"
/* vcscanf */ /* vcscanf_l */
#undef WIDE_SCANF #undef WIDE_SCANF
#define CONSOLE 1 #define CONSOLE 1
#undef STRING #undef STRING
@ -97,7 +97,7 @@ int CDECL MSVCRT_fscanf(MSVCRT_FILE *file, const char *format, ...)
int res; int res;
__ms_va_start(valist, format); __ms_va_start(valist, format);
res = MSVCRT_vfscanf(file, format, valist); res = MSVCRT_vfscanf_l(file, format, NULL, valist);
__ms_va_end(valist); __ms_va_end(valist);
return res; return res;
} }
@ -111,7 +111,7 @@ int CDECL MSVCRT_scanf(const char *format, ...)
int res; int res;
__ms_va_start(valist, format); __ms_va_start(valist, format);
res = MSVCRT_vfscanf(MSVCRT_stdin, format, valist); res = MSVCRT_vfscanf_l(MSVCRT_stdin, format, NULL, valist);
__ms_va_end(valist); __ms_va_end(valist);
return res; return res;
} }
@ -125,7 +125,7 @@ int CDECL MSVCRT_fwscanf(MSVCRT_FILE *file, const MSVCRT_wchar_t *format, ...)
int res; int res;
__ms_va_start(valist, format); __ms_va_start(valist, format);
res = MSVCRT_vfwscanf(file, format, valist); res = MSVCRT_vfwscanf_l(file, format, NULL, valist);
__ms_va_end(valist); __ms_va_end(valist);
return res; return res;
} }
@ -140,7 +140,7 @@ int CDECL MSVCRT_wscanf(const MSVCRT_wchar_t *format, ...)
int res; int res;
__ms_va_start(valist, format); __ms_va_start(valist, format);
res = MSVCRT_vfwscanf(MSVCRT_stdin, format, valist); res = MSVCRT_vfwscanf_l(MSVCRT_stdin, format, NULL, valist);
__ms_va_end(valist); __ms_va_end(valist);
return res; return res;
} }
@ -155,7 +155,7 @@ int CDECL MSVCRT_sscanf(const char *str, const char *format, ...)
int res; int res;
__ms_va_start(valist, format); __ms_va_start(valist, format);
res = MSVCRT_vsscanf(str, format, valist); res = MSVCRT_vsscanf_l(str, format, NULL, valist);
__ms_va_end(valist); __ms_va_end(valist);
return res; return res;
} }
@ -170,7 +170,7 @@ int CDECL MSVCRT_swscanf(const MSVCRT_wchar_t *str, const MSVCRT_wchar_t *format
int res; int res;
__ms_va_start(valist, format); __ms_va_start(valist, format);
res = MSVCRT_vswscanf(str, format, valist); res = MSVCRT_vswscanf_l(str, format, NULL, valist);
__ms_va_end(valist); __ms_va_end(valist);
return res; return res;
} }
@ -185,7 +185,7 @@ int CDECL _cscanf(const char *format, ...)
int res; int res;
__ms_va_start(valist, format); __ms_va_start(valist, format);
res = MSVCRT_vcscanf(format, valist); res = MSVCRT_vcscanf_l(format, NULL, valist);
__ms_va_end(valist); __ms_va_end(valist);
return res; return res;
} }

View File

@ -48,7 +48,7 @@
#ifdef CONSOLE #ifdef CONSOLE
#define _GETC_(file) (consumed++, _getch()) #define _GETC_(file) (consumed++, _getch())
#define _UNGETC_(nch, file) do { _ungetch(nch); consumed--; } while(0) #define _UNGETC_(nch, file) do { _ungetch(nch); consumed--; } while(0)
#define _FUNCTION_ static int MSVCRT_vcscanf(const char *format, __ms_va_list ap) #define _FUNCTION_ static int MSVCRT_vcscanf_l(const char *format, MSVCRT__locale_t locale, __ms_va_list ap)
#else #else
#ifdef STRING #ifdef STRING
#undef _EOF_ #undef _EOF_
@ -56,19 +56,19 @@
#define _GETC_(file) (consumed++, *file++) #define _GETC_(file) (consumed++, *file++)
#define _UNGETC_(nch, file) do { file--; consumed--; } while(0) #define _UNGETC_(nch, file) do { file--; consumed--; } while(0)
#ifdef WIDE_SCANF #ifdef WIDE_SCANF
#define _FUNCTION_ static int MSVCRT_vswscanf(const MSVCRT_wchar_t *file, const MSVCRT_wchar_t *format, __ms_va_list ap) #define _FUNCTION_ static int MSVCRT_vswscanf_l(const MSVCRT_wchar_t *file, const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list ap)
#else /* WIDE_SCANF */ #else /* WIDE_SCANF */
#define _FUNCTION_ static int MSVCRT_vsscanf(const char *file, const char *format, __ms_va_list ap) #define _FUNCTION_ static int MSVCRT_vsscanf_l(const char *file, const char *format, MSVCRT__locale_t locale, __ms_va_list ap)
#endif /* WIDE_SCANF */ #endif /* WIDE_SCANF */
#else /* STRING */ #else /* STRING */
#ifdef WIDE_SCANF #ifdef WIDE_SCANF
#define _GETC_(file) (consumed++, MSVCRT_fgetwc(file)) #define _GETC_(file) (consumed++, MSVCRT_fgetwc(file))
#define _UNGETC_(nch, file) do { MSVCRT_ungetwc(nch, file); consumed--; } while(0) #define _UNGETC_(nch, file) do { MSVCRT_ungetwc(nch, file); consumed--; } while(0)
#define _FUNCTION_ static int MSVCRT_vfwscanf(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, __ms_va_list ap) #define _FUNCTION_ static int MSVCRT_vfwscanf_l(MSVCRT_FILE* file, const MSVCRT_wchar_t *format, MSVCRT__locale_t locale, __ms_va_list ap)
#else /* WIDE_SCANF */ #else /* WIDE_SCANF */
#define _GETC_(file) (consumed++, MSVCRT_fgetc(file)) #define _GETC_(file) (consumed++, MSVCRT_fgetc(file))
#define _UNGETC_(nch, file) do { MSVCRT_ungetc(nch, file); consumed--; } while(0) #define _UNGETC_(nch, file) do { MSVCRT_ungetc(nch, file); consumed--; } while(0)
#define _FUNCTION_ static int MSVCRT_vfscanf(MSVCRT_FILE* file, const char *format, __ms_va_list ap) #define _FUNCTION_ static int MSVCRT_vfscanf_l(MSVCRT_FILE* file, const char *format, MSVCRT__locale_t locale, __ms_va_list ap)
#endif /* WIDE_SCANF */ #endif /* WIDE_SCANF */
#endif /* STRING */ #endif /* STRING */
#endif /* CONSOLE */ #endif /* CONSOLE */
@ -91,6 +91,9 @@ _FUNCTION_ {
nch = _GETC_(file); nch = _GETC_(file);
if (nch == _EOF_) return _EOF_RET; if (nch == _EOF_) return _EOF_RET;
if(!locale)
locale = get_locale();
while (*format) { while (*format) {
/* a whitespace character in the format string causes scanf to read, /* a whitespace character in the format string causes scanf to read,
* but not store, all consecutive white-space characters in the input * but not store, all consecutive white-space characters in the input
@ -250,7 +253,7 @@ _FUNCTION_ {
nch = _GETC_(file); nch = _GETC_(file);
} }
/* get first digit. */ /* get first digit. */
if ('.' != nch) { if (*locale->locinfo->lconv->decimal_point != nch) {
if (!_ISDIGIT_(nch)) break; if (!_ISDIGIT_(nch)) break;
cur = (nch - '0'); cur = (nch - '0');
nch = _GETC_(file); nch = _GETC_(file);
@ -265,7 +268,7 @@ _FUNCTION_ {
cur = 0; /* MaxPayneDemo Fix: .8 -> 0.8 */ cur = 0; /* MaxPayneDemo Fix: .8 -> 0.8 */
} }
/* handle decimals */ /* handle decimals */
if (width!=0 && nch == '.') { if (width!=0 && nch == *locale->locinfo->lconv->decimal_point) {
long double dec = 1; long double dec = 1;
nch = _GETC_(file); nch = _GETC_(file);
if (width>0) width--; if (width>0) width--;