~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xfree86/parser/Monitor.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Monitor.c,v 1.28 2003/08/24 17:37:08 dawes Exp $ */
 
2
/* 
 
3
 * 
 
4
 * Copyright (c) 1997  Metro Link Incorporated
 
5
 * 
 
6
 * Permission is hereby granted, free of charge, to any person obtaining a
 
7
 * copy of this software and associated documentation files (the "Software"), 
 
8
 * to deal in the Software without restriction, including without limitation
 
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
10
 * and/or sell copies of the Software, and to permit persons to whom the
 
11
 * Software is furnished to do so, subject to the following conditions:
 
12
 * 
 
13
 * The above copyright notice and this permission notice shall be included in
 
14
 * all copies or substantial portions of the Software.
 
15
 * 
 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
19
 * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
20
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 
21
 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
22
 * SOFTWARE.
 
23
 * 
 
24
 * Except as contained in this notice, the name of the Metro Link shall not be
 
25
 * used in advertising or otherwise to promote the sale, use or other dealings
 
26
 * in this Software without prior written authorization from Metro Link.
 
27
 * 
 
28
 */
 
29
/*
 
30
 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
 
31
 *
 
32
 * Permission is hereby granted, free of charge, to any person obtaining a
 
33
 * copy of this software and associated documentation files (the "Software"),
 
34
 * to deal in the Software without restriction, including without limitation
 
35
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
36
 * and/or sell copies of the Software, and to permit persons to whom the
 
37
 * Software is furnished to do so, subject to the following conditions:
 
38
 *
 
39
 * The above copyright notice and this permission notice shall be included in
 
40
 * all copies or substantial portions of the Software.
 
41
 *
 
42
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
43
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
44
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
45
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
46
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
47
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
48
 * OTHER DEALINGS IN THE SOFTWARE.
 
49
 *
 
50
 * Except as contained in this notice, the name of the copyright holder(s)
 
51
 * and author(s) shall not be used in advertising or otherwise to promote
 
52
 * the sale, use or other dealings in this Software without prior written
 
53
 * authorization from the copyright holder(s) and author(s).
 
54
 */
 
55
 
 
56
 
 
57
/* View/edit this file with tab stops set to 4 */
 
58
 
 
59
#ifdef HAVE_XORG_CONFIG_H
 
60
#include <xorg-config.h>
 
61
#endif
 
62
 
 
63
#include "xf86Parser.h"
 
64
#include "xf86tokens.h"
 
65
#include "Configint.h"
 
66
 
 
67
extern LexRec val;
 
68
 
 
69
static xf86ConfigSymTabRec MonitorTab[] =
 
70
{
 
71
        {ENDSECTION, "endsection"},
 
72
        {IDENTIFIER, "identifier"},
 
73
        {VENDOR, "vendorname"},
 
74
        {MODEL, "modelname"},
 
75
        {USEMODES, "usemodes"},
 
76
        {MODELINE, "modeline"},
 
77
        {DISPLAYSIZE, "displaysize"},
 
78
        {HORIZSYNC, "horizsync"},
 
79
        {VERTREFRESH, "vertrefresh"},
 
80
        {MODE, "mode"},
 
81
        {GAMMA, "gamma"},
 
82
        {OPTION, "option"},
 
83
        {-1, ""},
 
84
};
 
85
 
 
86
static xf86ConfigSymTabRec ModesTab[] =
 
87
{
 
88
        {ENDSECTION, "endsection"},
 
89
        {IDENTIFIER, "identifier"},
 
90
        {MODELINE, "modeline"},
 
91
        {MODE, "mode"},
 
92
        {-1, ""},
 
93
};
 
94
 
 
95
static xf86ConfigSymTabRec TimingTab[] =
 
96
{
 
97
        {TT_INTERLACE, "interlace"},
 
98
        {TT_PHSYNC, "+hsync"},
 
99
        {TT_NHSYNC, "-hsync"},
 
100
        {TT_PVSYNC, "+vsync"},
 
101
        {TT_NVSYNC, "-vsync"},
 
102
        {TT_CSYNC, "composite"},
 
103
        {TT_PCSYNC, "+csync"},
 
104
        {TT_NCSYNC, "-csync"},
 
105
        {TT_DBLSCAN, "doublescan"},
 
106
        {TT_HSKEW, "hskew"},
 
107
        {TT_BCAST, "bcast"},
 
108
        {TT_VSCAN, "vscan"},
 
109
        {TT_CUSTOM, "CUSTOM"},
 
110
        {-1, ""},
 
111
};
 
112
 
 
113
static xf86ConfigSymTabRec ModeTab[] =
 
114
{
 
115
        {DOTCLOCK, "dotclock"},
 
116
        {HTIMINGS, "htimings"},
 
117
        {VTIMINGS, "vtimings"},
 
118
        {FLAGS, "flags"},
 
119
        {HSKEW, "hskew"},
 
120
        {BCAST, "bcast"},
 
121
        {VSCAN, "vscan"},
 
122
        {ENDMODE, "endmode"},
 
123
        {-1, ""},
 
124
};
 
125
 
 
126
#define CLEANUP xf86freeModeLineList
 
127
 
 
128
XF86ConfModeLinePtr
 
129
xf86parseModeLine (void)
 
130
{
 
131
        int token;
 
132
        parsePrologue (XF86ConfModeLinePtr, XF86ConfModeLineRec)
 
133
 
 
134
        /* Identifier */
 
135
        if (xf86getSubToken (&(ptr->ml_comment)) != STRING)
 
136
                Error ("ModeLine identifier expected", NULL);
 
137
        ptr->ml_identifier = val.str;
 
138
 
 
139
        /* DotClock */
 
140
        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
141
                Error ("ModeLine dotclock expected", NULL);
 
142
        ptr->ml_clock = (int) (val.realnum * 1000.0 + 0.5);
 
143
 
 
144
        /* HDisplay */
 
145
        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
146
                Error ("ModeLine Hdisplay expected", NULL);
 
147
        ptr->ml_hdisplay = val.num;
 
148
 
 
149
        /* HSyncStart */
 
150
        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
151
                Error ("ModeLine HSyncStart expected", NULL);
 
152
        ptr->ml_hsyncstart = val.num;
 
153
 
 
154
        /* HSyncEnd */
 
155
        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
156
                Error ("ModeLine HSyncEnd expected", NULL);
 
157
        ptr->ml_hsyncend = val.num;
 
158
 
 
159
        /* HTotal */
 
160
        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
161
                Error ("ModeLine HTotal expected", NULL);
 
162
        ptr->ml_htotal = val.num;
 
163
 
 
164
        /* VDisplay */
 
165
        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
166
                Error ("ModeLine Vdisplay expected", NULL);
 
167
        ptr->ml_vdisplay = val.num;
 
168
 
 
169
        /* VSyncStart */
 
170
        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
171
                Error ("ModeLine VSyncStart expected", NULL);
 
172
        ptr->ml_vsyncstart = val.num;
 
173
 
 
174
        /* VSyncEnd */
 
175
        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
176
                Error ("ModeLine VSyncEnd expected", NULL);
 
177
        ptr->ml_vsyncend = val.num;
 
178
 
 
179
        /* VTotal */
 
180
        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
181
                Error ("ModeLine VTotal expected", NULL);
 
182
        ptr->ml_vtotal = val.num;
 
183
 
 
184
        token = xf86getSubTokenWithTab (&(ptr->ml_comment), TimingTab);
 
185
        while ((token == TT_INTERLACE) || (token == TT_PHSYNC) ||
 
186
                   (token == TT_NHSYNC) || (token == TT_PVSYNC) ||
 
187
                   (token == TT_NVSYNC) || (token == TT_CSYNC) ||
 
188
                   (token == TT_PCSYNC) || (token == TT_NCSYNC) ||
 
189
                   (token == TT_DBLSCAN) || (token == TT_HSKEW) ||
 
190
                   (token == TT_VSCAN) || (token == TT_BCAST))
 
191
        {
 
192
                switch (token)
 
193
                {
 
194
 
 
195
                case TT_INTERLACE:
 
196
                        ptr->ml_flags |= XF86CONF_INTERLACE;
 
197
                        break;
 
198
                case TT_PHSYNC:
 
199
                        ptr->ml_flags |= XF86CONF_PHSYNC;
 
200
                        break;
 
201
                case TT_NHSYNC:
 
202
                        ptr->ml_flags |= XF86CONF_NHSYNC;
 
203
                        break;
 
204
                case TT_PVSYNC:
 
205
                        ptr->ml_flags |= XF86CONF_PVSYNC;
 
206
                        break;
 
207
                case TT_NVSYNC:
 
208
                        ptr->ml_flags |= XF86CONF_NVSYNC;
 
209
                        break;
 
210
                case TT_CSYNC:
 
211
                        ptr->ml_flags |= XF86CONF_CSYNC;
 
212
                        break;
 
213
                case TT_PCSYNC:
 
214
                        ptr->ml_flags |= XF86CONF_PCSYNC;
 
215
                        break;
 
216
                case TT_NCSYNC:
 
217
                        ptr->ml_flags |= XF86CONF_NCSYNC;
 
218
                        break;
 
219
                case TT_DBLSCAN:
 
220
                        ptr->ml_flags |= XF86CONF_DBLSCAN;
 
221
                        break;
 
222
                case TT_HSKEW:
 
223
                        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
224
                                Error (NUMBER_MSG, "Hskew");
 
225
                        ptr->ml_hskew = val.num;
 
226
                        ptr->ml_flags |= XF86CONF_HSKEW;
 
227
                        break;
 
228
                case TT_BCAST:
 
229
                        ptr->ml_flags |= XF86CONF_BCAST;
 
230
                        break;
 
231
                case TT_VSCAN:
 
232
                        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
233
                                Error (NUMBER_MSG, "Vscan");
 
234
                        ptr->ml_vscan = val.num;
 
235
                        ptr->ml_flags |= XF86CONF_VSCAN;
 
236
                        break;
 
237
                case TT_CUSTOM:
 
238
                        ptr->ml_flags |= XF86CONF_CUSTOM;
 
239
                        break;
 
240
                case EOF_TOKEN:
 
241
                        Error (UNEXPECTED_EOF_MSG, NULL);
 
242
                        break;
 
243
                default:
 
244
                        Error (INVALID_KEYWORD_MSG, xf86tokenString ());
 
245
                        break;
 
246
                }
 
247
                token = xf86getSubTokenWithTab (&(ptr->ml_comment), TimingTab);
 
248
        }
 
249
        xf86unGetToken (token);
 
250
 
 
251
#ifdef DEBUG
 
252
        printf ("ModeLine parsed\n");
 
253
#endif
 
254
        return (ptr);
 
255
}
 
256
 
 
257
XF86ConfModeLinePtr
 
258
xf86parseVerboseMode (void)
 
259
{
 
260
        int token, token2;
 
261
        int had_dotclock = 0, had_htimings = 0, had_vtimings = 0;
 
262
        parsePrologue (XF86ConfModeLinePtr, XF86ConfModeLineRec)
 
263
 
 
264
                if (xf86getSubToken (&(ptr->ml_comment)) != STRING)
 
265
                Error ("Mode name expected", NULL);
 
266
        ptr->ml_identifier = val.str;
 
267
        while ((token = xf86getToken (ModeTab)) != ENDMODE)
 
268
        {
 
269
                switch (token)
 
270
                {
 
271
                case COMMENT:
 
272
                        ptr->ml_comment = xf86addComment(ptr->ml_comment, val.str);
 
273
                        break;
 
274
                case DOTCLOCK:
 
275
                        if ((token = xf86getSubToken (&(ptr->ml_comment))) != NUMBER)
 
276
                                Error (NUMBER_MSG, "DotClock");
 
277
                        ptr->ml_clock = (int) (val.realnum * 1000.0 + 0.5);
 
278
                        had_dotclock = 1;
 
279
                        break;
 
280
                case HTIMINGS:
 
281
                        if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
 
282
                                ptr->ml_hdisplay = val.num;
 
283
                        else
 
284
                                Error ("Horizontal display expected", NULL);
 
285
 
 
286
                        if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
 
287
                                ptr->ml_hsyncstart = val.num;
 
288
                        else
 
289
                                Error ("Horizontal sync start expected", NULL);
 
290
 
 
291
                        if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
 
292
                                ptr->ml_hsyncend = val.num;
 
293
                        else
 
294
                                Error ("Horizontal sync end expected", NULL);
 
295
 
 
296
                        if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
 
297
                                ptr->ml_htotal = val.num;
 
298
                        else
 
299
                                Error ("Horizontal total expected", NULL);
 
300
                        had_htimings = 1;
 
301
                        break;
 
302
                case VTIMINGS:
 
303
                        if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
 
304
                                ptr->ml_vdisplay = val.num;
 
305
                        else
 
306
                                Error ("Vertical display expected", NULL);
 
307
 
 
308
                        if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
 
309
                                ptr->ml_vsyncstart = val.num;
 
310
                        else
 
311
                                Error ("Vertical sync start expected", NULL);
 
312
 
 
313
                        if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
 
314
                                ptr->ml_vsyncend = val.num;
 
315
                        else
 
316
                                Error ("Vertical sync end expected", NULL);
 
317
 
 
318
                        if (xf86getSubToken (&(ptr->ml_comment)) == NUMBER)
 
319
                                ptr->ml_vtotal = val.num;
 
320
                        else
 
321
                                Error ("Vertical total expected", NULL);
 
322
                        had_vtimings = 1;
 
323
                        break;
 
324
                case FLAGS:
 
325
                        token = xf86getSubToken (&(ptr->ml_comment));
 
326
                        if (token != STRING)
 
327
                                Error (QUOTE_MSG, "Flags");
 
328
                        while (token == STRING)
 
329
                        {
 
330
                                token2 = xf86getStringToken (TimingTab);
 
331
                                switch (token2)
 
332
                                {
 
333
                                case TT_INTERLACE:
 
334
                                        ptr->ml_flags |= XF86CONF_INTERLACE;
 
335
                                        break;
 
336
                                case TT_PHSYNC:
 
337
                                        ptr->ml_flags |= XF86CONF_PHSYNC;
 
338
                                        break;
 
339
                                case TT_NHSYNC:
 
340
                                        ptr->ml_flags |= XF86CONF_NHSYNC;
 
341
                                        break;
 
342
                                case TT_PVSYNC:
 
343
                                        ptr->ml_flags |= XF86CONF_PVSYNC;
 
344
                                        break;
 
345
                                case TT_NVSYNC:
 
346
                                        ptr->ml_flags |= XF86CONF_NVSYNC;
 
347
                                        break;
 
348
                                case TT_CSYNC:
 
349
                                        ptr->ml_flags |= XF86CONF_CSYNC;
 
350
                                        break;
 
351
                                case TT_PCSYNC:
 
352
                                        ptr->ml_flags |= XF86CONF_PCSYNC;
 
353
                                        break;
 
354
                                case TT_NCSYNC:
 
355
                                        ptr->ml_flags |= XF86CONF_NCSYNC;
 
356
                                        break;
 
357
                                case TT_DBLSCAN:
 
358
                                        ptr->ml_flags |= XF86CONF_DBLSCAN;
 
359
                                        break;
 
360
                                case TT_CUSTOM:
 
361
                                        ptr->ml_flags |= XF86CONF_CUSTOM;
 
362
                                        break;
 
363
                                case EOF_TOKEN:
 
364
                                        Error (UNEXPECTED_EOF_MSG, NULL);
 
365
                                        break;
 
366
                                default:
 
367
                                        Error ("Unknown flag string", NULL);
 
368
                                        break;
 
369
                                }
 
370
                                token = xf86getSubToken (&(ptr->ml_comment));
 
371
                        }
 
372
                        xf86unGetToken (token);
 
373
                        break;
 
374
                case HSKEW:
 
375
                        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
376
                                Error ("Horizontal skew expected", NULL);
 
377
                        ptr->ml_flags |= XF86CONF_HSKEW;
 
378
                        ptr->ml_hskew = val.num;
 
379
                        break;
 
380
                case VSCAN:
 
381
                        if (xf86getSubToken (&(ptr->ml_comment)) != NUMBER)
 
382
                                Error ("Vertical scan count expected", NULL);
 
383
                        ptr->ml_flags |= XF86CONF_VSCAN;
 
384
                        ptr->ml_vscan = val.num;
 
385
                        break;
 
386
                case EOF_TOKEN:
 
387
                        Error (UNEXPECTED_EOF_MSG, NULL);
 
388
                        break;
 
389
                default:
 
390
                        Error ("Unexepcted token in verbose \"Mode\" entry\n", NULL);
 
391
                }
 
392
        }
 
393
        if (!had_dotclock)
 
394
                Error ("the dotclock is missing", NULL);
 
395
        if (!had_htimings)
 
396
                Error ("the horizontal timings are missing", NULL);
 
397
        if (!had_vtimings)
 
398
                Error ("the vertical timings are missing", NULL);
 
399
 
 
400
#ifdef DEBUG
 
401
        printf ("Verbose Mode parsed\n");
 
402
#endif
 
403
        return (ptr);
 
404
}
 
405
 
 
406
#undef CLEANUP
 
407
 
 
408
#define CLEANUP xf86freeMonitorList
 
409
 
 
410
XF86ConfMonitorPtr
 
411
xf86parseMonitorSection (void)
 
412
{
 
413
        int has_ident = FALSE;
 
414
        int token;
 
415
        parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec)
 
416
 
 
417
                while ((token = xf86getToken (MonitorTab)) != ENDSECTION)
 
418
        {
 
419
                switch (token)
 
420
                {
 
421
                case COMMENT:
 
422
                        ptr->mon_comment = xf86addComment(ptr->mon_comment, val.str);
 
423
                        break;
 
424
                case IDENTIFIER:
 
425
                        if (xf86getSubToken (&(ptr->mon_comment)) != STRING)
 
426
                                Error (QUOTE_MSG, "Identifier");
 
427
                        if (has_ident == TRUE)
 
428
                                Error (MULTIPLE_MSG, "Identifier");
 
429
                        ptr->mon_identifier = val.str;
 
430
                        has_ident = TRUE;
 
431
                        break;
 
432
                case VENDOR:
 
433
                        if (xf86getSubToken (&(ptr->mon_comment)) != STRING)
 
434
                                Error (QUOTE_MSG, "Vendor");
 
435
                        ptr->mon_vendor = val.str;
 
436
                        break;
 
437
                case MODEL:
 
438
                        if (xf86getSubToken (&(ptr->mon_comment)) != STRING)
 
439
                                Error (QUOTE_MSG, "ModelName");
 
440
                        ptr->mon_modelname = val.str;
 
441
                        break;
 
442
                case MODE:
 
443
                        HANDLE_LIST (mon_modeline_lst, xf86parseVerboseMode,
 
444
                                                 XF86ConfModeLinePtr);
 
445
                        break;
 
446
                case MODELINE:
 
447
                        HANDLE_LIST (mon_modeline_lst, xf86parseModeLine,
 
448
                                                 XF86ConfModeLinePtr);
 
449
                        break;
 
450
                case DISPLAYSIZE:
 
451
                        if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER)
 
452
                                Error (DISPLAYSIZE_MSG, NULL);
 
453
                        ptr->mon_width = val.realnum;
 
454
                        if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER)
 
455
                                Error (DISPLAYSIZE_MSG, NULL);
 
456
                        ptr->mon_height = val.realnum;
 
457
                        break;
 
458
 
 
459
                case HORIZSYNC:
 
460
                        if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER)
 
461
                                Error (HORIZSYNC_MSG, NULL);
 
462
                        do {
 
463
                                ptr->mon_hsync[ptr->mon_n_hsync].lo = val.realnum;
 
464
                                switch (token = xf86getSubToken (&(ptr->mon_comment)))
 
465
                                {
 
466
                                        case COMMA:
 
467
                                                ptr->mon_hsync[ptr->mon_n_hsync].hi =
 
468
                                                ptr->mon_hsync[ptr->mon_n_hsync].lo;
 
469
                                                break;
 
470
                                        case DASH:
 
471
                                                if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER ||
 
472
                                                    (float)val.realnum < ptr->mon_hsync[ptr->mon_n_hsync].lo)
 
473
                                                        Error (HORIZSYNC_MSG, NULL);
 
474
                                                ptr->mon_hsync[ptr->mon_n_hsync].hi = val.realnum;
 
475
                                                if ((token = xf86getSubToken (&(ptr->mon_comment))) == COMMA)
 
476
                                                        break;
 
477
                                                ptr->mon_n_hsync++;
 
478
                                                goto HorizDone;
 
479
                                        default:
 
480
                                                /* We cannot currently know if a '\n' was found,
 
481
                                                 * or this is a real error
 
482
                                                 */
 
483
                                                ptr->mon_hsync[ptr->mon_n_hsync].hi =
 
484
                                                ptr->mon_hsync[ptr->mon_n_hsync].lo;
 
485
                                                ptr->mon_n_hsync++;
 
486
                                                goto HorizDone;
 
487
                                }
 
488
                                if (ptr->mon_n_hsync >= CONF_MAX_HSYNC)
 
489
                                        Error ("Sorry. Too many horizontal sync intervals.", NULL);
 
490
                                ptr->mon_n_hsync++;
 
491
                        } while ((token = xf86getSubToken (&(ptr->mon_comment))) == NUMBER);
 
492
HorizDone:
 
493
                        xf86unGetToken (token);
 
494
                        break;
 
495
 
 
496
                case VERTREFRESH:
 
497
                        if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER)
 
498
                                Error (VERTREFRESH_MSG, NULL);
 
499
                        do {
 
500
                                ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo = val.realnum;
 
501
                                switch (token = xf86getSubToken (&(ptr->mon_comment)))
 
502
                                {
 
503
                                        case COMMA:
 
504
                                                ptr->mon_vrefresh[ptr->mon_n_vrefresh].hi =
 
505
                                                ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo;
 
506
                                                break;
 
507
                                        case DASH:
 
508
                                                if (xf86getSubToken (&(ptr->mon_comment)) != NUMBER ||
 
509
                                                    (float)val.realnum < ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo)
 
510
                                                        Error (VERTREFRESH_MSG, NULL);
 
511
                                                ptr->mon_vrefresh[ptr->mon_n_vrefresh].hi = val.realnum;
 
512
                                                if ((token = xf86getSubToken (&(ptr->mon_comment))) == COMMA)
 
513
                                                        break;
 
514
                                                ptr->mon_n_vrefresh++;
 
515
                                                goto VertDone;
 
516
                                        default:
 
517
                                                /* We cannot currently know if a '\n' was found,
 
518
                                                 * or this is a real error
 
519
                                                 */
 
520
                                                ptr->mon_vrefresh[ptr->mon_n_vrefresh].hi =
 
521
                                                ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo;
 
522
                                                ptr->mon_n_vrefresh++;
 
523
                                                goto VertDone;
 
524
                                }
 
525
                                if (ptr->mon_n_vrefresh >= CONF_MAX_VREFRESH)
 
526
                                        Error ("Sorry. Too many vertical refresh intervals.", NULL);
 
527
                                ptr->mon_n_vrefresh++;
 
528
                        } while ((token = xf86getSubToken (&(ptr->mon_comment))) == NUMBER);
 
529
VertDone:
 
530
                        xf86unGetToken (token);
 
531
                        break;
 
532
 
 
533
                case GAMMA:
 
534
                        if( xf86getSubToken (&(ptr->mon_comment)) != NUMBER )
 
535
                        {
 
536
                                Error (INVALID_GAMMA_MSG, NULL);
 
537
                        }
 
538
                        else
 
539
                        {
 
540
                                ptr->mon_gamma_red = ptr->mon_gamma_green =
 
541
                                        ptr->mon_gamma_blue = val.realnum;
 
542
                                if( xf86getSubToken (&(ptr->mon_comment)) == NUMBER )
 
543
                                {
 
544
                                        ptr->mon_gamma_green = val.realnum;
 
545
                                        if( xf86getSubToken (&(ptr->mon_comment)) == NUMBER )
 
546
                                        {
 
547
                                                ptr->mon_gamma_blue = val.realnum;
 
548
                                        }
 
549
                                        else
 
550
                                        {
 
551
                                                Error (INVALID_GAMMA_MSG, NULL);
 
552
                                        }
 
553
                                }
 
554
                                else
 
555
                                        xf86unGetToken (token);
 
556
                        }
 
557
                        break;
 
558
                case OPTION:
 
559
                        ptr->mon_option_lst = xf86parseOption(ptr->mon_option_lst);
 
560
                        break;
 
561
                case USEMODES:
 
562
                        {
 
563
                                XF86ConfModesLinkPtr mptr;
 
564
 
 
565
                                if ((token = xf86getSubToken (&(ptr->mon_comment))) != STRING)
 
566
                                        Error (QUOTE_MSG, "UseModes");
 
567
 
 
568
                                /* add to the end of the list of modes sections 
 
569
                                   referenced here */
 
570
                                mptr = xf86confcalloc (1, sizeof (XF86ConfModesLinkRec));
 
571
                                mptr->list.next = NULL;
 
572
                                mptr->ml_modes_str = val.str;
 
573
                                mptr->ml_modes = NULL;
 
574
                                ptr->mon_modes_sect_lst = (XF86ConfModesLinkPtr)
 
575
                                        xf86addListItem((GenericListPtr)ptr->mon_modes_sect_lst,
 
576
                                                    (GenericListPtr)mptr);
 
577
                        }
 
578
                        break;
 
579
                case EOF_TOKEN:
 
580
                        Error (UNEXPECTED_EOF_MSG, NULL);
 
581
                        break;
 
582
                default:
 
583
                        xf86parseError (INVALID_KEYWORD_MSG, xf86tokenString ());
 
584
                        CLEANUP (ptr);
 
585
                        return NULL;
 
586
                        break;
 
587
                }
 
588
        }
 
589
 
 
590
        if (!has_ident)
 
591
                Error (NO_IDENT_MSG, NULL);
 
592
 
 
593
#ifdef DEBUG
 
594
        printf ("Monitor section parsed\n");
 
595
#endif
 
596
        return ptr;
 
597
}
 
598
 
 
599
#undef CLEANUP
 
600
#define CLEANUP xf86freeModesList
 
601
 
 
602
XF86ConfModesPtr
 
603
xf86parseModesSection (void)
 
604
{
 
605
        int has_ident = FALSE;
 
606
        int token;
 
607
        parsePrologue (XF86ConfModesPtr, XF86ConfModesRec)
 
608
 
 
609
        while ((token = xf86getToken (ModesTab)) != ENDSECTION)
 
610
        {
 
611
                switch (token)
 
612
                {
 
613
                case COMMENT:
 
614
                        ptr->modes_comment = xf86addComment(ptr->modes_comment, val.str);
 
615
                        break;
 
616
                case IDENTIFIER:
 
617
                        if (xf86getSubToken (&(ptr->modes_comment)) != STRING)
 
618
                                Error (QUOTE_MSG, "Identifier");
 
619
                        if (has_ident == TRUE)
 
620
                                Error (MULTIPLE_MSG, "Identifier");
 
621
                        ptr->modes_identifier = val.str;
 
622
                        has_ident = TRUE;
 
623
                        break;
 
624
                case MODE:
 
625
                        HANDLE_LIST (mon_modeline_lst, xf86parseVerboseMode,
 
626
                                                 XF86ConfModeLinePtr);
 
627
                        break;
 
628
                case MODELINE:
 
629
                        HANDLE_LIST (mon_modeline_lst, xf86parseModeLine,
 
630
                                                 XF86ConfModeLinePtr);
 
631
                        break;
 
632
                default:
 
633
                        xf86parseError (INVALID_KEYWORD_MSG, xf86tokenString ());
 
634
                        CLEANUP (ptr);
 
635
                        return NULL;
 
636
                        break;
 
637
                }
 
638
        }
 
639
 
 
640
        if (!has_ident)
 
641
                Error (NO_IDENT_MSG, NULL);
 
642
 
 
643
#ifdef DEBUG
 
644
        printf ("Modes section parsed\n");
 
645
#endif
 
646
        return ptr;
 
647
}
 
648
 
 
649
#undef CLEANUP
 
650
 
 
651
void
 
652
xf86printMonitorSection (FILE * cf, XF86ConfMonitorPtr ptr)
 
653
{
 
654
        int i;
 
655
        XF86ConfModeLinePtr mlptr;
 
656
        XF86ConfModesLinkPtr mptr;
 
657
 
 
658
        while (ptr)
 
659
        {
 
660
                mptr = ptr->mon_modes_sect_lst;
 
661
                fprintf (cf, "Section \"Monitor\"\n");
 
662
                if (ptr->mon_comment)
 
663
                        fprintf (cf, "%s", ptr->mon_comment);
 
664
                if (ptr->mon_identifier)
 
665
                        fprintf (cf, "\tIdentifier   \"%s\"\n", ptr->mon_identifier);
 
666
                if (ptr->mon_vendor)
 
667
                        fprintf (cf, "\tVendorName   \"%s\"\n", ptr->mon_vendor);
 
668
                if (ptr->mon_modelname)
 
669
                        fprintf (cf, "\tModelName    \"%s\"\n", ptr->mon_modelname);
 
670
                while (mptr) {
 
671
                        fprintf (cf, "\tUseModes     \"%s\"\n", mptr->ml_modes_str);
 
672
                        mptr = mptr->list.next;
 
673
                }
 
674
                if (ptr->mon_width)
 
675
                        fprintf (cf, "\tDisplaySize  %d\t%d\n",
 
676
                                         ptr->mon_width,
 
677
                                         ptr->mon_height);
 
678
                if ( ptr->mon_n_hsync || ptr->mon_n_vrefresh )
 
679
                    fprintf(cf," ### Comment all HorizSync and VertSync values to use DDC:\n");
 
680
                for (i = 0; i < ptr->mon_n_hsync; i++)
 
681
                {
 
682
                        fprintf (cf, "\tHorizSync    %2.1f - %2.1f\n",
 
683
                                         ptr->mon_hsync[i].lo,
 
684
                                         ptr->mon_hsync[i].hi);
 
685
                }
 
686
                for (i = 0; i < ptr->mon_n_vrefresh; i++)
 
687
                {
 
688
                        fprintf (cf, "\tVertRefresh  %2.1f - %2.1f\n",
 
689
                                         ptr->mon_vrefresh[i].lo,
 
690
                                         ptr->mon_vrefresh[i].hi);
 
691
                }
 
692
                if (ptr->mon_gamma_red) {
 
693
                        if (ptr->mon_gamma_red == ptr->mon_gamma_green
 
694
                                && ptr->mon_gamma_red == ptr->mon_gamma_blue)
 
695
                        {
 
696
                                fprintf (cf, "\tGamma        %.4g\n",
 
697
                                        ptr->mon_gamma_red);
 
698
                        } else {
 
699
                                fprintf (cf, "\tGamma        %.4g %.4g %.4g\n",
 
700
                                        ptr->mon_gamma_red,
 
701
                                        ptr->mon_gamma_green,
 
702
                                        ptr->mon_gamma_blue);
 
703
                        }
 
704
                }
 
705
                for (mlptr = ptr->mon_modeline_lst; mlptr; mlptr = mlptr->list.next)
 
706
                {
 
707
                        fprintf (cf, "\tModeLine     \"%s\" %2.1f ",
 
708
                                         mlptr->ml_identifier, mlptr->ml_clock / 1000.0);
 
709
                        fprintf (cf, "%d %d %d %d %d %d %d %d",
 
710
                                         mlptr->ml_hdisplay, mlptr->ml_hsyncstart,
 
711
                                         mlptr->ml_hsyncend, mlptr->ml_htotal,
 
712
                                         mlptr->ml_vdisplay, mlptr->ml_vsyncstart,
 
713
                                         mlptr->ml_vsyncend, mlptr->ml_vtotal);
 
714
                        if (mlptr->ml_flags & XF86CONF_PHSYNC)
 
715
                                fprintf (cf, " +hsync");
 
716
                        if (mlptr->ml_flags & XF86CONF_NHSYNC)
 
717
                                fprintf (cf, " -hsync");
 
718
                        if (mlptr->ml_flags & XF86CONF_PVSYNC)
 
719
                                fprintf (cf, " +vsync");
 
720
                        if (mlptr->ml_flags & XF86CONF_NVSYNC)
 
721
                                fprintf (cf, " -vsync");
 
722
                        if (mlptr->ml_flags & XF86CONF_INTERLACE)
 
723
                                fprintf (cf, " interlace");
 
724
                        if (mlptr->ml_flags & XF86CONF_CSYNC)
 
725
                                fprintf (cf, " composite");
 
726
                        if (mlptr->ml_flags & XF86CONF_PCSYNC)
 
727
                                fprintf (cf, " +csync");
 
728
                        if (mlptr->ml_flags & XF86CONF_NCSYNC)
 
729
                                fprintf (cf, " -csync");
 
730
                        if (mlptr->ml_flags & XF86CONF_DBLSCAN)
 
731
                                fprintf (cf, " doublescan");
 
732
                        if (mlptr->ml_flags & XF86CONF_HSKEW)
 
733
                                fprintf (cf, " hskew %d", mlptr->ml_hskew);
 
734
                        if (mlptr->ml_flags & XF86CONF_BCAST)
 
735
                                fprintf (cf, " bcast");
 
736
                        fprintf (cf, "\n");
 
737
                }
 
738
                xf86printOptionList(cf, ptr->mon_option_lst, 1);
 
739
                fprintf (cf, "EndSection\n\n");
 
740
                ptr = ptr->list.next;
 
741
        }
 
742
}
 
743
 
 
744
void
 
745
xf86printModesSection (FILE * cf, XF86ConfModesPtr ptr)
 
746
{
 
747
        XF86ConfModeLinePtr mlptr;
 
748
 
 
749
        while (ptr)
 
750
        {
 
751
                fprintf (cf, "Section \"Modes\"\n");
 
752
                if (ptr->modes_comment)
 
753
                        fprintf (cf, "%s", ptr->modes_comment);
 
754
                if (ptr->modes_identifier)
 
755
                        fprintf (cf, "\tIdentifier     \"%s\"\n", ptr->modes_identifier);
 
756
                for (mlptr = ptr->mon_modeline_lst; mlptr; mlptr = mlptr->list.next)
 
757
                {
 
758
                        fprintf (cf, "\tModeLine     \"%s\" %2.1f ",
 
759
                                         mlptr->ml_identifier, mlptr->ml_clock / 1000.0);
 
760
                        fprintf (cf, "%d %d %d %d %d %d %d %d",
 
761
                                         mlptr->ml_hdisplay, mlptr->ml_hsyncstart,
 
762
                                         mlptr->ml_hsyncend, mlptr->ml_htotal,
 
763
                                         mlptr->ml_vdisplay, mlptr->ml_vsyncstart,
 
764
                                         mlptr->ml_vsyncend, mlptr->ml_vtotal);
 
765
                        if (mlptr->ml_flags & XF86CONF_PHSYNC)
 
766
                                fprintf (cf, " +hsync");
 
767
                        if (mlptr->ml_flags & XF86CONF_NHSYNC)
 
768
                                fprintf (cf, " -hsync");
 
769
                        if (mlptr->ml_flags & XF86CONF_PVSYNC)
 
770
                                fprintf (cf, " +vsync");
 
771
                        if (mlptr->ml_flags & XF86CONF_NVSYNC)
 
772
                                fprintf (cf, " -vsync");
 
773
                        if (mlptr->ml_flags & XF86CONF_INTERLACE)
 
774
                                fprintf (cf, " interlace");
 
775
                        if (mlptr->ml_flags & XF86CONF_CSYNC)
 
776
                                fprintf (cf, " composite");
 
777
                        if (mlptr->ml_flags & XF86CONF_PCSYNC)
 
778
                                fprintf (cf, " +csync");
 
779
                        if (mlptr->ml_flags & XF86CONF_NCSYNC)
 
780
                                fprintf (cf, " -csync");
 
781
                        if (mlptr->ml_flags & XF86CONF_DBLSCAN)
 
782
                                fprintf (cf, " doublescan");
 
783
                        if (mlptr->ml_flags & XF86CONF_HSKEW)
 
784
                                fprintf (cf, " hskew %d", mlptr->ml_hskew);
 
785
                        if (mlptr->ml_flags & XF86CONF_VSCAN)
 
786
                                fprintf (cf, " vscan %d", mlptr->ml_vscan);
 
787
                        if (mlptr->ml_flags & XF86CONF_BCAST)
 
788
                                fprintf (cf, " bcast");
 
789
                        if (mlptr->ml_comment)
 
790
                                fprintf (cf, "%s", mlptr->ml_comment);
 
791
                        else
 
792
                                fprintf (cf, "\n");
 
793
                }
 
794
                fprintf (cf, "EndSection\n\n");
 
795
                ptr = ptr->list.next;
 
796
        }
 
797
}
 
798
 
 
799
void
 
800
xf86freeMonitorList (XF86ConfMonitorPtr ptr)
 
801
{
 
802
        XF86ConfMonitorPtr prev;
 
803
 
 
804
        while (ptr)
 
805
        {
 
806
                TestFree (ptr->mon_identifier);
 
807
                TestFree (ptr->mon_vendor);
 
808
                TestFree (ptr->mon_modelname);
 
809
                TestFree (ptr->mon_comment);
 
810
                xf86optionListFree (ptr->mon_option_lst);
 
811
                xf86freeModeLineList (ptr->mon_modeline_lst);
 
812
                prev = ptr;
 
813
                ptr = ptr->list.next;
 
814
                xf86conffree (prev);
 
815
        }
 
816
}
 
817
 
 
818
void
 
819
xf86freeModesList (XF86ConfModesPtr ptr)
 
820
{
 
821
        XF86ConfModesPtr prev;
 
822
 
 
823
        while (ptr)
 
824
        {
 
825
                TestFree (ptr->modes_identifier);
 
826
                TestFree (ptr->modes_comment);
 
827
                xf86freeModeLineList (ptr->mon_modeline_lst);
 
828
                prev = ptr;
 
829
                ptr = ptr->list.next;
 
830
                xf86conffree (prev);
 
831
        }
 
832
}
 
833
 
 
834
void
 
835
xf86freeModeLineList (XF86ConfModeLinePtr ptr)
 
836
{
 
837
        XF86ConfModeLinePtr prev;
 
838
        while (ptr)
 
839
        {
 
840
                TestFree (ptr->ml_identifier);
 
841
                TestFree (ptr->ml_comment);
 
842
                prev = ptr;
 
843
                ptr = ptr->list.next;
 
844
                xf86conffree (prev);
 
845
        }
 
846
}
 
847
 
 
848
XF86ConfMonitorPtr
 
849
xf86findMonitor (const char *ident, XF86ConfMonitorPtr p)
 
850
{
 
851
        while (p)
 
852
        {
 
853
                if (xf86nameCompare (ident, p->mon_identifier) == 0)
 
854
                        return (p);
 
855
 
 
856
                p = p->list.next;
 
857
        }
 
858
        return (NULL);
 
859
}
 
860
 
 
861
XF86ConfModesPtr
 
862
xf86findModes (const char *ident, XF86ConfModesPtr p)
 
863
{
 
864
        while (p)
 
865
        {
 
866
                if (xf86nameCompare (ident, p->modes_identifier) == 0)
 
867
                        return (p);
 
868
 
 
869
                p = p->list.next;
 
870
        }
 
871
        return (NULL);
 
872
}
 
873
 
 
874
XF86ConfModeLinePtr
 
875
xf86findModeLine (const char *ident, XF86ConfModeLinePtr p)
 
876
{
 
877
        while (p)
 
878
        {
 
879
                if (xf86nameCompare (ident, p->ml_identifier) == 0)
 
880
                        return (p);
 
881
 
 
882
                p = p->list.next;
 
883
        }
 
884
        return (NULL);
 
885
}
 
886
 
 
887
int
 
888
xf86validateMonitor (XF86ConfigPtr p, XF86ConfScreenPtr screen)
 
889
{
 
890
        XF86ConfMonitorPtr monitor = screen->scrn_monitor;
 
891
        XF86ConfModesLinkPtr modeslnk = monitor->mon_modes_sect_lst;
 
892
        XF86ConfModesPtr modes;
 
893
        while(modeslnk)
 
894
        {
 
895
                modes = xf86findModes (modeslnk->ml_modes_str, p->conf_modes_lst);
 
896
                if (!modes)
 
897
                {
 
898
                        xf86validationError (UNDEFINED_MODES_MSG, 
 
899
                                             modeslnk->ml_modes_str, 
 
900
                                             screen->scrn_identifier);
 
901
                        return (FALSE);
 
902
                }
 
903
                modeslnk->ml_modes = modes;
 
904
                modeslnk = modeslnk->list.next;
 
905
        }
 
906
        return (TRUE);
 
907
}