]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - unix/uxputty.c
Merge branch 'pre-0.65'
[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(const char *arg, Conf *conf, int *allow_launch)
54 {
55     char *argdup, *p, *q;
56     argdup = dupstr(arg);
57     q = argdup;
58
59     if (got_host) {
60         /*
61          * If we already have a host name, treat this argument as a
62          * port number. NB we have to treat this as a saved -P
63          * argument, so that it will be deferred until it's a good
64          * moment to run it.
65          */
66         int ret = cmdline_process_param("-P", argdup, 1, conf);
67         assert(ret == 2);
68     } else if (!strncmp(q, "telnet:", 7)) {
69         /*
70          * If the hostname starts with "telnet:",
71          * set the protocol to Telnet and process
72          * the string as a Telnet URL.
73          */
74         char c;
75
76         q += 7;
77         if (q[0] == '/' && q[1] == '/')
78             q += 2;
79         conf_set_int(conf, CONF_protocol, PROT_TELNET);
80         p = q;
81         p += host_strcspn(p, ":/");
82         c = *p;
83         if (*p)
84             *p++ = '\0';
85         if (c == ':')
86             conf_set_int(conf, CONF_port, atoi(p));
87         else
88             conf_set_int(conf, CONF_port, -1);
89         conf_set_str(conf, CONF_host, q);
90         got_host = 1;
91     } else {
92         /*
93          * Otherwise, treat this argument as a host name.
94          */
95         p = argdup;
96         while (*p && !isspace((unsigned char)*p))
97             p++;
98         if (*p)
99             *p++ = '\0';
100         conf_set_str(conf, CONF_host, q);
101         got_host = 1;
102     }
103     if (got_host)
104         *allow_launch = TRUE;
105
106     sfree(argdup);
107
108     return 1;
109 }
110
111 char *make_default_wintitle(char *hostname)
112 {
113     return dupcat(hostname, " - ", appname, NULL);
114 }
115
116 /*
117  * X11-forwarding-related things suitable for Gtk app.
118  */
119
120 char *platform_get_x_display(void) {
121     const char *display;
122     /* Try to take account of --display and what have you. */
123     if (!(display = gdk_get_display()))
124         /* fall back to traditional method */
125         display = getenv("DISPLAY");
126     return dupstr(display);
127 }
128
129 const int share_can_be_downstream = TRUE;
130 const int share_can_be_upstream = TRUE;
131
132 int main(int argc, char **argv)
133 {
134     extern int pt_main(int argc, char **argv);
135     int ret;
136
137     sk_init();
138     flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
139     default_protocol = be_default_protocol;
140     /* Find the appropriate default port. */
141     {
142         Backend *b = backend_from_proto(default_protocol);
143         default_port = 0; /* illegal */
144         if (b)
145             default_port = b->default_port;
146     }
147     ret = pt_main(argc, argv);
148     cleanup_exit(ret);
149     return ret;             /* not reached, but placates optimisers */
150 }