Add the ability to do ssh by default: using -ssh command line option,
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 27 Oct 1999 14:28:11 +0000 (14:28 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 27 Oct 1999 14:28:11 +0000 (14:28 +0000)
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
windlg.c
window.c

diff --git a/putty.h b/putty.h
index 56f504c..1a623ac 100644 (file)
--- 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.
index d13a8c4..79faca3 100644 (file)
--- 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));
index d3ab4df..6b0f1db 100644 (file)
--- 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 == '@') {