Extensions.c revision 05b261ec
1/* 2 * Copyright 2004 Red Hat Inc., Raleigh, North Carolina. 3 * 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining 7 * a copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation on the rights to use, copy, modify, merge, 10 * publish, distribute, sublicense, and/or sell copies of the Software, 11 * and to permit persons to whom the Software is furnished to do so, 12 * subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial 16 * portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS 22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 * SOFTWARE. 26 */ 27 28/* 29 * Authors: 30 * Kevin E. Martin <kem@redhat.com> 31 * 32 */ 33 34#ifdef HAVE_XORG_CONFIG_H 35#include <xorg-config.h> 36#endif 37 38#include "xf86Parser.h" 39#include "xf86tokens.h" 40#include "Configint.h" 41 42extern LexRec val; 43 44static xf86ConfigSymTabRec ExtensionsTab[] = 45{ 46 {ENDSECTION, "endsection"}, 47 {OPTION, "option"}, 48 {-1, ""}, 49}; 50 51#define CLEANUP xf86freeExtensions 52 53XF86ConfExtensionsPtr 54xf86parseExtensionsSection (void) 55{ 56 int token; 57 parsePrologue (XF86ConfExtensionsPtr, XF86ConfExtensionsRec); 58 59 while ((token = xf86getToken (ExtensionsTab)) != ENDSECTION) { 60 switch (token) { 61 case OPTION: 62 ptr->ext_option_lst = xf86parseOption(ptr->ext_option_lst); 63 break; 64 case EOF_TOKEN: 65 Error (UNEXPECTED_EOF_MSG, NULL); 66 break; 67 case COMMENT: 68 ptr->extensions_comment = 69 xf86addComment(ptr->extensions_comment, val.str); 70 break; 71 default: 72 Error (INVALID_KEYWORD_MSG, xf86tokenString ()); 73 break; 74 } 75 } 76 77#ifdef DEBUG 78 ErrorF("Extensions section parsed\n"); 79#endif 80 81 return ptr; 82} 83 84#undef CLEANUP 85 86void 87xf86printExtensionsSection (FILE * cf, XF86ConfExtensionsPtr ptr) 88{ 89 XF86OptionPtr p; 90 91 if (ptr == NULL || ptr->ext_option_lst == NULL) 92 return; 93 94 p = ptr->ext_option_lst; 95 fprintf (cf, "Section \"Extensions\"\n"); 96 if (ptr->extensions_comment) 97 fprintf (cf, "%s", ptr->extensions_comment); 98 xf86printOptionList(cf, p, 1); 99 fprintf (cf, "EndSection\n\n"); 100} 101 102void 103xf86freeExtensions (XF86ConfExtensionsPtr ptr) 104{ 105 if (ptr == NULL) 106 return; 107 108 xf86optionListFree (ptr->ext_option_lst); 109 TestFree (ptr->extensions_comment); 110 xf86conffree (ptr); 111} 112