diff --git a/cmdline.c b/cmdline.c index fae28e58..d5364ff7 100644 --- a/cmdline.c +++ b/cmdline.c @@ -109,18 +109,6 @@ int cmdline_get_passwd_input(prompts_t *p) return 1; } -/* - * Here we have a flags word which describes the capabilities of - * the particular tool on whose behalf we're running. We will - * refuse certain command-line options if a particular tool - * inherently can't do anything sensible. For example, the file - * transfer tools (psftp, pscp) can't do a great deal with protocol - * selections (ever tried running scp over telnet?) or with port - * forwarding (even if it wasn't a hideously bad idea, they don't - * have the select/poll infrastructure to make them work). - */ -int cmdline_tooltype = 0; - static bool cmdline_check_unavailable(int flag, const char *p) { if (cmdline_tooltype & flag) { diff --git a/nocmdline.c b/nocmdline.c index 05a79baf..e4c6d08f 100644 --- a/nocmdline.c +++ b/nocmdline.c @@ -35,8 +35,3 @@ int cmdline_process_param(const char *p, char *value, { unreachable("cmdline_process_param should never be called"); } - -/* - * This variable will be referred to, so it has to exist. It's ignored. - */ -int cmdline_tooltype = 0; diff --git a/pscp.c b/pscp.c index a8e276c4..240ffff0 100644 --- a/pscp.c +++ b/pscp.c @@ -2218,6 +2218,8 @@ const bool share_can_be_upstream = false; static stdio_sink stderr_ss; static StripCtrlChars *stderr_scc; +const unsigned cmdline_tooltype = TOOLTYPE_FILETRANSFER; + /* * Main program. (Called `psftp_main' because it gets called from * *sftp.c; bit silly, I know, but it had to be called _something_.) @@ -2229,7 +2231,6 @@ int psftp_main(int argc, char *argv[]) default_protocol = PROT_TELNET; - cmdline_tooltype = TOOLTYPE_FILETRANSFER; sk_init(); /* Load Default Settings before doing anything else. */ diff --git a/psftp.c b/psftp.c index 3b4b6eb3..a47599e3 100644 --- a/psftp.c +++ b/psftp.c @@ -2750,6 +2750,8 @@ const bool share_can_be_upstream = false; static stdio_sink stderr_ss; static StripCtrlChars *stderr_scc; +const unsigned cmdline_tooltype = TOOLTYPE_FILETRANSFER; + /* * Main program. Parse arguments etc. */ @@ -2763,7 +2765,6 @@ int psftp_main(int argc, char *argv[]) bool sanitise_stderr = true; char *batchfile = NULL; - cmdline_tooltype = TOOLTYPE_FILETRANSFER; sk_init(); userhost = user = NULL; diff --git a/putty.h b/putty.h index 572d8ab2..041d81bc 100644 --- a/putty.h +++ b/putty.h @@ -1962,15 +1962,34 @@ void cmdline_cleanup(void); int cmdline_get_passwd_input(prompts_t *p); bool cmdline_host_ok(Conf *); bool cmdline_verbose(void); -#define TOOLTYPE_FILETRANSFER 1 -#define TOOLTYPE_NONNETWORK 2 -#define TOOLTYPE_HOST_ARG 4 -#define TOOLTYPE_HOST_ARG_CAN_BE_SESSION 8 -#define TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX 16 -#define TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD 32 -#define TOOLTYPE_PORT_ARG 64 -#define TOOLTYPE_NO_VERBOSE_OPTION 128 -extern int cmdline_tooltype; + +/* + * Here we have a flags word provided by each tool, which describes + * the capabilities of that tool that cmdline.c needs to know about. + * It will refuse certain command-line options if a particular tool + * inherently can't do anything sensible. For example, the file + * transfer tools (psftp, pscp) can't do a great deal with protocol + * selections (ever tried running scp over telnet?) or with port + * forwarding (even if it wasn't a hideously bad idea, they don't have + * the select/poll infrastructure to make them work). + */ +extern const unsigned cmdline_tooltype; + +/* Bit flags for the above */ +#define TOOLTYPE_LIST(X) \ + X(TOOLTYPE_FILETRANSFER) \ + X(TOOLTYPE_NONNETWORK) \ + X(TOOLTYPE_HOST_ARG) \ + X(TOOLTYPE_HOST_ARG_CAN_BE_SESSION) \ + X(TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX) \ + X(TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD) \ + X(TOOLTYPE_PORT_ARG) \ + X(TOOLTYPE_NO_VERBOSE_OPTION) \ + /* end of list */ +#define BITFLAG_INDEX(val) val ## _bitflag_index, +enum { TOOLTYPE_LIST(BITFLAG_INDEX) }; +#define BITFLAG_DEF(val) val = 1U << (val ## _bitflag_index), +enum { TOOLTYPE_LIST(BITFLAG_DEF) }; void cmdline_error(const char *, ...) PRINTF_LIKE(1, 2); diff --git a/unix/uxplink.c b/unix/uxplink.c index af08bcbd..c5b3eb96 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -570,6 +570,12 @@ const bool share_can_be_upstream = true; const bool buildinfo_gtk_relevant = false; +const unsigned cmdline_tooltype = + TOOLTYPE_HOST_ARG | + TOOLTYPE_HOST_ARG_CAN_BE_SESSION | + TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX | + TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD; + int main(int argc, char **argv) { bool sending; @@ -603,12 +609,6 @@ int main(int argc, char **argv) stderr_bs = BinarySink_UPCAST(&stderr_bcs); outgoingeof = EOF_NO; - cmdline_tooltype |= - (TOOLTYPE_HOST_ARG | - TOOLTYPE_HOST_ARG_CAN_BE_SESSION | - TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX | - TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD); - stderr_tty_init(); /* * Process the command line. diff --git a/unix/uxpterm.c b/unix/uxpterm.c index 054d56e5..ff8ff6cd 100644 --- a/unix/uxpterm.c +++ b/unix/uxpterm.c @@ -14,6 +14,8 @@ const bool dup_check_launchable = false; /* no need to check host name * in conf */ const bool use_pty_argv = true; +const unsigned cmdline_tooltype = TOOLTYPE_NONNETWORK; + /* gtkwin.c will call this, and in pterm it's not needed */ void noise_ultralight(NoiseSourceId id, unsigned long data) { } @@ -46,7 +48,6 @@ char *make_default_wintitle(char *hostname) void setup(bool single) { - cmdline_tooltype = TOOLTYPE_NONNETWORK; default_protocol = -1; if (single) diff --git a/unix/uxputty.c b/unix/uxputty.c index 9299bd80..3611712b 100644 --- a/unix/uxputty.c +++ b/unix/uxputty.c @@ -77,11 +77,14 @@ char *platform_get_x_display(void) { const bool share_can_be_downstream = true; const bool share_can_be_upstream = true; +const unsigned cmdline_tooltype = + TOOLTYPE_HOST_ARG | + TOOLTYPE_PORT_ARG | + TOOLTYPE_NO_VERBOSE_OPTION; + void setup(bool single) { sk_init(); - cmdline_tooltype |= TOOLTYPE_HOST_ARG | TOOLTYPE_PORT_ARG | - TOOLTYPE_NO_VERBOSE_OPTION; default_protocol = be_default_protocol; /* Find the appropriate default port. */ { diff --git a/windows/window.c b/windows/window.c index 7a82b4ce..b223cb9a 100644 --- a/windows/window.c +++ b/windows/window.c @@ -467,6 +467,11 @@ static void close_session(void *ignored_context) extern LogPolicy win_gui_logpolicy[1]; /* defined in windlg.c */ +const unsigned cmdline_tooltype = + TOOLTYPE_HOST_ARG | + TOOLTYPE_PORT_ARG | + TOOLTYPE_NO_VERBOSE_OPTION; + int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { MSG msg; @@ -477,8 +482,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) hinst = inst; hwnd = NULL; - cmdline_tooltype |= TOOLTYPE_HOST_ARG | TOOLTYPE_PORT_ARG | - TOOLTYPE_NO_VERBOSE_OPTION; sk_init(); diff --git a/windows/winplink.c b/windows/winplink.c index f708a72e..cac38ddb 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -225,6 +225,12 @@ void stdouterr_sent(struct handle *h, size_t new_backlog, int err) const bool share_can_be_downstream = true; const bool share_can_be_upstream = true; +const unsigned cmdline_tooltype = + TOOLTYPE_HOST_ARG | + TOOLTYPE_HOST_ARG_CAN_BE_SESSION | + TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX | + TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD; + int main(int argc, char **argv) { bool sending; @@ -249,12 +255,6 @@ int main(int argc, char **argv) default_protocol = PROT_SSH; default_port = 22; - cmdline_tooltype |= - (TOOLTYPE_HOST_ARG | - TOOLTYPE_HOST_ARG_CAN_BE_SESSION | - TOOLTYPE_HOST_ARG_PROTOCOL_PREFIX | - TOOLTYPE_HOST_ARG_FROM_LAUNCHABLE_LOAD); - /* * Process the command line. */