1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00
putty-source/unix/uxpterm.c
Simon Tatham b9a25510b0 Centralise PuTTY and Plink's non-option argument handling.
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.
2017-12-07 20:13:33 +00:00

53 lines
1.2 KiB
C

/*
* pterm main program.
*/
#include <stdio.h>
#include <stdlib.h>
#include "putty.h"
const char *const appname = "pterm";
const int use_event_log = 0; /* pterm doesn't need it */
const int new_session = 0, saved_sessions = 0; /* or these */
const int dup_check_launchable = 0; /* no need to check host name in conf */
const int use_pty_argv = TRUE;
Backend *select_backend(Conf *conf)
{
return &pty_backend;
}
void initial_config_box(Conf *conf, post_dialog_fn_t after, void *afterctx)
{
/*
* This is a no-op in pterm, except that we'll ensure the protocol
* is set to -1 to inhibit the useless Connection panel in the
* config box. So we do that and then just immediately call the
* post-dialog function with a positive result.
*/
conf_set_int(conf, CONF_protocol, -1);
after(afterctx, 1);
}
void cleanup_exit(int code)
{
exit(code);
}
char *make_default_wintitle(char *hostname)
{
return dupstr("pterm");
}
void setup(int single)
{
extern void pty_pre_init(void); /* declared in pty.c */
cmdline_tooltype = TOOLTYPE_NONNETWORK;
default_protocol = -1;
if (single)
pty_pre_init();
}