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 * - Remainder of the context menu:
25 * - Event Log (this means we must implement the Event Log; not
28 * - New Session and Duplicate Session (perhaps in pterm, in fact?!)
29 * + Duplicate Session will be fun, since we must work out
30 * how to pass the config data through.
31 * + In fact this should be easier on Unix, since fork() is
32 * available so we need not even exec (this also saves us
33 * the trouble of scrabbling around trying to find our own
34 * binary). Possible scenario: respond to Duplicate
35 * Session by forking. Parent continues as before; child
36 * unceremoniously frees all extant resources (backend,
37 * terminal, ldisc, frontend etc) and then _longjmps_ (I
38 * kid you not) back to a point in pt_main() which causes
39 * it to go back round to the point of opening a new
40 * terminal window and a new backend.
41 * + A tricky bit here is how to free everything without
42 * also _destroying_ things - calling GTK to free up
43 * existing widgets is liable to send destroy messages to
44 * the X server, which won't go down too well with the
45 * parent process. exec() is a much cleaner solution to
46 * this bit, but requires us to invent some ghastly IPC as
47 * we did in Windows PuTTY.
48 * + Arrgh! Also, this won't work in pterm since we'll
49 * already have dropped privileges by this point, so we
50 * can't get another pty. Sigh. Looks like exec has to be
51 * the way forward then :-/
53 * - Saved Sessions submenu (not in pterm of course)
56 * + we must also implement mid-session reconfig in pterm.c.
57 * + note this also requires config.c and uxcfg.c to be able
58 * to get hold of the application name.
60 * - Copy All to Clipboard (for what that's worth)
66 void cleanup_exit(int code
)
77 * Another bunch of temporary stub functions. These ones will want
78 * removing by means of implementing them properly: libcharset
79 * should invent its own sensible format for codepage names and a
80 * means of enumerating them, and printer_enum needs to be dealt
81 * with somehow or other too.
84 char *cp_name(int codepage
)
88 char *cp_enumerate(int index
)
92 int decode_codepage(char *cp_name
)
97 const char *const appname
= "PuTTY";
99 Backend
*select_backend(Config
*cfg
)
102 Backend
*back
= NULL
;
103 for (i
= 0; backends
[i
].backend
!= NULL
; i
++)
104 if (backends
[i
].protocol
== cfg
->protocol
) {
105 back
= backends
[i
].backend
;
108 assert(back
!= NULL
);
112 int cfgbox(Config
*cfg
)
114 extern int do_config_box(const char *title
, Config
*cfg
);
115 return do_config_box("PuTTY Configuration", cfg
);
118 static int got_host
= 0;
120 int process_nonoption_arg(char *arg
, Config
*cfg
)
126 * If we already have a host name, treat this argument as a
127 * port number. NB we have to treat this as a saved -P
128 * argument, so that it will be deferred until it's a good
131 int ret
= cmdline_process_param("-P", arg
, 1, cfg
);
133 } else if (!strncmp(q
, "telnet:", 7)) {
135 * If the hostname starts with "telnet:",
136 * set the protocol to Telnet and process
137 * the string as a Telnet URL.
142 if (q
[0] == '/' && q
[1] == '/')
144 cfg
->protocol
= PROT_TELNET
;
146 while (*p
&& *p
!= ':' && *p
!= '/')
155 strncpy(cfg
->host
, q
, sizeof(cfg
->host
) - 1);
156 cfg
->host
[sizeof(cfg
->host
) - 1] = '\0';
160 * Otherwise, treat this argument as a host name.
163 while (*p
&& !isspace((unsigned char)*p
))
167 strncpy(cfg
->host
, q
, sizeof(cfg
->host
) - 1);
168 cfg
->host
[sizeof(cfg
->host
) - 1] = '\0';
174 char *make_default_wintitle(char *hostname
)
176 return dupcat(hostname
, " - PuTTY", NULL
);
179 int main(int argc
, char **argv
)
181 extern int pt_main(int argc
, char **argv
);
183 flags
= FLAG_VERBOSE
| FLAG_INTERACTIVE
;
184 default_protocol
= be_default_protocol
;
185 /* Find the appropriate default port. */
188 default_port
= 0; /* illegal */
189 for (i
= 0; backends
[i
].backend
!= NULL
; i
++)
190 if (backends
[i
].protocol
== default_protocol
) {
191 default_port
= backends
[i
].backend
->default_port
;
195 return pt_main(argc
, argv
);