mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-08 08:58:00 +00:00
Make cmdline_tooltype a const int.
Another ugly mutable global variable gone: now, instead of this variable being defined in cmdline.c and written to by everyone's main(), it's defined _alongside_ everyone's main() as a constant, and cmdline.c just refers to it. A bonus is that now nocmdline.c doesn't have to define it anyway for tools that don't use cmdline.c. But mostly, it didn't need to be mutable, so better for it not to be. While I'm at it, I've also fiddled with the bit flags that go in it, to define their values automatically using a list macro instead of manually specifying each one to be a different power of 2.
This commit is contained in:
parent
9da36bd897
commit
575ee4f8fc
12
cmdline.c
12
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) {
|
||||
|
@ -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;
|
||||
|
3
pscp.c
3
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. */
|
||||
|
3
psftp.c
3
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;
|
||||
|
37
putty.h
37
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);
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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. */
|
||||
{
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user