eric pouech (@epo) commented about programs/cmd/lineedit.c:
> + int lastStartQuote;
> + int searchPos;
> + int insertPos;
> +} SEARCH_CONTEXT, *PSEARCH_CONTEXT;
> +
> +
> +static BOOL IsDirectoryOperation(const WCHAR *inputBuffer, const ULONG inputBufferLength)
> +{
> + int cc = 0;
> + BOOL ret = FALSE;
> +
> + while (cc < inputBufferLength && (inputBuffer[cc] == L' ' || inputBuffer[cc] == L'\t')) {
> + cc++;
> + }
> +
> + if ((cc + 2 < inputBufferLength && (inputBuffer[cc + 2] == L' ' || inputBuffer[cc + 2] == L'\t')) &&
questionning about finding the end of first word algorithm
native behavior is very inconsistent
`>cd\windows`
(note that there's no space between "cd" and "\\"). is supported as command, but tab-completion on "windows" doesn't work
**but**
`>cd"\windows"`
(idem no space, but with quotes). isn't supported as a command, but tab-completion does work
since this relates to corner cases of user interaction, I'm not sure we want to mimic all these broken behaviors
for consistency I'd rather suggest that you use `WCMD_parameter` to split the edit line into separate words you can then work upon
this at least will provide consistency across all the code
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/7843#note_101935
eric pouech (@epo) commented about programs/cmd/lineedit.c:
> + }
> + oldCurPos = curPos;
> + curPos = 0;
> + while (curPos < len &&
> + inputBuffer[curPos] != L'\t' &&
> + inputBuffer[curPos] != L'\x1B'
> + ) {
> +
> + curPos++;
> + }
> + /* curPos is often numRead - 1, but not always, as in the case where history is retrieved
> + * and then user backspaces to somewhere mid-string and then hits Tab.
> + */
> + TRACE("numRead: %lu, curPos: %u\n", *numRead, curPos);
> +
> + switch (inputBuffer[curPos]) {
looks to be that curPos can be \> \*numRead, hence reading garbage in that case
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/7843#note_101933
eric pouech (@epo) commented about programs/cmd/lineedit.c:
> + /* curPos is often numRead - 1, but not always, as in the case where history is retrieved
> + * and then user backspaces to somewhere mid-string and then hits Tab.
> + */
> + TRACE("numRead: %lu, curPos: %u\n", *numRead, curPos);
> +
> + switch (inputBuffer[curPos]) {
> + case L'\t':
> + TRACE("TAB: [%s]\n", wine_dbgstr_w(inputBuffer));
> + inputBuffer[curPos] = L'\0';
> + len = curPos;
> + sc.haveSearchResult = FALSE;
> +
> + /* See if we need to reset an existing search. */
> + if (sc.hSearch != INVALID_HANDLE_VALUE) {
> + /* If tab key was hit at a different location than last time */
> + if (curPos != oldCurPos) {
that's not sufficient, you have also to compare that inputbuffer up to current pos hasn't changed since previous call
(eg directory with za, za2 and zb zb2 files... circle twice from "za", replace "za" by "zb" and circle with tab...)
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/7843#note_101932
eric pouech (@epo) commented about programs/cmd/lineedit.c:
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
> + */
> +
> +#define WIN32_LEAN_AND_MEAN
> +
> +#include "wcmd.h"
> +#include "wine/debug.h"
> +
> +WINE_DEFAULT_DEBUG_CHANNEL(cmd);
> +
> +typedef struct _SEARCH_CONTEXT
> +{
> + HANDLE hSearch;
in new code, we tend not to use camel case for function names or fields but rather snake case
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/7843#note_101930
eric pouech (@epo) commented about programs/cmd/lineedit.c:
> +typedef struct _SEARCH_CONTEXT
> +{
> + HANDLE hSearch;
> + WIN32_FIND_DATAW findData;
> + BOOL haveQuotes;
> + BOOL ignoreTrailingQuote;
> + BOOL isDirSearch;
> + BOOL haveSearchResult;
> + BOOL hadOneMatch;
> + int lastStartQuote;
> + int searchPos;
> + int insertPos;
> +} SEARCH_CONTEXT, *PSEARCH_CONTEXT;
> +
> +
> +static BOOL IsDirectoryOperation(const WCHAR *inputBuffer, const ULONG inputBufferLength)
I'd like to see the code for specific handling of first word in a separate commit (just for clarity and make review easier)
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/7843#note_101927
thanks
a couple of high level comments:
* I don't think having a separate source file just for \~400 LoC is worth it
* WCMD_ReadConsole is way too big as a function and need to be split in smaller pieces.
* you should also be using the command line parsing functions instead of rewriting them (eg WCMD_parameter to loop against the various parameters)
from quick testing:
* when looping around files sometimes filename is inserted in quotes, while it shouldn't. Native seems to insert quotes only when filename contains specific characters (spaces...), but to also remove them if next file doesn't contain any...
* using "cd c:\\Program Files"\<tab\>\<backspace\>\\\<tab\> doesn't behave as native... native circles in the directory content, current MR only adds a double quote
* got a crash when playing with MR (perhaps one of the buffer overflow stated above, perhaps not)
* when the width of the console is smaller than the full line input (eg spread at least on two lines), circling gives some strange result (cursor and display when from bottom of screen buffer back to top, will previous content not shifted)
likely the current appoach of just having a handle to findfirst/findnext will not fit all the (long term) goals. at some point, we want to support shift-tab which circles backwards in the matching files. and I fail to see what using FindFirstFileEx brings as value, as you filter against directory when needed (I'm not asking for supporting shift-tab right now, but rather to put in place a structure were it wil fit simply when we implement it)
support for cd/rmdir/ and friends should be added in a second patch
I didn't go further in the review given the amount a remarks and problems stated above. I'll restart when they are solved
(will look in // to the ESC issue raised)
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/7843#note_101926