Pointer.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 "xf86Parser.h"
63#include "xf86tokens.h"
64#include "Configint.h"
65
66extern LexRec val;
67
68static xf86ConfigSymTabRec PointerTab[] =
69{
70	{PROTOCOL, "protocol"},
71	{EMULATE3, "emulate3buttons"},
72	{EM3TIMEOUT, "emulate3timeout"},
73	{ENDSUBSECTION, "endsubsection"},
74	{ENDSECTION, "endsection"},
75	{PDEVICE, "device"},
76	{PDEVICE, "port"},
77	{BAUDRATE, "baudrate"},
78	{SAMPLERATE, "samplerate"},
79	{CLEARDTR, "cleardtr"},
80	{CLEARRTS, "clearrts"},
81	{CHORDMIDDLE, "chordmiddle"},
82	{PRESOLUTION, "resolution"},
83	{DEVICE_NAME, "devicename"},
84	{ALWAYSCORE, "alwayscore"},
85	{PBUTTONS, "buttons"},
86	{ZAXISMAPPING, "zaxismapping"},
87	{-1, ""},
88};
89
90static xf86ConfigSymTabRec ZMapTab[] =
91{
92	{XAXIS, "x"},
93	{YAXIS, "y"},
94	{-1, ""},
95};
96
97#define CLEANUP xf86freeInputList
98
99XF86ConfInputPtr
100xf86parsePointerSection (void)
101{
102	char *s, *s1, *s2;
103	int l;
104	int token;
105	parsePrologue (XF86ConfInputPtr, XF86ConfInputRec)
106
107	while ((token = xf86getToken (PointerTab)) != ENDSECTION)
108	{
109		switch (token)
110		{
111		case COMMENT:
112			ptr->inp_comment = xf86addComment(ptr->inp_comment, val.str);
113			break;
114		case PROTOCOL:
115			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
116				Error (QUOTE_MSG, "Protocol");
117			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
118												strdup("Protocol"),
119												val.str);
120			break;
121		case PDEVICE:
122			if (xf86getSubToken (&(ptr->inp_comment)) != STRING)
123				Error (QUOTE_MSG, "Device");
124			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
125												strdup("Device"),
126												val.str);
127			break;
128		case EMULATE3:
129			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
130												strdup("Emulate3Buttons"),
131												NULL);
132			break;
133		case EM3TIMEOUT:
134			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0)
135				Error (POSITIVE_INT_MSG, "Emulate3Timeout");
136			s = xf86uLongToString(val.num);
137			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
138												strdup("Emulate3Timeout"),
139												s);
140			break;
141		case CHORDMIDDLE:
142			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
143												strdup("ChordMiddle"),
144												NULL);
145			break;
146		case PBUTTONS:
147			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0)
148				Error (POSITIVE_INT_MSG, "Buttons");
149			s = xf86uLongToString(val.num);
150			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
151												strdup("Buttons"), s);
152			break;
153		case BAUDRATE:
154			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0)
155				Error (POSITIVE_INT_MSG, "BaudRate");
156			s = xf86uLongToString(val.num);
157			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
158												strdup("BaudRate"), s);
159			break;
160		case SAMPLERATE:
161			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0)
162				Error (POSITIVE_INT_MSG, "SampleRate");
163			s = xf86uLongToString(val.num);
164			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
165												strdup("SampleRate"), s);
166			break;
167		case PRESOLUTION:
168			if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0)
169				Error (POSITIVE_INT_MSG, "Resolution");
170			s = xf86uLongToString(val.num);
171			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
172												strdup("Resolution"), s);
173			break;
174		case CLEARDTR:
175			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
176												strdup("ClearDTR"), NULL);
177			break;
178		case CLEARRTS:
179			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
180												strdup("ClearRTS"), NULL);
181			break;
182		case ZAXISMAPPING:
183			switch (xf86getToken(ZMapTab)) {
184			case NUMBER:
185				if (val.num < 0)
186					Error (ZAXISMAPPING_MSG, NULL);
187				s1 = xf86uLongToString(val.num);
188				if (xf86getSubToken (&(ptr->inp_comment)) != NUMBER || val.num < 0) {
189					free(s1);
190					Error (ZAXISMAPPING_MSG, NULL);
191				}
192				s2 = xf86uLongToString(val.num);
193				l = strlen(s1) + 1 + strlen(s2) + 1;
194				s = malloc(l);
195				sprintf(s, "%s %s", s1, s2);
196				free(s1);
197				free(s2);
198				break;
199			case XAXIS:
200				s = strdup("x");
201				break;
202			case YAXIS:
203				s = strdup("y");
204				break;
205			default:
206				Error (ZAXISMAPPING_MSG, NULL);
207				break;
208			}
209			ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
210												strdup("ZAxisMapping"),
211												s);
212			break;
213		case ALWAYSCORE:
214			break;
215		case EOF_TOKEN:
216			Error (UNEXPECTED_EOF_MSG, NULL);
217			break;
218		default:
219			Error (INVALID_KEYWORD_MSG, xf86tokenString ());
220			break;
221		}
222	}
223
224	ptr->inp_identifier = strdup(CONF_IMPLICIT_POINTER);
225	ptr->inp_driver = strdup("mouse");
226	ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst,
227										strdup("CorePointer"), NULL);
228
229#ifdef DEBUG
230	printf ("Pointer section parsed\n");
231#endif
232
233	return ptr;
234}
235
236#undef CLEANUP
237
238