Jacek Caban : scrrun: Add ITextStream::ReadLine implementation.
Alexandre Julliard
julliard at winehq.org
Thu Nov 7 16:16:04 CST 2019
Module: wine
Branch: master
Commit: 14de44513f343ad0e9590df07a877a6d250964bf
URL: https://source.winehq.org/git/wine.git/?a=commit;h=14de44513f343ad0e9590df07a877a6d250964bf
Author: Jacek Caban <jacek at codeweavers.com>
Date: Thu Nov 7 17:10:32 2019 +0100
scrrun: Add ITextStream::ReadLine implementation.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/scrrun/filesystem.c | 33 ++++++++++++++++++++++++---------
dlls/scrrun/tests/filesystem.c | 6 ------
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c
index b05a814593..5893435af7 100644
--- a/dlls/scrrun/filesystem.c
+++ b/dlls/scrrun/filesystem.c
@@ -21,6 +21,7 @@
#include <stdarg.h>
#include <limits.h>
#include <assert.h>
+#include <wchar.h>
#include "windef.h"
#include "winbase.h"
@@ -499,10 +500,11 @@ static HRESULT WINAPI textstream_Read(ITextStream *iface, LONG len, BSTR *text)
static HRESULT WINAPI textstream_ReadLine(ITextStream *iface, BSTR *text)
{
struct textstream *This = impl_from_ITextStream(iface);
- VARIANT_BOOL eos;
- HRESULT hr;
+ unsigned int skip = 0;
+ const WCHAR *nl;
+ HRESULT hr = S_OK;
- FIXME("(%p)->(%p): stub\n", This, text);
+ TRACE("(%p)->(%p)\n", This, text);
if (!text)
return E_POINTER;
@@ -511,15 +513,28 @@ static HRESULT WINAPI textstream_ReadLine(ITextStream *iface, BSTR *text)
if (textstream_check_iomode(This, IORead))
return CTL_E_BADFILEMODE;
- /* check for EOF */
- hr = ITextStream_get_AtEndOfStream(iface, &eos);
- if (FAILED(hr))
- return hr;
+ while (!(nl = wmemchr(This->read_buf, '\n', This->read_buf_size)) && !This->eof)
+ {
+ if (FAILED(hr = read_more_data(This)))
+ return hr;
+ }
- if (eos == VARIANT_TRUE)
+ if (This->eof && !This->read_buf_size)
return CTL_E_ENDOFFILE;
- return E_NOTIMPL;
+ if (!nl)
+ {
+ nl = This->read_buf + This->read_buf_size;
+ hr = S_FALSE;
+ }
+ else if (nl > This->read_buf && nl[-1] == '\r')
+ {
+ nl--;
+ skip = 2;
+ }
+ else skip = 1;
+
+ return read_from_buffer(This, nl - This->read_buf, text, skip) ? hr : E_OUTOFMEMORY;
}
static HRESULT WINAPI textstream_ReadAll(ITextStream *iface, BSTR *text)
diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c
index 3b4af3c498..2d5c6e4138 100644
--- a/dlls/scrrun/tests/filesystem.c
+++ b/dlls/scrrun/tests/filesystem.c
@@ -1732,10 +1732,8 @@ static void test_ReadAll(void)
str = NULL;
hr = ITextStream_ReadLine(stream, &str);
-todo_wine {
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(str != NULL, "got %p\n", str);
-}
SysFreeString(str);
lstrcpyW(buffW, secondlineW);
@@ -1743,7 +1741,6 @@ todo_wine {
str = NULL;
hr = ITextStream_ReadAll(stream, &str);
ok(hr == S_FALSE || broken(hr == S_OK) /* win2k */, "got 0x%08x\n", hr);
-todo_wine
ok(!lstrcmpW(buffW, str), "got %s\n", wine_dbgstr_w(str));
SysFreeString(str);
ITextStream_Release(stream);
@@ -1880,10 +1877,8 @@ static void test_Read(void)
str = NULL;
hr = ITextStream_ReadLine(stream, &str);
-todo_wine {
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(str != NULL, "got %p\n", str);
-}
SysFreeString(str);
lstrcpyW(buffW, secondlineW);
@@ -1891,7 +1886,6 @@ todo_wine {
str = NULL;
hr = ITextStream_Read(stream, 100, &str);
ok(hr == S_FALSE || broken(hr == S_OK) /* win2k */, "got 0x%08x\n", hr);
-todo_wine
ok(!lstrcmpW(buffW, str), "got %s\n", wine_dbgstr_w(str));
SysFreeString(str);
ITextStream_Release(stream);
More information about the wine-cvs
mailing list