Since r7265, a user could not launch a PuTTY session to a specific host by
authorjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Sun, 25 Feb 2007 00:50:24 +0000 (00:50 +0000)
committerjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Sun, 25 Feb 2007 00:50:24 +0000 (00:50 +0000)
simply specifying a hostname on the command line -- this would bring up the
config dialog. Use a slightly more sophisticated notion of whether the user
meant to launch a session.

git-svn-id: svn://svn.tartarus.org/sgt/putty@7321 cda61777-01e9-0310-a592-d414129be87e

unix/gtkwin.c
unix/unix.h
unix/uxpterm.c
unix/uxputty.c
windows/window.c

index 311cf38..388d422 100644 (file)
@@ -2408,7 +2408,7 @@ static void help(FILE *fp) {
     }
 }
 
-int do_cmdline(int argc, char **argv, int do_everything,
+int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch,
                struct gui_data *inst, Config *cfg)
 {
     int err = 0;
@@ -2614,7 +2614,8 @@ int do_cmdline(int argc, char **argv, int do_everything,
             exit(1);
 
        } else if(p[0] != '-' && (!do_everything ||
-                                  process_nonoption_arg(p, cfg))) {
+                                  process_nonoption_arg(p, cfg,
+                                                       allow_launch))) {
             /* do nothing */
 
        } else {
@@ -3477,15 +3478,22 @@ int pt_main(int argc, char **argv)
        /* Splatter this argument so it doesn't clutter a ps listing */
        memset(argv[1], 0, strlen(argv[1]));
     } else {
-       if (do_cmdline(argc, argv, 0, inst, &inst->cfg))
+       /* By default, we bring up the config dialog, rather than launching
+        * a session. This gets set to TRUE if something happens to change
+        * that (e.g., a hostname is specified on the command-line). */
+       int allow_launch = FALSE;
+       if (do_cmdline(argc, argv, 0, &allow_launch, inst, &inst->cfg))
            exit(1);                   /* pre-defaults pass to get -class */
        do_defaults(NULL, &inst->cfg);
-       if (do_cmdline(argc, argv, 1, inst, &inst->cfg))
+       if (do_cmdline(argc, argv, 1, &allow_launch, inst, &inst->cfg))
            exit(1);                   /* post-defaults, do everything */
 
        cmdline_run_saved(&inst->cfg);
 
-       if ((!loaded_session || !cfg_launchable(&inst->cfg)) &&
+       if (loaded_session)
+           allow_launch = TRUE;
+
+       if ((!allow_launch || !cfg_launchable(&inst->cfg)) &&
            !cfgbox(&inst->cfg))
            exit(0);                   /* config box hit Cancel */
     }
index 9c52de6..90faf5a 100644 (file)
@@ -80,7 +80,7 @@ int reallyclose(void *frontend);
 
 /* Things pterm.c needs from {ptermm,uxputty}.c */
 char *make_default_wintitle(char *hostname);
-int process_nonoption_arg(char *arg, Config *cfg);
+int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch);
 
 /* pterm.c needs this special function in xkeysym.c */
 int keysym_to_unicode(int keysym);
index 50fdad9..c20c14a 100644 (file)
@@ -33,7 +33,7 @@ void cleanup_exit(int code)
     exit(code);
 }
 
-int process_nonoption_arg(char *arg, Config *cfg)
+int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch)
 {
     return 0;                          /* pterm doesn't have any. */
 }
index 0abc1ff..54e0d71 100644 (file)
@@ -53,7 +53,7 @@ static int got_host = 0;
 
 const int use_event_log = 1, new_session = 1, saved_sessions = 1;
 
-int process_nonoption_arg(char *arg, Config *cfg)
+int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch)
 {
     char *p, *q = arg;
 
@@ -104,6 +104,8 @@ int process_nonoption_arg(char *arg, Config *cfg)
         cfg->host[sizeof(cfg->host) - 1] = '\0';
         got_host = 1;
     }
+    if (got_host)
+       *allow_launch = TRUE;
     return 1;
 }
 
index f654d2a..1df5fee 100644 (file)
@@ -361,6 +361,10 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
     {
        char *p;
        int got_host = 0;
+       /* By default, we bring up the config dialog, rather than launching
+        * a session. This gets set to TRUE if something happens to change
+        * that (e.g., a hostname is specified on the command-line). */
+       int allow_launch = FALSE;
 
        default_protocol = be_default_protocol;
        /* Find the appropriate default port. */
@@ -397,7 +401,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
            if (!cfg_launchable(&cfg) && !do_config()) {
                cleanup_exit(0);
            }
-           loaded_session = TRUE;     /* allow it to be launched directly */
+           allow_launch = TRUE;    /* allow it to be launched directly */
        } else if (*p == '&') {
            /*
             * An initial & means we've been given a command line
@@ -413,10 +417,10 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
                cfg = *cp;
                UnmapViewOfFile(cp);
                CloseHandle(filemap);
-               loaded_session = TRUE;
            } else if (!do_config()) {
                cleanup_exit(0);
            }
+           allow_launch = TRUE;
        } else {
            /*
             * Otherwise, break up the command line and deal with
@@ -541,8 +545,10 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 
        cmdline_run_saved(&cfg);
 
-       if ((!loaded_session || !cfg_launchable(&cfg)) &&
-           !do_config()) {
+       if (loaded_session || got_host)
+           allow_launch = TRUE;
+
+       if ((!allow_launch || !cfg_launchable(&cfg)) && !do_config()) {
            cleanup_exit(0);
        }