From: Joe Souza jsouza@yahoo.com
--- programs/cmd/directory.c | 13 ++++++++----- programs/cmd/wcmd.h | 2 ++ programs/cmd/wcmdmain.c | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/programs/cmd/directory.c b/programs/cmd/directory.c index 3a2a5955d12..6c3538484f6 100644 --- a/programs/cmd/directory.c +++ b/programs/cmd/directory.c @@ -256,6 +256,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le DIRECTORY_STACK *parms; int concurrentDirs = 0; BOOL done_header = FALSE; + BOOL operation_aborted = FALSE;
dir_count = 0; file_count = 0; @@ -333,7 +334,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le } WINE_TRACE("cols=%d, rows=%d\n", numCols, numRows);
- for (rows=0; rows<numRows; rows++) { + for (rows=0; rows<numRows && !operation_aborted; rows++) { BOOL addNewLine = TRUE; for (cols=0; cols<numCols; cols++) { WCHAR username[24]; @@ -428,9 +429,11 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le } if (addNewLine) WCMD_output_asis(L"\r\n"); cur_width = 0; + + operation_aborted = WCMD_is_command_aborted(); }
- if (!bare) { + if (!bare && !operation_aborted) { if (file_count == 1) { WCMD_output (L" 1 file %1!25s! bytes\n", WCMD_filesize64 (byte_count.QuadPart)); } @@ -442,7 +445,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le file_total = file_total + file_count; dir_total = dir_total + dir_count;
- if (!bare && !recurse) { + if (!bare && !recurse && !operation_aborted) { if (dir_count == 1) { WCMD_output (L"%1!8d! directory ", 1); } else { @@ -453,7 +456,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le free(fd);
/* When recursing, look in all subdirectories for matches */ - if (recurse) { + if (recurse && !operation_aborted) { DIRECTORY_STACK *dirStack = NULL; DIRECTORY_STACK *lastEntry = NULL; WIN32_FIND_DATAW finddata; @@ -535,7 +538,7 @@ static void WCMD_dir_trailer(const WCHAR *path) { WINE_TRACE("Writing trailer for '%s' gave %d(%ld)\n", wine_dbgstr_w(path), status, GetLastError());
- if (errorlevel == NO_ERROR && !bare) { + if (errorlevel == NO_ERROR && !bare && !WCMD_is_command_aborted()) { if (recurse) { WCMD_output (L"\n Total files listed:\n%1!8d! files%2!25s! bytes\n", file_total, WCMD_filesize64 (byte_total)); WCMD_output (L"%1!8d! directories %2!18s! bytes free\n\n", dir_total, WCMD_filesize64 (freebytes.QuadPart)); diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index caacd44995d..2e6d1eeffdc 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -224,6 +224,8 @@ RETURN_CODE WCMD_run_builtin_command(int cmd_index, WCHAR *cmd); BOOL WCMD_find_label(HANDLE h, const WCHAR*, LARGE_INTEGER *pos); void WCMD_set_label_end(WCHAR *string);
+BOOL WCMD_is_command_aborted(void); + void *xrealloc(void *, size_t) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(free);
static inline void *xalloc(size_t sz) __WINE_MALLOC; diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 223bb55d2c6..fe8e3ddcff0 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -57,6 +57,8 @@ static int max_height; static int max_width; static int numChars;
+static HANDLE control_c_event = NULL; + #define MAX_WRITECONSOLE_SIZE 65535
/* @@ -246,6 +248,8 @@ static void WCMD_output_asis_handle (DWORD std_handle, const WCHAR *message) { const WCHAR* ptr; WCHAR string[1024]; HANDLE handle = GetStdHandle(std_handle); + //FIXME: (see note below) + //HANDLE wait_handles[] = {GetStdHandle(STD_INPUT_HANDLE), control_c_event};
if (paged_mode) { do { @@ -260,6 +264,10 @@ static void WCMD_output_asis_handle (DWORD std_handle, const WCHAR *message) { if (++line_count >= max_height - 1) { line_count = 0; WCMD_output_asis_len(pagedMessage, lstrlenW(pagedMessage), handle); + //FIXME: This WaitForMultipleObjects call should be used instead of the WCMD_ReadFile call, + // but apparently the standard input handle is always signalled in Wine. + //WaitForMultipleObjects(ARRAY_SIZE(wait_handles), wait_handles, FALSE, INFINITE); + //WCMD_output_asis(L"\r\n"); WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), string, ARRAY_SIZE(string), &count); } } while (((message = ptr) != NULL) && (*ptr)); @@ -3848,9 +3856,18 @@ RETURN_CODE node_execute(CMD_NODE *node) return return_code; }
+ +BOOL WCMD_is_command_aborted(void) +{ + return (WAIT_OBJECT_0 == WaitForSingleObject(control_c_event, 0)); +} + static BOOL WINAPI my_event_handler(DWORD ctrl) { WCMD_output(L"\n"); + if (ctrl == CTRL_C_EVENT) { + SetEvent(control_c_event); + } return ctrl == CTRL_C_EVENT; }
@@ -4107,6 +4124,7 @@ int __cdecl wmain (int argc, WCHAR *argvW[]) } else { + control_c_event = CreateEventW(NULL, TRUE, FALSE, NULL); SetConsoleCtrlHandler(my_event_handler, TRUE); }
@@ -4234,10 +4252,12 @@ int __cdecl wmain (int argc, WCHAR *argvW[]) { if (rpl_status == RPL_SUCCESS && toExecute) { + ResetEvent(control_c_event); node_execute(toExecute); node_dispose_tree(toExecute); if (echo_mode) WCMD_output_asis(L"\r\n"); } } + CloseHandle(control_c_event); return 0; }