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#include "fields.h" /* Config file output line fields */
1117N/A
1117N/Aextern LexRec val;
1117N/A
1117N/Astatic xf86ConfigSymTabRec SubModuleTab[] =
1117N/A{
1117N/A {ENDSUBSECTION, "endsubsection"},
1117N/A {OPTION, "option"},
1117N/A {-1, ""},
1117N/A};
1117N/A
1117N/Astatic xf86ConfigSymTabRec ModuleTab[] =
1117N/A{
1117N/A {ENDSECTION, "endsection"},
1117N/A {LOAD, "load"},
1117N/A {LOAD_DRIVER, "loaddriver"},
1117N/A {SUBSECTION, "subsection"},
1117N/A {-1, ""},
1117N/A};
1117N/A
1117N/A#define CLEANUP xf86freeModules
1117N/A
1117N/AXF86LoadPtr
1117N/Axf86parseModuleSubSection (XF86LoadPtr head, char *name)
1117N/A{
1117N/A int token;
1117N/A parsePrologue (XF86LoadPtr, XF86LoadRec)
1117N/A
1117N/A ptr->load_name = name;
1117N/A ptr->load_type = XF86_LOAD_MODULE;
1117N/A ptr->ignore = 0;
1117N/A ptr->load_opt = NULL;
1117N/A ptr->list.next = NULL;
1117N/A
1117N/A while ((token = xf86getToken (SubModuleTab)) != ENDSUBSECTION)
1117N/A {
1117N/A switch (token)
1117N/A {
1117N/A case COMMENT:
1117N/A ptr->load_comment = xf86addComment(ptr->load_comment, val.str);
1117N/A break;
1117N/A case OPTION:
1117N/A ptr->load_opt = xf86parseOption(ptr->load_opt);
1117N/A break;
1117N/A case EOF_TOKEN:
1117N/A xf86parseError (UNEXPECTED_EOF_MSG, NULL);
1117N/A xf86conffree(ptr);
1117N/A return NULL;
1117N/A default:
1117N/A xf86parseError (INVALID_KEYWORD_MSG, xf86tokenString ());
1117N/A xf86conffree(ptr);
1117N/A return NULL;
1117N/A break;
1117N/A }
1117N/A
1117N/A }
1117N/A
1117N/A return ((XF86LoadPtr) xf86addListItem ((glp) head, (glp) ptr));
1117N/A}
1117N/A
1117N/AXF86ConfModulePtr
1117N/Axf86parseModuleSection (void)
1117N/A{
1117N/A int token;
1117N/A parsePrologue (XF86ConfModulePtr, XF86ConfModuleRec)
1117N/A
1117N/A while ((token = xf86getToken (ModuleTab)) != ENDSECTION)
1117N/A {
1117N/A switch (token)
1117N/A {
1117N/A case COMMENT:
1117N/A ptr->mod_comment = xf86addComment(ptr->mod_comment, val.str);
1117N/A break;
1117N/A case LOAD:
1117N/A if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "Load");
1117N/A ptr->mod_load_lst =
1117N/A xf86addNewLoadDirective (ptr->mod_load_lst, val.str,
1117N/A XF86_LOAD_MODULE, NULL);
1117N/A break;
1117N/A case LOAD_DRIVER:
1117N/A if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "LoadDriver");
1117N/A ptr->mod_load_lst =
1117N/A xf86addNewLoadDirective (ptr->mod_load_lst, val.str,
1117N/A XF86_LOAD_DRIVER, NULL);
1117N/A break;
1117N/A case SUBSECTION:
1117N/A if (xf86getSubToken (&(ptr->mod_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "SubSection");
1117N/A ptr->mod_load_lst =
1117N/A xf86parseModuleSubSection (ptr->mod_load_lst, val.str);
1117N/A break;
1117N/A case EOF_TOKEN:
1117N/A Error (UNEXPECTED_EOF_MSG, NULL);
1117N/A break;
1117N/A default:
1117N/A Error (INVALID_KEYWORD_MSG, xf86tokenString ());
1117N/A break;
1117N/A }
1117N/A }
1117N/A
1117N/A#ifdef DEBUG
1117N/A printf ("Module section parsed\n");
1117N/A#endif
1117N/A
1117N/A return ptr;
1117N/A}
1117N/A
1117N/A#undef CLEANUP
1117N/A
1117N/Avoid
1117N/Axf86printModuleSection (FILE * cf, XF86ConfModulePtr ptr)
1117N/A{
1117N/A XF86LoadPtr lptr;
1117N/A
1117N/A if (ptr == NULL)
1117N/A return;
1117N/A
1117N/A fprintf (cf, "Section \"Module\"\n");
1117N/A
1117N/A if (ptr->mod_comment)
1117N/A fprintf(cf, "%s", ptr->mod_comment);
1117N/A for (lptr = ptr->mod_load_lst; lptr; lptr = lptr->list.next)
1117N/A {
1117N/A switch (lptr->load_type)
1117N/A {
1117N/A case XF86_LOAD_MODULE:
1117N/A if( lptr->load_opt == NULL ) {
1117N/A fprintf (cf, "\tLoad \"%s\"", lptr->load_name);
1117N/A if (lptr->load_comment)
1117N/A fprintf(cf, "%s", lptr->load_comment);
1117N/A else
1117N/A fputc('\n', cf);
1117N/A }
1117N/A else
1117N/A {
1117N/A fprintf (cf, "\tSubSection \"%s\"\n", lptr->load_name);
1117N/A if (lptr->load_comment)
1117N/A fprintf(cf, "%s", lptr->load_comment);
1117N/A xf86printOptionList(cf, lptr->load_opt, xf86whitespace_2);
1117N/A fprintf (cf, "\tEndSubSection\n");
1117N/A }
1117N/A break;
1117N/A case XF86_LOAD_DRIVER:
1117N/A fprintf (cf, "\tLoadDriver \"%s\"", lptr->load_name);
1117N/A if (lptr->load_comment)
1117N/A fprintf(cf, "%s", lptr->load_comment);
1117N/A else
1117N/A fputc('\n', cf);
1117N/A break;
1117N/A#if 0
1117N/A default:
1117N/A fprintf (cf, "#\tUnknown type \"%s\"\n", lptr->load_name);
1117N/A break;
1117N/A#endif
1117N/A }
1117N/A }
1117N/A fprintf (cf, "EndSection\n\n");
1117N/A}
1117N/A
1117N/AXF86LoadPtr
1117N/Axf86addNewLoadDirective (XF86LoadPtr head, char *name, int type, XF86OptionPtr opts)
1117N/A{
1117N/A XF86LoadPtr new;
1117N/A int token;
1117N/A
1117N/A new = xf86confcalloc (1, sizeof (XF86LoadRec));
1117N/A new->load_name = name;
1117N/A new->load_type = type;
1117N/A new->load_opt = opts;
1117N/A new->ignore = 0;
1117N/A new->list.next = NULL;
1117N/A
1117N/A if ((token = xf86getToken(NULL)) == COMMENT)
1117N/A new->load_comment = xf86addComment(new->load_comment, val.str);
1117N/A else
1117N/A xf86unGetToken(token);
1117N/A
1117N/A return ((XF86LoadPtr) xf86addListItem ((glp) head, (glp) new));
1117N/A}
1117N/A
1117N/Avoid
1117N/Axf86freeModules (XF86ConfModulePtr ptr)
1117N/A{
1117N/A XF86LoadPtr lptr;
1117N/A XF86LoadPtr prev;
1117N/A
1117N/A if (ptr == NULL)
1117N/A return;
1117N/A lptr = ptr->mod_load_lst;
1117N/A while (lptr)
1117N/A {
1117N/A TestFree (lptr->load_name);
1117N/A TestFree (lptr->load_comment);
1117N/A prev = lptr;
1117N/A lptr = lptr->list.next;
1117N/A xf86conffree (prev);
1117N/A }
1117N/A TestFree (ptr->mod_comment);
1117N/A xf86conffree (ptr);
1117N/A}
1117N/A