1 // Copyright (c) 2011-2015 Ryan Prichard
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 #include "../shared/StringUtil.h"
27 #include "../shared/WindowsVersion.h"
28 #include "../shared/WinptyAssert.h"
29 #include "../shared/WinptyVersion.h"
32 #include "AgentCreateDesktop.h"
33 #include "DebugShowInput.h"
36 "Usage: %ls controlPipeName flags mouseMode cols rows\n"
37 "Usage: %ls controlPipeName --create-desktop\n"
39 "Ordinarily, this program is launched by winpty.dll and is not directly\n"
40 "useful to winpty users. However, it also has options intended for\n"
43 "Usage: %ls [options]\n"
46 " --show-input [--with-mouse] [--escape-input]\n"
47 " Dump INPUT_RECORDs from the console input buffer\n"
48 " --with-mouse: Include MOUSE_INPUT_RECORDs in the dump\n"
50 " --escape-input: Direct the new Windows 10 console to use\n"
51 " escape sequences for input\n"
52 " --version Print the winpty version\n";
54 static uint64_t winpty_atoi64(const char *str) {
55 return strtoll(str, NULL, 10);
62 // Technically, we should free the CommandLineToArgvW return value using
63 // a single call to LocalFree, but the call will never actually happen in
66 wchar_t *cmdline = GetCommandLineW();
67 ASSERT(cmdline != nullptr && "GetCommandLineW returned NULL");
68 wchar_t **argv = CommandLineToArgvW(cmdline, &argc);
69 ASSERT(argv != nullptr && "CommandLineToArgvW returned NULL");
71 if (argc == 2 && !wcscmp(argv[1], L"--version")) {
72 dumpVersionToStdout();
76 if (argc >= 2 && !wcscmp(argv[1], L"--show-input")) {
77 bool withMouse = false;
78 bool escapeInput = false;
79 for (int i = 2; i < argc; ++i) {
80 if (!wcscmp(argv[i], L"--with-mouse")) {
82 } else if (!wcscmp(argv[i], L"--escape-input")) {
85 fprintf(stderr, "Unrecognized --show-input option: %ls\n",
90 debugShowInput(withMouse, escapeInput);
94 if (argc == 3 && !wcscmp(argv[2], L"--create-desktop")) {
95 handleCreateDesktop(argv[1]);
100 fprintf(stderr, USAGE, argv[0], argv[0], argv[0]);
105 winpty_atoi64(utf8FromWide(argv[2]).c_str()),
106 atoi(utf8FromWide(argv[3]).c_str()),
107 atoi(utf8FromWide(argv[4]).c_str()),
108 atoi(utf8FromWide(argv[5]).c_str()));
111 // The Agent destructor shouldn't return, but if it does, exit