mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
JsonConfig: refactor to get rid of data-ffjson_*
This commit is contained in:
parent
5f52c64d4d
commit
dca9ce4b2d
@ -228,10 +228,11 @@ configure_file(src/fastfetch_config.h.in fastfetch_config.h)
|
||||
|
||||
set(LIBFASTFETCH_SRC
|
||||
src/common/bar.c
|
||||
src/common/config.c
|
||||
src/common/font.c
|
||||
src/common/format.c
|
||||
src/common/init.c
|
||||
src/common/json.c
|
||||
src/common/jsonconfig.c
|
||||
src/common/library.c
|
||||
src/common/option.c
|
||||
src/common/parsing.c
|
||||
|
@ -1,42 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
|
||||
#include <json-c/json.h>
|
||||
|
||||
#include "common/library.h"
|
||||
|
||||
typedef struct JSONCData
|
||||
{
|
||||
FF_LIBRARY_SYMBOL(json_tokener_parse)
|
||||
FF_LIBRARY_SYMBOL(json_object_is_type)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_array)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_boolean)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_double)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_int)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_string_len)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_string)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_object)
|
||||
FF_LIBRARY_SYMBOL(json_object_object_get)
|
||||
FF_LIBRARY_SYMBOL(json_object_put)
|
||||
} JSONCData;
|
||||
|
||||
bool ffJsonConfigParseModuleArgs(JSONCData* data, const char* key, json_object* val, FFModuleArgs* moduleArgs);
|
||||
const char* ffJsonConfigParseEnum(JSONCData* data, json_object* val, int* result, FFKeyValuePair pairs[]);
|
||||
|
||||
// Modified from json_object_object_foreach
|
||||
#define FF_JSON_OBJECT_OBJECT_FOREACH(data, obj, keyVar, valVar) \
|
||||
const char* keyVar = NULL; \
|
||||
json_object* valVar = NULL; \
|
||||
for (struct lh_entry* entry##keyVar = (obj) ? lh_table_head(data->ffjson_object_get_object(obj)) : NULL; \
|
||||
({ \
|
||||
if (entry##keyVar) \
|
||||
{ \
|
||||
keyVar = (const char*) lh_entry_k(entry##keyVar); \
|
||||
valVar = (json_object*) lh_entry_v(entry##keyVar); \
|
||||
}; \
|
||||
entry##keyVar; \
|
||||
}); \
|
||||
entry##keyVar = lh_entry_next(entry##keyVar))
|
||||
|
||||
#endif
|
139
src/common/json.c
Normal file
139
src/common/json.c
Normal file
@ -0,0 +1,139 @@
|
||||
#include "common/json.h"
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
|
||||
#include "common/library.h"
|
||||
#include "common/thread.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct FFJsonLibrary
|
||||
{
|
||||
FF_LIBRARY_SYMBOL(json_tokener_parse)
|
||||
FF_LIBRARY_SYMBOL(json_object_is_type)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_array)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_boolean)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_double)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_int)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_string_len)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_string)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_object)
|
||||
FF_LIBRARY_SYMBOL(json_object_object_get)
|
||||
FF_LIBRARY_SYMBOL(json_object_put)
|
||||
} FFJsonLibrary;
|
||||
|
||||
static const FFJsonLibrary* loadLibSymbols(const FFinstance* instance)
|
||||
{
|
||||
assert(instance);
|
||||
|
||||
static FFJsonLibrary lib;
|
||||
FF_LIBRARY_LOAD(libjsonc, &instance->config.libJSONC, NULL,
|
||||
#ifdef _WIN32
|
||||
"libjson-c-5" FF_LIBRARY_EXTENSION, -1
|
||||
#else
|
||||
"libjson-c" FF_LIBRARY_EXTENSION, 5
|
||||
#endif
|
||||
)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR(libjsonc, lib, json_tokener_parse, NULL)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR(libjsonc, lib, json_object_is_type, NULL)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR(libjsonc, lib, json_object_get_array, NULL)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR(libjsonc, lib, json_object_get_boolean, NULL)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR(libjsonc, lib, json_object_get_double, NULL)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR(libjsonc, lib, json_object_get_int, NULL)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR(libjsonc, lib, json_object_get_string_len, NULL)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR(libjsonc, lib, json_object_get_string, NULL)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR(libjsonc, lib, json_object_get_object, NULL)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR(libjsonc, lib, json_object_object_get, NULL)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR(libjsonc, lib, json_object_put, NULL)
|
||||
libjsonc = NULL; // don't dlclose automatically
|
||||
return &lib;
|
||||
}
|
||||
|
||||
const FFJsonLibrary* ffJsonLib = NULL;
|
||||
bool ffJsonLoadLibrary(const FFinstance* instance)
|
||||
{
|
||||
static bool loaded = false;
|
||||
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
|
||||
|
||||
if (!loaded)
|
||||
{
|
||||
ffThreadMutexLock(&mutex);
|
||||
|
||||
if(!loaded)
|
||||
{
|
||||
loaded = true;
|
||||
ffJsonLib = loadLibSymbols(instance);
|
||||
}
|
||||
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
}
|
||||
return !!ffJsonLib;
|
||||
}
|
||||
|
||||
struct json_object *json_tokener_parse(const char *str)
|
||||
{
|
||||
assert(ffJsonLib);
|
||||
return ffJsonLib->ffjson_tokener_parse(str);
|
||||
}
|
||||
|
||||
int json_object_is_type(const json_object *obj, enum json_type type)
|
||||
{
|
||||
assert(ffJsonLib);
|
||||
return ffJsonLib->ffjson_object_is_type(obj, type);
|
||||
}
|
||||
|
||||
struct array_list *json_object_get_array(const json_object *obj)
|
||||
{
|
||||
assert(ffJsonLib);
|
||||
return ffJsonLib->ffjson_object_get_array(obj);
|
||||
}
|
||||
|
||||
json_bool json_object_get_boolean(const json_object *obj)
|
||||
{
|
||||
assert(ffJsonLib);
|
||||
return ffJsonLib->ffjson_object_get_boolean(obj);
|
||||
}
|
||||
|
||||
double json_object_get_double(const json_object *obj)
|
||||
{
|
||||
assert(ffJsonLib);
|
||||
return ffJsonLib->ffjson_object_get_double(obj);
|
||||
}
|
||||
|
||||
int32_t json_object_get_int(const json_object *obj)
|
||||
{
|
||||
assert(ffJsonLib);
|
||||
return ffJsonLib->ffjson_object_get_int(obj);
|
||||
}
|
||||
|
||||
int json_object_get_string_len(const json_object *obj)
|
||||
{
|
||||
assert(ffJsonLib);
|
||||
return ffJsonLib->ffjson_object_get_string_len(obj);
|
||||
}
|
||||
|
||||
const char *json_object_get_string(json_object *obj)
|
||||
{
|
||||
assert(ffJsonLib);
|
||||
return ffJsonLib->ffjson_object_get_string(obj);
|
||||
}
|
||||
|
||||
struct lh_table *json_object_get_object(const json_object *obj)
|
||||
{
|
||||
assert(ffJsonLib);
|
||||
return ffJsonLib->ffjson_object_get_object(obj);
|
||||
}
|
||||
|
||||
struct json_object *json_object_object_get(const json_object *obj, const char *key)
|
||||
{
|
||||
assert(ffJsonLib);
|
||||
return ffJsonLib->ffjson_object_object_get(obj, key);
|
||||
}
|
||||
|
||||
int json_object_put(json_object *obj)
|
||||
{
|
||||
assert(ffJsonLib);
|
||||
return ffJsonLib->ffjson_object_put(obj);
|
||||
}
|
||||
|
||||
#endif
|
18
src/common/json.h
Normal file
18
src/common/json.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <json-c/json.h>
|
||||
|
||||
bool ffJsonLoadLibrary(const FFinstance* instance);
|
||||
|
||||
static inline void wrapJsoncFree(json_object** root)
|
||||
{
|
||||
assert(root);
|
||||
if (*root)
|
||||
json_object_put(*root);
|
||||
}
|
||||
|
||||
#endif
|
@ -1,33 +1,33 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/config.h"
|
||||
#include "common/jsonconfig.h"
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
|
||||
bool ffJsonConfigParseModuleArgs(JSONCData* data, const char* key, json_object* val, FFModuleArgs* moduleArgs)
|
||||
bool ffJsonConfigParseModuleArgs(const char* key, json_object* val, FFModuleArgs* moduleArgs)
|
||||
{
|
||||
if(strcasecmp(key, "key") == 0)
|
||||
{
|
||||
ffStrbufSetNS(&moduleArgs->key, (uint32_t) data->ffjson_object_get_string_len(val), data->ffjson_object_get_string(val));
|
||||
ffStrbufSetNS(&moduleArgs->key, (uint32_t) json_object_get_string_len(val), json_object_get_string(val));
|
||||
return true;
|
||||
}
|
||||
else if(strcasecmp(key, "format") == 0)
|
||||
{
|
||||
ffStrbufSetNS(&moduleArgs->outputFormat, (uint32_t) data->ffjson_object_get_string_len(val), data->ffjson_object_get_string(val));
|
||||
ffStrbufSetNS(&moduleArgs->outputFormat, (uint32_t) json_object_get_string_len(val), json_object_get_string(val));
|
||||
return true;
|
||||
}
|
||||
else if(strcasecmp(key, "error") == 0)
|
||||
{
|
||||
ffStrbufSetNS(&moduleArgs->errorFormat, (uint32_t) data->ffjson_object_get_string_len(val), data->ffjson_object_get_string(val));
|
||||
ffStrbufSetNS(&moduleArgs->errorFormat, (uint32_t) json_object_get_string_len(val), json_object_get_string(val));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* ffJsonConfigParseEnum(JSONCData* data, json_object* val, int* result, FFKeyValuePair pairs[])
|
||||
const char* ffJsonConfigParseEnum(json_object* val, int* result, FFKeyValuePair pairs[])
|
||||
{
|
||||
if (data->ffjson_object_is_type(val, json_type_int))
|
||||
if (json_object_is_type(val, json_type_int))
|
||||
{
|
||||
int intVal = data->ffjson_object_get_int(val);
|
||||
int intVal = json_object_get_int(val);
|
||||
|
||||
for (const FFKeyValuePair* pPair = pairs; pPair->key; ++pPair)
|
||||
{
|
||||
@ -40,9 +40,9 @@ const char* ffJsonConfigParseEnum(JSONCData* data, json_object* val, int* result
|
||||
|
||||
return "Invalid enum integer";
|
||||
}
|
||||
else if (data->ffjson_object_is_type(val, json_type_string))
|
||||
else if (json_object_is_type(val, json_type_string))
|
||||
{
|
||||
const char* strVal = data->ffjson_object_get_string(val);
|
||||
const char* strVal = json_object_get_string(val);
|
||||
for (const FFKeyValuePair* pPair = pairs; pPair->key; ++pPair)
|
||||
{
|
||||
if (strcasecmp(strVal, pPair->key) == 0)
|
10
src/common/jsonconfig.h
Normal file
10
src/common/jsonconfig.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
|
||||
#include "common/json.h"
|
||||
|
||||
bool ffJsonConfigParseModuleArgs(const char* key, json_object* val, FFModuleArgs* moduleArgs);
|
||||
const char* ffJsonConfigParseEnum(json_object* val, int* result, FFKeyValuePair pairs[]);
|
||||
|
||||
#endif
|
@ -71,80 +71,45 @@ FF_MAYBE_UNUSED static void detectTTY(FFTerminalFontResult* terminalFont)
|
||||
|
||||
#include "common/library.h"
|
||||
#include "common/processing.h"
|
||||
#include "common/json.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <json-c/json.h>
|
||||
|
||||
typedef struct JSONCData
|
||||
static const char* detectWTProfile(json_object* profile, FFstrbuf* name, double* size)
|
||||
{
|
||||
FF_LIBRARY_SYMBOL(json_tokener_parse)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_array)
|
||||
FF_LIBRARY_SYMBOL(json_object_is_type)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_double)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_string_len)
|
||||
FF_LIBRARY_SYMBOL(json_object_get_string)
|
||||
FF_LIBRARY_SYMBOL(json_object_object_get)
|
||||
FF_LIBRARY_SYMBOL(json_object_put)
|
||||
|
||||
json_object* root;
|
||||
} JSONCData;
|
||||
|
||||
static const char* detectWTProfile(JSONCData* data, json_object* profile, FFstrbuf* name, double* size)
|
||||
{
|
||||
json_object* font = data->ffjson_object_object_get(profile, "font");
|
||||
json_object* font = json_object_object_get(profile, "font");
|
||||
if (!font)
|
||||
return "json_object_object_get(profile, \"font\"); failed";
|
||||
|
||||
if (!data->ffjson_object_is_type(font, json_type_object))
|
||||
if (!json_object_is_type(font, json_type_object))
|
||||
return "json_object_is_type(font, json_type_object) returns false";
|
||||
|
||||
if (name->length == 0)
|
||||
{
|
||||
json_object* pface = data->ffjson_object_object_get(font, "face");
|
||||
if(data->ffjson_object_is_type(pface, json_type_string))
|
||||
ffStrbufAppendNS(name, (uint32_t) data->ffjson_object_get_string_len(pface), data->ffjson_object_get_string(pface));
|
||||
json_object* pface = json_object_object_get(font, "face");
|
||||
if(json_object_is_type(pface, json_type_string))
|
||||
ffStrbufAppendNS(name, (uint32_t) json_object_get_string_len(pface), json_object_get_string(pface));
|
||||
}
|
||||
|
||||
if (*size < 0)
|
||||
{
|
||||
json_object* psize = data->ffjson_object_object_get(font, "size");
|
||||
if (data->ffjson_object_is_type(psize, json_type_int) || data->ffjson_object_is_type(psize, json_type_double))
|
||||
*size = data->ffjson_object_get_double(psize);
|
||||
json_object* psize = json_object_object_get(font, "size");
|
||||
if (json_object_is_type(psize, json_type_int) || json_object_is_type(psize, json_type_double))
|
||||
*size = json_object_get_double(psize);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline void wrapJsoncFree(JSONCData* data)
|
||||
{
|
||||
assert(data);
|
||||
if (data->root)
|
||||
data->ffjson_object_put(data->root);
|
||||
}
|
||||
|
||||
static const char* detectFromWTImpl(const FFinstance* instance, FFstrbuf* content, FFstrbuf* name, double* size)
|
||||
{
|
||||
FF_LIBRARY_LOAD(libjsonc, &instance->config.libJSONC, "dlopen libjson-c" FF_LIBRARY_EXTENSION" failed",
|
||||
#ifdef _WIN32
|
||||
"libjson-c-5" FF_LIBRARY_EXTENSION, -1
|
||||
#else
|
||||
"libjson-c" FF_LIBRARY_EXTENSION, 5
|
||||
#endif
|
||||
)
|
||||
JSONCData __attribute__((__cleanup__(wrapJsoncFree))) data = {};
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_tokener_parse)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_is_type)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_array)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_double)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_string_len)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_string)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_object_get)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_put)
|
||||
if (ffJsonLoadLibrary(instance))
|
||||
return "Failed to load json-c library";
|
||||
|
||||
data.root = data.ffjson_tokener_parse(content->chars);
|
||||
if (!data.root)
|
||||
json_object* __attribute__((__cleanup__(wrapJsoncFree))) root = json_tokener_parse(content->chars);
|
||||
if (!root)
|
||||
return "Failed to parse WT JSON config file";
|
||||
|
||||
json_object* profiles = data.ffjson_object_object_get(data.root, "profiles");
|
||||
json_object* profiles = json_object_object_get(root, "profiles");
|
||||
if (!profiles)
|
||||
return "json_object_object_get(root, \"profiles\") failed";
|
||||
|
||||
@ -153,29 +118,29 @@ static const char* detectFromWTImpl(const FFinstance* instance, FFstrbuf* conten
|
||||
ffStrbufTrim(&wtProfileId, '\'');
|
||||
if (wtProfileId.length > 0)
|
||||
{
|
||||
array_list* list = data.ffjson_object_get_array(data.ffjson_object_object_get(profiles, "list"));
|
||||
array_list* list = json_object_get_array(json_object_object_get(profiles, "list"));
|
||||
if (list)
|
||||
{
|
||||
for (size_t idx = 0; idx < list->length; ++idx)
|
||||
{
|
||||
json_object* profile = (json_object*) list->array[idx];
|
||||
json_object* guid = data.ffjson_object_object_get(profile, "guid");
|
||||
json_object* guid = json_object_object_get(profile, "guid");
|
||||
|
||||
if (!data.ffjson_object_is_type(guid, json_type_string))
|
||||
if (!json_object_is_type(guid, json_type_string))
|
||||
continue;
|
||||
|
||||
if(ffStrbufEqualS(&wtProfileId, data.ffjson_object_get_string(guid)))
|
||||
if(ffStrbufEqualS(&wtProfileId, json_object_get_string(guid)))
|
||||
{
|
||||
detectWTProfile(&data, profile, name, size);
|
||||
detectWTProfile(profile, name, size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
json_object* defaults = data.ffjson_object_object_get(profiles, "defaults");
|
||||
json_object* defaults = json_object_object_get(profiles, "defaults");
|
||||
if (defaults)
|
||||
detectWTProfile(&data, defaults, name, size);
|
||||
detectWTProfile(defaults, name, size);
|
||||
|
||||
if(name->length == 0)
|
||||
ffStrbufSetS(name, "Cascadia Mono");
|
||||
|
@ -18,8 +18,7 @@
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
|
||||
#include "modules/os/os.h"
|
||||
#include "common/config.h"
|
||||
#include "common/jsonconfig.h"
|
||||
#include "modules/modules.h"
|
||||
|
||||
typedef struct CustomValue
|
||||
|
@ -148,7 +148,7 @@ void ffDestroyBatteryOptions(FFBatteryOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseBatteryJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseBatteryJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_BATTERY_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -156,29 +156,32 @@ bool ffParseBatteryJsonObject(FFinstance* instance, const char* type, JSONCData*
|
||||
FFBatteryOptions __attribute__((__cleanup__(ffDestroyBatteryOptions))) options;
|
||||
ffInitBatteryOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
#ifdef __linux__
|
||||
if (strcasecmp(key, "dir") == 0)
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
ffStrbufSetS(&options.dir, data->ffjson_object_get_string(val));
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (strcasecmp(key, "temp") == 0)
|
||||
{
|
||||
options.temp = (bool) data->ffjson_object_get_boolean(val);
|
||||
continue;
|
||||
}
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
#ifdef __linux__
|
||||
if (strcasecmp(key, "dir") == 0)
|
||||
{
|
||||
ffStrbufSetS(&options.dir, json_object_get_string(val));
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (strcasecmp(key, "temp") == 0)
|
||||
{
|
||||
options.temp = (bool) json_object_get_boolean(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintBattery(instance, &options);
|
||||
|
@ -9,6 +9,6 @@ bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, co
|
||||
void ffDestroyBatteryOptions(FFBatteryOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseBatteryJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseBatteryJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -68,7 +68,7 @@ void ffDestroyBiosOptions(FFBiosOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseBiosJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseBiosJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_BIOS_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -76,15 +76,18 @@ bool ffParseBiosJsonObject(FFinstance* instance, const char* type, JSONCData* da
|
||||
FFBiosOptions __attribute__((__cleanup__(ffDestroyBiosOptions))) options;
|
||||
ffInitBiosOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
|
||||
continue;
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_BIOS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
ffPrintError(instance, FF_BIOS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintBios(instance, &options);
|
||||
|
@ -8,6 +8,6 @@ bool ffParseBiosCommandOptions(FFBiosOptions* options, const char* key, const ch
|
||||
void ffDestroyBiosOptions(FFBiosOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseBiosJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseBiosJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -89,7 +89,7 @@ void ffDestroyBluetoothOptions(FFBluetoothOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseBluetoothJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseBluetoothJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_BLUETOOTH_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -97,21 +97,24 @@ bool ffParseBluetoothJsonObject(FFinstance* instance, const char* type, JSONCDat
|
||||
FFBluetoothOptions __attribute__((__cleanup__(ffDestroyBluetoothOptions))) options;
|
||||
ffInitBluetoothOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
if (strcasecmp(key, "showConnected") == 0)
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
options.showDisconnected = data->ffjson_object_get_boolean(val);
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_BLUETOOTH_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
if (strcasecmp(key, "showConnected") == 0)
|
||||
{
|
||||
options.showDisconnected = json_object_get_boolean(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
ffPrintError(instance, FF_BLUETOOTH_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintBluetooth(instance, &options);
|
||||
|
@ -8,6 +8,6 @@ bool ffParseBluetoothCommandOptions(FFBluetoothOptions* options, const char* key
|
||||
void ffDestroyBluetoothOptions(FFBluetoothOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseBluetoothJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseBluetoothJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -66,7 +66,7 @@ void ffDestroyBoardOptions(FFBoardOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseBoardJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseBoardJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_BOARD_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -74,15 +74,18 @@ bool ffParseBoardJsonObject(FFinstance* instance, const char* type, JSONCData* d
|
||||
FFBoardOptions __attribute__((__cleanup__(ffDestroyBoardOptions))) options;
|
||||
ffInitBoardOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
|
||||
continue;
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_BOARD_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
ffPrintError(instance, FF_BOARD_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintBoard(instance, &options);
|
||||
|
@ -8,6 +8,6 @@ bool ffParseBoardCommandOptions(FFBoardOptions* options, const char* key, const
|
||||
void ffDestroyBoardOptions(FFBoardOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseBoardJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseBoardJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -11,7 +11,7 @@ void ffPrintBreak(FFinstance* instance)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseBreakJsonObject(FFinstance* instance, const char* type, FF_MAYBE_UNUSED JSONCData* data, FF_MAYBE_UNUSED json_object* module)
|
||||
bool ffParseBreakJsonObject(FFinstance* instance, const char* type, FF_MAYBE_UNUSED json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_BREAK_MODULE_NAME) != 0)
|
||||
return false;
|
||||
|
@ -5,6 +5,6 @@
|
||||
void ffPrintBreak(FFinstance* instance);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseBreakJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseBreakJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -80,7 +80,7 @@ void ffDestroyBrightnessOptions(FFBrightnessOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseBrightnessJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseBrightnessJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_BRIGHTNESS_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -88,15 +88,18 @@ bool ffParseBrightnessJsonObject(FFinstance* instance, const char* type, JSONCDa
|
||||
FFBrightnessOptions __attribute__((__cleanup__(ffDestroyBrightnessOptions))) options;
|
||||
ffInitBrightnessOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
|
||||
continue;
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_BRIGHTNESS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
ffPrintError(instance, FF_BRIGHTNESS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintBrightness(instance, &options);
|
||||
|
@ -8,6 +8,6 @@ bool ffParseBrightnessCommandOptions(FFBrightnessOptions* options, const char* k
|
||||
void ffDestroyBrightnessOptions(FFBrightnessOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseBrightnessJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseBrightnessJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -85,7 +85,7 @@ void ffDestroyCommandOptions(FFCommandOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseCommandJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseCommandJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_COMMAND_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -93,27 +93,30 @@ bool ffParseCommandJsonObject(FFinstance* instance, const char* type, JSONCData*
|
||||
FFCommandOptions __attribute__((__cleanup__(ffDestroyCommandOptions))) options;
|
||||
ffInitCommandOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
if (strcasecmp(key, "shell") == 0)
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
ffStrbufSetS(&options.shell, data->ffjson_object_get_string(val));
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (strcasecmp(key, "text") == 0)
|
||||
{
|
||||
ffStrbufSetS(&options.text, data->ffjson_object_get_string(val));
|
||||
continue;
|
||||
}
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_COMMAND_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
if (strcasecmp(key, "shell") == 0)
|
||||
{
|
||||
ffStrbufSetS(&options.shell, json_object_get_string(val));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strcasecmp(key, "text") == 0)
|
||||
{
|
||||
ffStrbufSetS(&options.text, json_object_get_string(val));
|
||||
continue;
|
||||
}
|
||||
|
||||
ffPrintError(instance, FF_COMMAND_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintCommand(instance, &options);
|
||||
|
@ -8,6 +8,6 @@ bool ffParseCommandCommandOptions(FFCommandOptions* options, const char* key, co
|
||||
void ffDestroyCommandOptions(FFCommandOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseCommandJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseCommandJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -71,7 +71,7 @@ void ffDestroyDateTimeOptions(FFDateTimeOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseDateTimeJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseDateTimeJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_DATETIME_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -79,15 +79,18 @@ bool ffParseDateTimeJsonObject(FFinstance* instance, const char* type, JSONCData
|
||||
FFDateTimeOptions __attribute__((__cleanup__(ffDestroyDateTimeOptions))) options;
|
||||
ffInitDateTimeOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
|
||||
continue;
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_DATETIME_DISPLAY_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
ffPrintError(instance, FF_DATETIME_DISPLAY_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintDateTime(instance, &options);
|
||||
|
@ -8,6 +8,6 @@ bool ffParseDateTimeCommandOptions(FFDateTimeOptions* options, const char* key,
|
||||
void ffDestroyDateTimeOptions(FFDateTimeOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseDateTimeJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseDateTimeJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -159,7 +159,7 @@ void ffDestroyDisplayOptions(FFDisplayOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseDisplayJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseDisplayJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_DISPLAY_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -167,43 +167,46 @@ bool ffParseDisplayJsonObject(FFinstance* instance, const char* type, JSONCData*
|
||||
FFDisplayOptions __attribute__((__cleanup__(ffDestroyDisplayOptions))) options;
|
||||
ffInitDisplayOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
if (strcasecmp(key, "compactType") == 0)
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(data, val, &value, (FFKeyValuePair[]) {
|
||||
{ "none", FF_DISPLAY_COMPACT_TYPE_NONE },
|
||||
{ "original", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT },
|
||||
{ "scaled", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT },
|
||||
{},
|
||||
});
|
||||
if (error)
|
||||
ffPrintError(instance, FF_DISPLAY_MODULE_NAME, 0, &options.moduleArgs, "Invalid %s value: %s", key, error);
|
||||
else
|
||||
options.compactType = (FFDisplayCompactType) value;
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (strcasecmp(key, "detectName") == 0)
|
||||
{
|
||||
options.detectName = data->ffjson_object_get_boolean(val);
|
||||
continue;
|
||||
}
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
if (strcasecmp(key, "preciseRefreshRate") == 0)
|
||||
{
|
||||
options.preciseRefreshRate = data->ffjson_object_get_boolean(val);
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(key, "compactType") == 0)
|
||||
{
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
|
||||
{ "none", FF_DISPLAY_COMPACT_TYPE_NONE },
|
||||
{ "original", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT },
|
||||
{ "scaled", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT },
|
||||
{},
|
||||
});
|
||||
if (error)
|
||||
ffPrintError(instance, FF_DISPLAY_MODULE_NAME, 0, &options.moduleArgs, "Invalid %s value: %s", key, error);
|
||||
else
|
||||
options.compactType = (FFDisplayCompactType) value;
|
||||
continue;
|
||||
}
|
||||
|
||||
ffPrintError(instance, FF_DISPLAY_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
if (strcasecmp(key, "detectName") == 0)
|
||||
{
|
||||
options.detectName = json_object_get_boolean(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strcasecmp(key, "preciseRefreshRate") == 0)
|
||||
{
|
||||
options.preciseRefreshRate = json_object_get_boolean(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
ffPrintError(instance, FF_DISPLAY_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintDisplay(instance, &options);
|
||||
|
@ -8,6 +8,6 @@ bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, co
|
||||
void ffDestroyDisplayOptions(FFDisplayOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseDisplayJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseDisplayJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -77,7 +77,7 @@ void ffDestroyHostOptions(FFHostOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseHostJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseHostJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_HOST_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -85,15 +85,18 @@ bool ffParseHostJsonObject(FFinstance* instance, const char* type, JSONCData* da
|
||||
FFHostOptions __attribute__((__cleanup__(ffDestroyHostOptions))) options;
|
||||
ffInitHostOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
|
||||
continue;
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintHost(instance, &options);
|
||||
|
@ -8,6 +8,6 @@ bool ffParseHostCommandOptions(FFHostOptions* options, const char* key, const ch
|
||||
void ffDestroyHostOptions(FFHostOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseHostJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseHostJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -1,71 +1,59 @@
|
||||
#include "modules/jsonconfig/jsonconfig.h"
|
||||
#include "common/config.h"
|
||||
#include "common/jsonconfig.h"
|
||||
#include "common/printing.h"
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
|
||||
#include "common/io/io.h"
|
||||
#include "common/json.h"
|
||||
#include "modules/modules.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static inline bool parseModuleJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
static inline bool parseModuleJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
return
|
||||
ffParseTitleJsonObject(instance, type, data, module) ||
|
||||
ffParseBatteryJsonObject(instance, type, data, module) ||
|
||||
ffParseBiosJsonObject(instance, type, data, module) ||
|
||||
ffParseBluetoothJsonObject(instance, type, data, module) ||
|
||||
ffParseBoardJsonObject(instance, type, data, module) ||
|
||||
ffParseBreakJsonObject(instance, type, data, module) ||
|
||||
ffParseBrightnessJsonObject(instance, type, data, module) ||
|
||||
ffParseCommandJsonObject(instance, type, data, module) ||
|
||||
ffParseDateTimeJsonObject(instance, type, data, module) ||
|
||||
ffParseDisplayJsonObject(instance, type, data, module) ||
|
||||
ffParseHostJsonObject(instance, type, data, module) ||
|
||||
ffParseKernelJsonObject(instance, type, data, module) ||
|
||||
ffParseOSJsonObject(instance, type, data, module) ||
|
||||
ffParseSeparatorJsonObject(instance, type, data, module) ||
|
||||
ffParseTitleJsonObject(instance, type, module) ||
|
||||
ffParseBatteryJsonObject(instance, type, module) ||
|
||||
ffParseBiosJsonObject(instance, type, module) ||
|
||||
ffParseBluetoothJsonObject(instance, type, module) ||
|
||||
ffParseBoardJsonObject(instance, type, module) ||
|
||||
ffParseBreakJsonObject(instance, type, module) ||
|
||||
ffParseBrightnessJsonObject(instance, type, module) ||
|
||||
ffParseCommandJsonObject(instance, type, module) ||
|
||||
ffParseDateTimeJsonObject(instance, type, module) ||
|
||||
ffParseDisplayJsonObject(instance, type, module) ||
|
||||
ffParseHostJsonObject(instance, type, module) ||
|
||||
ffParseKernelJsonObject(instance, type, module) ||
|
||||
ffParseOSJsonObject(instance, type, module) ||
|
||||
ffParseSeparatorJsonObject(instance, type, module) ||
|
||||
false;
|
||||
}
|
||||
|
||||
typedef struct JsonConfigData
|
||||
static const char* parseModules(FFinstance* instance, json_object* modules)
|
||||
{
|
||||
JSONCData data;
|
||||
json_object* root;
|
||||
} JsonConfigData;
|
||||
|
||||
static inline void wrapJsoncFree(JsonConfigData* jsonConfig)
|
||||
{
|
||||
assert(jsonConfig);
|
||||
if (jsonConfig->root)
|
||||
jsonConfig->data.ffjson_object_put(jsonConfig->root);
|
||||
}
|
||||
|
||||
static const char* parseModules(FFinstance* instance, JSONCData* data, json_object* modules)
|
||||
{
|
||||
array_list* list = data->ffjson_object_get_array(modules);
|
||||
array_list* list = json_object_get_array(modules);
|
||||
if (!list) return "modules must be an array of strings or objects";
|
||||
|
||||
for (size_t idx = 0; idx < list->length; ++idx)
|
||||
{
|
||||
json_object* module = (json_object*) list->array[idx];
|
||||
const char* type = NULL;
|
||||
if (data->ffjson_object_is_type(module, json_type_string))
|
||||
if (json_object_is_type(module, json_type_string))
|
||||
{
|
||||
type = data->ffjson_object_get_string(module);
|
||||
type = json_object_get_string(module);
|
||||
module = NULL;
|
||||
}
|
||||
else if (data->ffjson_object_is_type(module, json_type_object))
|
||||
else if (json_object_is_type(module, json_type_object))
|
||||
{
|
||||
json_object* object = data->ffjson_object_object_get(module, "type");
|
||||
type = data->ffjson_object_get_string(object);
|
||||
json_object* object = json_object_object_get(module, "type");
|
||||
type = json_object_get_string(object);
|
||||
if (!type) return "module object must contain a type key";
|
||||
}
|
||||
else
|
||||
return "modules must be an array of strings or objects";
|
||||
|
||||
if(!parseModuleJsonObject(instance, type, data, module))
|
||||
if(!parseModuleJsonObject(instance, type, module))
|
||||
return "Unknown module type";
|
||||
}
|
||||
|
||||
@ -74,26 +62,8 @@ static const char* parseModules(FFinstance* instance, JSONCData* data, json_obje
|
||||
|
||||
static const char* printJsonConfig(FFinstance* instance)
|
||||
{
|
||||
FF_LIBRARY_LOAD(libjsonc, &instance->config.libJSONC, "dlopen libjson-c" FF_LIBRARY_EXTENSION" failed",
|
||||
#ifdef _WIN32
|
||||
"libjson-c-5" FF_LIBRARY_EXTENSION, -1
|
||||
#else
|
||||
"libjson-c" FF_LIBRARY_EXTENSION, 5
|
||||
#endif
|
||||
)
|
||||
JsonConfigData __attribute__((__cleanup__(wrapJsoncFree))) jsonConfig = {};
|
||||
JSONCData* data = &jsonConfig.data;
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_tokener_parse)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_is_type)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_array)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_boolean)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_double)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_int)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_string_len)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_string)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_object)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_object_get)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_put)
|
||||
if (!ffJsonLoadLibrary(instance))
|
||||
return "Failed to load json-c library";
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY content;
|
||||
ffStrbufInit(&content);
|
||||
@ -106,11 +76,11 @@ static const char* printJsonConfig(FFinstance* instance)
|
||||
if (success) break;
|
||||
}
|
||||
|
||||
jsonConfig.root = data->ffjson_tokener_parse(content.chars);
|
||||
if (!jsonConfig.root)
|
||||
json_object* __attribute__((__cleanup__(wrapJsoncFree))) root = json_tokener_parse(content.chars);
|
||||
if (!root)
|
||||
return "Failed to parse JSON config file";
|
||||
|
||||
lh_table* rootObject = data->ffjson_object_get_object(jsonConfig.root);
|
||||
lh_table* rootObject = json_object_get_object(root);
|
||||
if (!rootObject)
|
||||
return "Invalid JSON config format. Root value must be an object";
|
||||
|
||||
@ -118,11 +88,11 @@ static const char* printJsonConfig(FFinstance* instance)
|
||||
lh_foreach(rootObject, entry)
|
||||
{
|
||||
const char* key = (const char *)lh_entry_k(entry);
|
||||
json_object* val = (struct json_object *)lh_entry_v(entry);
|
||||
json_object* val = (json_object *)lh_entry_v(entry);
|
||||
|
||||
if (strcmp(key, "modules") == 0)
|
||||
{
|
||||
const char* error = parseModules(instance, data, val);
|
||||
const char* error = parseModules(instance, val);
|
||||
if (error) return error;
|
||||
}
|
||||
else
|
||||
|
@ -52,7 +52,7 @@ void ffDestroyKernelOptions(FFKernelOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseKernelJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseKernelJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_KERNEL_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -60,15 +60,18 @@ bool ffParseKernelJsonObject(FFinstance* instance, const char* type, JSONCData*
|
||||
FFKernelOptions __attribute__((__cleanup__(ffDestroyKernelOptions))) options;
|
||||
ffInitKernelOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
|
||||
continue;
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_KERNEL_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
ffPrintError(instance, FF_KERNEL_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintKernel(instance, &options);
|
||||
|
@ -9,6 +9,6 @@ bool ffParseKernelCommandOptions(FFKernelOptions* options, const char* key, cons
|
||||
void ffDestroyKernelOptions(FFKernelOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseKernelJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseKernelJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -175,7 +175,7 @@ void ffDestroyOSOptions(FFOSOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseOSJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseOSJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_OS_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -183,23 +183,26 @@ bool ffParseOSJsonObject(FFinstance* instance, const char* type, JSONCData* data
|
||||
FFOSOptions __attribute__((__cleanup__(ffDestroyOSOptions))) options;
|
||||
ffInitOSOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
if (strcasecmp(key, "file") == 0)
|
||||
{
|
||||
ffStrbufSetS(&options.file, data->ffjson_object_get_string(val));
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
ffPrintError(instance, FF_OS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
if (strcasecmp(key, "file") == 0)
|
||||
{
|
||||
ffStrbufSetS(&options.file, json_object_get_string(val));
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
ffPrintError(instance, FF_OS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintOS(instance, &options);
|
||||
|
@ -9,6 +9,6 @@ bool ffParseOSCommandOptions(FFOSOptions* options, const char* key, const char*
|
||||
void ffDestroyOSOptions(FFOSOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseOSJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseOSJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -61,7 +61,7 @@ void ffDestroySeparatorOptions(FFSeparatorOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseSeparatorJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseSeparatorJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_SEPARATOR_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -69,18 +69,21 @@ bool ffParseSeparatorJsonObject(FFinstance* instance, const char* type, JSONCDat
|
||||
FFSeparatorOptions __attribute__((__cleanup__(ffDestroySeparatorOptions))) options;
|
||||
ffInitSeparatorOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (strcasecmp(key, "string") == 0)
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
ffStrbufSetS(&options.string, data->ffjson_object_get_string(val));
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
ffPrintErrorString(instance, FF_SEPARATOR_MODULE_NAME, 0, NULL, NULL, "Unknown JSON key %s", key);
|
||||
if (strcasecmp(key, "string") == 0)
|
||||
{
|
||||
ffStrbufSetS(&options.string, json_object_get_string(val));
|
||||
continue;
|
||||
}
|
||||
|
||||
ffPrintErrorString(instance, FF_SEPARATOR_MODULE_NAME, 0, NULL, NULL, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintSeparator(instance, &options);
|
||||
|
@ -9,6 +9,6 @@ bool ffParseSeparatorCommandOptions(FFSeparatorOptions* options, const char* key
|
||||
void ffDestroySeparatorOptions(FFSeparatorOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseSeparatorJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseSeparatorJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
@ -61,7 +61,7 @@ void ffDestroyTitleOptions(FFTitleOptions* options)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
bool ffParseTitleJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
|
||||
bool ffParseTitleJsonObject(FFinstance* instance, const char* type, json_object* module)
|
||||
{
|
||||
if (strcasecmp(type, FF_TITLE_MODULE_NAME) != 0)
|
||||
return false;
|
||||
@ -69,18 +69,21 @@ bool ffParseTitleJsonObject(FFinstance* instance, const char* type, JSONCData* d
|
||||
FFTitleOptions __attribute__((__cleanup__(ffDestroyTitleOptions))) options;
|
||||
ffInitTitleOptions(&options);
|
||||
|
||||
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
|
||||
if (module)
|
||||
{
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
if (strcasecmp(key, "fdqn") == 0)
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
options.fdqn = data->ffjson_object_get_boolean(val);
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(key, "type") == 0)
|
||||
continue;
|
||||
|
||||
ffPrintErrorString(instance, FF_TITLE_MODULE_NAME, 0, NULL, NULL, "Unknown JSON key %s", key);
|
||||
if (strcasecmp(key, "fdqn") == 0)
|
||||
{
|
||||
options.fdqn = json_object_get_boolean(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
ffPrintErrorString(instance, FF_TITLE_MODULE_NAME, 0, NULL, NULL, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintTitle(instance, &options);
|
||||
|
@ -9,6 +9,6 @@ bool ffParseTitleCommandOptions(FFTitleOptions* options, const char* key, const
|
||||
void ffDestroyTitleOptions(FFTitleOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/config.h"
|
||||
bool ffParseTitleJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
|
||||
#include "common/jsonconfig.h"
|
||||
bool ffParseTitleJsonObject(FFinstance* instance, const char* type, json_object* module);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user