Loose end from r5031: the Kex panel should only be displayed in
[u/mdw/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/*
1d009ae7 16 * Clean up and exit.
17 */
18void cleanup_exit(int code)
19{
20 /*
21 * Clean up.
22 */
23 sk_cleanup();
24 random_save_seed();
25 exit(code);
26}
27
1d009ae7 28Backend *select_backend(Config *cfg)
29{
30 int i;
31 Backend *back = NULL;
32 for (i = 0; backends[i].backend != NULL; i++)
33 if (backends[i].protocol == cfg->protocol) {
34 back = backends[i].backend;
35 break;
36 }
37 assert(back != NULL);
38 return back;
39}
40
41int cfgbox(Config *cfg)
42{
f89c3294 43 return do_config_box("PuTTY Configuration", cfg, 0, 0);
1d009ae7 44}
45
46a3419b 46static int got_host = 0;
47
56801e3d 48const int use_event_log = 1, new_session = 1, saved_sessions = 1;
8eed910d 49
46a3419b 50int process_nonoption_arg(char *arg, Config *cfg)
51{
52 char *p, *q = arg;
53
54 if (got_host) {
55 /*
56 * If we already have a host name, treat this argument as a
57 * port number. NB we have to treat this as a saved -P
58 * argument, so that it will be deferred until it's a good
59 * moment to run it.
60 */
61 int ret = cmdline_process_param("-P", arg, 1, cfg);
62 assert(ret == 2);
63 } else if (!strncmp(q, "telnet:", 7)) {
64 /*
65 * If the hostname starts with "telnet:",
66 * set the protocol to Telnet and process
67 * the string as a Telnet URL.
68 */
69 char c;
70
71 q += 7;
72 if (q[0] == '/' && q[1] == '/')
73 q += 2;
74 cfg->protocol = PROT_TELNET;
75 p = q;
76 while (*p && *p != ':' && *p != '/')
77 p++;
78 c = *p;
79 if (*p)
80 *p++ = '\0';
81 if (c == ':')
82 cfg->port = atoi(p);
83 else
84 cfg->port = -1;
85 strncpy(cfg->host, q, sizeof(cfg->host) - 1);
86 cfg->host[sizeof(cfg->host) - 1] = '\0';
87 got_host = 1;
88 } else {
89 /*
90 * Otherwise, treat this argument as a host name.
91 */
320cb4be 92 p = arg;
46a3419b 93 while (*p && !isspace((unsigned char)*p))
94 p++;
95 if (*p)
96 *p++ = '\0';
97 strncpy(cfg->host, q, sizeof(cfg->host) - 1);
98 cfg->host[sizeof(cfg->host) - 1] = '\0';
99 got_host = 1;
100 }
101 return 1;
102}
103
10705014 104char *make_default_wintitle(char *hostname)
105{
106 return dupcat(hostname, " - PuTTY", NULL);
107}
108
46ed7b64 109/*
110 * X11-forwarding-related things suitable for Gtk app.
111 */
112
113const char platform_x11_best_transport[] = "unix";
114
115char *platform_get_x_display(void) {
116 const char *display;
117 /* Try to take account of --display and what have you. */
118 if (!(display = gdk_get_display()))
119 /* fall back to traditional method */
120 display = getenv("DISPLAY");
121 return dupstr(display);
122}
123
1d009ae7 124int main(int argc, char **argv)
125{
126 extern int pt_main(int argc, char **argv);
127 sk_init();
128 flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
129 default_protocol = be_default_protocol;
130 /* Find the appropriate default port. */
131 {
132 int i;
133 default_port = 0; /* illegal */
134 for (i = 0; backends[i].backend != NULL; i++)
135 if (backends[i].protocol == default_protocol) {
136 default_port = backends[i].backend->default_port;
137 break;
138 }
139 }
140 return pt_main(argc, argv);
141}