mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 09:39:58 -04:00
cfg.c takes a value as written and logged nothing about it: "pace_smooth = 0 ; off" keeps the comment in the value and cfg_bool reads it as on, "fullscreen = false" is on too, and "sharpness = 250" is past 0..100 (the audit's probe on cfg.c printed exactly that, with 0 log lines during the load). A player who edits the file by hand had no way to see why a setting did not take. After cfg_load (and after migrate, so a value it rewrites is checked as read) each file value is checked against its row: a 0|1 switch with any other value, a value that is not a number in a lo..hi range, and a word that is none of a list of words, case aside. A list with a number in it is left alone: it is the menu's presets and its consumer takes more (fps_limit any rate from 30 to 240). A list of words is reported as "none of the menu's choices" only, since a consumer may take more (dlss_preset a..m). A value holding " ;" or " #" is noted on any row: the comment is part of it. cfg_init checks the environment's NX2NAVI_ values the same way. At most 16 lines a load, then a count. The values read are unchanged; reading words for off or cutting comments (F-8) needs approval. Not reproduced before the change by a game run; the new tests/cfg_parse_check.py builds cfg.c with stand-ins and checks each kind of line with its line number, the environment's, the cap of 16 and a count, and no line for a file whose values fit (including fps_limit 144, render_scale 300, dlss_preset k, pad_layout xbox_prompts). Every value nx2navi.ini.example shows passes without a line. launcher_test PlayerIniTest, the cfg rows check and the compile checks pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
2.5 KiB
C
75 lines
2.5 KiB
C
// runtime/cfg.c's reading of nx2navi.ini and the environment, with stand-ins for what cfg.c links against. Built and
|
|
// run by tests/cfg_parse_check.py: `cfg_parse_check <case> <ini>` loads the file the script wrote and prints every line
|
|
// cfg.c logged ("log: ...") and what the case reads back ("got: ...").
|
|
// load cfg_load on the file; then cfg_init's check of the environment (the variables the script set)
|
|
#include <stdarg.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "cfg.h"
|
|
#include "host.h"
|
|
#include "platform/platform.h"
|
|
|
|
void rt_log(const char *fmt, ...) {
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
printf("log: ");
|
|
vprintf(fmt, ap);
|
|
printf("\n");
|
|
va_end(ap);
|
|
}
|
|
void rt_fatal(const char *fmt, ...) {
|
|
va_list ap;
|
|
va_start(ap, fmt);
|
|
printf("FATAL: ");
|
|
vprintf(fmt, ap);
|
|
printf("\n");
|
|
va_end(ap);
|
|
exit(3);
|
|
}
|
|
const char *bugcap_replay_dir(void) { return NULL; }
|
|
void perf_size(PerfSizes *s, const char *name, uint64_t count, uint64_t limit, uint64_t bytes) {
|
|
(void)s, (void)name, (void)count, (void)limit, (void)bytes;
|
|
}
|
|
static const char *ini;
|
|
int plat_exe_path(char *out, size_t n) { (void)out, (void)n; return 0; }
|
|
int plat_file_exists(const char *p) {
|
|
FILE *f = fopen(p, "rb");
|
|
if (f) fclose(f);
|
|
return f != NULL;
|
|
}
|
|
uint8_t *plat_file_read(const char *path, uint64_t *size) {
|
|
FILE *f = fopen(path, "rb");
|
|
if (!f) return NULL;
|
|
fseek(f, 0, SEEK_END);
|
|
long n = ftell(f);
|
|
fseek(f, 0, SEEK_SET);
|
|
uint8_t *d = malloc((size_t)n + 1);
|
|
if (fread(d, 1, (size_t)n, f) != (size_t)n) n = 0;
|
|
d[n] = 0;
|
|
fclose(f);
|
|
*size = (uint64_t)n;
|
|
return d;
|
|
}
|
|
int64_t plat_file_size(const char *p) { (void)p; return -1; }
|
|
int plat_file_write_atomic(const char *p, const void *d, size_t n) { (void)p, (void)d, (void)n; return 1; }
|
|
void plat_mutex_lock(PlatMutex *m) { (void)m; }
|
|
void plat_mutex_unlock(PlatMutex *m) { (void)m; }
|
|
int plat_setenv(const char *n, const char *v) { (void)n, (void)v; return 1; }
|
|
|
|
int main(int argc, char **argv) {
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
|
if (argc < 3) return 2;
|
|
ini = argv[2];
|
|
if (!strcmp(argv[1], "load")) {
|
|
if (!cfg_load(ini)) return printf("cfg_load failed\n"), 2;
|
|
printf("got: pace_smooth '%s'\n", cfg_get("NX2NAVI_PACE_SMOOTH") ? cfg_get("NX2NAVI_PACE_SMOOTH") : "(unset)");
|
|
printf("--- environment\n");
|
|
cfg_init(); // finds no nx2navi.ini next to the stand-in exe; checks the environment's values
|
|
return 0;
|
|
}
|
|
return 2;
|
|
}
|