Readjust checklist, because actually the section on updating the
[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{
9e164d82 36 Backend *back = backend_from_proto(cfg->protocol);
1d009ae7 37 assert(back != NULL);
38 return back;
39}
40
41int cfgbox(Config *cfg)
42{
1705f468 43 char *title = dupcat(appname, " Configuration", NULL);
44 int ret = do_config_box(title, cfg, 0, 0);
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
df7c7e52 53int process_nonoption_arg(char *arg, Config *cfg, 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 */
64 int ret = cmdline_process_param("-P", arg, 1, cfg);
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 cfg->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 cfg->port = atoi(p);
86 else
87 cfg->port = -1;
88 strncpy(cfg->host, q, sizeof(cfg->host) - 1);
89 cfg->host[sizeof(cfg->host) - 1] = '\0';
90 got_host = 1;
91 } else {
92 /*
93 * Otherwise, treat this argument as a host name.
94 */
320cb4be 95 p = arg;
46a3419b 96 while (*p && !isspace((unsigned char)*p))
97 p++;
98 if (*p)
99 *p++ = '\0';
100 strncpy(cfg->host, q, sizeof(cfg->host) - 1);
101 cfg->host[sizeof(cfg->host) - 1] = '\0';
102 got_host = 1;
103 }
df7c7e52 104 if (got_host)
105 *allow_launch = TRUE;
46a3419b 106 return 1;
107}
108
10705014 109char *make_default_wintitle(char *hostname)
110{
1705f468 111 return dupcat(hostname, " - ", appname, NULL);
10705014 112}
113
46ed7b64 114/*
115 * X11-forwarding-related things suitable for Gtk app.
116 */
117
46ed7b64 118char *platform_get_x_display(void) {
119 const char *display;
120 /* Try to take account of --display and what have you. */
121 if (!(display = gdk_get_display()))
122 /* fall back to traditional method */
123 display = getenv("DISPLAY");
124 return dupstr(display);
125}
126
1d009ae7 127int main(int argc, char **argv)
128{
129 extern int pt_main(int argc, char **argv);
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 }
140 return pt_main(argc, argv);
141}