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