1117N/A/*
1117N/A *
1117N/A * Copyright (c) 1997 Metro Link Incorporated
1117N/A *
1117N/A * Permission is hereby granted, free of charge, to any person obtaining a
1117N/A * copy of this software and associated documentation files (the "Software"),
1117N/A * to deal in the Software without restriction, including without limitation
1117N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1117N/A * and/or sell copies of the Software, and to permit persons to whom the
1117N/A * Software is furnished to do so, subject to the following conditions:
1117N/A *
1117N/A * The above copyright notice and this permission notice shall be included in
1117N/A * all copies or substantial portions of the Software.
1117N/A *
1117N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1117N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1117N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1117N/A * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
1117N/A * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
1117N/A * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1117N/A * SOFTWARE.
1117N/A *
1117N/A * Except as contained in this notice, the name of the Metro Link shall not be
1117N/A * used in advertising or otherwise to promote the sale, use or other dealings
1117N/A * in this Software without prior written authorization from Metro Link.
1117N/A *
1117N/A */
1117N/A/*
1117N/A * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
1117N/A *
1117N/A * Permission is hereby granted, free of charge, to any person obtaining a
1117N/A * copy of this software and associated documentation files (the "Software"),
1117N/A * to deal in the Software without restriction, including without limitation
1117N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1117N/A * and/or sell copies of the Software, and to permit persons to whom the
1117N/A * Software is furnished to do so, subject to the following conditions:
1117N/A *
1117N/A * The above copyright notice and this permission notice shall be included in
1117N/A * all copies or substantial portions of the Software.
1117N/A *
1117N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1117N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1117N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1117N/A * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1117N/A * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1117N/A * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1117N/A * OTHER DEALINGS IN THE SOFTWARE.
1117N/A *
1117N/A * Except as contained in this notice, the name of the copyright holder(s)
1117N/A * and author(s) shall not be used in advertising or otherwise to promote
1117N/A * the sale, use or other dealings in this Software without prior written
1117N/A * authorization from the copyright holder(s) and author(s).
1117N/A */
1117N/A
1117N/A
1117N/A/* View/edit this file with tab stops set to 4 */
1117N/A
1117N/A#include <string.h>
1117N/A
1117N/A#ifdef HAVE_XORG_CONFIG_H
1117N/A#include <xorg-config.h>
1117N/A#endif
1117N/A
1117N/A#include "xf86Parser.h"
1117N/A#include "xf86tokens.h"
1117N/A#include "Configint.h"
1117N/A#include "fields.h" /* Config file output line fields */
1117N/A
1117N/Aextern LexRec val;
1117N/A
1117N/Astatic xf86ConfigSymTabRec LayoutTab[] =
1117N/A{
1117N/A {ENDSECTION, "endsection"},
1117N/A {SCREEN, "screen"},
1117N/A {IDENTIFIER, "identifier"},
1117N/A {INACTIVE, "inactive"},
1117N/A {INPUTDEVICE, "inputdevice"},
1117N/A {OPTION, "option"},
1117N/A {-1, ""},
1117N/A};
1117N/A
1117N/Astatic xf86ConfigSymTabRec AdjTab[] =
1117N/A{
1117N/A {RIGHTOF, "rightof"},
1117N/A {LEFTOF, "leftof"},
1117N/A {ABOVE, "above"},
1117N/A {BELOW, "below"},
1117N/A {RELATIVE, "relative"},
1117N/A {ABSOLUTE, "absolute"},
1117N/A {-1, ""},
1117N/A};
1117N/A
1117N/A#define CLEANUP xf86freeLayoutList
1117N/A
1117N/AXF86ConfLayoutPtr
1117N/Axf86parseLayoutSection (void)
1117N/A{
1117N/A int has_ident = FALSE;
1117N/A int token;
1117N/A parsePrologue (XF86ConfLayoutPtr, XF86ConfLayoutRec)
1117N/A
1117N/A while ((token = xf86getToken (LayoutTab)) != ENDSECTION)
1117N/A {
1117N/A switch (token)
1117N/A {
1117N/A case COMMENT:
1117N/A ptr->lay_comment = xf86addComment(ptr->lay_comment, val.str);
1117N/A break;
1117N/A case IDENTIFIER:
1117N/A if (xf86getSubToken (&(ptr->lay_comment)) != STRING)
1117N/A Error (QUOTE_MSG, "Identifier");
1117N/A if (has_ident == TRUE)
1117N/A Error (MULTIPLE_MSG, "Identifier");
1117N/A ptr->lay_identifier = val.str;
1117N/A has_ident = TRUE;
1117N/A break;
1117N/A case INACTIVE:
1117N/A {
1117N/A XF86ConfInactivePtr iptr;
1117N/A
1117N/A iptr = xf86confcalloc (1, sizeof (XF86ConfInactiveRec));
1117N/A iptr->list.next = NULL;
1117N/A if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
1117N/A xf86conffree (iptr);
1117N/A Error (INACTIVE_MSG, NULL);
1117N/A }
1117N/A iptr->inactive_device_str = val.str;
1117N/A ptr->lay_inactive_lst = (XF86ConfInactivePtr)
1117N/A xf86addListItem ((glp) ptr->lay_inactive_lst, (glp) iptr);
1117N/A }
1117N/A break;
1117N/A case SCREEN:
1117N/A {
1117N/A XF86ConfAdjacencyPtr aptr;
1117N/A int absKeyword = 0;
1117N/A
1117N/A aptr = xf86confcalloc (1, sizeof (XF86ConfAdjacencyRec));
1117N/A aptr->list.next = NULL;
1117N/A aptr->adj_scrnum = -1;
1117N/A aptr->adj_where = CONF_ADJ_OBSOLETE;
1117N/A aptr->adj_x = 0;
1117N/A aptr->adj_y = 0;
1117N/A aptr->adj_refscreen = NULL;
1117N/A if ((token = xf86getSubToken (&(ptr->lay_comment))) == NUMBER)
1117N/A aptr->adj_scrnum = val.num;
1117N/A else
1117N/A xf86unGetToken (token);
1117N/A token = xf86getSubToken(&(ptr->lay_comment));
1117N/A if (token != STRING) {
1117N/A xf86conffree(aptr);
1117N/A Error (SCREEN_MSG, NULL);
1117N/A }
1117N/A aptr->adj_screen_str = val.str;
1117N/A
1117N/A token = xf86getSubTokenWithTab(&(ptr->lay_comment), AdjTab);
1117N/A switch (token)
1117N/A {
1117N/A case RIGHTOF:
1117N/A aptr->adj_where = CONF_ADJ_RIGHTOF;
1117N/A break;
1117N/A case LEFTOF:
1117N/A aptr->adj_where = CONF_ADJ_LEFTOF;
1117N/A break;
1117N/A case ABOVE:
1117N/A aptr->adj_where = CONF_ADJ_ABOVE;
1117N/A break;
1117N/A case BELOW:
1117N/A aptr->adj_where = CONF_ADJ_BELOW;
1117N/A break;
1117N/A case RELATIVE:
1117N/A aptr->adj_where = CONF_ADJ_RELATIVE;
1117N/A break;
1117N/A case ABSOLUTE:
1117N/A aptr->adj_where = CONF_ADJ_ABSOLUTE;
1117N/A absKeyword = 1;
1117N/A break;
1117N/A case EOF_TOKEN:
1117N/A xf86conffree(aptr);
1117N/A Error (UNEXPECTED_EOF_MSG, NULL);
1117N/A break;
1117N/A default:
1117N/A xf86unGetToken (token);
1117N/A token = xf86getSubToken(&(ptr->lay_comment));
1117N/A if (token == STRING)
1117N/A aptr->adj_where = CONF_ADJ_OBSOLETE;
1117N/A else
1117N/A aptr->adj_where = CONF_ADJ_ABSOLUTE;
1117N/A }
1117N/A switch (aptr->adj_where)
1117N/A {
1117N/A case CONF_ADJ_ABSOLUTE:
1117N/A if (absKeyword)
1117N/A token = xf86getSubToken(&(ptr->lay_comment));
1117N/A if (token == NUMBER)
1117N/A {
1117N/A aptr->adj_x = val.num;
1117N/A token = xf86getSubToken(&(ptr->lay_comment));
1117N/A if (token != NUMBER) {
1117N/A xf86conffree(aptr);
1117N/A Error(INVALID_SCR_MSG, NULL);
1117N/A }
1117N/A aptr->adj_y = val.num;
1117N/A } else {
1117N/A if (absKeyword) {
1117N/A xf86conffree(aptr);
1117N/A Error(INVALID_SCR_MSG, NULL);
1117N/A } else
1117N/A xf86unGetToken (token);
1117N/A }
1117N/A break;
1117N/A case CONF_ADJ_RIGHTOF:
1117N/A case CONF_ADJ_LEFTOF:
1117N/A case CONF_ADJ_ABOVE:
1117N/A case CONF_ADJ_BELOW:
1117N/A case CONF_ADJ_RELATIVE:
1117N/A token = xf86getSubToken(&(ptr->lay_comment));
1117N/A if (token != STRING) {
1117N/A xf86conffree(aptr);
1117N/A Error(INVALID_SCR_MSG, NULL);
1117N/A }
1117N/A aptr->adj_refscreen = val.str;
1117N/A if (aptr->adj_where == CONF_ADJ_RELATIVE)
1117N/A {
1117N/A token = xf86getSubToken(&(ptr->lay_comment));
1117N/A if (token != NUMBER) {
1117N/A xf86conffree(aptr);
1117N/A Error(INVALID_SCR_MSG, NULL);
1117N/A }
1117N/A aptr->adj_x = val.num;
1117N/A token = xf86getSubToken(&(ptr->lay_comment));
1117N/A if (token != NUMBER) {
1117N/A xf86conffree(aptr);
1117N/A Error(INVALID_SCR_MSG, NULL);
1117N/A }
1117N/A aptr->adj_y = val.num;
1117N/A }
1117N/A break;
1117N/A case CONF_ADJ_OBSOLETE:
1117N/A /* top */
1117N/A aptr->adj_top_str = val.str;
1117N/A
1117N/A /* bottom */
1117N/A if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
1117N/A xf86conffree(aptr);
1117N/A Error (SCREEN_MSG, NULL);
1117N/A }
1117N/A aptr->adj_bottom_str = val.str;
1117N/A
1117N/A /* left */
1117N/A if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
1117N/A xf86conffree(aptr);
1117N/A Error (SCREEN_MSG, NULL);
1117N/A }
1117N/A aptr->adj_left_str = val.str;
1117N/A
1117N/A /* right */
1117N/A if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
1117N/A xf86conffree(aptr);
1117N/A Error (SCREEN_MSG, NULL);
1117N/A }
1117N/A aptr->adj_right_str = val.str;
1117N/A
1117N/A }
1117N/A ptr->lay_adjacency_lst = (XF86ConfAdjacencyPtr)
1117N/A xf86addListItem ((glp) ptr->lay_adjacency_lst, (glp) aptr);
1117N/A }
1117N/A break;
1117N/A case INPUTDEVICE:
1117N/A {
1117N/A XF86ConfInputrefPtr iptr;
1117N/A
1117N/A iptr = xf86confcalloc (1, sizeof (XF86ConfInputrefRec));
1117N/A iptr->list.next = NULL;
1117N/A iptr->iref_option_lst = NULL;
1117N/A if (xf86getSubToken (&(ptr->lay_comment)) != STRING) {
1117N/A xf86conffree(iptr);
1117N/A Error (INPUTDEV_MSG, NULL);
1117N/A }
1117N/A iptr->iref_inputdev_str = val.str;
1117N/A while ((token = xf86getSubToken (&(ptr->lay_comment))) == STRING)
1117N/A {
1117N/A iptr->iref_option_lst =
1117N/A xf86addNewOption (iptr->iref_option_lst, val.str, NULL);
1117N/A }
1117N/A xf86unGetToken (token);
1117N/A ptr->lay_input_lst = (XF86ConfInputrefPtr)
1117N/A xf86addListItem ((glp) ptr->lay_input_lst, (glp) iptr);
1117N/A }
1117N/A break;
1117N/A case OPTION:
1117N/A ptr->lay_option_lst = xf86parseOption(ptr->lay_option_lst);
1117N/A break;
1117N/A case EOF_TOKEN:
1117N/A Error (UNEXPECTED_EOF_MSG, NULL);
1117N/A break;
1117N/A default:
1117N/A Error (INVALID_KEYWORD_MSG, xf86tokenString ());
1117N/A break;
1117N/A }
1117N/A }
1117N/A
1117N/A if (!has_ident)
1117N/A Error (NO_IDENT_MSG, NULL);
1117N/A
1117N/A#ifdef DEBUG
1117N/A printf ("ServerLayout section parsed\n");
1117N/A#endif
1117N/A
1117N/A return ptr;
1117N/A}
1117N/A
1117N/A#undef CLEANUP
1117N/A
1117N/Avoid
1117N/Axf86printLayoutSection (FILE * cf, XF86ConfLayoutPtr ptr)
1117N/A{
1117N/A XF86ConfAdjacencyPtr aptr;
1117N/A XF86ConfInactivePtr iptr;
1117N/A XF86ConfInputrefPtr inptr;
1117N/A XF86OptionPtr optr;
1117N/A
1117N/A while (ptr)
1117N/A {
1117N/A fprintf (cf, "Section \"ServerLayout\"\n");
1117N/A if (ptr->lay_comment)
1117N/A fprintf (cf, "%s", ptr->lay_comment);
1117N/A if (ptr->lay_identifier)
1117N/A fprintf (cf, "\tIdentifier \"%s\"\n", ptr->lay_identifier);
1117N/A
1117N/A for (aptr = ptr->lay_adjacency_lst; aptr; aptr = aptr->list.next)
1117N/A {
1117N/A fprintf (cf, "\tScreen ");
1117N/A if (aptr->adj_scrnum >= 0)
1117N/A fprintf (cf, "%2d", aptr->adj_scrnum);
1117N/A else
1117N/A fprintf (cf, " ");
1117N/A fprintf (cf, " \"%s\"", aptr->adj_screen_str);
1117N/A switch(aptr->adj_where)
1117N/A {
1117N/A case CONF_ADJ_OBSOLETE:
1117N/A fprintf (cf, " \"%s\"", aptr->adj_top_str);
1117N/A fprintf (cf, " \"%s\"", aptr->adj_bottom_str);
1117N/A fprintf (cf, " \"%s\"", aptr->adj_right_str);
1117N/A fprintf (cf, " \"%s\"\n", aptr->adj_left_str);
1117N/A break;
1117N/A case CONF_ADJ_ABSOLUTE:
1117N/A if (aptr->adj_x != -1)
1117N/A fprintf (cf, " %d %d\n", aptr->adj_x, aptr->adj_y);
1117N/A else
1117N/A fprintf (cf, "\n");
1117N/A break;
1117N/A case CONF_ADJ_RIGHTOF:
1117N/A fprintf (cf, " RightOf \"%s\"\n", aptr->adj_refscreen);
1117N/A break;
1117N/A case CONF_ADJ_LEFTOF:
1117N/A fprintf (cf, " LeftOf \"%s\"\n", aptr->adj_refscreen);
1117N/A break;
1117N/A case CONF_ADJ_ABOVE:
1117N/A fprintf (cf, " Above \"%s\"\n", aptr->adj_refscreen);
1117N/A break;
1117N/A case CONF_ADJ_BELOW:
1117N/A fprintf (cf, " Below \"%s\"\n", aptr->adj_refscreen);
1117N/A break;
1117N/A case CONF_ADJ_RELATIVE:
1117N/A fprintf (cf, " Relative \"%s\" %d %d\n", aptr->adj_refscreen,
1117N/A aptr->adj_x, aptr->adj_y);
1117N/A break;
1117N/A }
1117N/A }
1117N/A for (iptr = ptr->lay_inactive_lst; iptr; iptr = iptr->list.next)
1117N/A fprintf (cf, "\tInactive \"%s\"\n", iptr->inactive_device_str);
1117N/A for (inptr = ptr->lay_input_lst; inptr; inptr = inptr->list.next)
1117N/A {
1117N/A fprintf (cf, "\tInputDevice \"%s\"", inptr->iref_inputdev_str);
1117N/A for (optr = inptr->iref_option_lst; optr; optr = optr->list.next)
1117N/A {
1117N/A fprintf(cf, " \"%s\"", optr->opt_name);
1117N/A }
1117N/A fprintf(cf, "\n");
1117N/A }
1117N/A xf86printOptionList(cf, ptr->lay_option_lst, xf86whitespace_1);
1117N/A fprintf (cf, "EndSection\n\n");
1117N/A ptr = ptr->list.next;
1117N/A }
1117N/A}
1117N/A
1117N/Avoid
1117N/Axf86freeLayoutList (XF86ConfLayoutPtr ptr)
1117N/A{
1117N/A XF86ConfLayoutPtr prev;
1117N/A
1117N/A while (ptr)
1117N/A {
1117N/A TestFree (ptr->lay_identifier);
1117N/A TestFree (ptr->lay_comment);
1117N/A xf86freeAdjacencyList (ptr->lay_adjacency_lst);
1117N/A xf86freeInputrefList (ptr->lay_input_lst);
1117N/A prev = ptr;
1117N/A ptr = ptr->list.next;
1117N/A xf86conffree (prev);
1117N/A }
1117N/A}
1117N/A
1117N/Avoid
1117N/Axf86freeAdjacencyList (XF86ConfAdjacencyPtr ptr)
1117N/A{
1117N/A XF86ConfAdjacencyPtr prev;
1117N/A
1117N/A while (ptr)
1117N/A {
1117N/A TestFree (ptr->adj_screen_str);
1117N/A TestFree (ptr->adj_top_str);
1117N/A TestFree (ptr->adj_bottom_str);
1117N/A TestFree (ptr->adj_left_str);
1117N/A TestFree (ptr->adj_right_str);
1117N/A
1117N/A prev = ptr;
1117N/A ptr = ptr->list.next;
1117N/A xf86conffree (prev);
1117N/A }
1117N/A
1117N/A}
1117N/A
1117N/Avoid
1117N/Axf86freeInputrefList (XF86ConfInputrefPtr ptr)
1117N/A{
1117N/A XF86ConfInputrefPtr prev;
1117N/A
1117N/A while (ptr)
1117N/A {
1117N/A TestFree (ptr->iref_inputdev_str);
1117N/A xf86optionListFree (ptr->iref_option_lst);
1117N/A prev = ptr;
1117N/A ptr = ptr->list.next;
1117N/A xf86conffree (prev);
1117N/A }
1117N/A
1117N/A}
1117N/A
1117N/A#define CheckScreen(str, ptr)\
1117N/Aif (str[0] != '\0') \
1117N/A{ \
1117N/Ascreen = xf86findScreen (str, p->conf_screen_lst); \
1117N/Aif (!screen) \
1117N/A{ \
1117N/A xf86validationError (UNDEFINED_SCREEN_MSG, \
1117N/A str, layout->lay_identifier); \
1117N/A return (FALSE); \
1117N/A} \
1117N/Aelse \
1117N/A ptr = screen; \
1117N/A}
1117N/A
1117N/Aint
1117N/Axf86validateLayout (XF86ConfigPtr p)
1117N/A{
1117N/A XF86ConfLayoutPtr layout = p->conf_layout_lst;
1117N/A XF86ConfAdjacencyPtr adj;
1117N/A XF86ConfInactivePtr iptr;
1117N/A XF86ConfInputrefPtr inptr;
1117N/A XF86ConfScreenPtr screen;
1117N/A XF86ConfDevicePtr device;
1117N/A XF86ConfInputPtr input;
1117N/A
1117N/A while (layout)
1117N/A {
1117N/A adj = layout->lay_adjacency_lst;
1117N/A while (adj)
1117N/A {
1117N/A /* the first one can't be "" but all others can */
1117N/A screen = xf86findScreen (adj->adj_screen_str, p->conf_screen_lst);
1117N/A if (!screen)
1117N/A {
1117N/A xf86validationError (UNDEFINED_SCREEN_MSG,
1117N/A adj->adj_screen_str, layout->lay_identifier);
1117N/A return (FALSE);
1117N/A }
1117N/A else
1117N/A adj->adj_screen = screen;
1117N/A
1117N/A#if 0
1117N/A CheckScreen (adj->adj_top_str, adj->adj_top);
1117N/A CheckScreen (adj->adj_bottom_str, adj->adj_bottom);
1117N/A CheckScreen (adj->adj_left_str, adj->adj_left);
1117N/A CheckScreen (adj->adj_right_str, adj->adj_right);
1117N/A#endif
1117N/A
1117N/A adj = adj->list.next;
1117N/A }
1117N/A iptr = layout->lay_inactive_lst;
1117N/A while (iptr)
1117N/A {
1117N/A device = xf86findDevice (iptr->inactive_device_str,
1117N/A p->conf_device_lst);
1117N/A if (!device)
1117N/A {
1117N/A xf86validationError (UNDEFINED_DEVICE_LAY_MSG,
1117N/A iptr->inactive_device_str, layout->lay_identifier);
1117N/A return (FALSE);
1117N/A }
1117N/A else
1117N/A iptr->inactive_device = device;
1117N/A iptr = iptr->list.next;
1117N/A }
1117N/A inptr = layout->lay_input_lst;
1117N/A while (inptr)
1117N/A {
1117N/A input = xf86findInput (inptr->iref_inputdev_str,
1117N/A p->conf_input_lst);
1117N/A if (!input)
1117N/A {
1117N/A xf86validationError (UNDEFINED_INPUT_MSG,
1117N/A inptr->iref_inputdev_str, layout->lay_identifier);
1117N/A return (FALSE);
1117N/A }
1117N/A else
1117N/A inptr->iref_inputdev = input;
1117N/A inptr = inptr->list.next;
1117N/A }
1117N/A layout = layout->list.next;
1117N/A }
1117N/A return (TRUE);
1117N/A}
1117N/A
1117N/AXF86ConfLayoutPtr
1117N/Axf86findLayout (const char *name, XF86ConfLayoutPtr list)
1117N/A{
1117N/A while (list)
1117N/A {
1117N/A if (xf86nameCompare (list->lay_identifier, name) == 0)
1117N/A return (list);
1117N/A list = list->list.next;
1117N/A }
1117N/A return (NULL);
1117N/A}
1117N/A