3 * Copyright (c) 1997 Metro Link Incorporated
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * Except as contained in this notice, the name of the Metro Link shall not be
24 * used in advertising or otherwise to promote the sale, use or other dealings
25 * in this Software without prior written authorization from Metro Link.
29 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
31 * Permission is hereby granted, free of charge, to any person obtaining a
32 * copy of this software and associated documentation files (the "Software"),
33 * to deal in the Software without restriction, including without limitation
34 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
35 * and/or sell copies of the Software, and to permit persons to whom the
36 * Software is furnished to do so, subject to the following conditions:
38 * The above copyright notice and this permission notice shall be included in
39 * all copies or substantial portions of the Software.
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
44 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
45 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
46 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
47 * OTHER DEALINGS IN THE SOFTWARE.
49 * Except as contained in this notice, the name of the copyright holder(s)
50 * and author(s) shall not be used in advertising or otherwise to promote
51 * the sale, use or other dealings in this Software without prior written
52 * authorization from the copyright holder(s) and author(s).
56 /* View/edit this file with tab stops set to 4 */
58 #ifdef HAVE_XORG_CONFIG_H
59 #include <xorg-config.h>
62 #include "xf86Parser.h"
63 #include "xf86tokens.h"
64 #include "Configint.h"
69 static xf86ConfigSymTabRec ServerFlagsTab
[] =
71 {ENDSECTION
, "endsection"},
72 {NOTRAPSIGNALS
, "notrapsignals"},
74 {DONTZOOM
, "dontzoom"},
75 {DISABLEVIDMODE
, "disablevidmodeextension"},
76 {ALLOWNONLOCAL
, "allownonlocalxvidtune"},
77 {DISABLEMODINDEV
, "disablemodindev"},
78 {MODINDEVALLOWNONLOCAL
, "allownonlocalmodindev"},
79 {ALLOWMOUSEOPENFAIL
, "allowmouseopenfail"},
81 {BLANKTIME
, "blanktime"},
82 {STANDBYTIME
, "standbytime"},
83 {SUSPENDTIME
, "suspendtime"},
85 {DEFAULTLAYOUT
, "defaultserverlayout"},
89 #define CLEANUP xf86freeFlags
92 xf86parseFlagsSection (void)
95 parsePrologue (XF86ConfFlagsPtr
, XF86ConfFlagsRec
)
97 while ((token
= xf86getToken (ServerFlagsTab
)) != ENDSECTION
)
100 int strvalue
= FALSE
;
105 ptr
->flg_comment
= xf86addComment(ptr
->flg_comment
, val
.str
);
108 * these old keywords are turned into standard generic options.
109 * we fall through here on purpose
123 case DISABLEMODINDEV
:
124 case MODINDEVALLOWNONLOCAL
:
125 case ALLOWMOUSEOPENFAIL
:
128 while (ServerFlagsTab
[i
].token
!= -1)
132 if (ServerFlagsTab
[i
].token
== token
)
135 /* can't use strdup because it calls malloc */
136 tmp
= xf86configStrdup (ServerFlagsTab
[i
].name
);
139 tokentype
= xf86getSubToken(&(ptr
->flg_comment
));
141 if (tokentype
!= STRING
)
142 Error (QUOTE_MSG
, tmp
);
145 if (tokentype
!= NUMBER
)
146 Error (NUMBER_MSG
, tmp
);
147 valstr
= xf86confmalloc(16);
149 sprintf(valstr
, "%d", val
.num
);
152 ptr
->flg_option_lst
= xf86addNewOption
153 (ptr
->flg_option_lst
, tmp
, valstr
);
160 ptr
->flg_option_lst
= xf86parseOption(ptr
->flg_option_lst
);
164 Error (UNEXPECTED_EOF_MSG
, NULL
);
167 Error (INVALID_KEYWORD_MSG
, xf86tokenString ());
173 printf ("Flags section parsed\n");
182 xf86printServerFlagsSection (FILE * f
, XF86ConfFlagsPtr flags
)
186 if ((!flags
) || (!flags
->flg_option_lst
))
188 p
= flags
->flg_option_lst
;
189 fprintf (f
, "Section \"ServerFlags\"\n");
190 if (flags
->flg_comment
)
191 fprintf (f
, "%s", flags
->flg_comment
);
192 xf86printOptionList(f
, p
, 1);
193 fprintf (f
, "EndSection\n\n");
197 addNewOption2 (XF86OptionPtr head
, char *name
, char *val
, int used
)
199 XF86OptionPtr
new, old
= NULL
;
201 /* Don't allow duplicates, free old strings */
202 if (head
!= NULL
&& (old
= xf86findOption(head
, name
)) != NULL
) {
204 xf86conffree(new->opt_name
);
205 xf86conffree(new->opt_val
);
208 new = xf86confcalloc (1, sizeof (XF86OptionRec
));
209 new->opt_name
= name
;
211 new->opt_used
= used
;
215 return ((XF86OptionPtr
) xf86addListItem ((glp
) head
, (glp
) new));
219 xf86addNewOption (XF86OptionPtr head
, char *name
, char *val
)
221 return addNewOption2(head
, name
, val
, 0);
225 xf86freeFlags (XF86ConfFlagsPtr flags
)
229 xf86optionListFree (flags
->flg_option_lst
);
230 TestFree(flags
->flg_comment
);
231 xf86conffree (flags
);
235 xf86optionListDup (XF86OptionPtr opt
)
237 XF86OptionPtr newopt
= NULL
;
241 newopt
= xf86addNewOption(newopt
, xf86configStrdup(opt
->opt_name
),
242 xf86configStrdup(opt
->opt_val
));
243 newopt
->opt_used
= opt
->opt_used
;
244 if (opt
->opt_comment
)
245 newopt
->opt_comment
= xf86configStrdup(opt
->opt_comment
);
246 opt
= opt
->list
.next
;
252 xf86optionListFree (XF86OptionPtr opt
)
258 TestFree (opt
->opt_name
);
259 TestFree (opt
->opt_val
);
260 TestFree (opt
->opt_comment
);
262 opt
= opt
->list
.next
;
268 xf86optionName(XF86OptionPtr opt
)
271 return opt
->opt_name
;
276 xf86optionValue(XF86OptionPtr opt
)
284 xf86newOption(char *name
, char *value
)
288 opt
= xf86confcalloc(1, sizeof (XF86OptionRec
));
294 opt
->opt_name
= name
;
295 opt
->opt_val
= value
;
301 xf86nextOption(XF86OptionPtr list
)
305 return list
->list
.next
;
309 * this function searches the given option list for the named option and
310 * returns a pointer to the option rec if found. If not found, it returns
315 xf86findOption (XF86OptionPtr list
, const char *name
)
319 if (xf86nameCompare (list
->opt_name
, name
) == 0)
321 list
= list
->list
.next
;
327 * this function searches the given option list for the named option. If
328 * found and the option has a parameter, a pointer to the parameter is
329 * returned. If the option does not have a parameter an empty string is
330 * returned. If the option is not found, a NULL is returned.
334 xf86findOptionValue (XF86OptionPtr list
, const char *name
)
336 XF86OptionPtr p
= xf86findOption (list
, name
);
349 xf86optionListCreate( const char **options
, int count
, int used
)
351 XF86OptionPtr p
= NULL
;
357 for (count
= 0; options
[count
]; count
++)
360 if( (count
% 2) != 0 )
362 fprintf( stderr
, "xf86optionListCreate: count must be an even number.\n" );
365 for (i
= 0; i
< count
; i
+= 2)
367 /* can't use strdup because it calls malloc */
368 t1
= xf86confmalloc (sizeof (char) *
369 (strlen (options
[i
]) + 1));
370 strcpy (t1
, options
[i
]);
371 t2
= xf86confmalloc (sizeof (char) *
372 (strlen (options
[i
+ 1]) + 1));
373 strcpy (t2
, options
[i
+ 1]);
374 p
= addNewOption2 (p
, t1
, t2
, used
);
380 /* the 2 given lists are merged. If an option with the same name is present in
381 * both, the option from the user list - specified in the second argument -
382 * is used. The end result is a single valid list of options. Duplicates
383 * are freed, and the original lists are no longer guaranteed to be complete.
386 xf86optionListMerge (XF86OptionPtr head
, XF86OptionPtr tail
)
388 XF86OptionPtr a
, b
, ap
= NULL
, bp
= NULL
;
393 if (xf86nameCompare (a
->opt_name
, b
->opt_name
) == 0) {
401 ap
->list
.next
= a
->list
.next
;
402 a
->list
.next
= b
->list
.next
;
404 xf86optionListFree (b
);
411 if (!(a
= a
->list
.next
)) {
421 for (a
= head
; a
->list
.next
; a
= a
->list
.next
)
431 xf86uLongToString(unsigned long i
)
436 l
= (int)(ceil(log10((double)i
) + 2.5));
437 s
= xf86confmalloc(l
);
440 sprintf(s
, "%lu", i
);
445 xf86parseOption(XF86OptionPtr head
)
447 XF86OptionPtr option
, cnew
, old
;
448 char *name
, *comment
= NULL
;
451 if ((token
= xf86getSubToken(&comment
)) != STRING
) {
452 xf86parseError(BAD_OPTION_MSG
, NULL
);
454 xf86conffree(comment
);
459 if ((token
= xf86getSubToken(&comment
)) == STRING
) {
460 option
= xf86newOption(name
, val
.str
);
461 option
->opt_comment
= comment
;
462 if ((token
= xf86getToken(NULL
)) == COMMENT
)
463 option
->opt_comment
= xf86addComment(option
->opt_comment
, val
.str
);
465 xf86unGetToken(token
);
468 option
= xf86newOption(name
, NULL
);
469 option
->opt_comment
= comment
;
470 if (token
== COMMENT
)
471 option
->opt_comment
= xf86addComment(option
->opt_comment
, val
.str
);
473 xf86unGetToken(token
);
478 /* Don't allow duplicates */
479 if (head
!= NULL
&& (old
= xf86findOption(head
, name
)) != NULL
) {
481 xf86conffree(option
->opt_name
);
482 TestFree(option
->opt_val
);
483 TestFree(option
->opt_comment
);
484 xf86conffree(option
);
490 return ((XF86OptionPtr
)xf86addListItem((glp
)head
, (glp
)cnew
));
496 xf86printOptionList(FILE *fp
, XF86OptionPtr list
, int tabs
)
503 for (i
= 0; i
< tabs
; i
++)
506 fprintf(fp
, "Option \"%s\" \"%s\"", list
->opt_name
, list
->opt_val
);
508 fprintf(fp
, "Option \"%s\"", list
->opt_name
);
509 if (list
->opt_comment
)
510 fprintf(fp
, "%s", list
->opt_comment
);
513 list
= list
->list
.next
;