xfree86: Support non-Option boolean entries in configuration
Refactored code into the parser to allow the freeform boolean types used in Option entries to be used in other configuration entries. This isn't as powerful as allowing "No" to precede the option names, but it atleast gives a common handling of "yes", "no", etc. A type xf86TriState has been added to support an optional boolean. This allows the boolean sense of the value to be kept while providing a means to signal that it is unset. Signed-off-by: Dan Nicholson <dbn.lists@gmail.com> Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
This commit is contained in:
parent
90e6d93cf9
commit
c6e8637e29
|
@ -42,6 +42,7 @@
|
|||
#include "xf86.h"
|
||||
#include "xf86Xinput.h"
|
||||
#include "xf86Optrec.h"
|
||||
#include "xf86Parser.h"
|
||||
|
||||
static Bool ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p,
|
||||
Bool markUsed);
|
||||
|
@ -456,29 +457,7 @@ xf86ShowUnusedOptions(int scrnIndex, pointer options)
|
|||
static Bool
|
||||
GetBoolValue(OptionInfoPtr p, const char *s)
|
||||
{
|
||||
if (*s == '\0') {
|
||||
p->value.bool = TRUE;
|
||||
} else {
|
||||
if (xf86NameCmp(s, "1") == 0)
|
||||
p->value.bool = TRUE;
|
||||
else if (xf86NameCmp(s, "on") == 0)
|
||||
p->value.bool = TRUE;
|
||||
else if (xf86NameCmp(s, "true") == 0)
|
||||
p->value.bool = TRUE;
|
||||
else if (xf86NameCmp(s, "yes") == 0)
|
||||
p->value.bool = TRUE;
|
||||
else if (xf86NameCmp(s, "0") == 0)
|
||||
p->value.bool = FALSE;
|
||||
else if (xf86NameCmp(s, "off") == 0)
|
||||
p->value.bool = FALSE;
|
||||
else if (xf86NameCmp(s, "false") == 0)
|
||||
p->value.bool = FALSE;
|
||||
else if (xf86NameCmp(s, "no") == 0)
|
||||
p->value.bool = FALSE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
return xf86getBoolValue(&p->value.bool, s);
|
||||
}
|
||||
|
||||
static Bool
|
||||
|
|
|
@ -148,6 +148,8 @@ else\
|
|||
"The %s keyword requires a number to follow it."
|
||||
#define POSITIVE_INT_MSG \
|
||||
"The %s keyword requires a positive integer to follow it."
|
||||
#define BOOL_MSG \
|
||||
"The %s keyword requires a boolean to follow it."
|
||||
#define ZAXISMAPPING_MSG \
|
||||
"The ZAxisMapping keyword requires 2 positive numbers or X or Y to follow it."
|
||||
#define AUTOREPEAT_MSG \
|
||||
|
|
|
@ -1028,3 +1028,33 @@ xf86addComment(char *cur, char *add)
|
|||
|
||||
return (cur);
|
||||
}
|
||||
|
||||
Bool
|
||||
xf86getBoolValue(Bool *val, const char *str)
|
||||
{
|
||||
if (!val || !str)
|
||||
return FALSE;
|
||||
if (*str == '\0') {
|
||||
*val = TRUE;
|
||||
} else {
|
||||
if (strcmp(str, "1") == 0)
|
||||
*val = TRUE;
|
||||
else if (strcmp(str, "on") == 0)
|
||||
*val = TRUE;
|
||||
else if (strcmp(str, "true") == 0)
|
||||
*val = TRUE;
|
||||
else if (strcmp(str, "yes") == 0)
|
||||
*val = TRUE;
|
||||
else if (strcmp(str, "0") == 0)
|
||||
*val = FALSE;
|
||||
else if (strcmp(str, "off") == 0)
|
||||
*val = FALSE;
|
||||
else if (strcmp(str, "false") == 0)
|
||||
*val = FALSE;
|
||||
else if (strcmp(str, "no") == 0)
|
||||
*val = FALSE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
#ifndef _xf86Parser_h_
|
||||
#define _xf86Parser_h_
|
||||
|
||||
#include <X11/Xdefs.h>
|
||||
#include "xf86Optrec.h"
|
||||
|
||||
#define HAVE_PARSER_DECLS
|
||||
|
@ -330,6 +331,13 @@ typedef struct
|
|||
}
|
||||
XF86ConfInputrefRec, *XF86ConfInputrefPtr;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Bool set;
|
||||
Bool val;
|
||||
}
|
||||
xf86TriState;
|
||||
|
||||
/* Values for adj_where */
|
||||
#define CONF_ADJ_OBSOLETE -1
|
||||
#define CONF_ADJ_ABSOLUTE 0
|
||||
|
@ -480,5 +488,6 @@ extern _X_EXPORT int xf86itemNotSublist(GenericListPtr list_1, GenericListPtr li
|
|||
extern _X_EXPORT int xf86pathIsAbsolute(const char *path);
|
||||
extern _X_EXPORT int xf86pathIsSafe(const char *path);
|
||||
extern _X_EXPORT char *xf86addComment(char *cur, char *add);
|
||||
extern _X_EXPORT Bool xf86getBoolValue(Bool *val, const char *str);
|
||||
|
||||
#endif /* _xf86Parser_h_ */
|
||||
|
|
Loading…
Reference in New Issue