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