2023-03-07 14:56:13 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "util/FFstrbuf.h"
|
2023-08-19 11:10:14 +08:00
|
|
|
|
|
|
|
|
struct yyjson_val;
|
2023-08-29 11:13:55 +08:00
|
|
|
struct yyjson_mut_doc;
|
|
|
|
|
struct yyjson_mut_val;
|
2023-08-17 10:56:54 +08:00
|
|
|
|
|
|
|
|
// Must be the first field of FFModuleOptions
|
|
|
|
|
typedef struct FFModuleBaseInfo
|
|
|
|
|
{
|
|
|
|
|
const char* name;
|
2023-08-17 16:00:24 +08:00
|
|
|
bool (*parseCommandOptions)(void* options, const char* key, const char* value);
|
2023-08-19 11:10:14 +08:00
|
|
|
void (*parseJsonObject)(void* options, struct yyjson_val *module);
|
2023-08-17 10:56:54 +08:00
|
|
|
void (*printModule)(void* options);
|
2023-08-29 11:13:55 +08:00
|
|
|
void (*generateJson)(void* options, struct yyjson_mut_doc* doc, struct yyjson_mut_val* module);
|
2023-08-17 10:56:54 +08:00
|
|
|
} FFModuleBaseInfo;
|
|
|
|
|
|
|
|
|
|
static inline void ffOptionInitModuleBaseInfo(
|
|
|
|
|
FFModuleBaseInfo* baseInfo,
|
|
|
|
|
const char* name,
|
2023-08-17 16:00:24 +08:00
|
|
|
void* parseCommandOptions, // bool (*const parseCommandOptions)(void* options, const char* key, const char* value)
|
2023-08-17 10:56:54 +08:00
|
|
|
void* parseJsonObject, // void (*const parseJsonObject)(void* options, yyjson_val *module)
|
2023-08-29 11:13:55 +08:00
|
|
|
void* printModule, // void (*const printModule)(void* options)
|
|
|
|
|
void* generateJson // void (*const generateJson)(void* options, yyjson_mut_doc* doc, yyjson_mut_val* obj)
|
2023-08-17 10:56:54 +08:00
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
baseInfo->name = name;
|
2023-08-17 17:15:30 +08:00
|
|
|
baseInfo->parseCommandOptions = (__typeof__(baseInfo->parseCommandOptions)) parseCommandOptions;
|
|
|
|
|
baseInfo->parseJsonObject = (__typeof__(baseInfo->parseJsonObject)) parseJsonObject;
|
|
|
|
|
baseInfo->printModule = (__typeof__(baseInfo->printModule)) printModule;
|
2023-08-29 11:13:55 +08:00
|
|
|
baseInfo->generateJson = (__typeof__(baseInfo->generateJson)) generateJson;
|
2023-08-17 10:56:54 +08:00
|
|
|
}
|
2023-03-07 14:56:13 +08:00
|
|
|
|
|
|
|
|
typedef struct FFModuleArgs
|
|
|
|
|
{
|
|
|
|
|
FFstrbuf key;
|
2023-06-18 12:32:47 +08:00
|
|
|
FFstrbuf keyColor;
|
2023-03-07 14:56:13 +08:00
|
|
|
FFstrbuf outputFormat;
|
2023-08-15 21:40:22 +08:00
|
|
|
uint32_t keyWidth;
|
2023-03-07 14:56:13 +08:00
|
|
|
} FFModuleArgs;
|
|
|
|
|
|
2023-03-10 10:56:36 +08:00
|
|
|
typedef struct FFKeyValuePair
|
|
|
|
|
{
|
|
|
|
|
const char* key;
|
|
|
|
|
int value;
|
|
|
|
|
} FFKeyValuePair;
|
|
|
|
|
|
2023-03-07 14:56:13 +08:00
|
|
|
const char* ffOptionTestPrefix(const char* argumentKey, const char* moduleName);
|
|
|
|
|
bool ffOptionParseModuleArgs(const char* argumentKey, const char* pkey, const char* value, FFModuleArgs* result);
|
|
|
|
|
void ffOptionParseString(const char* argumentKey, const char* value, FFstrbuf* buffer);
|
2023-03-10 10:56:36 +08:00
|
|
|
FF_C_NODISCARD uint32_t ffOptionParseUInt32(const char* argumentKey, const char* value);
|
2023-06-25 14:33:13 +08:00
|
|
|
FF_C_NODISCARD int32_t ffOptionParseInt32(const char* argumentKey, const char* value);
|
2023-03-10 10:56:36 +08:00
|
|
|
FF_C_NODISCARD int ffOptionParseEnum(const char* argumentKey, const char* requestedKey, FFKeyValuePair pairs[]);
|
|
|
|
|
FF_C_NODISCARD bool ffOptionParseBoolean(const char* str);
|
2023-06-10 21:34:41 +08:00
|
|
|
void ffOptionParseColor(const char* value, FFstrbuf* buffer);
|
2023-03-07 14:56:13 +08:00
|
|
|
void ffOptionInitModuleArg(FFModuleArgs* args);
|
|
|
|
|
void ffOptionDestroyModuleArg(FFModuleArgs* args);
|