1d009ae7 |
1 | /* |
2 | * Unix PuTTY main program. |
3 | */ |
4 | |
5 | #include <stdio.h> |
46a3419b |
6 | #include <ctype.h> |
5bf9955d |
7 | #include <stdlib.h> |
1d009ae7 |
8 | #include <assert.h> |
1d009ae7 |
9 | #include <unistd.h> |
10 | |
11 | #include "putty.h" |
12 | #include "storage.h" |
13 | |
14 | /* |
5bf9955d |
15 | * TODO: |
1d009ae7 |
16 | * |
fbf6cb3b |
17 | * - Go through all the config options and ensure they can all be |
18 | * configured and reconfigured properly. |
56801e3d |
19 | * + icon title appears to be a non-option on Unix. |
20 | * + Why the hell did I faff about disabling two of the vtmode |
21 | * options? The rest aren't used either in pterm! Work out |
22 | * whether they should be, and how they can be. |
23 | * + Refresh in the codepage combo is badly broken. |
24 | * + `Don't translate line drawing chars' ?? What is this crap? |
25 | * It does nothing at all, and where's the option to paste as |
26 | * lqqqk? What was I smoking? |
27 | * |
28 | * - Better control of the individual config box features. |
29 | * + SSH packet logging shouldn't be mentioned in pterm, and in |
30 | * fact not PuTTYtel either. |
31 | * + Keepalives, and the Connection panel in general, shouldn't |
32 | * crop up in pterm. (And perhaps also not mid-session in |
33 | * rlogin and raw?) |
1d009ae7 |
34 | */ |
5bf9955d |
35 | |
1d009ae7 |
36 | /* |
37 | * Clean up and exit. |
38 | */ |
39 | void cleanup_exit(int code) |
40 | { |
41 | /* |
42 | * Clean up. |
43 | */ |
44 | sk_cleanup(); |
45 | random_save_seed(); |
46 | exit(code); |
47 | } |
48 | |
1d009ae7 |
49 | Backend *select_backend(Config *cfg) |
50 | { |
51 | int i; |
52 | Backend *back = NULL; |
53 | for (i = 0; backends[i].backend != NULL; i++) |
54 | if (backends[i].protocol == cfg->protocol) { |
55 | back = backends[i].backend; |
56 | break; |
57 | } |
58 | assert(back != NULL); |
59 | return back; |
60 | } |
61 | |
62 | int cfgbox(Config *cfg) |
63 | { |
56b9b9a7 |
64 | return do_config_box("PuTTY Configuration", cfg, 0); |
1d009ae7 |
65 | } |
66 | |
46a3419b |
67 | static int got_host = 0; |
68 | |
56801e3d |
69 | const int use_event_log = 1, new_session = 1, saved_sessions = 1; |
8eed910d |
70 | |
46a3419b |
71 | int process_nonoption_arg(char *arg, Config *cfg) |
72 | { |
73 | char *p, *q = arg; |
74 | |
75 | if (got_host) { |
76 | /* |
77 | * If we already have a host name, treat this argument as a |
78 | * port number. NB we have to treat this as a saved -P |
79 | * argument, so that it will be deferred until it's a good |
80 | * moment to run it. |
81 | */ |
82 | int ret = cmdline_process_param("-P", arg, 1, cfg); |
83 | assert(ret == 2); |
84 | } else if (!strncmp(q, "telnet:", 7)) { |
85 | /* |
86 | * If the hostname starts with "telnet:", |
87 | * set the protocol to Telnet and process |
88 | * the string as a Telnet URL. |
89 | */ |
90 | char c; |
91 | |
92 | q += 7; |
93 | if (q[0] == '/' && q[1] == '/') |
94 | q += 2; |
95 | cfg->protocol = PROT_TELNET; |
96 | p = q; |
97 | while (*p && *p != ':' && *p != '/') |
98 | p++; |
99 | c = *p; |
100 | if (*p) |
101 | *p++ = '\0'; |
102 | if (c == ':') |
103 | cfg->port = atoi(p); |
104 | else |
105 | cfg->port = -1; |
106 | strncpy(cfg->host, q, sizeof(cfg->host) - 1); |
107 | cfg->host[sizeof(cfg->host) - 1] = '\0'; |
108 | got_host = 1; |
109 | } else { |
110 | /* |
111 | * Otherwise, treat this argument as a host name. |
112 | */ |
320cb4be |
113 | p = arg; |
46a3419b |
114 | while (*p && !isspace((unsigned char)*p)) |
115 | p++; |
116 | if (*p) |
117 | *p++ = '\0'; |
118 | strncpy(cfg->host, q, sizeof(cfg->host) - 1); |
119 | cfg->host[sizeof(cfg->host) - 1] = '\0'; |
120 | got_host = 1; |
121 | } |
122 | return 1; |
123 | } |
124 | |
10705014 |
125 | char *make_default_wintitle(char *hostname) |
126 | { |
127 | return dupcat(hostname, " - PuTTY", NULL); |
128 | } |
129 | |
1d009ae7 |
130 | int main(int argc, char **argv) |
131 | { |
132 | extern int pt_main(int argc, char **argv); |
133 | sk_init(); |
134 | flags = FLAG_VERBOSE | FLAG_INTERACTIVE; |
135 | default_protocol = be_default_protocol; |
136 | /* Find the appropriate default port. */ |
137 | { |
138 | int i; |
139 | default_port = 0; /* illegal */ |
140 | for (i = 0; backends[i].backend != NULL; i++) |
141 | if (backends[i].protocol == default_protocol) { |
142 | default_port = backends[i].backend->default_port; |
143 | break; |
144 | } |
145 | } |
146 | return pt_main(argc, argv); |
147 | } |