135c4bbdfSmrg/* 235c4bbdfSmrg * 305b261ecSmrg * Copyright (c) 1997 Metro Link Incorporated 435c4bbdfSmrg * 505b261ecSmrg * Permission is hereby granted, free of charge, to any person obtaining a 635c4bbdfSmrg * copy of this software and associated documentation files (the "Software"), 705b261ecSmrg * to deal in the Software without restriction, including without limitation 805b261ecSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 905b261ecSmrg * and/or sell copies of the Software, and to permit persons to whom the 1005b261ecSmrg * Software is furnished to do so, subject to the following conditions: 1135c4bbdfSmrg * 1205b261ecSmrg * The above copyright notice and this permission notice shall be included in 1305b261ecSmrg * all copies or substantial portions of the Software. 1435c4bbdfSmrg * 1505b261ecSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1605b261ecSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1705b261ecSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1805b261ecSmrg * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 1905b261ecSmrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 2005b261ecSmrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 2105b261ecSmrg * SOFTWARE. 2235c4bbdfSmrg * 2305b261ecSmrg * Except as contained in this notice, the name of the Metro Link shall not be 2405b261ecSmrg * used in advertising or otherwise to promote the sale, use or other dealings 2505b261ecSmrg * in this Software without prior written authorization from Metro Link. 2635c4bbdfSmrg * 2705b261ecSmrg */ 2805b261ecSmrg/* 2905b261ecSmrg * Copyright (c) 1997-2003 by The XFree86 Project, Inc. 3005b261ecSmrg * 3105b261ecSmrg * Permission is hereby granted, free of charge, to any person obtaining a 3205b261ecSmrg * copy of this software and associated documentation files (the "Software"), 3305b261ecSmrg * to deal in the Software without restriction, including without limitation 3405b261ecSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 3505b261ecSmrg * and/or sell copies of the Software, and to permit persons to whom the 3605b261ecSmrg * Software is furnished to do so, subject to the following conditions: 3705b261ecSmrg * 3805b261ecSmrg * The above copyright notice and this permission notice shall be included in 3905b261ecSmrg * all copies or substantial portions of the Software. 4005b261ecSmrg * 4105b261ecSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4205b261ecSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4305b261ecSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 4405b261ecSmrg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 4505b261ecSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 4605b261ecSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 4705b261ecSmrg * OTHER DEALINGS IN THE SOFTWARE. 4805b261ecSmrg * 4905b261ecSmrg * Except as contained in this notice, the name of the copyright holder(s) 5005b261ecSmrg * and author(s) shall not be used in advertising or otherwise to promote 5105b261ecSmrg * the sale, use or other dealings in this Software without prior written 5205b261ecSmrg * authorization from the copyright holder(s) and author(s). 5305b261ecSmrg */ 5405b261ecSmrg 5505b261ecSmrg#ifdef HAVE_XORG_CONFIG_H 5605b261ecSmrg#include <xorg-config.h> 5705b261ecSmrg#endif 5805b261ecSmrg 596747b715Smrg#include "os.h" 6005b261ecSmrg#include "xf86Parser.h" 6105b261ecSmrg#include "xf86tokens.h" 6205b261ecSmrg#include "Configint.h" 6305b261ecSmrg 6405b261ecSmrg 651b5d61b8Smrgstatic const xf86ConfigSymTabRec InputTab[] = { 6635c4bbdfSmrg {ENDSECTION, "endsection"}, 6735c4bbdfSmrg {IDENTIFIER, "identifier"}, 6835c4bbdfSmrg {OPTION, "option"}, 6935c4bbdfSmrg {DRIVER, "driver"}, 7035c4bbdfSmrg {-1, ""}, 7105b261ecSmrg}; 7205b261ecSmrg 7305b261ecSmrg#define CLEANUP xf86freeInputList 7405b261ecSmrg 7505b261ecSmrgXF86ConfInputPtr 7635c4bbdfSmrgxf86parseInputSection(void) 7705b261ecSmrg{ 7835c4bbdfSmrg int has_ident = FALSE; 7935c4bbdfSmrg int token; 8035c4bbdfSmrg 8135c4bbdfSmrg parsePrologue(XF86ConfInputPtr, XF86ConfInputRec) 8235c4bbdfSmrg 8335c4bbdfSmrg while ((token = xf86getToken(InputTab)) != ENDSECTION) { 8435c4bbdfSmrg switch (token) { 8535c4bbdfSmrg case COMMENT: 8635c4bbdfSmrg ptr->inp_comment = xf86addComment(ptr->inp_comment, xf86_lex_val.str); 8758cf2af7Smrg free(xf86_lex_val.str); 8858cf2af7Smrg xf86_lex_val.str = NULL; 8935c4bbdfSmrg break; 9035c4bbdfSmrg case IDENTIFIER: 9135c4bbdfSmrg if (xf86getSubToken(&(ptr->inp_comment)) != STRING) 9235c4bbdfSmrg Error(QUOTE_MSG, "Identifier"); 9335c4bbdfSmrg if (has_ident == TRUE) 9435c4bbdfSmrg Error(MULTIPLE_MSG, "Identifier"); 9535c4bbdfSmrg ptr->inp_identifier = xf86_lex_val.str; 9635c4bbdfSmrg has_ident = TRUE; 9735c4bbdfSmrg break; 9835c4bbdfSmrg case DRIVER: 9935c4bbdfSmrg if (xf86getSubToken(&(ptr->inp_comment)) != STRING) 10035c4bbdfSmrg Error(QUOTE_MSG, "Driver"); 10135c4bbdfSmrg if (strcmp(xf86_lex_val.str, "keyboard") == 0) { 10235c4bbdfSmrg ptr->inp_driver = strdup("kbd"); 10335c4bbdfSmrg free(xf86_lex_val.str); 10435c4bbdfSmrg } 10535c4bbdfSmrg else 10635c4bbdfSmrg ptr->inp_driver = xf86_lex_val.str; 10735c4bbdfSmrg break; 10835c4bbdfSmrg case OPTION: 10935c4bbdfSmrg ptr->inp_option_lst = xf86parseOption(ptr->inp_option_lst); 11035c4bbdfSmrg break; 11135c4bbdfSmrg case EOF_TOKEN: 11235c4bbdfSmrg Error(UNEXPECTED_EOF_MSG); 11335c4bbdfSmrg break; 11435c4bbdfSmrg default: 11535c4bbdfSmrg Error(INVALID_KEYWORD_MSG, xf86tokenString()); 11635c4bbdfSmrg break; 11735c4bbdfSmrg } 11835c4bbdfSmrg } 11935c4bbdfSmrg 12035c4bbdfSmrg if (!has_ident) 12135c4bbdfSmrg Error(NO_IDENT_MSG); 12205b261ecSmrg 12305b261ecSmrg#ifdef DEBUG 12435c4bbdfSmrg printf("InputDevice section parsed\n"); 12505b261ecSmrg#endif 12605b261ecSmrg 12735c4bbdfSmrg return ptr; 12805b261ecSmrg} 12905b261ecSmrg 13005b261ecSmrg#undef CLEANUP 13105b261ecSmrg 13205b261ecSmrgvoid 13335c4bbdfSmrgxf86printInputSection(FILE * cf, XF86ConfInputPtr ptr) 13405b261ecSmrg{ 13535c4bbdfSmrg while (ptr) { 13635c4bbdfSmrg fprintf(cf, "Section \"InputDevice\"\n"); 13735c4bbdfSmrg if (ptr->inp_comment) 13835c4bbdfSmrg fprintf(cf, "%s", ptr->inp_comment); 13935c4bbdfSmrg if (ptr->inp_identifier) 14035c4bbdfSmrg fprintf(cf, "\tIdentifier \"%s\"\n", ptr->inp_identifier); 14135c4bbdfSmrg if (ptr->inp_driver) 14235c4bbdfSmrg fprintf(cf, "\tDriver \"%s\"\n", ptr->inp_driver); 14335c4bbdfSmrg xf86printOptionList(cf, ptr->inp_option_lst, 1); 14435c4bbdfSmrg fprintf(cf, "EndSection\n\n"); 14535c4bbdfSmrg ptr = ptr->list.next; 14635c4bbdfSmrg } 14705b261ecSmrg} 14805b261ecSmrg 14905b261ecSmrgvoid 15035c4bbdfSmrgxf86freeInputList(XF86ConfInputPtr ptr) 15105b261ecSmrg{ 15235c4bbdfSmrg XF86ConfInputPtr prev; 15335c4bbdfSmrg 15435c4bbdfSmrg while (ptr) { 15535c4bbdfSmrg TestFree(ptr->inp_identifier); 15635c4bbdfSmrg TestFree(ptr->inp_driver); 15735c4bbdfSmrg TestFree(ptr->inp_comment); 15835c4bbdfSmrg xf86optionListFree(ptr->inp_option_lst); 15935c4bbdfSmrg 16035c4bbdfSmrg prev = ptr; 16135c4bbdfSmrg ptr = ptr->list.next; 16235c4bbdfSmrg free(prev); 16335c4bbdfSmrg } 16405b261ecSmrg} 16505b261ecSmrg 16605b261ecSmrgint 16735c4bbdfSmrgxf86validateInput(XF86ConfigPtr p) 16805b261ecSmrg{ 16935c4bbdfSmrg XF86ConfInputPtr input = p->conf_input_lst; 17035c4bbdfSmrg 17135c4bbdfSmrg while (input) { 17235c4bbdfSmrg if (!input->inp_driver) { 17335c4bbdfSmrg xf86validationError(UNDEFINED_INPUTDRIVER_MSG, 17435c4bbdfSmrg input->inp_identifier); 17535c4bbdfSmrg return FALSE; 17635c4bbdfSmrg } 17735c4bbdfSmrg input = input->list.next; 17835c4bbdfSmrg } 17935c4bbdfSmrg return TRUE; 18005b261ecSmrg} 18105b261ecSmrg 18205b261ecSmrgXF86ConfInputPtr 18335c4bbdfSmrgxf86findInput(const char *ident, XF86ConfInputPtr p) 18405b261ecSmrg{ 18535c4bbdfSmrg while (p) { 18635c4bbdfSmrg if (xf86nameCompare(ident, p->inp_identifier) == 0) 18735c4bbdfSmrg return p; 18835c4bbdfSmrg 18935c4bbdfSmrg p = p->list.next; 19035c4bbdfSmrg } 19135c4bbdfSmrg return NULL; 19205b261ecSmrg} 19305b261ecSmrg 19405b261ecSmrgXF86ConfInputPtr 19535c4bbdfSmrgxf86findInputByDriver(const char *driver, XF86ConfInputPtr p) 19605b261ecSmrg{ 19735c4bbdfSmrg while (p) { 19835c4bbdfSmrg if (xf86nameCompare(driver, p->inp_driver) == 0) 19935c4bbdfSmrg return p; 20005b261ecSmrg 20135c4bbdfSmrg p = p->list.next; 20235c4bbdfSmrg } 20335c4bbdfSmrg return NULL; 20435c4bbdfSmrg} 205