mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-18 17:29:57 -04:00
Read a comment after a setting's value, and off, false and no for a switch, as players mean them in nx2navi.ini.
A hand-edited "pace_smooth = 0 ; off" kept the comment in the value, which the readers took as on, "fps_limit = 144 #
monitor" gave 60, and "fullscreen = false" or "rtss = off" were on, since every reader took anything but "0" as on;
the log only named these lines (the check added for F-7). Now, for a key whose row has a set of values, cfg_load cuts
an unquoted value at the first blank followed by ';' or '#' after the '=' ("key = ; note" is unset) and logs the line
once; free text keeps its whole value (window_size, monitor, audio_device and keys without a row such as mods_dir,
pipeline_cache and the bindings, where a path or name may hold " #"), as do a value in double quotes and the
environment's values. A switch (a row whose set is 0|1) written as false, off or no reads as 0 and as true, on or yes
as 1 through cfg_get itself, so every reader agrees (cfg_bool, rt_knob, the readers that compare with "0" or parse a
number); cfg_bool and rt_knob also take those words for keys of other rows, and rt_knob no longer logs them. F-7's
check now names a switch value only when it is none of those, and a comment kept in a value only where it stays
(free text, the environment). The launcher's reader (launcher/gameini.py) cuts the same way for keys the caller
says have a set of values; its mods keys stay free text. The menu's save still writes a changed key's line again
without its comment.
This changes what existing files with such lines do, which is what was approved. tests/cfg_parse_check.py,
tests/rt_knob_check.py and launcher_test PlayerIniTest cover the cut, the words, free text, quotes and the
environment, and pass; cfg_rows_check reports 0 problems; the runtime compile check and the -Wall comparison of cfg.c
and perf.c show no new warnings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -984,10 +984,11 @@ int rt_ab(void) {
|
||||
return k == 1 || k == 2;
|
||||
}
|
||||
|
||||
// rt_knob reads "0" as off, "ab" as the A/B blocks and anything else as on, so "off", "false" or "0 ; a note" turn a
|
||||
// switch on. A value other than 0, 1 and ab is logged once per switch; the names are string literals, so the table
|
||||
// holds their pointers (a full table logs no more). The value is still read as on: taking such words as off would
|
||||
// change what a written setting does.
|
||||
// rt_knob reads "0", false, off and no (any case) as off, "ab" as the A/B blocks, and anything else as on, as cfg.c
|
||||
// cfg_bool does; nx2navi.ini's loader has already cut a comment after a value of a key whose row has a set of
|
||||
// values ("0 ; a note", cfg.c cut_comment). A value other than 0, 1, ab and those words (true, on and yes for on) is
|
||||
// logged once per switch; the names are string literals, so the table holds their pointers (a full table logs no
|
||||
// more).
|
||||
#define KNOB_WARNED 32
|
||||
static const char *knob_warned[KNOB_WARNED];
|
||||
|
||||
@@ -995,7 +996,7 @@ static void knob_warn(const char *name, const char *key, const char *value) {
|
||||
for (int i = 0; i < KNOB_WARNED; i++) {
|
||||
const char *cur = __atomic_load_n(&knob_warned[i], __ATOMIC_ACQUIRE);
|
||||
if (!cur && __atomic_compare_exchange_n(&knob_warned[i], &cur, name, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) {
|
||||
rt_log("cfg: %s = '%s' is not 0, 1 or ab: read as 1", key, value);
|
||||
rt_log("cfg: %s = '%s' is not 0, 1, ab, on, off, true, false, yes or no: read as 1", key, value);
|
||||
return;
|
||||
}
|
||||
if (cur == name) return; // logged already (another thread may have taken this slot for it just now)
|
||||
@@ -1008,6 +1009,9 @@ int rt_knob(const char *name, const char *def) {
|
||||
const char *e = cfg_get(key);
|
||||
if (!e || !*e) e = def;
|
||||
if (!strcmp(e, "ab")) return 2;
|
||||
static const char *const word[] = {"false", "off", "no", "true", "on", "yes"};
|
||||
for (int i = 0; i < 6; i++)
|
||||
if (!strcasecmp(e, word[i])) return i >= 3;
|
||||
if (strcmp(e, "0") && strcmp(e, "1")) knob_warn(name, key, e);
|
||||
return strcmp(e, "0") != 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user