| 2464 | } |
| 2465 | |
| 2466 | int loadInputSettingsFromFile(const char *filename) |
| 2467 | { |
| 2468 | QDir dir; |
| 2469 | std::string path; |
| 2470 | const char *baseDir = FCEUI_GetBaseDirectory(); |
| 2471 | char base[512], line[256]; |
| 2472 | char id[128], val[128]; |
| 2473 | int i, j; |
| 2474 | |
| 2475 | path = std::string(baseDir) + "/input/presets/"; |
| 2476 | |
| 2477 | dir.mkpath(QString::fromStdString(path)); |
| 2478 | |
| 2479 | if (filename != NULL) |
| 2480 | { |
| 2481 | getFileBaseName(filename, base, NULL); |
| 2482 | |
| 2483 | path += std::string(base) + ".pre"; |
| 2484 | } |
| 2485 | else |
| 2486 | { |
| 2487 | const char *romFile = getRomFile(); |
| 2488 | |
| 2489 | if (romFile == NULL) |
| 2490 | { |
| 2491 | return -1; |
| 2492 | } |
| 2493 | getFileBaseName(romFile, base, NULL); |
| 2494 | |
| 2495 | path += std::string(base) + ".pre"; |
| 2496 | } |
| 2497 | |
| 2498 | FILE *fp = fopen(path.c_str(), "r"); |
| 2499 | |
| 2500 | if (fp == NULL) |
| 2501 | { |
| 2502 | return -1; |
| 2503 | } |
| 2504 | |
| 2505 | while (fgets(line, sizeof(line) - 1, fp) != 0) |
| 2506 | { |
| 2507 | i = 0; |
| 2508 | while (line[i] != 0) |
| 2509 | { |
| 2510 | if (line[i] == '#') |
| 2511 | { |
| 2512 | line[i] = 0; |
| 2513 | break; |
| 2514 | } |
| 2515 | i++; |
| 2516 | } |
| 2517 | |
| 2518 | i = 0; |
| 2519 | while (isspace(line[i])) |
| 2520 | i++; |
| 2521 | |
| 2522 | j = 0; |
| 2523 | while (isalnum(line[i]) || (line[i] == '_')) |
no test coverage detected