From: Hans Leidekker hans@codeweavers.com
--- programs/findstr/main.c | 28 ++++++++++++++++++++++++++-- programs/findstr/tests/findstr.c | 7 +++++++ 2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/programs/findstr/main.c b/programs/findstr/main.c index 3a6a250f514..f8f2de594c5 100644 --- a/programs/findstr/main.c +++ b/programs/findstr/main.c @@ -97,12 +97,32 @@ static void add_string(struct findstr_string **head, const WCHAR *string) *ptr = new_string; }
+static const WCHAR *substring(const WCHAR *str, const WCHAR *substr, BOOL case_sensitive) +{ + if (case_sensitive) return wcsstr(str, substr); + + while (*str) + { + const WCHAR *p1 = str, *p2 = substr; + + while (*p1 && *p2 && towlower(*p1) == towlower(*p2)) + { + p1++; + p2++; + } + if (!*p2) return str; + str++; + } + + return NULL; +} + int __cdecl wmain(int argc, WCHAR *argv[]) { struct findstr_string *string_head = NULL, *current_string, *next_string; struct findstr_file *file_head = NULL, *current_file, *next_file; WCHAR *string, *ptr, *buffer, line[MAXSTRING]; - BOOL has_string = FALSE, has_file = FALSE; + BOOL has_string = FALSE, has_file = FALSE, case_sensitive = TRUE; int ret = 1, i, j;
for (i = 0; i < argc; i++) @@ -151,6 +171,10 @@ int __cdecl wmain(int argc, WCHAR *argv[]) has_string = TRUE; } break; + case 'I': + case 'i': + case_sensitive = FALSE; + break; default: findstr_error_wprintf(STRING_IGNORED, argv[i][j]); break; @@ -196,7 +220,7 @@ int __cdecl wmain(int argc, WCHAR *argv[]) current_string = string_head; while (current_string) { - if (wcsstr(line, current_string->string)) + if (substring(line, current_string->string, case_sensitive)) { wprintf(line); if (current_file->file == stdin) diff --git a/programs/findstr/tests/findstr.c b/programs/findstr/tests/findstr.c index 1f565210e79..3ededf7551b 100644 --- a/programs/findstr/tests/findstr.c +++ b/programs/findstr/tests/findstr.c @@ -194,6 +194,13 @@ static void test_basic(void) run_find_stdin("/C:abc", "cba", 1); ok(stdout_size == 0, "Unexpected stdout buffer size %ld.\n", stdout_size); ok(stderr_size == 0, "Unexpected stderr buffer size %ld.\n", stderr_size); + + /* find string in file, case insensitive */ + run_find_file("/I aBc", "abc", 0); + ok(stdout_size > 0, "Unexpected stdout buffer size %ld.\n", stdout_size); + ok(stderr_size == 0, "Unexpected stderr buffer size %ld.\n", stderr_size); + ret = strcmp(stdout_buffer, "abc"); + ok(!ret, "Got the wrong result.\n"); }
START_TEST(findstr)
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=148690
Your paranoid android.
=== debian11b (64 bit WoW report) ===
d3d9: d3d9ex.c:3230: Test failed: Expected message 0x18 for window 0, but didn't receive it, i=0. d3d9ex.c:3236: Test failed: Got unexpected WINDOWPOS hwnd=0000000000000000, x=0, y=0, cx=0, cy=0, flags=0
kernel32: comm.c:1574: Test failed: AbortWaitCts hComPortEvent failed comm.c:1586: Test failed: Unexpected time 1001, expected around 500
user32: input.c:4305: Test succeeded inside todo block: button_down_hwnd_todo 1: got MSG_TEST_WIN hwnd 0000000000CC00EA, msg WM_LBUTTONDOWN, wparam 0x1, lparam 0x320032