| 1 | /* Copyright (C) 2007 L. Donnie Smith <donnie.smith@gatech.edu> |
|---|
| 2 | * |
|---|
| 3 | * This program is free software; you can redistribute it and/or modify |
|---|
| 4 | * it under the terms of the GNU General Public License as published by |
|---|
| 5 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 6 | * (at your option) any later version. |
|---|
| 7 | * |
|---|
| 8 | * This program is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * GNU General Public License for more details. |
|---|
| 12 | * |
|---|
| 13 | * You should have received a copy of the GNU General Public License |
|---|
| 14 | * along with this program; if not, write to the Free Software |
|---|
| 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 16 | * |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | %{ |
|---|
| 20 | #include <stdio.h> |
|---|
| 21 | #include <stdlib.h> |
|---|
| 22 | #include <string.h> |
|---|
| 23 | #include "conf.h" |
|---|
| 24 | #include "util.h" |
|---|
| 25 | #include "y.tab.h" |
|---|
| 26 | |
|---|
| 27 | #define step \ |
|---|
| 28 | do { \ |
|---|
| 29 | yylloc.first_line = yylloc.last_line; \ |
|---|
| 30 | yylloc.first_column = yylloc.last_column; \ |
|---|
| 31 | yylloc.last_column += strlen(yytext); \ |
|---|
| 32 | } while(0) |
|---|
| 33 | |
|---|
| 34 | #define step_nl \ |
|---|
| 35 | do { \ |
|---|
| 36 | yylloc.first_line = yylloc.last_line; \ |
|---|
| 37 | yylloc.first_column = yylloc.last_column; \ |
|---|
| 38 | yylloc.last_line++; \ |
|---|
| 39 | yylloc.last_column = 0; \ |
|---|
| 40 | } while (0) |
|---|
| 41 | |
|---|
| 42 | extern struct conf *cur_conf; |
|---|
| 43 | %} |
|---|
| 44 | |
|---|
| 45 | WM Wiimote\. |
|---|
| 46 | NC Nunchuk\. |
|---|
| 47 | CC Classic\. |
|---|
| 48 | PLUGIN Plugin\. |
|---|
| 49 | ID [[:alnum:]_][[:alnum:]_-]* |
|---|
| 50 | ACTION (KEY|BTN|ABS|REL)_[[:alnum:]_]+ |
|---|
| 51 | FILENAME [[:alnum:]_.-]+ |
|---|
| 52 | INT [0-9]+ |
|---|
| 53 | FLOAT [0-9]+(\.[0-9]*)?([eE][+/-]?[0-9]+)? |
|---|
| 54 | BLANK [[:blank:]]+ |
|---|
| 55 | |
|---|
| 56 | %option nounput |
|---|
| 57 | %x inc postinc |
|---|
| 58 | %% |
|---|
| 59 | ^include { |
|---|
| 60 | yylloc.first_line = yylloc.last_line; |
|---|
| 61 | yylloc.first_column = yylloc.last_column; |
|---|
| 62 | yylloc.last_line++; |
|---|
| 63 | yylloc.last_column = strlen(yytext) -1; |
|---|
| 64 | BEGIN(inc); |
|---|
| 65 | } |
|---|
| 66 | <inc>{BLANK} { step; } |
|---|
| 67 | <inc>{FILENAME} { |
|---|
| 68 | FILE *file; |
|---|
| 69 | step; |
|---|
| 70 | if ((file = conf_push_config(cur_conf, yytext, &yylloc))) { |
|---|
| 71 | yypush_buffer_state(yy_create_buffer(file, |
|---|
| 72 | YY_BUF_SIZE)); |
|---|
| 73 | yylloc.first_line = yylloc.last_line = 0; |
|---|
| 74 | yylloc.first_column = yylloc.last_column = 0; |
|---|
| 75 | } |
|---|
| 76 | BEGIN(INITIAL); |
|---|
| 77 | } |
|---|
| 78 | <<EOF>> { |
|---|
| 79 | yypop_buffer_state(); |
|---|
| 80 | conf_pop_config(cur_conf, &yylloc); |
|---|
| 81 | if (YY_CURRENT_BUFFER) { |
|---|
| 82 | BEGIN(postinc); |
|---|
| 83 | } |
|---|
| 84 | else { |
|---|
| 85 | yyterminate(); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | <postinc>\n { step_nl; BEGIN(INITIAL); } |
|---|
| 89 | |
|---|
| 90 | #[^\n]* { step; } |
|---|
| 91 | <*>{BLANK} { step; } |
|---|
| 92 | [-\.=~] { step; return *yytext; } |
|---|
| 93 | \n { step_nl; return '\n'; } |
|---|
| 94 | |
|---|
| 95 | {WM}Rumble { step; return WM_RUMBLE; } |
|---|
| 96 | |
|---|
| 97 | {WM}Up { step; yylval.Int = CONF_WM_BTN_UP; return WM_BTN; } |
|---|
| 98 | {WM}Down { step; yylval.Int = CONF_WM_BTN_DOWN; return WM_BTN; } |
|---|
| 99 | {WM}Left { step; yylval.Int = CONF_WM_BTN_LEFT; return WM_BTN; } |
|---|
| 100 | {WM}Right { step; yylval.Int = CONF_WM_BTN_RIGHT; return WM_BTN; } |
|---|
| 101 | {WM}A { step; yylval.Int = CONF_WM_BTN_A; return WM_BTN; } |
|---|
| 102 | {WM}B { step; yylval.Int = CONF_WM_BTN_B; return WM_BTN; } |
|---|
| 103 | {WM}Minus { step; yylval.Int = CONF_WM_BTN_MINUS; return WM_BTN; } |
|---|
| 104 | {WM}Plus { step; yylval.Int = CONF_WM_BTN_PLUS; return WM_BTN; } |
|---|
| 105 | {WM}Home { step; yylval.Int = CONF_WM_BTN_HOME; return WM_BTN; } |
|---|
| 106 | {WM}1 { step; yylval.Int = CONF_WM_BTN_1; return WM_BTN; } |
|---|
| 107 | {WM}2 { step; yylval.Int = CONF_WM_BTN_2; return WM_BTN; } |
|---|
| 108 | |
|---|
| 109 | {NC}C { step; yylval.Int = CONF_NC_BTN_C; return NC_BTN; } |
|---|
| 110 | {NC}Z { step; yylval.Int = CONF_NC_BTN_Z; return NC_BTN; } |
|---|
| 111 | |
|---|
| 112 | {CC}Up { step; yylval.Int = CONF_CC_BTN_UP; return CC_BTN; } |
|---|
| 113 | {CC}Down { step; yylval.Int = CONF_CC_BTN_DOWN; return CC_BTN; } |
|---|
| 114 | {CC}Left { step; yylval.Int = CONF_CC_BTN_LEFT; return CC_BTN; } |
|---|
| 115 | {CC}Right { step; yylval.Int = CONF_CC_BTN_RIGHT; return CC_BTN; } |
|---|
| 116 | {CC}Minus { step; yylval.Int = CONF_CC_BTN_MINUS; return CC_BTN; } |
|---|
| 117 | {CC}Plus { step; yylval.Int = CONF_CC_BTN_PLUS; return CC_BTN; } |
|---|
| 118 | {CC}Home { step; yylval.Int = CONF_CC_BTN_HOME; return CC_BTN; } |
|---|
| 119 | {CC}A { step; yylval.Int = CONF_CC_BTN_A; return CC_BTN; } |
|---|
| 120 | {CC}B { step; yylval.Int = CONF_CC_BTN_B; return CC_BTN; } |
|---|
| 121 | {CC}X { step; yylval.Int = CONF_CC_BTN_X; return CC_BTN; } |
|---|
| 122 | {CC}Y { step; yylval.Int = CONF_CC_BTN_Y; return CC_BTN; } |
|---|
| 123 | {CC}ZL { step; yylval.Int = CONF_CC_BTN_ZL; return CC_BTN; } |
|---|
| 124 | {CC}ZR { step; yylval.Int = CONF_CC_BTN_ZR; return CC_BTN; } |
|---|
| 125 | {CC}L { step; yylval.Int = CONF_CC_BTN_L; return CC_BTN; } |
|---|
| 126 | {CC}R { step; yylval.Int = CONF_CC_BTN_R; return CC_BTN; } |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | {WM}Dpad\.X { step; yylval.Int = CONF_WM_AXIS_DPAD_X; return AXIS; } |
|---|
| 130 | {WM}Dpad\.Y { step; yylval.Int = CONF_WM_AXIS_DPAD_Y; return AXIS; } |
|---|
| 131 | |
|---|
| 132 | {NC}Stick\.X { step; yylval.Int = CONF_NC_AXIS_STICK_X; return AXIS; } |
|---|
| 133 | {NC}Stick\.Y { step; yylval.Int = CONF_NC_AXIS_STICK_Y; return AXIS; } |
|---|
| 134 | |
|---|
| 135 | {CC}Dpad\.X { step; yylval.Int = CONF_CC_AXIS_DPAD_X; return AXIS; } |
|---|
| 136 | {CC}Dpad\.Y { step; yylval.Int = CONF_CC_AXIS_DPAD_Y; return AXIS; } |
|---|
| 137 | {CC}LStick\.X { step; yylval.Int = CONF_CC_AXIS_L_STICK_X;return AXIS; } |
|---|
| 138 | {CC}LStick\.Y { step; yylval.Int = CONF_CC_AXIS_L_STICK_Y;return AXIS; } |
|---|
| 139 | {CC}RStick\.X { step; yylval.Int = CONF_CC_AXIS_R_STICK_X;return AXIS; } |
|---|
| 140 | {CC}RStick\.Y { step; yylval.Int = CONF_CC_AXIS_R_STICK_Y;return AXIS; } |
|---|
| 141 | {CC}LAnalog { step; yylval.Int = CONF_CC_AXIS_L; return AXIS; } |
|---|
| 142 | {CC}RAnalog { step; yylval.Int = CONF_CC_AXIS_R; return AXIS; } |
|---|
| 143 | |
|---|
| 144 | {PLUGIN} { step; return PLUGIN; } |
|---|
| 145 | |
|---|
| 146 | On { step; yylval.Int = -1; return ON_OFF; } |
|---|
| 147 | Off { step; yylval.Int = 0; return ON_OFF; } |
|---|
| 148 | |
|---|
| 149 | {INT} { step; yylval.Int = atoi(yytext); return INT; } |
|---|
| 150 | {FLOAT} { step; yylval.Float = atof(yytext); return FLOAT; } |
|---|
| 151 | |
|---|
| 152 | {ACTION} { |
|---|
| 153 | step; |
|---|
| 154 | yylval.Int = lookup_action(yytext); |
|---|
| 155 | if (yylval.Int == -1) { |
|---|
| 156 | wminput_err("unknown identifier %s", |
|---|
| 157 | yytext); |
|---|
| 158 | } |
|---|
| 159 | else { |
|---|
| 160 | switch (*yytext) { |
|---|
| 161 | case 'K': |
|---|
| 162 | case 'B': |
|---|
| 163 | return BTN_ACTION; |
|---|
| 164 | break; |
|---|
| 165 | case 'A': |
|---|
| 166 | return ABS_AXIS_ACTION; |
|---|
| 167 | break; |
|---|
| 168 | case 'R': |
|---|
| 169 | return REL_AXIS_ACTION; |
|---|
| 170 | break; |
|---|
| 171 | } |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | {ID} { |
|---|
| 176 | step; |
|---|
| 177 | yylval.String = malloc(strlen(yytext) + 1); |
|---|
| 178 | if (!yylval.String) { |
|---|
| 179 | wminput_err("error on malloc"); |
|---|
| 180 | } |
|---|
| 181 | else { |
|---|
| 182 | strcpy(yylval.String, yytext); |
|---|
| 183 | return ID; |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | . { step; wminput_err("unexpected character %c", *yytext); } |
|---|
| 188 | %% |
|---|
| 189 | |
|---|
| 190 | int yywrap() |
|---|
| 191 | { |
|---|
| 192 | return -1; |
|---|
| 193 | } |
|---|