mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-02-09 16:36:34 +00:00
Implement reading of X resources, and -name to change the name under
which to look them up. [originally from svn r2084]
This commit is contained in:
parent
50ca5c1daf
commit
1f2ee65ae9
132
unix/pterm.c
132
unix/pterm.c
@ -1581,36 +1581,47 @@ char *get_x_display(void)
|
|||||||
return gdk_get_display();
|
return gdk_get_display();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
char *app_name = "pterm";
|
||||||
|
|
||||||
|
int do_cmdline(int argc, char **argv, int do_everything)
|
||||||
{
|
{
|
||||||
extern int pty_master_fd; /* declared in pty.c */
|
|
||||||
extern char **pty_argv; /* declared in pty.c */
|
|
||||||
extern void pty_pre_init(void); /* declared in pty.c */
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
extern char **pty_argv; /* declared in pty.c */
|
||||||
|
|
||||||
pty_pre_init();
|
/*
|
||||||
|
* Macros to make argument handling easier.
|
||||||
gtk_init(&argc, &argv);
|
*/
|
||||||
|
#define EXPECTS_ARG do { \
|
||||||
do_defaults(NULL, &cfg);
|
if (--argc <= 0) { \
|
||||||
|
err = 1; \
|
||||||
|
fprintf(stderr, "pterm: %s expects an argument\n", p); \
|
||||||
|
} else \
|
||||||
|
val = *++argv; \
|
||||||
|
} while (0)
|
||||||
|
#define SECOND_PASS_ONLY do { \
|
||||||
|
if (!do_everything) continue; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
char *val;
|
||||||
while (--argc > 0) {
|
while (--argc > 0) {
|
||||||
char *p = *++argv;
|
char *p = *++argv;
|
||||||
if (!strcmp(p, "-fn")) {
|
if (!strcmp(p, "-fn")) {
|
||||||
if (--argc > 0) {
|
EXPECTS_ARG;
|
||||||
strncpy(cfg.font, *++argv, sizeof(cfg.font));
|
SECOND_PASS_ONLY;
|
||||||
cfg.font[sizeof(cfg.font)-1] = '\0';
|
strncpy(cfg.font, val, sizeof(cfg.font));
|
||||||
} else
|
cfg.font[sizeof(cfg.font)-1] = '\0';
|
||||||
err = 1, fprintf(stderr, "pterm: -fn expects an argument\n");
|
|
||||||
}
|
} else if (!strcmp(p, "-fb")) {
|
||||||
if (!strcmp(p, "-fb")) {
|
EXPECTS_ARG;
|
||||||
if (--argc > 0) {
|
SECOND_PASS_ONLY;
|
||||||
strncpy(cfg.boldfont, *++argv, sizeof(cfg.boldfont));
|
strncpy(cfg.boldfont, val, sizeof(cfg.boldfont));
|
||||||
cfg.boldfont[sizeof(cfg.boldfont)-1] = '\0';
|
cfg.boldfont[sizeof(cfg.boldfont)-1] = '\0';
|
||||||
} else
|
|
||||||
err = 1, fprintf(stderr, "pterm: -fb expects an argument\n");
|
} else if (!strcmp(p, "-e")) {
|
||||||
}
|
/* This option swallows all further arguments. */
|
||||||
if (!strcmp(p, "-e")) {
|
if (!do_everything)
|
||||||
|
break;
|
||||||
|
|
||||||
if (--argc > 0) {
|
if (--argc > 0) {
|
||||||
int i;
|
int i;
|
||||||
pty_argv = smalloc((argc+1) * sizeof(char *));
|
pty_argv = smalloc((argc+1) * sizeof(char *));
|
||||||
@ -1621,39 +1632,64 @@ int main(int argc, char **argv)
|
|||||||
break; /* finished command-line processing */
|
break; /* finished command-line processing */
|
||||||
} else
|
} else
|
||||||
err = 1, fprintf(stderr, "pterm: -e expects an argument\n");
|
err = 1, fprintf(stderr, "pterm: -e expects an argument\n");
|
||||||
}
|
|
||||||
if (!strcmp(p, "-T")) {
|
} else if (!strcmp(p, "-T")) {
|
||||||
if (--argc > 0) {
|
EXPECTS_ARG;
|
||||||
strncpy(cfg.wintitle, *++argv, sizeof(cfg.wintitle));
|
SECOND_PASS_ONLY;
|
||||||
cfg.wintitle[sizeof(cfg.wintitle)-1] = '\0';
|
strncpy(cfg.wintitle, val, sizeof(cfg.wintitle));
|
||||||
} else
|
cfg.wintitle[sizeof(cfg.wintitle)-1] = '\0';
|
||||||
err = 1, fprintf(stderr, "pterm: -T expects an argument\n");
|
|
||||||
}
|
} else if (!strcmp(p, "-log")) {
|
||||||
if (!strcmp(p, "-log")) {
|
EXPECTS_ARG;
|
||||||
if (--argc > 0) {
|
SECOND_PASS_ONLY;
|
||||||
strncpy(cfg.logfilename, *++argv, sizeof(cfg.logfilename));
|
strncpy(cfg.logfilename, val, sizeof(cfg.logfilename));
|
||||||
cfg.logfilename[sizeof(cfg.logfilename)-1] = '\0';
|
cfg.logfilename[sizeof(cfg.logfilename)-1] = '\0';
|
||||||
cfg.logtype = LGTYP_DEBUG;
|
cfg.logtype = LGTYP_DEBUG;
|
||||||
} else
|
|
||||||
err = 1, fprintf(stderr, "pterm: -log expects an argument\n");
|
} else if (!strcmp(p, "-hide")) {
|
||||||
}
|
SECOND_PASS_ONLY;
|
||||||
if (!strcmp(p, "-hide")) {
|
|
||||||
cfg.hide_mouseptr = 1;
|
cfg.hide_mouseptr = 1;
|
||||||
}
|
|
||||||
if (!strcmp(p, "-ut-")) {
|
} else if (!strcmp(p, "-ut-")) {
|
||||||
|
SECOND_PASS_ONLY;
|
||||||
cfg.stamp_utmp = 0;
|
cfg.stamp_utmp = 0;
|
||||||
}
|
|
||||||
if (!strcmp(p, "-ls-")) {
|
} else if (!strcmp(p, "-ls-")) {
|
||||||
|
SECOND_PASS_ONLY;
|
||||||
cfg.login_shell = 0;
|
cfg.login_shell = 0;
|
||||||
}
|
|
||||||
if (!strcmp(p, "-nethack")) {
|
} else if (!strcmp(p, "-nethack")) {
|
||||||
|
SECOND_PASS_ONLY;
|
||||||
cfg.nethack_keypad = 1;
|
cfg.nethack_keypad = 1;
|
||||||
}
|
|
||||||
if (!strcmp(p, "-sb-")) {
|
} else if (!strcmp(p, "-sb-")) {
|
||||||
|
SECOND_PASS_ONLY;
|
||||||
cfg.scrollbar = 0;
|
cfg.scrollbar = 0;
|
||||||
|
|
||||||
|
} else if (!strcmp(p, "-name")) {
|
||||||
|
EXPECTS_ARG;
|
||||||
|
app_name = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
extern int pty_master_fd; /* declared in pty.c */
|
||||||
|
extern void pty_pre_init(void); /* declared in pty.c */
|
||||||
|
|
||||||
|
pty_pre_init();
|
||||||
|
|
||||||
|
gtk_init(&argc, &argv);
|
||||||
|
|
||||||
|
if (do_cmdline(argc, argv, 0)) /* pre-defaults pass to get -class */
|
||||||
|
exit(1);
|
||||||
|
do_defaults(NULL, &cfg);
|
||||||
|
if (do_cmdline(argc, argv, 1)) /* post-defaults, do everything */
|
||||||
|
exit(1);
|
||||||
|
|
||||||
inst->fonts[0] = gdk_font_load(cfg.font);
|
inst->fonts[0] = gdk_font_load(cfg.font);
|
||||||
if (!inst->fonts[0]) {
|
if (!inst->fonts[0]) {
|
||||||
fprintf(stderr, "pterm: unable to load font \"%s\"\n", cfg.font);
|
fprintf(stderr, "pterm: unable to load font \"%s\"\n", cfg.font);
|
||||||
|
@ -41,6 +41,9 @@ void init_ucs(void);
|
|||||||
char *get_x_display(void);
|
char *get_x_display(void);
|
||||||
int font_dimension(int which); /* 0 for width, 1 for height */
|
int font_dimension(int which); /* 0 for width, 1 for height */
|
||||||
|
|
||||||
|
/* Things uxstore.c needs from pterm.c */
|
||||||
|
char *app_name; /* for doing resource lookups */
|
||||||
|
|
||||||
#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,10 +5,18 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <gdk/gdkx.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
#include "putty.h"
|
#include "putty.h"
|
||||||
#include "storage.h"
|
#include "storage.h"
|
||||||
|
|
||||||
/* FIXME. For the moment, we do nothing at all here. */
|
/*
|
||||||
|
* For the moment, the only existing Unix utility is pterm and that
|
||||||
|
* has no GUI configuration at all, so our write routines need do
|
||||||
|
* nothing. Eventually I suppose these will read and write an rc
|
||||||
|
* file somewhere or other.
|
||||||
|
*/
|
||||||
|
|
||||||
void *open_settings_w(char *sessionname)
|
void *open_settings_w(char *sessionname)
|
||||||
{
|
{
|
||||||
@ -27,19 +35,46 @@ void close_settings_w(void *handle)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reading settings, for the moment, is done by retrieving X
|
||||||
|
* resources from the X display. When we introduce disk files, I
|
||||||
|
* think what will happen is that the X resources will override
|
||||||
|
* PuTTY's inbuilt defaults, but that the disk files will then
|
||||||
|
* override those. This isn't optimal, but it's the best I can
|
||||||
|
* immediately work out.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static Display *display;
|
||||||
|
|
||||||
void *open_settings_r(char *sessionname)
|
void *open_settings_r(char *sessionname)
|
||||||
{
|
{
|
||||||
return NULL;
|
static int thing_to_return_an_arbitrary_non_null_pointer_to;
|
||||||
|
display = GDK_DISPLAY();
|
||||||
|
if (!display)
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return &thing_to_return_an_arbitrary_non_null_pointer_to;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *read_setting_s(void *handle, char *key, char *buffer, int buflen)
|
char *read_setting_s(void *handle, char *key, char *buffer, int buflen)
|
||||||
{
|
{
|
||||||
return NULL;
|
char *val = XGetDefault(display, app_name, key);
|
||||||
|
if (!val)
|
||||||
|
return NULL;
|
||||||
|
else {
|
||||||
|
strncpy(buffer, val, buflen);
|
||||||
|
buffer[buflen-1] = '\0';
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_setting_i(void *handle, char *key, int defvalue)
|
int read_setting_i(void *handle, char *key, int defvalue)
|
||||||
{
|
{
|
||||||
return defvalue;
|
char *val = XGetDefault(display, app_name, key);
|
||||||
|
if (!val)
|
||||||
|
return defvalue;
|
||||||
|
else
|
||||||
|
return atoi(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_settings_r(void *handle)
|
void close_settings_r(void *handle)
|
||||||
|
Loading…
Reference in New Issue
Block a user