2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/console/history.c
5 * PURPOSE: Win32 Console Client history functions
6 * PROGRAMMERS: Jeffrey Morlan
9 /* INCLUDES *******************************************************************/
17 /* PRIVATE FUNCTIONS **********************************************************/
19 /* Get the size needed to copy a string to a capture buffer, including alignment */
21 IntStringSize(LPCVOID String
,
24 ULONG Size
= (Unicode
? wcslen(String
) : strlen(String
)) * sizeof(WCHAR
);
25 return (Size
+ 3) & -4;
29 /* Copy a string to a capture buffer */
31 IntCaptureMessageString(PCSR_CAPTURE_BUFFER CaptureBuffer
,
34 PUNICODE_STRING RequestString
)
39 Size
= wcslen(String
) * sizeof(WCHAR
);
40 CsrCaptureMessageBuffer(CaptureBuffer
, (PVOID
)String
, Size
, (PVOID
*)&RequestString
->Buffer
);
44 Size
= strlen(String
);
45 CsrAllocateMessagePointer(CaptureBuffer
, Size
* sizeof(WCHAR
), (PVOID
*)&RequestString
->Buffer
);
46 Size
= MultiByteToWideChar(CP_ACP
, 0, String
, Size
, RequestString
->Buffer
, Size
* sizeof(WCHAR
))
49 RequestString
->Length
= RequestString
->MaximumLength
= (USHORT
)Size
;
54 IntExpungeConsoleCommandHistory(LPCVOID lpExeName
, BOOL bUnicode
)
57 CONSOLE_API_MESSAGE ApiMessage
;
58 PCONSOLE_EXPUNGECOMMANDHISTORY ExpungeCommandHistoryRequest
= &ApiMessage
.Data
.ExpungeCommandHistoryRequest
;
59 PCSR_CAPTURE_BUFFER CaptureBuffer
;
61 if (lpExeName
== NULL
|| !(bUnicode
? *(PWCHAR
)lpExeName
: *(PCHAR
)lpExeName
))
63 SetLastError(ERROR_INVALID_PARAMETER
);
67 CaptureBuffer
= CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName
, bUnicode
));
70 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
71 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
75 IntCaptureMessageString(CaptureBuffer
, lpExeName
, bUnicode
,
76 &ExpungeCommandHistoryRequest
->ExeName
);
78 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
80 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepExpungeCommandHistory
),
81 sizeof(CONSOLE_EXPUNGECOMMANDHISTORY
));
83 CsrFreeCaptureBuffer(CaptureBuffer
);
85 if (!NT_SUCCESS(Status
))
87 BaseSetLastNTError(Status
);
96 IntGetConsoleCommandHistory(LPVOID lpHistory
, DWORD cbHistory
, LPCVOID lpExeName
, BOOL bUnicode
)
99 CONSOLE_API_MESSAGE ApiMessage
;
100 PCONSOLE_GETCOMMANDHISTORY GetCommandHistoryRequest
= &ApiMessage
.Data
.GetCommandHistoryRequest
;
101 PCSR_CAPTURE_BUFFER CaptureBuffer
;
102 DWORD HistoryLength
= cbHistory
* (bUnicode
? 1 : sizeof(WCHAR
));
104 if (lpExeName
== NULL
|| !(bUnicode
? *(PWCHAR
)lpExeName
: *(PCHAR
)lpExeName
))
106 SetLastError(ERROR_INVALID_PARAMETER
);
110 CaptureBuffer
= CsrAllocateCaptureBuffer(2, IntStringSize(lpExeName
, bUnicode
) +
114 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
115 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
119 IntCaptureMessageString(CaptureBuffer
, lpExeName
, bUnicode
,
120 &GetCommandHistoryRequest
->ExeName
);
121 GetCommandHistoryRequest
->Length
= HistoryLength
;
122 CsrAllocateMessagePointer(CaptureBuffer
, HistoryLength
,
123 (PVOID
*)&GetCommandHistoryRequest
->History
);
125 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
127 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCommandHistory
),
128 sizeof(CONSOLE_GETCOMMANDHISTORY
));
129 if (!NT_SUCCESS(Status
))
131 CsrFreeCaptureBuffer(CaptureBuffer
);
132 BaseSetLastNTError(Status
);
139 GetCommandHistoryRequest
->History
,
140 GetCommandHistoryRequest
->Length
);
144 WideCharToMultiByte(CP_ACP
, 0,
145 GetCommandHistoryRequest
->History
,
146 GetCommandHistoryRequest
->Length
/ sizeof(WCHAR
),
152 CsrFreeCaptureBuffer(CaptureBuffer
);
154 return GetCommandHistoryRequest
->Length
;
159 IntGetConsoleCommandHistoryLength(LPCVOID lpExeName
, BOOL bUnicode
)
162 CONSOLE_API_MESSAGE ApiMessage
;
163 PCONSOLE_GETCOMMANDHISTORYLENGTH GetCommandHistoryLengthRequest
= &ApiMessage
.Data
.GetCommandHistoryLengthRequest
;
164 PCSR_CAPTURE_BUFFER CaptureBuffer
;
166 if (lpExeName
== NULL
|| !(bUnicode
? *(PWCHAR
)lpExeName
: *(PCHAR
)lpExeName
))
168 SetLastError(ERROR_INVALID_PARAMETER
);
172 CaptureBuffer
= CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName
, bUnicode
));
175 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
176 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
180 IntCaptureMessageString(CaptureBuffer
, lpExeName
, bUnicode
,
181 &GetCommandHistoryLengthRequest
->ExeName
);
183 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
185 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepGetCommandHistoryLength
),
186 sizeof(CONSOLE_GETCOMMANDHISTORYLENGTH
));
188 CsrFreeCaptureBuffer(CaptureBuffer
);
190 if (!NT_SUCCESS(Status
))
192 BaseSetLastNTError(Status
);
196 return GetCommandHistoryLengthRequest
->Length
;
201 IntSetConsoleNumberOfCommands(DWORD dwNumCommands
,
206 CONSOLE_API_MESSAGE ApiMessage
;
207 PCONSOLE_SETHISTORYNUMBERCOMMANDS SetHistoryNumberCommandsRequest
= &ApiMessage
.Data
.SetHistoryNumberCommandsRequest
;
208 PCSR_CAPTURE_BUFFER CaptureBuffer
;
210 if (lpExeName
== NULL
|| !(bUnicode
? *(PWCHAR
)lpExeName
: *(PCHAR
)lpExeName
))
212 SetLastError(ERROR_INVALID_PARAMETER
);
216 CaptureBuffer
= CsrAllocateCaptureBuffer(1, IntStringSize(lpExeName
, bUnicode
));
219 DPRINT1("CsrAllocateCaptureBuffer failed!\n");
220 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
224 IntCaptureMessageString(CaptureBuffer
, lpExeName
, bUnicode
,
225 &SetHistoryNumberCommandsRequest
->ExeName
);
226 SetHistoryNumberCommandsRequest
->NumCommands
= dwNumCommands
;
228 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
230 CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX
, ConsolepSetNumberOfCommands
),
231 sizeof(CONSOLE_SETHISTORYNUMBERCOMMANDS
));
233 CsrFreeCaptureBuffer(CaptureBuffer
);
235 if (!NT_SUCCESS(Status
))
237 BaseSetLastNTError(Status
);
245 /* FUNCTIONS ******************************************************************/
248 * @implemented (Undocumented)
252 ExpungeConsoleCommandHistoryW(LPCWSTR lpExeName
)
254 return IntExpungeConsoleCommandHistory(lpExeName
, TRUE
);
259 * @implemented (Undocumented)
263 ExpungeConsoleCommandHistoryA(LPCSTR lpExeName
)
265 return IntExpungeConsoleCommandHistory(lpExeName
, FALSE
);
270 * @implemented (Undocumented)
274 GetConsoleCommandHistoryW(LPWSTR lpHistory
,
278 return IntGetConsoleCommandHistory(lpHistory
, cbHistory
, lpExeName
, TRUE
);
283 * @implemented (Undocumented)
287 GetConsoleCommandHistoryA(LPSTR lpHistory
,
291 return IntGetConsoleCommandHistory(lpHistory
, cbHistory
, lpExeName
, FALSE
);
296 * @implemented (Undocumented)
300 GetConsoleCommandHistoryLengthW(LPCWSTR lpExeName
)
302 return IntGetConsoleCommandHistoryLength(lpExeName
, TRUE
);
307 * @implemented (Undocumented)
311 GetConsoleCommandHistoryLengthA(LPCSTR lpExeName
)
313 return IntGetConsoleCommandHistoryLength(lpExeName
, FALSE
) / sizeof(WCHAR
);
318 * @implemented (Undocumented)
322 SetConsoleNumberOfCommandsW(DWORD dwNumCommands
,
325 return IntSetConsoleNumberOfCommands(dwNumCommands
, lpExeName
, TRUE
);
330 * @implemented (Undocumented)
334 SetConsoleNumberOfCommandsA(DWORD dwNumCommands
,
337 return IntSetConsoleNumberOfCommands(dwNumCommands
, lpExeName
, FALSE
);
346 SetConsoleCommandHistoryMode(IN DWORD dwMode
)