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