| 1 |
/* Copyright (C) 2007 L. Donnie Smith <wiimote@abstrakraft.org> |
|---|
| 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 |
* ChangeLog: |
|---|
| 18 |
* 2007-04-08 L. Donnie Smith <cwiid@abstrakraft.org> |
|---|
| 19 |
* * added param rules |
|---|
| 20 |
* |
|---|
| 21 |
* 2007-03-04 L. Donnie Smith <cwiid@abstrakraft.org> |
|---|
| 22 |
* * Initial ChangeLog |
|---|
| 23 |
*/ |
|---|
| 24 |
|
|---|
| 25 |
%{ |
|---|
| 26 |
#include <stdio.h> |
|---|
| 27 |
#include <stdlib.h> |
|---|
| 28 |
#include <string.h> |
|---|
| 29 |
#include "conf.h" |
|---|
| 30 |
#include "util.h" |
|---|
| 31 |
#include "y.tab.h" |
|---|
| 32 |
|
|---|
| 33 |
#define step \ |
|---|
| 34 |
do { \ |
|---|
| 35 |
yylloc.first_line = yylloc.last_line; \ |
|---|
| 36 |
yylloc.first_column = yylloc.last_column; \ |
|---|
| 37 |
yylloc.last_column += strlen(yytext); \ |
|---|
| 38 |
} while(0) |
|---|
| 39 |
|
|---|
| 40 |
#define step_nl \ |
|---|
| 41 |
do { \ |
|---|
| 42 |
yylloc.first_line = yylloc.last_line; \ |
|---|
| 43 |
yylloc.first_column = yylloc.last_column; \ |
|---|
| 44 |
yylloc.last_line++; \ |
|---|
| 45 |
yylloc.last_column = 0; \ |
|---|
| 46 |
} while (0) |
|---|
| 47 |
|
|---|
| 48 |
extern struct conf *cur_conf; |
|---|
| 49 |
%} |
|---|
| 50 |
|
|---|
| 51 |
WM Wiimote\. |
|---|
| 52 |
NC Nunchuk\. |
|---|
| 53 |
CC Classic\. |
|---|
| 54 |
PLUGIN Plugin\. |
|---|
| 55 |
ID [[:alnum:]_][[:alnum:]_-]* |
|---|
| 56 |
ACTION (KEY|BTN|ABS|REL)_[[:alnum:]_]+ |
|---|
| 57 |
FILENAME [[:alnum:]_.-]+ |
|---|
| 58 |
INT [0-9]+ |
|---|
| 59 |
FLOAT [0-9]+(\.[0-9]*)?([eE][+/-]?[0-9]+)? |
|---|
| 60 |
BLANK [[:blank:]]+ |
|---|
| 61 |
|
|---|
| 62 |
%option nounput |
|---|
| 63 |
%x inc postinc |
|---|
| 64 |
%% |
|---|
| 65 |
\ninclude { |
|---|
| 66 |
yylloc.first_line = yylloc.last_line; |
|---|
| 67 |
yylloc.first_column = yylloc.last_column; |
|---|
| 68 |
yylloc.last_line++; |
|---|
| 69 |
yylloc.last_column = strlen(yytext) -1; |
|---|
| 70 |
BEGIN(inc); |
|---|
| 71 |
} |
|---|
| 72 |
<inc>{BLANK} { step; } |
|---|
| 73 |
<inc>{FILENAME} { |
|---|
| 74 |
FILE *file; |
|---|
| 75 |
step; |
|---|
| 76 |
if ((file = conf_push_config(cur_conf, yytext, &yylloc))) { |
|---|
| 77 |
yypush_buffer_state(yy_create_buffer(file, |
|---|
| 78 |
YY_BUF_SIZE)); |
|---|
| 79 |
yylloc.first_line = yylloc.last_line = 0; |
|---|
| 80 |
yylloc.first_column = yylloc.last_column = 0; |
|---|
| 81 |
} |
|---|
| 82 |
BEGIN(INITIAL); |
|---|
| 83 |
} |
|---|
| 84 |
<<EOF>> { |
|---|
| 85 |
yypop_buffer_state(); |
|---|
| 86 |
conf_pop_config(cur_conf, &yylloc); |
|---|
| 87 |
if (YY_CURRENT_BUFFER) { |
|---|
| 88 |
BEGIN(postinc); |
|---|
| 89 |
} |
|---|
| 90 |
else { |
|---|
| 91 |
yyterminate(); |
|---|
| 92 |
} |
|---|
| 93 |
} |
|---|
| 94 |
<postinc>\n { step_nl; BEGIN(INITIAL); } |
|---|
| 95 |
|
|---|
| 96 |
#[^\n]* { step; } |
|---|
| 97 |
<*>{BLANK} { step; } |
|---|
| 98 |
[-\.=~] { step; return *yytext; } |
|---|
| 99 |
\n { step_nl; return '\n'; } |
|---|
| 100 |
|
|---|
| 101 |
{WM}Rumble { step; return WM_RUMBLE; } |
|---|
| 102 |
|
|---|
| 103 |
{WM}Up { step; yylval.Int = CONF_WM_BTN_UP; return WM_BTN; } |
|---|
| 104 |
{WM}Down { step; yylval.Int = CONF_WM_BTN_DOWN; return WM_BTN; } |
|---|
| 105 |
{WM}Left { step; yylval.Int = CONF_WM_BTN_LEFT; return WM_BTN; } |
|---|
| 106 |
{WM}Right { step; yylval.Int = CONF_WM_BTN_RIGHT; return WM_BTN; } |
|---|
| 107 |
{WM}A { step; yylval.Int = CONF_WM_BTN_A; return WM_BTN; } |
|---|
| 108 |
{WM}B { step; yylval.Int = CONF_WM_BTN_B; return WM_BTN; } |
|---|
| 109 |
{WM}Minus { step; yylval.Int = CONF_WM_BTN_MINUS; return WM_BTN; } |
|---|
| 110 |
{WM}Plus { step; yylval.Int = CONF_WM_BTN_PLUS; return WM_BTN; } |
|---|
| 111 |
{WM}Home { step; yylval.Int = CONF_WM_BTN_HOME; return WM_BTN; } |
|---|
| 112 |
{WM}1 { step; yylval.Int = CONF_WM_BTN_1; return WM_BTN; } |
|---|
| 113 |
{WM}2 { step; yylval.Int = CONF_WM_BTN_2; return WM_BTN; } |
|---|
| 114 |
|
|---|
| 115 |
{NC}C { step; yylval.Int = CONF_NC_BTN_C; return NC_BTN; } |
|---|
| 116 |
{NC}Z { step; yylval.Int = CONF_NC_BTN_Z; return NC_BTN; } |
|---|
| 117 |
|
|---|
| 118 |
{CC}Up { step; yylval.Int = CONF_CC_BTN_UP; return CC_BTN; } |
|---|
| 119 |
{CC}Down { step; yylval.Int = CONF_CC_BTN_DOWN; return CC_BTN; } |
|---|
| 120 |
{CC}Left { step; yylval.Int = CONF_CC_BTN_LEFT; return CC_BTN; } |
|---|
| 121 |
{CC}Right { step; yylval.Int = CONF_CC_BTN_RIGHT; return CC_BTN; } |
|---|
| 122 |
{CC}Minus { step; yylval.Int = CONF_CC_BTN_MINUS; return CC_BTN; } |
|---|
| 123 |
{CC}Plus { step; yylval.Int = CONF_CC_BTN_PLUS; return CC_BTN; } |
|---|
| 124 |
{CC}Home { step; yylval.Int = CONF_CC_BTN_HOME; return CC_BTN; } |
|---|
| 125 |
{CC}A { step; yylval.Int = CONF_CC_BTN_A; return CC_BTN; } |
|---|
| 126 |
{CC}B { step; yylval.Int = CONF_CC_BTN_B; return CC_BTN; } |
|---|
| 127 |
{CC}X { step; yylval.Int = CONF_CC_BTN_X; return CC_BTN; } |
|---|
| 128 |
{CC}Y { step; yylval.Int = CONF_CC_BTN_Y; return CC_BTN; } |
|---|
| 129 |
{CC}ZL { step; yylval.Int = CONF_CC_BTN_ZL; return CC_BTN; } |
|---|
| 130 |
{CC}ZR { step; yylval.Int = CONF_CC_BTN_ZR; return CC_BTN; } |
|---|
| 131 |
{CC}L { step; yylval.Int = CONF_CC_BTN_L; return CC_BTN; } |
|---|
| 132 |
{CC}R { step; yylval.Int = CONF_CC_BTN_R; return CC_BTN; } |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
{WM}Dpad\.X { step; yylval.Int = CONF_WM_AXIS_DPAD_X; return AXIS; } |
|---|
| 136 |
{WM}Dpad\.Y { step; yylval.Int = CONF_WM_AXIS_DPAD_Y; return AXIS; } |
|---|
| 137 |
|
|---|
| 138 |
{NC}Stick\.X { step; yylval.Int = CONF_NC_AXIS_STICK_X; return AXIS; } |
|---|
| 139 |
{NC}Stick\.Y { step; yylval.Int = CONF_NC_AXIS_STICK_Y; return AXIS; } |
|---|
| 140 |
|
|---|
| 141 |
{CC}Dpad\.X { step; yylval.Int = CONF_CC_AXIS_DPAD_X; return AXIS; } |
|---|
| 142 |
{CC}Dpad\.Y { step; yylval.Int = CONF_CC_AXIS_DPAD_Y; return AXIS; } |
|---|
| 143 |
{CC}LStick\.X { step; yylval.Int = CONF_CC_AXIS_L_STICK_X;return AXIS; } |
|---|
| 144 |
{CC}LStick\.Y { step; yylval.Int = CONF_CC_AXIS_L_STICK_Y;return AXIS; } |
|---|
| 145 |
{CC}RStick\.X { step; yylval.Int = CONF_CC_AXIS_R_STICK_X;return AXIS; } |
|---|
| 146 |
{CC}RStick\.Y { step; yylval.Int = CONF_CC_AXIS_R_STICK_Y;return AXIS; } |
|---|
| 147 |
{CC}LAnalog { step; yylval.Int = CONF_CC_AXIS_L; return AXIS; } |
|---|
| 148 |
{CC}RAnalog { step; yylval.Int = CONF_CC_AXIS_R; return AXIS; } |
|---|
| 149 |
|
|---|
| 150 |
{PLUGIN} { step; return PLUGIN; } |
|---|
| 151 |
|
|---|
| 152 |
On { step; yylval.Int = -1; return ON_OFF; } |
|---|
| 153 |
Off { step; yylval.Int = 0; return ON_OFF; } |
|---|
| 154 |
|
|---|
| 155 |
{INT} { step; yylval.Int = atoi(yytext); return INT; } |
|---|
| 156 |
{FLOAT} { step; yylval.Float = atof(yytext); return FLOAT; } |
|---|
| 157 |
|
|---|
| 158 |
{ACTION} { |
|---|
| 159 |
step; |
|---|
| 160 |
yylval.Int = lookup_action(yytext); |
|---|
| 161 |
if (yylval.Int == -1) { |
|---|
| 162 |
wminput_err("unknown identifier %s", |
|---|
| 163 |
yytext); |
|---|
| 164 |
} |
|---|
| 165 |
else { |
|---|
| 166 |
switch (*yytext) { |
|---|
| 167 |
case 'K': |
|---|
| 168 |
case 'B': |
|---|
| 169 |
return BTN_ACTION; |
|---|
| 170 |
break; |
|---|
| 171 |
case 'A': |
|---|
| 172 |
return ABS_AXIS_ACTION; |
|---|
| 173 |
break; |
|---|
| 174 |
case 'R': |
|---|
| 175 |
return REL_AXIS_ACTION; |
|---|
| 176 |
break; |
|---|
| 177 |
} |
|---|
| 178 |
} |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
{ID} { |
|---|
| 182 |
step; |
|---|
| 183 |
yylval.String = malloc(strlen(yytext) + 1); |
|---|
| 184 |
if (!yylval.String) { |
|---|
| 185 |
wminput_err("error on malloc"); |
|---|
| 186 |
} |
|---|
| 187 |
else { |
|---|
| 188 |
strcpy(yylval.String, yytext); |
|---|
| 189 |
return ID; |
|---|
| 190 |
} |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
. { step; wminput_err("unexpected character %c", *yytext); } |
|---|
| 194 |
%% |
|---|
| 195 |
|
|---|
| 196 |
int yywrap() |
|---|
| 197 |
{ |
|---|
| 198 |
return -1; |
|---|
| 199 |
} |
|---|
| 200 |
|
|---|