]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - unix/uxputty.c
Update version number for 0.66 release.
[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 #include <gdk/gdk.h>
11
12 #include "putty.h"
13 #include "storage.h"
14
15 /*
16  * Stubs to avoid uxpty.c needing to be linked in.
17  */
18 const int use_pty_argv = FALSE;
19 char **pty_argv;                       /* never used */
20
21 /*
22  * Clean up and exit.
23  */
24 void cleanup_exit(int code)
25 {
26     /*
27      * Clean up.
28      */
29     sk_cleanup();
30     random_save_seed();
31     exit(code);
32 }
33
34 Backend *select_backend(Conf *conf)
35 {
36     Backend *back = backend_from_proto(conf_get_int(conf, CONF_protocol));
37     assert(back != NULL);
38     return back;
39 }
40
41 int cfgbox(Conf *conf)
42 {
43     char *title = dupcat(appname, " Configuration", NULL);
44     int ret = do_config_box(title, conf, 0, 0);
45     sfree(title);
46     return ret;
47 }
48
49 static int got_host = 0;
50
51 const int use_event_log = 1, new_session = 1, saved_sessions = 1;
52
53 int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch)
54 {
55     char *p, *q = arg;
56
57     if (got_host) {
58         /*
59          * If we already have a host name, treat this argument as a
60          * port number. NB we have to treat this as a saved -P
61          * argument, so that it will be deferred until it's a good
62          * moment to run it.
63          */
64         int ret = cmdline_process_param("-P", arg, 1, conf);
65         assert(ret == 2);
66     } else if (!strncmp(q, "telnet:", 7)) {
67         /*
68          * If the hostname starts with "telnet:",
69          * set the protocol to Telnet and process
70          * the string as a Telnet URL.
71          */
72         char c;
73
74         q += 7;
75         if (q[0] == '/' && q[1] == '/')
76             q += 2;
77         conf_set_int(conf, CONF_protocol, PROT_TELNET);
78         p = q;
79         p += host_strcspn(p, ":/");
80         c = *p;
81         if (*p)
82             *p++ = '\0';
83         if (c == ':')
84             conf_set_int(conf, CONF_port, atoi(p));
85         else
86             conf_set_int(conf, CONF_port, -1);
87         conf_set_str(conf, CONF_host, q);
88         got_host = 1;
89     } else {
90         /*
91          * Otherwise, treat this argument as a host name.
92          */
93         p = arg;
94         while (*p && !isspace((unsigned char)*p))
95             p++;
96         if (*p)
97             *p++ = '\0';
98         conf_set_str(conf, CONF_host, q);
99         got_host = 1;
100     }
101     if (got_host)
102         *allow_launch = TRUE;
103     return 1;
104 }
105
106 char *make_default_wintitle(char *hostname)
107 {
108     return dupcat(hostname, " - ", appname, NULL);
109 }
110
111 /*
112  * X11-forwarding-related things suitable for Gtk app.
113  */
114
115 char *platform_get_x_display(void) {
116     const char *display;
117     /* Try to take account of --display and what have you. */
118     if (!(display = gdk_get_display()))
119         /* fall back to traditional method */
120         display = getenv("DISPLAY");
121     return dupstr(display);
122 }
123
124 const int share_can_be_downstream = TRUE;
125 const int share_can_be_upstream = TRUE;
126
127 int main(int argc, char **argv)
128 {
129     extern int pt_main(int argc, char **argv);
130     int ret;
131
132     sk_init();
133     flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
134     default_protocol = be_default_protocol;
135     /* Find the appropriate default port. */
136     {
137         Backend *b = backend_from_proto(default_protocol);
138         default_port = 0; /* illegal */
139         if (b)
140             default_port = b->default_port;
141     }
142     ret = pt_main(argc, argv);
143     cleanup_exit(ret);
144     return ret;             /* not reached, but placates optimisers */
145 }