1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-06-18 16:35:24 +02:00

wmaker: factorize duplicated code

This patch is factorizing is_same and getBool functions in misc.
is_same is renamed to WMStrEqual
getBool is renamed to WMPLGetBool
to prevent name collision issues.
This commit is contained in:
David Maciejak
2026-02-03 18:36:55 -05:00
committed by Carlos R. Mafra
parent 92e1e9fb0b
commit 1e63c590b6
6 changed files with 53 additions and 130 deletions
+3 -36
View File
@@ -43,14 +43,13 @@
#include "icon.h"
#include "misc.h"
#define APPLY_VAL(value, flag, attrib) \
if (value) {attr->flag = getBool(attrib, value); \
if (mask) mask->flag = 1;}
#define APPLY_VAL(value, flag, attrib) \
if (value) {attr->flag = WMPLGetBool(value); \
if (mask) mask->flag = 1;}
/* Local stuff */
/* type converters */
static int getBool(WMPropList *, WMPropList *);
static char *getString(WMPropList *, WMPropList *);
static WMPropList *ANoTitlebar = NULL;
static WMPropList *ANoResizebar;
@@ -634,38 +633,6 @@ void wDefaultPurgeInfo(const char *instance, const char *class)
WMPLSetCaseSensitive(False);
}
/* --------------------------- Local ----------------------- */
static int getBool(WMPropList * key, WMPropList * value)
{
char *val;
if (!WMIsPLString(value)) {
wwarning(_("Wrong option format for key \"%s\". Should be %s."),
WMGetFromPLString(key), "Boolean");
return 0;
}
val = WMGetFromPLString(value);
if ((val[1] == '\0' && (val[0] == 'y' || val[0] == 'Y' || val[0] == 'T' || val[0] == 't' || val[0] == '1'))
|| (strcasecmp(val, "YES") == 0 || strcasecmp(val, "TRUE") == 0)) {
return 1;
} else if ((val[1] == '\0'
&& (val[0] == 'n' || val[0] == 'N' || val[0] == 'F' || val[0] == 'f' || val[0] == '0'))
|| (strcasecmp(val, "NO") == 0 || strcasecmp(val, "FALSE") == 0)) {
return 0;
} else {
wwarning(_("can't convert \"%s\" to boolean"), val);
/* We return False if we can't convert to BOOLEAN.
* This is because all options defaults to False.
* -1 is not checked and thus is interpreted as True,
* which is not good.*/
return 0;
}
}
/* WARNING: Do not free the value returned by this function!! */
static char *getString(WMPropList * key, WMPropList * value)
{