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 56/* View/edit this file with tab stops set to 4 */ 57 58#ifdef HAVE_XORG_CONFIG_H 59#include <xorg-config.h> 60#endif 61 62#include "xf86Parser.h" 63#include "xf86tokens.h" 64#include "Configint.h" 65 66extern LexRec val; 67 68static xf86ConfigSymTabRec VendorSubTab[] = 69{ 70 {ENDSUBSECTION, "endsubsection"}, 71 {IDENTIFIER, "identifier"}, 72 {OPTION, "option"}, 73 {-1, ""}, 74}; 75 76#define CLEANUP xf86freeVendorSubList 77 78static XF86ConfVendSubPtr 79xf86parseVendorSubSection (void) 80{ 81 int has_ident = FALSE; 82 int token; 83 parsePrologue (XF86ConfVendSubPtr, XF86ConfVendSubRec) 84 85 while ((token = xf86getToken (VendorSubTab)) != ENDSUBSECTION) 86 { 87 switch (token) 88 { 89 case COMMENT: 90 ptr->vs_comment = xf86addComment(ptr->vs_comment, val.str); 91 break; 92 case IDENTIFIER: 93 if (xf86getSubToken (&(ptr->vs_comment))) 94 Error (QUOTE_MSG, "Identifier"); 95 if (has_ident == TRUE) 96 Error (MULTIPLE_MSG, "Identifier"); 97 ptr->vs_identifier = val.str; 98 has_ident = TRUE; 99 break; 100 case OPTION: 101 ptr->vs_option_lst = xf86parseOption(ptr->vs_option_lst); 102 break; 103 104 case EOF_TOKEN: 105 Error (UNEXPECTED_EOF_MSG, NULL); 106 break; 107 default: 108 Error (INVALID_KEYWORD_MSG, xf86tokenString ()); 109 break; 110 } 111 } 112 113#ifdef DEBUG 114 printf ("Vendor subsection parsed\n"); 115#endif 116 117 return ptr; 118} 119 120#undef CLEANUP 121 122static xf86ConfigSymTabRec VendorTab[] = 123{ 124 {ENDSECTION, "endsection"}, 125 {IDENTIFIER, "identifier"}, 126 {OPTION, "option"}, 127 {SUBSECTION, "subsection"}, 128 {-1, ""}, 129}; 130 131#define CLEANUP xf86freeVendorList 132 133XF86ConfVendorPtr 134xf86parseVendorSection (void) 135{ 136 int has_ident = FALSE; 137 int token; 138 parsePrologue (XF86ConfVendorPtr, XF86ConfVendorRec) 139 140 while ((token = xf86getToken (VendorTab)) != ENDSECTION) 141 { 142 switch (token) 143 { 144 case COMMENT: 145 ptr->vnd_comment = xf86addComment(ptr->vnd_comment, val.str); 146 break; 147 case IDENTIFIER: 148 if (xf86getSubToken (&(ptr->vnd_comment)) != STRING) 149 Error (QUOTE_MSG, "Identifier"); 150 if (has_ident == TRUE) 151 Error (MULTIPLE_MSG, "Identifier"); 152 ptr->vnd_identifier = val.str; 153 has_ident = TRUE; 154 break; 155 case OPTION: 156 ptr->vnd_option_lst = xf86parseOption(ptr->vnd_option_lst); 157 break; 158 case SUBSECTION: 159 if (xf86getSubToken (&(ptr->vnd_comment)) != STRING) 160 Error (QUOTE_MSG, "SubSection"); 161 { 162 HANDLE_LIST (vnd_sub_lst, xf86parseVendorSubSection, 163 XF86ConfVendSubPtr); 164 } 165 break; 166 case EOF_TOKEN: 167 Error (UNEXPECTED_EOF_MSG, NULL); 168 break; 169 default: 170 Error (INVALID_KEYWORD_MSG, xf86tokenString ()); 171 break; 172 } 173 174 } 175 176 if (!has_ident) 177 Error (NO_IDENT_MSG, NULL); 178 179#ifdef DEBUG 180 printf ("Vendor section parsed\n"); 181#endif 182 183 return ptr; 184} 185 186#undef CLEANUP 187 188void 189xf86printVendorSection (FILE * cf, XF86ConfVendorPtr ptr) 190{ 191 XF86ConfVendSubPtr pptr; 192 193 while (ptr) 194 { 195 fprintf (cf, "Section \"Vendor\"\n"); 196 if (ptr->vnd_comment) 197 fprintf (cf, "%s", ptr->vnd_comment); 198 if (ptr->vnd_identifier) 199 fprintf (cf, "\tIdentifier \"%s\"\n", ptr->vnd_identifier); 200 201 xf86printOptionList(cf, ptr->vnd_option_lst, 1); 202 for (pptr = ptr->vnd_sub_lst; pptr; pptr = pptr->list.next) 203 { 204 fprintf (cf, "\tSubSection \"Vendor\"\n"); 205 if (pptr->vs_comment) 206 fprintf (cf, "%s", pptr->vs_comment); 207 if (pptr->vs_identifier) 208 fprintf (cf, "\t\tIdentifier \"%s\"\n", pptr->vs_identifier); 209 xf86printOptionList(cf, pptr->vs_option_lst, 2); 210 fprintf (cf, "\tEndSubSection\n"); 211 } 212 fprintf (cf, "EndSection\n\n"); 213 ptr = ptr->list.next; 214 } 215} 216 217void 218xf86freeVendorList (XF86ConfVendorPtr p) 219{ 220 if (p == NULL) 221 return; 222 xf86freeVendorSubList (p->vnd_sub_lst); 223 TestFree (p->vnd_identifier); 224 TestFree (p->vnd_comment); 225 xf86optionListFree (p->vnd_option_lst); 226 free (p); 227} 228 229void 230xf86freeVendorSubList (XF86ConfVendSubPtr ptr) 231{ 232 XF86ConfVendSubPtr prev; 233 234 while (ptr) 235 { 236 TestFree (ptr->vs_identifier); 237 TestFree (ptr->vs_name); 238 TestFree (ptr->vs_comment); 239 xf86optionListFree (ptr->vs_option_lst); 240 prev = ptr; 241 ptr = ptr->list.next; 242 free (prev); 243 } 244} 245