1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
|
/*
* Copyright (c) 1997 Metro Link Incorporated
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Metro Link shall not be
* used in advertising or otherwise to promote the sale, use or other dealings
* in this Software without prior written authorization from Metro Link.
*
*/
/*
* Copyright (c) 1997-2003 by The XFree86 Project, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of the copyright holder(s)
* and author(s) shall not be used in advertising or otherwise to promote
* the sale, use or other dealings in this Software without prior written
* authorization from the copyright holder(s) and author(s).
*/
#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif
#include "xf86Parser.h"
#include "xf86tokens.h"
#include "Configint.h"
#include <X11/Xfuncproto.h>
#include "Xprintf.h"
#include "optionstr.h"
static const xf86ConfigSymTabRec ServerFlagsTab[] = {
{ENDSECTION, "endsection"},
{NOTRAPSIGNALS, "notrapsignals"},
{DONTZAP, "dontzap"},
{DONTZOOM, "dontzoom"},
{DISABLEVIDMODE, "disablevidmodeextension"},
{ALLOWNONLOCAL, "allownonlocalxvidtune"},
{DISABLEMODINDEV, "disablemodindev"},
{MODINDEVALLOWNONLOCAL, "allownonlocalmodindev"},
{ALLOWMOUSEOPENFAIL, "allowmouseopenfail"},
{OPTION, "option"},
{BLANKTIME, "blanktime"},
{STANDBYTIME, "standbytime"},
{SUSPENDTIME, "suspendtime"},
{OFFTIME, "offtime"},
{DEFAULTLAYOUT, "defaultserverlayout"},
{-1, ""},
};
#define CLEANUP xf86freeFlags
XF86ConfFlagsPtr
xf86parseFlagsSection(void)
{
int token;
parsePrologue(XF86ConfFlagsPtr, XF86ConfFlagsRec)
while ((token = xf86getToken(ServerFlagsTab)) != ENDSECTION) {
int hasvalue = FALSE;
int strvalue = FALSE;
int tokentype;
switch (token) {
case COMMENT:
ptr->flg_comment = xf86addComment(ptr->flg_comment, xf86_lex_val.str);
break;
/*
* these old keywords are turned into standard generic options.
* we fall through here on purpose
*/
case DEFAULTLAYOUT:
strvalue = TRUE;
case BLANKTIME:
case STANDBYTIME:
case SUSPENDTIME:
case OFFTIME:
hasvalue = TRUE;
case NOTRAPSIGNALS:
case DONTZAP:
case DONTZOOM:
case DISABLEVIDMODE:
case ALLOWNONLOCAL:
case DISABLEMODINDEV:
case MODINDEVALLOWNONLOCAL:
case ALLOWMOUSEOPENFAIL:
{
int i = 0;
while (ServerFlagsTab[i].token != -1) {
char *tmp;
if (ServerFlagsTab[i].token == token) {
char *valstr = NULL;
tmp = strdup(ServerFlagsTab[i].name);
if (hasvalue) {
tokentype = xf86getSubToken(&(ptr->flg_comment));
if (strvalue) {
if (tokentype != STRING)
Error(QUOTE_MSG, tmp);
valstr = xf86_lex_val.str;
}
else {
if (tokentype != NUMBER)
Error(NUMBER_MSG, tmp);
if (asprintf(&valstr, "%d", xf86_lex_val.num) == -1)
valstr = NULL;
}
}
ptr->flg_option_lst = xf86addNewOption
(ptr->flg_option_lst, tmp, valstr);
}
i++;
}
}
break;
case OPTION:
ptr->flg_option_lst = xf86parseOption(ptr->flg_option_lst);
break;
case EOF_TOKEN:
Error(UNEXPECTED_EOF_MSG);
break;
default:
Error(INVALID_KEYWORD_MSG, xf86tokenString());
break;
}
}
#ifdef DEBUG
printf("Flags section parsed\n");
#endif
return ptr;
}
#undef CLEANUP
void
xf86printServerFlagsSection(FILE * f, XF86ConfFlagsPtr flags)
{
XF86OptionPtr p;
if ((!flags) || (!flags->flg_option_lst))
return;
p = flags->flg_option_lst;
fprintf(f, "Section \"ServerFlags\"\n");
if (flags->flg_comment)
fprintf(f, "%s", flags->flg_comment);
xf86printOptionList(f, p, 1);
fprintf(f, "EndSection\n\n");
}
static XF86OptionPtr
addNewOption2(XF86OptionPtr head, char *name, char *_val, int used)
{
XF86OptionPtr new, old = NULL;
/* Don't allow duplicates, free old strings */
if (head != NULL && (old = xf86findOption(head, name)) != NULL) {
new = old;
free(new->opt_name);
free(new->opt_val);
}
else
new = calloc(1, sizeof(*new));
new->opt_name = name;
new->opt_val = _val;
new->opt_used = used;
if (old)
return head;
return ((XF86OptionPtr) xf86addListItem((glp) head, (glp) new));
}
XF86OptionPtr
xf86addNewOption(XF86OptionPtr head, char *name, char *_val)
{
return addNewOption2(head, name, _val, 0);
}
void
xf86freeFlags(XF86ConfFlagsPtr flags)
{
if (flags == NULL)
return;
xf86optionListFree(flags->flg_option_lst);
TestFree(flags->flg_comment);
free(flags);
}
XF86OptionPtr
xf86optionListDup(XF86OptionPtr opt)
{
XF86OptionPtr newopt = NULL;
char *_val;
while (opt) {
_val = opt->opt_val ? strdup(opt->opt_val) : NULL;
newopt = xf86addNewOption(newopt, strdup(opt->opt_name), _val);
newopt->opt_used = opt->opt_used;
if (opt->opt_comment)
newopt->opt_comment = strdup(opt->opt_comment);
opt = opt->list.next;
}
return newopt;
}
void
xf86optionListFree(XF86OptionPtr opt)
{
XF86OptionPtr prev;
while (opt) {
TestFree(opt->opt_name);
TestFree(opt->opt_val);
TestFree(opt->opt_comment);
prev = opt;
opt = opt->list.next;
free(prev);
}
}
char *
xf86optionName(XF86OptionPtr opt)
{
if (opt)
return opt->opt_name;
return 0;
}
char *
xf86optionValue(XF86OptionPtr opt)
{
if (opt)
return opt->opt_val;
return 0;
}
XF86OptionPtr
xf86newOption(char *name, char *value)
{
XF86OptionPtr opt;
opt = calloc(1, sizeof(*opt));
if (!opt)
return NULL;
opt->opt_used = 0;
opt->list.next = 0;
opt->opt_name = name;
opt->opt_val = value;
return opt;
}
XF86OptionPtr
xf86nextOption(XF86OptionPtr list)
{
if (!list)
return NULL;
return list->list.next;
}
/*
* this function searches the given option list for the named option and
* returns a pointer to the option rec if found. If not found, it returns
* NULL
*/
XF86OptionPtr
xf86findOption(XF86OptionPtr list, const char *name)
{
while (list) {
if (xf86nameCompare(list->opt_name, name) == 0)
return list;
list = list->list.next;
}
return NULL;
}
/*
* this function searches the given option list for the named option. If
* found and the option has a parameter, a pointer to the parameter is
* returned. If the option does not have a parameter an empty string is
* returned. If the option is not found, a NULL is returned.
*/
const char *
xf86findOptionValue(XF86OptionPtr list, const char *name)
{
XF86OptionPtr p = xf86findOption(list, name);
if (p) {
if (p->opt_val)
return p->opt_val;
else
return "";
}
return NULL;
}
XF86OptionPtr
xf86optionListCreate(const char **options, int count, int used)
{
XF86OptionPtr p = NULL;
char *t1, *t2;
int i;
if (count == -1) {
for (count = 0; options[count]; count++);
}
if ((count % 2) != 0) {
fprintf(stderr,
"xf86optionListCreate: count must be an even number.\n");
return NULL;
}
for (i = 0; i < count; i += 2) {
t1 = strdup(options[i]);
t2 = strdup(options[i + 1]);
p = addNewOption2(p, t1, t2, used);
}
return p;
}
/* the 2 given lists are merged. If an option with the same name is present in
* both, the option from the user list - specified in the second argument -
* is used. The end result is a single valid list of options. Duplicates
* are freed, and the original lists are no longer guaranteed to be complete.
*/
XF86OptionPtr
xf86optionListMerge(XF86OptionPtr head, XF86OptionPtr tail)
{
XF86OptionPtr a, b, ap = NULL, bp = NULL;
a = tail;
b = head;
while (tail && b) {
if (xf86nameCompare(a->opt_name, b->opt_name) == 0) {
if (b == head)
head = a;
else
bp->list.next = a;
if (a == tail)
tail = a->list.next;
else
ap->list.next = a->list.next;
a->list.next = b->list.next;
b->list.next = NULL;
xf86optionListFree(b);
b = a->list.next;
bp = a;
a = tail;
ap = NULL;
}
else {
ap = a;
if (!(a = a->list.next)) {
a = tail;
bp = b;
b = b->list.next;
ap = NULL;
}
}
}
if (head) {
for (a = head; a->list.next; a = a->list.next);
a->list.next = tail;
}
else
head = tail;
return head;
}
char *
xf86uLongToString(unsigned long i)
{
char *s;
if (asprintf(&s, "%lu", i) == -1)
return NULL;
return s;
}
XF86OptionPtr
xf86parseOption(XF86OptionPtr head)
{
XF86OptionPtr option, cnew, old;
char *name, *comment = NULL;
int token;
if ((token = xf86getSubToken(&comment)) != STRING) {
xf86parseError(BAD_OPTION_MSG);
free(comment);
return head;
}
name = xf86_lex_val.str;
if ((token = xf86getSubToken(&comment)) == STRING) {
option = xf86newOption(name, xf86_lex_val.str);
option->opt_comment = comment;
if ((token = xf86getToken(NULL)) == COMMENT)
option->opt_comment = xf86addComment(option->opt_comment, xf86_lex_val.str);
else
xf86unGetToken(token);
}
else {
option = xf86newOption(name, NULL);
option->opt_comment = comment;
if (token == COMMENT)
option->opt_comment = xf86addComment(option->opt_comment, xf86_lex_val.str);
else
xf86unGetToken(token);
}
old = NULL;
/* Don't allow duplicates */
if (head != NULL && (old = xf86findOption(head, name)) != NULL) {
cnew = old;
free(option->opt_name);
TestFree(option->opt_val);
TestFree(option->opt_comment);
free(option);
}
else
cnew = option;
if (old == NULL)
return ((XF86OptionPtr) xf86addListItem((glp) head, (glp) cnew));
return head;
}
void
xf86printOptionList(FILE * fp, XF86OptionPtr list, int tabs)
{
int i;
if (!list)
return;
while (list) {
for (i = 0; i < tabs; i++)
fputc('\t', fp);
if (list->opt_val)
fprintf(fp, "Option \"%s\" \"%s\"", list->opt_name,
list->opt_val);
else
fprintf(fp, "Option \"%s\"", list->opt_name);
if (list->opt_comment)
fprintf(fp, "%s", list->opt_comment);
else
fputc('\n', fp);
list = list->list.next;
}
}
|