RJK's `pterm --help' patch. I _must_ find a better alternative to
[u/mdw/putty] / unix / uxstore.c
CommitLineData
1709795f 1/*
2 * uxstore.c: Unix-specific implementation of the interface defined
3 * in storage.h.
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
0ac15bdc 8#include <ctype.h>
faec60ed 9#include <gtk/gtk.h>
10#include <gdk/gdkx.h>
11#include <X11/Xlib.h>
1709795f 12#include "putty.h"
13#include "storage.h"
0ac15bdc 14#include "tree234.h"
1709795f 15
faec60ed 16/*
17 * For the moment, the only existing Unix utility is pterm and that
18 * has no GUI configuration at all, so our write routines need do
19 * nothing. Eventually I suppose these will read and write an rc
20 * file somewhere or other.
21 */
1709795f 22
23void *open_settings_w(char *sessionname)
24{
25 return NULL;
26}
27
28void write_setting_s(void *handle, char *key, char *value)
29{
30}
31
32void write_setting_i(void *handle, char *key, int value)
33{
34}
35
36void close_settings_w(void *handle)
37{
38}
39
faec60ed 40/*
41 * Reading settings, for the moment, is done by retrieving X
42 * resources from the X display. When we introduce disk files, I
43 * think what will happen is that the X resources will override
44 * PuTTY's inbuilt defaults, but that the disk files will then
45 * override those. This isn't optimal, but it's the best I can
46 * immediately work out.
47 */
48
49static Display *display;
50
0ac15bdc 51struct xrm_string {
52 char *key;
53 char *value;
54};
55
56static tree234 *xrmtree = NULL;
57
58int xrmcmp(void *av, void *bv)
59{
60 struct xrm_string *a = (struct xrm_string *)av;
61 struct xrm_string *b = (struct xrm_string *)bv;
62 return strcmp(a->key, b->key);
63}
64
65void provide_xrm_string(char *string)
66{
67 char *p, *q;
68 struct xrm_string *xrms, *ret;
69
70 p = q = strchr(string, ':');
71 if (!q) {
72 fprintf(stderr, "pterm: expected a colon in resource string"
73 " \"%s\"\n", string);
74 return;
75 }
76 q++;
77 while (p > string && p[-1] != '.' && p[-1] != '*')
78 p--;
79 xrms = smalloc(sizeof(struct xrm_string));
80 xrms->key = smalloc(q-p);
81 memcpy(xrms->key, p, q-p);
82 xrms->key[q-p-1] = '\0';
83 while (*q && isspace(*q))
84 q++;
85 xrms->value = dupstr(q);
86
87 if (!xrmtree)
88 xrmtree = newtree234(xrmcmp);
89
90 ret = add234(xrmtree, xrms);
91 if (ret) {
92 /* Override an existing string. */
93 del234(xrmtree, ret);
94 add234(xrmtree, xrms);
95 }
96}
97
98char *get_setting(char *key)
99{
100 struct xrm_string tmp, *ret;
101 tmp.key = key;
102 if (xrmtree) {
103 ret = find234(xrmtree, &tmp, NULL);
104 if (ret)
105 return ret->value;
106 }
107 return XGetDefault(display, app_name, key);
108}
109
1709795f 110void *open_settings_r(char *sessionname)
111{
faec60ed 112 static int thing_to_return_an_arbitrary_non_null_pointer_to;
113 display = GDK_DISPLAY();
114 if (!display)
115 return NULL;
116 else
117 return &thing_to_return_an_arbitrary_non_null_pointer_to;
1709795f 118}
119
120char *read_setting_s(void *handle, char *key, char *buffer, int buflen)
121{
0ac15bdc 122 char *val = get_setting(key);
faec60ed 123 if (!val)
124 return NULL;
125 else {
126 strncpy(buffer, val, buflen);
127 buffer[buflen-1] = '\0';
128 return buffer;
129 }
1709795f 130}
131
132int read_setting_i(void *handle, char *key, int defvalue)
133{
0ac15bdc 134 char *val = get_setting(key);
faec60ed 135 if (!val)
136 return defvalue;
137 else
138 return atoi(val);
1709795f 139}
140
141void close_settings_r(void *handle)
142{
143}
144
145void del_settings(char *sessionname)
146{
147}
148
149void *enum_settings_start(void)
150{
151 return NULL;
152}
153
154char *enum_settings_next(void *handle, char *buffer, int buflen)
155{
156 return NULL;
157}
158
159void enum_settings_finish(void *handle)
160{
161}
162
163int verify_host_key(char *hostname, int port, char *keytype, char *key)
164{
165 return 1; /* key does not exist in registry */
166}
167
168void store_host_key(char *hostname, int port, char *keytype, char *key)
169{
170}
171
172void read_random_seed(noise_consumer_t consumer)
173{
174}
175
176void write_random_seed(void *data, int len)
177{
178}
179
180void cleanup_all(void)
181{
182}