[KERNEL32][CONSRV]
[reactos.git] / reactos / dll / win32 / kernel32 / client / console / readwrite.c
index df78b95..d42f8d0 100644 (file)
@@ -60,11 +60,17 @@ IntReadConsole(HANDLE hConsoleInput,
     /* Set up the data to send to the Console Server */
     ReadConsoleRequest->InputHandle = hConsoleInput;
     ReadConsoleRequest->Unicode = bUnicode;
-    ReadConsoleRequest->NrCharactersToRead = (WORD)nNumberOfCharsToRead;
+    ReadConsoleRequest->NrCharactersToRead = nNumberOfCharsToRead;
     ReadConsoleRequest->NrCharactersRead = 0;
     ReadConsoleRequest->CtrlWakeupMask = 0;
     if (pInputControl && pInputControl->nLength == sizeof(CONSOLE_READCONSOLE_CONTROL))
     {
+        /*
+         * From MSDN (ReadConsole function), the description
+         * for pInputControl says:
+         * "This parameter requires Unicode input by default.
+         * For ANSI mode, set this parameter to NULL."
+         */
         ReadConsoleRequest->NrCharactersRead = pInputControl->nInitialChars;
         memcpy(ReadConsoleRequest->Buffer,
                lpBuffer,
@@ -114,11 +120,11 @@ IntReadConsole(HANDLE hConsoleInput,
 static
 BOOL
 IntGetConsoleInput(HANDLE hConsoleInput,
-                   BOOL bRead,
                    PINPUT_RECORD lpBuffer,
                    DWORD nLength,
                    LPDWORD lpNumberOfEventsRead,
-                   BOOL bUnicode)
+                   WORD wFlags,
+                   BOOLEAN bUnicode)
 {
     NTSTATUS Status;
     CONSOLE_API_MESSAGE ApiMessage;
@@ -152,10 +158,10 @@ IntGetConsoleInput(HANDLE hConsoleInput,
 
     /* Set up the data to send to the Console Server */
     GetInputRequest->InputHandle = hConsoleInput;
-    GetInputRequest->Unicode = bUnicode;
-    GetInputRequest->bRead = bRead;
     GetInputRequest->InputsRead = 0;
     GetInputRequest->Length = nLength;
+    GetInputRequest->wFlags = wFlags;
+    GetInputRequest->Unicode = bUnicode;
 
     /* Call the server */
     Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
@@ -269,7 +275,7 @@ IntReadConsoleOutput(HANDLE hConsoleOutput,
     }
 
     /* Return the read region */
-    DPRINT("read region: %lx\n", ReadOutputRequest->ReadRegion);
+    DPRINT("read region: %p\n", ReadOutputRequest->ReadRegion);
     *lpReadRegion = ReadOutputRequest->ReadRegion;
 
     /* Release the capture buffer */
@@ -454,7 +460,8 @@ IntWriteConsoleInput(HANDLE hConsoleInput,
                      PINPUT_RECORD lpBuffer,
                      DWORD nLength,
                      LPDWORD lpNumberOfEventsWritten,
-                     BOOL bUnicode)
+                     BOOL bUnicode,
+                     BOOL bAppendToEnd)
 {
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_WRITEINPUT WriteInputRequest = &ApiMessage.Data.WriteInputRequest;
@@ -482,8 +489,9 @@ IntWriteConsoleInput(HANDLE hConsoleInput,
 
     /* Set up the data to send to the Console Server */
     WriteInputRequest->InputHandle = hConsoleInput;
-    WriteInputRequest->Unicode = bUnicode;
     WriteInputRequest->Length = nLength;
+    WriteInputRequest->Unicode = bUnicode;
+    WriteInputRequest->AppendToEnd = bAppendToEnd;
 
     /* Call the server */
     CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
@@ -586,7 +594,7 @@ IntWriteConsoleOutput(HANDLE hConsoleOutput,
     }
 
     /* Return the read region */
-    DPRINT("read region: %lx\n", WriteOutputRequest->WriteRegion);
+    DPRINT("read region: %p\n", WriteOutputRequest->WriteRegion);
     *lpWriteRegion = WriteOutputRequest->WriteRegion;
 
     /* Release the capture buffer */
@@ -654,7 +662,7 @@ IntWriteConsoleOutputCode(HANDLE hConsoleOutput,
     WriteOutputCodeRequest->CodeType = CodeType;
     WriteOutputCodeRequest->Coord = dwWriteCoord;
 
-    WriteOutputCodeRequest->Length = nLength;
+    WriteOutputCodeRequest->Length = (USHORT)nLength;
 
     /* Call the server */
     Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
@@ -817,10 +825,10 @@ PeekConsoleInputW(HANDLE hConsoleInput,
                   LPDWORD lpNumberOfEventsRead)
 {
     return IntGetConsoleInput(hConsoleInput,
-                              FALSE,
                               lpBuffer,
                               nLength,
                               lpNumberOfEventsRead,
+                              CONSOLE_READ_KEEPEVENT | CONSOLE_READ_CONTINUE,
                               TRUE);
 }
 
@@ -838,10 +846,10 @@ PeekConsoleInputA(HANDLE hConsoleInput,
                   LPDWORD lpNumberOfEventsRead)
 {
     return IntGetConsoleInput(hConsoleInput,
-                              FALSE,
                               lpBuffer,
                               nLength,
                               lpNumberOfEventsRead,
+                              CONSOLE_READ_KEEPEVENT | CONSOLE_READ_CONTINUE,
                               FALSE);
 }
 
@@ -859,10 +867,10 @@ ReadConsoleInputW(HANDLE hConsoleInput,
                   LPDWORD lpNumberOfEventsRead)
 {
     return IntGetConsoleInput(hConsoleInput,
-                              TRUE,
                               lpBuffer,
                               nLength,
                               lpNumberOfEventsRead,
+                              0,
                               TRUE);
 }
 
@@ -880,29 +888,55 @@ ReadConsoleInputA(HANDLE hConsoleInput,
                   LPDWORD lpNumberOfEventsRead)
 {
     return IntGetConsoleInput(hConsoleInput,
-                              TRUE,
                               lpBuffer,
                               nLength,
                               lpNumberOfEventsRead,
+                              0,
                               FALSE);
 }
 
 
+/*--------------------------------------------------------------
+ *     ReadConsoleInputExW
+ *
+ * @implemented
+ */
 BOOL
 WINAPI
-ReadConsoleInputExW(HANDLE hConsole, LPVOID lpBuffer, DWORD dwLen, LPDWORD Unknown1, DWORD Unknown2)
+ReadConsoleInputExW(HANDLE hConsoleInput,
+                    PINPUT_RECORD lpBuffer,
+                    DWORD nLength,
+                    LPDWORD lpNumberOfEventsRead,
+                    WORD wFlags)
 {
-    STUB;
-    return FALSE;
+    return IntGetConsoleInput(hConsoleInput,
+                              lpBuffer,
+                              nLength,
+                              lpNumberOfEventsRead,
+                              wFlags,
+                              TRUE);
 }
 
 
+/*--------------------------------------------------------------
+ *     ReadConsoleInputExA
+ *
+ * @implemented
+ */
 BOOL
 WINAPI
-ReadConsoleInputExA(HANDLE hConsole, LPVOID lpBuffer, DWORD dwLen, LPDWORD Unknown1, DWORD Unknown2)
+ReadConsoleInputExA(HANDLE hConsoleInput,
+                    PINPUT_RECORD lpBuffer,
+                    DWORD nLength,
+                    LPDWORD lpNumberOfEventsRead,
+                    WORD wFlags)
 {
-    STUB;
-    return FALSE;
+    return IntGetConsoleInput(hConsoleInput,
+                              lpBuffer,
+                              nLength,
+                              lpNumberOfEventsRead,
+                              wFlags,
+                              FALSE);
 }
 
 
@@ -1080,6 +1114,7 @@ WriteConsoleInputW(HANDLE hConsoleInput,
                                 (PINPUT_RECORD)lpBuffer,
                                 nLength,
                                 lpNumberOfEventsWritten,
+                                TRUE,
                                 TRUE);
 }
 
@@ -1100,6 +1135,49 @@ WriteConsoleInputA(HANDLE hConsoleInput,
                                 (PINPUT_RECORD)lpBuffer,
                                 nLength,
                                 lpNumberOfEventsWritten,
+                                FALSE,
+                                TRUE);
+}
+
+
+/*--------------------------------------------------------------
+ *     WriteConsoleInputVDMW
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+WriteConsoleInputVDMW(HANDLE hConsoleInput,
+                      CONST INPUT_RECORD *lpBuffer,
+                      DWORD nLength,
+                      LPDWORD lpNumberOfEventsWritten)
+{
+    return IntWriteConsoleInput(hConsoleInput,
+                                (PINPUT_RECORD)lpBuffer,
+                                nLength,
+                                lpNumberOfEventsWritten,
+                                TRUE,
+                                FALSE);
+}
+
+
+/*--------------------------------------------------------------
+ *     WriteConsoleInputVDMA
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+WriteConsoleInputVDMA(HANDLE hConsoleInput,
+                      CONST INPUT_RECORD *lpBuffer,
+                      DWORD nLength,
+                      LPDWORD lpNumberOfEventsWritten)
+{
+    return IntWriteConsoleInput(hConsoleInput,
+                                (PINPUT_RECORD)lpBuffer,
+                                nLength,
+                                lpNumberOfEventsWritten,
+                                FALSE,
                                 FALSE);
 }