]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - unix/uxputty.c
Create OS X application bundles for PuTTY and pterm.
[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 <gtk/gtk.h>
11 #include <gdk/gdk.h>
12
13 #include "putty.h"
14 #include "storage.h"
15
16 #include "gtkcompat.h"
17
18 /*
19  * Stubs to avoid uxpty.c needing to be linked in.
20  */
21 const int use_pty_argv = FALSE;
22 char **pty_argv;                       /* never used */
23 char *pty_osx_envrestore_prefix;
24
25 /*
26  * Clean up and exit.
27  */
28 void cleanup_exit(int code)
29 {
30     /*
31      * Clean up.
32      */
33     sk_cleanup();
34     random_save_seed();
35     exit(code);
36 }
37
38 Backend *select_backend(Conf *conf)
39 {
40     Backend *back = backend_from_proto(conf_get_int(conf, CONF_protocol));
41     assert(back != NULL);
42     return back;
43 }
44
45 int cfgbox(Conf *conf)
46 {
47     char *title = dupcat(appname, " Configuration", NULL);
48     int ret = do_config_box(title, conf, 0, 0);
49     sfree(title);
50     return ret;
51 }
52
53 static int got_host = 0;
54
55 const int use_event_log = 1, new_session = 1, saved_sessions = 1;
56
57 int process_nonoption_arg(const char *arg, Conf *conf, int *allow_launch)
58 {
59     char *argdup, *p, *q;
60     argdup = dupstr(arg);
61     q = argdup;
62
63     if (got_host) {
64         /*
65          * If we already have a host name, treat this argument as a
66          * port number. NB we have to treat this as a saved -P
67          * argument, so that it will be deferred until it's a good
68          * moment to run it.
69          */
70         int ret = cmdline_process_param("-P", argdup, 1, conf);
71         assert(ret == 2);
72     } else if (!strncmp(q, "telnet:", 7)) {
73         /*
74          * If the hostname starts with "telnet:",
75          * set the protocol to Telnet and process
76          * the string as a Telnet URL.
77          */
78         char c;
79
80         q += 7;
81         if (q[0] == '/' && q[1] == '/')
82             q += 2;
83         conf_set_int(conf, CONF_protocol, PROT_TELNET);
84         p = q;
85         p += host_strcspn(p, ":/");
86         c = *p;
87         if (*p)
88             *p++ = '\0';
89         if (c == ':')
90             conf_set_int(conf, CONF_port, atoi(p));
91         else
92             conf_set_int(conf, CONF_port, -1);
93         conf_set_str(conf, CONF_host, q);
94         got_host = 1;
95     } else {
96         /*
97          * Otherwise, treat this argument as a host name.
98          */
99         p = argdup;
100         while (*p && !isspace((unsigned char)*p))
101             p++;
102         if (*p)
103             *p++ = '\0';
104         conf_set_str(conf, CONF_host, q);
105         got_host = 1;
106     }
107     if (got_host)
108         *allow_launch = TRUE;
109
110     sfree(argdup);
111
112     return 1;
113 }
114
115 char *make_default_wintitle(char *hostname)
116 {
117     return dupcat(hostname, " - ", appname, NULL);
118 }
119
120 /*
121  * X11-forwarding-related things suitable for Gtk app.
122  */
123
124 char *platform_get_x_display(void) {
125     const char *display;
126     /* Try to take account of --display and what have you. */
127     if (!(display = gdk_get_display()))
128         /* fall back to traditional method */
129         display = getenv("DISPLAY");
130     return dupstr(display);
131 }
132
133 const int share_can_be_downstream = TRUE;
134 const int share_can_be_upstream = TRUE;
135
136 void setup(int single)
137 {
138     sk_init();
139     flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
140     default_protocol = be_default_protocol;
141     /* Find the appropriate default port. */
142     {
143         Backend *b = backend_from_proto(default_protocol);
144         default_port = 0; /* illegal */
145         if (b)
146             default_port = b->default_port;
147     }
148 }