]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - unix/uxputty.c
New FAQ entry for 32-bit vs 64-bit.
[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 char *pty_osx_envrestore_prefix;
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(Conf *conf)
39 {
40     Backend *back = backend_from_proto(conf_get_int(conf, CONF_protocol));
41     assert(back != NULL);
42     return back;
43 }
44
45 int cfgbox(Conf *conf)
46 {
47     char *title = dupcat(appname, " Configuration", NULL);
48     int ret = do_config_box(title, conf, 0, 0);
49     sfree(title);
50     return ret;
51 }
52
53 static int got_host = 0;
54
55 const int use_event_log = 1, new_session = 1, saved_sessions = 1;
56 const int dup_check_launchable = 1;
57
58 int process_nonoption_arg(const char *arg, Conf *conf, int *allow_launch)
59 {
60     char *argdup, *p, *q;
61     argdup = dupstr(arg);
62     q = argdup;
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", argdup, 1, conf);
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         conf_set_int(conf, CONF_protocol, PROT_TELNET);
85         p = q;
86         p += host_strcspn(p, ":/");
87         c = *p;
88         if (*p)
89             *p++ = '\0';
90         if (c == ':')
91             conf_set_int(conf, CONF_port, atoi(p));
92         else
93             conf_set_int(conf, CONF_port, -1);
94         conf_set_str(conf, CONF_host, q);
95         got_host = 1;
96     } else {
97         /*
98          * Otherwise, treat this argument as a host name.
99          */
100         p = argdup;
101         while (*p && !isspace((unsigned char)*p))
102             p++;
103         if (*p)
104             *p++ = '\0';
105         conf_set_str(conf, CONF_host, q);
106         got_host = 1;
107     }
108     if (got_host)
109         *allow_launch = TRUE;
110
111     sfree(argdup);
112
113     return 1;
114 }
115
116 char *make_default_wintitle(char *hostname)
117 {
118     return dupcat(hostname, " - ", appname, NULL);
119 }
120
121 /*
122  * X11-forwarding-related things suitable for Gtk app.
123  */
124
125 char *platform_get_x_display(void) {
126     const char *display;
127     /* Try to take account of --display and what have you. */
128     if (!(display = gdk_get_display()))
129         /* fall back to traditional method */
130         display = getenv("DISPLAY");
131     return dupstr(display);
132 }
133
134 const int share_can_be_downstream = TRUE;
135 const int share_can_be_upstream = TRUE;
136
137 void setup(int single)
138 {
139     sk_init();
140     flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
141     default_protocol = be_default_protocol;
142     /* Find the appropriate default port. */
143     {
144         Backend *b = backend_from_proto(default_protocol);
145         default_port = 0; /* illegal */
146         if (b)
147             default_port = b->default_port;
148     }
149 }