First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / parser / Layout.c
blob5d1348acbc20d8aed8f66793eddd9f0361889414
1 /*
2 *
3 * Copyright (c) 1997 Metro Link Incorporated
4 *
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
21 * SOFTWARE.
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>
60 #endif
62 #include "xf86Parser.h"
63 #include "xf86tokens.h"
64 #include "Configint.h"
65 #include <string.h>
67 extern LexRec val;
69 static xf86ConfigSymTabRec LayoutTab[] =
71 {ENDSECTION, "endsection"},
72 {SCREEN, "screen"},
73 {IDENTIFIER, "identifier"},
74 {INACTIVE, "inactive"},
75 {INPUTDEVICE, "inputdevice"},
76 {OPTION, "option"},
77 {-1, ""},
80 static xf86ConfigSymTabRec AdjTab[] =
82 {RIGHTOF, "rightof"},
83 {LEFTOF, "leftof"},
84 {ABOVE, "above"},
85 {BELOW, "below"},
86 {RELATIVE, "relative"},
87 {ABSOLUTE, "absolute"},
88 {-1, ""},
91 #define CLEANUP xf86freeLayoutList
93 XF86ConfLayoutPtr
94 xf86parseLayoutSection (void)
96 int has_ident = FALSE;
97 int token;
98 parsePrologue (XF86ConfLayoutPtr, XF86ConfLayoutRec)
100 while ((token = xf86getToken (LayoutTab)) != ENDSECTION)
102 switch (token)
104 case COMMENT:
105 ptr->lay_comment = xf86addComment(ptr->lay_comment, val.str);
106 break;
107 case IDENTIFIER:
108 if (xf86getSubToken (&(ptr->lay_comment)) != STRING)
109 Error (QUOTE_MSG, "Identifier");
110 if (has_ident == TRUE)
111 Error (MULTIPLE_MSG, "Identifier");
112 ptr->lay_identifier = val.str;
113 has_ident = TRUE;
114 break;
115 case INACTIVE:
117 XF86ConfInactivePtr iptr;
119 iptr = xf86confcalloc (1, sizeof (XF86ConfInactiveRec));
120 iptr->list.next = NULL;
121 if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
122 xf86conffree (iptr);
123 Error (INACTIVE_MSG, NULL);
125 iptr->inactive_device_str = val.str;
126 ptr->lay_inactive_lst = (XF86ConfInactivePtr)
127 xf86addListItem ((glp) ptr->lay_inactive_lst, (glp) iptr);
129 break;
130 case SCREEN:
132 XF86ConfAdjacencyPtr aptr;
133 int absKeyword = 0;
135 aptr = xf86confcalloc (1, sizeof (XF86ConfAdjacencyRec));
136 aptr->list.next = NULL;
137 aptr->adj_scrnum = -1;
138 aptr->adj_where = CONF_ADJ_OBSOLETE;
139 aptr->adj_x = 0;
140 aptr->adj_y = 0;
141 aptr->adj_refscreen = NULL;
142 if ((token = xf86getSubToken (&(ptr->lay_comment))) == NUMBER)
143 aptr->adj_scrnum = val.num;
144 else
145 xf86unGetToken (token);
146 token = xf86getSubToken(&(ptr->lay_comment));
147 if (token != STRING) {
148 xf86conffree(aptr);
149 Error (SCREEN_MSG, NULL);
151 aptr->adj_screen_str = val.str;
153 token = xf86getSubTokenWithTab(&(ptr->lay_comment), AdjTab);
154 switch (token)
156 case RIGHTOF:
157 aptr->adj_where = CONF_ADJ_RIGHTOF;
158 break;
159 case LEFTOF:
160 aptr->adj_where = CONF_ADJ_LEFTOF;
161 break;
162 case ABOVE:
163 aptr->adj_where = CONF_ADJ_ABOVE;
164 break;
165 case BELOW:
166 aptr->adj_where = CONF_ADJ_BELOW;
167 break;
168 case RELATIVE:
169 aptr->adj_where = CONF_ADJ_RELATIVE;
170 break;
171 case ABSOLUTE:
172 aptr->adj_where = CONF_ADJ_ABSOLUTE;
173 absKeyword = 1;
174 break;
175 case EOF_TOKEN:
176 xf86conffree(aptr);
177 Error (UNEXPECTED_EOF_MSG, NULL);
178 break;
179 default:
180 xf86unGetToken (token);
181 token = xf86getSubToken(&(ptr->lay_comment));
182 if (token == STRING)
183 aptr->adj_where = CONF_ADJ_OBSOLETE;
184 else
185 aptr->adj_where = CONF_ADJ_ABSOLUTE;
187 switch (aptr->adj_where)
189 case CONF_ADJ_ABSOLUTE:
190 if (absKeyword)
191 token = xf86getSubToken(&(ptr->lay_comment));
192 if (token == NUMBER)
194 aptr->adj_x = val.num;
195 token = xf86getSubToken(&(ptr->lay_comment));
196 if (token != NUMBER) {
197 xf86conffree(aptr);
198 Error(INVALID_SCR_MSG, NULL);
200 aptr->adj_y = val.num;
201 } else {
202 if (absKeyword) {
203 xf86conffree(aptr);
204 Error(INVALID_SCR_MSG, NULL);
205 } else
206 xf86unGetToken (token);
208 break;
209 case CONF_ADJ_RIGHTOF:
210 case CONF_ADJ_LEFTOF:
211 case CONF_ADJ_ABOVE:
212 case CONF_ADJ_BELOW:
213 case CONF_ADJ_RELATIVE:
214 token = xf86getSubToken(&(ptr->lay_comment));
215 if (token != STRING) {
216 xf86conffree(aptr);
217 Error(INVALID_SCR_MSG, NULL);
219 aptr->adj_refscreen = val.str;
220 if (aptr->adj_where == CONF_ADJ_RELATIVE)
222 token = xf86getSubToken(&(ptr->lay_comment));
223 if (token != NUMBER) {
224 xf86conffree(aptr);
225 Error(INVALID_SCR_MSG, NULL);
227 aptr->adj_x = val.num;
228 token = xf86getSubToken(&(ptr->lay_comment));
229 if (token != NUMBER) {
230 xf86conffree(aptr);
231 Error(INVALID_SCR_MSG, NULL);
233 aptr->adj_y = val.num;
235 break;
236 case CONF_ADJ_OBSOLETE:
237 /* top */
238 aptr->adj_top_str = val.str;
240 /* bottom */
241 if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
242 xf86conffree(aptr);
243 Error (SCREEN_MSG, NULL);
245 aptr->adj_bottom_str = val.str;
247 /* left */
248 if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
249 xf86conffree(aptr);
250 Error (SCREEN_MSG, NULL);
252 aptr->adj_left_str = val.str;
254 /* right */
255 if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
256 xf86conffree(aptr);
257 Error (SCREEN_MSG, NULL);
259 aptr->adj_right_str = val.str;
262 ptr->lay_adjacency_lst = (XF86ConfAdjacencyPtr)
263 xf86addListItem ((glp) ptr->lay_adjacency_lst, (glp) aptr);
265 break;
266 case INPUTDEVICE:
268 XF86ConfInputrefPtr iptr;
270 iptr = xf86confcalloc (1, sizeof (XF86ConfInputrefRec));
271 iptr->list.next = NULL;
272 iptr->iref_option_lst = NULL;
273 if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
274 xf86conffree(iptr);
275 Error (INPUTDEV_MSG, NULL);
277 iptr->iref_inputdev_str = val.str;
278 while ((token = xf86getSubToken (&(ptr->lay_comment))) == STRING)
280 iptr->iref_option_lst =
281 xf86addNewOption (iptr->iref_option_lst, val.str, NULL);
283 xf86unGetToken (token);
284 ptr->lay_input_lst = (XF86ConfInputrefPtr)
285 xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr);
287 break;
288 case OPTION:
289 ptr->lay_option_lst = xf86parseOption(ptr->lay_option_lst);
290 break;
291 case EOF_TOKEN:
292 Error (UNEXPECTED_EOF_MSG, NULL);
293 break;
294 default:
295 Error (INVALID_KEYWORD_MSG, xf86tokenString ());
296 break;
300 if (!has_ident)
301 Error (NO_IDENT_MSG, NULL);
303 #ifdef DEBUG
304 printf ("Layout section parsed\n");
305 #endif
307 return ptr;
310 #undef CLEANUP
312 void
313 xf86printLayoutSection (FILE * cf, XF86ConfLayoutPtr ptr)
315 XF86ConfAdjacencyPtr aptr;
316 XF86ConfInactivePtr iptr;
317 XF86ConfInputrefPtr inptr;
318 XF86OptionPtr optr;
320 while (ptr)
322 fprintf (cf, "Section \"ServerLayout\"\n");
323 if (ptr->lay_comment)
324 fprintf (cf, "%s", ptr->lay_comment);
325 if (ptr->lay_identifier)
326 fprintf (cf, "\tIdentifier \"%s\"\n", ptr->lay_identifier);
328 for (aptr = ptr->lay_adjacency_lst; aptr; aptr = aptr->list.next)
330 fprintf (cf, "\tScreen ");
331 if (aptr->adj_scrnum >= 0)
332 fprintf (cf, "%2d", aptr->adj_scrnum);
333 else
334 fprintf (cf, " ");
335 fprintf (cf, " \"%s\"", aptr->adj_screen_str);
336 switch(aptr->adj_where)
338 case CONF_ADJ_OBSOLETE:
339 fprintf (cf, " \"%s\"", aptr->adj_top_str);
340 fprintf (cf, " \"%s\"", aptr->adj_bottom_str);
341 fprintf (cf, " \"%s\"", aptr->adj_right_str);
342 fprintf (cf, " \"%s\"\n", aptr->adj_left_str);
343 break;
344 case CONF_ADJ_ABSOLUTE:
345 if (aptr->adj_x != -1)
346 fprintf (cf, " %d %d\n", aptr->adj_x, aptr->adj_y);
347 else
348 fprintf (cf, "\n");
349 break;
350 case CONF_ADJ_RIGHTOF:
351 fprintf (cf, " RightOf \"%s\"\n", aptr->adj_refscreen);
352 break;
353 case CONF_ADJ_LEFTOF:
354 fprintf (cf, " LeftOf \"%s\"\n", aptr->adj_refscreen);
355 break;
356 case CONF_ADJ_ABOVE:
357 fprintf (cf, " Above \"%s\"\n", aptr->adj_refscreen);
358 break;
359 case CONF_ADJ_BELOW:
360 fprintf (cf, " Below \"%s\"\n", aptr->adj_refscreen);
361 break;
362 case CONF_ADJ_RELATIVE:
363 fprintf (cf, " Relative \"%s\" %d %d\n", aptr->adj_refscreen,
364 aptr->adj_x, aptr->adj_y);
365 break;
368 for (iptr = ptr->lay_inactive_lst; iptr; iptr = iptr->list.next)
369 fprintf (cf, "\tInactive \"%s\"\n", iptr->inactive_device_str);
370 for (inptr = ptr->lay_input_lst; inptr; inptr = inptr->list.next)
372 fprintf (cf, "\tInputDevice \"%s\"", inptr->iref_inputdev_str);
373 for (optr = inptr->iref_option_lst; optr; optr = optr->list.next)
375 fprintf(cf, " \"%s\"", optr->opt_name);
377 fprintf(cf, "\n");
379 xf86printOptionList(cf, ptr->lay_option_lst, 1);
380 fprintf (cf, "EndSection\n\n");
381 ptr = ptr->list.next;
385 static void
386 xf86freeAdjacencyList (XF86ConfAdjacencyPtr ptr)
388 XF86ConfAdjacencyPtr prev;
390 while (ptr)
392 TestFree (ptr->adj_screen_str);
393 TestFree (ptr->adj_top_str);
394 TestFree (ptr->adj_bottom_str);
395 TestFree (ptr->adj_left_str);
396 TestFree (ptr->adj_right_str);
398 prev = ptr;
399 ptr = ptr->list.next;
400 xf86conffree (prev);
405 static void
406 xf86freeInputrefList (XF86ConfInputrefPtr ptr)
408 XF86ConfInputrefPtr prev;
410 while (ptr)
412 TestFree (ptr->iref_inputdev_str);
413 xf86optionListFree (ptr->iref_option_lst);
414 prev = ptr;
415 ptr = ptr->list.next;
416 xf86conffree (prev);
421 void
422 xf86freeLayoutList (XF86ConfLayoutPtr ptr)
424 XF86ConfLayoutPtr prev;
426 while (ptr)
428 TestFree (ptr->lay_identifier);
429 TestFree (ptr->lay_comment);
430 xf86freeAdjacencyList (ptr->lay_adjacency_lst);
431 xf86freeInputrefList (ptr->lay_input_lst);
432 prev = ptr;
433 ptr = ptr->list.next;
434 xf86conffree (prev);
438 #define CheckScreen(str, ptr)\
439 if (str[0] != '\0') \
441 screen = xf86findScreen (str, p->conf_screen_lst); \
442 if (!screen) \
444 xf86validationError (UNDEFINED_SCREEN_MSG, \
445 str, layout->lay_identifier); \
446 return (FALSE); \
448 else \
449 ptr = screen; \
453 xf86validateLayout (XF86ConfigPtr p)
455 XF86ConfLayoutPtr layout = p->conf_layout_lst;
456 XF86ConfAdjacencyPtr adj;
457 XF86ConfInactivePtr iptr;
458 XF86ConfInputrefPtr inptr;
459 XF86ConfScreenPtr screen;
460 XF86ConfDevicePtr device;
461 XF86ConfInputPtr input;
463 while (layout)
465 adj = layout->lay_adjacency_lst;
466 while (adj)
468 /* the first one can't be "" but all others can */
469 screen = xf86findScreen (adj->adj_screen_str, p->conf_screen_lst);
470 if (!screen)
472 xf86validationError (UNDEFINED_SCREEN_MSG,
473 adj->adj_screen_str, layout->lay_identifier);
474 return (FALSE);
476 else
477 adj->adj_screen = screen;
479 #if 0
480 CheckScreen (adj->adj_top_str, adj->adj_top);
481 CheckScreen (adj->adj_bottom_str, adj->adj_bottom);
482 CheckScreen (adj->adj_left_str, adj->adj_left);
483 CheckScreen (adj->adj_right_str, adj->adj_right);
484 #endif
486 adj = adj->list.next;
488 iptr = layout->lay_inactive_lst;
489 while (iptr)
491 device = xf86findDevice (iptr->inactive_device_str,
492 p->conf_device_lst);
493 if (!device)
495 xf86validationError (UNDEFINED_DEVICE_LAY_MSG,
496 iptr->inactive_device_str, layout->lay_identifier);
497 return (FALSE);
499 else
500 iptr->inactive_device = device;
501 iptr = iptr->list.next;
503 inptr = layout->lay_input_lst;
504 while (inptr)
506 input = xf86findInput (inptr->iref_inputdev_str,
507 p->conf_input_lst);
508 if (!input)
510 xf86validationError (UNDEFINED_INPUT_MSG,
511 inptr->iref_inputdev_str, layout->lay_identifier);
512 return (FALSE);
514 else
515 inptr->iref_inputdev = input;
516 inptr = inptr->list.next;
518 layout = layout->list.next;
520 return (TRUE);
523 XF86ConfLayoutPtr
524 xf86findLayout (const char *name, XF86ConfLayoutPtr list)
526 while (list)
528 if (xf86nameCompare (list->lay_identifier, name) == 0)
529 return (list);
530 list = list->list.next;
532 return (NULL);