From: Alfred Agrell floating@muncher.se
--- programs/cmd/builtins.c | 91 +++++++++++++++++++++++++++++++++++++++++ programs/cmd/cmd.rc | 3 ++ programs/cmd/wcmd.h | 36 ++++++++-------- programs/cmd/wcmdmain.c | 3 ++ 4 files changed, 116 insertions(+), 17 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index d7c5090d17f..502cfe9ec38 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -72,6 +72,7 @@ const WCHAR inbuilt[][10] = { L"START", L"TIME", L"TITLE", + L"MODE", L"TYPE", L"VERIFY", L"VER", @@ -3417,6 +3418,96 @@ RETURN_CODE WCMD_title(const WCHAR *args) return NO_ERROR; }
+/**************************************************************************** + * WCMD_mode + * + * Get or set the console size + */ +static RETURN_CODE WCMD_mode_con(WCHAR *args); + +RETURN_CODE WCMD_mode(WCHAR *args) +{ + WCHAR *device = WCMD_parameter(args, 0, NULL, FALSE, FALSE); + + if (!*device) + { + /* just print everything (which is CON only for now) */ + WCMD_mode_con(args); + errorlevel = 0; + } + else if (!wcsicmp(device, L"CON")) + { + errorlevel = WCMD_mode_con(args); + } + else + { + WCMD_output(L"Invalid parameter - %1\r\n", device); + errorlevel = -1; + } + return errorlevel; +} + +static RETURN_CODE WCMD_mode_con(WCHAR *args) +{ + CONSOLE_SCREEN_BUFFER_INFO inf; + UINT keybd_speed, keybd_delay; + BOOL changed = FALSE; + WCHAR buf[1024]; + HANDLE console; + WCHAR *argN; + int argno; + + errorlevel = 0; + console = CreateFileW(L"CONOUT$", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + SystemParametersInfoA(SPI_GETKEYBOARDSPEED, 0, &keybd_speed, 0); + SystemParametersInfoA(SPI_GETKEYBOARDDELAY, 0, &keybd_delay, 0); + GetConsoleScreenBufferInfo(console, &inf); + + for (argno = 1; ; argno++) + { + WCHAR *arg = WCMD_parameter_with_delims(args, argno, &argN, FALSE, FALSE, L" "); + if (!*arg) break; + + if (!wcsnicmp(arg, L"COLS=", 5) && (inf.dwSize.X = wcstoul(arg+5, NULL, 10))) + changed = TRUE; + else if (!wcsnicmp(arg, L"LINES=", 6) && (inf.dwSize.Y = wcstoul(arg+6, NULL, 10))) + changed = TRUE; + else + { + WCMD_output(L"Invalid parameter - %1\r\n", arg); + errorlevel = -1; + } + } + + if (changed) + { + if (!SetConsoleScreenBufferSize(console, inf.dwSize)) + { + WCMD_output_asis(L"The screen cannot be set to the number of lines and columns specified.\r\n"); + errorlevel = -1; + } + } + else if (errorlevel == 0) + { + wsprintfW(buf, + L"\r\n" + L"Status for device CON:\r\n" + L"----------------------\r\n" + L" Lines: %u\r\n" + L" Columns: %u\r\n" + L" Keyboard rate: %u\r\n" + L" Keyboard delay: %u\r\n" + L" Code page: %u\r\n" + L"\r\n", + inf.dwSize.Y, inf.dwSize.X, keybd_speed, keybd_delay, GetConsoleCP()); + WCMD_output_asis(buf); + } + CloseHandle(console); + return errorlevel; +} + /**************************************************************************** * WCMD_type * diff --git a/programs/cmd/cmd.rc b/programs/cmd/cmd.rc index 90091090e11..83598bdc4d7 100644 --- a/programs/cmd/cmd.rc +++ b/programs/cmd/cmd.rc @@ -235,6 +235,9 @@ called from the command line.\n" WCMD_TITLE, "TITLE <string> sets the window title for the cmd window.\n"
+ WCMD_MODE, +"MODE tells the cmd window size.\n" + WCMD_TYPE, "TYPE <filename> copies <filename> to the console device (or elsewhere if\n\ redirected). No check is made that the file is readable text.\n" diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index 225ebd44310..86d8cb40921 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -192,6 +192,7 @@ RETURN_CODE WCMD_setshow_time(void); RETURN_CODE WCMD_shift(const WCHAR *args); RETURN_CODE WCMD_start(WCHAR *args); RETURN_CODE WCMD_title(const WCHAR *); +RETURN_CODE WCMD_mode(WCHAR *); RETURN_CODE WCMD_type(WCHAR *); RETURN_CODE WCMD_verify(void); RETURN_CODE WCMD_version(void); @@ -378,25 +379,26 @@ static inline BOOL WCMD_is_in_context(const WCHAR *ext) #define WCMD_START 29 #define WCMD_TIME 30 #define WCMD_TITLE 31 -#define WCMD_TYPE 32 -#define WCMD_VERIFY 33 -#define WCMD_VER 34 -#define WCMD_VOL 35 - -#define WCMD_ENDLOCAL 36 -#define WCMD_SETLOCAL 37 -#define WCMD_PUSHD 38 -#define WCMD_POPD 39 -#define WCMD_ASSOC 40 -#define WCMD_COLOR 41 -#define WCMD_FTYPE 42 -#define WCMD_MORE 43 -#define WCMD_CHOICE 44 -#define WCMD_MKLINK 45 -#define WCMD_CHGDRIVE 46 +#define WCMD_MODE 32 +#define WCMD_TYPE 33 +#define WCMD_VERIFY 34 +#define WCMD_VER 35 +#define WCMD_VOL 36 + +#define WCMD_ENDLOCAL 37 +#define WCMD_SETLOCAL 38 +#define WCMD_PUSHD 39 +#define WCMD_POPD 40 +#define WCMD_ASSOC 41 +#define WCMD_COLOR 42 +#define WCMD_FTYPE 43 +#define WCMD_MORE 44 +#define WCMD_CHOICE 45 +#define WCMD_MKLINK 46 +#define WCMD_CHGDRIVE 47
/* Must be last in list */ -#define WCMD_EXIT 47 +#define WCMD_EXIT 48
/* Some standard messages */ extern WCHAR anykey[]; diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 77f1112be23..792e35689e8 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -1789,6 +1789,9 @@ RETURN_CODE WCMD_run_builtin_command(int cmd_index, WCHAR *cmd) case WCMD_TIME: return_code = WCMD_setshow_time(); break; + case WCMD_MODE: + return_code = WCMD_mode(parms_start); + break; case WCMD_TITLE: return_code = WCMD_title(parms_start); break;