| 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 "os.h" |
| 60 | #include "xf86Parser.h" |
| 61 | #include "xf86tokens.h" |
| 62 | #include "Configint.h" |
| 63 | |
| 64 | extern LexRec val; |
| 65 | |
| 66 | static |
| 67 | xf86ConfigSymTabRec InputTab[] = { |
| 68 | {ENDSECTION, "endsection"}, |
| 69 | {IDENTIFIER, "identifier"}, |
| 70 | {OPTION, "option"}, |
| 71 | {DRIVER, "driver"}, |
| 72 | {-1, ""}, |
| 73 | }; |
| 74 | |
| 75 | #define CLEANUP xf86freeInputList |
| 76 | |
| 77 | XF86ConfInputPtr |
| 78 | xf86parseInputSection(void) |
| 79 | { |
| 80 | int has_ident = FALSE; |
| 81 | int token; |
| 82 | |
| 83 | parsePrologue(XF86ConfInputPtr, XF86ConfInputRec) |
| 84 | |
| 85 | while ((token = xf86getToken(InputTab)) != ENDSECTION) { |
| 86 | switch (token) { |
| 87 | case COMMENT: |
| 88 | ptr->inp_comment = xf86addComment(ptr->inp_comment, val.str); |
| 89 | break; |
| 90 | case IDENTIFIER: |
| 91 | if (xf86getSubToken(&(ptr->inp_comment)) != STRING) |
| 92 | Error(QUOTE_MSG, "Identifier"); |
| 93 | if (has_ident == TRUE) |
| 94 | Error(MULTIPLE_MSG, "Identifier"); |
| 95 | ptr->inp_identifier = val.str; |
| 96 | has_ident = TRUE; |
| 97 | break; |
| 98 | case DRIVER: |
| 99 | if (xf86getSubToken(&(ptr->inp_comment)) != STRING) |
| 100 | Error(QUOTE_MSG, "Driver"); |
| 101 | if (strcmp(val.str, "keyboard") == 0) { |
| 102 | ptr->inp_driver = strdup("kbd"); |
| 103 | free(val.str); |
| 104 | } |
| 105 | else |
| 106 | ptr->inp_driver = val.str; |
| 107 | break; |
| 108 | case OPTION: |
| 109 | ptr->inp_option_lst = xf86parseOption(ptr->inp_option_lst); |
| 110 | break; |
| 111 | case EOF_TOKEN: |
| 112 | Error(UNEXPECTED_EOF_MSG); |
| 113 | break; |
| 114 | default: |
| 115 | Error(INVALID_KEYWORD_MSG, xf86tokenString()); |
| 116 | break; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if (!has_ident) |
| 121 | Error(NO_IDENT_MSG); |
| 122 | |
| 123 | #ifdef DEBUG |
| 124 | printf("InputDevice section parsed\n"); |
| 125 | #endif |
| 126 | |
| 127 | return ptr; |
| 128 | } |
| 129 | |
| 130 | #undef CLEANUP |
| 131 | |
| 132 | void |
| 133 | xf86printInputSection(FILE * cf, XF86ConfInputPtr ptr) |
| 134 | { |
| 135 | while (ptr) { |
| 136 | fprintf(cf, "Section \"InputDevice\"\n"); |
| 137 | if (ptr->inp_comment) |
| 138 | fprintf(cf, "%s", ptr->inp_comment); |
| 139 | if (ptr->inp_identifier) |
| 140 | fprintf(cf, "\tIdentifier \"%s\"\n", ptr->inp_identifier); |
| 141 | if (ptr->inp_driver) |
| 142 | fprintf(cf, "\tDriver \"%s\"\n", ptr->inp_driver); |
| 143 | xf86printOptionList(cf, ptr->inp_option_lst, 1); |
| 144 | fprintf(cf, "EndSection\n\n"); |
| 145 | ptr = ptr->list.next; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | void |
| 150 | xf86freeInputList(XF86ConfInputPtr ptr) |
| 151 | { |
| 152 | XF86ConfInputPtr prev; |
| 153 | |
| 154 | while (ptr) { |
| 155 | TestFree(ptr->inp_identifier); |
| 156 | TestFree(ptr->inp_driver); |
| 157 | TestFree(ptr->inp_comment); |
| 158 | xf86optionListFree(ptr->inp_option_lst); |
| 159 | |
| 160 | prev = ptr; |
| 161 | ptr = ptr->list.next; |
| 162 | free(prev); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | int |
| 167 | xf86validateInput(XF86ConfigPtr p) |
| 168 | { |
| 169 | XF86ConfInputPtr input = p->conf_input_lst; |
| 170 | |
| 171 | while (input) { |
| 172 | if (!input->inp_driver) { |
| 173 | xf86validationError(UNDEFINED_INPUTDRIVER_MSG, |
| 174 | input->inp_identifier); |
| 175 | return FALSE; |
| 176 | } |
| 177 | input = input->list.next; |
| 178 | } |
| 179 | return TRUE; |
| 180 | } |
| 181 | |
| 182 | XF86ConfInputPtr |
| 183 | xf86findInput(const char *ident, XF86ConfInputPtr p) |
| 184 | { |
| 185 | while (p) { |
| 186 | if (xf86nameCompare(ident, p->inp_identifier) == 0) |
| 187 | return p; |
| 188 | |
| 189 | p = p->list.next; |
| 190 | } |
| 191 | return NULL; |
| 192 | } |
| 193 | |
| 194 | XF86ConfInputPtr |
| 195 | xf86findInputByDriver(const char *driver, XF86ConfInputPtr p) |
| 196 | { |
| 197 | while (p) { |
| 198 | if (xf86nameCompare(driver, p->inp_driver) == 0) |
| 199 | return p; |
| 200 | |
| 201 | p = p->list.next; |
| 202 | } |
| 203 | return NULL; |
| 204 | } |