2 * Unix PuTTY main program.
17 * - libcharset enumeration.
19 * - fix the printer enum (I think the sensible thing is simply to
20 * have uxcfg.c remove the drop-down list completely, since you
21 * can't sensibly provide an enumerated list of lpr commands!).
23 * - Ctrl+right-click for a context menu (also in Windows for
24 * consistency, I think). This should contain pretty much
25 * everything in the Windows PuTTY menu, and a subset of that in
28 * - Telnet special commands (not in pterm :-)
30 * - Event Log (this means we must implement the Event Log; not
33 * - New Session and Duplicate Session (perhaps in pterm, in fact?!)
34 * + Duplicate Session will be fun, since we must work out
35 * how to pass the config data through.
36 * + In fact this should be easier on Unix, since fork() is
37 * available so we need not even exec (this also saves us
38 * the trouble of scrabbling around trying to find our own
39 * binary). Possible scenario: respond to Duplicate
40 * Session by forking. Parent continues as before; child
41 * unceremoniously frees all extant resources (backend,
42 * terminal, ldisc, frontend etc) and then _longjmps_ (I
43 * kid you not) back to a point in pt_main() which causes
44 * it to go back round to the point of opening a new
45 * terminal window and a new backend.
46 * + A tricky bit here is how to free everything without
47 * also _destroying_ things - calling GTK to free up
48 * existing widgets is liable to send destroy messages to
49 * the X server, which won't go down too well with the
50 * parent process. exec() is a much cleaner solution to
51 * this bit, but requires us to invent some ghastly IPC as
52 * we did in Windows PuTTY.
53 * + Arrgh! Also, this won't work in pterm since we'll
54 * already have dropped privileges by this point, so we
55 * can't get another pty. Sigh. Looks like exec has to be
56 * the way forward then :-/
58 * - Saved Sessions submenu (not in pterm of course)
61 * + we must also implement mid-session reconfig in pterm.c.
62 * + note this also requires config.c and uxcfg.c to be able
63 * to get hold of the application name.
65 * - Copy All to Clipboard (for what that's worth)
67 * - Clear Scrollback and Reset Terminal
69 * - About (and uxcfg.c must also supply the about box)
75 void cleanup_exit(int code
)
86 * Another bunch of temporary stub functions. These ones will want
87 * removing by means of implementing them properly: libcharset
88 * should invent its own sensible format for codepage names and a
89 * means of enumerating them, and printer_enum needs to be dealt
90 * with somehow or other too.
93 char *cp_name(int codepage
)
97 char *cp_enumerate(int index
)
101 int decode_codepage(char *cp_name
)
106 printer_enum
*printer_start_enum(int *nprinters_ptr
) {
110 char *printer_get_name(printer_enum
*pe
, int i
) { return NULL
;
112 void printer_finish_enum(printer_enum
*pe
) { }
114 Backend
*select_backend(Config
*cfg
)
117 Backend
*back
= NULL
;
118 for (i
= 0; backends
[i
].backend
!= NULL
; i
++)
119 if (backends
[i
].protocol
== cfg
->protocol
) {
120 back
= backends
[i
].backend
;
123 assert(back
!= NULL
);
127 int cfgbox(Config
*cfg
)
129 extern int do_config_box(const char *title
, Config
*cfg
);
130 return do_config_box("PuTTY Configuration", cfg
);
133 static int got_host
= 0;
135 int process_nonoption_arg(char *arg
, Config
*cfg
)
141 * If we already have a host name, treat this argument as a
142 * port number. NB we have to treat this as a saved -P
143 * argument, so that it will be deferred until it's a good
146 int ret
= cmdline_process_param("-P", arg
, 1, cfg
);
148 } else if (!strncmp(q
, "telnet:", 7)) {
150 * If the hostname starts with "telnet:",
151 * set the protocol to Telnet and process
152 * the string as a Telnet URL.
157 if (q
[0] == '/' && q
[1] == '/')
159 cfg
->protocol
= PROT_TELNET
;
161 while (*p
&& *p
!= ':' && *p
!= '/')
170 strncpy(cfg
->host
, q
, sizeof(cfg
->host
) - 1);
171 cfg
->host
[sizeof(cfg
->host
) - 1] = '\0';
175 * Otherwise, treat this argument as a host name.
177 while (*p
&& !isspace((unsigned char)*p
))
181 strncpy(cfg
->host
, q
, sizeof(cfg
->host
) - 1);
182 cfg
->host
[sizeof(cfg
->host
) - 1] = '\0';
188 char *make_default_wintitle(char *hostname
)
190 return dupcat(hostname
, " - PuTTY", NULL
);
193 int main(int argc
, char **argv
)
195 extern int pt_main(int argc
, char **argv
);
197 flags
= FLAG_VERBOSE
| FLAG_INTERACTIVE
;
198 default_protocol
= be_default_protocol
;
199 /* Find the appropriate default port. */
202 default_port
= 0; /* illegal */
203 for (i
= 0; backends
[i
].backend
!= NULL
; i
++)
204 if (backends
[i
].protocol
== default_protocol
) {
205 default_port
= backends
[i
].backend
->default_port
;
209 return pt_main(argc
, argv
);