diff options
Diffstat (limited to 'hw/xfree86/common/xf86Option.c')
-rw-r--r-- | hw/xfree86/common/xf86Option.c | 181 |
1 files changed, 142 insertions, 39 deletions
diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c index 6ca1590e4..0ba09b507 100644 --- a/hw/xfree86/common/xf86Option.c +++ b/hw/xfree86/common/xf86Option.c @@ -1,10 +1,33 @@ -/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Option.c,v 1.25 2002/09/10 17:39:28 dawes Exp $ */ - +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Option.c,v 1.29 2003/10/18 12:34:19 dawes Exp $ */ /* - * Copyright (c) 1998 by The XFree86 Project, Inc. + * Copyright (c) 1998-2003 by The XFree86 Project, Inc. * - * Author: David Dawes <dawes@xfree86.org> + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +/* + * Author: David Dawes <dawes@xfree86.org> * * This file includes public option handling functions. */ @@ -17,7 +40,8 @@ #include "xf86Xinput.h" #include "xf86Optrec.h" -static Bool ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p); +static Bool ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p, + Bool markUsed); /* * xf86CollectOptions collects the options from each of the config file @@ -140,42 +164,41 @@ xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts, /* Created for new XInput stuff -- essentially extensions to the parser */ -/* These xf86Set* functions are intended for use by non-screen specific code */ - -int -xf86SetIntOption(pointer optlist, const char *name, int deflt) +static int +LookupIntOption(pointer optlist, const char *name, int deflt, Bool markUsed) { OptionInfoRec o; o.name = name; o.type = OPTV_INTEGER; - if (ParseOptionValue(-1, optlist, &o)) + if (ParseOptionValue(-1, optlist, &o, markUsed)) deflt = o.value.num; return deflt; } -double -xf86SetRealOption(pointer optlist, const char *name, double deflt) +static double +LookupRealOption(pointer optlist, const char *name, double deflt, + Bool markUsed) { OptionInfoRec o; o.name = name; o.type = OPTV_REAL; - if (ParseOptionValue(-1, optlist, &o)) + if (ParseOptionValue(-1, optlist, &o, markUsed)) deflt = o.value.realnum; return deflt; } -char * -xf86SetStrOption(pointer optlist, const char *name, char *deflt) +static char * +LookupStrOption(pointer optlist, const char *name, char *deflt, Bool markUsed) { OptionInfoRec o; o.name = name; o.type = OPTV_STRING; - if (ParseOptionValue(-1, optlist, &o)) + if (ParseOptionValue(-1, optlist, &o, markUsed)) deflt = o.value.str; if (deflt) return xstrdup(deflt); @@ -184,24 +207,84 @@ xf86SetStrOption(pointer optlist, const char *name, char *deflt) } -int -xf86SetBoolOption(pointer optlist, const char *name, int deflt) +static int +LookupBoolOption(pointer optlist, const char *name, int deflt, Bool markUsed) { OptionInfoRec o; o.name = name; o.type = OPTV_BOOLEAN; - if (ParseOptionValue(-1, optlist, &o)) + if (ParseOptionValue(-1, optlist, &o, markUsed)) deflt = o.value.bool; return deflt; } +/* These xf86Set* functions are intended for use by non-screen specific code */ + +int +xf86SetIntOption(pointer optlist, const char *name, int deflt) +{ + return LookupIntOption(optlist, name, deflt, TRUE); +} + + +double +xf86SetRealOption(pointer optlist, const char *name, double deflt) +{ + return LookupRealOption(optlist, name, deflt, TRUE); +} + + +char * +xf86SetStrOption(pointer optlist, const char *name, char *deflt) +{ + return LookupStrOption(optlist, name, deflt, TRUE); +} + + +int +xf86SetBoolOption(pointer optlist, const char *name, int deflt) +{ + return LookupBoolOption(optlist, name, deflt, TRUE); +} + +/* + * These are like the Set*Option functions, but they don't mark the options + * as used. + */ +int +xf86CheckIntOption(pointer optlist, const char *name, int deflt) +{ + return LookupIntOption(optlist, name, deflt, FALSE); +} + + +double +xf86CheckRealOption(pointer optlist, const char *name, double deflt) +{ + return LookupRealOption(optlist, name, deflt, FALSE); +} + + +char * +xf86CheckStrOption(pointer optlist, const char *name, char *deflt) +{ + return LookupStrOption(optlist, name, deflt, FALSE); +} + + +int +xf86CheckBoolOption(pointer optlist, const char *name, int deflt) +{ + return LookupBoolOption(optlist, name, deflt, FALSE); +} + /* * addNewOption() has the required property of replacing the option value - * it the option is alread present. + * if the option is already present. */ pointer -xf86ReplaceIntOption(pointer optlist, char *name, int val) +xf86ReplaceIntOption(pointer optlist, const char *name, const int val) { char *tmp = xnfalloc(16); sprintf(tmp,"%i",val); @@ -209,20 +292,29 @@ xf86ReplaceIntOption(pointer optlist, char *name, int val) } pointer -xf86ReplaceBoolOption(pointer optlist, char *name, Bool val) +xf86ReplaceRealOption(pointer optlist, const char *name, const double val) +{ + char *tmp = xnfalloc(32); + snprintf(tmp,32,"%f",val); + return xf86AddNewOption(optlist,name,tmp); +} + +pointer +xf86ReplaceBoolOption(pointer optlist, const char *name, const Bool val) { - return xf86AddNewOption(optlist,name,(Bool)val?"True":"False"); + return xf86AddNewOption(optlist,name,val?"True":"False"); } pointer -xf86ReplaceStrOption(pointer optlist, char *name, char* val) +xf86ReplaceStrOption(pointer optlist, const char *name, const char* val) { return xf86AddNewOption(optlist,name,val); } pointer -xf86AddNewOption(pointer head, char *name, char *val) +xf86AddNewOption(pointer head, const char *name, const char *val) { + /* XXX These should actually be allocated in the parser library. */ char *tmp = strdup(val); char *tmp_name = strdup(name); @@ -387,14 +479,17 @@ GetBoolValue(OptionInfoPtr p, const char *s) } static Bool -ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p) +ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p, + Bool markUsed) { char *s, *end; - Bool wasUsed; + Bool wasUsed = FALSE; if ((s = xf86findOptionValue(options, p->name)) != NULL) { - wasUsed = xf86CheckIfOptionUsedByName(options, p->name); - xf86MarkOptionUsedByName(options, p->name); + if (markUsed) { + wasUsed = xf86CheckIfOptionUsedByName(options, p->name); + xf86MarkOptionUsedByName(options, p->name); + } switch (p->type) { case OPTV_INTEGER: if (*s == '\0') { @@ -501,7 +596,7 @@ ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p) p->found = FALSE; break; } - if (p->found) { + if (p->found && markUsed) { int verb = 2; if (wasUsed) verb = 4; @@ -535,7 +630,8 @@ ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p) newn = n; } if ((s = xf86findOptionValue(options, newn)) != NULL) { - xf86MarkOptionUsedByName(options, newn); + if (markUsed) + xf86MarkOptionUsedByName(options, newn); if (GetBoolValue(&opt, s)) { p->value.bool = !opt.value.bool; p->found = TRUE; @@ -547,7 +643,7 @@ ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p) } else { p->found = FALSE; } - if (p->found) { + if (p->found && markUsed) { xf86DrvMsgVerb(scrnIndex, X_CONFIG, 2, "Option \"%s\"", newn); if (*s != 0) { xf86ErrorFVerb(2, " \"%s\"", s); @@ -568,7 +664,7 @@ xf86ProcessOptions(int scrnIndex, pointer options, OptionInfoPtr optinfo) OptionInfoPtr p; for (p = optinfo; p->name != NULL; p++) { - ParseOptionValue(scrnIndex, options, p); + ParseOptionValue(scrnIndex, options, p, TRUE); } } @@ -576,20 +672,27 @@ xf86ProcessOptions(int scrnIndex, pointer options, OptionInfoPtr optinfo) OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec *table, int token) { - const OptionInfoRec *p; + const OptionInfoRec *p, *match = NULL, *set = NULL; if (!table) { ErrorF("xf86TokenToOptinfo: table is NULL\n"); return NULL; } - for (p = table; p->token >= 0 && p->token != token; p++) - ; + for (p = table; p->token >= 0; p++) { + if (p->token == token) { + match = p; + if (p->found) + set = p; + } + } - if (p->token < 0) - return NULL; + if (set) + return (OptionInfoPtr)set; + else if (match) + return (OptionInfoPtr)match; else - return (OptionInfoPtr)p; + return NULL; } |