Author: hbelusca Date: Sat Sep 30 21:37:34 2017 New Revision: 76009
URL: http://svn.reactos.org/svn/reactos?rev=76009&view=rev Log: [CMD]: Small refactoring: - 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.
Modified: trunk/reactos/base/shell/cmd/cmd.c trunk/reactos/base/shell/cmd/cmd.h trunk/reactos/base/shell/cmd/console.c trunk/reactos/base/shell/cmd/console.h trunk/reactos/base/shell/cmd/dir.c trunk/reactos/base/shell/cmd/precomp.h trunk/reactos/base/shell/cmd/screen.c trunk/reactos/base/shell/cmd/start.c
Modified: trunk/reactos/base/shell/cmd/cmd.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=76... ============================================================================== --- trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] Sat Sep 30 21:37:34 2017 @@ -311,10 +311,11 @@ { 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; - TCHAR szFullCmdLine [CMDLINE_LENGTH]; + TCHAR szFullCmdLine[CMDLINE_LENGTH];
TRACE ("Execute: '%s' '%s'\n", debugstr_aw(First), debugstr_aw(Rest));
@@ -1762,33 +1763,6 @@ }
-#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 */ @@ -1997,7 +1971,6 @@ if (IsExistingFile(_T("cmdexit.bat"))) { ConErrResPuts(STRING_CMD_ERROR5); - ParseCommandLine(_T("cmdexit.bat")); } else if (IsExistingFile(_T("\cmdexit.bat")))
Modified: trunk/reactos/base/shell/cmd/cmd.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.h?rev=76... ============================================================================== --- trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] Sat Sep 30 21:37:34 2017 @@ -25,12 +25,6 @@
#include <config.h>
-#include <winnls.h> -#include <winreg.h> -#include <winuser.h> -#include <wincon.h> -#include <tchar.h> - #include "cmdver.h" #include "cmddbg.h"
@@ -43,7 +37,6 @@ #define D_ON _T("on") #define D_OFF _T("off")
- /* command line buffer length */ #define CMDLINE_LENGTH 8192
@@ -51,7 +44,6 @@ #define BUFF_SIZE 16384
/* Global variables */ -extern HANDLE hIn; extern LPTSTR lpOriginalEnvironment; extern WORD wColor; extern WORD wDefColor; @@ -62,8 +54,6 @@ extern BOOL bEnableExtensions; extern BOOL bDelayedExpansion; extern INT nErrorLevel; -extern SHORT maxx; -extern SHORT maxy; extern BOOL bUnicodeOutput;
Modified: trunk/reactos/base/shell/cmd/console.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/console.c?re... ============================================================================== --- trunk/reactos/base/shell/cmd/console.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/console.c [iso-8859-1] Sat Sep 30 21:37:34 2017 @@ -507,6 +507,33 @@
+#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 */
Modified: trunk/reactos/base/shell/cmd/console.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/console.h?re... ============================================================================== --- trunk/reactos/base/shell/cmd/console.h [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/console.h [iso-8859-1] Sat Sep 30 21:37:34 2017 @@ -72,6 +72,11 @@ VOID SetCursorType (BOOL, BOOL);
+#ifdef INCLUDE_CMD_COLOR +BOOL ConGetDefaultAttributes(PWORD pwDefAttr); +#endif + + BOOL ConSetTitle(IN LPCTSTR lpConsoleTitle);
#ifdef INCLUDE_CMD_BEEP
Modified: trunk/reactos/base/shell/cmd/dir.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/dir.c?rev=76... ============================================================================== --- trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/dir.c [iso-8859-1] Sat Sep 30 21:37:34 2017 @@ -1052,7 +1052,7 @@ /* 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>")); }
Modified: trunk/reactos/base/shell/cmd/precomp.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/precomp.h?re... ============================================================================== --- trunk/reactos/base/shell/cmd/precomp.h [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/precomp.h [iso-8859-1] Sat Sep 30 21:37:34 2017 @@ -7,15 +7,20 @@ #define _CRT_SECURE_NO_DEPRECATE #endif /*_MSC_VER */
+#include <stdio.h> +#include <stdarg.h> #include <stdlib.h> #include <malloc.h> +#include <tchar.h>
#define WIN32_NO_STATUS -#include <stdarg.h> #include <windef.h> #include <winbase.h> +#include <winnls.h> +#include <winreg.h> +#include <winuser.h> +#include <wincon.h> #include <shellapi.h> -#include <stdio.h>
#define NTOS_MODE_USER #include <ndk/rtlfuncs.h>
Modified: trunk/reactos/base/shell/cmd/screen.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/screen.c?rev... ============================================================================== --- trunk/reactos/base/shell/cmd/screen.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/screen.c [iso-8859-1] Sat Sep 30 21:37:34 2017 @@ -15,13 +15,13 @@
#ifdef INCLUDE_CMD_SCREEN
- -INT CommandScreen (LPTSTR param) +INT CommandScreen(LPTSTR param) { - SHORT x,y; + SHORT x, y; + SHORT maxx, maxy; BOOL bSkipText = FALSE;
- if (_tcsncmp (param, _T("/?"), 2) == 0) + if (_tcsncmp(param, _T("/?"), 2) == 0) { ConOutResPaging(TRUE,STRING_SCREEN_HELP); return 0; @@ -29,72 +29,71 @@
nErrorLevel = 0;
- //get row - while(_istspace(*param)) + /* Retrieve the screen dimensions */ + GetScreenSize(&maxx, &maxy); + + /* Get row */ + while (_istspace(*param)) param++;
- if (!(*param)) + if (!*param) { - error_req_param_missing (); + error_req_param_missing(); return 1; }
y = _ttoi(param); - if (y<0 || y>(maxy-1)) + if (y < 0 || y > (maxy-1)) { ConOutResPuts(STRING_SCREEN_ROW); - 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; }
- while(_istspace(*param)) + while (_istspace(*param)) param++;
- if (!(*param)) + if (!*param) { - error_req_param_missing (); + error_req_param_missing(); return 1; }
x = _ttoi(param); - if (x<0 || x>(maxx-1)) + if (x < 0 || x > (maxx-1)) { ConErrResPuts(STRING_SCREEN_COL); return 1; }
- //get text - if (!(param = _tcschr(param,_T(' ')))) + /* Get text */ + if (!(param = _tcschr(param, _T(' ')))) { bSkipText = TRUE; } else { - while(_istspace(*param)) + while (_istspace(*param)) param++;
- if (!(*param)) - { + if (!*param) bSkipText = TRUE; - } }
bIgnoreEcho = TRUE;
if (bSkipText) - x=0; + x = 0;
+ SetCursorXY(x, y);
- SetCursorXY(x,y); - - if (!(bSkipText)) + if (!bSkipText) ConOutPuts(param);
return 0;
Modified: trunk/reactos/base/shell/cmd/start.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/start.c?rev=... ============================================================================== --- trunk/reactos/base/shell/cmd/start.c [iso-8859-1] (original) +++ trunk/reactos/base/shell/cmd/start.c [iso-8859-1] Sat Sep 30 21:37:34 2017 @@ -45,7 +45,7 @@ BOOL bWait = FALSE; BOOL bBat = FALSE; BOOL bCreate = FALSE; - TCHAR szFullCmdLine [CMDLINE_LENGTH]; + TCHAR szFullCmdLine[CMDLINE_LENGTH]; PROCESS_INFORMATION prci; STARTUPINFO stui; #ifdef UNICODE @@ -303,6 +303,7 @@ nErrorLevel = (INT)dwExitCode; } CloseHandle (prci.hProcess); + /* Get New code page if it has change */ InputCodePage= GetConsoleCP(); OutputCodePage = GetConsoleOutputCP();