Fix a couple of signedness compiler warnings, presumably due to me
[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
1d009ae7 34Backend *select_backend(Config *cfg)
35{
36 int i;
37 Backend *back = NULL;
38 for (i = 0; backends[i].backend != NULL; i++)
39 if (backends[i].protocol == cfg->protocol) {
40 back = backends[i].backend;
41 break;
42 }
43 assert(back != NULL);
44 return back;
45}
46
47int cfgbox(Config *cfg)
48{
f89c3294 49 return do_config_box("PuTTY Configuration", cfg, 0, 0);
1d009ae7 50}
51
46a3419b 52static int got_host = 0;
53
56801e3d 54const int use_event_log = 1, new_session = 1, saved_sessions = 1;
8eed910d 55
df7c7e52 56int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch)
46a3419b 57{
58 char *p, *q = arg;
59
60 if (got_host) {
61 /*
62 * If we already have a host name, treat this argument as a
63 * port number. NB we have to treat this as a saved -P
64 * argument, so that it will be deferred until it's a good
65 * moment to run it.
66 */
67 int ret = cmdline_process_param("-P", arg, 1, cfg);
68 assert(ret == 2);
69 } else if (!strncmp(q, "telnet:", 7)) {
70 /*
71 * If the hostname starts with "telnet:",
72 * set the protocol to Telnet and process
73 * the string as a Telnet URL.
74 */
75 char c;
76
77 q += 7;
78 if (q[0] == '/' && q[1] == '/')
79 q += 2;
80 cfg->protocol = PROT_TELNET;
81 p = q;
82 while (*p && *p != ':' && *p != '/')
83 p++;
84 c = *p;
85 if (*p)
86 *p++ = '\0';
87 if (c == ':')
88 cfg->port = atoi(p);
89 else
90 cfg->port = -1;
91 strncpy(cfg->host, q, sizeof(cfg->host) - 1);
92 cfg->host[sizeof(cfg->host) - 1] = '\0';
93 got_host = 1;
94 } else {
95 /*
96 * Otherwise, treat this argument as a host name.
97 */
320cb4be 98 p = arg;
46a3419b 99 while (*p && !isspace((unsigned char)*p))
100 p++;
101 if (*p)
102 *p++ = '\0';
103 strncpy(cfg->host, q, sizeof(cfg->host) - 1);
104 cfg->host[sizeof(cfg->host) - 1] = '\0';
105 got_host = 1;
106 }
df7c7e52 107 if (got_host)
108 *allow_launch = TRUE;
46a3419b 109 return 1;
110}
111
10705014 112char *make_default_wintitle(char *hostname)
113{
114 return dupcat(hostname, " - PuTTY", NULL);
115}
116
46ed7b64 117/*
118 * X11-forwarding-related things suitable for Gtk app.
119 */
120
121const char platform_x11_best_transport[] = "unix";
122
123char *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
1d009ae7 132int main(int argc, char **argv)
133{
134 extern int pt_main(int argc, char **argv);
135 sk_init();
136 flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
137 default_protocol = be_default_protocol;
138 /* Find the appropriate default port. */
139 {
140 int i;
141 default_port = 0; /* illegal */
142 for (i = 0; backends[i].backend != NULL; i++)
143 if (backends[i].protocol == default_protocol) {
144 default_port = backends[i].backend->default_port;
145 break;
146 }
147 }
148 return pt_main(argc, argv);
149}