Changelog: dlls/msvcrt/file.c: MSVCRT_lseekfgetws fgetws defaults to multibyte strings -- Uwe Bonnes bon@elektron.ikp.physik.tu-darmstadt.de Free Software: If you contribute nothing, expect nothing -- Index: wine/dlls/msvcrt/file.c =================================================================== RCS file: /home/wine/wine/dlls/msvcrt/file.c,v retrieving revision 1.28 diff -u -r1.28 file.c @@ -1562,17 +1564,37 @@ return _fgetwchar(); } +/******************************************************************** + * fgetmbc (internal) + * + * Read a multibyte character from a file + * + */ + +static BOOL MSVCRT_fgetmbc (char *mbc, MSVCRT_FILE* file) +{ + CHAR * s=mbc; + for (*s = MSVCRT_fgetc(file); (*s != MSVCRT_EOF) && !MSVCRT_isleadbyte(*s); + s++); + return (*(s-1) != MSVCRT_EOF); +} /********************************************************************* * fgetws (MSVCRT.@) */ WCHAR *MSVCRT_fgetws(WCHAR *s, int size, MSVCRT_FILE* file) { int cc; + char mbchar[8]; + BOOL instrg; WCHAR * buf_start = s; TRACE(":file(%p) fd (%d) str (%p) len (%d)\n", - file,file->_file,s,size); - + file,file->_file,s, size); +#if 0 + /* Only files opened in binary mode have wide character. + All others are multibyte characters + Multibyte characters should be the normal case for now + */ for(cc = MSVCRT_fgetwc(file); cc != MSVCRT_WEOF && cc != L'\n'; cc = MSVCRT_fgetwc(file)) if (cc != L'\r') @@ -1589,7 +1611,26 @@ if (--size > 0) *s++ = '\n'; *s = '\0'; -/* TRACE(":got '%s'\n", buf_start); */ +#endif + for(instrg=MSVCRT_fgetmbc(mbchar, file); instrg && *mbchar != '\n'; + instrg=MSVCRT_fgetmbc(mbchar, file)) + if (*mbchar != '\r') + { + if (--size <= 0) break; + MSVCRT_mbtowc(s,mbchar, 8); + s++; + } + if ((!instrg) && (s == buf_start)) /* If nothing read, return 0*/ + { + TRACE(":nothing read\n"); + return 0; + } + if (*mbchar == '\n') + if (--size > 0) + *s++ = '\n'; + *s = '\0'; + + TRACE(":got '%s'\n", debugstr_w(buf_start)); return buf_start; } @@ -2252,6 +2300,8 @@ MSVCRT_wint_t cc; WCHAR* ws = buf; + /* FIXME bon 020707: Probably we should read the input as + Multibyte charaters */ for (cc = MSVCRT_fgetwc(MSVCRT_stdin); cc != MSVCRT_WEOF && cc != '\n'; cc = MSVCRT_fgetwc(MSVCRT_stdin)) {