2 * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 typedef std::map<string,SDLKey> kMap;
31 /// ***** Private Method Headers *****
33 void processLine(const string& str, inputMap* map);
34 bool extractLine(const string& str, string* name, string* value);
36 /// ***** Private Variables *****
38 char* configDir = "../configs/";
40 /// ***** Public Methods *****
42 void readConfigs(inputMap* map)
46 strcpy(fileName, configDir);
47 strcat(fileName, "test.cfg");
49 ifstream file(fileName);
53 cerr << "Unable to open file " << fileName << "." << endl;
65 processLine(line, map);
71 /// ***** Private Methods *****
73 void processLine(const string& str, inputMap* map)
80 extracted = extractLine(str, &name, &value);
84 //map->insert(name, value);
86 cout << value << endl;
91 * Return true iff the string str, had a name and value extracted and saved in
92 * name and value. Otherwise return false and leave name and value alone.
94 bool extractLine(const string& str, string* name, string* value)
97 * state := 0 if eating leading name whitespace
99 * := 2 if eating trailing name whitespace
100 * := 3 if eating leading value whitespace
101 * := 4 if saving value
102 * := 5 if all is done and well
114 const char* c_str = str.c_str();
118 if(c_str[char_pos] == 0 && state != 4)
124 if(c_str[char_pos] != ' '
125 && c_str[char_pos] != '\t')
128 name_start = char_pos;
132 if(c_str[char_pos] == ' '
133 || c_str[char_pos] == '\t'
134 || c_str[char_pos] == '=')
140 if(c_str[char_pos] == '=')
141 char_pos--; // decrement to stay on this char
144 if(c_str[char_pos] == '=')
147 if(c_str[char_pos] != ' '
148 && c_str[char_pos] != '\t')
154 if(c_str[char_pos] != ' '
155 && c_str[char_pos] != '\t')
158 value_start = char_pos;
162 if(c_str[char_pos] == ' '
163 || c_str[char_pos] == '\t'
164 || c_str[char_pos] == 0)
167 value_end = char_pos;
181 name->replace(0, 0, c_str, name_start, name_end-name_start);
182 value->replace(0, 0, c_str, value_start, value_end-value_start);
187 bool extractKey(const string& str, Uint8* key)
189 // if(str.length() != 1)
197 // add all the letters
198 for (int i = 'A'; i <= 'Z'; i++) // uppercase
199 keyMap["" + (char)i] = (SDLKey)i;
200 for (int i = 'a'; i <= 'z'; i++) // lowercase
201 keyMap["" + (char)i] = (SDLKey)i;
203 // add all the numbers
204 for (int i = '0'; i <= '9'; i++)
205 keyMap["" + (char)i] = (SDLKey)i;
208 // add the function keys
209 int F1 = (int)Key.F1;
210 for (int i = F1; i <= (int)Key.F15; i++)
212 keyMap.Add("F" + (i - F1 + 1), (Key)i);
213 keyMap.Add("f" + (i - F1 + 1), (Key)i);
217 keyMap["LCtrl"] = SDLK_LCTRL;
218 keyMap["LeftControl"] = SDLK_LCTRL;
219 keyMap["LAlt"] = SDLK_LALT;
220 keyMap["LeftAlt"] = SDLK_LALT;
221 keyMap["LShift"] = SDLK_LSHIFT;
222 keyMap["LeftShift"] = SDLK_LSHIFT;
223 keyMap["LWin"] = SDLK_LSUPER;
224 keyMap["LeftWindows"] = SDLK_LSUPER;
225 keyMap["LeftMeta"] = SDLK_LMETA;
226 keyMap["LMeta"] = SDLK_LMETA;
228 keyMap["RCtrl"] = SDLK_RCTRL;
229 keyMap["RightControl"] = SDLK_RCTRL;
230 keyMap["RAlt"] = SDLK_RALT;
231 keyMap["RightAlt"] = SDLK_RALT;
232 keyMap["RShift"] = SDLK_RSHIFT;
233 keyMap["RightShift"] = SDLK_RSHIFT;
234 keyMap["RWin"] = SDLK_RSUPER;
235 keyMap["RightWindows"] = SDLK_RSUPER;
236 keyMap["RightMeta"] = SDLK_RMETA;
237 keyMap["RMeta"] = SDLK_RMETA;
239 keyMap["Esc"] = SDLK_ESCAPE;
240 keyMap["Escape"] = SDLK_ESCAPE;
242 keyMap["Return"] = SDLK_RETURN;
243 keyMap["Enter"] = SDLK_RETURN;
245 keyMap["Insert"] = SDLK_INSERT;
246 keyMap["Home"] = SDLK_HOME;
247 keyMap["Delete"] = SDLK_DELETE;
248 keyMap["End"] = SDLK_END;
249 keyMap["PageUp"] = SDLK_PAGEUP;
250 keyMap["PageDown"] = SDLK_PAGEDOWN;
252 keyMap["Minus"] = SDLK_MINUS;
253 keyMap["Equal"] = SDLK_EQUALS;
254 keyMap["Equals"] = SDLK_EQUALS;
255 keyMap["LeftBracket"] = SDLK_LEFTBRACKET;
256 keyMap["LBracket"] = SDLK_LEFTBRACKET;
257 keyMap["RightBracket"] = SDLK_RIGHTBRACKET;
258 keyMap["RBracket"] = SDLK_RIGHTBRACKET;
259 keyMap["Backslash"] = SDLK_BACKSLASH;
260 keyMap["Slash"] = SDLK_SLASH;
261 keyMap["Semicolon"] = SDLK_SEMICOLON;
262 keyMap["Semi"] = SDLK_SEMICOLON;
263 keyMap["Quote"] = SDLK_QUOTE;
264 keyMap["Comma"] = SDLK_COMMA;
265 keyMap["Period"] = SDLK_PERIOD;
266 keyMap["Space"] = SDLK_SPACE;
267 keyMap["BSpace"] = SDLK_BACKSPACE;
268 keyMap["Backspace"] = SDLK_BACKSPACE;
269 keyMap["BackSpace"] = SDLK_BACKSPACE;
271 keyMap["Tab"] = SDLK_TAB;
272 keyMap["BackQuote"] = SDLK_BACKQUOTE;
273 keyMap["BQuote"] = SDLK_BACKQUOTE;
274 keyMap["CapsLock"] = SDLK_CAPSLOCK;
275 keyMap["Caps"] = SDLK_CAPSLOCK;
277 keyMap["Up"] = SDLK_UP;
278 keyMap["Down"] = SDLK_DOWN;
279 keyMap["Left"] = SDLK_LEFT;
280 keyMap["Right"] = SDLK_RIGHT;