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