read.c revision 4642e01f
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 TopLevelTab[] = 69{ 70 {SECTION, "section"}, 71 {-1, ""}, 72}; 73 74#define CLEANUP xf86freeConfig 75 76/* 77 * This function resolves name references and reports errors if the named 78 * objects cannot be found. 79 */ 80static int 81xf86validateConfig (XF86ConfigPtr p) 82{ 83 if (!xf86validateScreen (p)) 84 return FALSE; 85 if (!xf86validateInput (p)) 86 return FALSE; 87 if (!xf86validateLayout (p)) 88 return FALSE; 89 90 return (TRUE); 91} 92 93XF86ConfigPtr 94xf86readConfigFile (void) 95{ 96 int token; 97 XF86ConfigPtr ptr = NULL; 98 99 if ((ptr = xf86confcalloc (1, sizeof (XF86ConfigRec))) == NULL) 100 { 101 return NULL; 102 } 103 104 while ((token = xf86getToken (TopLevelTab)) != EOF_TOKEN) 105 { 106 switch (token) 107 { 108 case COMMENT: 109 ptr->conf_comment = xf86addComment(ptr->conf_comment, val.str); 110 break; 111 case SECTION: 112 if (xf86getSubToken (&(ptr->conf_comment)) != STRING) 113 { 114 xf86parseError (QUOTE_MSG, "Section"); 115 CLEANUP (ptr); 116 return (NULL); 117 } 118 xf86setSection (val.str); 119 if (xf86nameCompare (val.str, "files") == 0) 120 { 121 xf86conffree(val.str); 122 val.str = NULL; 123 HANDLE_RETURN (conf_files, xf86parseFilesSection ()); 124 } 125 else if (xf86nameCompare (val.str, "serverflags") == 0) 126 { 127 xf86conffree(val.str); 128 val.str = NULL; 129 HANDLE_RETURN (conf_flags, xf86parseFlagsSection ()); 130 } 131 else if (xf86nameCompare (val.str, "pointer") == 0) 132 { 133 xf86conffree(val.str); 134 val.str = NULL; 135 HANDLE_LIST (conf_input_lst, xf86parsePointerSection, 136 XF86ConfInputPtr); 137 } 138 else if (xf86nameCompare (val.str, "videoadaptor") == 0) 139 { 140 xf86conffree(val.str); 141 val.str = NULL; 142 HANDLE_LIST (conf_videoadaptor_lst, xf86parseVideoAdaptorSection, 143 XF86ConfVideoAdaptorPtr); 144 } 145 else if (xf86nameCompare (val.str, "device") == 0) 146 { 147 xf86conffree(val.str); 148 val.str = NULL; 149 HANDLE_LIST (conf_device_lst, xf86parseDeviceSection, 150 XF86ConfDevicePtr); 151 } 152 else if (xf86nameCompare (val.str, "monitor") == 0) 153 { 154 xf86conffree(val.str); 155 val.str = NULL; 156 HANDLE_LIST (conf_monitor_lst, xf86parseMonitorSection, 157 XF86ConfMonitorPtr); 158 } 159 else if (xf86nameCompare (val.str, "modes") == 0) 160 { 161 xf86conffree(val.str); 162 val.str = NULL; 163 HANDLE_LIST (conf_modes_lst, xf86parseModesSection, 164 XF86ConfModesPtr); 165 } 166 else if (xf86nameCompare (val.str, "screen") == 0) 167 { 168 xf86conffree(val.str); 169 val.str = NULL; 170 HANDLE_LIST (conf_screen_lst, xf86parseScreenSection, 171 XF86ConfScreenPtr); 172 } 173 else if (xf86nameCompare(val.str, "inputdevice") == 0) 174 { 175 xf86conffree(val.str); 176 val.str = NULL; 177 HANDLE_LIST (conf_input_lst, xf86parseInputSection, 178 XF86ConfInputPtr); 179 } 180 else if (xf86nameCompare (val.str, "module") == 0) 181 { 182 xf86conffree(val.str); 183 val.str = NULL; 184 HANDLE_RETURN (conf_modules, xf86parseModuleSection ()); 185 } 186 else if (xf86nameCompare (val.str, "serverlayout") == 0) 187 { 188 xf86conffree(val.str); 189 val.str = NULL; 190 HANDLE_LIST (conf_layout_lst, xf86parseLayoutSection, 191 XF86ConfLayoutPtr); 192 } 193 else if (xf86nameCompare (val.str, "vendor") == 0) 194 { 195 xf86conffree(val.str); 196 val.str = NULL; 197 HANDLE_LIST (conf_vendor_lst, xf86parseVendorSection, 198 XF86ConfVendorPtr); 199 } 200 else if (xf86nameCompare (val.str, "dri") == 0) 201 { 202 xf86conffree(val.str); 203 val.str = NULL; 204 HANDLE_RETURN (conf_dri, xf86parseDRISection ()); 205 } 206 else if (xf86nameCompare (val.str, "extensions") == 0) 207 { 208 xf86conffree(val.str); 209 val.str = NULL; 210 HANDLE_RETURN (conf_extensions, xf86parseExtensionsSection ()); 211 } 212 else 213 { 214 Error (INVALID_SECTION_MSG, xf86tokenString ()); 215 xf86conffree(val.str); 216 val.str = NULL; 217 } 218 break; 219 default: 220 Error (INVALID_KEYWORD_MSG, xf86tokenString ()); 221 xf86conffree(val.str); 222 val.str = NULL; 223 } 224 } 225 226 if (xf86validateConfig (ptr)) 227 return (ptr); 228 else 229 { 230 CLEANUP (ptr); 231 return (NULL); 232 } 233} 234 235#undef CLEANUP 236 237/* 238 * adds an item to the end of the linked list. Any record whose first field 239 * is a GenericListRec can be cast to this type and used with this function. 240 * A pointer to the head of the list is returned to handle the addition of 241 * the first item. 242 */ 243GenericListPtr 244xf86addListItem (GenericListPtr head, GenericListPtr new) 245{ 246 GenericListPtr p = head; 247 GenericListPtr last = NULL; 248 249 while (p) 250 { 251 last = p; 252 p = p->next; 253 } 254 255 if (last) 256 { 257 last->next = new; 258 return (head); 259 } 260 else 261 return (new); 262} 263 264/* 265 * Test if one chained list contains the other. 266 * In this case both list have the same endpoint (provided they don't loop) 267 */ 268int 269xf86itemNotSublist(GenericListPtr list_1, GenericListPtr list_2) 270{ 271 GenericListPtr p = list_1; 272 GenericListPtr last_1 = NULL, last_2 = NULL; 273 274 while (p) { 275 last_1 = p; 276 p = p->next; 277 } 278 279 p = list_2; 280 while (p) { 281 last_2 = p; 282 p = p->next; 283 } 284 285 return (!(last_1 == last_2)); 286} 287 288void 289xf86freeConfig (XF86ConfigPtr p) 290{ 291 if (p == NULL) 292 return; 293 294 xf86freeFiles (p->conf_files); 295 xf86freeModules (p->conf_modules); 296 xf86freeFlags (p->conf_flags); 297 xf86freeMonitorList (p->conf_monitor_lst); 298 xf86freeModesList (p->conf_modes_lst); 299 xf86freeVideoAdaptorList (p->conf_videoadaptor_lst); 300 xf86freeDeviceList (p->conf_device_lst); 301 xf86freeScreenList (p->conf_screen_lst); 302 xf86freeLayoutList (p->conf_layout_lst); 303 xf86freeInputList (p->conf_input_lst); 304 xf86freeVendorList (p->conf_vendor_lst); 305 xf86freeDRI (p->conf_dri); 306 xf86freeExtensions (p->conf_extensions); 307 TestFree(p->conf_comment); 308 309 xf86conffree (p); 310} 311