mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
Add the -xrm command-line option, to allow specification of an
arbitrary X resource which doesn't have a dedicated command-line option. [originally from svn r2089]
This commit is contained in:
parent
e70c66b8b0
commit
3c6a770e9f
@ -97,6 +97,12 @@ enables you to play NetHack with the numeric keypad without having
|
|||||||
to use the NetHack "number_pad" option (which requires you to press
|
to use the NetHack "number_pad" option (which requires you to press
|
||||||
"n" before any repeat count). So you can move with the numeric
|
"n" before any repeat count). So you can move with the numeric
|
||||||
keypad, and enter repeat counts with the normal number keys.
|
keypad, and enter repeat counts with the normal number keys.
|
||||||
|
.IP "\fB-xrm\fP \fIresource-string\fP"
|
||||||
|
This option specifies an X resource string. Useful for setting
|
||||||
|
resources which do not have their own command-line options. For
|
||||||
|
example:
|
||||||
|
|
||||||
|
pterm -xrm 'ScrollbarOnLeft: 1'
|
||||||
.SH X RESOURCES
|
.SH X RESOURCES
|
||||||
\fIpterm\fP can be more completely configured by means of X
|
\fIpterm\fP can be more completely configured by means of X
|
||||||
resources. All of these resources are of the form \fIpterm.FOO\fP
|
resources. All of these resources are of the form \fIpterm.FOO\fP
|
||||||
|
@ -1733,6 +1733,11 @@ int do_cmdline(int argc, char **argv, int do_everything)
|
|||||||
} else if (!strcmp(p, "-name")) {
|
} else if (!strcmp(p, "-name")) {
|
||||||
EXPECTS_ARG;
|
EXPECTS_ARG;
|
||||||
app_name = val;
|
app_name = val;
|
||||||
|
|
||||||
|
} else if (!strcmp(p, "-xrm")) {
|
||||||
|
EXPECTS_ARG;
|
||||||
|
provide_xrm_string(val);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,9 @@ int font_dimension(int which); /* 0 for width, 1 for height */
|
|||||||
/* Things uxstore.c needs from pterm.c */
|
/* Things uxstore.c needs from pterm.c */
|
||||||
char *app_name; /* for doing resource lookups */
|
char *app_name; /* for doing resource lookups */
|
||||||
|
|
||||||
|
/* Things uxstore.c provides to pterm.c */
|
||||||
|
void provide_xrm_string(char *string);
|
||||||
|
|
||||||
#define DEFAULT_CODEPAGE 0 /* FIXME: no idea how to do this */
|
#define DEFAULT_CODEPAGE 0 /* FIXME: no idea how to do this */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,11 +5,13 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <gdk/gdkx.h>
|
#include <gdk/gdkx.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include "putty.h"
|
#include "putty.h"
|
||||||
#include "storage.h"
|
#include "storage.h"
|
||||||
|
#include "tree234.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For the moment, the only existing Unix utility is pterm and that
|
* For the moment, the only existing Unix utility is pterm and that
|
||||||
@ -46,6 +48,65 @@ void close_settings_w(void *handle)
|
|||||||
|
|
||||||
static Display *display;
|
static Display *display;
|
||||||
|
|
||||||
|
struct xrm_string {
|
||||||
|
char *key;
|
||||||
|
char *value;
|
||||||
|
};
|
||||||
|
|
||||||
|
static tree234 *xrmtree = NULL;
|
||||||
|
|
||||||
|
int xrmcmp(void *av, void *bv)
|
||||||
|
{
|
||||||
|
struct xrm_string *a = (struct xrm_string *)av;
|
||||||
|
struct xrm_string *b = (struct xrm_string *)bv;
|
||||||
|
return strcmp(a->key, b->key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void provide_xrm_string(char *string)
|
||||||
|
{
|
||||||
|
char *p, *q;
|
||||||
|
struct xrm_string *xrms, *ret;
|
||||||
|
|
||||||
|
p = q = strchr(string, ':');
|
||||||
|
if (!q) {
|
||||||
|
fprintf(stderr, "pterm: expected a colon in resource string"
|
||||||
|
" \"%s\"\n", string);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
q++;
|
||||||
|
while (p > string && p[-1] != '.' && p[-1] != '*')
|
||||||
|
p--;
|
||||||
|
xrms = smalloc(sizeof(struct xrm_string));
|
||||||
|
xrms->key = smalloc(q-p);
|
||||||
|
memcpy(xrms->key, p, q-p);
|
||||||
|
xrms->key[q-p-1] = '\0';
|
||||||
|
while (*q && isspace(*q))
|
||||||
|
q++;
|
||||||
|
xrms->value = dupstr(q);
|
||||||
|
|
||||||
|
if (!xrmtree)
|
||||||
|
xrmtree = newtree234(xrmcmp);
|
||||||
|
|
||||||
|
ret = add234(xrmtree, xrms);
|
||||||
|
if (ret) {
|
||||||
|
/* Override an existing string. */
|
||||||
|
del234(xrmtree, ret);
|
||||||
|
add234(xrmtree, xrms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *get_setting(char *key)
|
||||||
|
{
|
||||||
|
struct xrm_string tmp, *ret;
|
||||||
|
tmp.key = key;
|
||||||
|
if (xrmtree) {
|
||||||
|
ret = find234(xrmtree, &tmp, NULL);
|
||||||
|
if (ret)
|
||||||
|
return ret->value;
|
||||||
|
}
|
||||||
|
return XGetDefault(display, app_name, key);
|
||||||
|
}
|
||||||
|
|
||||||
void *open_settings_r(char *sessionname)
|
void *open_settings_r(char *sessionname)
|
||||||
{
|
{
|
||||||
static int thing_to_return_an_arbitrary_non_null_pointer_to;
|
static int thing_to_return_an_arbitrary_non_null_pointer_to;
|
||||||
@ -58,7 +119,7 @@ void *open_settings_r(char *sessionname)
|
|||||||
|
|
||||||
char *read_setting_s(void *handle, char *key, char *buffer, int buflen)
|
char *read_setting_s(void *handle, char *key, char *buffer, int buflen)
|
||||||
{
|
{
|
||||||
char *val = XGetDefault(display, app_name, key);
|
char *val = get_setting(key);
|
||||||
if (!val)
|
if (!val)
|
||||||
return NULL;
|
return NULL;
|
||||||
else {
|
else {
|
||||||
@ -70,7 +131,7 @@ char *read_setting_s(void *handle, char *key, char *buffer, int buflen)
|
|||||||
|
|
||||||
int read_setting_i(void *handle, char *key, int defvalue)
|
int read_setting_i(void *handle, char *key, int defvalue)
|
||||||
{
|
{
|
||||||
char *val = XGetDefault(display, app_name, key);
|
char *val = get_setting(key);
|
||||||
if (!val)
|
if (!val)
|
||||||
return defvalue;
|
return defvalue;
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user