2 * Copyright (c) 1997 Metro Link Incorporated
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * Except as contained in this notice, the name of the Metro Link shall not be
23 * used in advertising or otherwise to promote the sale, use or other dealings
24 * in this Software without prior written authorization from Metro Link.
28 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
30 * Permission is hereby granted, free of charge, to any person obtaining a
31 * copy of this software and associated documentation files (the "Software"),
32 * to deal in the Software without restriction, including without limitation
33 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
34 * and/or sell copies of the Software, and to permit persons to whom the
35 * Software is furnished to do so, subject to the following conditions:
37 * The above copyright notice and this permission notice shall be included in
38 * all copies or substantial portions of the Software.
40 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
43 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
44 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
45 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
46 * OTHER DEALINGS IN THE SOFTWARE.
48 * Except as contained in this notice, the name of the copyright holder(s)
49 * and author(s) shall not be used in advertising or otherwise to promote
50 * the sale, use or other dealings in this Software without prior written
51 * authorization from the copyright holder(s) and author(s).
54 #ifdef HAVE_XORG_CONFIG_H
55 #include <xorg-config.h>
58 #include "xf86Parser.h"
59 #include "xf86tokens.h"
60 #include "Configint.h"
61 #include <X11/Xfuncproto.h>
63 #include "optionstr.h"
67 static xf86ConfigSymTabRec ServerFlagsTab
[] = {
68 {ENDSECTION
, "endsection"},
69 {NOTRAPSIGNALS
, "notrapsignals"},
71 {DONTZOOM
, "dontzoom"},
72 {DISABLEVIDMODE
, "disablevidmodeextension"},
73 {ALLOWNONLOCAL
, "allownonlocalxvidtune"},
74 {DISABLEMODINDEV
, "disablemodindev"},
75 {MODINDEVALLOWNONLOCAL
, "allownonlocalmodindev"},
76 {ALLOWMOUSEOPENFAIL
, "allowmouseopenfail"},
78 {BLANKTIME
, "blanktime"},
79 {STANDBYTIME
, "standbytime"},
80 {SUSPENDTIME
, "suspendtime"},
82 {DEFAULTLAYOUT
, "defaultserverlayout"},
86 #define CLEANUP xf86freeFlags
89 xf86parseFlagsSection(void)
93 parsePrologue(XF86ConfFlagsPtr
, XF86ConfFlagsRec
)
95 while ((token
= xf86getToken(ServerFlagsTab
)) != ENDSECTION
) {
102 ptr
->flg_comment
= xf86addComment(ptr
->flg_comment
, val
.str
);
105 * these old keywords are turned into standard generic options.
106 * we fall through here on purpose
120 case DISABLEMODINDEV
:
121 case MODINDEVALLOWNONLOCAL
:
122 case ALLOWMOUSEOPENFAIL
:
126 while (ServerFlagsTab
[i
].token
!= -1) {
129 if (ServerFlagsTab
[i
].token
== token
) {
132 tmp
= strdup(ServerFlagsTab
[i
].name
);
134 tokentype
= xf86getSubToken(&(ptr
->flg_comment
));
136 if (tokentype
!= STRING
)
137 Error(QUOTE_MSG
, tmp
);
141 if (tokentype
!= NUMBER
)
142 Error(NUMBER_MSG
, tmp
);
143 if (asprintf(&valstr
, "%d", val
.num
) == -1)
147 ptr
->flg_option_lst
= xf86addNewOption
148 (ptr
->flg_option_lst
, tmp
, valstr
);
155 ptr
->flg_option_lst
= xf86parseOption(ptr
->flg_option_lst
);
159 Error(UNEXPECTED_EOF_MSG
);
162 Error(INVALID_KEYWORD_MSG
, xf86tokenString());
168 printf("Flags section parsed\n");
177 xf86printServerFlagsSection(FILE * f
, XF86ConfFlagsPtr flags
)
181 if ((!flags
) || (!flags
->flg_option_lst
))
183 p
= flags
->flg_option_lst
;
184 fprintf(f
, "Section \"ServerFlags\"\n");
185 if (flags
->flg_comment
)
186 fprintf(f
, "%s", flags
->flg_comment
);
187 xf86printOptionList(f
, p
, 1);
188 fprintf(f
, "EndSection\n\n");
192 addNewOption2(XF86OptionPtr head
, char *name
, char *val
, int used
)
194 XF86OptionPtr
new, old
= NULL
;
196 /* Don't allow duplicates, free old strings */
197 if (head
!= NULL
&& (old
= xf86findOption(head
, name
)) != NULL
) {
203 new = calloc(1, sizeof(*new));
204 new->opt_name
= name
;
206 new->opt_used
= used
;
210 return ((XF86OptionPtr
) xf86addListItem((glp
) head
, (glp
) new));
214 xf86addNewOption(XF86OptionPtr head
, char *name
, char *val
)
216 return addNewOption2(head
, name
, val
, 0);
220 xf86freeFlags(XF86ConfFlagsPtr flags
)
224 xf86optionListFree(flags
->flg_option_lst
);
225 TestFree(flags
->flg_comment
);
230 xf86optionListDup(XF86OptionPtr opt
)
232 XF86OptionPtr newopt
= NULL
;
236 val
= opt
->opt_val
? strdup(opt
->opt_val
) : NULL
;
237 newopt
= xf86addNewOption(newopt
, strdup(opt
->opt_name
), val
);
238 newopt
->opt_used
= opt
->opt_used
;
239 if (opt
->opt_comment
)
240 newopt
->opt_comment
= strdup(opt
->opt_comment
);
241 opt
= opt
->list
.next
;
247 xf86optionListFree(XF86OptionPtr opt
)
252 TestFree(opt
->opt_name
);
253 TestFree(opt
->opt_val
);
254 TestFree(opt
->opt_comment
);
256 opt
= opt
->list
.next
;
262 xf86optionName(XF86OptionPtr opt
)
265 return opt
->opt_name
;
270 xf86optionValue(XF86OptionPtr opt
)
278 xf86newOption(char *name
, char *value
)
282 opt
= calloc(1, sizeof(*opt
));
288 opt
->opt_name
= name
;
289 opt
->opt_val
= value
;
295 xf86nextOption(XF86OptionPtr list
)
299 return list
->list
.next
;
303 * this function searches the given option list for the named option and
304 * returns a pointer to the option rec if found. If not found, it returns
309 xf86findOption(XF86OptionPtr list
, const char *name
)
312 if (xf86nameCompare(list
->opt_name
, name
) == 0)
314 list
= list
->list
.next
;
320 * this function searches the given option list for the named option. If
321 * found and the option has a parameter, a pointer to the parameter is
322 * returned. If the option does not have a parameter an empty string is
323 * returned. If the option is not found, a NULL is returned.
327 xf86findOptionValue(XF86OptionPtr list
, const char *name
)
329 XF86OptionPtr p
= xf86findOption(list
, name
);
341 xf86optionListCreate(const char **options
, int count
, int used
)
343 XF86OptionPtr p
= NULL
;
348 for (count
= 0; options
[count
]; count
++);
350 if ((count
% 2) != 0) {
352 "xf86optionListCreate: count must be an even number.\n");
355 for (i
= 0; i
< count
; i
+= 2) {
356 t1
= strdup(options
[i
]);
357 t2
= strdup(options
[i
+ 1]);
358 p
= addNewOption2(p
, t1
, t2
, used
);
364 /* the 2 given lists are merged. If an option with the same name is present in
365 * both, the option from the user list - specified in the second argument -
366 * is used. The end result is a single valid list of options. Duplicates
367 * are freed, and the original lists are no longer guaranteed to be complete.
370 xf86optionListMerge(XF86OptionPtr head
, XF86OptionPtr tail
)
372 XF86OptionPtr a
, b
, ap
= NULL
, bp
= NULL
;
377 if (xf86nameCompare(a
->opt_name
, b
->opt_name
) == 0) {
385 ap
->list
.next
= a
->list
.next
;
386 a
->list
.next
= b
->list
.next
;
388 xf86optionListFree(b
);
396 if (!(a
= a
->list
.next
)) {
406 for (a
= head
; a
->list
.next
; a
= a
->list
.next
);
416 xf86uLongToString(unsigned long i
)
420 if (asprintf(&s
, "%lu", i
) == -1)
426 xf86parseOption(XF86OptionPtr head
)
428 XF86OptionPtr option
, cnew
, old
;
429 char *name
, *comment
= NULL
;
432 if ((token
= xf86getSubToken(&comment
)) != STRING
) {
433 xf86parseError(BAD_OPTION_MSG
);
439 if ((token
= xf86getSubToken(&comment
)) == STRING
) {
440 option
= xf86newOption(name
, val
.str
);
441 option
->opt_comment
= comment
;
442 if ((token
= xf86getToken(NULL
)) == COMMENT
)
443 option
->opt_comment
= xf86addComment(option
->opt_comment
, val
.str
);
445 xf86unGetToken(token
);
448 option
= xf86newOption(name
, NULL
);
449 option
->opt_comment
= comment
;
450 if (token
== COMMENT
)
451 option
->opt_comment
= xf86addComment(option
->opt_comment
, val
.str
);
453 xf86unGetToken(token
);
458 /* Don't allow duplicates */
459 if (head
!= NULL
&& (old
= xf86findOption(head
, name
)) != NULL
) {
461 free(option
->opt_name
);
462 TestFree(option
->opt_val
);
463 TestFree(option
->opt_comment
);
470 return ((XF86OptionPtr
) xf86addListItem((glp
) head
, (glp
) cnew
));
476 xf86printOptionList(FILE * fp
, XF86OptionPtr list
, int tabs
)
483 for (i
= 0; i
< tabs
; i
++)
486 fprintf(fp
, "Option \"%s\" \"%s\"", list
->opt_name
,
489 fprintf(fp
, "Option \"%s\"", list
->opt_name
);
490 if (list
->opt_comment
)
491 fprintf(fp
, "%s", list
->opt_comment
);
494 list
= list
->list
.next
;