1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Screen.c,v 1.28 2003/11/07 23:41:41 dawes Exp $ */
/*
*
* Copyright (c) 1997 Metro Link Incorporated
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Metro Link shall not be
* used in advertising or otherwise to promote the sale, use or other dealings
* in this Software without prior written authorization from Metro Link.
*
*/
/*
* Copyright (c) 1997-2003 by The XFree86 Project, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of the copyright holder(s)
* and author(s) shall not be used in advertising or otherwise to promote
* the sale, use or other dealings in this Software without prior written
* authorization from the copyright holder(s) and author(s).
*/
/* View/edit this file with tab stops set to 4 */
#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif
#include "xf86Parser.h"
#include "xf86tokens.h"
#include "Configint.h"
extern LexRec val;
static xf86ConfigSymTabRec DisplayTab[] =
{
{ENDSUBSECTION, "endsubsection"},
{MODES, "modes"},
{VIEWPORT, "viewport"},
{VIRTUAL, "virtual"},
{VISUAL, "visual"},
{BLACK_TOK, "black"},
{WHITE_TOK, "white"},
{DEPTH, "depth"},
{BPP, "fbbpp"},
{WEIGHT, "weight"},
{OPTION, "option"},
{-1, ""},
};
#define CLEANUP xf86freeDisplayList
XF86ConfDisplayPtr
xf86parseDisplaySubSection (void)
{
int token;
parsePrologue (XF86ConfDisplayPtr, XF86ConfDisplayRec)
ptr->disp_black.red = ptr->disp_black.green = ptr->disp_black.blue = -1;
ptr->disp_white.red = ptr->disp_white.green = ptr->disp_white.blue = -1;
ptr->disp_frameX0 = ptr->disp_frameY0 = -1;
while ((token = xf86getToken (DisplayTab)) != ENDSUBSECTION)
{
switch (token)
{
case COMMENT:
ptr->disp_comment = xf86addComment(ptr->disp_comment, val.str);
break;
case VIEWPORT:
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (VIEWPORT_MSG, NULL);
ptr->disp_frameX0 = val.num;
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (VIEWPORT_MSG, NULL);
ptr->disp_frameY0 = val.num;
break;
case VIRTUAL:
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (VIRTUAL_MSG, NULL);
ptr->disp_virtualX = val.num;
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (VIRTUAL_MSG, NULL);
ptr->disp_virtualY = val.num;
break;
case DEPTH:
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (NUMBER_MSG, "Display");
ptr->disp_depth = val.num;
break;
case BPP:
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (NUMBER_MSG, "Display");
ptr->disp_bpp = val.num;
break;
case VISUAL:
if (xf86getSubToken (&(ptr->disp_comment)) != STRING)
Error (QUOTE_MSG, "Display");
ptr->disp_visual = val.str;
break;
case WEIGHT:
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (WEIGHT_MSG, NULL);
ptr->disp_weight.red = val.num;
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (WEIGHT_MSG, NULL);
ptr->disp_weight.green = val.num;
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (WEIGHT_MSG, NULL);
ptr->disp_weight.blue = val.num;
break;
case BLACK_TOK:
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (BLACK_MSG, NULL);
ptr->disp_black.red = val.num;
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (BLACK_MSG, NULL);
ptr->disp_black.green = val.num;
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (BLACK_MSG, NULL);
ptr->disp_black.blue = val.num;
break;
case WHITE_TOK:
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (WHITE_MSG, NULL);
ptr->disp_white.red = val.num;
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (WHITE_MSG, NULL);
ptr->disp_white.green = val.num;
if (xf86getSubToken (&(ptr->disp_comment)) != NUMBER)
Error (WHITE_MSG, NULL);
ptr->disp_white.blue = val.num;
break;
case MODES:
{
XF86ModePtr mptr;
while ((token = xf86getSubTokenWithTab (&(ptr->disp_comment), DisplayTab)) == STRING)
{
mptr = xf86confcalloc (1, sizeof (XF86ModeRec));
mptr->mode_name = val.str;
mptr->list.next = NULL;
ptr->disp_mode_lst = (XF86ModePtr)
xf86addListItem ((glp) ptr->disp_mode_lst, (glp) mptr);
}
xf86unGetToken (token);
}
break;
case OPTION:
ptr->disp_option_lst = xf86parseOption(ptr->disp_option_lst);
break;
case EOF_TOKEN:
Error (UNEXPECTED_EOF_MSG, NULL);
break;
default:
Error (INVALID_KEYWORD_MSG, xf86tokenString ());
break;
}
}
#ifdef DEBUG
printf ("Display subsection parsed\n");
#endif
return ptr;
}
#undef CLEANUP
static xf86ConfigSymTabRec ScreenTab[] =
{
{ENDSECTION, "endsection"},
{IDENTIFIER, "identifier"},
{OBSDRIVER, "driver"},
{MDEVICE, "device"},
{MONITOR, "monitor"},
{VIDEOADAPTOR, "videoadaptor"},
{SCREENNO, "screenno"},
{SUBSECTION, "subsection"},
{DEFAULTDEPTH, "defaultcolordepth"},
{DEFAULTDEPTH, "defaultdepth"},
{DEFAULTBPP, "defaultbpp"},
{DEFAULTFBBPP, "defaultfbbpp"},
{OPTION, "option"},
{-1, ""},
};
#define CLEANUP xf86freeScreenList
XF86ConfScreenPtr
xf86parseScreenSection (void)
{
int has_ident = FALSE;
int has_driver= FALSE;
int token;
parsePrologue (XF86ConfScreenPtr, XF86ConfScreenRec)
while ((token = xf86getToken (ScreenTab)) != ENDSECTION)
{
switch (token)
{
case COMMENT:
ptr->scrn_comment = xf86addComment(ptr->scrn_comment, val.str);
break;
case IDENTIFIER:
if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
Error (QUOTE_MSG, "Identifier");
ptr->scrn_identifier = val.str;
if (has_ident || has_driver)
Error (ONLY_ONE_MSG,"Identifier or Driver");
has_ident = TRUE;
break;
case OBSDRIVER:
if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
Error (QUOTE_MSG, "Driver");
ptr->scrn_obso_driver = val.str;
if (has_ident || has_driver)
Error (ONLY_ONE_MSG,"Identifier or Driver");
has_driver = TRUE;
break;
case DEFAULTDEPTH:
if (xf86getSubToken (&(ptr->scrn_comment)) != NUMBER)
Error (NUMBER_MSG, "DefaultDepth");
ptr->scrn_defaultdepth = val.num;
break;
case DEFAULTBPP:
if (xf86getSubToken (&(ptr->scrn_comment)) != NUMBER)
Error (NUMBER_MSG, "DefaultBPP");
ptr->scrn_defaultbpp = val.num;
break;
case DEFAULTFBBPP:
if (xf86getSubToken (&(ptr->scrn_comment)) != NUMBER)
Error (NUMBER_MSG, "DefaultFbBPP");
ptr->scrn_defaultfbbpp = val.num;
break;
case MDEVICE:
if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
Error (QUOTE_MSG, "Device");
ptr->scrn_device_str = val.str;
break;
case MONITOR:
if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
Error (QUOTE_MSG, "Monitor");
ptr->scrn_monitor_str = val.str;
break;
case VIDEOADAPTOR:
{
XF86ConfAdaptorLinkPtr aptr;
if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
Error (QUOTE_MSG, "VideoAdaptor");
/* Don't allow duplicates */
for (aptr = ptr->scrn_adaptor_lst; aptr;
aptr = (XF86ConfAdaptorLinkPtr) aptr->list.next)
if (xf86nameCompare (val.str, aptr->al_adaptor_str) == 0)
break;
if (aptr == NULL)
{
aptr = xf86confcalloc (1, sizeof (XF86ConfAdaptorLinkRec));
aptr->list.next = NULL;
aptr->al_adaptor_str = val.str;
ptr->scrn_adaptor_lst = (XF86ConfAdaptorLinkPtr)
xf86addListItem ((glp) ptr->scrn_adaptor_lst, (glp) aptr);
}
}
break;
case OPTION:
ptr->scrn_option_lst = xf86parseOption(ptr->scrn_option_lst);
break;
case SUBSECTION:
if (xf86getSubToken (&(ptr->scrn_comment)) != STRING)
Error (QUOTE_MSG, "SubSection");
{
xf86conffree(val.str);
HANDLE_LIST (scrn_display_lst, xf86parseDisplaySubSection,
XF86ConfDisplayPtr);
}
break;
case EOF_TOKEN:
Error (UNEXPECTED_EOF_MSG, NULL);
break;
default:
Error (INVALID_KEYWORD_MSG, xf86tokenString ());
break;
}
}
if (!has_ident && !has_driver)
Error (NO_IDENT_MSG, NULL);
#ifdef DEBUG
printf ("Screen section parsed\n");
#endif
return ptr;
}
void
xf86printScreenSection (FILE * cf, XF86ConfScreenPtr ptr)
{
XF86ConfAdaptorLinkPtr aptr;
XF86ConfDisplayPtr dptr;
XF86ModePtr mptr;
while (ptr)
{
fprintf (cf, "Section \"Screen\"\n");
if (ptr->scrn_comment)
fprintf (cf, "%s", ptr->scrn_comment);
if (ptr->scrn_identifier)
fprintf (cf, "\tIdentifier \"%s\"\n", ptr->scrn_identifier);
if (ptr->scrn_obso_driver)
fprintf (cf, "\tDriver \"%s\"\n", ptr->scrn_obso_driver);
if (ptr->scrn_device_str)
fprintf (cf, "\tDevice \"%s\"\n", ptr->scrn_device_str);
if (ptr->scrn_monitor_str)
fprintf (cf, "\tMonitor \"%s\"\n", ptr->scrn_monitor_str);
if (ptr->scrn_defaultdepth)
fprintf (cf, "\tDefaultDepth %d\n",
ptr->scrn_defaultdepth);
if (ptr->scrn_defaultbpp)
fprintf (cf, "\tDefaultBPP %d\n",
ptr->scrn_defaultbpp);
if (ptr->scrn_defaultfbbpp)
fprintf (cf, "\tDefaultFbBPP %d\n",
ptr->scrn_defaultfbbpp);
xf86printOptionList(cf, ptr->scrn_option_lst, 1);
for (aptr = ptr->scrn_adaptor_lst; aptr; aptr = aptr->list.next)
{
fprintf (cf, "\tVideoAdaptor \"%s\"\n", aptr->al_adaptor_str);
}
for (dptr = ptr->scrn_display_lst; dptr; dptr = dptr->list.next)
{
fprintf (cf, "\tSubSection \"Display\"\n");
if (dptr->disp_comment)
fprintf (cf, "%s", dptr->disp_comment);
if (dptr->disp_frameX0 >= 0 || dptr->disp_frameY0 >= 0)
{
fprintf (cf, "\t\tViewport %d %d\n",
dptr->disp_frameX0, dptr->disp_frameY0);
}
if (dptr->disp_virtualX != 0 || dptr->disp_virtualY != 0)
{
fprintf (cf, "\t\tVirtual %d %d\n",
dptr->disp_virtualX, dptr->disp_virtualY);
}
if (dptr->disp_depth)
{
fprintf (cf, "\t\tDepth %d\n", dptr->disp_depth);
}
if (dptr->disp_bpp)
{
fprintf (cf, "\t\tFbBPP %d\n", dptr->disp_bpp);
}
if (dptr->disp_visual)
{
fprintf (cf, "\t\tVisual \"%s\"\n", dptr->disp_visual);
}
if (dptr->disp_weight.red != 0)
{
fprintf (cf, "\t\tWeight %d %d %d\n",
dptr->disp_weight.red, dptr->disp_weight.green, dptr->disp_weight.blue);
}
if (dptr->disp_black.red != -1)
{
fprintf (cf, "\t\tBlack 0x%04x 0x%04x 0x%04x\n",
dptr->disp_black.red, dptr->disp_black.green, dptr->disp_black.blue);
}
if (dptr->disp_white.red != -1)
{
fprintf (cf, "\t\tWhite 0x%04x 0x%04x 0x%04x\n",
dptr->disp_white.red, dptr->disp_white.green, dptr->disp_white.blue);
}
if (dptr->disp_mode_lst)
{
fprintf (cf, "\t\tModes ");
}
for (mptr = dptr->disp_mode_lst; mptr; mptr = mptr->list.next)
{
fprintf (cf, " \"%s\"", mptr->mode_name);
}
if (dptr->disp_mode_lst)
{
fprintf (cf, "\n");
}
xf86printOptionList(cf, dptr->disp_option_lst, 2);
fprintf (cf, "\tEndSubSection\n");
}
fprintf (cf, "EndSection\n\n");
ptr = ptr->list.next;
}
}
void
xf86freeScreenList (XF86ConfScreenPtr ptr)
{
XF86ConfScreenPtr prev;
while (ptr)
{
TestFree (ptr->scrn_identifier);
TestFree (ptr->scrn_monitor_str);
TestFree (ptr->scrn_device_str);
TestFree (ptr->scrn_comment);
xf86optionListFree (ptr->scrn_option_lst);
xf86freeAdaptorLinkList (ptr->scrn_adaptor_lst);
xf86freeDisplayList (ptr->scrn_display_lst);
prev = ptr;
ptr = ptr->list.next;
xf86conffree (prev);
}
}
void
xf86freeAdaptorLinkList (XF86ConfAdaptorLinkPtr ptr)
{
XF86ConfAdaptorLinkPtr prev;
while (ptr)
{
TestFree (ptr->al_adaptor_str);
prev = ptr;
ptr = ptr->list.next;
xf86conffree (prev);
}
}
void
xf86freeDisplayList (XF86ConfDisplayPtr ptr)
{
XF86ConfDisplayPtr prev;
while (ptr)
{
xf86freeModeList (ptr->disp_mode_lst);
xf86optionListFree (ptr->disp_option_lst);
prev = ptr;
ptr = ptr->list.next;
xf86conffree (prev);
}
}
void
xf86freeModeList (XF86ModePtr ptr)
{
XF86ModePtr prev;
while (ptr)
{
TestFree (ptr->mode_name);
prev = ptr;
ptr = ptr->list.next;
xf86conffree (prev);
}
}
int
xf86validateScreen (XF86ConfigPtr p)
{
XF86ConfScreenPtr screen = p->conf_screen_lst;
XF86ConfMonitorPtr monitor;
XF86ConfDevicePtr device;
XF86ConfAdaptorLinkPtr adaptor;
if (!screen)
{
xf86validationError ("At least one Screen section is required.");
return (FALSE);
}
while (screen)
{
if (screen->scrn_obso_driver && !screen->scrn_identifier)
screen->scrn_identifier = screen->scrn_obso_driver;
monitor = xf86findMonitor (screen->scrn_monitor_str, p->conf_monitor_lst);
if (screen->scrn_monitor_str)
{
if (!monitor)
{
xf86validationError (UNDEFINED_MONITOR_MSG,
screen->scrn_monitor_str, screen->scrn_identifier);
return (FALSE);
}
else
{
screen->scrn_monitor = monitor;
if (!xf86validateMonitor(p, screen))
return (FALSE);
}
}
device = xf86findDevice (screen->scrn_device_str, p->conf_device_lst);
if (!device)
{
xf86validationError (UNDEFINED_DEVICE_MSG,
screen->scrn_device_str, screen->scrn_identifier);
return (FALSE);
}
else
screen->scrn_device = device;
adaptor = screen->scrn_adaptor_lst;
while (adaptor)
{
adaptor->al_adaptor = xf86findVideoAdaptor (adaptor->al_adaptor_str, p->conf_videoadaptor_lst);
if (!adaptor->al_adaptor)
{
xf86validationError (UNDEFINED_ADAPTOR_MSG, adaptor->al_adaptor_str, screen->scrn_identifier);
return (FALSE);
}
else if (adaptor->al_adaptor->va_fwdref)
{
xf86validationError (ADAPTOR_REF_TWICE_MSG, adaptor->al_adaptor_str,
adaptor->al_adaptor->va_fwdref);
return (FALSE);
}
adaptor->al_adaptor->va_fwdref = xf86configStrdup(screen->scrn_identifier);
adaptor = adaptor->list.next;
}
screen = screen->list.next;
}
return (TRUE);
}
XF86ConfScreenPtr
xf86findScreen (const char *ident, XF86ConfScreenPtr p)
{
while (p)
{
if (xf86nameCompare (ident, p->scrn_identifier) == 0)
return (p);
p = p->list.next;
}
return (NULL);
}
|