Add "Extensions" section support to configuration parser

This commit is contained in:
Kevin E Martin 2004-07-31 09:14:06 +00:00
parent d690556d49
commit 383b6b5986
9 changed files with 211 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $XdotOrg$ */
/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86Config.c,v 1.2 2004/04/23 19:20:32 eich Exp $ */
/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Config.c,v 3.276 2003/10/08 14:58:26 dawes Exp $ */
@ -128,6 +128,7 @@ static Bool addDefaultModes(MonPtr monitorp);
#ifdef XF86DRI
static Bool configDRI(XF86ConfDRIPtr drip);
#endif
static Bool configExtensions(XF86ConfExtensionsPtr conf_ext);
/*
* xf86GetPathElem --
@ -2395,6 +2396,46 @@ configDRI(XF86ConfDRIPtr drip)
}
#endif
static Bool
configExtensions(XF86ConfExtensionsPtr conf_ext)
{
XF86OptionPtr o;
/* Extension enable/disable in miinitext.c */
extern Bool EnableDisableExtension(char *name, Bool enable);
if (conf_ext && conf_ext->ext_option_lst) {
for (o = conf_ext->ext_option_lst; o; o = xf86NextOption(o)) {
char *name = xf86OptionName(o);
char *val = xf86OptionValue(o);
if (xf86NameCmp(val, "enable") == 0) {
if (EnableDisableExtension(name, TRUE)) {
xf86Msg(X_CONFIG, "Extension \"%s\" is enabled\n", name);
} else {
xf86Msg(X_ERROR,
"Extension \"%s\" is unrecognized\n", name);
return FALSE;
}
} else if (xf86NameCmp(val, "disable") == 0) {
if (EnableDisableExtension(name, FALSE)) {
xf86Msg(X_CONFIG, "Extension \"%s\" is disabled\n", name);
} else {
xf86Msg(X_ERROR,
"Extension \"%s\" is unrecognized\n", name);
return FALSE;
}
} else {
xf86Msg(X_ERROR,
"%s is not a valid value for the Extension option\n",
val);
return FALSE;
}
}
}
return TRUE;
}
static Bool
configInput(IDevPtr inputp, XF86ConfInputPtr conf_input, MessageType from)
{
@ -2551,7 +2592,8 @@ xf86HandleConfigFile(Bool autoconfig)
if (!configFiles(xf86configptr->conf_files) ||
!configServerFlags(xf86configptr->conf_flags,
xf86ConfigLayout.options)
xf86ConfigLayout.options) ||
!configExtensions(xf86configptr->conf_extensions)
#ifdef XF86DRI
|| !configDRI(xf86configptr->conf_dri)
#endif

View File

@ -0,0 +1,107 @@
/*
* Copyright 2004 Red Hat Inc., Raleigh, North Carolina.
*
* All Rights Reserved.
*
* 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 on 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 (including the
* next paragraph) 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
* NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
* 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.
*/
/*
* Authors:
* Kevin E. Martin <kem@redhat.com>
*
*/
#include "xf86Parser.h"
#include "xf86tokens.h"
#include "Configint.h"
extern LexRec val;
static xf86ConfigSymTabRec ExtensionsTab[] =
{
{ENDSECTION, "endsection"},
{OPTION, "option"},
{-1, ""},
};
#define CLEANUP xf86freeExtensions
XF86ConfExtensionsPtr
xf86parseExtensionsSection (void)
{
int token;
parsePrologue (XF86ConfExtensionsPtr, XF86ConfExtensionsRec);
while ((token = xf86getToken (ExtensionsTab)) != ENDSECTION) {
switch (token) {
case OPTION:
ptr->ext_option_lst = xf86parseOption(ptr->ext_option_lst);
break;
case EOF_TOKEN:
Error (UNEXPECTED_EOF_MSG, NULL);
break;
case COMMENT:
ptr->extensions_comment =
xf86addComment(ptr->extensions_comment, val.str);
break;
default:
Error (INVALID_KEYWORD_MSG, xf86tokenString ());
break;
}
}
#ifdef DEBUG
ErrorF("Extensions section parsed\n");
#endif
return ptr;
}
#undef CLEANUP
void
xf86printExtensionsSection (FILE * cf, XF86ConfExtensionsPtr ptr)
{
XF86OptionPtr p;
if (ptr == NULL || ptr->ext_option_lst == NULL)
return;
p = ptr->ext_option_lst;
fprintf (cf, "Section \"Extensions\"\n");
if (ptr->extensions_comment)
fprintf (cf, "%s", ptr->extensions_comment);
xf86printOptionList(cf, p, 1);
fprintf (cf, "EndSection\n\n");
}
void
xf86freeExtensions (XF86ConfExtensionsPtr ptr)
{
if (ptr == NULL)
return;
xf86optionListFree (ptr->ext_option_lst);
TestFree (ptr->extensions_comment);
xf86conffree (ptr);
}

View File

@ -116,6 +116,10 @@ void xf86freeBuffersList (XF86ConfBuffersPtr ptr);
XF86ConfDRIPtr xf86parseDRISection (void);
void xf86printDRISection (FILE * cf, XF86ConfDRIPtr ptr);
void xf86freeDRI (XF86ConfDRIPtr ptr);
/* Extensions.c */
XF86ConfExtensionsPtr xf86parseExtensionsSection (void);
void xf86printExtensionsSection (FILE * cf, XF86ConfExtensionsPtr ptr);
void xf86freeExtensions (XF86ConfExtensionsPtr ptr);
#ifndef IN_XSERVER
/* Externally provided functions */

View File

@ -191,6 +191,12 @@ xf86readConfigFile (void)
val.str = NULL;
HANDLE_RETURN (conf_dri, xf86parseDRISection ());
}
else if (xf86nameCompare (val.str, "extensions") == 0)
{
xf86conffree(val.str);
val.str = NULL;
HANDLE_RETURN (conf_extensions, xf86parseExtensionsSection ());
}
else
{
Error (INVALID_SECTION_MSG, xf86tokenString ());
@ -304,6 +310,7 @@ xf86freeConfig (XF86ConfigPtr p)
xf86freeInputList (p->conf_input_lst);
xf86freeVendorList (p->conf_vendor_lst);
xf86freeDRI (p->conf_dri);
xf86freeExtensions (p->conf_extensions);
TestFree(p->conf_comment);
xf86conffree (p);

View File

@ -130,6 +130,8 @@ doWriteConfigFile (const char *filename, XF86ConfigPtr cptr)
xf86printDRISection (cf, cptr->conf_dri);
xf86printExtensionsSection (cf, cptr->conf_extensions);
fclose(cf);
return 1;
}

View File

@ -414,6 +414,13 @@ typedef struct
}
XF86ConfDRIRec, *XF86ConfDRIPtr;
typedef struct
{
XF86OptionPtr ext_option_lst;
char *extensions_comment;
}
XF86ConfExtensionsRec, *XF86ConfExtensionsPtr;
typedef struct
{
XF86ConfFilesPtr conf_files;
@ -428,6 +435,7 @@ typedef struct
XF86ConfLayoutPtr conf_layout_lst;
XF86ConfVendorPtr conf_vendor_lst;
XF86ConfDRIPtr conf_dri;
XF86ConfExtensionsPtr conf_extensions;
char *conf_comment;
}
XF86ConfigRec, *XF86ConfigPtr;

View File

@ -1,4 +1,4 @@
/* $XdotOrg: xc/programs/Xserver/include/globals.h,v 1.2 2004/04/23 19:54:23 eich Exp $ */
/* $XdotOrg: xc/programs/Xserver/include/globals.h,v 1.3 2004/07/31 04:23:21 kem Exp $ */
/* $XFree86: xc/programs/Xserver/include/globals.h,v 1.3 1999/09/25 14:38:21 dawes Exp $ */
#ifndef _XSERV_GLOBAL_H_
@ -57,4 +57,8 @@ extern Bool noRenderExtension;
extern Bool noXevieExtension;
#endif
#ifdef COMPOSITE
extern Bool noCompositeExtension;
#endif
#endif /* _XSERV_GLOBAL_H_ */

View File

@ -1,4 +1,4 @@
/* $XdotOrg: xc/programs/Xserver/mi/miinitext.c,v 1.7 2004/07/31 04:23:21 kem Exp $ */
/* $XdotOrg: xc/programs/Xserver/mi/miinitext.c,v 1.8 2004/07/31 08:24:14 anholt Exp $ */
/* $XFree86: xc/programs/Xserver/mi/miinitext.c,v 3.67 2003/01/12 02:44:27 dawes Exp $ */
/***********************************************************
@ -101,6 +101,9 @@ extern Bool noRenderExtension;
#ifdef XEVIE
extern Bool noXevieExtension;
#endif
#ifdef COMPOSITE
extern Bool noCompositeExtension;
#endif
#ifndef XFree86LOADER
#define INITARGS void
@ -308,6 +311,9 @@ static ExtensionToggle ExtensionToggleList[] =
#endif
#ifdef XEVIE
{ "XEVIE", &noXevieExtension },
#endif
#ifdef COMPOSITE
{ "COMPOSITE", &noCompositeExtension },
#endif
{ NULL, NULL }
};
@ -323,13 +329,18 @@ Bool EnableDisableExtension(char *name, Bool enable)
}
}
return FALSE;
}
void EnableDisableExtensionError(char *name, Bool enable)
{
ExtensionToggle *ext = &ExtensionToggleList[0];
ErrorF("Extension \"%s\" is not recognized\n", name);
ErrorF("Only the following extensions can be run-time %s:\n",
enable ? "enabled" : "disabled");
for (ext = &ExtensionToggleList[0]; ext->name != NULL; ext++)
ErrorF(" %s\n", ext->name);
return FALSE;
}
#ifndef XFree86LOADER
@ -482,7 +493,7 @@ InitExtensions(argc, argv)
DamageExtensionInit();
#endif
#ifdef COMPOSITE
CompositeExtensionInit ();
if (!noCompositeExtension) CompositeExtensionInit();
#endif
}
@ -614,7 +625,7 @@ static ExtensionModule staticExtensions[] = {
{ DamageExtensionInit, "DAMAGE", NULL, NULL },
#endif
#ifdef COMPOSITE
{ CompositeExtensionInit, "COMPOSITE", NULL, NULL },
{ CompositeExtensionInit, "COMPOSITE", &noCompositeExtension, NULL },
#endif
#ifdef XEVIE
{ XevieExtensionInit, "XEVIE", &noXevieExtension, NULL },

View File

@ -1,4 +1,4 @@
/* $XdotOrg: xc/programs/Xserver/os/utils.c,v 1.3 2004/06/19 21:56:01 gisburn Exp $ */
/* $XdotOrg: xc/programs/Xserver/os/utils.c,v 1.4 2004/07/31 04:23:21 kem Exp $ */
/* $Xorg: utils.c,v 1.5 2001/02/09 02:05:24 xorgcvs Exp $ */
/*
@ -142,6 +142,10 @@ Bool PanoramiXOneExposeRequest = FALSE;
Bool noXevieExtension = TRUE;
#endif
#ifdef COMPOSITE
Bool noCompositeExtension = TRUE;
#endif
int auditTrailLevel = 1;
Bool Must_have_memory = FALSE;
@ -177,6 +181,7 @@ extern char dispatchExceptionAtReset;
/* Extension enable/disable in miinitext.c */
extern Bool EnableDisableExtension(char *name, Bool enable);
extern void EnableDisableExtensionError(char *name, Bool enable);
OsSigHandlerPtr
OsSignal(sig, handler)
@ -1011,12 +1016,22 @@ ProcessCommandLine(int argc, char *argv[])
#endif
else if ( strcmp( argv[i], "+extension") == 0)
{
if (++i >= argc || !EnableDisableExtension(argv[i], TRUE))
if (++i < argc)
{
if (!EnableDisableExtension(argv[i], TRUE))
EnableDisableExtensionError(argv[i], TRUE);
}
else
UseMsg();
}
else if ( strcmp( argv[i], "-extension") == 0)
{
if (++i >= argc || !EnableDisableExtension(argv[i], FALSE))
if (++i < argc)
{
if (!EnableDisableExtension(argv[i], FALSE))
EnableDisableExtensionError(argv[i], FALSE);
}
else
UseMsg();
}
else