master ohmu/fastfetch-openbsd / src / common / jsonconfig.h
ohmu  ·  2026-10-15
 1#pragma once
 2
 3#include "common/ffdata.h"
 4#include "common/option.h"
 5
 6// `key` / `val` may be null when the JSON object has no such member; `moduleArgs` is always real
 7[[gnu::nonnull(3)]] bool ffJsonConfigParseModuleArgs(yyjson_val* key, yyjson_val* val, FFModuleArgs* moduleArgs);
 8// `val` may be null (yyjson predicates tolerate it); `result` and `pairs` may not.
 9// Returns an error string, null on success, so it is `nodiscard`.
10[[gnu::nonnull(2, 3), nodiscard]] const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair pairs[]);
11// Reads an integer in `[0, max]` into `result`. Returns false for anything else.
12//
13// `yyjson_get_uint()` accepts the signed number subtype as well and reinterprets its bits, so the
14// bare `(uint32_t) yyjson_get_uint(val)` it replaces turned `-1` into `UINT32_MAX` — 4.3 billion
15// characters for `separator.times`, a ~50 day sleep for `waitTime`.
16[[gnu::nonnull(1, 2), nodiscard]] bool ffJsonConfigParseUInt32(yyjson_val* val, uint32_t* result, uint32_t max);
17
18// The three helpers below are routinely called as statements, to add a key to a document, so their
19// result is not `nodiscard`.
20[[gnu::nonnull(1, 2)]] yyjson_api_inline yyjson_mut_val* yyjson_mut_strbuf(yyjson_mut_doc* doc, const FFstrbuf* buf) {
21    return yyjson_mut_strncpy(doc, buf->chars, buf->length);
22}
23
24[[gnu::nonnull(1, 2, 3, 4)]] yyjson_api_inline bool yyjson_mut_obj_add_strbuf(yyjson_mut_doc* doc,
25    yyjson_mut_val* obj,
26    const char* _key,
27    const FFstrbuf* buf) {
28    return yyjson_mut_obj_add_strncpy(doc, obj, _key, buf->chars, buf->length);
29}
30
31[[gnu::nonnull(1, 2, 3)]] yyjson_api_inline bool yyjson_mut_arr_add_strbuf(yyjson_mut_doc* doc,
32    yyjson_mut_val* obj,
33    const FFstrbuf* buf) {
34    return yyjson_mut_arr_add_strncpy(doc, obj, buf->chars, buf->length);
35}
36
37[[gnu::nonnull(1)]] void ffPrintJsonConfig(FFdata* data, bool prepare);
38[[gnu::nonnull(1, 2, 3)]] void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* moduleArgs);