1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-22 14:39:24 -05:00

Merge assorted pterm fixes from 'pre-0.77'.

This commit is contained in:
Simon Tatham 2022-05-21 10:59:31 +01:00
commit 751671d73a
5 changed files with 56 additions and 13 deletions

View File

@ -759,11 +759,13 @@ int cmdline_process_param(const char *p, char *value,
if (!strcmp(p, "-4") || !strcmp(p, "-ipv4")) { if (!strcmp(p, "-4") || !strcmp(p, "-ipv4")) {
RETURN(1); RETURN(1);
UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
SAVEABLE(1); SAVEABLE(1);
conf_set_int(conf, CONF_addressfamily, ADDRTYPE_IPV4); conf_set_int(conf, CONF_addressfamily, ADDRTYPE_IPV4);
} }
if (!strcmp(p, "-6") || !strcmp(p, "-ipv6")) { if (!strcmp(p, "-6") || !strcmp(p, "-ipv6")) {
RETURN(1); RETURN(1);
UNAVAILABLE_IN(TOOLTYPE_NONNETWORK);
SAVEABLE(1); SAVEABLE(1);
conf_set_int(conf, CONF_addressfamily, ADDRTYPE_IPV6); conf_set_int(conf, CONF_addressfamily, ADDRTYPE_IPV6);
} }

View File

@ -25,6 +25,27 @@ struct ConPTY {
Backend backend; Backend backend;
}; };
DECL_WINDOWS_FUNCTION(static, HRESULT, CreatePseudoConsole,
(COORD, HANDLE, HANDLE, DWORD, HPCON *));
DECL_WINDOWS_FUNCTION(static, void, ClosePseudoConsole, (HPCON));
DECL_WINDOWS_FUNCTION(static, HRESULT, ResizePseudoConsole, (HPCON, COORD));
static bool init_conpty_api(void)
{
static bool tried = false;
if (!tried) {
tried = true;
HMODULE kernel32_module = load_system32_dll("kernel32.dll");
GET_WINDOWS_FUNCTION(kernel32_module, CreatePseudoConsole);
GET_WINDOWS_FUNCTION(kernel32_module, ClosePseudoConsole);
GET_WINDOWS_FUNCTION(kernel32_module, ResizePseudoConsole);
}
return (p_CreatePseudoConsole != NULL &&
p_ClosePseudoConsole != NULL &&
p_ResizePseudoConsole != NULL);
}
static void conpty_terminate(ConPTY *conpty) static void conpty_terminate(ConPTY *conpty)
{ {
if (conpty->out) { if (conpty->out) {
@ -49,7 +70,7 @@ static void conpty_terminate(ConPTY *conpty)
conpty->hprocess = INVALID_HANDLE_VALUE; conpty->hprocess = INVALID_HANDLE_VALUE;
} }
if (conpty->pseudoconsole != INVALID_HANDLE_VALUE) { if (conpty->pseudoconsole != INVALID_HANDLE_VALUE) {
ClosePseudoConsole(conpty->pseudoconsole); p_ClosePseudoConsole(conpty->pseudoconsole);
conpty->pseudoconsole = INVALID_HANDLE_VALUE; conpty->pseudoconsole = INVALID_HANDLE_VALUE;
} }
} }
@ -78,7 +99,7 @@ static void conpty_process_wait_callback(void *vctx)
* as things clean themselves up. * as things clean themselves up.
*/ */
if (conpty->pseudoconsole != INVALID_HANDLE_VALUE) { if (conpty->pseudoconsole != INVALID_HANDLE_VALUE) {
ClosePseudoConsole(conpty->pseudoconsole); p_ClosePseudoConsole(conpty->pseudoconsole);
conpty->pseudoconsole = INVALID_HANDLE_VALUE; conpty->pseudoconsole = INVALID_HANDLE_VALUE;
} }
} }
@ -158,6 +179,12 @@ static char *conpty_init(const BackendVtable *vt, Seat *seat,
STARTUPINFOEX si; STARTUPINFOEX si;
memset(&si, 0, sizeof(si)); memset(&si, 0, sizeof(si));
if (!init_conpty_api()) {
err = dupprintf("Pseudo-console API is not available on this "
"Windows system");
goto out;
}
if (!CreatePipe(&in_r, &in_w, NULL, 0)) { if (!CreatePipe(&in_r, &in_w, NULL, 0)) {
err = dupprintf("CreatePipe: %s", win_strerror(GetLastError())); err = dupprintf("CreatePipe: %s", win_strerror(GetLastError()));
goto out; goto out;
@ -171,7 +198,7 @@ static char *conpty_init(const BackendVtable *vt, Seat *seat,
size.X = conf_get_int(conf, CONF_width); size.X = conf_get_int(conf, CONF_width);
size.Y = conf_get_int(conf, CONF_height); size.Y = conf_get_int(conf, CONF_height);
HRESULT result = CreatePseudoConsole(size, in_r, out_w, 0, &pcon); HRESULT result = p_CreatePseudoConsole(size, in_r, out_w, 0, &pcon);
if (FAILED(result)) { if (FAILED(result)) {
if (HRESULT_FACILITY(result) == FACILITY_WIN32) if (HRESULT_FACILITY(result) == FACILITY_WIN32)
err = dupprintf("CreatePseudoConsole: %s", err = dupprintf("CreatePseudoConsole: %s",
@ -190,7 +217,7 @@ static char *conpty_init(const BackendVtable *vt, Seat *seat,
si.StartupInfo.cb = sizeof(si); si.StartupInfo.cb = sizeof(si);
size_t attrsize = 0; SIZE_T attrsize = 0;
InitializeProcThreadAttributeList(NULL, 1, 0, &attrsize); InitializeProcThreadAttributeList(NULL, 1, 0, &attrsize);
si.lpAttributeList = smalloc(attrsize); si.lpAttributeList = smalloc(attrsize);
if (!InitializeProcThreadAttributeList( if (!InitializeProcThreadAttributeList(
@ -271,7 +298,7 @@ static char *conpty_init(const BackendVtable *vt, Seat *seat,
if (out_w != INVALID_HANDLE_VALUE) if (out_w != INVALID_HANDLE_VALUE)
CloseHandle(out_w); CloseHandle(out_w);
if (pcon_needs_cleanup) if (pcon_needs_cleanup)
ClosePseudoConsole(pcon); p_ClosePseudoConsole(pcon);
sfree(si.lpAttributeList); sfree(si.lpAttributeList);
return err; return err;
} }
@ -311,7 +338,7 @@ static void conpty_size(Backend *be, int width, int height)
COORD size; COORD size;
size.X = width; size.X = width;
size.Y = height; size.Y = height;
ResizePseudoConsole(conpty->pseudoconsole, size); p_ResizePseudoConsole(conpty->pseudoconsole, size);
} }
static void conpty_special(Backend *be, SessionSpecialCode code, int arg) static void conpty_special(Backend *be, SessionSpecialCode code, int arg)

View File

@ -1,6 +1,10 @@
#include "putty.h" #include "putty.h"
#include "storage.h" #include "storage.h"
const unsigned cmdline_tooltype =
TOOLTYPE_NONNETWORK |
TOOLTYPE_NO_VERBOSE_OPTION;
void gui_term_process_cmdline(Conf *conf, char *cmdline) void gui_term_process_cmdline(Conf *conf, char *cmdline)
{ {
do_defaults(NULL, conf); do_defaults(NULL, conf);
@ -16,8 +20,16 @@ void gui_term_process_cmdline(Conf *conf, char *cmdline)
split_into_argv(cmdline, &argc, &argv, &argstart); split_into_argv(cmdline, &argc, &argv, &argstart);
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
const char *arg = argv[i]; char *arg = argv[i];
if (!strcmp(arg, "-e")) { int retd = cmdline_process_param(
arg, i+1<argc?argv[i+1]:NULL, 1, conf);
if (retd == -2) {
cmdline_error("option \"%s\" requires an argument", arg);
} else if (retd == 2) {
i++; /* skip next argument */
} else if (retd == 1) {
continue; /* nothing further needs doing */
} else if (!strcmp(arg, "-e")) {
if (i+1 < argc) { if (i+1 < argc) {
/* The command to execute is taken to be the unparsed /* The command to execute is taken to be the unparsed
* version of the whole remainder of the command line. */ * version of the whole remainder of the command line. */
@ -33,6 +45,8 @@ void gui_term_process_cmdline(Conf *conf, char *cmdline)
} }
} }
cmdline_run_saved(conf);
conf_set_int(conf, CONF_sharrow_type, SHARROW_BITMAP); conf_set_int(conf, CONF_sharrow_type, SHARROW_BITMAP);
} }

View File

@ -6,6 +6,11 @@ extern const char *dialog_box_demo_screenshot_filename;
static strbuf *demo_terminal_data = NULL; static strbuf *demo_terminal_data = NULL;
static const char *terminal_demo_screenshot_filename; static const char *terminal_demo_screenshot_filename;
const unsigned cmdline_tooltype =
TOOLTYPE_HOST_ARG |
TOOLTYPE_PORT_ARG |
TOOLTYPE_NO_VERBOSE_OPTION;
void gui_term_process_cmdline(Conf *conf, char *cmdline) void gui_term_process_cmdline(Conf *conf, char *cmdline)
{ {
char *p; char *p;

View File

@ -515,11 +515,6 @@ char *terminal_window_class_a(void)
return classname; return classname;
} }
const unsigned cmdline_tooltype =
TOOLTYPE_HOST_ARG |
TOOLTYPE_PORT_ARG |
TOOLTYPE_NO_VERBOSE_OPTION;
HINSTANCE hinst; HINSTANCE hinst;
int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)