"-noagent" and friends should be marked SAVEABLE, to ensure they're not
[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/*
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
46a3419b 56int process_nonoption_arg(char *arg, Config *cfg)
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 }
107 return 1;
108}
109
10705014 110char *make_default_wintitle(char *hostname)
111{
112 return dupcat(hostname, " - PuTTY", NULL);
113}
114
46ed7b64 115/*
116 * X11-forwarding-related things suitable for Gtk app.
117 */
118
119const char platform_x11_best_transport[] = "unix";
120
121char *platform_get_x_display(void) {
122 const char *display;
123 /* Try to take account of --display and what have you. */
124 if (!(display = gdk_get_display()))
125 /* fall back to traditional method */
126 display = getenv("DISPLAY");
127 return dupstr(display);
128}
129
1d009ae7 130int main(int argc, char **argv)
131{
132 extern int pt_main(int argc, char **argv);
133 sk_init();
134 flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
135 default_protocol = be_default_protocol;
136 /* Find the appropriate default port. */
137 {
138 int i;
139 default_port = 0; /* illegal */
140 for (i = 0; backends[i].backend != NULL; i++)
141 if (backends[i].protocol == default_protocol) {
142 default_port = backends[i].backend->default_port;
143 break;
144 }
145 }
146 return pt_main(argc, argv);
147}