135c4bbdfSmrg/* 235c4bbdfSmrg * 305b261ecSmrg * Copyright (c) 1997 Metro Link Incorporated 435c4bbdfSmrg * 505b261ecSmrg * Permission is hereby granted, free of charge, to any person obtaining a 635c4bbdfSmrg * copy of this software and associated documentation files (the "Software"), 705b261ecSmrg * to deal in the Software without restriction, including without limitation 805b261ecSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 905b261ecSmrg * and/or sell copies of the Software, and to permit persons to whom the 1005b261ecSmrg * Software is furnished to do so, subject to the following conditions: 1135c4bbdfSmrg * 1205b261ecSmrg * The above copyright notice and this permission notice shall be included in 1305b261ecSmrg * all copies or substantial portions of the Software. 1435c4bbdfSmrg * 1505b261ecSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1605b261ecSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1705b261ecSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1805b261ecSmrg * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 1905b261ecSmrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 2005b261ecSmrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 2105b261ecSmrg * SOFTWARE. 2235c4bbdfSmrg * 2305b261ecSmrg * Except as contained in this notice, the name of the Metro Link shall not be 2405b261ecSmrg * used in advertising or otherwise to promote the sale, use or other dealings 2505b261ecSmrg * in this Software without prior written authorization from Metro Link. 2635c4bbdfSmrg * 2705b261ecSmrg */ 2805b261ecSmrg/* 2905b261ecSmrg * Copyright (c) 1997-2003 by The XFree86 Project, Inc. 3005b261ecSmrg * 3105b261ecSmrg * Permission is hereby granted, free of charge, to any person obtaining a 3205b261ecSmrg * copy of this software and associated documentation files (the "Software"), 3305b261ecSmrg * to deal in the Software without restriction, including without limitation 3405b261ecSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 3505b261ecSmrg * and/or sell copies of the Software, and to permit persons to whom the 3605b261ecSmrg * Software is furnished to do so, subject to the following conditions: 3705b261ecSmrg * 3805b261ecSmrg * The above copyright notice and this permission notice shall be included in 3905b261ecSmrg * all copies or substantial portions of the Software. 4005b261ecSmrg * 4105b261ecSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4205b261ecSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4305b261ecSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 4405b261ecSmrg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 4505b261ecSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 4605b261ecSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 4705b261ecSmrg * OTHER DEALINGS IN THE SOFTWARE. 4805b261ecSmrg * 4905b261ecSmrg * Except as contained in this notice, the name of the copyright holder(s) 5005b261ecSmrg * and author(s) shall not be used in advertising or otherwise to promote 5105b261ecSmrg * the sale, use or other dealings in this Software without prior written 5205b261ecSmrg * authorization from the copyright holder(s) and author(s). 5305b261ecSmrg */ 5405b261ecSmrg 5505b261ecSmrg#ifdef HAVE_XORG_CONFIG_H 5605b261ecSmrg#include <xorg-config.h> 5705b261ecSmrg#endif 5805b261ecSmrg 5905b261ecSmrg#include "xf86Parser.h" 6005b261ecSmrg#include "xf86tokens.h" 6105b261ecSmrg#include "Configint.h" 6205b261ecSmrg 6305b261ecSmrg 641b5d61b8Smrgstatic const xf86ConfigSymTabRec SubModuleTab[] = { 6535c4bbdfSmrg {ENDSUBSECTION, "endsubsection"}, 6635c4bbdfSmrg {OPTION, "option"}, 6735c4bbdfSmrg {-1, ""}, 6805b261ecSmrg}; 6905b261ecSmrg 701b5d61b8Smrgstatic const xf86ConfigSymTabRec ModuleTab[] = { 7135c4bbdfSmrg {ENDSECTION, "endsection"}, 7235c4bbdfSmrg {LOAD, "load"}, 7335c4bbdfSmrg {DISABLE, "disable"}, 7435c4bbdfSmrg {LOAD_DRIVER, "loaddriver"}, 7535c4bbdfSmrg {SUBSECTION, "subsection"}, 7635c4bbdfSmrg {-1, ""}, 7705b261ecSmrg}; 7805b261ecSmrg 7905b261ecSmrg#define CLEANUP xf86freeModules 8005b261ecSmrg 8105b261ecSmrgstatic XF86LoadPtr 8235c4bbdfSmrgxf86parseModuleSubSection(XF86LoadPtr head, char *name) 8305b261ecSmrg{ 8435c4bbdfSmrg int token; 8535c4bbdfSmrg 8635c4bbdfSmrg parsePrologue(XF86LoadPtr, XF86LoadRec) 8705b261ecSmrg 8835c4bbdfSmrg ptr->load_name = name; 8935c4bbdfSmrg ptr->load_type = XF86_LOAD_MODULE; 9035c4bbdfSmrg ptr->ignore = 0; 9135c4bbdfSmrg ptr->load_opt = NULL; 9235c4bbdfSmrg ptr->list.next = NULL; 9305b261ecSmrg 9435c4bbdfSmrg while ((token = xf86getToken(SubModuleTab)) != ENDSUBSECTION) { 9535c4bbdfSmrg switch (token) { 9635c4bbdfSmrg case COMMENT: 9735c4bbdfSmrg ptr->load_comment = xf86addComment(ptr->load_comment, xf86_lex_val.str); 9858cf2af7Smrg free(xf86_lex_val.str); 9958cf2af7Smrg xf86_lex_val.str = NULL; 10035c4bbdfSmrg break; 10135c4bbdfSmrg case OPTION: 10235c4bbdfSmrg ptr->load_opt = xf86parseOption(ptr->load_opt); 10335c4bbdfSmrg break; 10435c4bbdfSmrg case EOF_TOKEN: 10535c4bbdfSmrg xf86parseError(UNEXPECTED_EOF_MSG); 10635c4bbdfSmrg free(ptr); 10735c4bbdfSmrg return NULL; 10835c4bbdfSmrg default: 10935c4bbdfSmrg xf86parseError(INVALID_KEYWORD_MSG, xf86tokenString()); 11035c4bbdfSmrg free(ptr); 11135c4bbdfSmrg return NULL; 11235c4bbdfSmrg break; 11335c4bbdfSmrg } 11405b261ecSmrg 11535c4bbdfSmrg } 11605b261ecSmrg 11735c4bbdfSmrg return ((XF86LoadPtr) xf86addListItem((glp) head, (glp) ptr)); 11805b261ecSmrg} 11905b261ecSmrg 12005b261ecSmrgXF86ConfModulePtr 12135c4bbdfSmrgxf86parseModuleSection(void) 12205b261ecSmrg{ 12335c4bbdfSmrg int token; 12435c4bbdfSmrg 12535c4bbdfSmrg parsePrologue(XF86ConfModulePtr, XF86ConfModuleRec) 12605b261ecSmrg 12735c4bbdfSmrg while ((token = xf86getToken(ModuleTab)) != ENDSECTION) { 12835c4bbdfSmrg switch (token) { 12935c4bbdfSmrg case COMMENT: 13035c4bbdfSmrg ptr->mod_comment = xf86addComment(ptr->mod_comment, xf86_lex_val.str); 13158cf2af7Smrg free(xf86_lex_val.str); 13258cf2af7Smrg xf86_lex_val.str = NULL; 13335c4bbdfSmrg break; 13435c4bbdfSmrg case LOAD: 13535c4bbdfSmrg if (xf86getSubToken(&(ptr->mod_comment)) != STRING) 13635c4bbdfSmrg Error(QUOTE_MSG, "Load"); 13735c4bbdfSmrg ptr->mod_load_lst = 13835c4bbdfSmrg xf86addNewLoadDirective(ptr->mod_load_lst, xf86_lex_val.str, 13935c4bbdfSmrg XF86_LOAD_MODULE, NULL); 14035c4bbdfSmrg break; 14135c4bbdfSmrg case DISABLE: 14235c4bbdfSmrg if (xf86getSubToken(&(ptr->mod_comment)) != STRING) 14335c4bbdfSmrg Error(QUOTE_MSG, "Disable"); 14435c4bbdfSmrg ptr->mod_disable_lst = 14535c4bbdfSmrg xf86addNewLoadDirective(ptr->mod_disable_lst, xf86_lex_val.str, 14635c4bbdfSmrg XF86_DISABLE_MODULE, NULL); 14735c4bbdfSmrg break; 14835c4bbdfSmrg case LOAD_DRIVER: 14935c4bbdfSmrg if (xf86getSubToken(&(ptr->mod_comment)) != STRING) 15035c4bbdfSmrg Error(QUOTE_MSG, "LoadDriver"); 15135c4bbdfSmrg ptr->mod_load_lst = 15235c4bbdfSmrg xf86addNewLoadDirective(ptr->mod_load_lst, xf86_lex_val.str, 15335c4bbdfSmrg XF86_LOAD_DRIVER, NULL); 15435c4bbdfSmrg break; 15535c4bbdfSmrg case SUBSECTION: 15635c4bbdfSmrg if (xf86getSubToken(&(ptr->mod_comment)) != STRING) 15735c4bbdfSmrg Error(QUOTE_MSG, "SubSection"); 15835c4bbdfSmrg ptr->mod_load_lst = 15935c4bbdfSmrg xf86parseModuleSubSection(ptr->mod_load_lst, xf86_lex_val.str); 16035c4bbdfSmrg break; 16135c4bbdfSmrg case EOF_TOKEN: 16235c4bbdfSmrg Error(UNEXPECTED_EOF_MSG); 16335c4bbdfSmrg break; 16435c4bbdfSmrg default: 16535c4bbdfSmrg Error(INVALID_KEYWORD_MSG, xf86tokenString()); 16635c4bbdfSmrg break; 16735c4bbdfSmrg } 16835c4bbdfSmrg } 16905b261ecSmrg 17005b261ecSmrg#ifdef DEBUG 17135c4bbdfSmrg printf("Module section parsed\n"); 17205b261ecSmrg#endif 17305b261ecSmrg 17435c4bbdfSmrg return ptr; 17505b261ecSmrg} 17605b261ecSmrg 17705b261ecSmrg#undef CLEANUP 17805b261ecSmrg 17905b261ecSmrgvoid 18035c4bbdfSmrgxf86printModuleSection(FILE * cf, XF86ConfModulePtr ptr) 18105b261ecSmrg{ 18235c4bbdfSmrg XF86LoadPtr lptr; 18305b261ecSmrg 18435c4bbdfSmrg if (ptr == NULL) 18535c4bbdfSmrg return; 18605b261ecSmrg 18735c4bbdfSmrg if (ptr->mod_comment) 18835c4bbdfSmrg fprintf(cf, "%s", ptr->mod_comment); 18935c4bbdfSmrg for (lptr = ptr->mod_load_lst; lptr; lptr = lptr->list.next) { 19035c4bbdfSmrg switch (lptr->load_type) { 19135c4bbdfSmrg case XF86_LOAD_MODULE: 19235c4bbdfSmrg if (lptr->load_opt == NULL) { 19335c4bbdfSmrg fprintf(cf, "\tLoad \"%s\"", lptr->load_name); 19435c4bbdfSmrg if (lptr->load_comment) 19535c4bbdfSmrg fprintf(cf, "%s", lptr->load_comment); 19635c4bbdfSmrg else 19735c4bbdfSmrg fputc('\n', cf); 19835c4bbdfSmrg } 19935c4bbdfSmrg else { 20035c4bbdfSmrg fprintf(cf, "\tSubSection \"%s\"\n", lptr->load_name); 20135c4bbdfSmrg if (lptr->load_comment) 20235c4bbdfSmrg fprintf(cf, "%s", lptr->load_comment); 20335c4bbdfSmrg xf86printOptionList(cf, lptr->load_opt, 2); 20435c4bbdfSmrg fprintf(cf, "\tEndSubSection\n"); 20535c4bbdfSmrg } 20635c4bbdfSmrg break; 20735c4bbdfSmrg case XF86_LOAD_DRIVER: 20835c4bbdfSmrg fprintf(cf, "\tLoadDriver \"%s\"", lptr->load_name); 20935c4bbdfSmrg if (lptr->load_comment) 21035c4bbdfSmrg fprintf(cf, "%s", lptr->load_comment); 21135c4bbdfSmrg else 21235c4bbdfSmrg fputc('\n', cf); 21335c4bbdfSmrg break; 21405b261ecSmrg#if 0 21535c4bbdfSmrg default: 21635c4bbdfSmrg fprintf(cf, "#\tUnknown type \"%s\"\n", lptr->load_name); 21735c4bbdfSmrg break; 21805b261ecSmrg#endif 21935c4bbdfSmrg } 22035c4bbdfSmrg } 22105b261ecSmrg} 22205b261ecSmrg 22305b261ecSmrgXF86LoadPtr 22435c4bbdfSmrgxf86addNewLoadDirective(XF86LoadPtr head, const char *name, int type, 22535c4bbdfSmrg XF86OptionPtr opts) 22605b261ecSmrg{ 22735c4bbdfSmrg XF86LoadPtr new; 22835c4bbdfSmrg int token; 22905b261ecSmrg 23035c4bbdfSmrg new = calloc(1, sizeof(XF86LoadRec)); 23135c4bbdfSmrg new->load_name = name; 23235c4bbdfSmrg new->load_type = type; 23335c4bbdfSmrg new->load_opt = opts; 23435c4bbdfSmrg new->ignore = 0; 23535c4bbdfSmrg new->list.next = NULL; 23605b261ecSmrg 23758cf2af7Smrg if ((token = xf86getToken(NULL)) == COMMENT) { 23835c4bbdfSmrg new->load_comment = xf86addComment(new->load_comment, xf86_lex_val.str); 23958cf2af7Smrg free(xf86_lex_val.str); 24058cf2af7Smrg xf86_lex_val.str = NULL; 24158cf2af7Smrg } else { 24235c4bbdfSmrg xf86unGetToken(token); 24358cf2af7Smrg } 24405b261ecSmrg 24535c4bbdfSmrg return ((XF86LoadPtr) xf86addListItem((glp) head, (glp) new)); 24605b261ecSmrg} 24705b261ecSmrg 24805b261ecSmrgvoid 24935c4bbdfSmrgxf86freeModules(XF86ConfModulePtr ptr) 25005b261ecSmrg{ 25135c4bbdfSmrg XF86LoadPtr lptr; 25235c4bbdfSmrg XF86LoadPtr prev; 25305b261ecSmrg 25435c4bbdfSmrg if (ptr == NULL) 25535c4bbdfSmrg return; 25635c4bbdfSmrg lptr = ptr->mod_load_lst; 25735c4bbdfSmrg while (lptr) { 25835c4bbdfSmrg TestFree(lptr->load_name); 25935c4bbdfSmrg TestFree(lptr->load_comment); 26035c4bbdfSmrg prev = lptr; 26135c4bbdfSmrg lptr = lptr->list.next; 26235c4bbdfSmrg free(prev); 26335c4bbdfSmrg } 26435c4bbdfSmrg lptr = ptr->mod_disable_lst; 26535c4bbdfSmrg while (lptr) { 26635c4bbdfSmrg TestFree(lptr->load_name); 26735c4bbdfSmrg TestFree(lptr->load_comment); 26835c4bbdfSmrg prev = lptr; 26935c4bbdfSmrg lptr = lptr->list.next; 27035c4bbdfSmrg free(prev); 27135c4bbdfSmrg } 27235c4bbdfSmrg TestFree(ptr->mod_comment); 27335c4bbdfSmrg free(ptr); 27405b261ecSmrg} 275