Add some missing calls to cleanup_exit.
[sgt/putty] / unix / uxputty.c
CommitLineData
1d009ae7 1/*
2 * Unix PuTTY main program.
3 */
4
5#include <stdio.h>
46a3419b 6#include <ctype.h>
5bf9955d 7#include <stdlib.h>
1d009ae7 8#include <assert.h>
1d009ae7 9#include <unistd.h>
46ed7b64 10#include <gdk/gdk.h>
1d009ae7 11
12#include "putty.h"
13#include "storage.h"
14
15/*
fbcc43d3 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/*
1d009ae7 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
4a693cfc 34Backend *select_backend(Conf *conf)
1d009ae7 35{
4a693cfc 36 Backend *back = backend_from_proto(conf_get_int(conf, CONF_protocol));
1d009ae7 37 assert(back != NULL);
38 return back;
39}
40
4a693cfc 41int cfgbox(Conf *conf)
1d009ae7 42{
1705f468 43 char *title = dupcat(appname, " Configuration", NULL);
4a693cfc 44 int ret = do_config_box(title, conf, 0, 0);
1705f468 45 sfree(title);
46 return ret;
1d009ae7 47}
48
46a3419b 49static int got_host = 0;
50
56801e3d 51const int use_event_log = 1, new_session = 1, saved_sessions = 1;
8eed910d 52
4a693cfc 53int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch)
46a3419b 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 */
4a693cfc 64 int ret = cmdline_process_param("-P", arg, 1, conf);
46a3419b 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;
4a693cfc 77 conf_set_int(conf, CONF_protocol, PROT_TELNET);
46a3419b 78 p = q;
79 while (*p && *p != ':' && *p != '/')
80 p++;
81 c = *p;
82 if (*p)
83 *p++ = '\0';
84 if (c == ':')
4a693cfc 85 conf_set_int(conf, CONF_port, atoi(p));
46a3419b 86 else
4a693cfc 87 conf_set_int(conf, CONF_port, -1);
88 conf_set_str(conf, CONF_host, q);
46a3419b 89 got_host = 1;
90 } else {
91 /*
92 * Otherwise, treat this argument as a host name.
93 */
320cb4be 94 p = arg;
46a3419b 95 while (*p && !isspace((unsigned char)*p))
96 p++;
97 if (*p)
98 *p++ = '\0';
4a693cfc 99 conf_set_str(conf, CONF_host, q);
46a3419b 100 got_host = 1;
101 }
df7c7e52 102 if (got_host)
103 *allow_launch = TRUE;
46a3419b 104 return 1;
105}
106
10705014 107char *make_default_wintitle(char *hostname)
108{
1705f468 109 return dupcat(hostname, " - ", appname, NULL);
10705014 110}
111
46ed7b64 112/*
113 * X11-forwarding-related things suitable for Gtk app.
114 */
115
46ed7b64 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
1d009ae7 125int main(int argc, char **argv)
126{
127 extern int pt_main(int argc, char **argv);
f08a390f 128 int ret;
129
1d009ae7 130 sk_init();
131 flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
132 default_protocol = be_default_protocol;
133 /* Find the appropriate default port. */
134 {
9e164d82 135 Backend *b = backend_from_proto(default_protocol);
1d009ae7 136 default_port = 0; /* illegal */
9e164d82 137 if (b)
138 default_port = b->default_port;
1d009ae7 139 }
f08a390f 140 ret = pt_main(argc, argv);
141 cleanup_exit(ret);
142 return ret; /* not reached, but placates optimisers */
1d009ae7 143}