From: Alfred Agrell floating@muncher.se
--- programs/cmd/builtins.c | 96 +++++++++++++++++++++++++++++++++++++++++ programs/cmd/cmd.rc | 15 +++++++ programs/cmd/wcmd.h | 67 +++++++++++++++------------- programs/cmd/wcmdmain.c | 3 ++ 4 files changed, 150 insertions(+), 31 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index d7c5090d17f..76abaff5138 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -58,6 +58,7 @@ const WCHAR inbuilt[][10] = { L"LABEL", L"MD", L"MKDIR", + L"MODE", L"MOVE", L"PATH", L"PAUSE", @@ -3417,6 +3418,101 @@ 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) +{ + CONSOLE_SCREEN_BUFFER_INFO inf; + UINT keybd_speed, keybd_delay; + RETURN_CODE return_code = 0; + WCHAR buf[1024]; + HANDLE console; + WCHAR *num_end; + WCHAR *argN; + BOOL valid; + int argno; + + console = CreateFileW(L"CONOUT$", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (console == INVALID_HANDLE_VALUE || !GetConsoleScreenBufferInfo(console, &inf)) + { + WCMD_output_stderr(WCMD_LoadMessage(WCMD_MODE_NODEVICE), L"CON"); + return_code = -1; + goto out; + } + SystemParametersInfoA(SPI_GETKEYBOARDSPEED, 0, &keybd_speed, 0); + SystemParametersInfoA(SPI_GETKEYBOARDDELAY, 0, &keybd_delay, 0); + + if (*args) + { + for (argno = 1; ; argno++) + { + WCHAR *arg = WCMD_parameter_with_delims(args, argno, &argN, FALSE, FALSE, L" "); + if (!*arg) break; + + valid = FALSE; + if (!wcsnicmp(arg, L"COLS=", 5)) + { + inf.dwSize.X = wcstoul(arg+5, &num_end, 10); + if (!*num_end) + valid = TRUE; + } + else if (!wcsnicmp(arg, L"LINES=", 6)) + { + inf.dwSize.Y = wcstoul(arg+6, &num_end, 10); + if (!*num_end) + valid = TRUE; + } + if (!valid) + { + WCMD_output_stderr(WCMD_LoadMessage(WCMD_ARGERR)); + return_code = -1; + goto out; + } + } + if (!SetConsoleScreenBufferSize(console, inf.dwSize)) + { + WCMD_output_stderr(WCMD_LoadMessage(WCMD_MODE_CON_CANTRESIZE)); + return_code = -1; + } + } + else + { + wsprintfW(buf, WCMD_LoadMessage(WCMD_MODE_CON_OUTPUT), inf.dwSize.Y, inf.dwSize.X, keybd_speed, keybd_delay, GetConsoleCP()); + WCMD_output_asis(buf); + } +out: + if (console != INVALID_HANDLE_VALUE) + CloseHandle(console); + return return_code; +} + +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; +} + /**************************************************************************** * WCMD_type * diff --git a/programs/cmd/cmd.rc b/programs/cmd/cmd.rc index 90091090e11..d032246ff50 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" @@ -406,4 +409,16 @@ Enter HELP <command> for further information on any of the above commands.\n" WCMD_BADTOKEN, "Syntax error: unexpected %1\n" WCMD_ENDOFLINE, "End of line" WCMD_ENDOFFILE, "End of file" + WCMD_MODE_NODEVICE, "Device %1 not found\n" + WCMD_MODE_CON_CANTRESIZE, "Can't set the requested size\n" + WCMD_MODE_CON_OUTPUT, +"\n\ +Status for device CON:\n\ +----------------------\n\ + Lines: %u\n\ + Columns: %u\n\ + Keyboard rate: %u\n\ + Keyboard delay: %u\n\ + Code page: %u\n\ +\n" } diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index 225ebd44310..a6fca3e9880 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -168,6 +168,7 @@ BOOL WCMD_get_fullpath(const WCHAR *, SIZE_T, WCHAR *, WCHAR **); RETURN_CODE WCMD_give_help(WCHAR *args); RETURN_CODE WCMD_goto(void); RETURN_CODE WCMD_label(void); +RETURN_CODE WCMD_mode(WCHAR *); void WCMD_leave_paged_mode(void); RETURN_CODE WCMD_more(WCHAR *); RETURN_CODE WCMD_move (void); @@ -364,39 +365,40 @@ static inline BOOL WCMD_is_in_context(const WCHAR *ext) #define WCMD_LABEL 15 #define WCMD_MD 16 #define WCMD_MKDIR 17 -#define WCMD_MOVE 18 -#define WCMD_PATH 19 -#define WCMD_PAUSE 20 -#define WCMD_PROMPT 21 -#define WCMD_REM 22 -#define WCMD_REN 23 -#define WCMD_RENAME 24 -#define WCMD_RD 25 -#define WCMD_RMDIR 26 -#define WCMD_SET 27 -#define WCMD_SHIFT 28 -#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 18 +#define WCMD_MOVE 19 +#define WCMD_PATH 20 +#define WCMD_PAUSE 21 +#define WCMD_PROMPT 22 +#define WCMD_REM 23 +#define WCMD_REN 24 +#define WCMD_RENAME 25 +#define WCMD_RD 26 +#define WCMD_RMDIR 27 +#define WCMD_SET 28 +#define WCMD_SHIFT 29 +#define WCMD_START 30 +#define WCMD_TIME 31 +#define WCMD_TITLE 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[]; @@ -452,3 +454,6 @@ extern WCHAR version_string[]; #define WCMD_BADTOKEN 1047 #define WCMD_ENDOFLINE 1048 #define WCMD_ENDOFFILE 1049 +#define WCMD_MODE_NODEVICE 1050 +#define WCMD_MODE_CON_CANTRESIZE 1051 +#define WCMD_MODE_CON_OUTPUT 1052 diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 77f1112be23..505de1ebd9f 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -1748,6 +1748,9 @@ RETURN_CODE WCMD_run_builtin_command(int cmd_index, WCHAR *cmd) case WCMD_MKDIR: return_code = WCMD_create_dir(parms_start); break; + case WCMD_MODE: + return_code = WCMD_mode(parms_start); + break; case WCMD_MOVE: return_code = WCMD_move(); break;