[CMD]: Small refactoring:
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 30 Sep 2017 21:37:34 +0000 (21:37 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 30 Sep 2017 21:37:34 +0000 (21:37 +0000)
- Moving ConGetDefaultAttributes() in console.h;
- Moving some SDK inclusions into precomp.h;
- Removing extern HANDLE hIn; and localize the SHORT maxx/y variables;
- Comment fix;
- Whitespace fixes for screen.c.

svn path=/trunk/; revision=76009

reactos/base/shell/cmd/cmd.c
reactos/base/shell/cmd/cmd.h
reactos/base/shell/cmd/console.c
reactos/base/shell/cmd/console.h
reactos/base/shell/cmd/dir.c
reactos/base/shell/cmd/precomp.h
reactos/base/shell/cmd/screen.c
reactos/base/shell/cmd/start.c

index bc608f8..0ca9494 100644 (file)
@@ -311,10 +311,11 @@ Execute(LPTSTR Full, LPTSTR First, LPTSTR Rest, PARSED_COMMAND *Cmd)
 {
     TCHAR szFullName[MAX_PATH];
     TCHAR *first, *rest, *dot;
 {
     TCHAR szFullName[MAX_PATH];
     TCHAR *first, *rest, *dot;
-    TCHAR szWindowTitle[MAX_PATH], szNewTitle[MAX_PATH*2];
+    TCHAR szWindowTitle[MAX_PATH];
+    TCHAR szNewTitle[MAX_PATH*2];
     DWORD dwExitCode = 0;
     TCHAR *FirstEnd;
     DWORD dwExitCode = 0;
     TCHAR *FirstEnd;
-    TCHAR szFullCmdLine [CMDLINE_LENGTH];
+    TCHAR szFullCmdLine[CMDLINE_LENGTH];
 
     TRACE ("Execute: \'%s\' \'%s\'\n", debugstr_aw(First), debugstr_aw(Rest));
 
 
     TRACE ("Execute: \'%s\' \'%s\'\n", debugstr_aw(First), debugstr_aw(Rest));
 
@@ -1762,33 +1763,6 @@ GetCmdLineCommand(TCHAR *commandline, TCHAR *ptr, BOOL AlwaysStrip)
 }
 
 
 }
 
 
-#ifdef INCLUDE_CMD_COLOR
-
-BOOL ConGetDefaultAttributes(PWORD pwDefAttr)
-{
-    BOOL Success;
-    HANDLE hConsole;
-    CONSOLE_SCREEN_BUFFER_INFO csbi;
-
-    /* Do not modify *pwDefAttr if we fail, in which case use default attributes */
-
-    hConsole = CreateFile(_T("CONOUT$"), GENERIC_READ|GENERIC_WRITE,
-                          FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
-                          OPEN_EXISTING, 0, NULL);
-    if (hConsole == INVALID_HANDLE_VALUE)
-        return FALSE; // No default console
-
-    Success = GetConsoleScreenBufferInfo(hConsole, &csbi);
-    if (Success)
-        *pwDefAttr = csbi.wAttributes;
-
-    CloseHandle(hConsole);
-    return Success;
-}
-
-#endif
-
-
 /*
  * Set up global initializations and process parameters
  */
 /*
  * Set up global initializations and process parameters
  */
@@ -1997,7 +1971,6 @@ static VOID Cleanup(VOID)
     if (IsExistingFile(_T("cmdexit.bat")))
     {
         ConErrResPuts(STRING_CMD_ERROR5);
     if (IsExistingFile(_T("cmdexit.bat")))
     {
         ConErrResPuts(STRING_CMD_ERROR5);
-
         ParseCommandLine(_T("cmdexit.bat"));
     }
     else if (IsExistingFile(_T("\\cmdexit.bat")))
         ParseCommandLine(_T("cmdexit.bat"));
     }
     else if (IsExistingFile(_T("\\cmdexit.bat")))
index a0c7b56..8dab4a7 100644 (file)
 
 #include <config.h>
 
 
 #include <config.h>
 
-#include <winnls.h>
-#include <winreg.h>
-#include <winuser.h>
-#include <wincon.h>
-#include <tchar.h>
-
 #include "cmdver.h"
 #include "cmddbg.h"
 
 #include "cmdver.h"
 #include "cmddbg.h"
 
@@ -43,7 +37,6 @@
 #define D_ON         _T("on")
 #define D_OFF        _T("off")
 
 #define D_ON         _T("on")
 #define D_OFF        _T("off")
 
-
 /* command line buffer length */
 #define CMDLINE_LENGTH  8192
 
 /* command line buffer length */
 #define CMDLINE_LENGTH  8192
 
@@ -51,7 +44,6 @@
 #define BUFF_SIZE 16384
 
 /* Global variables */
 #define BUFF_SIZE 16384
 
 /* Global variables */
-extern HANDLE hIn;
 extern LPTSTR lpOriginalEnvironment;
 extern WORD   wColor;
 extern WORD   wDefColor;
 extern LPTSTR lpOriginalEnvironment;
 extern WORD   wColor;
 extern WORD   wDefColor;
@@ -62,8 +54,6 @@ extern BOOL   bDisableBatchEcho;
 extern BOOL   bEnableExtensions;
 extern BOOL   bDelayedExpansion;
 extern INT    nErrorLevel;
 extern BOOL   bEnableExtensions;
 extern BOOL   bDelayedExpansion;
 extern INT    nErrorLevel;
-extern SHORT  maxx;
-extern SHORT  maxy;
 extern BOOL bUnicodeOutput;
 
 
 extern BOOL bUnicodeOutput;
 
 
index b83686f..346d497 100644 (file)
@@ -507,6 +507,33 @@ VOID GetScreenSize(PSHORT maxx, PSHORT maxy)
 
 
 
 
 
 
+#ifdef INCLUDE_CMD_COLOR
+
+BOOL ConGetDefaultAttributes(PWORD pwDefAttr)
+{
+    BOOL Success;
+    HANDLE hConsole;
+    CONSOLE_SCREEN_BUFFER_INFO csbi;
+
+    /* Do not modify *pwDefAttr if we fail, in which case use default attributes */
+
+    hConsole = CreateFile(_T("CONOUT$"), GENERIC_READ|GENERIC_WRITE,
+                          FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
+                          OPEN_EXISTING, 0, NULL);
+    if (hConsole == INVALID_HANDLE_VALUE)
+        return FALSE; // No default console
+
+    Success = GetConsoleScreenBufferInfo(hConsole, &csbi);
+    if (Success)
+        *pwDefAttr = csbi.wAttributes;
+
+    CloseHandle(hConsole);
+    return Success;
+}
+
+#endif
+
+
 BOOL ConSetTitle(IN LPCTSTR lpConsoleTitle)
 {
     /* Now really set the console title */
 BOOL ConSetTitle(IN LPCTSTR lpConsoleTitle)
 {
     /* Now really set the console title */
index 69ef9d3..74a8e96 100644 (file)
@@ -72,6 +72,11 @@ VOID GetScreenSize (PSHORT, PSHORT);
 VOID SetCursorType (BOOL, BOOL);
 
 
 VOID SetCursorType (BOOL, BOOL);
 
 
+#ifdef INCLUDE_CMD_COLOR
+BOOL ConGetDefaultAttributes(PWORD pwDefAttr);
+#endif
+
+
 BOOL ConSetTitle(IN LPCTSTR lpConsoleTitle);
 
 #ifdef INCLUDE_CMD_BEEP
 BOOL ConSetTitle(IN LPCTSTR lpConsoleTitle);
 
 #ifdef INCLUDE_CMD_BEEP
index 093ae8b..ffd03a9 100644 (file)
@@ -1052,7 +1052,7 @@ DirPrintOldList(PDIRFINDINFO ptrFiles[],        /* [IN] Files' Info */
         /* Calculate size */
         if (ptrFiles[i]->stFindInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
         {
         /* Calculate size */
         if (ptrFiles[i]->stFindInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
         {
-            /* Directory, no size it's a directory*/
+            /* Directory, no size it's a directory */
             iSizeFormat = -17;
             _tcscpy(szSize, _T("<DIR>"));
         }
             iSizeFormat = -17;
             _tcscpy(szSize, _T("<DIR>"));
         }
index d55dff9..8f2af74 100644 (file)
@@ -7,15 +7,20 @@
 #define _CRT_SECURE_NO_DEPRECATE
 #endif /*_MSC_VER */
 
 #define _CRT_SECURE_NO_DEPRECATE
 #endif /*_MSC_VER */
 
+#include <stdio.h>
+#include <stdarg.h>
 #include <stdlib.h>
 #include <malloc.h>
 #include <stdlib.h>
 #include <malloc.h>
+#include <tchar.h>
 
 #define WIN32_NO_STATUS
 
 #define WIN32_NO_STATUS
-#include <stdarg.h>
 #include <windef.h>
 #include <winbase.h>
 #include <windef.h>
 #include <winbase.h>
+#include <winnls.h>
+#include <winreg.h>
+#include <winuser.h>
+#include <wincon.h>
 #include <shellapi.h>
 #include <shellapi.h>
-#include <stdio.h>
 
 #define NTOS_MODE_USER
 #include <ndk/rtlfuncs.h>
 
 #define NTOS_MODE_USER
 #include <ndk/rtlfuncs.h>
index b45d9da..0304b52 100644 (file)
 
 #ifdef INCLUDE_CMD_SCREEN
 
 
 #ifdef INCLUDE_CMD_SCREEN
 
-
-INT CommandScreen (LPTSTR param)
+INT CommandScreen(LPTSTR param)
 {
 {
-    SHORT x,y;
+    SHORT x, y;
+    SHORT maxx, maxy;
     BOOL bSkipText = FALSE;
 
     BOOL bSkipText = FALSE;
 
-    if (_tcsncmp (param, _T("/?"), 2) == 0)
+    if (_tcsncmp(param, _T("/?"), 2) == 0)
     {
         ConOutResPaging(TRUE,STRING_SCREEN_HELP);
         return 0;
     {
         ConOutResPaging(TRUE,STRING_SCREEN_HELP);
         return 0;
@@ -29,72 +29,71 @@ INT CommandScreen (LPTSTR param)
 
     nErrorLevel = 0;
 
 
     nErrorLevel = 0;
 
-    //get row
-    while(_istspace(*param))
+    /* Retrieve the screen dimensions */
+    GetScreenSize(&maxx, &maxy);
+
+    /* Get row */
+    while (_istspace(*param))
         param++;
 
         param++;
 
-    if (!(*param))
+    if (!*param)
     {
     {
-        error_req_param_missing ();
+        error_req_param_missing();
         return 1;
     }
 
     y = _ttoi(param);
         return 1;
     }
 
     y = _ttoi(param);
-    if (y<0 || y>(maxy-1))
+    if (y < 0 || y > (maxy-1))
     {
         ConOutResPuts(STRING_SCREEN_ROW);
     {
         ConOutResPuts(STRING_SCREEN_ROW);
-
         return 1;
     }
 
         return 1;
     }
 
-    //get col
-    if (!(param = _tcschr(param,_T(' '))))
+    /* Get column */
+    if (!(param = _tcschr(param, _T(' '))))
     {
     {
-        error_req_param_missing ();
+        error_req_param_missing();
         return 1;
     }
 
         return 1;
     }
 
-    while(_istspace(*param))
+    while (_istspace(*param))
         param++;
 
         param++;
 
-    if (!(*param))
+    if (!*param)
     {
     {
-        error_req_param_missing ();
+        error_req_param_missing();
         return 1;
     }
 
     x = _ttoi(param);
         return 1;
     }
 
     x = _ttoi(param);
-    if (x<0 || x>(maxx-1))
+    if (x < 0 || x > (maxx-1))
     {
         ConErrResPuts(STRING_SCREEN_COL);
         return 1;
     }
 
     {
         ConErrResPuts(STRING_SCREEN_COL);
         return 1;
     }
 
-    //get text
-    if (!(param = _tcschr(param,_T(' '))))
+    /* Get text */
+    if (!(param = _tcschr(param, _T(' '))))
     {
         bSkipText = TRUE;
     }
     else
     {
     {
         bSkipText = TRUE;
     }
     else
     {
-        while(_istspace(*param))
+        while (_istspace(*param))
             param++;
 
             param++;
 
-        if (!(*param))
-        {
+        if (!*param)
             bSkipText = TRUE;
             bSkipText = TRUE;
-        }
     }
 
     bIgnoreEcho = TRUE;
 
     if (bSkipText)
     }
 
     bIgnoreEcho = TRUE;
 
     if (bSkipText)
-        x=0;
-
+        x = 0;
 
 
-    SetCursorXY(x,y);
+    SetCursorXY(x, y);
 
 
-    if (!(bSkipText))
+    if (!bSkipText)
         ConOutPuts(param);
 
     return 0;
         ConOutPuts(param);
 
     return 0;
index de1b78f..f13bd8e 100644 (file)
@@ -45,7 +45,7 @@ INT cmd_start (LPTSTR Rest)
     BOOL bWait = FALSE;
     BOOL bBat  = FALSE;
     BOOL bCreate = FALSE;
     BOOL bWait = FALSE;
     BOOL bBat  = FALSE;
     BOOL bCreate = FALSE;
-    TCHAR szFullCmdLine [CMDLINE_LENGTH];
+    TCHAR szFullCmdLine[CMDLINE_LENGTH];
     PROCESS_INFORMATION prci;
     STARTUPINFO stui;
 #ifdef UNICODE
     PROCESS_INFORMATION prci;
     STARTUPINFO stui;
 #ifdef UNICODE
@@ -303,6 +303,7 @@ INT cmd_start (LPTSTR Rest)
             nErrorLevel = (INT)dwExitCode;
         }
         CloseHandle (prci.hProcess);
             nErrorLevel = (INT)dwExitCode;
         }
         CloseHandle (prci.hProcess);
+
         /* Get New code page if it has change */
         InputCodePage= GetConsoleCP();
         OutputCodePage = GetConsoleOutputCP();
         /* Get New code page if it has change */
         InputCodePage= GetConsoleCP();
         OutputCodePage = GetConsoleOutputCP();