int main()

in src/agent/main.cc [58:114]


int main() {
    dumpWindowsVersion();
    dumpVersionToTrace();

    // Technically, we should free the CommandLineToArgvW return value using
    // a single call to LocalFree, but the call will never actually happen in
    // the normal case.
    int argc = 0;
    wchar_t *cmdline = GetCommandLineW();
    ASSERT(cmdline != nullptr && "GetCommandLineW returned NULL");
    wchar_t **argv = CommandLineToArgvW(cmdline, &argc);
    ASSERT(argv != nullptr && "CommandLineToArgvW returned NULL");

    if (argc == 2 && !wcscmp(argv[1], L"--version")) {
        dumpVersionToStdout();
        return 0;
    }

    if (argc >= 2 && !wcscmp(argv[1], L"--show-input")) {
        bool withMouse = false;
        bool escapeInput = false;
        for (int i = 2; i < argc; ++i) {
            if (!wcscmp(argv[i], L"--with-mouse")) {
                withMouse = true;
            } else if (!wcscmp(argv[i], L"--escape-input")) {
                escapeInput = true;
            } else {
                fprintf(stderr, "Unrecognized --show-input option: %ls\n",
                    argv[i]);
                return 1;
            }
        }
        debugShowInput(withMouse, escapeInput);
        return 0;
    }

    if (argc == 3 && !wcscmp(argv[2], L"--create-desktop")) {
        handleCreateDesktop(argv[1]);
        return 0;
    }

    if (argc != 6) {
        fprintf(stderr, USAGE, argv[0], argv[0], argv[0]);
        return 1;
    }

    Agent agent(argv[1],
                winpty_atoi64(utf8FromWide(argv[2]).c_str()),
                atoi(utf8FromWide(argv[3]).c_str()),
                atoi(utf8FromWide(argv[4]).c_str()),
                atoi(utf8FromWide(argv[5]).c_str()));
    agent.run();

    // The Agent destructor shouldn't return, but if it does, exit
    // unsuccessfully.
    return 1;
}