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

« back to all changes in this revision

Viewing changes to hw/xfree86/parser/Flags.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/Flags.c,v 1.23 2003/08/24 17:37:07 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
#include <math.h>
 
67
 
 
68
extern LexRec val;
 
69
 
 
70
static xf86ConfigSymTabRec ServerFlagsTab[] =
 
71
{
 
72
        {ENDSECTION, "endsection"},
 
73
        {NOTRAPSIGNALS, "notrapsignals"},
 
74
        {DONTZAP, "dontzap"},
 
75
        {DONTZOOM, "dontzoom"},
 
76
        {DISABLEVIDMODE, "disablevidmodeextension"},
 
77
        {ALLOWNONLOCAL, "allownonlocalxvidtune"},
 
78
        {DISABLEMODINDEV, "disablemodindev"},
 
79
        {MODINDEVALLOWNONLOCAL, "allownonlocalmodindev"},
 
80
        {ALLOWMOUSEOPENFAIL, "allowmouseopenfail"},
 
81
        {OPTION, "option"},
 
82
        {BLANKTIME, "blanktime"},
 
83
        {STANDBYTIME, "standbytime"},
 
84
        {SUSPENDTIME, "suspendtime"},
 
85
        {OFFTIME, "offtime"},
 
86
        {DEFAULTLAYOUT, "defaultserverlayout"},
 
87
        {-1, ""},
 
88
};
 
89
 
 
90
#define CLEANUP xf86freeFlags
 
91
 
 
92
XF86ConfFlagsPtr
 
93
xf86parseFlagsSection (void)
 
94
{
 
95
        int token;
 
96
        parsePrologue (XF86ConfFlagsPtr, XF86ConfFlagsRec)
 
97
 
 
98
        while ((token = xf86getToken (ServerFlagsTab)) != ENDSECTION)
 
99
        {
 
100
                int hasvalue = FALSE;
 
101
                int strvalue = FALSE;
 
102
                int tokentype;
 
103
                switch (token)
 
104
                {
 
105
                case COMMENT:
 
106
                        ptr->flg_comment = xf86addComment(ptr->flg_comment, val.str);
 
107
                        break;
 
108
                        /* 
 
109
                         * these old keywords are turned into standard generic options.
 
110
                         * we fall through here on purpose
 
111
                         */
 
112
                case DEFAULTLAYOUT:
 
113
                        strvalue = TRUE;
 
114
                case BLANKTIME:
 
115
                case STANDBYTIME:
 
116
                case SUSPENDTIME:
 
117
                case OFFTIME:
 
118
                        hasvalue = TRUE;
 
119
                case NOTRAPSIGNALS:
 
120
                case DONTZAP:
 
121
                case DONTZOOM:
 
122
                case DISABLEVIDMODE:
 
123
                case ALLOWNONLOCAL:
 
124
                case DISABLEMODINDEV:
 
125
                case MODINDEVALLOWNONLOCAL:
 
126
                case ALLOWMOUSEOPENFAIL:
 
127
                        {
 
128
                                int i = 0;
 
129
                                while (ServerFlagsTab[i].token != -1)
 
130
                                {
 
131
                                        char *tmp;
 
132
 
 
133
                                        if (ServerFlagsTab[i].token == token)
 
134
                                        {
 
135
                                                char *valstr = NULL;
 
136
                                                /* can't use strdup because it calls malloc */
 
137
                                                tmp = xf86configStrdup (ServerFlagsTab[i].name);
 
138
                                                if (hasvalue)
 
139
                                                {
 
140
                                                        tokentype = xf86getSubToken(&(ptr->flg_comment));
 
141
                                                        if (strvalue) {
 
142
                                                                if (tokentype != STRING)
 
143
                                                                        Error (QUOTE_MSG, tmp);
 
144
                                                                valstr = val.str;
 
145
                                                        } else {
 
146
                                                                if (tokentype != NUMBER)
 
147
                                                                        Error (NUMBER_MSG, tmp);
 
148
                                                                valstr = xf86confmalloc(16);
 
149
                                                                if (valstr)
 
150
                                                                        sprintf(valstr, "%d", val.num);
 
151
                                                        }
 
152
                                                }
 
153
                                                ptr->flg_option_lst = xf86addNewOption
 
154
                                                        (ptr->flg_option_lst, tmp, valstr);
 
155
                                        }
 
156
                                        i++;
 
157
                                }
 
158
                        }
 
159
                        break;
 
160
                case OPTION:
 
161
                        ptr->flg_option_lst = xf86parseOption(ptr->flg_option_lst);
 
162
                        break;
 
163
 
 
164
                case EOF_TOKEN:
 
165
                        Error (UNEXPECTED_EOF_MSG, NULL);
 
166
                        break;
 
167
                default:
 
168
                        Error (INVALID_KEYWORD_MSG, xf86tokenString ());
 
169
                        break;
 
170
                }
 
171
        }
 
172
 
 
173
#ifdef DEBUG
 
174
        printf ("Flags section parsed\n");
 
175
#endif
 
176
 
 
177
        return ptr;
 
178
}
 
179
 
 
180
#undef CLEANUP
 
181
 
 
182
void
 
183
xf86printServerFlagsSection (FILE * f, XF86ConfFlagsPtr flags)
 
184
{
 
185
        XF86OptionPtr p;
 
186
 
 
187
        if ((!flags) || (!flags->flg_option_lst))
 
188
                return;
 
189
        p = flags->flg_option_lst;
 
190
        fprintf (f, "Section \"ServerFlags\"\n");
 
191
        if (flags->flg_comment)
 
192
                fprintf (f, "%s", flags->flg_comment);
 
193
        xf86printOptionList(f, p, 1);
 
194
        fprintf (f, "EndSection\n\n");
 
195
}
 
196
 
 
197
static XF86OptionPtr
 
198
addNewOption2 (XF86OptionPtr head, char *name, char *val, int used)
 
199
{
 
200
        XF86OptionPtr new, old = NULL;
 
201
 
 
202
        /* Don't allow duplicates */
 
203
        if (head != NULL && (old = xf86findOption(head, name)) != NULL)
 
204
                new = old;
 
205
        else {
 
206
                new = xf86confcalloc (1, sizeof (XF86OptionRec));
 
207
                new->list.next = NULL;
 
208
        }
 
209
        new->opt_name = name;
 
210
        new->opt_val = val;
 
211
        new->opt_used = used;
 
212
        
 
213
        if (old == NULL)
 
214
                return ((XF86OptionPtr) xf86addListItem ((glp) head, (glp) new));
 
215
        else 
 
216
                return head;
 
217
}
 
218
 
 
219
XF86OptionPtr
 
220
xf86addNewOption (XF86OptionPtr head, char *name, char *val)
 
221
{
 
222
        return addNewOption2(head, name, val, 0);
 
223
}
 
224
 
 
225
void
 
226
xf86freeFlags (XF86ConfFlagsPtr flags)
 
227
{
 
228
        if (flags == NULL)
 
229
                return;
 
230
        xf86optionListFree (flags->flg_option_lst);
 
231
        TestFree(flags->flg_comment);
 
232
        xf86conffree (flags);
 
233
}
 
234
 
 
235
XF86OptionPtr
 
236
xf86optionListDup (XF86OptionPtr opt)
 
237
{
 
238
        XF86OptionPtr newopt = NULL;
 
239
 
 
240
        while (opt)
 
241
        {
 
242
                newopt = xf86addNewOption(newopt, xf86configStrdup(opt->opt_name), 
 
243
                                          xf86configStrdup(opt->opt_val));
 
244
                newopt->opt_used = opt->opt_used;
 
245
                if (opt->opt_comment)
 
246
                        newopt->opt_comment = xf86configStrdup(opt->opt_comment);
 
247
                opt = opt->list.next;
 
248
        }
 
249
        return newopt;
 
250
}
 
251
 
 
252
void
 
253
xf86optionListFree (XF86OptionPtr opt)
 
254
{
 
255
        XF86OptionPtr prev;
 
256
 
 
257
        while (opt)
 
258
        {
 
259
                TestFree (opt->opt_name);
 
260
                TestFree (opt->opt_val);
 
261
                TestFree (opt->opt_comment);
 
262
                prev = opt;
 
263
                opt = opt->list.next;
 
264
                xf86conffree (prev);
 
265
        }
 
266
}
 
267
 
 
268
char *
 
269
xf86optionName(XF86OptionPtr opt)
 
270
{
 
271
        if (opt)
 
272
                return opt->opt_name;
 
273
        return 0;
 
274
}
 
275
 
 
276
char *
 
277
xf86optionValue(XF86OptionPtr opt)
 
278
{
 
279
        if (opt)
 
280
                return opt->opt_val;
 
281
        return 0;
 
282
}
 
283
 
 
284
XF86OptionPtr
 
285
xf86newOption(char *name, char *value)
 
286
{
 
287
        XF86OptionPtr opt;
 
288
 
 
289
        opt = xf86confcalloc(1, sizeof (XF86OptionRec));
 
290
        if (!opt)
 
291
                return NULL;
 
292
 
 
293
        opt->opt_used = 0;
 
294
        opt->list.next = 0;
 
295
        opt->opt_name = name;
 
296
        opt->opt_val = value;
 
297
 
 
298
        return opt;
 
299
}
 
300
 
 
301
XF86OptionPtr
 
302
xf86nextOption(XF86OptionPtr list)
 
303
{
 
304
        if (!list)
 
305
                return NULL;
 
306
        return list->list.next;
 
307
}
 
308
 
 
309
/*
 
310
 * this function searches the given option list for the named option and
 
311
 * returns a pointer to the option rec if found. If not found, it returns
 
312
 * NULL
 
313
 */
 
314
 
 
315
XF86OptionPtr
 
316
xf86findOption (XF86OptionPtr list, const char *name)
 
317
{
 
318
        while (list)
 
319
        {
 
320
                if (xf86nameCompare (list->opt_name, name) == 0)
 
321
                        return (list);
 
322
                list = list->list.next;
 
323
        }
 
324
        return (NULL);
 
325
}
 
326
 
 
327
/*
 
328
 * this function searches the given option list for the named option. If
 
329
 * found and the option has a parameter, a pointer to the parameter is
 
330
 * returned.  If the option does not have a parameter an empty string is
 
331
 * returned.  If the option is not found, a NULL is returned.
 
332
 */
 
333
 
 
334
char *
 
335
xf86findOptionValue (XF86OptionPtr list, const char *name)
 
336
{
 
337
        XF86OptionPtr p = xf86findOption (list, name);
 
338
 
 
339
        if (p)
 
340
        {
 
341
                if (p->opt_val)
 
342
                        return (p->opt_val);
 
343
                else
 
344
                        return "";
 
345
        }
 
346
        return (NULL);
 
347
}
 
348
 
 
349
XF86OptionPtr
 
350
xf86optionListCreate( const char **options, int count, int used )
 
351
{
 
352
        XF86OptionPtr p = NULL;
 
353
        char *t1, *t2;
 
354
        int i;
 
355
 
 
356
        if (count == -1)
 
357
        {
 
358
                for (count = 0; options[count]; count++)
 
359
                        ;
 
360
        }
 
361
        if( (count % 2) != 0 )
 
362
        {
 
363
                fprintf( stderr, "xf86optionListCreate: count must be an even number.\n" );
 
364
                return (NULL);
 
365
        }
 
366
        for (i = 0; i < count; i += 2)
 
367
        {
 
368
                /* can't use strdup because it calls malloc */
 
369
                t1 = xf86confmalloc (sizeof (char) *
 
370
                                (strlen (options[i]) + 1));
 
371
                strcpy (t1, options[i]);
 
372
                t2 = xf86confmalloc (sizeof (char) *
 
373
                                (strlen (options[i + 1]) + 1));
 
374
                strcpy (t2, options[i + 1]);
 
375
                p = addNewOption2 (p, t1, t2, used);
 
376
        }
 
377
 
 
378
        return (p);
 
379
}
 
380
 
 
381
/* the 2 given lists are merged. If an option with the same name is present in
 
382
 * both, the option from the user list - specified in the second argument -
 
383
 * is used. The end result is a single valid list of options. Duplicates
 
384
 * are freed, and the original lists are no longer guaranteed to be complete.
 
385
 */
 
386
XF86OptionPtr
 
387
xf86optionListMerge (XF86OptionPtr head, XF86OptionPtr tail)
 
388
{
 
389
        XF86OptionPtr a, b, ap = NULL, bp = NULL;
 
390
 
 
391
        a = tail;
 
392
        b = head;
 
393
        while (tail && b) {
 
394
                if (xf86nameCompare (a->opt_name, b->opt_name) == 0) {
 
395
                        if (b == head)
 
396
                                head = a;
 
397
                        else
 
398
                                bp->list.next = a;
 
399
                        if (a == tail)
 
400
                                tail = a->list.next;
 
401
                        else
 
402
                                ap->list.next = a->list.next;
 
403
                        a->list.next = b->list.next;
 
404
                        b->list.next = NULL;
 
405
                        xf86optionListFree (b);
 
406
                        b = a->list.next;
 
407
                        bp = a;
 
408
                        a = tail;
 
409
                        ap = NULL;
 
410
                } else {
 
411
                        ap = a;
 
412
                        if (!(a = a->list.next)) {
 
413
                                a = tail;
 
414
                                bp = b;
 
415
                                b = b->list.next;
 
416
                                ap = NULL;
 
417
                        }
 
418
                }
 
419
        }
 
420
 
 
421
        if (head) {
 
422
                for (a = head; a->list.next; a = a->list.next)
 
423
                        ;
 
424
                a->list.next = tail;
 
425
        } else 
 
426
                head = tail;
 
427
 
 
428
        return (head);
 
429
}
 
430
 
 
431
char *
 
432
xf86uLongToString(unsigned long i)
 
433
{
 
434
        char *s;
 
435
        int l;
 
436
 
 
437
        l = (int)(ceil(log10((double)i) + 2.5));
 
438
        s = xf86confmalloc(l);
 
439
        if (!s)
 
440
                return NULL;
 
441
        sprintf(s, "%lu", i);
 
442
        return s;
 
443
}
 
444
 
 
445
void
 
446
xf86debugListOptions(XF86OptionPtr Options)
 
447
{
 
448
        while (Options) {
 
449
                ErrorF("Option: %s Value: %s\n",Options->opt_name,Options->opt_val);
 
450
                Options = Options->list.next;
 
451
        }
 
452
}
 
453
 
 
454
XF86OptionPtr
 
455
xf86parseOption(XF86OptionPtr head)
 
456
{
 
457
        XF86OptionPtr option, cnew, old;
 
458
        char *name, *comment = NULL;
 
459
        int token;
 
460
 
 
461
        if ((token = xf86getSubToken(&comment)) != STRING) {
 
462
                xf86parseError(BAD_OPTION_MSG, NULL);
 
463
                if (comment)
 
464
                        xf86conffree(comment);
 
465
                return (head);
 
466
        }
 
467
 
 
468
        name = val.str;
 
469
        if ((token = xf86getSubToken(&comment)) == STRING) {
 
470
                option = xf86newOption(name, val.str);
 
471
                option->opt_comment = comment;
 
472
                if ((token = xf86getToken(NULL)) == COMMENT)
 
473
                        option->opt_comment = xf86addComment(option->opt_comment, val.str);
 
474
                else
 
475
                        xf86unGetToken(token);
 
476
        }
 
477
        else {
 
478
                option = xf86newOption(name, NULL);
 
479
                option->opt_comment = comment;
 
480
                if (token == COMMENT)
 
481
                        option->opt_comment = xf86addComment(option->opt_comment, val.str);
 
482
                else
 
483
                        xf86unGetToken(token);
 
484
        }
 
485
 
 
486
        old = NULL;
 
487
 
 
488
        /* Don't allow duplicates */
 
489
        if (head != NULL && (old = xf86findOption(head, name)) != NULL) {
 
490
                cnew = old;
 
491
                xf86conffree(option->opt_name);
 
492
                TestFree(option->opt_val);
 
493
                TestFree(option->opt_comment);
 
494
                xf86conffree(option);
 
495
        }
 
496
        else
 
497
                cnew = option;
 
498
        
 
499
        if (old == NULL)
 
500
                return ((XF86OptionPtr)xf86addListItem((glp)head, (glp)cnew));
 
501
 
 
502
        return (head);
 
503
}
 
504
 
 
505
void
 
506
xf86printOptionList(FILE *fp, XF86OptionPtr list, int tabs)
 
507
{
 
508
        int i;
 
509
 
 
510
        if (!list)
 
511
                return;
 
512
        while (list) {
 
513
                for (i = 0; i < tabs; i++)
 
514
                        fputc('\t', fp);
 
515
                if (list->opt_val)
 
516
                        fprintf(fp, "Option         \"%s\" \"%s\"", list->opt_name, list->opt_val);
 
517
                else
 
518
                        fprintf(fp, "Option         \"%s\"", list->opt_name);
 
519
                if (list->opt_comment)
 
520
                        fprintf(fp, "%s", list->opt_comment);
 
521
                else
 
522
                        fputc('\n', fp);
 
523
                list = list->list.next;
 
524
        }
 
525
}