| 193 | //========================================================================================================== |
| 194 | |
| 195 | void load_profile() { |
| 196 | color_ostream_proxy out(Core::getInstance().getConsole()); |
| 197 | FILE* infile = fopen(profile_file_name, "r"); |
| 198 | size_t civ = 0; |
| 199 | |
| 200 | if (!infile) { |
| 201 | out.printerr("No profile file found at {}\n", profile_file_name); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | fields i = first_fields; |
| 206 | char line[80]; |
| 207 | int count = 80; |
| 208 | bool found; |
| 209 | |
| 210 | while (true) { |
| 211 | if (!fgets(line, count, infile) || line[0] != '[') { |
| 212 | out.printerr("Failed to find token start '[' at line {}\n", static_cast<int8_t>(i)); |
| 213 | fclose(infile); |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | for (int k = 1; k < count; k++) { |
| 218 | if (line[k] == ':') { |
| 219 | for (int l = 1; l < k; l++) { |
| 220 | if (state->finder_list[static_cast<int8_t>(i) + civ].text.c_str()[l - 1] != line[l]) { |
| 221 | out.printerr("Token mismatch of {} vs {}\n", line, state->finder_list[static_cast<int8_t>(i) + civ].text.c_str()); |
| 222 | fclose(infile); |
| 223 | return; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | found = false; |
| 228 | |
| 229 | for (size_t l = 0; l < state->plotinfo[static_cast<int8_t>(i) + civ]->list.size(); l++) { |
| 230 | for (int m = k + 1; m < count; m++) { |
| 231 | if (state->plotinfo[static_cast<int8_t>(i) + civ]->list[l].text.c_str()[m - (k + 1)] != line[m]) { |
| 232 | if (state->plotinfo[static_cast<int8_t>(i) + civ]->list[l].text.c_str()[m - (k + 1)] == '\0' && |
| 233 | line[m] == ']') { |
| 234 | found = true; |
| 235 | } |
| 236 | break; |
| 237 | } |
| 238 | } |
| 239 | if (found) { |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | if (!found) { |
| 245 | out.printerr("Value extraction failure from {}\n", line); |
| 246 | fclose(infile); |
| 247 | return; |
| 248 | } |
| 249 | |
| 250 | break; |
| 251 | } |
| 252 | } |