diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2009-10-02 06:28:03 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2009-12-22 23:24:02 -0800 |
commit | c6e8637e29e0ca11dfb35c02da7ca6002ac8c597 (patch) | |
tree | 3b47a975af96fac80cac15570cd2eba0a5defa97 | |
parent | 90e6d93cf9bfafd63d7849dc16ce194d6f9c9d5f (diff) |
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>
-rw-r--r-- | hw/xfree86/common/xf86Option.c | 25 | ||||
-rw-r--r-- | hw/xfree86/parser/Configint.h | 2 | ||||
-rw-r--r-- | hw/xfree86/parser/scan.c | 30 | ||||
-rw-r--r-- | hw/xfree86/parser/xf86Parser.h | 9 |
4 files changed, 43 insertions, 23 deletions
diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c index ad8d1c426..a2868bf21 100644 --- a/hw/xfree86/common/xf86Option.c +++ b/hw/xfree86/common/xf86Option.c @@ -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 diff --git a/hw/xfree86/parser/Configint.h b/hw/xfree86/parser/Configint.h index cdc7be806..03509b397 100644 --- a/hw/xfree86/parser/Configint.h +++ b/hw/xfree86/parser/Configint.h @@ -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 \ diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c index d2e8b6d2b..270dbd5bb 100644 --- a/hw/xfree86/parser/scan.c +++ b/hw/xfree86/parser/scan.c @@ -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; +} diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h index 603080066..72beb5fa0 100644 --- a/hw/xfree86/parser/xf86Parser.h +++ b/hw/xfree86/parser/xf86Parser.h @@ -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_ */ |