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