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 LayoutTab
[] =
71 {ENDSECTION
, "endsection"},
73 {IDENTIFIER
, "identifier"},
74 {INACTIVE
, "inactive"},
75 {INPUTDEVICE
, "inputdevice"},
80 static xf86ConfigSymTabRec AdjTab
[] =
86 {RELATIVE
, "relative"},
87 {ABSOLUTE
, "absolute"},
91 #define CLEANUP xf86freeLayoutList
94 xf86parseLayoutSection (void)
96 int has_ident
= FALSE
;
98 parsePrologue (XF86ConfLayoutPtr
, XF86ConfLayoutRec
)
100 while ((token
= xf86getToken (LayoutTab
)) != ENDSECTION
)
105 ptr
->lay_comment
= xf86addComment(ptr
->lay_comment
, val
.str
);
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
;
117 XF86ConfInactivePtr iptr
;
119 iptr
= xf86confcalloc (1, sizeof (XF86ConfInactiveRec
));
120 iptr
->list
.next
= NULL
;
121 if (xf86getSubToken (&(ptr
->lay_comment
)) != STRING
) {
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
);
132 XF86ConfAdjacencyPtr aptr
;
135 aptr
= xf86confcalloc (1, sizeof (XF86ConfAdjacencyRec
));
136 aptr
->list
.next
= NULL
;
137 aptr
->adj_scrnum
= -1;
138 aptr
->adj_where
= CONF_ADJ_OBSOLETE
;
141 aptr
->adj_refscreen
= NULL
;
142 if ((token
= xf86getSubToken (&(ptr
->lay_comment
))) == NUMBER
)
143 aptr
->adj_scrnum
= val
.num
;
145 xf86unGetToken (token
);
146 token
= xf86getSubToken(&(ptr
->lay_comment
));
147 if (token
!= STRING
) {
149 Error (SCREEN_MSG
, NULL
);
151 aptr
->adj_screen_str
= val
.str
;
153 token
= xf86getSubTokenWithTab(&(ptr
->lay_comment
), AdjTab
);
157 aptr
->adj_where
= CONF_ADJ_RIGHTOF
;
160 aptr
->adj_where
= CONF_ADJ_LEFTOF
;
163 aptr
->adj_where
= CONF_ADJ_ABOVE
;
166 aptr
->adj_where
= CONF_ADJ_BELOW
;
169 aptr
->adj_where
= CONF_ADJ_RELATIVE
;
172 aptr
->adj_where
= CONF_ADJ_ABSOLUTE
;
177 Error (UNEXPECTED_EOF_MSG
, NULL
);
180 xf86unGetToken (token
);
181 token
= xf86getSubToken(&(ptr
->lay_comment
));
183 aptr
->adj_where
= CONF_ADJ_OBSOLETE
;
185 aptr
->adj_where
= CONF_ADJ_ABSOLUTE
;
187 switch (aptr
->adj_where
)
189 case CONF_ADJ_ABSOLUTE
:
191 token
= xf86getSubToken(&(ptr
->lay_comment
));
194 aptr
->adj_x
= val
.num
;
195 token
= xf86getSubToken(&(ptr
->lay_comment
));
196 if (token
!= NUMBER
) {
198 Error(INVALID_SCR_MSG
, NULL
);
200 aptr
->adj_y
= val
.num
;
204 Error(INVALID_SCR_MSG
, NULL
);
206 xf86unGetToken (token
);
209 case CONF_ADJ_RIGHTOF
:
210 case CONF_ADJ_LEFTOF
:
213 case CONF_ADJ_RELATIVE
:
214 token
= xf86getSubToken(&(ptr
->lay_comment
));
215 if (token
!= STRING
) {
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
) {
225 Error(INVALID_SCR_MSG
, NULL
);
227 aptr
->adj_x
= val
.num
;
228 token
= xf86getSubToken(&(ptr
->lay_comment
));
229 if (token
!= NUMBER
) {
231 Error(INVALID_SCR_MSG
, NULL
);
233 aptr
->adj_y
= val
.num
;
236 case CONF_ADJ_OBSOLETE
:
238 aptr
->adj_top_str
= val
.str
;
241 if (xf86getSubToken (&(ptr
->lay_comment
)) != STRING
) {
243 Error (SCREEN_MSG
, NULL
);
245 aptr
->adj_bottom_str
= val
.str
;
248 if (xf86getSubToken (&(ptr
->lay_comment
)) != STRING
) {
250 Error (SCREEN_MSG
, NULL
);
252 aptr
->adj_left_str
= val
.str
;
255 if (xf86getSubToken (&(ptr
->lay_comment
)) != STRING
) {
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
);
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
) {
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
);
289 ptr
->lay_option_lst
= xf86parseOption(ptr
->lay_option_lst
);
292 Error (UNEXPECTED_EOF_MSG
, NULL
);
295 Error (INVALID_KEYWORD_MSG
, xf86tokenString ());
301 Error (NO_IDENT_MSG
, NULL
);
304 printf ("Layout section parsed\n");
313 xf86printLayoutSection (FILE * cf
, XF86ConfLayoutPtr ptr
)
315 XF86ConfAdjacencyPtr aptr
;
316 XF86ConfInactivePtr iptr
;
317 XF86ConfInputrefPtr inptr
;
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
);
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
);
344 case CONF_ADJ_ABSOLUTE
:
345 if (aptr
->adj_x
!= -1)
346 fprintf (cf
, " %d %d\n", aptr
->adj_x
, aptr
->adj_y
);
350 case CONF_ADJ_RIGHTOF
:
351 fprintf (cf
, " RightOf \"%s\"\n", aptr
->adj_refscreen
);
353 case CONF_ADJ_LEFTOF
:
354 fprintf (cf
, " LeftOf \"%s\"\n", aptr
->adj_refscreen
);
357 fprintf (cf
, " Above \"%s\"\n", aptr
->adj_refscreen
);
360 fprintf (cf
, " Below \"%s\"\n", aptr
->adj_refscreen
);
362 case CONF_ADJ_RELATIVE
:
363 fprintf (cf
, " Relative \"%s\" %d %d\n", aptr
->adj_refscreen
,
364 aptr
->adj_x
, aptr
->adj_y
);
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
);
379 xf86printOptionList(cf
, ptr
->lay_option_lst
, 1);
380 fprintf (cf
, "EndSection\n\n");
381 ptr
= ptr
->list
.next
;
386 xf86freeAdjacencyList (XF86ConfAdjacencyPtr ptr
)
388 XF86ConfAdjacencyPtr prev
;
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
);
399 ptr
= ptr
->list
.next
;
406 xf86freeInputrefList (XF86ConfInputrefPtr ptr
)
408 XF86ConfInputrefPtr prev
;
412 TestFree (ptr
->iref_inputdev_str
);
413 xf86optionListFree (ptr
->iref_option_lst
);
415 ptr
= ptr
->list
.next
;
422 xf86freeLayoutList (XF86ConfLayoutPtr ptr
)
424 XF86ConfLayoutPtr prev
;
428 TestFree (ptr
->lay_identifier
);
429 TestFree (ptr
->lay_comment
);
430 xf86freeAdjacencyList (ptr
->lay_adjacency_lst
);
431 xf86freeInputrefList (ptr
->lay_input_lst
);
433 ptr
= ptr
->list
.next
;
438 #define CheckScreen(str, ptr)\
439 if (str[0] != '\0') \
441 screen = xf86findScreen (str, p->conf_screen_lst); \
444 xf86validationError (UNDEFINED_SCREEN_MSG, \
445 str, layout->lay_identifier); \
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
;
465 adj
= layout
->lay_adjacency_lst
;
468 /* the first one can't be "" but all others can */
469 screen
= xf86findScreen (adj
->adj_screen_str
, p
->conf_screen_lst
);
472 xf86validationError (UNDEFINED_SCREEN_MSG
,
473 adj
->adj_screen_str
, layout
->lay_identifier
);
477 adj
->adj_screen
= screen
;
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
);
486 adj
= adj
->list
.next
;
488 iptr
= layout
->lay_inactive_lst
;
491 device
= xf86findDevice (iptr
->inactive_device_str
,
495 xf86validationError (UNDEFINED_DEVICE_LAY_MSG
,
496 iptr
->inactive_device_str
, layout
->lay_identifier
);
500 iptr
->inactive_device
= device
;
501 iptr
= iptr
->list
.next
;
503 inptr
= layout
->lay_input_lst
;
506 input
= xf86findInput (inptr
->iref_inputdev_str
,
510 xf86validationError (UNDEFINED_INPUT_MSG
,
511 inptr
->iref_inputdev_str
, layout
->lay_identifier
);
515 inptr
->iref_inputdev
= input
;
516 inptr
= inptr
->list
.next
;
518 layout
= layout
->list
.next
;
524 xf86findLayout (const char *name
, XF86ConfLayoutPtr list
)
528 if (xf86nameCompare (list
->lay_identifier
, name
) == 0)
530 list
= list
->list
.next
;