1706f2543Smrg/*
2706f2543Smrg *
3706f2543Smrg * Copyright (c) 1997  Metro Link Incorporated
4706f2543Smrg *
5706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6706f2543Smrg * copy of this software and associated documentation files (the "Software"),
7706f2543Smrg * to deal in the Software without restriction, including without limitation
8706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the
10706f2543Smrg * Software is furnished to do so, subject to the following conditions:
11706f2543Smrg *
12706f2543Smrg * The above copyright notice and this permission notice shall be included in
13706f2543Smrg * all copies or substantial portions of the Software.
14706f2543Smrg *
15706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18706f2543Smrg * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19706f2543Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20706f2543Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21706f2543Smrg * SOFTWARE.
22706f2543Smrg *
23706f2543Smrg * Except as contained in this notice, the name of the Metro Link shall not be
24706f2543Smrg * used in advertising or otherwise to promote the sale, use or other dealings
25706f2543Smrg * in this Software without prior written authorization from Metro Link.
26706f2543Smrg *
27706f2543Smrg */
28706f2543Smrg/*
29706f2543Smrg * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
30706f2543Smrg *
31706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a
32706f2543Smrg * copy of this software and associated documentation files (the "Software"),
33706f2543Smrg * to deal in the Software without restriction, including without limitation
34706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
35706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the
36706f2543Smrg * Software is furnished to do so, subject to the following conditions:
37706f2543Smrg *
38706f2543Smrg * The above copyright notice and this permission notice shall be included in
39706f2543Smrg * all copies or substantial portions of the Software.
40706f2543Smrg *
41706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
44706f2543Smrg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
45706f2543Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
46706f2543Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
47706f2543Smrg * OTHER DEALINGS IN THE SOFTWARE.
48706f2543Smrg *
49706f2543Smrg * Except as contained in this notice, the name of the copyright holder(s)
50706f2543Smrg * and author(s) shall not be used in advertising or otherwise to promote
51706f2543Smrg * the sale, use or other dealings in this Software without prior written
52706f2543Smrg * authorization from the copyright holder(s) and author(s).
53706f2543Smrg */
54706f2543Smrg
55706f2543Smrg
56706f2543Smrg/* View/edit this file with tab stops set to 4 */
57706f2543Smrg
58706f2543Smrg#ifdef HAVE_XORG_CONFIG_H
59706f2543Smrg#include <xorg-config.h>
60706f2543Smrg#endif
61706f2543Smrg
62706f2543Smrg#include "xf86Parser.h"
63706f2543Smrg#include "xf86tokens.h"
64706f2543Smrg#include "Configint.h"
65706f2543Smrg
66706f2543Smrgextern LexRec val;
67706f2543Smrg
68706f2543Smrgstatic xf86ConfigSymTabRec DisplayTab[] =
69706f2543Smrg{
70706f2543Smrg	{ENDSUBSECTION, "endsubsection"},
71706f2543Smrg	{MODES, "modes"},
72706f2543Smrg	{VIEWPORT, "viewport"},
73706f2543Smrg	{VIRTUAL, "virtual"},
74706f2543Smrg	{VISUAL, "visual"},
75706f2543Smrg	{BLACK_TOK, "black"},
76706f2543Smrg	{WHITE_TOK, "white"},
77706f2543Smrg	{DEPTH, "depth"},
78706f2543Smrg	{BPP, "fbbpp"},
79706f2543Smrg	{WEIGHT, "weight"},
80706f2543Smrg	{OPTION, "option"},
81706f2543Smrg	{-1, ""},
82706f2543Smrg};
83706f2543Smrg
84706f2543Smrg#define CLEANUP xf86freeDisplayList
85706f2543Smrg
86706f2543Smrgstatic XF86ConfDisplayPtr
87706f2543Smrgxf86parseDisplaySubSection (void)
88706f2543Smrg{
89706f2543Smrg	int token;
90706f2543Smrg	parsePrologue (XF86ConfDisplayPtr, XF86ConfDisplayRec)
91706f2543Smrg
92706f2543Smrg	ptr->disp_black.red = ptr->disp_black.green = ptr->disp_black.blue = -1;
93706f2543Smrg	ptr->disp_white.red = ptr->disp_white.green = ptr->disp_white.blue = -1;
94706f2543Smrg	ptr->disp_frameX0 = ptr->disp_frameY0 = -1;
95706f2543Smrg	while ((token = xf86getToken (DisplayTab)) != ENDSUBSECTION)
96706f2543Smrg	{
97706f2543Smrg		switch (token)
98706f2543Smrg		{
99706f2543Smrg		case COMMENT:
100706f2543Smrg			ptr->disp_comment = xf86addComment(ptr->disp_comment, val.str);
101706f2543Smrg			break;
102706f2543Smrg		case VIEWPORT:
103706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
104706f2543Smrg				Error (VIEWPORT_MSG, NULL);
105706f2543Smrg			ptr->disp_frameX0 = val.num;
106706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
107706f2543Smrg				Error (VIEWPORT_MSG, NULL);
108706f2543Smrg			ptr->disp_frameY0 = val.num;
109706f2543Smrg			break;
110706f2543Smrg		case VIRTUAL:
111706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
112706f2543Smrg				Error (VIRTUAL_MSG, NULL);
113706f2543Smrg			ptr->disp_virtualX = val.num;
114706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
115706f2543Smrg				Error (VIRTUAL_MSG, NULL);
116706f2543Smrg			ptr->disp_virtualY = val.num;
117706f2543Smrg			break;
118706f2543Smrg		case DEPTH:
119706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
120706f2543Smrg				Error (NUMBER_MSG, "Display");
121706f2543Smrg			ptr->disp_depth = val.num;
122706f2543Smrg			break;
123706f2543Smrg		case BPP:
124706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
125706f2543Smrg				Error (NUMBER_MSG, "Display");
126706f2543Smrg			ptr->disp_bpp = val.num;
127706f2543Smrg			break;
128706f2543Smrg		case VISUAL:
129706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != STRING)
130706f2543Smrg				Error (QUOTE_MSG, "Display");
131706f2543Smrg			ptr->disp_visual = val.str;
132706f2543Smrg			break;
133706f2543Smrg		case WEIGHT:
134706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
135706f2543Smrg				Error (WEIGHT_MSG, NULL);
136706f2543Smrg			ptr->disp_weight.red = val.num;
137706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
138706f2543Smrg				Error (WEIGHT_MSG, NULL);
139706f2543Smrg			ptr->disp_weight.green = val.num;
140706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
141706f2543Smrg				Error (WEIGHT_MSG, NULL);
142706f2543Smrg			ptr->disp_weight.blue = val.num;
143706f2543Smrg			break;
144706f2543Smrg		case BLACK_TOK:
145706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
146706f2543Smrg				Error (BLACK_MSG, NULL);
147706f2543Smrg			ptr->disp_black.red = val.num;
148706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
149706f2543Smrg				Error (BLACK_MSG, NULL);
150706f2543Smrg			ptr->disp_black.green = val.num;
151706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
152706f2543Smrg				Error (BLACK_MSG, NULL);
153706f2543Smrg			ptr->disp_black.blue = val.num;
154706f2543Smrg			break;
155706f2543Smrg		case WHITE_TOK:
156706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
157706f2543Smrg				Error (WHITE_MSG, NULL);
158706f2543Smrg			ptr->disp_white.red = val.num;
159706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
160706f2543Smrg				Error (WHITE_MSG, NULL);
161706f2543Smrg			ptr->disp_white.green = val.num;
162706f2543Smrg			if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
163706f2543Smrg				Error (WHITE_MSG, NULL);
164706f2543Smrg			ptr->disp_white.blue = val.num;
165706f2543Smrg			break;
166706f2543Smrg		case MODES:
167706f2543Smrg			{
168706f2543Smrg				XF86ModePtr mptr;
169706f2543Smrg
170706f2543Smrg				while ((token = xf86getSubTokenWithTab (&(ptr->disp_comment), DisplayTab)) == STRING)
171706f2543Smrg				{
172706f2543Smrg					mptr = calloc (1, sizeof (XF86ModeRec));
173706f2543Smrg					mptr->mode_name = val.str;
174706f2543Smrg					mptr->list.next = NULL;
175706f2543Smrg					ptr->disp_mode_lst = (XF86ModePtr)
176706f2543Smrg						xf86addListItem ((glp) ptr->disp_mode_lst, (glp) mptr);
177706f2543Smrg				}
178706f2543Smrg				xf86unGetToken (token);
179706f2543Smrg			}
180706f2543Smrg			break;
181706f2543Smrg		case OPTION:
182706f2543Smrg			ptr->disp_option_lst = xf86parseOption(ptr->disp_option_lst);
183706f2543Smrg			break;
184706f2543Smrg
185706f2543Smrg		case EOF_TOKEN:
186706f2543Smrg			Error (UNEXPECTED_EOF_MSG, NULL);
187706f2543Smrg			break;
188706f2543Smrg		default:
189706f2543Smrg			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
190706f2543Smrg			break;
191706f2543Smrg		}
192706f2543Smrg	}
193706f2543Smrg
194706f2543Smrg#ifdef DEBUG
195706f2543Smrg	printf ("Display subsection parsed\n");
196706f2543Smrg#endif
197706f2543Smrg
198706f2543Smrg	return ptr;
199706f2543Smrg}
200706f2543Smrg
201706f2543Smrg#undef CLEANUP
202706f2543Smrg
203706f2543Smrgstatic xf86ConfigSymTabRec ScreenTab[] =
204706f2543Smrg{
205706f2543Smrg	{ENDSECTION, "endsection"},
206706f2543Smrg	{IDENTIFIER, "identifier"},
207706f2543Smrg	{OBSDRIVER, "driver"},
208706f2543Smrg	{MDEVICE, "device"},
209706f2543Smrg	{MONITOR, "monitor"},
210706f2543Smrg	{VIDEOADAPTOR, "videoadaptor"},
211706f2543Smrg	{SCREENNO, "screenno"},
212706f2543Smrg	{SUBSECTION, "subsection"},
213706f2543Smrg	{DEFAULTDEPTH, "defaultcolordepth"},
214706f2543Smrg	{DEFAULTDEPTH, "defaultdepth"},
215706f2543Smrg	{DEFAULTBPP, "defaultbpp"},
216706f2543Smrg	{DEFAULTFBBPP, "defaultfbbpp"},
217706f2543Smrg	{VIRTUAL, "virtual"},
218706f2543Smrg	{OPTION, "option"},
219706f2543Smrg	{-1, ""},
220706f2543Smrg};
221706f2543Smrg
222706f2543Smrg#define CLEANUP xf86freeScreenList
223706f2543SmrgXF86ConfScreenPtr
224706f2543Smrgxf86parseScreenSection (void)
225706f2543Smrg{
226706f2543Smrg	int has_ident = FALSE;
227706f2543Smrg	int has_driver= FALSE;
228706f2543Smrg	int token;
229706f2543Smrg
230706f2543Smrg	parsePrologue (XF86ConfScreenPtr, XF86ConfScreenRec)
231706f2543Smrg
232706f2543Smrg		while ((token = xf86getToken (ScreenTab)) != ENDSECTION)
233706f2543Smrg	{
234706f2543Smrg		switch (token)
235706f2543Smrg		{
236706f2543Smrg		case COMMENT:
237706f2543Smrg			ptr->scrn_comment = xf86addComment(ptr->scrn_comment, val.str);
238706f2543Smrg			break;
239706f2543Smrg		case IDENTIFIER:
240706f2543Smrg			if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
241706f2543Smrg				Error (QUOTE_MSG, "Identifier");
242706f2543Smrg			ptr->scrn_identifier = val.str;
243706f2543Smrg			if (has_ident || has_driver)
244706f2543Smrg				Error (ONLY_ONE_MSG,"Identifier or Driver");
245706f2543Smrg			has_ident = TRUE;
246706f2543Smrg			break;
247706f2543Smrg		case OBSDRIVER:
248706f2543Smrg			if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
249706f2543Smrg				Error (QUOTE_MSG, "Driver");
250706f2543Smrg			ptr->scrn_obso_driver = val.str;
251706f2543Smrg			if (has_ident || has_driver)
252706f2543Smrg				Error (ONLY_ONE_MSG,"Identifier or Driver");
253706f2543Smrg			has_driver = TRUE;
254706f2543Smrg			break;
255706f2543Smrg		case DEFAULTDEPTH:
256706f2543Smrg			if (xf86getSubToken (&(ptr->scrn_comment)) != NUMBER)
257706f2543Smrg				Error (NUMBER_MSG, "DefaultDepth");
258706f2543Smrg			ptr->scrn_defaultdepth = val.num;
259706f2543Smrg			break;
260706f2543Smrg		case DEFAULTBPP:
261706f2543Smrg			if (xf86getSubToken (&(ptr->scrn_comment)) != NUMBER)
262706f2543Smrg				Error (NUMBER_MSG, "DefaultBPP");
263706f2543Smrg			ptr->scrn_defaultbpp = val.num;
264706f2543Smrg			break;
265706f2543Smrg		case DEFAULTFBBPP:
266706f2543Smrg			if (xf86getSubToken (&(ptr->scrn_comment)) != NUMBER)
267706f2543Smrg				Error (NUMBER_MSG, "DefaultFbBPP");
268706f2543Smrg			ptr->scrn_defaultfbbpp = val.num;
269706f2543Smrg			break;
270706f2543Smrg		case MDEVICE:
271706f2543Smrg			if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
272706f2543Smrg				Error (QUOTE_MSG, "Device");
273706f2543Smrg			ptr->scrn_device_str = val.str;
274706f2543Smrg			break;
275706f2543Smrg		case MONITOR:
276706f2543Smrg			if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
277706f2543Smrg				Error (QUOTE_MSG, "Monitor");
278706f2543Smrg			ptr->scrn_monitor_str = val.str;
279706f2543Smrg			break;
280706f2543Smrg		case VIDEOADAPTOR:
281706f2543Smrg			{
282706f2543Smrg				XF86ConfAdaptorLinkPtr aptr;
283706f2543Smrg
284706f2543Smrg				if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
285706f2543Smrg					Error (QUOTE_MSG, "VideoAdaptor");
286706f2543Smrg
287706f2543Smrg				/* Don't allow duplicates */
288706f2543Smrg				for (aptr = ptr->scrn_adaptor_lst; aptr;
289706f2543Smrg					aptr = (XF86ConfAdaptorLinkPtr) aptr->list.next)
290706f2543Smrg					if (xf86nameCompare (val.str, aptr->al_adaptor_str) == 0)
291706f2543Smrg						break;
292706f2543Smrg
293706f2543Smrg				if (aptr == NULL)
294706f2543Smrg				{
295706f2543Smrg					aptr = calloc (1, sizeof (XF86ConfAdaptorLinkRec));
296706f2543Smrg					aptr->list.next = NULL;
297706f2543Smrg					aptr->al_adaptor_str = val.str;
298706f2543Smrg					ptr->scrn_adaptor_lst = (XF86ConfAdaptorLinkPtr)
299706f2543Smrg						xf86addListItem ((glp) ptr->scrn_adaptor_lst, (glp) aptr);
300706f2543Smrg				}
301706f2543Smrg			}
302706f2543Smrg			break;
303706f2543Smrg		case VIRTUAL:
304706f2543Smrg			if (xf86getSubToken (&(ptr->scrn_comment)) != NUMBER)
305706f2543Smrg				Error (VIRTUAL_MSG, NULL);
306706f2543Smrg			ptr->scrn_virtualX = val.num;
307706f2543Smrg			if (xf86getSubToken (&(ptr->scrn_comment)) != NUMBER)
308706f2543Smrg				Error (VIRTUAL_MSG, NULL);
309706f2543Smrg			ptr->scrn_virtualY = val.num;
310706f2543Smrg			break;
311706f2543Smrg		case OPTION:
312706f2543Smrg			ptr->scrn_option_lst = xf86parseOption(ptr->scrn_option_lst);
313706f2543Smrg			break;
314706f2543Smrg		case SUBSECTION:
315706f2543Smrg			if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
316706f2543Smrg				Error (QUOTE_MSG, "SubSection");
317706f2543Smrg			{
318706f2543Smrg				free(val.str);
319706f2543Smrg				HANDLE_LIST (scrn_display_lst, xf86parseDisplaySubSection,
320706f2543Smrg							 XF86ConfDisplayPtr);
321706f2543Smrg			}
322706f2543Smrg			break;
323706f2543Smrg		case EOF_TOKEN:
324706f2543Smrg			Error (UNEXPECTED_EOF_MSG, NULL);
325706f2543Smrg			break;
326706f2543Smrg		default:
327706f2543Smrg			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
328706f2543Smrg			break;
329706f2543Smrg		}
330706f2543Smrg	}
331706f2543Smrg
332706f2543Smrg	if (!has_ident && !has_driver)
333706f2543Smrg		Error (NO_IDENT_MSG, NULL);
334706f2543Smrg
335706f2543Smrg#ifdef DEBUG
336706f2543Smrg	printf ("Screen section parsed\n");
337706f2543Smrg#endif
338706f2543Smrg
339706f2543Smrg	return ptr;
340706f2543Smrg}
341706f2543Smrg
342706f2543Smrgvoid
343706f2543Smrgxf86printScreenSection (FILE * cf, XF86ConfScreenPtr ptr)
344706f2543Smrg{
345706f2543Smrg	XF86ConfAdaptorLinkPtr aptr;
346706f2543Smrg	XF86ConfDisplayPtr dptr;
347706f2543Smrg	XF86ModePtr mptr;
348706f2543Smrg
349706f2543Smrg	while (ptr)
350706f2543Smrg	{
351706f2543Smrg		fprintf (cf, "Section \"Screen\"\n");
352706f2543Smrg		if (ptr->scrn_comment)
353706f2543Smrg			fprintf (cf, "%s", ptr->scrn_comment);
354706f2543Smrg		if (ptr->scrn_identifier)
355706f2543Smrg			fprintf (cf, "\tIdentifier \"%s\"\n", ptr->scrn_identifier);
356706f2543Smrg		if (ptr->scrn_obso_driver)
357706f2543Smrg			fprintf (cf, "\tDriver     \"%s\"\n", ptr->scrn_obso_driver);
358706f2543Smrg		if (ptr->scrn_device_str)
359706f2543Smrg			fprintf (cf, "\tDevice     \"%s\"\n", ptr->scrn_device_str);
360706f2543Smrg		if (ptr->scrn_monitor_str)
361706f2543Smrg			fprintf (cf, "\tMonitor    \"%s\"\n", ptr->scrn_monitor_str);
362706f2543Smrg		if (ptr->scrn_defaultdepth)
363706f2543Smrg			fprintf (cf, "\tDefaultDepth     %d\n",
364706f2543Smrg					 ptr->scrn_defaultdepth);
365706f2543Smrg		if (ptr->scrn_defaultbpp)
366706f2543Smrg			fprintf (cf, "\tDefaultBPP     %d\n",
367706f2543Smrg					 ptr->scrn_defaultbpp);
368706f2543Smrg		if (ptr->scrn_defaultfbbpp)
369706f2543Smrg			fprintf (cf, "\tDefaultFbBPP     %d\n",
370706f2543Smrg					 ptr->scrn_defaultfbbpp);
371706f2543Smrg		xf86printOptionList(cf, ptr->scrn_option_lst, 1);
372706f2543Smrg		for (aptr = ptr->scrn_adaptor_lst; aptr; aptr = aptr->list.next)
373706f2543Smrg		{
374706f2543Smrg			fprintf (cf, "\tVideoAdaptor \"%s\"\n", aptr->al_adaptor_str);
375706f2543Smrg		}
376706f2543Smrg		if (ptr->scrn_virtualX && ptr->scrn_virtualY)
377706f2543Smrg			fprintf (cf, "\tVirtual     %d %d\n",
378706f2543Smrg				 ptr->scrn_virtualX,
379706f2543Smrg				 ptr->scrn_virtualY);
380706f2543Smrg		for (dptr = ptr->scrn_display_lst; dptr; dptr = dptr->list.next)
381706f2543Smrg		{
382706f2543Smrg			fprintf (cf, "\tSubSection \"Display\"\n");
383706f2543Smrg			if (dptr->disp_comment)
384706f2543Smrg				fprintf (cf, "%s", dptr->disp_comment);
385706f2543Smrg			if (dptr->disp_frameX0 >= 0 || dptr->disp_frameY0 >= 0)
386706f2543Smrg			{
387706f2543Smrg				fprintf (cf, "\t\tViewport   %d %d\n",
388706f2543Smrg						 dptr->disp_frameX0, dptr->disp_frameY0);
389706f2543Smrg			}
390706f2543Smrg			if (dptr->disp_virtualX != 0 || dptr->disp_virtualY != 0)
391706f2543Smrg			{
392706f2543Smrg				fprintf (cf, "\t\tVirtual   %d %d\n",
393706f2543Smrg						 dptr->disp_virtualX, dptr->disp_virtualY);
394706f2543Smrg			}
395706f2543Smrg			if (dptr->disp_depth)
396706f2543Smrg			{
397706f2543Smrg				fprintf (cf, "\t\tDepth     %d\n", dptr->disp_depth);
398706f2543Smrg			}
399706f2543Smrg			if (dptr->disp_bpp)
400706f2543Smrg			{
401706f2543Smrg				fprintf (cf, "\t\tFbBPP     %d\n", dptr->disp_bpp);
402706f2543Smrg			}
403706f2543Smrg			if (dptr->disp_visual)
404706f2543Smrg			{
405706f2543Smrg				fprintf (cf, "\t\tVisual    \"%s\"\n", dptr->disp_visual);
406706f2543Smrg			}
407706f2543Smrg			if (dptr->disp_weight.red != 0)
408706f2543Smrg			{
409706f2543Smrg				fprintf (cf, "\t\tWeight    %d %d %d\n",
410706f2543Smrg					 dptr->disp_weight.red, dptr->disp_weight.green, dptr->disp_weight.blue);
411706f2543Smrg			}
412706f2543Smrg			if (dptr->disp_black.red != -1)
413706f2543Smrg			{
414706f2543Smrg				fprintf (cf, "\t\tBlack     0x%04x 0x%04x 0x%04x\n",
415706f2543Smrg					  dptr->disp_black.red, dptr->disp_black.green, dptr->disp_black.blue);
416706f2543Smrg			}
417706f2543Smrg			if (dptr->disp_white.red != -1)
418706f2543Smrg			{
419706f2543Smrg				fprintf (cf, "\t\tWhite     0x%04x 0x%04x 0x%04x\n",
420706f2543Smrg					  dptr->disp_white.red, dptr->disp_white.green, dptr->disp_white.blue);
421706f2543Smrg			}
422706f2543Smrg			if (dptr->disp_mode_lst)
423706f2543Smrg			{
424706f2543Smrg				fprintf (cf, "\t\tModes   ");
425706f2543Smrg			}
426706f2543Smrg			for (mptr = dptr->disp_mode_lst; mptr; mptr = mptr->list.next)
427706f2543Smrg			{
428706f2543Smrg				fprintf (cf, " \"%s\"", mptr->mode_name);
429706f2543Smrg			}
430706f2543Smrg			if (dptr->disp_mode_lst)
431706f2543Smrg			{
432706f2543Smrg				fprintf (cf, "\n");
433706f2543Smrg			}
434706f2543Smrg			xf86printOptionList(cf, dptr->disp_option_lst, 2);
435706f2543Smrg			fprintf (cf, "\tEndSubSection\n");
436706f2543Smrg		}
437706f2543Smrg		fprintf (cf, "EndSection\n\n");
438706f2543Smrg		ptr = ptr->list.next;
439706f2543Smrg	}
440706f2543Smrg
441706f2543Smrg}
442706f2543Smrg
443706f2543Smrgvoid
444706f2543Smrgxf86freeScreenList (XF86ConfScreenPtr ptr)
445706f2543Smrg{
446706f2543Smrg	XF86ConfScreenPtr prev;
447706f2543Smrg
448706f2543Smrg	while (ptr)
449706f2543Smrg	{
450706f2543Smrg		TestFree (ptr->scrn_identifier);
451706f2543Smrg		TestFree (ptr->scrn_monitor_str);
452706f2543Smrg		TestFree (ptr->scrn_device_str);
453706f2543Smrg		TestFree (ptr->scrn_comment);
454706f2543Smrg		xf86optionListFree (ptr->scrn_option_lst);
455706f2543Smrg		xf86freeAdaptorLinkList (ptr->scrn_adaptor_lst);
456706f2543Smrg		xf86freeDisplayList (ptr->scrn_display_lst);
457706f2543Smrg		prev = ptr;
458706f2543Smrg		ptr = ptr->list.next;
459706f2543Smrg		free (prev);
460706f2543Smrg	}
461706f2543Smrg}
462706f2543Smrg
463706f2543Smrgvoid
464706f2543Smrgxf86freeAdaptorLinkList (XF86ConfAdaptorLinkPtr ptr)
465706f2543Smrg{
466706f2543Smrg	XF86ConfAdaptorLinkPtr prev;
467706f2543Smrg
468706f2543Smrg	while (ptr)
469706f2543Smrg	{
470706f2543Smrg		TestFree (ptr->al_adaptor_str);
471706f2543Smrg		prev = ptr;
472706f2543Smrg		ptr = ptr->list.next;
473706f2543Smrg		free (prev);
474706f2543Smrg	}
475706f2543Smrg}
476706f2543Smrg
477706f2543Smrgvoid
478706f2543Smrgxf86freeDisplayList (XF86ConfDisplayPtr ptr)
479706f2543Smrg{
480706f2543Smrg	XF86ConfDisplayPtr prev;
481706f2543Smrg
482706f2543Smrg	while (ptr)
483706f2543Smrg	{
484706f2543Smrg		xf86freeModeList (ptr->disp_mode_lst);
485706f2543Smrg		xf86optionListFree (ptr->disp_option_lst);
486706f2543Smrg		prev = ptr;
487706f2543Smrg		ptr = ptr->list.next;
488706f2543Smrg		free (prev);
489706f2543Smrg	}
490706f2543Smrg}
491706f2543Smrg
492706f2543Smrgvoid
493706f2543Smrgxf86freeModeList (XF86ModePtr ptr)
494706f2543Smrg{
495706f2543Smrg	XF86ModePtr prev;
496706f2543Smrg
497706f2543Smrg	while (ptr)
498706f2543Smrg	{
499706f2543Smrg		TestFree (ptr->mode_name);
500706f2543Smrg		prev = ptr;
501706f2543Smrg		ptr = ptr->list.next;
502706f2543Smrg		free (prev);
503706f2543Smrg	}
504706f2543Smrg}
505706f2543Smrg
506706f2543Smrgint
507706f2543Smrgxf86validateScreen (XF86ConfigPtr p)
508706f2543Smrg{
509706f2543Smrg	XF86ConfScreenPtr screen = p->conf_screen_lst;
510706f2543Smrg	XF86ConfMonitorPtr monitor;
511706f2543Smrg	XF86ConfAdaptorLinkPtr adaptor;
512706f2543Smrg
513706f2543Smrg	while (screen)
514706f2543Smrg	{
515706f2543Smrg		if (screen->scrn_obso_driver && !screen->scrn_identifier)
516706f2543Smrg			screen->scrn_identifier = screen->scrn_obso_driver;
517706f2543Smrg
518706f2543Smrg		monitor = xf86findMonitor (screen->scrn_monitor_str, p->conf_monitor_lst);
519706f2543Smrg		if (screen->scrn_monitor_str)
520706f2543Smrg		{
521706f2543Smrg			if (monitor)
522706f2543Smrg			{
523706f2543Smrg				screen->scrn_monitor = monitor;
524706f2543Smrg				if (!xf86validateMonitor(p, screen))
525706f2543Smrg					return FALSE;
526706f2543Smrg			}
527706f2543Smrg		}
528706f2543Smrg
529706f2543Smrg		screen->scrn_device= xf86findDevice (screen->scrn_device_str, p->conf_device_lst);
530706f2543Smrg
531706f2543Smrg		adaptor = screen->scrn_adaptor_lst;
532706f2543Smrg		while (adaptor)
533706f2543Smrg		{
534706f2543Smrg			adaptor->al_adaptor = xf86findVideoAdaptor (adaptor->al_adaptor_str, p->conf_videoadaptor_lst);
535706f2543Smrg			if (!adaptor->al_adaptor)
536706f2543Smrg			{
537706f2543Smrg				xf86validationError (UNDEFINED_ADAPTOR_MSG, adaptor->al_adaptor_str, screen->scrn_identifier);
538706f2543Smrg				return FALSE;
539706f2543Smrg			}
540706f2543Smrg			else if (adaptor->al_adaptor->va_fwdref)
541706f2543Smrg			{
542706f2543Smrg				xf86validationError (ADAPTOR_REF_TWICE_MSG, adaptor->al_adaptor_str,
543706f2543Smrg						     adaptor->al_adaptor->va_fwdref);
544706f2543Smrg				return FALSE;
545706f2543Smrg			}
546706f2543Smrg
547706f2543Smrg			adaptor->al_adaptor->va_fwdref = strdup(screen->scrn_identifier);
548706f2543Smrg			adaptor = adaptor->list.next;
549706f2543Smrg		}
550706f2543Smrg
551706f2543Smrg		screen = screen->list.next;
552706f2543Smrg	}
553706f2543Smrg
554706f2543Smrg	return TRUE;
555706f2543Smrg}
556706f2543Smrg
557706f2543SmrgXF86ConfScreenPtr
558706f2543Smrgxf86findScreen (const char *ident, XF86ConfScreenPtr p)
559706f2543Smrg{
560706f2543Smrg	while (p)
561706f2543Smrg	{
562706f2543Smrg		if (xf86nameCompare (ident, p->scrn_identifier) == 0)
563706f2543Smrg			return p;
564706f2543Smrg
565706f2543Smrg		p = p->list.next;
566706f2543Smrg	}
567706f2543Smrg	return NULL;
568706f2543Smrg}
569706f2543Smrg
570