]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - unix/uxputty.c
73e119731d500d1779f2531787e392eb9c97d703
[PuTTY.git] / unix / uxputty.c
1 /*
2  * Unix PuTTY main program.
3  */
4
5 #include <stdio.h>
6 #include <ctype.h>
7 #include <stdlib.h>
8 #include <assert.h>
9 #include <unistd.h>
10 #include <gdk/gdk.h>
11
12 #include "putty.h"
13 #include "storage.h"
14
15 /*
16  * Stubs to avoid uxpty.c needing to be linked in.
17  */
18 const int use_pty_argv = FALSE;
19 char **pty_argv;                       /* never used */
20
21 /*
22  * Clean up and exit.
23  */
24 void cleanup_exit(int code)
25 {
26     /*
27      * Clean up.
28      */
29     sk_cleanup();
30     random_save_seed();
31     exit(code);
32 }
33
34 Backend *select_backend(Config *cfg)
35 {
36     Backend *back = backend_from_proto(cfg->protocol);
37     assert(back != NULL);
38     return back;
39 }
40
41 int cfgbox(Config *cfg)
42 {
43     char *title = dupcat(appname, " Configuration", NULL);
44     int ret = do_config_box(title, cfg, 0, 0);
45     sfree(title);
46     return ret;
47 }
48
49 static int got_host = 0;
50
51 const int use_event_log = 1, new_session = 1, saved_sessions = 1;
52
53 int process_nonoption_arg(char *arg, Config *cfg, int *allow_launch)
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          */
95         p = arg;
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     }
104     if (got_host)
105         *allow_launch = TRUE;
106     return 1;
107 }
108
109 char *make_default_wintitle(char *hostname)
110 {
111     return dupcat(hostname, " - ", appname, NULL);
112 }
113
114 /*
115  * X11-forwarding-related things suitable for Gtk app.
116  */
117
118 char *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
127 int 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     {
135         Backend *b = backend_from_proto(default_protocol);
136         default_port = 0; /* illegal */
137         if (b)
138             default_port = b->default_port;
139     }
140     return pt_main(argc, argv);
141 }