Global: make FFinstance instance a global variable

As discussed in https://github.com/fastfetch-cli/fastfetch/discussions/473
This commit is contained in:
李通洲
2023-06-24 10:59:53 +08:00
parent 48b01c9665
commit d0f093c567
255 changed files with 2020 additions and 2064 deletions
+11 -11
View File
@@ -6,44 +6,44 @@
#define FF_GAMEPAD_NUM_FORMAT_ARGS 2
static void printDevice(FFinstance* instance, FFGamepadOptions* options, const FFGamepadDevice* device, uint8_t index)
static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device, uint8_t index)
{
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs.key, &options->moduleArgs.keyColor);
ffPrintLogoAndKey(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs.key, &options->moduleArgs.keyColor);
ffStrbufPutTo(&device->name, stdout);
}
else
{
ffPrintFormat(instance, FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_GAMEPAD_NUM_FORMAT_ARGS, (FFformatarg[]) {
ffPrintFormat(FF_GAMEPAD_MODULE_NAME, index, &options->moduleArgs, FF_GAMEPAD_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &device->name},
{FF_FORMAT_ARG_TYPE_STRBUF, &device->identifier},
});
}
}
void ffPrintGamepad(FFinstance* instance, FFGamepadOptions* options)
void ffPrintGamepad(FFGamepadOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFGamepadDevice));
const char* error = ffDetectGamepad(instance, &result);
const char* error = ffDetectGamepad(&result);
if(error)
{
ffPrintError(instance, FF_GAMEPAD_MODULE_NAME, 0, &options->moduleArgs, "%s", error);
ffPrintError(FF_GAMEPAD_MODULE_NAME, 0, &options->moduleArgs, "%s", error);
return;
}
if(!result.length)
{
ffPrintError(instance, FF_GAMEPAD_MODULE_NAME, 0, &options->moduleArgs, "No devices detected");
ffPrintError(FF_GAMEPAD_MODULE_NAME, 0, &options->moduleArgs, "No devices detected");
return;
}
uint8_t index = 0;
FF_LIST_FOR_EACH(FFGamepadDevice, device, result)
{
printDevice(instance, options, device, result.length > 1 ? ++index : 0);
printDevice(options, device, result.length > 1 ? ++index : 0);
ffStrbufDestroy(&device->identifier);
ffStrbufDestroy(&device->name);
}
@@ -70,7 +70,7 @@ void ffDestroyGamepadOptions(FFGamepadOptions* options)
ffOptionDestroyModuleArg(&options->moduleArgs);
}
void ffParseGamepadJsonObject(FFinstance* instance, yyjson_val* module)
void ffParseGamepadJsonObject(yyjson_val* module)
{
FFGamepadOptions __attribute__((__cleanup__(ffDestroyGamepadOptions))) options;
ffInitGamepadOptions(&options);
@@ -88,9 +88,9 @@ void ffParseGamepadJsonObject(FFinstance* instance, yyjson_val* module)
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
ffPrintError(instance, FF_GAMEPAD_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
ffPrintError(FF_GAMEPAD_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
}
ffPrintGamepad(instance, &options);
ffPrintGamepad(&options);
}
+2 -2
View File
@@ -4,8 +4,8 @@
#define FF_GAMEPAD_MODULE_NAME "Gamepad"
void ffPrintGamepad(FFinstance* instance, FFGamepadOptions* options);
void ffPrintGamepad(FFGamepadOptions* options);
void ffInitGamepadOptions(FFGamepadOptions* options);
bool ffParseGamepadCommandOptions(FFGamepadOptions* options, const char* key, const char* value);
void ffDestroyGamepadOptions(FFGamepadOptions* options);
void ffParseGamepadJsonObject(FFinstance* instance, yyjson_val* module);
void ffParseGamepadJsonObject(yyjson_val* module);