Input.c revision 6747b715
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
22 *
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.
26 *
27 */
28/*
29 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
30 *
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:
37 *
38 * The above copyright notice and this permission notice shall be included in
39 * all copies or substantial portions of the Software.
40 *
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.
48 *
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).
53 */
54
55
56/* View/edit this file with tab stops set to 4 */
57
58#ifdef HAVE_XORG_CONFIG_H
59#include <xorg-config.h>
60#endif
61
62#include "os.h"
63#include "xf86Parser.h"
64#include "xf86tokens.h"
65#include "Configint.h"
66
67extern LexRec val;
68
69static
70xf86ConfigSymTabRec InputTab[] =
71{
72	{ENDSECTION, "endsection"},
73	{IDENTIFIER, "identifier"},
74	{OPTION, "option"},
75	{DRIVER, "driver"},
76	{-1, ""},
77};
78
79#define CLEANUP xf86freeInputList
80
81XF86ConfInputPtr
82xf86parseInputSection (void)
83{
84	int has_ident = FALSE;
85	int token;
86	parsePrologue (XF86ConfInputPtr, XF86ConfInputRec)
87
88	while ((token = xf86getToken (InputTab)) != ENDSECTION)
89	{
90		switch (token)
91		{
92		case COMMENT:
93			ptr->inp_comment = xf86addComment(ptr->inp_comment, val.str);
94			break;
95		case IDENTIFIER:
96			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
97				Error (QUOTE_MSG, "Identifier");
98			if (has_ident == TRUE)
99				Error (MULTIPLE_MSG, "Identifier");
100			ptr->inp_identifier = val.str;
101			has_ident = TRUE;
102			break;
103		case DRIVER:
104			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
105				Error (QUOTE_MSG, "Driver");
106                        if (strcmp(val.str, "keyboard") == 0) {
107                            ptr->inp_driver = strdup("kbd");
108                            free(val.str);
109                        }
110                        else
111			    ptr->inp_driver = val.str;
112			break;
113		case OPTION:
114			ptr->inp_option_lst = xf86parseOption(ptr->inp_option_lst);
115			break;
116		case EOF_TOKEN:
117			Error (UNEXPECTED_EOF_MSG, NULL);
118			break;
119		default:
120			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
121			break;
122		}
123	}
124
125	if (!has_ident)
126		Error (NO_IDENT_MSG, NULL);
127
128#ifdef DEBUG
129	printf ("InputDevice section parsed\n");
130#endif
131
132	return ptr;
133}
134
135#undef CLEANUP
136
137void
138xf86printInputSection (FILE * cf, XF86ConfInputPtr ptr)
139{
140	while (ptr)
141	{
142		fprintf (cf, "Section \"InputDevice\"\n");
143		if (ptr->inp_comment)
144			fprintf (cf, "%s", ptr->inp_comment);
145		if (ptr->inp_identifier)
146			fprintf (cf, "\tIdentifier  \"%s\"\n", ptr->inp_identifier);
147		if (ptr->inp_driver)
148			fprintf (cf, "\tDriver      \"%s\"\n", ptr->inp_driver);
149		xf86printOptionList(cf, ptr->inp_option_lst, 1);
150		fprintf (cf, "EndSection\n\n");
151		ptr = ptr->list.next;
152	}
153}
154
155void
156xf86freeInputList (XF86ConfInputPtr ptr)
157{
158	XF86ConfInputPtr prev;
159
160	while (ptr)
161	{
162		TestFree (ptr->inp_identifier);
163		TestFree (ptr->inp_driver);
164		TestFree (ptr->inp_comment);
165		xf86optionListFree (ptr->inp_option_lst);
166
167		prev = ptr;
168		ptr = ptr->list.next;
169		free (prev);
170	}
171}
172
173int
174xf86validateInput (XF86ConfigPtr p)
175{
176	XF86ConfInputPtr input = p->conf_input_lst;
177
178	while (input) {
179		if (!input->inp_driver) {
180			xf86validationError (UNDEFINED_INPUTDRIVER_MSG, input->inp_identifier);
181			return FALSE;
182		}
183		input = input->list.next;
184	}
185	return TRUE;
186}
187
188XF86ConfInputPtr
189xf86findInput (const char *ident, XF86ConfInputPtr p)
190{
191	while (p)
192	{
193		if (xf86nameCompare (ident, p->inp_identifier) == 0)
194			return p;
195
196		p = p->list.next;
197	}
198	return NULL;
199}
200
201XF86ConfInputPtr
202xf86findInputByDriver (const char *driver, XF86ConfInputPtr p)
203{
204	while (p)
205	{
206		if (xf86nameCompare (driver, p->inp_driver) == 0)
207			return p;
208
209		p = p->list.next;
210	}
211	return NULL;
212}
213
214