From a0dd01612e9284752e217e036c7dc48b612e931f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Thu, 15 Nov 2012 17:09:51 +0000 Subject: [PATCH] [KERNEL32] - Move history-functions to a dedicated source file. The functions were created in r47580 and therefore update the description header of the file. svn path=/branches/ros-csrss/; revision=57709 --- dll/win32/kernel32/client/console/console.c | 283 ------------------ dll/win32/kernel32/client/console/history.c | 313 ++++++++++++++++++++ 2 files changed, 313 insertions(+), 283 deletions(-) create mode 100644 dll/win32/kernel32/client/console/history.c diff --git a/dll/win32/kernel32/client/console/console.c b/dll/win32/kernel32/client/console/console.c index e764147ba26..5d200891b12 100644 --- a/dll/win32/kernel32/client/console/console.c +++ b/dll/win32/kernel32/client/console/console.c @@ -266,211 +266,6 @@ DuplicateConsoleHandle(HANDLE hConsole, } -static BOOL -IntExpungeConsoleCommandHistory(LPCVOID lpExeName, BOOL bUnicode) -{ - CSR_API_MESSAGE Request; - PCSR_CAPTURE_BUFFER CaptureBuffer; - NTSTATUS Status; - - if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); - if (!CaptureBuffer) - { - DPRINT1("CsrAllocateCaptureBuffer failed!\n"); - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - - IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, - &Request.Data.ExpungeCommandHistory.ExeName); - - Status = CsrClientCallServer(&Request, - CaptureBuffer, - CSR_CREATE_API_NUMBER(CSR_CONSOLE, EXPUNGE_COMMAND_HISTORY), - sizeof(CSR_API_MESSAGE)); - - CsrFreeCaptureBuffer(CaptureBuffer); - - if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) - { - BaseSetLastNTError(Status); - return FALSE; - } - - return TRUE; -} - -/* - * @implemented (Undocumented) - */ -BOOL -WINAPI -ExpungeConsoleCommandHistoryW(LPCWSTR lpExeName) -{ - return IntExpungeConsoleCommandHistory(lpExeName, TRUE); -} - -/* - * @implemented (Undocumented) - */ -BOOL -WINAPI -ExpungeConsoleCommandHistoryA(LPCSTR lpExeName) -{ - return IntExpungeConsoleCommandHistory(lpExeName, FALSE); -} - - -static DWORD -IntGetConsoleCommandHistory(LPVOID lpHistory, DWORD cbHistory, LPCVOID lpExeName, BOOL bUnicode) -{ - CSR_API_MESSAGE Request; - PCSR_CAPTURE_BUFFER CaptureBuffer; - NTSTATUS Status; - DWORD HistoryLength = cbHistory * (bUnicode ? 1 : sizeof(WCHAR)); - - if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) - { - SetLastError(ERROR_INVALID_PARAMETER); - return 0; - } - - CaptureBuffer = CsrAllocateCaptureBuffer(2, IntStringSize(lpExeName, bUnicode) + - HistoryLength); - if (!CaptureBuffer) - { - DPRINT1("CsrAllocateCaptureBuffer failed!\n"); - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return 0; - } - - IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, - &Request.Data.GetCommandHistory.ExeName); - Request.Data.GetCommandHistory.Length = HistoryLength; - CsrAllocateMessagePointer(CaptureBuffer, HistoryLength, - (PVOID*)&Request.Data.GetCommandHistory.History); - - Status = CsrClientCallServer(&Request, - CaptureBuffer, - CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_COMMAND_HISTORY), - sizeof(CSR_API_MESSAGE)); - if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) - { - CsrFreeCaptureBuffer(CaptureBuffer); - BaseSetLastNTError(Status); - return 0; - } - - if (bUnicode) - { - memcpy(lpHistory, - Request.Data.GetCommandHistory.History, - Request.Data.GetCommandHistory.Length); - } - else - { - WideCharToMultiByte(CP_ACP, 0, - Request.Data.GetCommandHistory.History, - Request.Data.GetCommandHistory.Length / sizeof(WCHAR), - lpHistory, - cbHistory, - NULL, NULL); - } - - CsrFreeCaptureBuffer(CaptureBuffer); - return Request.Data.GetCommandHistory.Length; -} - -/* - * @implemented (Undocumented) - */ -DWORD -WINAPI -GetConsoleCommandHistoryW(LPWSTR lpHistory, - DWORD cbHistory, - LPCWSTR lpExeName) -{ - return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, TRUE); -} - -/* - * @implemented (Undocumented) - */ -DWORD -WINAPI -GetConsoleCommandHistoryA(LPSTR lpHistory, - DWORD cbHistory, - LPCSTR lpExeName) -{ - return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, FALSE); -} - - -static DWORD -IntGetConsoleCommandHistoryLength(LPCVOID lpExeName, BOOL bUnicode) -{ - CSR_API_MESSAGE Request; - PCSR_CAPTURE_BUFFER CaptureBuffer; - NTSTATUS Status; - - if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) - { - SetLastError(ERROR_INVALID_PARAMETER); - return 0; - } - - CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); - if (!CaptureBuffer) - { - DPRINT1("CsrAllocateCaptureBuffer failed!\n"); - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return 0; - } - - IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, - &Request.Data.GetCommandHistoryLength.ExeName); - - Status = CsrClientCallServer(&Request, - CaptureBuffer, - CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_COMMAND_HISTORY_LENGTH), - sizeof(CSR_API_MESSAGE)); - - CsrFreeCaptureBuffer(CaptureBuffer); - - if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) - { - BaseSetLastNTError(Status); - return 0; - } - - return Request.Data.GetCommandHistoryLength.Length; -} - -/* - * @implemented (Undocumented) - */ -DWORD -WINAPI -GetConsoleCommandHistoryLengthW(LPCWSTR lpExeName) -{ - return IntGetConsoleCommandHistoryLength(lpExeName, TRUE); -} - -/* - * @implemented (Undocumented) - */ -DWORD -WINAPI -GetConsoleCommandHistoryLengthA(LPCSTR lpExeName) -{ - return IntGetConsoleCommandHistoryLength(lpExeName, FALSE) / sizeof(WCHAR); -} /* @@ -802,72 +597,6 @@ SetConsoleMenuClose(DWORD Unknown0) } -static BOOL -IntSetConsoleNumberOfCommands(DWORD dwNumCommands, - LPCVOID lpExeName, - BOOL bUnicode) -{ - CSR_API_MESSAGE Request; - PCSR_CAPTURE_BUFFER CaptureBuffer; - NTSTATUS Status; - - if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) - { - SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; - } - - CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); - if (!CaptureBuffer) - { - DPRINT1("CsrAllocateCaptureBuffer failed!\n"); - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - - IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, - &Request.Data.SetHistoryNumberCommands.ExeName); - Request.Data.SetHistoryNumberCommands.NumCommands = dwNumCommands; - - Status = CsrClientCallServer(&Request, - CaptureBuffer, - CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_HISTORY_NUMBER_COMMANDS), - sizeof(CSR_API_MESSAGE)); - - CsrFreeCaptureBuffer(CaptureBuffer); - - if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) - { - BaseSetLastNTError(Status); - return FALSE; - } - - return TRUE; -} - -/* - * @implemented (Undocumented) - */ -BOOL -WINAPI -SetConsoleNumberOfCommandsA(DWORD dwNumCommands, - LPCWSTR lpExeName) -{ - return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, FALSE); -} - -/* - * @implemented (Undocumented) - */ -BOOL -WINAPI -SetConsoleNumberOfCommandsW(DWORD dwNumCommands, - LPCSTR lpExeName) -{ - return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, TRUE); -} - - /* * @unimplemented (Undocumented) */ @@ -3840,16 +3569,4 @@ SetLastConsoleEventActive(VOID) return FALSE; } -/* - * @unimplemented - */ -BOOL -WINAPI -SetConsoleCommandHistoryMode(IN DWORD dwMode) -{ - STUB; - return FALSE; -} - - /* EOF */ diff --git a/dll/win32/kernel32/client/console/history.c b/dll/win32/kernel32/client/console/history.c new file mode 100644 index 00000000000..cedd78cd526 --- /dev/null +++ b/dll/win32/kernel32/client/console/history.c @@ -0,0 +1,313 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: dll/win32/kernel32/client/console/history.c + * PURPOSE: Win32 Console Client history functions + * PROGRAMMERS: Jeffrey Morlan + */ + +/* INCLUDES *******************************************************************/ + +#include + +#define NDEBUG +#include + + +/* PRIVATE FUNCTIONS **********************************************************/ + +static BOOL +IntExpungeConsoleCommandHistory(LPCVOID lpExeName, BOOL bUnicode) +{ + CSR_API_MESSAGE Request; + PCSR_CAPTURE_BUFFER CaptureBuffer; + NTSTATUS Status; + + if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); + if (!CaptureBuffer) + { + DPRINT1("CsrAllocateCaptureBuffer failed!\n"); + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + + IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, + &Request.Data.ExpungeCommandHistory.ExeName); + + Status = CsrClientCallServer(&Request, + CaptureBuffer, + CSR_CREATE_API_NUMBER(CSR_CONSOLE, EXPUNGE_COMMAND_HISTORY), + sizeof(CSR_API_MESSAGE)); + + CsrFreeCaptureBuffer(CaptureBuffer); + + if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) + { + BaseSetLastNTError(Status); + return FALSE; + } + + return TRUE; +} + + +static DWORD +IntGetConsoleCommandHistory(LPVOID lpHistory, DWORD cbHistory, LPCVOID lpExeName, BOOL bUnicode) +{ + CSR_API_MESSAGE Request; + PCSR_CAPTURE_BUFFER CaptureBuffer; + NTSTATUS Status; + DWORD HistoryLength = cbHistory * (bUnicode ? 1 : sizeof(WCHAR)); + + if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + CaptureBuffer = CsrAllocateCaptureBuffer(2, IntStringSize(lpExeName, bUnicode) + + HistoryLength); + if (!CaptureBuffer) + { + DPRINT1("CsrAllocateCaptureBuffer failed!\n"); + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } + + IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, + &Request.Data.GetCommandHistory.ExeName); + Request.Data.GetCommandHistory.Length = HistoryLength; + CsrAllocateMessagePointer(CaptureBuffer, HistoryLength, + (PVOID*)&Request.Data.GetCommandHistory.History); + + Status = CsrClientCallServer(&Request, + CaptureBuffer, + CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_COMMAND_HISTORY), + sizeof(CSR_API_MESSAGE)); + if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) + { + CsrFreeCaptureBuffer(CaptureBuffer); + BaseSetLastNTError(Status); + return 0; + } + + if (bUnicode) + { + memcpy(lpHistory, + Request.Data.GetCommandHistory.History, + Request.Data.GetCommandHistory.Length); + } + else + { + WideCharToMultiByte(CP_ACP, 0, + Request.Data.GetCommandHistory.History, + Request.Data.GetCommandHistory.Length / sizeof(WCHAR), + lpHistory, + cbHistory, + NULL, NULL); + } + + CsrFreeCaptureBuffer(CaptureBuffer); + return Request.Data.GetCommandHistory.Length; +} + + +static DWORD +IntGetConsoleCommandHistoryLength(LPCVOID lpExeName, BOOL bUnicode) +{ + CSR_API_MESSAGE Request; + PCSR_CAPTURE_BUFFER CaptureBuffer; + NTSTATUS Status; + + if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + + CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); + if (!CaptureBuffer) + { + DPRINT1("CsrAllocateCaptureBuffer failed!\n"); + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } + + IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, + &Request.Data.GetCommandHistoryLength.ExeName); + + Status = CsrClientCallServer(&Request, + CaptureBuffer, + CSR_CREATE_API_NUMBER(CSR_CONSOLE, GET_COMMAND_HISTORY_LENGTH), + sizeof(CSR_API_MESSAGE)); + + CsrFreeCaptureBuffer(CaptureBuffer); + + if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) + { + BaseSetLastNTError(Status); + return 0; + } + + return Request.Data.GetCommandHistoryLength.Length; +} + + +static BOOL +IntSetConsoleNumberOfCommands(DWORD dwNumCommands, + LPCVOID lpExeName, + BOOL bUnicode) +{ + CSR_API_MESSAGE Request; + PCSR_CAPTURE_BUFFER CaptureBuffer; + NTSTATUS Status; + + if (lpExeName == NULL || !(bUnicode ? *(PWCHAR)lpExeName : *(PCHAR)lpExeName)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + CaptureBuffer = CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName, bUnicode)); + if (!CaptureBuffer) + { + DPRINT1("CsrAllocateCaptureBuffer failed!\n"); + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + + IntCaptureMessageString(CaptureBuffer, lpExeName, bUnicode, + &Request.Data.SetHistoryNumberCommands.ExeName); + Request.Data.SetHistoryNumberCommands.NumCommands = dwNumCommands; + + Status = CsrClientCallServer(&Request, + CaptureBuffer, + CSR_CREATE_API_NUMBER(CSR_CONSOLE, SET_HISTORY_NUMBER_COMMANDS), + sizeof(CSR_API_MESSAGE)); + + CsrFreeCaptureBuffer(CaptureBuffer); + + if (!NT_SUCCESS(Status) || !NT_SUCCESS(Status = Request.Status)) + { + BaseSetLastNTError(Status); + return FALSE; + } + + return TRUE; +} + + +/* FUNCTIONS ******************************************************************/ + +/* + * @implemented (Undocumented) + */ +BOOL +WINAPI +ExpungeConsoleCommandHistoryW(LPCWSTR lpExeName) +{ + return IntExpungeConsoleCommandHistory(lpExeName, TRUE); +} + + +/* + * @implemented (Undocumented) + */ +BOOL +WINAPI +ExpungeConsoleCommandHistoryA(LPCSTR lpExeName) +{ + return IntExpungeConsoleCommandHistory(lpExeName, FALSE); +} + + +/* + * @implemented (Undocumented) + */ +DWORD +WINAPI +GetConsoleCommandHistoryW(LPWSTR lpHistory, + DWORD cbHistory, + LPCWSTR lpExeName) +{ + return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, TRUE); +} + + +/* + * @implemented (Undocumented) + */ +DWORD +WINAPI +GetConsoleCommandHistoryA(LPSTR lpHistory, + DWORD cbHistory, + LPCSTR lpExeName) +{ + return IntGetConsoleCommandHistory(lpHistory, cbHistory, lpExeName, FALSE); +} + + +/* + * @implemented (Undocumented) + */ +DWORD +WINAPI +GetConsoleCommandHistoryLengthW(LPCWSTR lpExeName) +{ + return IntGetConsoleCommandHistoryLength(lpExeName, TRUE); +} + + +/* + * @implemented (Undocumented) + */ +DWORD +WINAPI +GetConsoleCommandHistoryLengthA(LPCSTR lpExeName) +{ + return IntGetConsoleCommandHistoryLength(lpExeName, FALSE) / sizeof(WCHAR); +} + + +/* + * @implemented (Undocumented) + */ +BOOL +WINAPI +SetConsoleNumberOfCommandsW(DWORD dwNumCommands, + LPCSTR lpExeName) +{ + return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, TRUE); +} + + +/* + * @implemented (Undocumented) + */ +BOOL +WINAPI +SetConsoleNumberOfCommandsA(DWORD dwNumCommands, + LPCWSTR lpExeName) +{ + return IntSetConsoleNumberOfCommands(dwNumCommands, lpExeName, FALSE); +} + + +/* + * @unimplemented + */ +BOOL +WINAPI +SetConsoleCommandHistoryMode(IN DWORD dwMode) +{ + STUB; + return FALSE; +} + +/* EOF */