37 tok/s from Qwen3-Next-80B (48 GB) on a 32 GB laptop, 24 without drafts vs 2.8 for llama.cpp; reading 62 vs 16 tok/s. Faster than llama.cpp on all 13 models compared in Q4_K_M. LLMs bigger than your RAM, pure C, CPU or GPU.
C avx2ccpu-inferenceggufinference-enginelinuxllmlocal-llmmixture-of-expertsmoenvmequantizationqwen3simdspeculative-decodingvulkan
Release 2026-10-03: strict settings - a word not known is refused with the nearest
camauri9339c27582b3
diff --git a/ChangeLog.md b/ChangeLog.mdindex a1ab0be..9687284 100644--- a/ChangeLog.md+++ b/ChangeLog.md@@ -2,6 +2,13 @@> Curated, user-facing summary of completed work, newest first.+## [2026-10-03] - Strict settings++- **A word not known is refused, with the one nearest to it.** `janas-chat` (command line and `chat.conf`), `janas-server`, `janas-mcp` and `janas-bench` refuse an option mistyped ("--tmep is not an option (did you mean --temp?)") and a value that is not one: numbers are read whole and within their limits (`--ctx 32k` was 32 tokens, `--temp 0,7` was 0, `--port 70000` wrapped), choices are one of theirs (`--think of` turned reasoning on, `--mode ecco` was auto). `janas-bench` left an unknown option and a last one without its value aside, and measured something else than asked. The chat's file said "a word it does not know" without saying which, and went on.+- **mcp.json**: a key a letter or two from one Janas reads (`arg`, `evn`) is refused with the one meant, `disabled` must be `true` or `false`; the keys of the other clients are left to them.+- **The services' settings files** (`flights.conf`, `prices.conf`): a line naming no setting is told at the start and in the answer that says the key is missing; `aviationstack_key_old = ...` is no longer read as the key.+- **The variables of the environment**: a `JANAS_` one Janas does not read is told when a program starts, with the name meant; `tests/test_words.c` checks the table of names against every one the sources read.+## [2026-10-03] - The services' pages beside their code- **src/services/README.md** sums up the services and links each one's page, now `src/services/<service>/README.md` beside its code (they were in `docs/services/`); the main README links the summary.diff --git a/README.md b/README.mdindex 2614d4d..58aaf8e 100644--- a/README.md+++ b/README.md@@ -282,7 +282,7 @@ In the chat, a line starting with `/` is a command, and it turns grey-blue as so`/help` and `/about` open a page over the conversation: the text is laid out to the window however narrow it is, the arrows and **Page Up** and **Page Down** move in it, and **ESC** closes it - no other key does, so a page cannot be shut by the one you pressed looking for a way down. `/about` gives the version, the author, the licence and the repository, and then the model, the machine and the engine as they are at that moment: the three things a report of a problem needs, which were until now to be gathered by hand.-What a command changes lasts for that conversation and no longer: a knob turned to try something does not quietly become the way things are. `/save-config` writes the settings to `~/.config/janas/chat.conf` and `/load-config` reads them back, losing whatever is set at the time, which it asks about first, and `/del-config` throws the file away so that the next start uses the chat's own settings again. The file holds the words of the command line, one option to a line and the rest of the line its value, so the same reader takes both and you can open it and edit it; it is read before the command line, which therefore wins. The system message is not kept in it, and the context, the cache, the bits and the attention are read at the next start, since they are settled when the model is opened.+What a command changes lasts for that conversation and no longer: a knob turned to try something does not quietly become the way things are. `/save-config` writes the settings to `~/.config/janas/chat.conf` and `/load-config` reads them back, losing whatever is set at the time, which it asks about first, and `/del-config` throws the file away so that the next start uses the chat's own settings again. The file holds the words of the command line, one option to a line and the rest of the line its value, so the same reader takes both and you can open it and edit it; it is read before the command line, which therefore wins. The system message is not kept in it, and the context, the cache, the bits and the attention are read at the next start, since they are settled when the model is opened. A word the chat does not know is refused, on the command line and in the file alike, with the option nearest to it: `--tmep` ("did you mean --temp?"), a value that is not one - `--ctx 32k`, `--temp 0,7`, `--think of`, `--mode ecco` - rather than taken for something else. `janas-server`, `janas-mcp` and `janas-bench` do the same with theirs, and each program tells at its start a variable of the environment named like Janas's and not one of them (`JANAS_EXPERT_BIT` for `JANAS_EXPERT_BITS`), which would otherwise do nothing in silence.A model marks its replies up - `**bold**`, `*italic*`, backticks, fenced blocks, headings, bullets - and the chat reads those marks rather than printing them: bold is bold, a block of code is told from the prose by its colour, a dash becomes a bullet. An underscore counts as italic only alone and at the edge of a word, so `_this_` and `**_this_**` are marks while `snake_case` and `__init__`, which a conversation about code is full of, stay as they are; a star inside a word is not a mark either, so `2*3` is a product. `--no-markdown` and `/markdown off` print the marks as they come, and a pipe always gets them: a script may want them.@@ -318,7 +318,7 @@ The chat also starts the [Model Context Protocol](https://modelcontextprotocol.i"/home/me/notes"]}}}```-Their tools are given to the model as `server__tool`. When the model calls one, the chat shows the call with its arguments and waits for a key: `y` runs it, `n` tells the model it was not allowed, `a` runs it and every later call of the same tool. `/mcp` lists the servers and their tools; `/mcp auto`, or `--mcp-auto` at the start, runs the calls without asking - which a pipe needs, since nobody is there to answer, and without which a piped chat runs none. `--no-mcp` starts no server. A tool runs with your rights, and what it answers is text somebody else wrote that the model then reads: configure only servers you trust, and read the calls before saying yes. For the same reason the instructions a server gives for its tools stay out of the model's system message unless `--mcp-instructions` asks for them; then they follow it, marked as the servers' and not the user's.+A key a letter or two from one of those Janas reads (`arg` for `args`, `evn` for `env`) is refused with the one meant, and `disabled` is `true` or `false`, not the text "true"; the keys of the other clients (`autoApprove`, `cwd`, `envFile`...) are left to them. Their tools are given to the model as `server__tool`. When the model calls one, the chat shows the call with its arguments and waits for a key: `y` runs it, `n` tells the model it was not allowed, `a` runs it and every later call of the same tool. `/mcp` lists the servers and their tools; `/mcp auto`, or `--mcp-auto` at the start, runs the calls without asking - which a pipe needs, since nobody is there to answer, and without which a piped chat runs none. `--no-mcp` starts no server. A tool runs with your rights, and what it answers is text somebody else wrote that the model then reads: configure only servers you trust, and read the calls before saying yes. For the same reason the instructions a server gives for its tools stay out of the model's system message unless `--mcp-instructions` asks for them; then they follow it, marked as the servers' and not the user's.Servers are spoken to over their standard input and output (the stdio transport), in either era of the protocol: the stateless revision 2026-07-28, and the handshake of 2025-11-25 and before, which most servers still speak; which one a server speaks is found out when it starts. What a server writes to its standard error goes to `~/.cache/janas/mcp/<name>.log`. A server that listens at an address is named with `url` (and `headers`, for an `Authorization` say) instead of `command`, and spoken to over Streamable HTTP, again in either era; `https://` too, the server's certificate checked against the system's certificate authorities (or `SSL_CERT_FILE`) and its name. It has been run against the test server in [`tests/mcp_fake_server.c`](tests/mcp_fake_server.c), in both eras, over stdio and over HTTP, and against two reference servers over stdio, both of the 2025-11-25 era: `@modelcontextprotocol/server-filesystem` 0.2.0 (npx, 14 tools) and `mcp-server-git` 1.30.0 (uvx, 12 tools), together, with Qwen3-4B choosing among their 26 tools - `git_log` for the last commit of a repository, `list_directory` then `read_text_file` to find a date in a folder. Their descriptions take about 3,700 tokens of the system message, read once and kept computed. Over HTTPS it has reached DeepWiki (`https://mcp.deepwiki.com/mcp`, 2025-11-25 era, a session per client). A small model does not always find its way: asked without a hint, Qwen3-4B tried to read the folder itself as a file, got the server's error, and stopped there.diff --git a/build.sh b/build.shindex 3f65c5b..c36cf70 100755--- a/build.sh+++ b/build.sh@@ -339,7 +339,8 @@ if [ "$VARIANT" = release ]; then*/common_hf_*.o) ;; # for the tools, with libjanas.a only# what the services share (src/services/common/): theirs only*/services_*.o) ;;- */llm_json.o) mcp_objs+=("$o") llm_objs+=("$o") ;;+ # the JSON reader and the strict reading of words: both+ */llm_json.o | */common_words.o) mcp_objs+=("$o") llm_objs+=("$o") ;;*) llm_objs+=("$o") ;;esacdonediff --git a/src/bench/main.c b/src/bench/main.cindex 734944f..9197ab6 100644--- a/src/bench/main.c+++ b/src/bench/main.c@@ -30,7 +30,9 @@#include <sys/utsname.h>#include <time.h>+#include "common/env_names.h"#include "common/sysinfo.h"+#include "common/words.h"#include "janas/llm.h"#include "llm/api_internal.h"#include "llm/expert_cache.h"@@ -173,6 +175,7 @@ static int measure_chat(janas_llm *llm, uint32_t n_gen, int sampled,int main(int argc, char **argv){+ janas_env_check("janas-bench");if (argc < 2 || argv[1][0] == '-') {fprintf(stderr, "usage: janas-bench <model.jns> [--mtp <file>] ""[--prompt <tokens>] [--gen <tokens>] [--ctx <tokens>] "@@ -185,21 +188,43 @@ int main(int argc, char **argv)p.n_ctx = 4096;uint32_t n_prompt = 256, n_gen = 64;int rounds = 3;- for (int i = 2; i + 1 < argc; i += 2) {- if (strcmp(argv[i], "--mtp") == 0)- p.mtp_path = argv[i + 1];- else if (strcmp(argv[i], "--prompt") == 0)- n_prompt = (uint32_t)atoi(argv[i + 1]);- else if (strcmp(argv[i], "--gen") == 0)- n_gen = (uint32_t)atoi(argv[i + 1]);- else if (strcmp(argv[i], "--ctx") == 0)- p.n_ctx = (uint32_t)atoi(argv[i + 1]);- else if (strcmp(argv[i], "--rounds") == 0)- rounds = atoi(argv[i + 1]) > 0 ? atoi(argv[i + 1]) : 1;- else if (strcmp(argv[i], "--cache") == 0)- p.cache_bytes = (uint64_t)(atof(argv[i + 1]) * (1 << 30));- else if (strcmp(argv[i], "--reserve") == 0)- p.reserve_bytes = (uint64_t)(atof(argv[i + 1]) * (1 << 30));+ static const char *const options[] = {"--mtp", "--prompt", "--gen",+ "--ctx", "--rounds", "--cache",+ "--reserve"};+ for (int i = 2; i < argc; i += 2) {+ const char *a = argv[i], *v = i + 1 < argc ? argv[i + 1] : NULL;+ char why[200] = "";+ long long x = 0;+ double r = 0;+ if (strcmp(a, "--mtp") == 0 && v)+ p.mtp_path = v;+ else if (strcmp(a, "--prompt") == 0 || strcmp(a, "--gen") == 0 ||+ strcmp(a, "--ctx") == 0 || strcmp(a, "--rounds") == 0) {+ if (janas_word_int(v, 1, UINT32_MAX, &x, why, sizeof why) == 0) {+ if (a[2] == 'p')+ n_prompt = (uint32_t)x;+ else if (a[2] == 'g')+ n_gen = (uint32_t)x;+ else if (a[2] == 'c')+ p.n_ctx = (uint32_t)x;+ else+ rounds = x < 1000 ? (int)x : 1000;+ }+ } else if (strcmp(a, "--cache") == 0 || strcmp(a, "--reserve") == 0) {+ if (janas_word_real(v, 0, 1 << 20, &r, why, sizeof why) == 0)+ *(a[2] == 'c' ? &p.cache_bytes : &p.reserve_bytes) =+ (uint64_t)(r * (1 << 30));+ } else {+ janas_unknown_word(why, sizeof why, a, "an option", options,+ sizeof options / sizeof *options);+ fprintf(stderr, "janas-bench: %s\n", why);+ return 2;+ }+ if (why[0] || !v) {+ fprintf(stderr, "janas-bench: %s: %s\n", a,+ why[0] ? why : "a value is missing");+ return 2;+ }}if (n_prompt < 2 || n_gen < 1 || n_prompt + 2 * n_gen + 64 > p.n_ctx) {fprintf(stderr, "janas-bench: prompt and generation must fit the "diff --git a/src/chat/main.c b/src/chat/main.cindex 3faa9bd..54d13a4 100644--- a/src/chat/main.c+++ b/src/chat/main.c@@ -29,7 +29,9 @@#include <time.h>#include <unistd.h>+#include "common/env_names.h"#include "common/sysinfo.h"+#include "common/words.h"#include "edit.h"#include "layout.h"#include "janas/llm.h"@@ -799,10 +801,66 @@ struct chat_opts { /* where the words land: main keeps them, this names them */int *all_tools;};-static int take_options(int n, char **w, struct chat_opts *o)+/* every option, for the nearest to one mistyped: the first twelve stand+ alone, the others take a value */+static const char *const OPTIONS[] = {+ "--no-spec", "--stats", "--no-markdown", "--no-gpu",+ "--no-preload", "--no-recap", "--no-mtp", "--no-mcp",+ "--no-services", "--all-tools", "--mcp-auto", "--mcp-instructions",+ "--mtp", "--draft", "--think", "--mode",+ "--ctx", "--cache", "--reserve", "--bits",+ "--attention", "--system", "--mcp-config", "--progress",+ "--temp", "--top-k", "--top-p", "--min-p",+ "--seed", "--max"};+#define N_OPTIONS (sizeof OPTIONS / sizeof *OPTIONS)++/* v of option a as a whole number or a number within limits; on a+ mistake, the reason into why and -1 */+static int opt_int(const char *a, const char *v, long long lo, long long hi,+ long long *x, char *why, size_t why_len)+{+ char r[160];+ if (janas_word_int(v, lo, hi, x, r, sizeof r) == 0)+ return 0;+ snprintf(why, why_len, "%s: %s", a, r);+ return -1;+}++static int opt_real(const char *a, const char *v, double lo, double hi,+ double *x, char *why, size_t why_len)+{+ char r[160];+ if (janas_word_real(v, lo, hi, x, r, sizeof r) == 0)+ return 0;+ snprintf(why, why_len, "%s: %s", a, r);+ return -1;+}++static int opt_choice(const char *a, const char *v, const char *const *names,+ size_t n, char *why, size_t why_len)+{+ char r[300];+ int k = janas_word_choice(v, names, n, r, sizeof r);+ if (k < 0)+ snprintf(why, why_len, "%s: %s", a, r);+ return k;+}++/* The words of a command line or of the settings file. 0, or -1 with what+ was wrong in why: an option not known (with the nearest), a value that+ is not one. */+static int take_options(int n, char **w, struct chat_opts *o, char *why,+ size_t why_len){+ static const char *const ON_OFF[] = {"off", "on"};+ static const char *const MODES[] = {"auto", "eco", "max"};+ static const char *const ATTN[] = {"auto", "exact", "fast"};+ static const char *const BITS[] = {"2", "4", "6"};for (int i = 0; i < n; i++) {const char *a = w[i], *v = i + 1 < n ? w[i + 1] : NULL;+ long long x;+ double r;+ int k;if (strcmp(a, "--no-spec") == 0) {o->cp->speculate = 0;continue;@@ -851,7 +909,16 @@ static int take_options(int n, char **w, struct chat_opts *o)*o->mcp_instructions = 1;continue;}+ int valued = 0;+ for (size_t j = 12; j < N_OPTIONS && !valued; j++)+ valued = strcmp(a, OPTIONS[j]) == 0;+ if (!valued) {+ janas_unknown_word(why, why_len, a, "an option", OPTIONS,+ N_OPTIONS);+ return -1;+ }if (!v) {+ snprintf(why, why_len, "%s wants a value", a);return -1;}i++;@@ -859,44 +926,70 @@ static int take_options(int n, char **w, struct chat_opts *o)o->mp->mtp_path = v;else if (strcmp(a, "--draft") == 0)o->mp->draft_path = v;- else if (strcmp(a, "--think") == 0)- o->cp->thinking = strcmp(v, "off") == 0 ? 0 : 1;- else if (strcmp(a, "--mode") == 0)- o->mp->mode = strcmp(v, "eco") == 0 ? JANAS_LLM_MODE_ECO- : strcmp(v, "max") == 0 ? JANAS_LLM_MODE_MAX- : JANAS_LLM_MODE_AUTO;- else if (strcmp(a, "--ctx") == 0)- o->mp->n_ctx = (uint32_t)atol(v);- else if (strcmp(a, "--cache") == 0)- o->mp->cache_bytes = (uint64_t)(atof(v) * (1 << 30));- else if (strcmp(a, "--reserve") == 0)- o->mp->reserve_bytes = (uint64_t)(atof(v) * (1 << 30));- else if (strcmp(a, "--bits") == 0)- o->mp->expert_bits = atoi(v);- else if (strcmp(a, "--attention") == 0)- o->mp->attn_scores = strcmp(v, "exact") == 0 ? JANAS_LLM_ATTN_EXACT- : strcmp(v, "fast") == 0 ? JANAS_LLM_ATTN_FAST- : JANAS_LLM_ATTN_AUTO;- else if (strcmp(a, "--system") == 0)+ else if (strcmp(a, "--think") == 0) {+ if ((k = opt_choice(a, v, ON_OFF, 2, why, why_len)) < 0)+ return -1;+ o->cp->thinking = k;+ } else if (strcmp(a, "--mode") == 0) {+ if ((k = opt_choice(a, v, MODES, 3, why, why_len)) < 0)+ return -1;+ o->mp->mode = k == 1 ? JANAS_LLM_MODE_ECO+ : k == 2 ? JANAS_LLM_MODE_MAX+ : JANAS_LLM_MODE_AUTO;+ } else if (strcmp(a, "--ctx") == 0) {+ if (opt_int(a, v, 0, UINT32_MAX, &x, why, why_len) != 0)+ return -1;+ o->mp->n_ctx = (uint32_t)x;+ } else if (strcmp(a, "--cache") == 0) {+ if (opt_real(a, v, 0, 1 << 20, &r, why, why_len) != 0)+ return -1;+ o->mp->cache_bytes = (uint64_t)(r * (1 << 30));+ } else if (strcmp(a, "--reserve") == 0) {+ if (opt_real(a, v, 0, 1 << 20, &r, why, why_len) != 0)+ return -1;+ o->mp->reserve_bytes = (uint64_t)(r * (1 << 30));+ } else if (strcmp(a, "--bits") == 0) {+ if ((k = opt_choice(a, v, BITS, 3, why, why_len)) < 0)+ return -1;+ o->mp->expert_bits = 2 + 2 * k;+ } else if (strcmp(a, "--attention") == 0) {+ if ((k = opt_choice(a, v, ATTN, 3, why, why_len)) < 0)+ return -1;+ o->mp->attn_scores = k == 1 ? JANAS_LLM_ATTN_EXACT+ : k == 2 ? JANAS_LLM_ATTN_FAST+ : JANAS_LLM_ATTN_AUTO;+ } else if (strcmp(a, "--system") == 0)*o->system_arg = v;else if (strcmp(a, "--mcp-config") == 0)*o->mcp_config = v;- else if (strcmp(a, "--progress") == 0)+ else if (strcmp(a, "--progress") == 0) {+ if (opt_real(a, v, 0, 86400, &r, why, why_len) != 0)+ return -1;setenv("JANAS_PROGRESS", v, 1);- else if (strcmp(a, "--temp") == 0)- o->cp->temperature = (float)atof(v);- else if (strcmp(a, "--top-k") == 0)- o->cp->top_k = atoi(v);- else if (strcmp(a, "--top-p") == 0)- o->cp->top_p = (float)atof(v);- else if (strcmp(a, "--min-p") == 0)- o->cp->min_p = (float)atof(v);- else if (strcmp(a, "--seed") == 0)- o->cp->seed = strtoull(v, NULL, 10);- else if (strcmp(a, "--max") == 0)- o->cp->max_reply = atoi(v);- else {- return -1;+ } else if (strcmp(a, "--temp") == 0) {+ if (opt_real(a, v, 0, 100, &r, why, why_len) != 0)+ return -1;+ o->cp->temperature = (float)r;+ } else if (strcmp(a, "--top-k") == 0) {+ if (opt_int(a, v, 0, INT32_MAX, &x, why, why_len) != 0)+ return -1;+ o->cp->top_k = (int32_t)x;+ } else if (strcmp(a, "--top-p") == 0) {+ if (opt_real(a, v, 0, 1, &r, why, why_len) != 0)+ return -1;+ o->cp->top_p = (float)r;+ } else if (strcmp(a, "--min-p") == 0) {+ if (opt_real(a, v, 0, 1, &r, why, why_len) != 0)+ return -1;+ o->cp->min_p = (float)r;+ } else if (strcmp(a, "--seed") == 0) {+ if (opt_int(a, v, 0, LLONG_MAX, &x, why, why_len) != 0)+ return -1;+ o->cp->seed = (uint64_t)x;+ } else if (strcmp(a, "--max") == 0) {+ if (opt_int(a, v, 0, INT32_MAX, &x, why, why_len) != 0)+ return -1;+ o->cp->max_reply = (int32_t)x;}}return 0;@@ -1397,6 +1490,7 @@ static int show_reply(const janas_llm *llm, janas_llm_chat *c, int markdown,int main(int argc, char **argv){+ janas_env_check("janas-chat");/* wcwidth() answers for the locale's character set, and in the C localeit answers -1 to everything past ASCII: ask for the user's own */setlocale(LC_CTYPE, "");@@ -1439,14 +1533,21 @@ int main(int argc, char **argv)int cn = 0;char **cw = conf_read(cpath, &cn, &conf_text);if (cw) {- if (take_options(cn, cw, &o) != 0)- fprintf(stderr, "janas-chat: %s has a word it does not know\n",- cpath);+ char why[400];+ int bad = take_options(cn, cw, &o, why, sizeof why) != 0;free(cw);+ if (bad) {+ fprintf(stderr, "janas-chat: %s: %s\n", cpath, why);+ free(conf_text);+ return 2;+ }}}- if (take_options(argc - 2, argv + 2, &o) != 0) {- usage();+ char why[400];+ if (take_options(argc - 2, argv + 2, &o, why, sizeof why) != 0) {+ fprintf(stderr, "janas-chat: %s\n", why);+ fprintf(stderr, "janas-chat --help lists the options\n");+ free(conf_text);return 2;}@@ -1614,8 +1715,9 @@ int main(int argc, char **argv)term_printf(&term, "no %s to read\n", cpath);free(text);} else {- if (take_options(cn, cw, &o) != 0)- term_printf(&term, "a word in it is not known\n");+ char bad[400];+ if (take_options(cn, cw, &o, bad, sizeof bad) != 0)+ term_printf(&term, "%s: %s\n", cpath, bad);free(cw);free(conf_text); /* the older words are let go */conf_text = text;diff --git a/src/common/env_names.c b/src/common/env_names.cnew file mode 100644index 0000000..fd8ee94--- /dev/null+++ b/src/common/env_names.c@@ -0,0 +1,107 @@+/* SPDX-License-Identifier: GPL-3.0-or-later+ Copyright (C) 2026 Maurizio Cammalleri */+/*+ * env_names.c - the variables of the environment Janas reads (see+ * env_names.h).+ */+#include "common/env_names.h"++#include <stdio.h>+#include <string.h>++#include "common/words.h"++extern char **environ;++const char *const JANAS_ENV_NAMES[] = {"JANAS_ALPHAVANTAGE_KEY",+ "JANAS_API_KEY",+ "JANAS_ARENA_HUGE",+ "JANAS_ATTN",+ "JANAS_ATTN_SKIPSTAT",+ "JANAS_AVIATIONSTACK_KEY",+ "JANAS_BLOCK_THREADS",+ "JANAS_DRAFT_VOCAB",+ "JANAS_EXPERT_BITS",+ "JANAS_EXPERTS",+ "JANAS_EXPTRACE",+ "JANAS_FLIGHTS_CONFIG",+ "JANAS_GPU",+ "JANAS_GPU_ALLOC",+ "JANAS_GPU_ALWAYS",+ "JANAS_GPU_ATT_SG",+ "JANAS_GPU_BLOCK",+ "JANAS_GPU_BLOCKWAIT",+ "JANAS_GPU_COPY",+ "JANAS_GPU_DEVICE",+ "JANAS_GPU_EXPERTS",+ "JANAS_GPU_FULL_N",+ "JANAS_GPU_KEEPALIVE_US",+ "JANAS_GPU_MIN_N",+ "JANAS_GPU_NO_ROW",+ "JANAS_GPU_NOSPIN",+ "JANAS_GPU_REPACK",+ "JANAS_GPU_ROW_NV",+ "JANAS_GPU_SG",+ "JANAS_GPU_TOKEN",+ "JANAS_GPU_TOKEN_PROFILE",+ "JANAS_GPU_VERBOSE",+ "JANAS_GPU_XCOH",+ "JANAS_KERNELS",+ "JANAS_KV",+ "JANAS_LOCATION",+ "JANAS_METRICS",+ "JANAS_METRICS_EVERY",+ "JANAS_NOMINATIM_URL",+ "JANAS_OSRM_URL",+ "JANAS_OVERPASS_URL",+ "JANAS_OVERPASS_URL2",+ "JANAS_PHOTON_URL",+ "JANAS_POOLTRACE",+ "JANAS_PREFETCH",+ "JANAS_PREFILL_BLOCK",+ "JANAS_PROGRESS",+ "JANAS_SHA256_C",+ "JANAS_SWA_RING",+ "JANAS_TRACE",+ "JANAS_TRANSITOUS_URL",+ "JANAS_TUNE",+ "JANAS_TUNE_THREADS",+ "JANAS_URING",+ "JANAS_URING_BATCH",+ "JANAS_URING_DEEP",+ "JANAS_VALHALLA_URL",+ "JANAS_VMAP",+ "JANAS_WARM"};+const size_t JANAS_N_ENV_NAMES =+ sizeof JANAS_ENV_NAMES / sizeof *JANAS_ENV_NAMES;++/* read by Janas's own scripts, not by its programs */+static const char *const SCRIPTS[] = {"JANAS_MODELS"};++int janas_env_check(const char *prog)+{+ int n = 0;+ for (char **e = environ; e && *e; e++) {+ if (strncmp(*e, "JANAS_", 6) != 0)+ continue;+ char name[96];+ size_t k = strcspn(*e, "=");+ if (k >= sizeof name)+ k = sizeof name - 1;+ memcpy(name, *e, k);+ name[k] = 0;+ int known = 0;+ for (size_t i = 0; i < JANAS_N_ENV_NAMES && !known; i++)+ known = strcmp(name, JANAS_ENV_NAMES[i]) == 0;+ for (size_t i = 0; i < sizeof SCRIPTS / sizeof *SCRIPTS && !known; i++)+ known = strcmp(name, SCRIPTS[i]) == 0;+ if (known)+ continue;+ char why[240];+ janas_unknown_word(why, sizeof why, name, "a variable of Janas",+ JANAS_ENV_NAMES, JANAS_N_ENV_NAMES);+ fprintf(stderr, "%s: %s: it does nothing\n", prog, why);+ n++;+ }+ return n;+}diff --git a/src/common/env_names.h b/src/common/env_names.hnew file mode 100644index 0000000..6f3ee45--- /dev/null+++ b/src/common/env_names.h@@ -0,0 +1,25 @@+/* SPDX-License-Identifier: GPL-3.0-or-later+ Copyright (C) 2026 Maurizio Cammalleri */+/*+ * env_names.h - the variables of the environment Janas reads (env_names.c),+ * so that one set with a name Janas does not know - JANAS_EXPERT_BIT for+ * JANAS_EXPERT_BITS - is told when a program starts, instead of doing+ * nothing in silence. A warning, not a refusal: a variable may be meant for+ * another version of Janas.+ */+#ifndef JANAS_COMMON_ENV_NAMES_H+#define JANAS_COMMON_ENV_NAMES_H++#include <stddef.h>++/* every JANAS_ variable read, by the programs, the library or the+ services; tests/test_env_names.c checks it against the sources */+extern const char *const JANAS_ENV_NAMES[];+extern const size_t JANAS_N_ENV_NAMES;++/* On stderr, prefixed by prog, a line for each JANAS_ variable of the+ environment not among them, with the name nearest to it. The number of+ them. */+int janas_env_check(const char *prog);++#endifdiff --git a/src/common/mcp_config.c b/src/common/mcp_config.cindex d593c7a..32381c5 100644--- a/src/common/mcp_config.c+++ b/src/common/mcp_config.c@@ -10,6 +10,7 @@#include <stdlib.h>#include <string.h>+#include "common/words.h"#include "llm/json.h"#define CONFIG_MAX_BYTES ((size_t)4 << 20)@@ -51,6 +52,42 @@ static const char *plain(const struct janas_json *v)return s && strlen(s) == v->n ? s : NULL;}+/* the keys read here */+static const char *const KEYS[] = {"command", "args", "env", "url",+ "headers", "disabled", "type"};+/* keys of the other clients, left to them: not a mistyped one of ours */+static const char *const THEIRS[] = {+ "autoApprove", "alwaysAllow", "disabledTools", "enabledTools",+ "includeTools", "excludeTools", "timeout", "transport",+ "transportType", "cwd", "envFile", "headersHelper",+ "oauth", "description", "serverUrl", "trust",+ "dev", "name", "enabled", "tools"};++/* a key near one of ours and not another client's: a mistake to say */+static int mistyped(const struct janas_json *k, const char *server, char *err,+ size_t err_len)+{+ char key[64];+ if (k->key_n >= sizeof key || memchr(k->key, 0, k->key_n))+ return 0;+ memcpy(key, k->key, k->key_n);+ key[k->key_n] = 0;+ for (size_t i = 0; i < sizeof KEYS / sizeof *KEYS; i++)+ if (strcmp(key, KEYS[i]) == 0)+ return 0;+ for (size_t i = 0; i < sizeof THEIRS / sizeof *THEIRS; i++)+ if (strcmp(key, THEIRS[i]) == 0)+ return 0;+ const char *near = janas_closest(key, KEYS, sizeof KEYS / sizeof *KEYS);+ if (!near)+ return 0;+ snprintf(err, err_len,+ "server %s: \"%s\" is not a key (did you mean "+ "\"%s\"?)",+ server, key, near);+ return 1;+}+static int one(const struct janas_json *s, struct janas_mcp_conf *c, char *err,size_t err_len){@@ -60,7 +97,16 @@ static int one(const struct janas_json *s, struct janas_mcp_conf *c, char *err,return -1;}c->name = dup_n(s->key, s->key_n);+ if (!c->name)+ goto oom;+ for (const struct janas_json *k = s->child; k; k = k->next)+ if (mistyped(k, c->name, err, err_len))+ return -1;const struct janas_json *d = janas_json_get(s, "disabled");+ if (d && d->type != JANAS_JSON_TRUE && d->type != JANAS_JSON_FALSE) {+ snprintf(err, err_len, "server %s: disabled is true or false", c->name);+ return -1;+ }c->disabled = d && d->type == JANAS_JSON_TRUE;const struct janas_json *type = janas_json_get(s, "type");const struct janas_json *url = janas_json_get(s, "url");diff --git a/src/common/mcp_config.h b/src/common/mcp_config.hindex 2133916..040faed 100644--- a/src/common/mcp_config.h+++ b/src/common/mcp_config.h@@ -13,8 +13,11 @@* "headers": {"Authorization": "Bearer ..."}}}}** "servers" (VS Code's name) is read as well as "mcpServers"; "disabled":- * true leaves a server out; "type" may say "stdio", "http" or "sse". The- * default file is $XDG_CONFIG_HOME/janas/mcp.json, or ~/.config/janas/.+ * true leaves a server out; "type" may say "stdio", "http" or "sse". A key+ * a letter or two from one of these is refused as mistyped, with the one+ * meant; the keys of the other clients (autoApprove, cwd...) are left to+ * them. The default file is $XDG_CONFIG_HOME/janas/mcp.json, or+ * ~/.config/janas/.*/#ifndef JANAS_MCP_CONFIG_H#define JANAS_MCP_CONFIG_Hdiff --git a/src/common/words.c b/src/common/words.cnew file mode 100644index 0000000..63a9a08--- /dev/null+++ b/src/common/words.c@@ -0,0 +1,161 @@+/* SPDX-License-Identifier: GPL-3.0-or-later+ Copyright (C) 2026 Maurizio Cammalleri */+/*+ * words.c - the words a user gives a program, read strictly (see words.h).+ */+#include "common/words.h"++#include <ctype.h>+#include <errno.h>+#include <math.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>++#define LONGEST 64 /* longer words are compared by their start */++/* Damerau's distance (two letters swapped count one), case aside */+static int distance(const char *a, const char *b)+{+ size_t na = strlen(a), nb = strlen(b);+ if (na > LONGEST)+ na = LONGEST;+ if (nb > LONGEST)+ nb = LONGEST;+ int d[LONGEST + 1][LONGEST + 1]; /* 17 KB: on the stack, thread-safe */+ for (size_t i = 0; i <= na; i++)+ d[i][0] = (int)i;+ for (size_t j = 0; j <= nb; j++)+ d[0][j] = (int)j;+ for (size_t i = 1; i <= na; i++)+ for (size_t j = 1; j <= nb; j++) {+ int ca = tolower((unsigned char)a[i - 1]);+ int cb = tolower((unsigned char)b[j - 1]);+ int v = d[i - 1][j - 1] + (ca != cb);+ if (d[i - 1][j] + 1 < v)+ v = d[i - 1][j] + 1;+ if (d[i][j - 1] + 1 < v)+ v = d[i][j - 1] + 1;+ if (i > 1 && j > 1 && ca == tolower((unsigned char)b[j - 2]) &&+ tolower((unsigned char)a[i - 2]) == cb &&+ d[i - 2][j - 2] + 1 < v)+ v = d[i - 2][j - 2] + 1;+ d[i][j] = v;+ }+ return d[na][nb];+}++/* one the start of the other, the shorter of four letters or more */+static int starts(const char *a, const char *b)+{+ size_t na = strlen(a), nb = strlen(b), n = na < nb ? na : nb;+ if (n < 4 || na == nb)+ return 0;+ for (size_t i = 0; i < n; i++)+ if (tolower((unsigned char)a[i]) != tolower((unsigned char)b[i]))+ return 0;+ return 1;+}++const char *janas_closest(const char *w, const char *const *names, size_t n)+{+ if (!w || !*w)+ return NULL;+ size_t len = strlen(w);+ int most = len >= 12 ? 3 : len >= 6 ? 2 : 1;+ const char *best = NULL;+ int best_d = most + 1;+ for (size_t i = 0; i < n && names[i]; i++) {+ int d = distance(w, names[i]);+ if (d < best_d) {+ best_d = d;+ best = names[i];+ }+ }+ for (size_t i = 0; !best && i < n && names[i]; i++)+ if (starts(w, names[i]))+ best = names[i];+ return best;+}++void janas_unknown_word(char *buf, size_t cap, const char *w, const char *what,+ const char *const *names, size_t n)+{+ const char *near = janas_closest(w, names, n);+ if (near)+ snprintf(buf, cap, "%s is not %s (did you mean %s?)", w, what, near);+ else+ snprintf(buf, cap, "%s is not %s", w, what);+}++int janas_word_int(const char *v, long long lo, long long hi, long long *out,+ char *why, size_t why_len)+{+ char *end;+ errno = 0;+ long long x =+ v && *v && !isspace((unsigned char)*v) ? strtoll(v, &end, 10) : 0;+ if (!v || !*v || isspace((unsigned char)*v) || *end || errno) {+ if (v)+ snprintf(why, why_len, "%s is not a whole number", v);+ else+ snprintf(why, why_len, "a value is missing");+ return -1;+ }+ if (x < lo || x > hi) {+ snprintf(why, why_len, "%s is %s %lld", v, x < lo ? "below" : "above",+ x < lo ? lo : hi);+ return -1;+ }+ *out = x;+ return 0;+}++int janas_word_real(const char *v, double lo, double hi, double *out, char *why,+ size_t why_len)+{+ char *end;+ double x = v && *v && !isspace((unsigned char)*v) ? strtod(v, &end) : 0;+ if (!v || !*v || isspace((unsigned char)*v) || *end || !isfinite(x)) {+ if (v)+ snprintf(why, why_len, "%s is not a number", v);+ else+ snprintf(why, why_len, "a value is missing");+ return -1;+ }+ if (x < lo || x > hi) {+ snprintf(why, why_len, "%s is %s %g", v, x < lo ? "below" : "above",+ x < lo ? lo : hi);+ return -1;+ }+ *out = x;+ return 0;+}++int janas_word_choice(const char *v, const char *const *names, size_t n,+ char *why, size_t why_len)+{+ for (size_t i = 0; v && i < n && names[i]; i++)+ if (strcmp(v, names[i]) == 0)+ return (int)i;+ char list[256] = "";+ size_t k = 0;+ for (size_t i = 0; i < n && names[i] && k < sizeof list; i++) {+ int m = snprintf(list + k, sizeof list - k, "%s%s", i ? ", " : "",+ names[i]);+ if (m < 0)+ break;+ k += (size_t)m;+ }+ /* a word mistyped has a nearest; a number (3 for 2, 4 or 6) has not */+ int letters = 0;+ for (const char *c = v; c && *c && !letters; c++)+ letters = isalpha((unsigned char)*c);+ const char *near = letters ? janas_closest(v, names, n) : NULL;+ if (near)+ snprintf(why, why_len, "%s is not one of %s (did you mean %s?)",+ v ? v : "nothing", list, near);+ else+ snprintf(why, why_len, "%s is not one of %s", v ? v : "nothing", list);+ return -1;+}diff --git a/src/common/words.h b/src/common/words.hnew file mode 100644index 0000000..412769f--- /dev/null+++ b/src/common/words.h@@ -0,0 +1,37 @@+/* SPDX-License-Identifier: GPL-3.0-or-later+ Copyright (C) 2026 Maurizio Cammalleri */+/*+ * words.h - the words a user gives a program (options, their values, the+ * keys of a configuration, the names of variables), read strictly: a word+ * that is not known is refused with the known one nearest to it, a number+ * is read whole and within its limits, so that "--ctx 32k" is not taken+ * for 32 nor "--tmep" left aside in silence.+ */+#ifndef JANAS_COMMON_WORDS_H+#define JANAS_COMMON_WORDS_H++#include <stddef.h>++/* Of names[0..n) (NULL ends them early), the one nearest to w: a letter or+ two away (three for long names), two letters swapped, or one the start+ of the other; NULL when none is that near. Case does not count. */+const char *janas_closest(const char *w, const char *const *names, size_t n);++/* "w is not <what>", and " (did you mean X?)" when one of names is near:+ into buf, always ended. */+void janas_unknown_word(char *buf, size_t cap, const char *w, const char *what,+ const char *const *names, size_t n);++/* v read whole as a number within [lo, hi]: 0, or -1 with the reason in+ why ("32k is not a whole number", "70000 is above 65535"). */+int janas_word_int(const char *v, long long lo, long long hi, long long *out,+ char *why, size_t why_len);+int janas_word_real(const char *v, double lo, double hi, double *out, char *why,+ size_t why_len);++/* The index of v among names[0..n), or -1 with the reason in why (the+ choices, and the nearest). */+int janas_word_choice(const char *v, const char *const *names, size_t n,+ char *why, size_t why_len);++#endifdiff --git a/src/get/main.c b/src/get/main.cindex e1c98de..b8f413f 100644--- a/src/get/main.c+++ b/src/get/main.c@@ -20,6 +20,7 @@#include <sys/statvfs.h>#include "catalog.h"+#include "common/env_names.h"#include "common/sysinfo.h"#include "steps.h"@@ -201,6 +202,7 @@ static int from_hf(const char *spec, const char *dir, int keep)int main(int argc, char **argv){+ janas_env_check("janas-get");if (argc < 2) {usage();return 2;diff --git a/src/mcp/main.c b/src/mcp/main.cindex 9279f26..88bf0ad 100644--- a/src/mcp/main.c+++ b/src/mcp/main.c@@ -20,6 +20,8 @@#include <string.h>#include <unistd.h>+#include "common/env_names.h"+#include "common/words.h"#include "serve.h"#ifndef JANAS_VERSION@@ -84,6 +86,7 @@ static janas_llm *open_model(const char *path, const struct janas_llm_params *p,int main(int argc, char **argv){+ janas_env_check("janas-mcp");struct mcpd d = {.call_seconds = 600};struct janas_llm_params mp;janas_llm_params_default(&mp);@@ -97,31 +100,60 @@ int main(int argc, char **argv)model = a;continue;}- if (strcmp(a, "-h") == 0 || strcmp(a, "--help") == 0 || !v) {+ static const char *const options[] = {+ "--embedding-model", "--mtp", "--ctx", "--cache",+ "--reserve", "--temp", "--max", "--think",+ "--timeout", "--help"};+ if (strcmp(a, "-h") == 0 || strcmp(a, "--help") == 0) {usage();- return strcmp(a, "-h") == 0 || strcmp(a, "--help") == 0 ? 0 : 2;+ return 0;+ }+ char why[300] = "";+ long long x = 0;+ double r = 0;+ int known = 0;+ for (size_t k = 0; k + 1 < sizeof options / sizeof *options; k++)+ known |= strcmp(a, options[k]) == 0;+ if (!known)+ janas_unknown_word(why, sizeof why, a, "an option", options,+ sizeof options / sizeof *options);+ else if (!v)+ snprintf(why, sizeof why, "%s wants a value", a);+ if (why[0]) {+ fprintf(stderr, "janas-mcp: %s\n", why);+ return 2;}i++;if (strcmp(a, "--embedding-model") == 0)emb = v;else if (strcmp(a, "--mtp") == 0)mp.mtp_path = v;- else if (strcmp(a, "--ctx") == 0)- mp.n_ctx = (uint32_t)atol(v);- else if (strcmp(a, "--cache") == 0)- mp.cache_bytes = (uint64_t)(atof(v) * (1 << 30));- else if (strcmp(a, "--reserve") == 0)- mp.reserve_bytes = (uint64_t)(atof(v) * (1 << 30));- else if (strcmp(a, "--temp") == 0)- d.cp.temperature = (float)atof(v);- else if (strcmp(a, "--max") == 0)- d.cp.max_reply = atoi(v);- else if (strcmp(a, "--think") == 0)- d.cp.thinking = strcmp(v, "on") == 0;- else if (strcmp(a, "--timeout") == 0)- d.call_seconds = atoi(v);- else {- usage();+ else if (strcmp(a, "--ctx") == 0) {+ if (janas_word_int(v, 0, UINT32_MAX, &x, why, sizeof why) == 0)+ mp.n_ctx = (uint32_t)x;+ } else if (strcmp(a, "--cache") == 0) {+ if (janas_word_real(v, 0, 1 << 20, &r, why, sizeof why) == 0)+ mp.cache_bytes = (uint64_t)(r * (1 << 30));+ } else if (strcmp(a, "--reserve") == 0) {+ if (janas_word_real(v, 0, 1 << 20, &r, why, sizeof why) == 0)+ mp.reserve_bytes = (uint64_t)(r * (1 << 30));+ } else if (strcmp(a, "--temp") == 0) {+ if (janas_word_real(v, 0, 100, &r, why, sizeof why) == 0)+ d.cp.temperature = (float)r;+ } else if (strcmp(a, "--max") == 0) {+ if (janas_word_int(v, 0, INT32_MAX, &x, why, sizeof why) == 0)+ d.cp.max_reply = (int32_t)x;+ } else if (strcmp(a, "--think") == 0) {+ static const char *const on_off[] = {"off", "on"};+ int k = janas_word_choice(v, on_off, 2, why, sizeof why);+ if (k >= 0)+ d.cp.thinking = k;+ } else if (strcmp(a, "--timeout") == 0) {+ if (janas_word_int(v, 0, 86400 * 7, &x, why, sizeof why) == 0)+ d.call_seconds = (int)x;+ }+ if (why[0]) {+ fprintf(stderr, "janas-mcp: %s: %s\n", a, why);return 2;}}diff --git a/src/server/main.c b/src/server/main.cindex 2575f0a..353ddba 100644--- a/src/server/main.c+++ b/src/server/main.c@@ -7,7 +7,11 @@*/#include "server.h"+#include "common/env_names.h"+#include "common/words.h"+#include <netdb.h>+#include <limits.h>#include <signal.h>#include <stdio.h>#include <stdlib.h>@@ -100,6 +104,64 @@ static const char *arg(int argc, char **argv, int *i)return argv[++*i];}+/* every option, for the nearest to one mistyped */+static const char *const OPTIONS[] = {"--help", "--version",+ "--host", "--port",+ "--api-key", "--name",+ "--ctx", "--reserve",+ "--cache", "--mtp",+ "--draft", "--mode",+ "--think", "--embedding-model",+ "--no-mtp", "--no-gpu",+ "--keep", "--keep-memory",+ "--keep-disk", "--store",+ "--no-store", "--queue",+ "--max-body", "--connections",+ "--max-input", "--warn-input",+ "--fim-prefix", "--fim-suffix",+ "--fim-max", "--metrics",+ "--progress", "--no-mcp",+ "--test", "--verbose"};++/* the value of option argv[*i], read whole within [lo, hi]; a mistake+ ends the program, as a missing value does */+static long long num(int argc, char **argv, int *i, long long lo, long long hi)+{+ const char *a = argv[*i], *v = arg(argc, argv, i);+ long long x;+ char why[160];+ if (janas_word_int(v, lo, hi, &x, why, sizeof why) != 0) {+ fprintf(stderr, "janas-server: %s: %s\n", a, why);+ exit(2);+ }+ return x;+}++static double real(int argc, char **argv, int *i, double lo, double hi)+{+ const char *a = argv[*i], *v = arg(argc, argv, i);+ double x;+ char why[160];+ if (janas_word_real(v, lo, hi, &x, why, sizeof why) != 0) {+ fprintf(stderr, "janas-server: %s: %s\n", a, why);+ exit(2);+ }+ return x;+}++static int choice(int argc, char **argv, int *i, const char *const *names,+ size_t n)+{+ const char *a = argv[*i], *v = arg(argc, argv, i);+ char why[300];+ int k = janas_word_choice(v, names, n, why, sizeof why);+ if (k < 0) {+ fprintf(stderr, "janas-server: %s: %s\n", a, why);+ exit(2);+ }+ return k;+}+/* Where the store goes when --store does not say: $XDG_DATA_HOME/janas/server, or ~/.local/share/janas/server. 0, or -1 with no home. */static int default_store(char *buf, size_t len)@@ -125,6 +187,7 @@ static char *model_name(const char *path)int main(int argc, char **argv){+ janas_env_check("janas-server");struct srv s = {0};struct srv_config *c = &s.cfg;janas_llm_params_default(&c->llm);@@ -152,35 +215,32 @@ int main(int argc, char **argv)} else if (!strcmp(a, "--host")) {c->host = arg(argc, argv, &i);} else if (!strcmp(a, "--port")) {- c->port = (uint16_t)atoi(arg(argc, argv, &i));+ c->port = (uint16_t)num(argc, argv, &i, 1, 65535);} else if (!strcmp(a, "--api-key")) {c->api_key = arg(argc, argv, &i);} else if (!strcmp(a, "--name")) {c->model_id = arg(argc, argv, &i);} else if (!strcmp(a, "--ctx")) {- c->llm.n_ctx = (uint32_t)atoi(arg(argc, argv, &i));+ c->llm.n_ctx = (uint32_t)num(argc, argv, &i, 0, UINT32_MAX);} else if (!strcmp(a, "--reserve")) {c->llm.reserve_bytes =- (uint64_t)(atof(arg(argc, argv, &i)) * (1 << 30));+ (uint64_t)(real(argc, argv, &i, 0, 1 << 20) * (1 << 30));} else if (!strcmp(a, "--cache")) {c->llm.cache_bytes =- (uint64_t)(atof(arg(argc, argv, &i)) * (1 << 30));+ (uint64_t)(real(argc, argv, &i, 0, 1 << 20) * (1 << 30));} else if (!strcmp(a, "--mtp")) {c->llm.mtp_path = arg(argc, argv, &i);} else if (!strcmp(a, "--draft")) {c->llm.draft_path = arg(argc, argv, &i);} else if (!strcmp(a, "--mode")) {- const char *m = arg(argc, argv, &i);- c->llm.mode = !strcmp(m, "eco") ? JANAS_LLM_MODE_ECO- : !strcmp(m, "max") ? JANAS_LLM_MODE_MAX- : JANAS_LLM_MODE_AUTO;+ static const char *const modes[] = {"auto", "eco", "max"};+ int m = choice(argc, argv, &i, modes, 3);+ c->llm.mode = m == 1 ? JANAS_LLM_MODE_ECO+ : m == 2 ? JANAS_LLM_MODE_MAX+ : JANAS_LLM_MODE_AUTO;} else if (!strcmp(a, "--think")) {- const char *v = arg(argc, argv, &i);- if (strcmp(v, "on") && strcmp(v, "off")) {- fprintf(stderr, "janas-server: --think is on or off\n");- return 2;- }- c->thinking = strcmp(v, "off") ? 1 : 0;+ static const char *const on_off[] = {"off", "on"};+ c->thinking = choice(argc, argv, &i, on_off, 2);} else if (!strcmp(a, "--embedding-model")) {c->embed_path = arg(argc, argv, &i);} else if (!strcmp(a, "--no-mtp")) {@@ -188,36 +248,39 @@ int main(int argc, char **argv)} else if (!strcmp(a, "--no-gpu")) {c->no_gpu = 1;} else if (!strcmp(a, "--keep")) {- c->keep = atoi(arg(argc, argv, &i));+ c->keep = (int)num(argc, argv, &i, 0, 1 << 20);} else if (!strcmp(a, "--keep-memory")) {- c->keep_bytes = (uint64_t)(atof(arg(argc, argv, &i)) * (1 << 30));+ c->keep_bytes =+ (uint64_t)(real(argc, argv, &i, 0, 1 << 20) * (1 << 30));} else if (!strcmp(a, "--keep-disk")) {- c->keep_disk = (uint64_t)(atof(arg(argc, argv, &i)) * (1 << 30));+ c->keep_disk =+ (uint64_t)(real(argc, argv, &i, 0, 1 << 20) * (1 << 30));} else if (!strcmp(a, "--store")) {c->store_dir = arg(argc, argv, &i);no_store = 0;} else if (!strcmp(a, "--no-store")) {no_store = 1;} else if (!strcmp(a, "--queue")) {- c->max_queue = (uint32_t)atoi(arg(argc, argv, &i));+ c->max_queue = (uint32_t)num(argc, argv, &i, 0, 1 << 20);} else if (!strcmp(a, "--max-body")) {- c->max_body = (size_t)atoi(arg(argc, argv, &i)) << 20;+ c->max_body = (size_t)num(argc, argv, &i, 1, 1 << 14) << 20;} else if (!strcmp(a, "--connections")) {- c->max_connections = atoi(arg(argc, argv, &i));+ c->max_connections = (int)num(argc, argv, &i, 1, 1 << 16);} else if (!strcmp(a, "--max-input")) {- c->max_input = (uint32_t)atol(arg(argc, argv, &i));+ c->max_input = (uint32_t)num(argc, argv, &i, 0, UINT32_MAX);} else if (!strcmp(a, "--warn-input")) {- c->warn_input = (uint32_t)atol(arg(argc, argv, &i));+ c->warn_input = (uint32_t)num(argc, argv, &i, 0, UINT32_MAX);} else if (!strcmp(a, "--fim-prefix")) {- c->fim_prefix = (uint32_t)atol(arg(argc, argv, &i));+ c->fim_prefix = (uint32_t)num(argc, argv, &i, 0, UINT32_MAX);} else if (!strcmp(a, "--fim-suffix")) {- c->fim_suffix = (uint32_t)atol(arg(argc, argv, &i));+ c->fim_suffix = (uint32_t)num(argc, argv, &i, 0, UINT32_MAX);} else if (!strcmp(a, "--fim-max")) {- c->fim_max = (uint32_t)atol(arg(argc, argv, &i));+ c->fim_max = (uint32_t)num(argc, argv, &i, 0, UINT32_MAX);} else if (!strcmp(a, "--metrics")) {setenv("JANAS_METRICS", arg(argc, argv, &i), 1);} else if (!strcmp(a, "--progress")) {- setenv("JANAS_PROGRESS", arg(argc, argv, &i), 1);+ real(argc, argv, &i, 0, 86400);+ setenv("JANAS_PROGRESS", argv[i], 1);} else if (!strcmp(a, "--no-mcp")) {c->no_mcp = 1;} else if (!strcmp(a, "--test")) {@@ -226,8 +289,11 @@ int main(int argc, char **argv)c->verbose = 1;setenv("JANAS_PROGRESS", "30", 0); /* unless one is asked */} else if (a[0] == '-') {- fprintf(stderr, "janas-server: unknown option %s\n", a);- usage(stderr);+ char why[200];+ janas_unknown_word(why, sizeof why, a, "an option", OPTIONS,+ sizeof OPTIONS / sizeof *OPTIONS);+ fprintf(stderr, "janas-server: %s\n", why);+ fprintf(stderr, "janas-server --help lists the options\n");return 2;} else if (!c->model_path) {c->model_path = a;diff --git a/src/services/common/conf.c b/src/services/common/conf.cnew file mode 100644index 0000000..de7a19e--- /dev/null+++ b/src/services/common/conf.c@@ -0,0 +1,60 @@+/* SPDX-License-Identifier: GPL-3.0-or-later+ Copyright (C) 2026 Maurizio Cammalleri */+/*+ * conf.c - a service's settings file (see conf.h).+ */+#include "services/common/conf.h"++#include <ctype.h>+#include <stdio.h>+#include <string.h>++#include "common/words.h"++int janas_conf_get(const char *path, const char *const *names, size_t n,+ const char *name, char *val, size_t cap, char *why,+ size_t why_len)+{+ if (why_len)+ why[0] = 0;+ if (cap)+ val[0] = 0;+ FILE *f = path ? fopen(path, "r") : NULL;+ if (!f)+ return 0;+ const char *base = strrchr(path, '/');+ base = base ? base + 1 : path;+ char line[512];+ int found = 0, at = 0;+ while (fgets(line, sizeof line, f)) {+ at++;+ char *a = line + strspn(line, " \t");+ size_t len = strlen(a);+ while (len && isspace((unsigned char)a[len - 1]))+ a[--len] = 0;+ if (!*a || *a == '#')+ continue;+ size_t k = strcspn(a, " \t=");+ char *v = a + k;+ v += strspn(v, " \t");+ if (*v == '=')+ v += 1 + strspn(v + 1, " \t");+ a[k] = 0;+ if (strcmp(a, name) == 0) {+ snprintf(val, cap, "%s", v);+ found = 1;+ continue;+ }+ int known = 0;+ for (size_t i = 0; i < n && !known; i++)+ known = strcmp(a, names[i]) == 0;+ if (!known && why_len && !why[0]) {+ char w[200];+ janas_unknown_word(w, sizeof w, a, "a setting", names, n);+ snprintf(why, why_len, "%s, line %d: %s", base, at, w);+ }+ }+ memset(line, 0, sizeof line); /* a key read is not left about */+ fclose(f);+ return found;+}diff --git a/src/services/common/conf.h b/src/services/common/conf.hnew file mode 100644index 0000000..8daf16b--- /dev/null+++ b/src/services/common/conf.h@@ -0,0 +1,26 @@+/* SPDX-License-Identifier: GPL-3.0-or-later+ Copyright (C) 2026 Maurizio Cammalleri */+/*+ * conf.h - a service's settings file (conf.c): lines "name = value", a+ * line starting with # a comment. A line naming no setting the service+ * knows is not left aside in silence: it is told, with the name nearest+ * to it, so that a key written "aviationstak_key" does not leave the+ * service keyless without a word.+ */+#ifndef JANAS_SERVICES_CONF_H+#define JANAS_SERVICES_CONF_H++#include <stddef.h>++/*+ * The value of name in the file path, into val (cap bytes); names[0..n)+ * are all the settings the file may hold. 1 with the value, 0 when the+ * file or the line is missing. The first line naming none of them is told+ * in why ("flights.conf, line 2: aviationstak_key is not a setting (did+ * you mean aviationstack_key?)"), which is "" otherwise.+ */+int janas_conf_get(const char *path, const char *const *names, size_t n,+ const char *name, char *val, size_t cap, char *why,+ size_t why_len);++#endifdiff --git a/src/services/flights/README.md b/src/services/flights/README.mdindex c976f45..5d65ba0 100644--- a/src/services/flights/README.md+++ b/src/services/flights/README.md@@ -32,7 +32,7 @@ Register at [aviationstack.com](https://aviationstack.com) for the free plan: 10aviationstack_key = YOUR_KEY```-or in another file named by `--config FILE` or `JANAS_FLIGHTS_CONFIG`, or in the variable `JANAS_AVIATIONSTACK_KEY` (which wins). Without a key the service runs on open data only; `flight_status` then tells where a flight is, not its times.+or in another file named by `--config FILE` or `JANAS_FLIGHTS_CONFIG`, or in the variable `JANAS_AVIATIONSTACK_KEY` (which wins). Without a key the service runs on open data only; `flight_status` then tells where a flight is, not its times. A line of the file naming no setting (`aviationstak_key`) is told when the service starts, with the name meant, and in the answer that says there is no key.## What it does with AviationStack's answersdiff --git a/src/services/flights/flights.h b/src/services/flights/flights.hindex f64a0d2..de278c2 100644--- a/src/services/flights/flights.h+++ b/src/services/flights/flights.h@@ -84,6 +84,8 @@ struct fl_sched {/* The key, from JANAS_AVIATIONSTACK_KEY or the line "aviationstack_key =..." of the file at path: 1 when there is one. */int fl_sched_config(const char *path);+/* a line of the settings file not understood, or "" */+const char *fl_sched_problem(void);int fl_sched_have(void);/* The flights of a query of /v1/flights ("flight_iata=FR5904",diff --git a/src/services/flights/main.c b/src/services/flights/main.cindex 4b74622..58ee9c8 100644--- a/src/services/flights/main.c+++ b/src/services/flights/main.c@@ -97,6 +97,8 @@ int main(int argc, char **argv)"janas-flights: ready, tools: flight_status flights_between ""flights_over flights_nearby; schedules: %s\n",sched ? "AviationStack" : "none (no key)");+ if (fl_sched_problem()[0])+ fprintf(stderr, "janas-flights: %s\n", fl_sched_problem());janas_mcps_run(&srv);fl_sched_free();fprintf(stderr, "janas-flights: the client has gone\n");diff --git a/src/services/flights/schedule.c b/src/services/flights/schedule.cindex 9a919b6..05a4dbf 100644--- a/src/services/flights/schedule.c+++ b/src/services/flights/schedule.c@@ -14,12 +14,14 @@#include <time.h>#include "flights.h"+#include "services/common/conf.h"#define BASE "https://api.aviationstack.com/v1/flights?access_key="#define KEEP_S 600 /* how long an answer is kept */#define N_KEPT 16static char key[128];+static char conf_problem[300]; /* a line of the file not understood */static struct {char query[128];@@ -44,19 +46,10 @@ int fl_sched_config(const char *path)trim(key);return 1;}- FILE *f = path ? fopen(path, "r") : NULL;- if (!f)- return 0;- char line[512];- while (fgets(line, sizeof line, f)) {- trim(line);- if (strncmp(line, "aviationstack_key", 17) != 0)- continue;- char *v = line + 17;- v += strspn(v, " \t=");- snprintf(key, sizeof key, "%s", v);- }- fclose(f);+ static const char *const names[] = {"aviationstack_key"};+ janas_conf_get(path, names, 1, names[0], key, sizeof key, conf_problem,+ sizeof conf_problem);+ trim(key);return key[0] != 0;}@@ -65,6 +58,11 @@ int fl_sched_have(void)return key[0] != 0;}+const char *fl_sched_problem(void)+{+ return conf_problem;+}+/* "2026-09-30T18:25:00+00:00" in the zone tz. AviationStack writes theairport's local time and marks it +00:00 whatever the zone: the offsetis ignored, the zone of the airport is the one that counts. */diff --git a/src/services/flights/tools.c b/src/services/flights/tools.cindex a31a214..9798df7 100644--- a/src/services/flights/tools.c+++ b/src/services/flights/tools.c@@ -805,10 +805,15 @@ static int flights_between(const struct janas_json *args, struct janas_buf *b)return 0;}if (!fl_sched_have()) {- const char *m = "This server has no AviationStack key, so it knows "- "no schedules: flights_between is not available. "- "flights_nearby shows what flies near an airport "- "now.";+ char m[600];+ snprintf(m, sizeof m,+ "This server has no AviationStack key, so it knows no "+ "schedules: flights_between is not available. "+ "flights_nearby shows what flies near an airport now.%s%s",+ fl_sched_problem()[0] ? " Its settings file has a line it "+ "does not know: "+ : "",+ fl_sched_problem());janas_mcps_text_result(b, m, strlen(m), 1);return 0;}diff --git a/src/services/prices/README.md b/src/services/prices/README.mdindex d3ac330..f81fc47 100644--- a/src/services/prices/README.md+++ b/src/services/prices/README.md@@ -42,7 +42,7 @@ Alpha Vantage gives a free key ("it takes fewer than 20 seconds", it says): <httalphavantage_key = YOUR_KEY```-or in `JANAS_ALPHAVANTAGE_KEY`. The free key allows 25 requests a day (Alpha Vantage lifts the limit for verified open-source projects); a question costs one or two. Without a key, `prices_stock` answers how to get one. The prices may be delayed.+or in `JANAS_ALPHAVANTAGE_KEY`. The free key allows 25 requests a day (Alpha Vantage lifts the limit for verified open-source projects); a question costs one or two. Without a key, `prices_stock` answers how to get one. The prices may be delayed. A line of the file naming no setting (`alphavantage = ...`) is told when the service starts, with the name meant, and in the answer that says there is no key.## Running itdiff --git a/src/services/prices/fetch.c b/src/services/prices/fetch.cindex 581bd8f..1d4cb4d 100644--- a/src/services/prices/fetch.c+++ b/src/services/prices/fetch.c@@ -14,6 +14,7 @@#include <string.h>#include <time.h>+#include "services/common/conf.h"#include "services/common/https_get.h"#include "prices.h"@@ -37,6 +38,7 @@ static struct {} hosts[N_HOSTS];static char key[128];+static char conf_problem[300]; /* a line of the file not understood */static double since(const struct timespec *t){@@ -148,23 +150,17 @@ void pr_key_config(const char *path)take(getenv("JANAS_ALPHAVANTAGE_KEY"));if (key[0] || !path)return;- FILE *f = fopen(path, "r");- if (!f)- return;- char line[512];- while (!key[0] && fgets(line, sizeof line, f)) {- if (strncmp(line, "alphavantage_key", 16) != 0)- continue;- const char *v = strchr(line, '=');- if (v) {- v++;- while (*v == ' ' || *v == '\t')- v++;- take(v);- }- }- memset(line, 0, sizeof line);- fclose(f);+ static const char *const names[] = {"alphavantage_key"};+ char v[160];+ if (janas_conf_get(path, names, 1, names[0], v, sizeof v, conf_problem,+ sizeof conf_problem))+ take(v);+ memset(v, 0, sizeof v);+}++const char *pr_key_problem(void)+{+ return conf_problem;}const char *pr_key(void)diff --git a/src/services/prices/main.c b/src/services/prices/main.cindex 3dccc72..9f73767 100644--- a/src/services/prices/main.c+++ b/src/services/prices/main.c@@ -83,6 +83,8 @@ int main(int argc, char **argv)}fprintf(stderr, "janas-prices %s: ready, 7 tools; shares: %s\n",JANAS_VERSION, pr_key() ? "Alpha Vantage" : "none (no key)");+ if (pr_key_problem()[0])+ fprintf(stderr, "janas-prices: %s\n", pr_key_problem());janas_mcps_run(&srv);pr_fetch_free();return 0;diff --git a/src/services/prices/money.c b/src/services/prices/money.cindex 695e731..bf14d1c 100644--- a/src/services/prices/money.c+++ b/src/services/prices/money.c@@ -213,11 +213,14 @@ int pr_tool_stock(const struct janas_json *args, struct janas_buf *b)return pr_fail(b, "No share named.");if (!pr_key())return pr_fail(- b, "Share prices need a free key of Alpha Vantage, which the user "- "has not given: it is had at "- "https://www.alphavantage.co/support/#api-key and goes in "- "~/.config/janas/prices.conf as the line alphavantage_key = "- "KEY (or in JANAS_ALPHAVANTAGE_KEY). Tell the user so.");+ b,+ "Share prices need a free key of Alpha Vantage, which the user "+ "has not given: it is had at "+ "https://www.alphavantage.co/support/#api-key and goes in "+ "~/.config/janas/prices.conf as the line alphavantage_key = "+ "KEY (or in JANAS_ALPHAVANTAGE_KEY).%s%s Tell the user so.",+ pr_key_problem()[0] ? " That file has a line not understood: " : "",+ pr_key_problem());struct pr_quote q;char err[400] = "";memset(&q, 0, sizeof q);diff --git a/src/services/prices/prices.h b/src/services/prices/prices.hindex 2a2c46c..934288a 100644--- a/src/services/prices/prices.h+++ b/src/services/prices/prices.h@@ -32,6 +32,8 @@ void pr_url_put(struct janas_buf *b, const char *s);"alphavantage_key = KEY" of the file); NULL when none. */void pr_key_config(const char *path);const char *pr_key(void);+/* a line of the settings file not understood, or "" */+const char *pr_key_problem(void);/* ---- place.c ---- */diff --git a/tests/test_mcp.c b/tests/test_mcp.cindex ee8e2ef..abb39b1 100644--- a/tests/test_mcp.c+++ b/tests/test_mcp.c@@ -172,6 +172,35 @@ static void test_config(void)sizeof(err)) != 0,"bad config %zu accepted", i);}+ /* a key a letter from one of ours is refused, with the one meant;+ the other clients' keys and keys far from ours are left alone */+ const char *typo = "{\"mcpServers\": {\"a\": {\"command\": \"x\", "+ "\"arg\": [\"-v\"]}}}";+ CHECK(janas_mcp_config_parse(typo, strlen(typo), &c, &n, err,+ sizeof(err)) != 0 &&+ strstr(err, "\"arg\" is not a key (did you mean \"args\"?)"),+ "arg: %s", err);+ const char *evn = "{\"mcpServers\": {\"a\": {\"command\": \"x\", "+ "\"evn\": {\"A\": \"b\"}}}}";+ CHECK(janas_mcp_config_parse(evn, strlen(evn), &c, &n, err, sizeof(err)) !=+ 0 &&+ strstr(err, "did you mean \"env\"?"),+ "evn: %s", err);+ const char *theirs =+ "{\"mcpServers\": {\"a\": {\"command\": \"x\", \"autoApprove\": [], "+ "\"cwd\": \"/\", \"envFile\": \".env\", \"headersHelper\": \"h\", "+ "\"dev\": {}, \"somethingElse\": 1}}}";+ rc = janas_mcp_config_parse(theirs, strlen(theirs), &c, &n, err,+ sizeof(err));+ CHECK(rc == 0 && n == 1, "other clients' keys: %s", err);+ if (rc == 0)+ janas_mcp_config_free(c, n);+ const char *off = "{\"mcpServers\": {\"a\": {\"command\": \"x\", "+ "\"disabled\": \"true\"}}}";+ CHECK(janas_mcp_config_parse(off, strlen(off), &c, &n, err, sizeof(err)) !=+ 0 &&+ strstr(err, "disabled is true or false"),+ "disabled as a string: %s", err);char text[1024];size_t len = strlen(CONFIG);for (int it = 0; it < 20000; it++) {diff --git a/tests/test_words.c b/tests/test_words.cnew file mode 100644index 0000000..c255566--- /dev/null+++ b/tests/test_words.c@@ -0,0 +1,227 @@+/* SPDX-License-Identifier: GPL-3.0-or-later+ Copyright (C) 2026 Maurizio Cammalleri */+/*+ * test_words.c - the strict reading of what a user gives Janas: the+ * nearest of known names, numbers and choices read whole, a service's+ * settings file, and the table of the variables of the environment,+ * checked against every JANAS_ name the sources read.+ */+#define _GNU_SOURCE /* nftw's FTW_PHYS */+#include <ftw.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <unistd.h>++#include "common/env_names.h"+#include "common/words.h"+#include "services/common/conf.h"++static int failures;++#define CHECK(c, ...) \+ do { \+ if (!(c)) { \+ printf("FAIL %s:%d: ", __FILE__, __LINE__); \+ printf(__VA_ARGS__); \+ printf("\n"); \+ failures++; \+ } \+ } while (0)++static const char *const OPTS[] = {+ "--temp", "--top-k", "--top-p", "--ctx", "--cache", "--reserve",+ "--max", "--no-mtp", "--mtp", "--think", "--mcp-auto"};+#define N_OPTS (sizeof OPTS / sizeof *OPTS)++static void closest(void)+{+ struct {+ const char *w, *want;+ } t[] = {+ {"--tmep", "--temp"}, /* two letters swapped */+ {"--temperature", "--temp"}, /* one the start of the other */+ {"--chache", "--cache"}, /* one letter more */+ {"--reserv", "--reserve"}, /* one less */+ {"--TEMP", "--temp"}, /* case aside */+ {"--mcp-aut", "--mcp-auto"}, /* the start, four letters or more */+ {"--frobnicate", NULL}, /* nothing near */+ {"--x", NULL},+ {"", NULL},+ };+ for (size_t i = 0; i < sizeof t / sizeof *t; i++) {+ const char *got = janas_closest(t[i].w, OPTS, N_OPTS);+ CHECK(t[i].want ? got && strcmp(got, t[i].want) == 0 : !got,+ "%s: %s, wanted %s", t[i].w, got ? got : "none",+ t[i].want ? t[i].want : "none");+ }+ char m[200];+ janas_unknown_word(m, sizeof m, "--tmep", "an option", OPTS, N_OPTS);+ CHECK(strcmp(m, "--tmep is not an option (did you mean --temp?)") == 0,+ "%s", m);+ janas_unknown_word(m, sizeof m, "--zzz", "an option", OPTS, N_OPTS);+ CHECK(strcmp(m, "--zzz is not an option") == 0, "%s", m);+ const char *env[] = {"JANAS_EXPERT_BITS", "JANAS_EXPERTS"};+ const char *got = janas_closest("JANAS_EXPERT_BIT", env, 2);+ CHECK(got && strcmp(got, "JANAS_EXPERT_BITS") == 0, "env: %s",+ got ? got : "none");+}++static void numbers(void)+{+ long long x = -1;+ double r = -1;+ char why[160];+ CHECK(janas_word_int("16384", 0, 1 << 30, &x, why, sizeof why) == 0 &&+ x == 16384,+ "16384");+ CHECK(janas_word_int("32k", 0, 1 << 30, &x, why, sizeof why) != 0 &&+ strcmp(why, "32k is not a whole number") == 0,+ "32k: %s", why);+ CHECK(janas_word_int("70000", 1, 65535, &x, why, sizeof why) != 0 &&+ strcmp(why, "70000 is above 65535") == 0,+ "70000: %s", why);+ CHECK(janas_word_int("-1", 0, 10, &x, why, sizeof why) != 0 &&+ strcmp(why, "-1 is below 0") == 0,+ "-1: %s", why);+ CHECK(janas_word_int("", 0, 10, &x, why, sizeof why) != 0, "empty");+ CHECK(janas_word_int(" 5", 0, 10, &x, why, sizeof why) != 0, "space");+ CHECK(janas_word_int(NULL, 0, 10, &x, why, sizeof why) != 0 &&+ strcmp(why, "a value is missing") == 0,+ "missing: %s", why);+ CHECK(janas_word_int("99999999999999999999", 0, 10, &x, why, sizeof why) !=+ 0,+ "overflow");+ CHECK(janas_word_real("0.7", 0, 100, &r, why, sizeof why) == 0 && r == 0.7,+ "0.7");+ CHECK(janas_word_real("1e-05", 0, 1, &r, why, sizeof why) == 0, "1e-05");+ CHECK(janas_word_real("0,7", 0, 100, &r, why, sizeof why) != 0 &&+ strcmp(why, "0,7 is not a number") == 0,+ "0,7: %s", why);+ CHECK(janas_word_real("nan", 0, 100, &r, why, sizeof why) != 0, "nan");+ CHECK(janas_word_real("1.5", 0, 1, &r, why, sizeof why) != 0 &&+ strcmp(why, "1.5 is above 1") == 0,+ "1.5: %s", why);+ const char *on_off[] = {"off", "on"};+ CHECK(janas_word_choice("on", on_off, 2, why, sizeof why) == 1, "on");+ CHECK(janas_word_choice("of", on_off, 2, why, sizeof why) == -1 &&+ strcmp(why, "of is not one of off, on (did you mean off?)") == 0,+ "of: %s", why);+}++static void settings(void)+{+ char path[512];+ const char *dir = getenv("TMPDIR");+ snprintf(path, sizeof path, "%s/janas_test_words_%d.conf",+ dir && *dir ? dir : "/tmp", (int)getpid());+ FILE *f = fopen(path, "w");+ CHECK(f, "cannot write %s", path);+ if (!f)+ return;+ fputs("# a comment\n\n aviationstak_key = WRONG\n"+ "aviationstack_key = ABCDEFGH12 \n",+ f);+ fclose(f);+ const char *names[] = {"aviationstack_key"};+ char val[64], why[300];+ int got = janas_conf_get(path, names, 1, names[0], val, sizeof val, why,+ sizeof why);+ CHECK(got == 1 && strcmp(val, "ABCDEFGH12") == 0, "value: %s", val);+ CHECK(strstr(why, ", line 3: aviationstak_key is not a setting (did you "+ "mean aviationstack_key?)") != NULL,+ "why: %s", why);+ f = fopen(path, "w");+ if (f) {+ fputs("aviationstack_key KEY2KEY2\n", f); /* no = : taken too */+ fclose(f);+ }+ got = janas_conf_get(path, names, 1, names[0], val, sizeof val, why,+ sizeof why);+ CHECK(got == 1 && strcmp(val, "KEY2KEY2") == 0 && !why[0],+ "without =: %s / %s", val, why);+ unlink(path);+ CHECK(janas_conf_get(path, names, 1, names[0], val, sizeof val, why,+ sizeof why) == 0 &&+ !val[0] && !why[0],+ "no file");+}++/* every "JANAS_..." string of the sources must be in the table, and every+ name of the table in the sources */+static char seen[256][48];+static int n_seen;++static int scan(const char *path, const struct stat *st, int kind,+ struct FTW *ftw)+{+ (void)st;+ (void)ftw;+ size_t n = strlen(path);+ if (kind != FTW_F || n < 3 || strstr(path, "third_party") ||+ (strcmp(path + n - 2, ".c") && strcmp(path + n - 2, ".h")) ||+ strstr(path, "env_names.c"))+ return 0;+ FILE *f = fopen(path, "r");+ if (!f)+ return 0;+ static char text[1 << 20];+ size_t len = fread(text, 1, sizeof text - 1, f);+ fclose(f);+ text[len] = 0;+ for (char *p = text; (p = strstr(p, "\"JANAS_")); p++) {+ size_t k = 1;+ while (p[k] == '_' || (p[k] >= 'A' && p[k] <= 'Z') ||+ (p[k] >= '0' && p[k] <= '9'))+ k++;+ if (p[k] != '"' || k - 1 >= sizeof seen[0])+ continue;+ char name[48];+ memcpy(name, p + 1, k - 1);+ name[k - 1] = 0;+ int known = 0;+ for (size_t i = 0; i < JANAS_N_ENV_NAMES && !known; i++)+ known = strcmp(name, JANAS_ENV_NAMES[i]) == 0;+ CHECK(known, "%s reads %s, not in src/common/env_names.c", path, name);+ int dup = 0;+ for (int i = 0; i < n_seen && !dup; i++)+ dup = strcmp(seen[i], name) == 0;+ if (!dup && n_seen < 256)+ strcpy(seen[n_seen++], name);+ }+ return 0;+}++static void env_table(void)+{+ if (access("src/common/env_names.c", R_OK) != 0) {+ printf("test_words: the sources are not here, table not checked\n");+ return;+ }+ nftw("src", scan, 16, FTW_PHYS);+ for (size_t i = 0; i < JANAS_N_ENV_NAMES; i++) {+ int found = 0;+ for (int k = 0; k < n_seen && !found; k++)+ found = strcmp(seen[k], JANAS_ENV_NAMES[i]) == 0;+ CHECK(found, "%s is in the table and read nowhere", JANAS_ENV_NAMES[i]);+ }+ setenv("JANAS_EXPERT_BIT", "2", 1);+ setenv("JANAS_EXPERT_BITS", "2", 1);+ CHECK(janas_env_check("test_words") == 1, "one unknown variable");+ unsetenv("JANAS_EXPERT_BIT");+ unsetenv("JANAS_EXPERT_BITS");+}++int main(void)+{+ closest();+ numbers();+ settings();+ env_table();+ if (failures) {+ printf("test_words: %d failures\n", failures);+ return 1;+ }+ printf("test_words: ok\n");+ return 0;+}