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