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