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 const char* configDir = "configs/";
39 const char* testFile = "test.cfg";
41 /// ***** Public Methods *****
43 void readConfigs(inputMap* map)
47 strcpy(fileName, configDir);
48 strcat(fileName, testFile);
50 ifstream file(fileName);
54 cerr << "Unable to open file " << fileName << "." << endl;
66 processLine(line, map);
72 /// ***** Private Methods *****
74 void processLine(const string& str, inputMap* map)
81 extracted = extractLine(str, &name, &value);
85 //map->insert(name, value);
87 cout << value << endl;
92 * Return true iff the string str, had a name and value extracted and saved in
93 * name and value. Otherwise return false and leave name and value alone.
95 bool extractLine(const string& str, string* name, string* value)
98 * state := 0 if eating leading name whitespace
100 * := 2 if eating trailing name whitespace
101 * := 3 if eating leading value whitespace
102 * := 4 if saving value
103 * := 5 if all is done and well
115 const char* c_str = str.c_str();
119 if(c_str[char_pos] == 0 && state != 4)
125 if(c_str[char_pos] != ' '
126 && c_str[char_pos] != '\t')
129 name_start = char_pos;
133 if(c_str[char_pos] == ' '
134 || c_str[char_pos] == '\t'
135 || c_str[char_pos] == '=')
141 if(c_str[char_pos] == '=')
142 char_pos--; // decrement to stay on this char
145 if(c_str[char_pos] != ' '
146 && c_str[char_pos] != '\t'
147 && c_str[char_pos] != '=')
152 if(c_str[char_pos] == '=')
158 if(c_str[char_pos] != ' '
159 && c_str[char_pos] != '\t')
162 value_start = char_pos;
166 if(c_str[char_pos] == ' '
167 || c_str[char_pos] == '\t'
168 || c_str[char_pos] == 0)
171 value_end = char_pos;
185 name->replace(0, 0, c_str, name_start, name_end-name_start);
186 value->replace(0, 0, c_str, value_start, value_end-value_start);
191 bool extractKey(const string& str, Uint8* key)
193 // if(str.length() != 1)
201 // add all the letters
202 for (int i = 'A'; i <= 'Z'; i++) // uppercase
203 keyMap["" + (char)i] = (SDLKey)i;
204 for (int i = 'a'; i <= 'z'; i++) // lowercase
205 keyMap["" + (char)i] = (SDLKey)i;
207 // add all the numbers
208 for (int i = '0'; i <= '9'; i++)
209 keyMap["" + (char)i] = (SDLKey)i;
212 // add the function keys
213 int F1 = (int)Key.F1;
214 for (int i = F1; i <= (int)Key.F15; i++)
216 keyMap.Add("F" + (i - F1 + 1), (Key)i);
217 keyMap.Add("f" + (i - F1 + 1), (Key)i);
221 keyMap["LCtrl"] = SDLK_LCTRL;
222 keyMap["LeftControl"] = SDLK_LCTRL;
223 keyMap["LAlt"] = SDLK_LALT;
224 keyMap["LeftAlt"] = SDLK_LALT;
225 keyMap["LShift"] = SDLK_LSHIFT;
226 keyMap["LeftShift"] = SDLK_LSHIFT;
227 keyMap["LWin"] = SDLK_LSUPER;
228 keyMap["LeftWindows"] = SDLK_LSUPER;
229 keyMap["LeftMeta"] = SDLK_LMETA;
230 keyMap["LMeta"] = SDLK_LMETA;
232 keyMap["RCtrl"] = SDLK_RCTRL;
233 keyMap["RightControl"] = SDLK_RCTRL;
234 keyMap["RAlt"] = SDLK_RALT;
235 keyMap["RightAlt"] = SDLK_RALT;
236 keyMap["RShift"] = SDLK_RSHIFT;
237 keyMap["RightShift"] = SDLK_RSHIFT;
238 keyMap["RWin"] = SDLK_RSUPER;
239 keyMap["RightWindows"] = SDLK_RSUPER;
240 keyMap["RightMeta"] = SDLK_RMETA;
241 keyMap["RMeta"] = SDLK_RMETA;
243 keyMap["Esc"] = SDLK_ESCAPE;
244 keyMap["Escape"] = SDLK_ESCAPE;
246 keyMap["Return"] = SDLK_RETURN;
247 keyMap["Enter"] = SDLK_RETURN;
249 keyMap["Insert"] = SDLK_INSERT;
250 keyMap["Home"] = SDLK_HOME;
251 keyMap["Delete"] = SDLK_DELETE;
252 keyMap["End"] = SDLK_END;
253 keyMap["PageUp"] = SDLK_PAGEUP;
254 keyMap["PageDown"] = SDLK_PAGEDOWN;
256 keyMap["Minus"] = SDLK_MINUS;
257 keyMap["Equal"] = SDLK_EQUALS;
258 keyMap["Equals"] = SDLK_EQUALS;
259 keyMap["LeftBracket"] = SDLK_LEFTBRACKET;
260 keyMap["LBracket"] = SDLK_LEFTBRACKET;
261 keyMap["RightBracket"] = SDLK_RIGHTBRACKET;
262 keyMap["RBracket"] = SDLK_RIGHTBRACKET;
263 keyMap["Backslash"] = SDLK_BACKSLASH;
264 keyMap["Slash"] = SDLK_SLASH;
265 keyMap["Semicolon"] = SDLK_SEMICOLON;
266 keyMap["Semi"] = SDLK_SEMICOLON;
267 keyMap["Quote"] = SDLK_QUOTE;
268 keyMap["Comma"] = SDLK_COMMA;
269 keyMap["Period"] = SDLK_PERIOD;
270 keyMap["Space"] = SDLK_SPACE;
271 keyMap["BSpace"] = SDLK_BACKSPACE;
272 keyMap["Backspace"] = SDLK_BACKSPACE;
273 keyMap["BackSpace"] = SDLK_BACKSPACE;
275 keyMap["Tab"] = SDLK_TAB;
276 keyMap["BackQuote"] = SDLK_BACKQUOTE;
277 keyMap["BQuote"] = SDLK_BACKQUOTE;
278 keyMap["CapsLock"] = SDLK_CAPSLOCK;
279 keyMap["Caps"] = SDLK_CAPSLOCK;
281 keyMap["Up"] = SDLK_UP;
282 keyMap["Down"] = SDLK_DOWN;
283 keyMap["Left"] = SDLK_LEFT;
284 keyMap["Right"] = SDLK_RIGHT;