1d009ae7 |
1 | /* |
2 | * Unix PuTTY main program. |
3 | */ |
4 | |
5 | #include <stdio.h> |
5bf9955d |
6 | #include <stdlib.h> |
1d009ae7 |
7 | #include <assert.h> |
1d009ae7 |
8 | #include <unistd.h> |
9 | |
10 | #include "putty.h" |
11 | #include "storage.h" |
12 | |
13 | /* |
5bf9955d |
14 | * TODO: |
1d009ae7 |
15 | * |
5bf9955d |
16 | * - Arrange for the window title not to be `pterm'. |
17 | * |
18 | * - Fix command-line parsing to be more PuTTYlike and not so |
19 | * ptermy - in particular non-option arguments should be |
20 | * hostname and port in the obvious way. |
21 | * |
22 | * - Session loading and saving; current thinking says the best |
23 | * way is to have a subdir .putty/sessions containing files |
24 | * whose names are actually munged saved session names. |
25 | * |
26 | * - libcharset enumeration. |
27 | * |
28 | * - fix the printer enum (I think the sensible thing is simply to |
29 | * have uxcfg.c remove the drop-down list completely, since you |
30 | * can't sensibly provide an enumerated list of lpr commands!). |
31 | * |
32 | * - Ctrl+right-click for a context menu (also in Windows for |
33 | * consistency, I think). This should contain pretty much |
34 | * everything in the Windows PuTTY menu, and a subset of that in |
35 | * pterm: |
36 | * |
37 | * - Telnet special commands (not in pterm :-) |
38 | * |
39 | * - Event Log (this means we must implement the Event Log; not |
40 | * in pterm) |
41 | * |
42 | * - New Session and Duplicate Session (perhaps in pterm, in fact?!) |
43 | * + Duplicate Session will be fun, since we must work out |
44 | * how to pass the config data through. |
45 | * + In fact this should be easier on Unix, since fork() is |
46 | * available so we need not even exec (this also saves us |
47 | * the trouble of scrabbling around trying to find our own |
48 | * binary). Possible scenario: respond to Duplicate |
49 | * Session by forking. Parent continues as before; child |
50 | * unceremoniously frees all extant resources (backend, |
51 | * terminal, ldisc, frontend etc) and then _longjmps_ (I |
52 | * kid you not) back to a point in pt_main() which causes |
53 | * it to go back round to the point of opening a new |
54 | * terminal window and a new backend. |
55 | * + A tricky bit here is how to free everything without |
56 | * also _destroying_ things - calling GTK to free up |
57 | * existing widgets is liable to send destroy messages to |
58 | * the X server, which won't go down too well with the |
59 | * parent process. exec() is a much cleaner solution to |
60 | * this bit, but requires us to invent some ghastly IPC as |
61 | * we did in Windows PuTTY. |
62 | * + Arrgh! Also, this won't work in pterm since we'll |
63 | * already have dropped privileges by this point, so we |
64 | * can't get another pty. Sigh. Looks like exec has to be |
65 | * the way forward then :-/ |
66 | * |
67 | * - Saved Sessions submenu (not in pterm of course) |
68 | * |
69 | * - Change Settings |
70 | * + we must also implement mid-session reconfig in pterm.c. |
71 | * + note this also requires config.c and uxcfg.c to be able |
72 | * to get hold of the application name. |
73 | * |
74 | * - Copy All to Clipboard (for what that's worth) |
75 | * |
76 | * - Clear Scrollback and Reset Terminal |
77 | * |
78 | * - About (and uxcfg.c must also supply the about box) |
1d009ae7 |
79 | */ |
5bf9955d |
80 | |
1d009ae7 |
81 | void cmdline_error(char *p, ...) |
82 | { |
83 | va_list ap; |
84 | fprintf(stderr, "plink: "); |
85 | va_start(ap, p); |
86 | vfprintf(stderr, p, ap); |
87 | va_end(ap); |
88 | fputc('\n', stderr); |
89 | exit(1); |
90 | } |
91 | |
92 | /* |
93 | * Clean up and exit. |
94 | */ |
95 | void cleanup_exit(int code) |
96 | { |
97 | /* |
98 | * Clean up. |
99 | */ |
100 | sk_cleanup(); |
101 | random_save_seed(); |
102 | exit(code); |
103 | } |
104 | |
1d009ae7 |
105 | /* |
106 | * Another bunch of temporary stub functions. These ones will want |
107 | * removing by means of implementing them properly: libcharset |
108 | * should invent its own sensible format for codepage names and a |
109 | * means of enumerating them, and printer_enum needs to be dealt |
110 | * with somehow or other too. |
111 | */ |
112 | |
113 | char *cp_name(int codepage) |
114 | { |
115 | return ""; |
116 | } |
117 | char *cp_enumerate(int index) |
118 | { |
119 | return NULL; |
120 | } |
121 | int decode_codepage(char *cp_name) |
122 | { |
123 | return -2; |
124 | } |
125 | |
126 | printer_enum *printer_start_enum(int *nprinters_ptr) { |
127 | *nprinters_ptr = 0; |
128 | return NULL; |
129 | } |
130 | char *printer_get_name(printer_enum *pe, int i) { return NULL; |
131 | } |
132 | void printer_finish_enum(printer_enum *pe) { } |
133 | |
134 | Backend *select_backend(Config *cfg) |
135 | { |
136 | int i; |
137 | Backend *back = NULL; |
138 | for (i = 0; backends[i].backend != NULL; i++) |
139 | if (backends[i].protocol == cfg->protocol) { |
140 | back = backends[i].backend; |
141 | break; |
142 | } |
143 | assert(back != NULL); |
144 | return back; |
145 | } |
146 | |
147 | int cfgbox(Config *cfg) |
148 | { |
149 | extern int do_config_box(const char *title, Config *cfg); |
150 | return do_config_box("PuTTY Configuration", cfg); |
151 | } |
152 | |
153 | int main(int argc, char **argv) |
154 | { |
155 | extern int pt_main(int argc, char **argv); |
156 | sk_init(); |
157 | flags = FLAG_VERBOSE | FLAG_INTERACTIVE; |
158 | default_protocol = be_default_protocol; |
159 | /* Find the appropriate default port. */ |
160 | { |
161 | int i; |
162 | default_port = 0; /* illegal */ |
163 | for (i = 0; backends[i].backend != NULL; i++) |
164 | if (backends[i].protocol == default_protocol) { |
165 | default_port = backends[i].backend->default_port; |
166 | break; |
167 | } |
168 | } |
169 | return pt_main(argc, argv); |
170 | } |