mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 18:07:59 +00:00
f91c3127ad
In the Windows API, there are two places you can get a command line in the form of a single unsplit string. One is via the command-line parameter to WinMain(); the other is by calling GetCommandLine(). But the two have different semantics: the WinMain command line string is only the part after the program name, whereas GetCommandLine() returns the full command line _including_ the program name. PuTTY has never yet had to parse the full output of GetCommandLine, but I have plans that will involve it beginning to do so. So I need to make sure the utility function split_into_argv() can handle it. This is not trivial because the quoting convention is different for the program name than for everything else. In the program's normal arguments, parsed by the C library startup code, the convention is that backslashes are special when they appear before a double quote, because that's how you write a literal double quote. But in the program name, backslashes are _never_ special, because that's how CreateProcess parses the program name at the start of the command line, and the C library must follow suit in order to correctly identify where the program name ends and the arguments begin. In particular, consider a command line such as this: "C:\Program Files\Foo\"foo.exe "hello \"world\"" The \" in the middle of the program name must be treated as a literal backslash, followed by a non-literal double quote which matches the one at the start of the string and causes the space in 'Program Files' to be treated as part of the pathname. But the same \" when it appears in the subsequent argument is treated as an escaped double quote, and turns into a literal " in the argument string. This commit adds support for this special initial-word handling in split_into_argv(), via an extra boolean argument indicating whether to turn that mode on. However, all existing call sites set the flag to false, because the new mode isn't needed _yet_. So there should be no functional change.
66 lines
1.9 KiB
C
66 lines
1.9 KiB
C
#include "putty.h"
|
|
#include "storage.h"
|
|
|
|
const unsigned cmdline_tooltype =
|
|
TOOLTYPE_NONNETWORK |
|
|
TOOLTYPE_NO_VERBOSE_OPTION;
|
|
|
|
void gui_term_process_cmdline(Conf *conf, char *cmdline)
|
|
{
|
|
do_defaults(NULL, conf);
|
|
conf_set_str(conf, CONF_remote_cmd, "");
|
|
|
|
cmdline = handle_restrict_acl_cmdline_prefix(cmdline);
|
|
if (handle_special_sessionname_cmdline(cmdline, conf) ||
|
|
handle_special_filemapping_cmdline(cmdline, conf))
|
|
return;
|
|
|
|
int argc;
|
|
char **argv, **argstart;
|
|
split_into_argv(cmdline, false, &argc, &argv, &argstart);
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
char *arg = argv[i];
|
|
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) {
|
|
/* The command to execute is taken to be the unparsed
|
|
* version of the whole remainder of the command line. */
|
|
conf_set_str(conf, CONF_remote_cmd, argstart[i+1]);
|
|
return;
|
|
} else {
|
|
cmdline_error("option \"%s\" requires an argument", arg);
|
|
}
|
|
} else if (arg[0] == '-') {
|
|
cmdline_error("unrecognised option \"%s\"", arg);
|
|
} else {
|
|
cmdline_error("unexpected non-option argument \"%s\"", arg);
|
|
}
|
|
}
|
|
|
|
cmdline_run_saved(conf);
|
|
|
|
conf_set_int(conf, CONF_sharrow_type, SHARROW_BITMAP);
|
|
}
|
|
|
|
const struct BackendVtable *backend_vt_from_conf(Conf *conf)
|
|
{
|
|
return &conpty_backend;
|
|
}
|
|
|
|
const wchar_t *get_app_user_model_id(void)
|
|
{
|
|
return L"SimonTatham.Pterm";
|
|
}
|
|
|
|
void gui_terminal_ready(HWND hwnd, Seat *seat, Backend *backend)
|
|
{
|
|
}
|