1117N/A/*
1117N/A *
1117N/A * Copyright (c) 1997 Metro Link Incorporated
1117N/A *
1117N/A * Permission is hereby granted, free of charge, to any person obtaining a
1117N/A * copy of this software and associated documentation files (the "Software"),
1117N/A * to deal in the Software without restriction, including without limitation
1117N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1117N/A * and/or sell copies of the Software, and to permit persons to whom the
1117N/A * Software is furnished to do so, subject to the following conditions:
1117N/A *
1117N/A * The above copyright notice and this permission notice shall be included in
1117N/A * all copies or substantial portions of the Software.
1117N/A *
1117N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1117N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1117N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1117N/A * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
1117N/A * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
1117N/A * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1117N/A * SOFTWARE.
1117N/A *
1117N/A * Except as contained in this notice, the name of the Metro Link shall not be
1117N/A * used in advertising or otherwise to promote the sale, use or other dealings
1117N/A * in this Software without prior written authorization from Metro Link.
1117N/A *
1117N/A */
1117N/A/*
1117N/A * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
1117N/A *
1117N/A * Permission is hereby granted, free of charge, to any person obtaining a
1117N/A * copy of this software and associated documentation files (the "Software"),
1117N/A * to deal in the Software without restriction, including without limitation
1117N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1117N/A * and/or sell copies of the Software, and to permit persons to whom the
1117N/A * Software is furnished to do so, subject to the following conditions:
1117N/A *
1117N/A * The above copyright notice and this permission notice shall be included in
1117N/A * all copies or substantial portions of the Software.
1117N/A *
1117N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1117N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1117N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1117N/A * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1117N/A * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1117N/A * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1117N/A * OTHER DEALINGS IN THE SOFTWARE.
1117N/A *
1117N/A * Except as contained in this notice, the name of the copyright holder(s)
1117N/A * and author(s) shall not be used in advertising or otherwise to promote
1117N/A * the sale, use or other dealings in this Software without prior written
1117N/A * authorization from the copyright holder(s) and author(s).
1117N/A */
1117N/A
1117N/A
1117N/A/* View/edit this file with tab stops set to 4 */
1117N/A
1117N/A#ifdef HAVE_XORG_CONFIG_H
1117N/A#include <xorg-config.h>
1117N/A#endif
1117N/A
1117N/A#include "xf86Parser.h"
1117N/A#include "xf86tokens.h"
1117N/A#include "Configint.h"
1117N/A
1117N/Aextern LexRec val;
1117N/A
1117N/Astatic xf86ConfigSymTabRec TopLevelTab[] =
1117N/A{
1117N/A {SECTION, "section"},
1117N/A {-1, ""},
1117N/A};
1117N/A
1117N/A
1117N/A/*
1117N/A * xf86parseConfigFile()
1117N/A *
1117N/A * Parse a configuration file, appending it to the current
1117N/A * configuration data.
1117N/A */
1117N/A
1117N/A#define CLEANUP xf86freeConfig
1117N/A
1117N/Astatic
1117N/AXF86ConfigPtr
1117N/Axf86parseConfigFile(XF86ConfigPtr ptr)
1117N/A{
1117N/A int token; /* Scanner token code */
1117N/A
1117N/A while ((token = xf86getToken (TopLevelTab)) != EOF_TOKEN)
1117N/A {
1117N/A switch (token)
1117N/A {
1117N/A case COMMENT:
1117N/A ptr->conf_comment = xf86addComment(ptr->conf_comment, val.str);
1117N/A break;
1117N/A case SECTION:
1117N/A if (xf86getSubToken (&(ptr->conf_comment)) != STRING)
1117N/A {
1117N/A xf86parseError (QUOTE_MSG, "Section");
1117N/A CLEANUP (ptr);
1117N/A return (NULL);
1117N/A }
1117N/A xf86setSection (val.str);
1117N/A if (xf86nameCompare (val.str, "files") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_RETURN (conf_files, xf86parseFilesSection ());
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "serverflags") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_RETURN (conf_flags, xf86parseFlagsSection ());
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "keyboard") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_LIST (conf_input_lst, xf86parseKeyboardSection,
1117N/A XF86ConfInputPtr);
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "pointer") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_LIST (conf_input_lst, xf86parsePointerSection,
1117N/A XF86ConfInputPtr);
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "videoadaptor") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_LIST (conf_videoadaptor_lst, xf86parseVideoAdaptorSection,
1117N/A XF86ConfVideoAdaptorPtr);
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "device") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_LIST (conf_device_lst, xf86parseDeviceSection,
1117N/A XF86ConfDevicePtr);
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "monitor") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_LIST (conf_monitor_lst, xf86parseMonitorSection,
1117N/A XF86ConfMonitorPtr);
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "modes") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_LIST (conf_modes_lst, xf86parseModesSection,
1117N/A XF86ConfModesPtr);
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "screen") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_LIST (conf_screen_lst, xf86parseScreenSection,
1117N/A XF86ConfScreenPtr);
1117N/A }
1117N/A else if (xf86nameCompare(val.str, "inputdevice") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_LIST (conf_input_lst, xf86parseInputSection,
1117N/A XF86ConfInputPtr);
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "module") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_RETURN (conf_modules, xf86parseModuleSection ());
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "serverlayout") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_LIST (conf_layout_lst, xf86parseLayoutSection,
1117N/A XF86ConfLayoutPtr);
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "vendor") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_LIST (conf_vendor_lst, xf86parseVendorSection,
1117N/A XF86ConfVendorPtr);
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "dri") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_RETURN (conf_dri, xf86parseDRISection ());
1117N/A }
1117N/A else if (xf86nameCompare (val.str, "extensions") == 0)
1117N/A {
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A HANDLE_RETURN (conf_extensions, xf86parseExtensionsSection ());
1117N/A }
1117N/A else
1117N/A {
1117N/A Error (INVALID_SECTION_MSG, xf86tokenString ());
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A }
1117N/A break;
1117N/A default:
1117N/A Error (INVALID_KEYWORD_MSG, xf86tokenString ());
1117N/A xf86conffree(val.str);
1117N/A val.str = NULL;
1117N/A }
1117N/A }
1117N/A
1117N/A return (ptr);
1117N/A}
1117N/A
1117N/A
1117N/A/*
1117N/A * xf86readConfigFile()
1117N/A *
1117N/A * Read and validate the (initial) configuration file.
1117N/A */
1117N/A
1117N/AXF86ConfigPtr
1117N/Axf86readConfigFile(void)
1117N/A{
1117N/A XF86ConfigPtr ptr;
1117N/A
1117N/A if ((ptr = xf86confcalloc (1, sizeof (XF86ConfigRec))) == NULL)
1117N/A {
1117N/A return (NULL);
1117N/A }
1117N/A memset(ptr, 0, sizeof (XF86ConfigRec)); /* Redundant */
1117N/A
1117N/A /*
1117N/A * Read, parse, and validate the configuration
1117N/A */
1117N/A ptr = xf86parseConfigFile(ptr);
1117N/A if (ptr != NULL) {
1117N/A if (!xf86validateConfig(ptr)) {
1117N/A CLEANUP(ptr);
1117N/A ptr = NULL;
1117N/A }
1117N/A }
1117N/A
1117N/A return (ptr);
1117N/A}
1117N/A
1117N/A#if defined(SMI_FBCONFIG)
1117N/A
1117N/A/*
1117N/A * xf86readNextConfigFile()
1117N/A *
1117N/A * Read an additional configuration file, appending it to the current
1117N/A * configuration data.
1117N/A *
1117N/A * Note that we can't revalidate existing configuration data without
1117N/A * the possibility of memory leaks involving Screen sections. For
1117N/A * our purposes, additional configuration files are expected to
1117N/A * contain only Modes sections, so revalidation isn't a big concern.
1117N/A */
1117N/A
1117N/AXF86ConfigPtr
1117N/Axf86readNextConfigFile(XF86ConfigPtr ptr)
1117N/A{
1117N/A
1117N/A ptr = xf86parseConfigFile(ptr);
1117N/A if (ptr != NULL) {
1117N/A if (!xf86validateDevice(ptr) ||
1117N/A#if (0)
1117N/A !xf86validateScreen(ptr) ||
1117N/A#endif
1117N/A !xf86validateInput(ptr) ||
1117N/A !xf86validateLayout(ptr)) {
1117N/A CLEANUP(ptr);
1117N/A ptr = NULL;
1117N/A }
1117N/A }
1117N/A return (ptr);
1117N/A}
1117N/A
1117N/A#endif
1117N/A#undef CLEANUP
1117N/A
1117N/A
1117N/A/*
1117N/A * This function resolves name references and reports errors if the named
1117N/A * objects cannot be found.
1117N/A */
1117N/Aint
1117N/Axf86validateConfig (XF86ConfigPtr p)
1117N/A{
1117N/A if (!xf86validateDevice (p))
1117N/A return FALSE;
1117N/A if (!xf86validateScreen (p))
1117N/A return FALSE;
1117N/A if (!xf86validateInput (p))
1117N/A return FALSE;
1117N/A if (!xf86validateLayout (p))
1117N/A return FALSE;
1117N/A
1117N/A return (TRUE);
1117N/A}
1117N/A
1117N/A/*
1117N/A * adds an item to the end of the linked list. Any record whose first field
1117N/A * is a GenericListRec can be cast to this type and used with this function.
1117N/A * A pointer to the head of the list is returned to handle the addition of
1117N/A * the first item.
1117N/A */
1117N/AGenericListPtr
1117N/Axf86addListItem (GenericListPtr head, GenericListPtr new)
1117N/A{
1117N/A GenericListPtr p = head;
1117N/A GenericListPtr last = NULL;
1117N/A
1117N/A while (p)
1117N/A {
1117N/A last = p;
1117N/A p = p->next;
1117N/A }
1117N/A
1117N/A if (last)
1117N/A {
1117N/A last->next = new;
1117N/A return (head);
1117N/A }
1117N/A else
1117N/A return (new);
1117N/A}
1117N/A
1117N/A/*
1117N/A * Test if one chained list contains the other.
1117N/A * In this case both list have the same endpoint (provided they don't loop)
1117N/A */
1117N/Aint
1117N/Axf86itemNotSublist(GenericListPtr list_1, GenericListPtr list_2)
1117N/A{
1117N/A GenericListPtr p = list_1;
1117N/A GenericListPtr last_1 = NULL, last_2 = NULL;
1117N/A
1117N/A while (p) {
1117N/A last_1 = p;
1117N/A p = p->next;
1117N/A }
1117N/A
1117N/A p = list_2;
1117N/A while (p) {
1117N/A last_2 = p;
1117N/A p = p->next;
1117N/A }
1117N/A
1117N/A return (!(last_1 == last_2));
1117N/A}
1117N/A
1117N/Avoid
1117N/Axf86freeConfig (XF86ConfigPtr p)
1117N/A{
1117N/A if (p == NULL)
1117N/A return;
1117N/A
1117N/A xf86freeFiles (p->conf_files);
1117N/A xf86freeModules (p->conf_modules);
1117N/A xf86freeFlags (p->conf_flags);
1117N/A xf86freeMonitorList (p->conf_monitor_lst);
1117N/A xf86freeModesList (p->conf_modes_lst);
1117N/A xf86freeVideoAdaptorList (p->conf_videoadaptor_lst);
1117N/A xf86freeDeviceList (p->conf_device_lst);
1117N/A xf86freeScreenList (p->conf_screen_lst);
1117N/A xf86freeLayoutList (p->conf_layout_lst);
1117N/A xf86freeInputList (p->conf_input_lst);
1117N/A xf86freeVendorList (p->conf_vendor_lst);
1117N/A xf86freeDRI (p->conf_dri);
1117N/A xf86freeExtensions (p->conf_extensions);
1117N/A TestFree(p->conf_comment);
1117N/A
1117N/A xf86conffree (p);
1117N/A}