| 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 | extern LexRec val; |
| 64 | |
| 65 | static xf86ConfigSymTabRec VideoPortTab[] = { |
| 66 | {ENDSUBSECTION, "endsubsection"}, |
| 67 | {IDENTIFIER, "identifier"}, |
| 68 | {OPTION, "option"}, |
| 69 | {-1, ""}, |
| 70 | }; |
| 71 | |
| 72 | #define CLEANUP xf86freeVideoPortList |
| 73 | |
| 74 | static void |
| 75 | xf86freeVideoPortList(XF86ConfVideoPortPtr ptr) |
| 76 | { |
| 77 | XF86ConfVideoPortPtr prev; |
| 78 | |
| 79 | while (ptr) { |
| 80 | TestFree(ptr->vp_identifier); |
| 81 | TestFree(ptr->vp_comment); |
| 82 | xf86optionListFree(ptr->vp_option_lst); |
| 83 | prev = ptr; |
| 84 | ptr = ptr->list.next; |
| 85 | free(prev); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | static XF86ConfVideoPortPtr |
| 90 | xf86parseVideoPortSubSection(void) |
| 91 | { |
| 92 | int has_ident = FALSE; |
| 93 | int token; |
| 94 | |
| 95 | parsePrologue(XF86ConfVideoPortPtr, XF86ConfVideoPortRec) |
| 96 | |
| 97 | while ((token = xf86getToken(VideoPortTab)) != ENDSUBSECTION) { |
| 98 | switch (token) { |
| 99 | case COMMENT: |
| 100 | ptr->vp_comment = xf86addComment(ptr->vp_comment, val.str); |
| 101 | break; |
| 102 | case IDENTIFIER: |
| 103 | if (xf86getSubToken(&(ptr->vp_comment)) != STRING) |
| 104 | Error(QUOTE_MSG, "Identifier"); |
| 105 | if (has_ident == TRUE) |
| 106 | Error(MULTIPLE_MSG, "Identifier"); |
| 107 | ptr->vp_identifier = val.str; |
| 108 | has_ident = TRUE; |
| 109 | break; |
| 110 | case OPTION: |
| 111 | ptr->vp_option_lst = xf86parseOption(ptr->vp_option_lst); |
| 112 | break; |
| 113 | |
| 114 | case EOF_TOKEN: |
| 115 | Error(UNEXPECTED_EOF_MSG); |
| 116 | break; |
| 117 | default: |
| 118 | Error(INVALID_KEYWORD_MSG, xf86tokenString()); |
| 119 | break; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | #ifdef DEBUG |
| 124 | printf("VideoPort subsection parsed\n"); |
| 125 | #endif |
| 126 | |
| 127 | return ptr; |
| 128 | } |
| 129 | |
| 130 | #undef CLEANUP |
| 131 | |
| 132 | static xf86ConfigSymTabRec VideoAdaptorTab[] = { |
| 133 | {ENDSECTION, "endsection"}, |
| 134 | {IDENTIFIER, "identifier"}, |
| 135 | {VENDOR, "vendorname"}, |
| 136 | {BOARD, "boardname"}, |
| 137 | {BUSID, "busid"}, |
| 138 | {DRIVER, "driver"}, |
| 139 | {OPTION, "option"}, |
| 140 | {SUBSECTION, "subsection"}, |
| 141 | {-1, ""}, |
| 142 | }; |
| 143 | |
| 144 | #define CLEANUP xf86freeVideoAdaptorList |
| 145 | |
| 146 | XF86ConfVideoAdaptorPtr |
| 147 | xf86parseVideoAdaptorSection(void) |
| 148 | { |
| 149 | int has_ident = FALSE; |
| 150 | int token; |
| 151 | |
| 152 | parsePrologue(XF86ConfVideoAdaptorPtr, XF86ConfVideoAdaptorRec) |
| 153 | |
| 154 | while ((token = xf86getToken(VideoAdaptorTab)) != ENDSECTION) { |
| 155 | switch (token) { |
| 156 | case COMMENT: |
| 157 | ptr->va_comment = xf86addComment(ptr->va_comment, val.str); |
| 158 | break; |
| 159 | case IDENTIFIER: |
| 160 | if (xf86getSubToken(&(ptr->va_comment)) != STRING) |
| 161 | Error(QUOTE_MSG, "Identifier"); |
| 162 | ptr->va_identifier = val.str; |
| 163 | if (has_ident == TRUE) |
| 164 | Error(MULTIPLE_MSG, "Identifier"); |
| 165 | has_ident = TRUE; |
| 166 | break; |
| 167 | case VENDOR: |
| 168 | if (xf86getSubToken(&(ptr->va_comment)) != STRING) |
| 169 | Error(QUOTE_MSG, "Vendor"); |
| 170 | ptr->va_vendor = val.str; |
| 171 | break; |
| 172 | case BOARD: |
| 173 | if (xf86getSubToken(&(ptr->va_comment)) != STRING) |
| 174 | Error(QUOTE_MSG, "Board"); |
| 175 | ptr->va_board = val.str; |
| 176 | break; |
| 177 | case BUSID: |
| 178 | if (xf86getSubToken(&(ptr->va_comment)) != STRING) |
| 179 | Error(QUOTE_MSG, "BusID"); |
| 180 | ptr->va_busid = val.str; |
| 181 | break; |
| 182 | case DRIVER: |
| 183 | if (xf86getSubToken(&(ptr->va_comment)) != STRING) |
| 184 | Error(QUOTE_MSG, "Driver"); |
| 185 | ptr->va_driver = val.str; |
| 186 | break; |
| 187 | case OPTION: |
| 188 | ptr->va_option_lst = xf86parseOption(ptr->va_option_lst); |
| 189 | break; |
| 190 | case SUBSECTION: |
| 191 | if (xf86getSubToken(&(ptr->va_comment)) != STRING) |
| 192 | Error(QUOTE_MSG, "SubSection"); |
| 193 | { |
| 194 | HANDLE_LIST(va_port_lst, xf86parseVideoPortSubSection, |
| 195 | XF86ConfVideoPortPtr); |
| 196 | } |
| 197 | break; |
| 198 | |
| 199 | case EOF_TOKEN: |
| 200 | Error(UNEXPECTED_EOF_MSG); |
| 201 | break; |
| 202 | default: |
| 203 | Error(INVALID_KEYWORD_MSG, xf86tokenString()); |
| 204 | break; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | if (!has_ident) |
| 209 | Error(NO_IDENT_MSG); |
| 210 | |
| 211 | #ifdef DEBUG |
| 212 | printf("VideoAdaptor section parsed\n"); |
| 213 | #endif |
| 214 | |
| 215 | return ptr; |
| 216 | } |
| 217 | |
| 218 | void |
| 219 | xf86printVideoAdaptorSection(FILE * cf, XF86ConfVideoAdaptorPtr ptr) |
| 220 | { |
| 221 | XF86ConfVideoPortPtr pptr; |
| 222 | |
| 223 | while (ptr) { |
| 224 | fprintf(cf, "Section \"VideoAdaptor\"\n"); |
| 225 | if (ptr->va_comment) |
| 226 | fprintf(cf, "%s", ptr->va_comment); |
| 227 | if (ptr->va_identifier) |
| 228 | fprintf(cf, "\tIdentifier \"%s\"\n", ptr->va_identifier); |
| 229 | if (ptr->va_vendor) |
| 230 | fprintf(cf, "\tVendorName \"%s\"\n", ptr->va_vendor); |
| 231 | if (ptr->va_board) |
| 232 | fprintf(cf, "\tBoardName \"%s\"\n", ptr->va_board); |
| 233 | if (ptr->va_busid) |
| 234 | fprintf(cf, "\tBusID \"%s\"\n", ptr->va_busid); |
| 235 | if (ptr->va_driver) |
| 236 | fprintf(cf, "\tDriver \"%s\"\n", ptr->va_driver); |
| 237 | xf86printOptionList(cf, ptr->va_option_lst, 1); |
| 238 | for (pptr = ptr->va_port_lst; pptr; pptr = pptr->list.next) { |
| 239 | fprintf(cf, "\tSubSection \"VideoPort\"\n"); |
| 240 | if (pptr->vp_comment) |
| 241 | fprintf(cf, "%s", pptr->vp_comment); |
| 242 | if (pptr->vp_identifier) |
| 243 | fprintf(cf, "\t\tIdentifier \"%s\"\n", pptr->vp_identifier); |
| 244 | xf86printOptionList(cf, pptr->vp_option_lst, 2); |
| 245 | fprintf(cf, "\tEndSubSection\n"); |
| 246 | } |
| 247 | fprintf(cf, "EndSection\n\n"); |
| 248 | ptr = ptr->list.next; |
| 249 | } |
| 250 | |
| 251 | } |
| 252 | |
| 253 | void |
| 254 | xf86freeVideoAdaptorList(XF86ConfVideoAdaptorPtr ptr) |
| 255 | { |
| 256 | XF86ConfVideoAdaptorPtr prev; |
| 257 | |
| 258 | while (ptr) { |
| 259 | TestFree(ptr->va_identifier); |
| 260 | TestFree(ptr->va_vendor); |
| 261 | TestFree(ptr->va_board); |
| 262 | TestFree(ptr->va_busid); |
| 263 | TestFree(ptr->va_driver); |
| 264 | TestFree(ptr->va_fwdref); |
| 265 | TestFree(ptr->va_comment); |
| 266 | xf86freeVideoPortList(ptr->va_port_lst); |
| 267 | xf86optionListFree(ptr->va_option_lst); |
| 268 | prev = ptr; |
| 269 | ptr = ptr->list.next; |
| 270 | free(prev); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | XF86ConfVideoAdaptorPtr |
| 275 | xf86findVideoAdaptor(const char *ident, XF86ConfVideoAdaptorPtr p) |
| 276 | { |
| 277 | while (p) { |
| 278 | if (xf86nameCompare(ident, p->va_identifier) == 0) |
| 279 | return p; |
| 280 | |
| 281 | p = p->list.next; |
| 282 | } |
| 283 | return NULL; |
| 284 | } |