3 * Copyright (c) 1997 Metro Link Incorporated
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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
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.
29 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
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:
38 * The above copyright notice and this permission notice shall be included in
39 * all copies or substantial portions of the Software.
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.
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).
55 #ifdef HAVE_XORG_CONFIG_H
56 #include <xorg-config.h>
59 #include "xf86Parser.h"
60 #include "xf86tokens.h"
61 #include "Configint.h"
65 static xf86ConfigSymTabRec DisplayTab
[] = {
66 {ENDSUBSECTION
, "endsubsection"},
68 {VIEWPORT
, "viewport"},
80 #define CLEANUP xf86freeDisplayList
82 static XF86ConfDisplayPtr
83 xf86parseDisplaySubSection(void)
87 parsePrologue(XF86ConfDisplayPtr
, XF86ConfDisplayRec
)
89 ptr
->disp_black
.red
= ptr
->disp_black
.green
= ptr
->disp_black
.blue
= -1;
90 ptr
->disp_white
.red
= ptr
->disp_white
.green
= ptr
->disp_white
.blue
= -1;
91 ptr
->disp_frameX0
= ptr
->disp_frameY0
= -1;
92 while ((token
= xf86getToken(DisplayTab
)) != ENDSUBSECTION
) {
95 ptr
->disp_comment
= xf86addComment(ptr
->disp_comment
, val
.str
);
98 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
100 ptr
->disp_frameX0
= val
.num
;
101 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
103 ptr
->disp_frameY0
= val
.num
;
106 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
108 ptr
->disp_virtualX
= val
.num
;
109 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
111 ptr
->disp_virtualY
= val
.num
;
114 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
115 Error(NUMBER_MSG
, "Display");
116 ptr
->disp_depth
= val
.num
;
119 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
120 Error(NUMBER_MSG
, "Display");
121 ptr
->disp_bpp
= val
.num
;
124 if (xf86getSubToken(&(ptr
->disp_comment
)) != STRING
)
125 Error(QUOTE_MSG
, "Display");
126 ptr
->disp_visual
= val
.str
;
129 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
131 ptr
->disp_weight
.red
= val
.num
;
132 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
134 ptr
->disp_weight
.green
= val
.num
;
135 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
137 ptr
->disp_weight
.blue
= val
.num
;
140 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
142 ptr
->disp_black
.red
= val
.num
;
143 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
145 ptr
->disp_black
.green
= val
.num
;
146 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
148 ptr
->disp_black
.blue
= val
.num
;
151 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
153 ptr
->disp_white
.red
= val
.num
;
154 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
156 ptr
->disp_white
.green
= val
.num
;
157 if (xf86getSubToken(&(ptr
->disp_comment
)) != NUMBER
)
159 ptr
->disp_white
.blue
= val
.num
;
166 xf86getSubTokenWithTab(&(ptr
->disp_comment
),
167 DisplayTab
)) == STRING
) {
168 mptr
= calloc(1, sizeof(XF86ModeRec
));
169 mptr
->mode_name
= val
.str
;
170 mptr
->list
.next
= NULL
;
171 ptr
->disp_mode_lst
= (XF86ModePtr
)
172 xf86addListItem((glp
) ptr
->disp_mode_lst
, (glp
) mptr
);
174 xf86unGetToken(token
);
178 ptr
->disp_option_lst
= xf86parseOption(ptr
->disp_option_lst
);
182 Error(UNEXPECTED_EOF_MSG
);
185 Error(INVALID_KEYWORD_MSG
, xf86tokenString());
191 printf("Display subsection parsed\n");
199 static xf86ConfigSymTabRec ScreenTab
[] = {
200 {ENDSECTION
, "endsection"},
201 {IDENTIFIER
, "identifier"},
202 {OBSDRIVER
, "driver"},
204 {MONITOR
, "monitor"},
205 {VIDEOADAPTOR
, "videoadaptor"},
206 {SCREENNO
, "screenno"},
207 {SUBSECTION
, "subsection"},
208 {DEFAULTDEPTH
, "defaultcolordepth"},
209 {DEFAULTDEPTH
, "defaultdepth"},
210 {DEFAULTBPP
, "defaultbpp"},
211 {DEFAULTFBBPP
, "defaultfbbpp"},
212 {VIRTUAL
, "virtual"},
217 #define CLEANUP xf86freeScreenList
219 xf86parseScreenSection(void)
221 int has_ident
= FALSE
;
222 int has_driver
= FALSE
;
225 parsePrologue(XF86ConfScreenPtr
, XF86ConfScreenRec
)
227 while ((token
= xf86getToken(ScreenTab
)) != ENDSECTION
) {
230 ptr
->scrn_comment
= xf86addComment(ptr
->scrn_comment
, val
.str
);
233 if (xf86getSubToken(&(ptr
->scrn_comment
)) != STRING
)
234 Error(QUOTE_MSG
, "Identifier");
235 ptr
->scrn_identifier
= val
.str
;
236 if (has_ident
|| has_driver
)
237 Error(ONLY_ONE_MSG
, "Identifier or Driver");
241 if (xf86getSubToken(&(ptr
->scrn_comment
)) != STRING
)
242 Error(QUOTE_MSG
, "Driver");
243 ptr
->scrn_obso_driver
= val
.str
;
244 if (has_ident
|| has_driver
)
245 Error(ONLY_ONE_MSG
, "Identifier or Driver");
249 if (xf86getSubToken(&(ptr
->scrn_comment
)) != NUMBER
)
250 Error(NUMBER_MSG
, "DefaultDepth");
251 ptr
->scrn_defaultdepth
= val
.num
;
254 if (xf86getSubToken(&(ptr
->scrn_comment
)) != NUMBER
)
255 Error(NUMBER_MSG
, "DefaultBPP");
256 ptr
->scrn_defaultbpp
= val
.num
;
259 if (xf86getSubToken(&(ptr
->scrn_comment
)) != NUMBER
)
260 Error(NUMBER_MSG
, "DefaultFbBPP");
261 ptr
->scrn_defaultfbbpp
= val
.num
;
264 if (xf86getSubToken(&(ptr
->scrn_comment
)) != STRING
)
265 Error(QUOTE_MSG
, "Device");
266 ptr
->scrn_device_str
= val
.str
;
269 if (xf86getSubToken(&(ptr
->scrn_comment
)) != STRING
)
270 Error(QUOTE_MSG
, "Monitor");
271 ptr
->scrn_monitor_str
= val
.str
;
275 XF86ConfAdaptorLinkPtr aptr
;
277 if (xf86getSubToken(&(ptr
->scrn_comment
)) != STRING
)
278 Error(QUOTE_MSG
, "VideoAdaptor");
280 /* Don't allow duplicates */
281 for (aptr
= ptr
->scrn_adaptor_lst
; aptr
;
282 aptr
= (XF86ConfAdaptorLinkPtr
) aptr
->list
.next
)
283 if (xf86nameCompare(val
.str
, aptr
->al_adaptor_str
) == 0)
287 aptr
= calloc(1, sizeof(XF86ConfAdaptorLinkRec
));
288 aptr
->list
.next
= NULL
;
289 aptr
->al_adaptor_str
= val
.str
;
290 ptr
->scrn_adaptor_lst
= (XF86ConfAdaptorLinkPtr
)
291 xf86addListItem((glp
) ptr
->scrn_adaptor_lst
, (glp
) aptr
);
296 if (xf86getSubToken(&(ptr
->scrn_comment
)) != NUMBER
)
298 ptr
->scrn_virtualX
= val
.num
;
299 if (xf86getSubToken(&(ptr
->scrn_comment
)) != NUMBER
)
301 ptr
->scrn_virtualY
= val
.num
;
304 ptr
->scrn_option_lst
= xf86parseOption(ptr
->scrn_option_lst
);
307 if (xf86getSubToken(&(ptr
->scrn_comment
)) != STRING
)
308 Error(QUOTE_MSG
, "SubSection");
311 HANDLE_LIST(scrn_display_lst
, xf86parseDisplaySubSection
,
316 Error(UNEXPECTED_EOF_MSG
);
319 Error(INVALID_KEYWORD_MSG
, xf86tokenString());
324 if (!has_ident
&& !has_driver
)
328 printf("Screen section parsed\n");
335 xf86printScreenSection(FILE * cf
, XF86ConfScreenPtr ptr
)
337 XF86ConfAdaptorLinkPtr aptr
;
338 XF86ConfDisplayPtr dptr
;
342 fprintf(cf
, "Section \"Screen\"\n");
343 if (ptr
->scrn_comment
)
344 fprintf(cf
, "%s", ptr
->scrn_comment
);
345 if (ptr
->scrn_identifier
)
346 fprintf(cf
, "\tIdentifier \"%s\"\n", ptr
->scrn_identifier
);
347 if (ptr
->scrn_obso_driver
)
348 fprintf(cf
, "\tDriver \"%s\"\n", ptr
->scrn_obso_driver
);
349 if (ptr
->scrn_device_str
)
350 fprintf(cf
, "\tDevice \"%s\"\n", ptr
->scrn_device_str
);
351 if (ptr
->scrn_monitor_str
)
352 fprintf(cf
, "\tMonitor \"%s\"\n", ptr
->scrn_monitor_str
);
353 if (ptr
->scrn_defaultdepth
)
354 fprintf(cf
, "\tDefaultDepth %d\n", ptr
->scrn_defaultdepth
);
355 if (ptr
->scrn_defaultbpp
)
356 fprintf(cf
, "\tDefaultBPP %d\n", ptr
->scrn_defaultbpp
);
357 if (ptr
->scrn_defaultfbbpp
)
358 fprintf(cf
, "\tDefaultFbBPP %d\n", ptr
->scrn_defaultfbbpp
);
359 xf86printOptionList(cf
, ptr
->scrn_option_lst
, 1);
360 for (aptr
= ptr
->scrn_adaptor_lst
; aptr
; aptr
= aptr
->list
.next
) {
361 fprintf(cf
, "\tVideoAdaptor \"%s\"\n", aptr
->al_adaptor_str
);
363 if (ptr
->scrn_virtualX
&& ptr
->scrn_virtualY
)
364 fprintf(cf
, "\tVirtual %d %d\n",
365 ptr
->scrn_virtualX
, ptr
->scrn_virtualY
);
366 for (dptr
= ptr
->scrn_display_lst
; dptr
; dptr
= dptr
->list
.next
) {
367 fprintf(cf
, "\tSubSection \"Display\"\n");
368 if (dptr
->disp_comment
)
369 fprintf(cf
, "%s", dptr
->disp_comment
);
370 if (dptr
->disp_frameX0
>= 0 || dptr
->disp_frameY0
>= 0) {
371 fprintf(cf
, "\t\tViewport %d %d\n",
372 dptr
->disp_frameX0
, dptr
->disp_frameY0
);
374 if (dptr
->disp_virtualX
!= 0 || dptr
->disp_virtualY
!= 0) {
375 fprintf(cf
, "\t\tVirtual %d %d\n",
376 dptr
->disp_virtualX
, dptr
->disp_virtualY
);
378 if (dptr
->disp_depth
) {
379 fprintf(cf
, "\t\tDepth %d\n", dptr
->disp_depth
);
381 if (dptr
->disp_bpp
) {
382 fprintf(cf
, "\t\tFbBPP %d\n", dptr
->disp_bpp
);
384 if (dptr
->disp_visual
) {
385 fprintf(cf
, "\t\tVisual \"%s\"\n", dptr
->disp_visual
);
387 if (dptr
->disp_weight
.red
!= 0) {
388 fprintf(cf
, "\t\tWeight %d %d %d\n",
389 dptr
->disp_weight
.red
, dptr
->disp_weight
.green
,
390 dptr
->disp_weight
.blue
);
392 if (dptr
->disp_black
.red
!= -1) {
393 fprintf(cf
, "\t\tBlack 0x%04x 0x%04x 0x%04x\n",
394 dptr
->disp_black
.red
, dptr
->disp_black
.green
,
395 dptr
->disp_black
.blue
);
397 if (dptr
->disp_white
.red
!= -1) {
398 fprintf(cf
, "\t\tWhite 0x%04x 0x%04x 0x%04x\n",
399 dptr
->disp_white
.red
, dptr
->disp_white
.green
,
400 dptr
->disp_white
.blue
);
402 if (dptr
->disp_mode_lst
) {
403 fprintf(cf
, "\t\tModes ");
405 for (mptr
= dptr
->disp_mode_lst
; mptr
; mptr
= mptr
->list
.next
) {
406 fprintf(cf
, " \"%s\"", mptr
->mode_name
);
408 if (dptr
->disp_mode_lst
) {
411 xf86printOptionList(cf
, dptr
->disp_option_lst
, 2);
412 fprintf(cf
, "\tEndSubSection\n");
414 fprintf(cf
, "EndSection\n\n");
415 ptr
= ptr
->list
.next
;
421 xf86freeScreenList(XF86ConfScreenPtr ptr
)
423 XF86ConfScreenPtr prev
;
426 TestFree(ptr
->scrn_identifier
);
427 TestFree(ptr
->scrn_monitor_str
);
428 TestFree(ptr
->scrn_device_str
);
429 TestFree(ptr
->scrn_comment
);
430 xf86optionListFree(ptr
->scrn_option_lst
);
431 xf86freeAdaptorLinkList(ptr
->scrn_adaptor_lst
);
432 xf86freeDisplayList(ptr
->scrn_display_lst
);
434 ptr
= ptr
->list
.next
;
440 xf86freeAdaptorLinkList(XF86ConfAdaptorLinkPtr ptr
)
442 XF86ConfAdaptorLinkPtr prev
;
445 TestFree(ptr
->al_adaptor_str
);
447 ptr
= ptr
->list
.next
;
453 xf86freeDisplayList(XF86ConfDisplayPtr ptr
)
455 XF86ConfDisplayPtr prev
;
458 xf86freeModeList(ptr
->disp_mode_lst
);
459 xf86optionListFree(ptr
->disp_option_lst
);
461 ptr
= ptr
->list
.next
;
467 xf86freeModeList(XF86ModePtr ptr
)
472 TestFree(ptr
->mode_name
);
474 ptr
= ptr
->list
.next
;
480 xf86validateScreen(XF86ConfigPtr p
)
482 XF86ConfScreenPtr screen
= p
->conf_screen_lst
;
483 XF86ConfMonitorPtr monitor
;
484 XF86ConfAdaptorLinkPtr adaptor
;
487 if (screen
->scrn_obso_driver
&& !screen
->scrn_identifier
)
488 screen
->scrn_identifier
= screen
->scrn_obso_driver
;
491 xf86findMonitor(screen
->scrn_monitor_str
, p
->conf_monitor_lst
);
492 if (screen
->scrn_monitor_str
) {
494 screen
->scrn_monitor
= monitor
;
495 if (!xf86validateMonitor(p
, screen
))
500 screen
->scrn_device
=
501 xf86findDevice(screen
->scrn_device_str
, p
->conf_device_lst
);
503 adaptor
= screen
->scrn_adaptor_lst
;
505 adaptor
->al_adaptor
=
506 xf86findVideoAdaptor(adaptor
->al_adaptor_str
,
507 p
->conf_videoadaptor_lst
);
508 if (!adaptor
->al_adaptor
) {
509 xf86validationError(UNDEFINED_ADAPTOR_MSG
,
510 adaptor
->al_adaptor_str
,
511 screen
->scrn_identifier
);
514 else if (adaptor
->al_adaptor
->va_fwdref
) {
515 xf86validationError(ADAPTOR_REF_TWICE_MSG
,
516 adaptor
->al_adaptor_str
,
517 adaptor
->al_adaptor
->va_fwdref
);
521 adaptor
->al_adaptor
->va_fwdref
= strdup(screen
->scrn_identifier
);
522 adaptor
= adaptor
->list
.next
;
525 screen
= screen
->list
.next
;
532 xf86findScreen(const char *ident
, XF86ConfScreenPtr p
)
535 if (xf86nameCompare(ident
, p
->scrn_identifier
) == 0)