2 * Unix PuTTY main program.
17 * - Copy-and-paste from the Event Log.
19 * - Remainder of the context menu:
21 * - New Session and Duplicate Session (perhaps in pterm, in fact?!)
22 * + Duplicate Session will be fun, since we must work out
23 * how to pass the config data through.
24 * + In fact this should be easier on Unix, since fork() is
25 * available so we need not even exec (this also saves us
26 * the trouble of scrabbling around trying to find our own
27 * binary). Possible scenario: respond to Duplicate
28 * Session by forking. Parent continues as before; child
29 * unceremoniously frees all extant resources (backend,
30 * terminal, ldisc, frontend etc) and then _longjmps_ (I
31 * kid you not) back to a point in pt_main() which causes
32 * it to go back round to the point of opening a new
33 * terminal window and a new backend.
34 * + A tricky bit here is how to free everything without
35 * also _destroying_ things - calling GTK to free up
36 * existing widgets is liable to send destroy messages to
37 * the X server, which won't go down too well with the
38 * parent process. exec() is a much cleaner solution to
39 * this bit, but requires us to invent some ghastly IPC as
40 * we did in Windows PuTTY.
41 * + Arrgh! Also, this won't work in pterm since we'll
42 * already have dropped privileges by this point, so we
43 * can't get another pty. Sigh. Looks like exec has to be
44 * the way forward then :-/
46 * - Saved Sessions submenu (not in pterm of course)
48 * - Copy All to Clipboard (for what that's worth)
54 void cleanup_exit(int code)
64 Backend *select_backend(Config *cfg)
68 for (i = 0; backends[i].backend != NULL; i++)
69 if (backends[i].protocol == cfg->protocol) {
70 back = backends[i].backend;
77 int cfgbox(Config *cfg)
79 return do_config_box("PuTTY Configuration", cfg, 0);
82 static int got_host = 0;
84 const int use_event_log = 1;
86 int process_nonoption_arg(char *arg, Config *cfg)
92 * If we already have a host name, treat this argument as a
93 * port number. NB we have to treat this as a saved -P
94 * argument, so that it will be deferred until it's a good
97 int ret = cmdline_process_param("-P", arg, 1, cfg);
99 } else if (!strncmp(q, "telnet:", 7)) {
101 * If the hostname starts with "telnet:",
102 * set the protocol to Telnet and process
103 * the string as a Telnet URL.
108 if (q[0] == '/' && q[1] == '/')
110 cfg->protocol = PROT_TELNET;
112 while (*p && *p != ':' && *p != '/')
121 strncpy(cfg->host, q, sizeof(cfg->host) - 1);
122 cfg->host[sizeof(cfg->host) - 1] = '\0';
126 * Otherwise, treat this argument as a host name.
129 while (*p && !isspace((unsigned char)*p))
133 strncpy(cfg->host, q, sizeof(cfg->host) - 1);
134 cfg->host[sizeof(cfg->host) - 1] = '\0';
140 char *make_default_wintitle(char *hostname)
142 return dupcat(hostname, " - PuTTY", NULL);
145 int main(int argc, char **argv)
147 extern int pt_main(int argc, char **argv);
149 flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
150 default_protocol = be_default_protocol;
151 /* Find the appropriate default port. */
154 default_port = 0; /* illegal */
155 for (i = 0; backends[i].backend != NULL; i++)
156 if (backends[i].protocol == default_protocol) {
157 default_port = backends[i].backend->default_port;
161 return pt_main(argc, argv);