From d467d2c22e8b06afe31b3db5c125d7ca298fbd4c Mon Sep 17 00:00:00 2001 From: Jeremy Sowden Date: Thu, 3 Oct 2019 23:06:55 +0100 Subject: [PATCH] fookb: add default parameter values. If there is no config-file in $HOME, use a default parameter value instead of complaining and exiting. Signed-off-by: Jeremy Sowden --- fookb/params.c | 48 +++++++++++++++++++++++++++++++++++------------- fookb/params.h | 9 ++++++++- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/fookb/params.c b/fookb/params.c index 8501e04..7bbacae 100644 --- a/fookb/params.c +++ b/fookb/params.c @@ -19,16 +19,40 @@ char *read_param(char *string) /* Command line parameters take precedence over all */ - if (!strcmp(string, "Icon1") && icon1) - return icon1; - if (!strcmp(string, "Icon2") && icon2) - return icon2; - if (!strcmp(string, "Icon3") && icon3) - return icon3; - if (!strcmp(string, "Icon4") && icon4) - return icon4; - if (!strcmp(string, "IconBoom") && iconboom) - return iconboom; + if (!strcmp(string, "Icon1")) { + if (icon1) + return icon1; + + result = DEFAULT_ICON1; + } + if (!strcmp(string, "Icon2")) { + if (icon2) + return icon2; + + result = DEFAULT_ICON2; + } + if (!strcmp(string, "Icon3")) { + if (icon3) + return icon3; + + result = DEFAULT_ICON3; + } + if (!strcmp(string, "Icon4")) { + if (icon4) + return icon4; + + result = DEFAULT_ICON4; + } + if (!strcmp(string, "IconBoom")) { + if (iconboom) + return iconboom; + + result = DEFAULT_ICON_BOOM; + } + if (!strcmp(string, "Sound")) + result = DEFAULT_SOUND; + if (!strcmp(string, "Command")) + result = DEFAULT_COMMAND; /* * Here we start the game with property lists. @@ -44,9 +68,7 @@ char *read_param(char *string) wfree(path); if (!pl) { - lputs("Cannot open config file: "); - lputs(DEFAULTS_FILE); - exit(EXIT_FAILURE); + return result; } tmp = WMCreatePLString(string); diff --git a/fookb/params.h b/fookb/params.h index c15652c..d52fc2b 100644 --- a/fookb/params.h +++ b/fookb/params.h @@ -8,8 +8,15 @@ #ifndef PARAMS_H #define PARAMS_H +#define DEFAULTS_FILE "~/.fookb" -#define DEFAULTS_FILE "~/.fookb" +#define DEFAULT_ICON1 "/usr/local/share/fookb/lat.xpm" +#define DEFAULT_ICON2 "/usr/local/share/fookb/rus.xpm" +#define DEFAULT_ICON3 "/usr/local/share/fookb/3.xpm" +#define DEFAULT_ICON4 "/usr/local/share/fookb/4.xpm" +#define DEFAULT_ICON_BOOM "/usr/local/share/fookb/boom.xpm" +#define DEFAULT_SOUND "Yes" +#define DEFAULT_COMMAND "/usr/bin/play /usr/local/share/fookb/beep_spring.au" char *read_param(char *);