Parses the supplied config file and turns it into a map object. * NOTE: Does not work with certain filepath shortcuts (e.g. ~ as user's home) */
| 136 | * NOTE: Does not work with certain filepath shortcuts (e.g. ~ as user's home) |
| 137 | */ |
| 138 | map<int, int> KeyConfig::parseConfigFile(string filepath) |
| 139 | { |
| 140 | ifstream config_file(filepath.c_str()); |
| 141 | map<int,int> keymap; |
| 142 | string line; |
| 143 | |
| 144 | while(getline(config_file, line)) |
| 145 | { |
| 146 | string str_action = getActionFromString(line); |
| 147 | string key = getKeyFromString(line); |
| 148 | |
| 149 | if(str_action != "" && key != "" && str_action[0] != '#') |
| 150 | { |
| 151 | int key_action = convertStringToAction(str_action); |
| 152 | if(key.substr(0,4) == "left") |
| 153 | { |
| 154 | keymap[KEY_LEFT] = key_action; |
| 155 | } |
| 156 | else if(key.substr(0,5) == "right") |
| 157 | { |
| 158 | keymap[KEY_RIGHT] = key_action; |
| 159 | } |
| 160 | else if(key.substr(0,2) == "up") |
| 161 | { |
| 162 | keymap[KEY_UP] = key_action; |
| 163 | } |
| 164 | else if(key.substr(0,4) == "down") |
| 165 | { |
| 166 | keymap[KEY_DOWN] = key_action; |
| 167 | } |
| 168 | else if(key.substr(0,3) == "esc") |
| 169 | { |
| 170 | keymap[KEY_ESC] = key_action; |
| 171 | } |
| 172 | else if(key.substr(0,3) == "hex") |
| 173 | { |
| 174 | const char *hex = key.substr(4).c_str(); |
| 175 | if (hex) |
| 176 | keymap[strtoul(hex,0,0)] = key_action; |
| 177 | } |
| 178 | else keymap[key[0]] = key_action; |
| 179 | } |
| 180 | } |
| 181 | return keymap; |
| 182 | } |
nothing calls this directly
no test coverage detected