Add some missing calls to cleanup_exit.
[sgt/putty] / unix / uxputty.c
... / ...
CommitLineData
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 */
18const int use_pty_argv = FALSE;
19char **pty_argv; /* never used */
20
21/*
22 * Clean up and exit.
23 */
24void cleanup_exit(int code)
25{
26 /*
27 * Clean up.
28 */
29 sk_cleanup();
30 random_save_seed();
31 exit(code);
32}
33
34Backend *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
41int 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
49static int got_host = 0;
50
51const int use_event_log = 1, new_session = 1, saved_sessions = 1;
52
53int 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 while (*p && *p != ':' && *p != '/')
80 p++;
81 c = *p;
82 if (*p)
83 *p++ = '\0';
84 if (c == ':')
85 conf_set_int(conf, CONF_port, atoi(p));
86 else
87 conf_set_int(conf, CONF_port, -1);
88 conf_set_str(conf, CONF_host, q);
89 got_host = 1;
90 } else {
91 /*
92 * Otherwise, treat this argument as a host name.
93 */
94 p = arg;
95 while (*p && !isspace((unsigned char)*p))
96 p++;
97 if (*p)
98 *p++ = '\0';
99 conf_set_str(conf, CONF_host, q);
100 got_host = 1;
101 }
102 if (got_host)
103 *allow_launch = TRUE;
104 return 1;
105}
106
107char *make_default_wintitle(char *hostname)
108{
109 return dupcat(hostname, " - ", appname, NULL);
110}
111
112/*
113 * X11-forwarding-related things suitable for Gtk app.
114 */
115
116char *platform_get_x_display(void) {
117 const char *display;
118 /* Try to take account of --display and what have you. */
119 if (!(display = gdk_get_display()))
120 /* fall back to traditional method */
121 display = getenv("DISPLAY");
122 return dupstr(display);
123}
124
125int main(int argc, char **argv)
126{
127 extern int pt_main(int argc, char **argv);
128 int ret;
129
130 sk_init();
131 flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
132 default_protocol = be_default_protocol;
133 /* Find the appropriate default port. */
134 {
135 Backend *b = backend_from_proto(default_protocol);
136 default_port = 0; /* illegal */
137 if (b)
138 default_port = b->default_port;
139 }
140 ret = pt_main(argc, argv);
141 cleanup_exit(ret);
142 return ret; /* not reached, but placates optimisers */
143}