From: Isira Seneviratne Subject: [PATCH] find: Implement non-flag functionality. Message-Id: Date: Wed, 6 Feb 2019 13:46:53 +0530

From ef4896d44899d52a4456c5b019759e5e74bb0d09 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Wed, 6 Feb 2019 13:43:54 +0530 Subject: [PATCH] find: Implement non-flag functionality. Signed-off-by: Isira Seneviratne --- programs/find/Makefile.in | 1 + programs/find/find.c | 96 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 5 deletions(-) diff --git a/programs/find/Makefile.in b/programs/find/Makefile.in index ef8d61b7ce..4039b30364 100644 --- a/programs/find/Makefile.in +++ b/programs/find/Makefile.in @@ -1,4 +1,5 @@ MODULE = find.exe APPMODE = -mconsole -municode +IMPORTS = shlwapi C_SRCS = find.c diff --git a/programs/find/find.c b/programs/find/find.c index 9d7aecd402..928c58ca95 100644 --- a/programs/find/find.c +++ b/programs/find/find.c @@ -1,5 +1,6 @@ /* * Copyright 2018 Fabian Maurer + * Copyright 2019 Isira Seneviratne * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,16 +19,101 @@ #include "wine/debug.h" +#include +#include +#include +#include +#include + WINE_DEFAULT_DEBUG_CHANNEL(find); +/* FIXME: + * + * -- find in Windows does not accept strings that are not enclosed in double quotes. + * -- using an infinite loop to read input in the read_input() method below causes a crash. + */ + +typedef enum { + FIND_NO_FLAGS = 0, + FIND_V = 1, + FIND_C = 2, + FIND_N = 4, + FIND_I = 8, +} FIND_TYPE; + +void read_input(WCHAR *str) +{ + WCHAR buf_w[256]; + char buf[256]; + + fgets(buf, 256, stdin); + MultiByteToWideChar(CP_ACP, 0, buf, -1, buf_w, 256); + wprintf(L"%d", lstrlenW(buf_w)); + if (StrStrW(buf_w, str) != NULL) + { + WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR, + buf_w, -1, buf, 256, NULL, NULL); + printf("%s", buf); + } +} + int wmain(int argc, WCHAR *argv[]) { - int i; + int i, str_index = -1; + HANDLE input_file, output_file; + FIND_TYPE type = FIND_NO_FLAGS; + + for (i = 1; i < argc; i++) + { + if (lstrlenW(argv[i]) == 2 && argv[i][0] == '/') + { + switch (argv[i][1]) + { + case 'V': + type |= FIND_V; + break; + + case 'C': + type |= FIND_C; + break; + + case 'N': + type |= FIND_N; + break; + + case 'I': + type |= FIND_I; + break; + + default: + printf("FIND: Invalid switch\n"); + return 0; + } + } + else + str_index = i; + } + + if (str_index == -1) + { + printf("FIND: Parameter format not correct\n"); + return 0; + } - WINE_FIXME("stub:"); - for (i = 0; i < argc; i++) - WINE_FIXME(" %s", wine_dbgstr_w(argv[i])); - WINE_FIXME("\n"); + switch (type) + { + case FIND_V: + case FIND_C: + case FIND_N: + case FIND_I: + /* Not implemented */ + WINE_FIXME("Flags not implemented\n"); + break; + case FIND_NO_FLAGS: + /* Searches a user-entered string for the desired value until the program is terminated */ + read_input(argv[str_index]); + break; + } return 0; } -- 2.20.1