Vendor.c revision 58cf2af7
1/* 2 * 3 * Copyright (c) 1997 Metro Link Incorporated 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 20 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 * SOFTWARE. 22 * 23 * Except as contained in this notice, the name of the Metro Link shall not be 24 * used in advertising or otherwise to promote the sale, use or other dealings 25 * in this Software without prior written authorization from Metro Link. 26 * 27 */ 28/* 29 * Copyright (c) 1997-2003 by The XFree86 Project, Inc. 30 * 31 * Permission is hereby granted, free of charge, to any person obtaining a 32 * copy of this software and associated documentation files (the "Software"), 33 * to deal in the Software without restriction, including without limitation 34 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 35 * and/or sell copies of the Software, and to permit persons to whom the 36 * Software is furnished to do so, subject to the following conditions: 37 * 38 * The above copyright notice and this permission notice shall be included in 39 * all copies or substantial portions of the Software. 40 * 41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 42 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 43 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 44 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 45 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 46 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 47 * OTHER DEALINGS IN THE SOFTWARE. 48 * 49 * Except as contained in this notice, the name of the copyright holder(s) 50 * and author(s) shall not be used in advertising or otherwise to promote 51 * the sale, use or other dealings in this Software without prior written 52 * authorization from the copyright holder(s) and author(s). 53 */ 54 55#ifdef HAVE_XORG_CONFIG_H 56#include <xorg-config.h> 57#endif 58 59#include "xf86Parser.h" 60#include "xf86tokens.h" 61#include "Configint.h" 62 63 64static const xf86ConfigSymTabRec VendorSubTab[] = { 65 {ENDSUBSECTION, "endsubsection"}, 66 {IDENTIFIER, "identifier"}, 67 {OPTION, "option"}, 68 {-1, ""}, 69}; 70 71static void 72xf86freeVendorSubList(XF86ConfVendSubPtr ptr) 73{ 74 XF86ConfVendSubPtr prev; 75 76 while (ptr) { 77 TestFree(ptr->vs_identifier); 78 TestFree(ptr->vs_name); 79 TestFree(ptr->vs_comment); 80 xf86optionListFree(ptr->vs_option_lst); 81 prev = ptr; 82 ptr = ptr->list.next; 83 free(prev); 84 } 85} 86 87#define CLEANUP xf86freeVendorSubList 88 89static XF86ConfVendSubPtr 90xf86parseVendorSubSection(void) 91{ 92 int has_ident = FALSE; 93 int token; 94 95 parsePrologue(XF86ConfVendSubPtr, XF86ConfVendSubRec) 96 97 while ((token = xf86getToken(VendorSubTab)) != ENDSUBSECTION) { 98 switch (token) { 99 case COMMENT: 100 ptr->vs_comment = xf86addComment(ptr->vs_comment, xf86_lex_val.str); 101 free(xf86_lex_val.str); 102 xf86_lex_val.str = NULL; 103 break; 104 case IDENTIFIER: 105 if (xf86getSubToken(&(ptr->vs_comment))) 106 Error(QUOTE_MSG, "Identifier"); 107 if (has_ident == TRUE) 108 Error(MULTIPLE_MSG, "Identifier"); 109 ptr->vs_identifier = xf86_lex_val.str; 110 has_ident = TRUE; 111 break; 112 case OPTION: 113 ptr->vs_option_lst = xf86parseOption(ptr->vs_option_lst); 114 break; 115 116 case EOF_TOKEN: 117 Error(UNEXPECTED_EOF_MSG); 118 break; 119 default: 120 Error(INVALID_KEYWORD_MSG, xf86tokenString()); 121 break; 122 } 123 } 124 125#ifdef DEBUG 126 printf("Vendor subsection parsed\n"); 127#endif 128 129 return ptr; 130} 131 132#undef CLEANUP 133 134static const xf86ConfigSymTabRec VendorTab[] = { 135 {ENDSECTION, "endsection"}, 136 {IDENTIFIER, "identifier"}, 137 {OPTION, "option"}, 138 {SUBSECTION, "subsection"}, 139 {-1, ""}, 140}; 141 142#define CLEANUP xf86freeVendorList 143 144XF86ConfVendorPtr 145xf86parseVendorSection(void) 146{ 147 int has_ident = FALSE; 148 int token; 149 150 parsePrologue(XF86ConfVendorPtr, XF86ConfVendorRec) 151 152 while ((token = xf86getToken(VendorTab)) != ENDSECTION) { 153 switch (token) { 154 case COMMENT: 155 ptr->vnd_comment = xf86addComment(ptr->vnd_comment, xf86_lex_val.str); 156 free(xf86_lex_val.str); 157 xf86_lex_val.str = NULL; 158 break; 159 case IDENTIFIER: 160 if (xf86getSubToken(&(ptr->vnd_comment)) != STRING) 161 Error(QUOTE_MSG, "Identifier"); 162 if (has_ident == TRUE) 163 Error(MULTIPLE_MSG, "Identifier"); 164 ptr->vnd_identifier = xf86_lex_val.str; 165 has_ident = TRUE; 166 break; 167 case OPTION: 168 ptr->vnd_option_lst = xf86parseOption(ptr->vnd_option_lst); 169 break; 170 case SUBSECTION: 171 if (xf86getSubToken(&(ptr->vnd_comment)) != STRING) 172 Error(QUOTE_MSG, "SubSection"); 173 { 174 HANDLE_LIST(vnd_sub_lst, xf86parseVendorSubSection, 175 XF86ConfVendSubPtr); 176 } 177 break; 178 case EOF_TOKEN: 179 Error(UNEXPECTED_EOF_MSG); 180 break; 181 default: 182 Error(INVALID_KEYWORD_MSG, xf86tokenString()); 183 break; 184 } 185 186 } 187 188 if (!has_ident) 189 Error(NO_IDENT_MSG); 190 191#ifdef DEBUG 192 printf("Vendor section parsed\n"); 193#endif 194 195 return ptr; 196} 197 198#undef CLEANUP 199 200void 201xf86printVendorSection(FILE * cf, XF86ConfVendorPtr ptr) 202{ 203 XF86ConfVendSubPtr pptr; 204 205 while (ptr) { 206 fprintf(cf, "Section \"Vendor\"\n"); 207 if (ptr->vnd_comment) 208 fprintf(cf, "%s", ptr->vnd_comment); 209 if (ptr->vnd_identifier) 210 fprintf(cf, "\tIdentifier \"%s\"\n", ptr->vnd_identifier); 211 212 xf86printOptionList(cf, ptr->vnd_option_lst, 1); 213 for (pptr = ptr->vnd_sub_lst; pptr; pptr = pptr->list.next) { 214 fprintf(cf, "\tSubSection \"Vendor\"\n"); 215 if (pptr->vs_comment) 216 fprintf(cf, "%s", pptr->vs_comment); 217 if (pptr->vs_identifier) 218 fprintf(cf, "\t\tIdentifier \"%s\"\n", pptr->vs_identifier); 219 xf86printOptionList(cf, pptr->vs_option_lst, 2); 220 fprintf(cf, "\tEndSubSection\n"); 221 } 222 fprintf(cf, "EndSection\n\n"); 223 ptr = ptr->list.next; 224 } 225} 226 227void 228xf86freeVendorList(XF86ConfVendorPtr p) 229{ 230 if (p == NULL) 231 return; 232 xf86freeVendorSubList(p->vnd_sub_lst); 233 TestFree(p->vnd_identifier); 234 TestFree(p->vnd_comment); 235 xf86optionListFree(p->vnd_option_lst); 236 free(p); 237} 238