From e277c42d9ad347cb7baeb9a6a5c84616bf55288f Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 27 Oct 1999 14:28:11 +0000 Subject: [PATCH] Add the ability to do ssh by default: using -ssh command line option, or by manually adding protocol and port settings to Default Settings in the Registry, or by compiling with -DSSH_DEFAULT git-svn-id: svn://svn.tartarus.org/sgt/putty@260 cda61777-01e9-0310-a592-d414129be87e --- putty.h | 13 +++++++++++++ windlg.c | 23 ++++++++++------------- window.c | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/putty.h b/putty.h index 56f504c0..1a623ac2 100644 --- a/putty.h +++ b/putty.h @@ -130,7 +130,20 @@ typedef struct { short wordness[256]; } Config; +/* + * You can compile with -DSSH_DEFAULT to have ssh by default. + */ +#ifndef SSH_DEFAULT +#define DEFAULT_PROTOCOL PROT_TELNET +#define DEFAULT_PORT 23 +#else +#define DEFAULT_PROTOCOL PROT_SSH +#define DEFAULT_PORT 22 +#endif + GLOBAL Config cfg; +GLOBAL int default_protocol; +GLOBAL int default_port; /* * Exports from window.c. diff --git a/windlg.c b/windlg.c index d13a8c43..79faca3a 100644 --- a/windlg.c +++ b/windlg.c @@ -210,6 +210,7 @@ static void load_settings (char *section, int do_host) { int i; HKEY subkey1, sesskey; char *p; + char prot[10]; p = malloc(3*strlen(section)+1); mungestr(section, p); @@ -225,20 +226,16 @@ static void load_settings (char *section, int do_host) { free(p); - if (do_host) { - char prot[10]; - gpps (sesskey, "HostName", "", cfg.host, sizeof(cfg.host)); - gppi (sesskey, "PortNumber", 23, &cfg.port); - gpps (sesskey, "Protocol", "telnet", prot, 10); - if (!strcmp(prot, "ssh")) - cfg.protocol = PROT_SSH; - else - cfg.protocol = PROT_TELNET; - } else { + gpps (sesskey, "HostName", "", cfg.host, sizeof(cfg.host)); + gppi (sesskey, "PortNumber", default_port, &cfg.port); + gpps (sesskey, "Protocol", "default", prot, 10); + if (!strcmp(prot, "ssh")) + cfg.protocol = PROT_SSH; + else if (!strcmp(prot, "telnet")) cfg.protocol = PROT_TELNET; - cfg.port = 23; - *cfg.host = '\0'; - } + else + cfg.protocol = default_protocol; + gppi (sesskey, "CloseOnExit", 1, &cfg.close_on_exit); gpps (sesskey, "TerminalType", "xterm", cfg.termtype, sizeof(cfg.termtype)); diff --git a/window.c b/window.c index d3ab4dfa..6b0f1dba 100644 --- a/window.c +++ b/window.c @@ -100,12 +100,33 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { { char *p; + default_protocol = DEFAULT_PROTOCOL; + default_port = DEFAULT_PORT; + do_defaults(NULL); p = cmdline; while (*p && isspace(*p)) p++; /* + * Process command line options first. Yes, this can be + * done better, and it will be as soon as I have the + * energy... + */ + while (*p == '-') { + char *q = p + strcspn(p, " \t"); + p++; + if (q == p + 3 && + tolower(p[0]) == 's' && + tolower(p[1]) == 's' && + tolower(p[2]) == 'h') { + default_protocol = cfg.protocol = PROT_SSH; + default_port = cfg.port = 22; + } + p = q + strspn(q, " \t"); + } + + /* * An initial @ means to activate a saved session. */ if (*p == '@') { -- 2.11.0