]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - unix/uxputty.c
Make the `vtmode' config option work under X. In the process I've
[PuTTY.git] / unix / uxputty.c
1 /*
2  * Unix PuTTY main program.
3  */
4
5 #include <stdio.h>
6 #include <ctype.h>
7 #include <stdlib.h>
8 #include <assert.h>
9 #include <unistd.h>
10
11 #include "putty.h"
12 #include "storage.h"
13
14 /*
15  * TODO:
16  *
17  *  - Better control of the individual config box features.
18  *     + SSH packet logging shouldn't be mentioned in pterm, and in
19  *       fact not PuTTYtel either.
20  *     + Keepalives, and the Connection panel in general, shouldn't
21  *       crop up in pterm. (And perhaps also not mid-session in
22  *       rlogin and raw?)
23  */
24
25 /*
26  * Clean up and exit.
27  */
28 void cleanup_exit(int code)
29 {
30     /*
31      * Clean up.
32      */
33     sk_cleanup();
34     random_save_seed();
35     exit(code);
36 }
37
38 Backend *select_backend(Config *cfg)
39 {
40     int i;
41     Backend *back = NULL;
42     for (i = 0; backends[i].backend != NULL; i++)
43         if (backends[i].protocol == cfg->protocol) {
44             back = backends[i].backend;
45             break;
46         }
47     assert(back != NULL);
48     return back;
49 }
50
51 int cfgbox(Config *cfg)
52 {
53     return do_config_box("PuTTY Configuration", cfg, 0);
54 }
55
56 static int got_host = 0;
57
58 const int use_event_log = 1, new_session = 1, saved_sessions = 1;
59
60 int process_nonoption_arg(char *arg, Config *cfg)
61 {
62     char *p, *q = arg;
63
64     if (got_host) {
65         /*
66          * If we already have a host name, treat this argument as a
67          * port number. NB we have to treat this as a saved -P
68          * argument, so that it will be deferred until it's a good
69          * moment to run it.
70          */
71         int ret = cmdline_process_param("-P", arg, 1, cfg);
72         assert(ret == 2);
73     } else if (!strncmp(q, "telnet:", 7)) {
74         /*
75          * If the hostname starts with "telnet:",
76          * set the protocol to Telnet and process
77          * the string as a Telnet URL.
78          */
79         char c;
80
81         q += 7;
82         if (q[0] == '/' && q[1] == '/')
83             q += 2;
84         cfg->protocol = PROT_TELNET;
85         p = q;
86         while (*p && *p != ':' && *p != '/')
87             p++;
88         c = *p;
89         if (*p)
90             *p++ = '\0';
91         if (c == ':')
92             cfg->port = atoi(p);
93         else
94             cfg->port = -1;
95         strncpy(cfg->host, q, sizeof(cfg->host) - 1);
96         cfg->host[sizeof(cfg->host) - 1] = '\0';
97         got_host = 1;
98     } else {
99         /*
100          * Otherwise, treat this argument as a host name.
101          */
102         p = arg;
103         while (*p && !isspace((unsigned char)*p))
104             p++;
105         if (*p)
106             *p++ = '\0';
107         strncpy(cfg->host, q, sizeof(cfg->host) - 1);
108         cfg->host[sizeof(cfg->host) - 1] = '\0';
109         got_host = 1;
110     }
111     return 1;
112 }
113
114 char *make_default_wintitle(char *hostname)
115 {
116     return dupcat(hostname, " - PuTTY", NULL);
117 }
118
119 int main(int argc, char **argv)
120 {
121     extern int pt_main(int argc, char **argv);
122     sk_init();
123     flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
124     default_protocol = be_default_protocol;
125     /* Find the appropriate default port. */
126     {
127         int i;
128         default_port = 0; /* illegal */
129         for (i = 0; backends[i].backend != NULL; i++)
130             if (backends[i].protocol == default_protocol) {
131                 default_port = backends[i].backend->default_port;
132                 break;
133             }
134     }
135     return pt_main(argc, argv);
136 }