mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 09:58:01 +00:00
b9a25510b0
This is another piece of long-overdue refactoring similar to the
recent commit e3796cb77
. But where that one dealt with normalisation
of stuff already stored _in_ a Conf by whatever means (including, in
particular, handling a user typing 'username@host.name' into the
Hostname box of the GUI session dialog box), this one deals with
handling argv entries and putting them into the Conf.
This isn't exactly a pure no-functional-change-at-all refactoring. On
the other hand, it isn't a full-on cleanup that completely
rationalises all the user-visible behaviour as well as the code
structure. It's somewhere in between: I've preserved all the behaviour
quirks that I could imagine a reason for having intended, but taken
the opportunity to _not_ faithfully replicate anything I thought was
clearly just a bug.
So, for example, the following inconsistency is carefully preserved:
the command 'plink -load session nextword' treats 'nextword' as a host
name if the loaded session hasn't provided a hostname already, and
otherwise treats 'nextword' as the remote command to execute on the
already-specified remote host, but the same combination of arguments
to GUI PuTTY will _always_ treat 'nextword' as a hostname, overriding
a hostname (if any) in the saved session. That makes some sense to me
because of the different shapes of the overall command lines.
On the other hand, there are two behaviour changes I know of as a
result of this commit: a third argument to GUI PuTTY (after a hostname
and port) now provokes an error message instead of being silently
ignored, and in Plink, if you combine a -P option (specifying a port
number) with the historical comma-separated protocol selection prefix
on the hostname argument (which I'd completely forgotten even existed
until this piece of work), then the -P will now override the selected
protocol's default port number, whereas previously the default port
would win. For example, 'plink -P 12345 telnet,hostname' will now
connect via Telnet to port 12345 instead of to port 23.
There may be scope for removing or rethinking some of the command-
line syntax quirks in the wake of this change. If we do decide to do
anything like that, then hopefully having it all in one place will
make it easier to remove or change things consistently across the
tools.
92 lines
1.9 KiB
C
92 lines
1.9 KiB
C
/*
|
|
* Unix PuTTY main program.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <ctype.h>
|
|
#include <stdlib.h>
|
|
#include <assert.h>
|
|
#include <unistd.h>
|
|
#include <gtk/gtk.h>
|
|
#include <gdk/gdk.h>
|
|
|
|
#define MAY_REFER_TO_GTK_IN_HEADERS
|
|
|
|
#include "putty.h"
|
|
#include "storage.h"
|
|
|
|
#include "gtkcompat.h"
|
|
|
|
/*
|
|
* Stubs to avoid uxpty.c needing to be linked in.
|
|
*/
|
|
const int use_pty_argv = FALSE;
|
|
char **pty_argv; /* never used */
|
|
char *pty_osx_envrestore_prefix;
|
|
|
|
/*
|
|
* Clean up and exit.
|
|
*/
|
|
void cleanup_exit(int code)
|
|
{
|
|
/*
|
|
* Clean up.
|
|
*/
|
|
sk_cleanup();
|
|
random_save_seed();
|
|
exit(code);
|
|
}
|
|
|
|
Backend *select_backend(Conf *conf)
|
|
{
|
|
Backend *back = backend_from_proto(conf_get_int(conf, CONF_protocol));
|
|
assert(back != NULL);
|
|
return back;
|
|
}
|
|
|
|
void initial_config_box(Conf *conf, post_dialog_fn_t after, void *afterctx)
|
|
{
|
|
char *title = dupcat(appname, " Configuration", NULL);
|
|
create_config_box(title, conf, FALSE, 0, after, afterctx);
|
|
sfree(title);
|
|
}
|
|
|
|
const int use_event_log = 1, new_session = 1, saved_sessions = 1;
|
|
const int dup_check_launchable = 1;
|
|
|
|
char *make_default_wintitle(char *hostname)
|
|
{
|
|
return dupcat(hostname, " - ", appname, NULL);
|
|
}
|
|
|
|
/*
|
|
* X11-forwarding-related things suitable for Gtk app.
|
|
*/
|
|
|
|
char *platform_get_x_display(void) {
|
|
const char *display;
|
|
/* Try to take account of --display and what have you. */
|
|
if (!(display = gdk_get_display()))
|
|
/* fall back to traditional method */
|
|
display = getenv("DISPLAY");
|
|
return dupstr(display);
|
|
}
|
|
|
|
const int share_can_be_downstream = TRUE;
|
|
const int share_can_be_upstream = TRUE;
|
|
|
|
void setup(int single)
|
|
{
|
|
sk_init();
|
|
flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
|
|
cmdline_tooltype |= TOOLTYPE_HOST_ARG | TOOLTYPE_PORT_ARG;
|
|
default_protocol = be_default_protocol;
|
|
/* Find the appropriate default port. */
|
|
{
|
|
Backend *b = backend_from_proto(default_protocol);
|
|
default_port = 0; /* illegal */
|
|
if (b)
|
|
default_port = b->default_port;
|
|
}
|
|
}
|