Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / parser / Input.c
blob3d9801968ae4db5d72b23aae601cdf3b34bb41fa
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"
66 extern LexRec val;
68 static
69 xf86ConfigSymTabRec InputTab[] =
71 {ENDSECTION, "endsection"},
72 {IDENTIFIER, "identifier"},
73 {OPTION, "option"},
74 {DRIVER, "driver"},
75 {-1, ""},
78 #define CLEANUP xf86freeInputList
80 XF86ConfInputPtr
81 xf86parseInputSection (void)
83 int has_ident = FALSE;
84 int token;
85 parsePrologue (XF86ConfInputPtr, XF86ConfInputRec)
87 while ((token = xf86getToken (InputTab)) != ENDSECTION)
89 switch (token)
91 case COMMENT:
92 ptr->inp_comment = xf86addComment(ptr->inp_comment, val.str);
93 break;
94 case IDENTIFIER:
95 if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
96 Error (QUOTE_MSG, "Identifier");
97 if (has_ident == TRUE)
98 Error (MULTIPLE_MSG, "Identifier");
99 ptr->inp_identifier = val.str;
100 has_ident = TRUE;
101 break;
102 case DRIVER:
103 if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
104 Error (QUOTE_MSG, "Driver");
105 if (strcmp(val.str, "keyboard") == 0)
106 ptr->inp_driver = "kbd";
107 else
108 ptr->inp_driver = val.str;
109 break;
110 case OPTION:
111 ptr->inp_option_lst = xf86parseOption(ptr->inp_option_lst);
112 break;
113 case EOF_TOKEN:
114 Error (UNEXPECTED_EOF_MSG, NULL);
115 break;
116 default:
117 Error (INVALID_KEYWORD_MSG, xf86tokenString ());
118 break;
122 if (!has_ident)
123 Error (NO_IDENT_MSG, NULL);
125 #ifdef DEBUG
126 printf ("InputDevice section parsed\n");
127 #endif
129 return ptr;
132 #undef CLEANUP
134 void
135 xf86printInputSection (FILE * cf, XF86ConfInputPtr ptr)
137 while (ptr)
139 fprintf (cf, "Section \"InputDevice\"\n");
140 if (ptr->inp_comment)
141 fprintf (cf, "%s", ptr->inp_comment);
142 if (ptr->inp_identifier)
143 fprintf (cf, "\tIdentifier \"%s\"\n", ptr->inp_identifier);
144 if (ptr->inp_driver)
145 fprintf (cf, "\tDriver \"%s\"\n", ptr->inp_driver);
146 xf86printOptionList(cf, ptr->inp_option_lst, 1);
147 fprintf (cf, "EndSection\n\n");
148 ptr = ptr->list.next;
152 void
153 xf86freeInputList (XF86ConfInputPtr ptr)
155 XF86ConfInputPtr prev;
157 while (ptr)
159 TestFree (ptr->inp_identifier);
160 TestFree (ptr->inp_driver);
161 TestFree (ptr->inp_comment);
162 xf86optionListFree (ptr->inp_option_lst);
164 prev = ptr;
165 ptr = ptr->list.next;
166 xf86conffree (prev);
171 xf86validateInput (XF86ConfigPtr p)
173 XF86ConfInputPtr input = p->conf_input_lst;
175 #if 0 /* Enable this later */
176 if (!input) {
177 xf86validationError ("At least one InputDevice section is required.");
178 return (FALSE);
180 #endif
182 while (input) {
183 if (!input->inp_driver) {
184 xf86validationError (UNDEFINED_INPUTDRIVER_MSG, input->inp_identifier);
185 return (FALSE);
187 input = input->list.next;
189 return (TRUE);
192 XF86ConfInputPtr
193 xf86findInput (const char *ident, XF86ConfInputPtr p)
195 while (p)
197 if (xf86nameCompare (ident, p->inp_identifier) == 0)
198 return (p);
200 p = p->list.next;
202 return (NULL);
205 XF86ConfInputPtr
206 xf86findInputByDriver (const char *driver, XF86ConfInputPtr p)
208 while (p)
210 if (xf86nameCompare (driver, p->inp_driver) == 0)
211 return (p);
213 p = p->list.next;
215 return (NULL);