1
/* $XFree86: xc/programs/Xserver/hw/xfree86/parser/Flags.c,v 1.23 2003/08/24 17:37:07 dawes Exp $ */
4
* Copyright (c) 1997 Metro Link Incorporated
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:
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
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
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.
30
* Copyright (c) 1997-2003 by The XFree86 Project, Inc.
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:
39
* The above copyright notice and this permission notice shall be included in
40
* all copies or substantial portions of the Software.
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.
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).
57
/* View/edit this file with tab stops set to 4 */
59
#ifdef HAVE_XORG_CONFIG_H
60
#include <xorg-config.h>
63
#include "xf86Parser.h"
64
#include "xf86tokens.h"
65
#include "Configint.h"
70
static xf86ConfigSymTabRec ServerFlagsTab[] =
72
{ENDSECTION, "endsection"},
73
{NOTRAPSIGNALS, "notrapsignals"},
75
{DONTZOOM, "dontzoom"},
76
{DISABLEVIDMODE, "disablevidmodeextension"},
77
{ALLOWNONLOCAL, "allownonlocalxvidtune"},
78
{DISABLEMODINDEV, "disablemodindev"},
79
{MODINDEVALLOWNONLOCAL, "allownonlocalmodindev"},
80
{ALLOWMOUSEOPENFAIL, "allowmouseopenfail"},
82
{BLANKTIME, "blanktime"},
83
{STANDBYTIME, "standbytime"},
84
{SUSPENDTIME, "suspendtime"},
86
{DEFAULTLAYOUT, "defaultserverlayout"},
90
#define CLEANUP xf86freeFlags
93
xf86parseFlagsSection (void)
96
parsePrologue (XF86ConfFlagsPtr, XF86ConfFlagsRec)
98
while ((token = xf86getToken (ServerFlagsTab)) != ENDSECTION)
100
int hasvalue = FALSE;
101
int strvalue = FALSE;
106
ptr->flg_comment = xf86addComment(ptr->flg_comment, val.str);
109
* these old keywords are turned into standard generic options.
110
* we fall through here on purpose
124
case DISABLEMODINDEV:
125
case MODINDEVALLOWNONLOCAL:
126
case ALLOWMOUSEOPENFAIL:
129
while (ServerFlagsTab[i].token != -1)
133
if (ServerFlagsTab[i].token == token)
136
/* can't use strdup because it calls malloc */
137
tmp = xf86configStrdup (ServerFlagsTab[i].name);
140
tokentype = xf86getSubToken(&(ptr->flg_comment));
142
if (tokentype != STRING)
143
Error (QUOTE_MSG, tmp);
146
if (tokentype != NUMBER)
147
Error (NUMBER_MSG, tmp);
148
valstr = xf86confmalloc(16);
150
sprintf(valstr, "%d", val.num);
153
ptr->flg_option_lst = xf86addNewOption
154
(ptr->flg_option_lst, tmp, valstr);
161
ptr->flg_option_lst = xf86parseOption(ptr->flg_option_lst);
165
Error (UNEXPECTED_EOF_MSG, NULL);
168
Error (INVALID_KEYWORD_MSG, xf86tokenString ());
174
printf ("Flags section parsed\n");
183
xf86printServerFlagsSection (FILE * f, XF86ConfFlagsPtr flags)
187
if ((!flags) || (!flags->flg_option_lst))
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");
198
addNewOption2 (XF86OptionPtr head, char *name, char *val, int used)
200
XF86OptionPtr new, old = NULL;
202
/* Don't allow duplicates */
203
if (head != NULL && (old = xf86findOption(head, name)) != NULL)
206
new = xf86confcalloc (1, sizeof (XF86OptionRec));
207
new->list.next = NULL;
209
new->opt_name = name;
211
new->opt_used = used;
214
return ((XF86OptionPtr) xf86addListItem ((glp) head, (glp) new));
220
xf86addNewOption (XF86OptionPtr head, char *name, char *val)
222
return addNewOption2(head, name, val, 0);
226
xf86freeFlags (XF86ConfFlagsPtr flags)
230
xf86optionListFree (flags->flg_option_lst);
231
TestFree(flags->flg_comment);
232
xf86conffree (flags);
236
xf86optionListDup (XF86OptionPtr opt)
238
XF86OptionPtr newopt = NULL;
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;
253
xf86optionListFree (XF86OptionPtr opt)
259
TestFree (opt->opt_name);
260
TestFree (opt->opt_val);
261
TestFree (opt->opt_comment);
263
opt = opt->list.next;
269
xf86optionName(XF86OptionPtr opt)
272
return opt->opt_name;
277
xf86optionValue(XF86OptionPtr opt)
285
xf86newOption(char *name, char *value)
289
opt = xf86confcalloc(1, sizeof (XF86OptionRec));
295
opt->opt_name = name;
296
opt->opt_val = value;
302
xf86nextOption(XF86OptionPtr list)
306
return list->list.next;
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
316
xf86findOption (XF86OptionPtr list, const char *name)
320
if (xf86nameCompare (list->opt_name, name) == 0)
322
list = list->list.next;
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.
335
xf86findOptionValue (XF86OptionPtr list, const char *name)
337
XF86OptionPtr p = xf86findOption (list, name);
350
xf86optionListCreate( const char **options, int count, int used )
352
XF86OptionPtr p = NULL;
358
for (count = 0; options[count]; count++)
361
if( (count % 2) != 0 )
363
fprintf( stderr, "xf86optionListCreate: count must be an even number.\n" );
366
for (i = 0; i < count; i += 2)
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);
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.
387
xf86optionListMerge (XF86OptionPtr head, XF86OptionPtr tail)
389
XF86OptionPtr a, b, ap = NULL, bp = NULL;
394
if (xf86nameCompare (a->opt_name, b->opt_name) == 0) {
402
ap->list.next = a->list.next;
403
a->list.next = b->list.next;
405
xf86optionListFree (b);
412
if (!(a = a->list.next)) {
422
for (a = head; a->list.next; a = a->list.next)
432
xf86uLongToString(unsigned long i)
437
l = (int)(ceil(log10((double)i) + 2.5));
438
s = xf86confmalloc(l);
441
sprintf(s, "%lu", i);
446
xf86debugListOptions(XF86OptionPtr Options)
449
ErrorF("Option: %s Value: %s\n",Options->opt_name,Options->opt_val);
450
Options = Options->list.next;
455
xf86parseOption(XF86OptionPtr head)
457
XF86OptionPtr option, cnew, old;
458
char *name, *comment = NULL;
461
if ((token = xf86getSubToken(&comment)) != STRING) {
462
xf86parseError(BAD_OPTION_MSG, NULL);
464
xf86conffree(comment);
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);
475
xf86unGetToken(token);
478
option = xf86newOption(name, NULL);
479
option->opt_comment = comment;
480
if (token == COMMENT)
481
option->opt_comment = xf86addComment(option->opt_comment, val.str);
483
xf86unGetToken(token);
488
/* Don't allow duplicates */
489
if (head != NULL && (old = xf86findOption(head, name)) != NULL) {
491
xf86conffree(option->opt_name);
492
TestFree(option->opt_val);
493
TestFree(option->opt_comment);
494
xf86conffree(option);
500
return ((XF86OptionPtr)xf86addListItem((glp)head, (glp)cnew));
506
xf86printOptionList(FILE *fp, XF86OptionPtr list, int tabs)
513
for (i = 0; i < tabs; i++)
516
fprintf(fp, "Option \"%s\" \"%s\"", list->opt_name, list->opt_val);
518
fprintf(fp, "Option \"%s\"", list->opt_name);
519
if (list->opt_comment)
520
fprintf(fp, "%s", list->opt_comment);
523
list = list->list.next;