Simplify code.
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Tue, 29 Jul 2014 13:49:03 +0000 (13:49 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Tue, 29 Jul 2014 13:49:03 +0000 (13:49 +0000)
svn path=/branches/condrv_restructure/; revision=63768

dll/win32/kernel32/client/console/readwrite.c
include/reactos/subsys/win/conmsg.h
win32ss/user/winsrv/consrv/condrv/text.c
win32ss/user/winsrv/consrv/conoutput.c

index 9d96080..fa16afd 100644 (file)
@@ -319,6 +319,14 @@ IntReadConsoleOutputCode(HANDLE hConsoleOutput,
 
     DPRINT("IntReadConsoleOutputCode\n");
 
 
     DPRINT("IntReadConsoleOutputCode\n");
 
+    if ( (CodeType != CODE_ASCII    ) &&
+         (CodeType != CODE_UNICODE  ) &&
+         (CodeType != CODE_ATTRIBUTE) )
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
     /* Set up the data to send to the Console Server */
     ReadOutputCodeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
     ReadOutputCodeRequest->OutputHandle  = hConsoleOutput;
     /* Set up the data to send to the Console Server */
     ReadOutputCodeRequest->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
     ReadOutputCodeRequest->OutputHandle  = hConsoleOutput;
@@ -330,20 +338,16 @@ IntReadConsoleOutputCode(HANDLE hConsoleOutput,
     switch (CodeType)
     {
         case CODE_ASCII:
     switch (CodeType)
     {
         case CODE_ASCII:
-            CodeSize = sizeof(CHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar);
             break;
 
         case CODE_UNICODE:
             break;
 
         case CODE_UNICODE:
-            CodeSize = sizeof(WCHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar);
             break;
 
         case CODE_ATTRIBUTE:
             break;
 
         case CODE_ATTRIBUTE:
-            CodeSize = sizeof(WORD);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, Attribute);
             break;
             break;
-
-        default:
-            SetLastError(ERROR_INVALID_PARAMETER);
-            return FALSE;
     }
     SizeBytes = nLength * CodeSize;
 
     }
     SizeBytes = nLength * CodeSize;
 
@@ -355,7 +359,7 @@ IntReadConsoleOutputCode(HANDLE hConsoleOutput,
      */
     if (SizeBytes <= sizeof(ReadOutputCodeRequest->CodeStaticBuffer))
     {
      */
     if (SizeBytes <= sizeof(ReadOutputCodeRequest->CodeStaticBuffer))
     {
-        ReadOutputCodeRequest->pCode.pCode = ReadOutputCodeRequest->CodeStaticBuffer;
+        ReadOutputCodeRequest->pCode = ReadOutputCodeRequest->CodeStaticBuffer;
         // CaptureBuffer = NULL;
     }
     else
         // CaptureBuffer = NULL;
     }
     else
@@ -372,7 +376,7 @@ IntReadConsoleOutputCode(HANDLE hConsoleOutput,
         /* Allocate space in the Buffer */
         CsrAllocateMessagePointer(CaptureBuffer,
                                   SizeBytes,
         /* Allocate space in the Buffer */
         CsrAllocateMessagePointer(CaptureBuffer,
                                   SizeBytes,
-                                  (PVOID*)&ReadOutputCodeRequest->pCode.pCode);
+                                  (PVOID*)&ReadOutputCodeRequest->pCode);
     }
 
     /* Call the server */
     }
 
     /* Call the server */
@@ -386,7 +390,7 @@ IntReadConsoleOutputCode(HANDLE hConsoleOutput,
     {
         DWORD NumCodes = ReadOutputCodeRequest->NumCodes;
         RtlCopyMemory(pCode,
     {
         DWORD NumCodes = ReadOutputCodeRequest->NumCodes;
         RtlCopyMemory(pCode,
-                      ReadOutputCodeRequest->pCode.pCode,
+                      ReadOutputCodeRequest->pCode,
                       NumCodes * CodeSize);
 
         if (lpNumberOfCodesRead != NULL)
                       NumCodes * CodeSize);
 
         if (lpNumberOfCodesRead != NULL)
@@ -675,6 +679,14 @@ IntWriteConsoleOutputCode(HANDLE hConsoleOutput,
         return FALSE;
     }
 
         return FALSE;
     }
 
+    if ( (CodeType != CODE_ASCII    ) &&
+         (CodeType != CODE_UNICODE  ) &&
+         (CodeType != CODE_ATTRIBUTE) )
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
     DPRINT("IntWriteConsoleOutputCode\n");
 
     /* Set up the data to send to the Console Server */
     DPRINT("IntWriteConsoleOutputCode\n");
 
     /* Set up the data to send to the Console Server */
@@ -688,20 +700,16 @@ IntWriteConsoleOutputCode(HANDLE hConsoleOutput,
     switch (CodeType)
     {
         case CODE_ASCII:
     switch (CodeType)
     {
         case CODE_ASCII:
-            CodeSize = sizeof(CHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar);
             break;
 
         case CODE_UNICODE:
             break;
 
         case CODE_UNICODE:
-            CodeSize = sizeof(WCHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar);
             break;
 
         case CODE_ATTRIBUTE:
             break;
 
         case CODE_ATTRIBUTE:
-            CodeSize = sizeof(WORD);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, Attribute);
             break;
             break;
-
-        default:
-            SetLastError(ERROR_INVALID_PARAMETER);
-            return FALSE;
     }
     SizeBytes = nLength * CodeSize;
 
     }
     SizeBytes = nLength * CodeSize;
 
@@ -713,10 +721,10 @@ IntWriteConsoleOutputCode(HANDLE hConsoleOutput,
      */
     if (SizeBytes <= sizeof(WriteOutputCodeRequest->CodeStaticBuffer))
     {
      */
     if (SizeBytes <= sizeof(WriteOutputCodeRequest->CodeStaticBuffer))
     {
-        WriteOutputCodeRequest->pCode.pCode = WriteOutputCodeRequest->CodeStaticBuffer;
+        WriteOutputCodeRequest->pCode = WriteOutputCodeRequest->CodeStaticBuffer;
         // CaptureBuffer = NULL;
 
         // CaptureBuffer = NULL;
 
-        RtlCopyMemory(WriteOutputCodeRequest->pCode.pCode,
+        RtlCopyMemory(WriteOutputCodeRequest->pCode,
                       pCode,
                       SizeBytes);
     }
                       pCode,
                       SizeBytes);
     }
@@ -735,7 +743,7 @@ IntWriteConsoleOutputCode(HANDLE hConsoleOutput,
         CsrCaptureMessageBuffer(CaptureBuffer,
                                 (PVOID)pCode,
                                 SizeBytes,
         CsrCaptureMessageBuffer(CaptureBuffer,
                                 (PVOID)pCode,
                                 SizeBytes,
-                                (PVOID*)&WriteOutputCodeRequest->pCode.pCode);
+                                (PVOID*)&WriteOutputCodeRequest->pCode);
     }
 
     /* Call the server */
     }
 
     /* Call the server */
@@ -779,6 +787,8 @@ IntFillConsoleOutputCode(HANDLE hConsoleOutput,
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_FILLOUTPUTCODE FillOutputRequest = &ApiMessage.Data.FillOutputRequest;
 
     CONSOLE_API_MESSAGE ApiMessage;
     PCONSOLE_FILLOUTPUTCODE FillOutputRequest = &ApiMessage.Data.FillOutputRequest;
 
+    DPRINT("IntFillConsoleOutputCode\n");
+
     if ( (CodeType != CODE_ASCII    ) &&
          (CodeType != CODE_UNICODE  ) &&
          (CodeType != CODE_ATTRIBUTE) )
     if ( (CodeType != CODE_ASCII    ) &&
          (CodeType != CODE_UNICODE  ) &&
          (CodeType != CODE_ATTRIBUTE) )
index 88f4f39..a16e9a4 100644 (file)
@@ -464,7 +464,7 @@ typedef union _CODE_ELEMENT
     CHAR  AsciiChar;
     WCHAR UnicodeChar;
     WORD  Attribute;
     CHAR  AsciiChar;
     WCHAR UnicodeChar;
     WORD  Attribute;
-} CODE_ELEMENT, *PCODE_ELEMENT;
+} CODE_ELEMENT;
 
 typedef struct
 {
 
 typedef struct
 {
@@ -473,14 +473,15 @@ typedef struct
     COORD  Coord;
 
     CODE_TYPE CodeType;
     COORD  Coord;
 
     CODE_TYPE CodeType;
-    CHAR      CodeStaticBuffer[80];
-    union
-    {
-        PVOID  pCode;
-        PCHAR  AsciiChar;
-        PWCHAR UnicodeChar;
-        PWORD  Attribute;
-    } pCode;    // Either a pointer to a character or to an attribute.
+    CHAR      CodeStaticBuffer[80]; // == 40 * sizeof(CODE_ELEMENT)
+    PVOID     pCode; // Either a pointer to a character or to an attribute.
+    // union
+    // {
+        // PVOID  pCode;
+        // PCHAR  AsciiChar;
+        // PWCHAR UnicodeChar;
+        // PWORD  Attribute;
+    // } pCode;    // Either a pointer to a character or to an attribute.
 
     ULONG NumCodes;
 } CONSOLE_READOUTPUTCODE , *PCONSOLE_READOUTPUTCODE,
 
     ULONG NumCodes;
 } CONSOLE_READOUTPUTCODE , *PCONSOLE_READOUTPUTCODE,
index c8f132c..bef1bf0 100644 (file)
@@ -913,15 +913,15 @@ ConDrvReadConsoleOutputString(IN PCONSOLE Console,
     switch (CodeType)
     {
         case CODE_ASCII:
     switch (CodeType)
     {
         case CODE_ASCII:
-            CodeSize = sizeof(CHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar);
             break;
 
         case CODE_UNICODE:
             break;
 
         case CODE_UNICODE:
-            CodeSize = sizeof(WCHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar);
             break;
 
         case CODE_ATTRIBUTE:
             break;
 
         case CODE_ATTRIBUTE:
-            CodeSize = sizeof(WORD);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, Attribute);
             break;
 
         default:
             break;
 
         default:
@@ -982,21 +982,6 @@ ConDrvReadConsoleOutputString(IN PCONSOLE Console,
         }
     }
 
         }
     }
 
-    // switch (CodeType)
-    // {
-        // case CODE_UNICODE:
-            // *(PWCHAR)ReadBuffer = 0;
-            // break;
-
-        // case CODE_ASCII:
-            // *(PCHAR)ReadBuffer = 0;
-            // break;
-
-        // case CODE_ATTRIBUTE:
-            // *(PWORD)ReadBuffer = 0;
-            // break;
-    // }
-
     // EndCoord->X = Xpos;
     // EndCoord->Y = (Ypos - Buffer->VirtualY + Buffer->ScreenBufferSize.Y) % Buffer->ScreenBufferSize.Y;
 
     // EndCoord->X = Xpos;
     // EndCoord->Y = (Ypos - Buffer->VirtualY + Buffer->ScreenBufferSize.Y) % Buffer->ScreenBufferSize.Y;
 
@@ -1036,15 +1021,15 @@ ConDrvWriteConsoleOutputString(IN PCONSOLE Console,
     switch (CodeType)
     {
         case CODE_ASCII:
     switch (CodeType)
     {
         case CODE_ASCII:
-            CodeSize = sizeof(CHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar);
             break;
 
         case CODE_UNICODE:
             break;
 
         case CODE_UNICODE:
-            CodeSize = sizeof(WCHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar);
             break;
 
         case CODE_ATTRIBUTE:
             break;
 
         case CODE_ATTRIBUTE:
-            CodeSize = sizeof(WORD);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, Attribute);
             break;
 
         default:
             break;
 
         default:
index b8850aa..275c2ed 100644 (file)
@@ -540,15 +540,15 @@ CSR_API(SrvReadConsoleOutputString)
     switch (ReadOutputCodeRequest->CodeType)
     {
         case CODE_ASCII:
     switch (ReadOutputCodeRequest->CodeType)
     {
         case CODE_ASCII:
-            CodeSize = sizeof(CHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar);
             break;
 
         case CODE_UNICODE:
             break;
 
         case CODE_UNICODE:
-            CodeSize = sizeof(WCHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar);
             break;
 
         case CODE_ATTRIBUTE:
             break;
 
         case CODE_ATTRIBUTE:
-            CodeSize = sizeof(WORD);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, Attribute);
             break;
 
         default:
             break;
 
         default:
@@ -567,20 +567,20 @@ CSR_API(SrvReadConsoleOutputString)
          * Adjust the internal pointer, because its old value points to
          * the static buffer in the original ApiMessage structure.
          */
          * Adjust the internal pointer, because its old value points to
          * the static buffer in the original ApiMessage structure.
          */
-        // ReadOutputCodeRequest->pCode.pCode = ReadOutputCodeRequest->CodeStaticBuffer;
+        // ReadOutputCodeRequest->pCode = ReadOutputCodeRequest->CodeStaticBuffer;
         pCode = ReadOutputCodeRequest->CodeStaticBuffer;
     }
     else
     {
         if (!CsrValidateMessageBuffer(ApiMessage,
         pCode = ReadOutputCodeRequest->CodeStaticBuffer;
     }
     else
     {
         if (!CsrValidateMessageBuffer(ApiMessage,
-                                      (PVOID*)&ReadOutputCodeRequest->pCode.pCode,
+                                      (PVOID*)&ReadOutputCodeRequest->pCode,
                                       ReadOutputCodeRequest->NumCodes,
                                       CodeSize))
         {
             return STATUS_INVALID_PARAMETER;
         }
 
                                       ReadOutputCodeRequest->NumCodes,
                                       CodeSize))
         {
             return STATUS_INVALID_PARAMETER;
         }
 
-        pCode = ReadOutputCodeRequest->pCode.pCode;
+        pCode = ReadOutputCodeRequest->pCode;
     }
 
     Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
     }
 
     Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
@@ -624,15 +624,15 @@ CSR_API(SrvWriteConsoleOutputString)
     switch (WriteOutputCodeRequest->CodeType)
     {
         case CODE_ASCII:
     switch (WriteOutputCodeRequest->CodeType)
     {
         case CODE_ASCII:
-            CodeSize = sizeof(CHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, AsciiChar);
             break;
 
         case CODE_UNICODE:
             break;
 
         case CODE_UNICODE:
-            CodeSize = sizeof(WCHAR);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, UnicodeChar);
             break;
 
         case CODE_ATTRIBUTE:
             break;
 
         case CODE_ATTRIBUTE:
-            CodeSize = sizeof(WORD);
+            CodeSize = RTL_FIELD_SIZE(CODE_ELEMENT, Attribute);
             break;
 
         default:
             break;
 
         default:
@@ -651,20 +651,20 @@ CSR_API(SrvWriteConsoleOutputString)
          * Adjust the internal pointer, because its old value points to
          * the static buffer in the original ApiMessage structure.
          */
          * Adjust the internal pointer, because its old value points to
          * the static buffer in the original ApiMessage structure.
          */
-        // WriteOutputCodeRequest->pCode.pCode = WriteOutputCodeRequest->CodeStaticBuffer;
+        // WriteOutputCodeRequest->pCode = WriteOutputCodeRequest->CodeStaticBuffer;
         pCode = WriteOutputCodeRequest->CodeStaticBuffer;
     }
     else
     {
         if (!CsrValidateMessageBuffer(ApiMessage,
         pCode = WriteOutputCodeRequest->CodeStaticBuffer;
     }
     else
     {
         if (!CsrValidateMessageBuffer(ApiMessage,
-                                      (PVOID*)&WriteOutputCodeRequest->pCode.pCode,
+                                      (PVOID*)&WriteOutputCodeRequest->pCode,
                                       WriteOutputCodeRequest->NumCodes,
                                       CodeSize))
         {
             return STATUS_INVALID_PARAMETER;
         }
 
                                       WriteOutputCodeRequest->NumCodes,
                                       CodeSize))
         {
             return STATUS_INVALID_PARAMETER;
         }
 
-        pCode = WriteOutputCodeRequest->pCode.pCode;
+        pCode = WriteOutputCodeRequest->pCode;
     }
 
     Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),
     }
 
     Status = ConSrvGetTextModeBuffer(ConsoleGetPerProcessData(CsrGetClientThread()->Process),