Modules: return bool to indicate whether the detection is succeeded

This commit is contained in:
李通洲
2025-08-18 13:38:30 +08:00
parent a9aaa36b2c
commit 3b5e9c74d6
147 changed files with 869 additions and 538 deletions
+8 -5
View File
@@ -125,7 +125,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin
}
}
void ffPrintBattery(FFBatteryOptions* options)
bool ffPrintBattery(FFBatteryOptions* options)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBatteryResult));
@@ -134,12 +134,12 @@ void ffPrintBattery(FFBatteryOptions* options)
if (error)
{
ffPrintError(FF_BATTERY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if(results.length == 0)
{
ffPrintError(FF_BATTERY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", "No batteries found");
return;
return false;
}
for(uint32_t i = 0; i < results.length; i++)
@@ -157,6 +157,7 @@ void ffPrintBattery(FFBatteryOptions* options)
ffStrbufDestroy(&result->serial);
ffStrbufDestroy(&result->manufactureDate);
}
return true;
}
void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module)
@@ -198,7 +199,7 @@ void ffGenerateBatteryJsonConfig(FFBatteryOptions* options, yyjson_mut_doc* doc,
ffPercentGenerateJsonConfig(doc, module, options->percent);
}
void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBatteryResult));
@@ -206,7 +207,7 @@ void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc,
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -241,6 +242,8 @@ void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc,
ffStrbufDestroy(&battery->status);
ffStrbufDestroy(&battery->serial);
}
return true;
}
void ffInitBatteryOptions(FFBatteryOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_BATTERY_MODULE_NAME "Battery"
void ffPrintBattery(FFBatteryOptions* options);
bool ffPrintBattery(FFBatteryOptions* options);
void ffInitBatteryOptions(FFBatteryOptions* options);
void ffDestroyBatteryOptions(FFBatteryOptions* options);
+9 -2
View File
@@ -4,8 +4,9 @@
#include "modules/bios/bios.h"
#include "util/stringUtils.h"
void ffPrintBios(FFBiosOptions* options)
bool ffPrintBios(FFBiosOptions* options)
{
bool success = false;
FFBiosResult bios;
ffStrbufInit(&bios.date);
ffStrbufInit(&bios.release);
@@ -66,6 +67,7 @@ void ffPrintBios(FFBiosOptions* options)
FF_FORMAT_ARG(bios.type, "type"),
}));
}
success = true;
exit:
ffStrbufDestroy(&bios.date);
@@ -73,6 +75,8 @@ exit:
ffStrbufDestroy(&bios.vendor);
ffStrbufDestroy(&bios.version);
ffStrbufDestroy(&bios.type);
return success;
}
void ffParseBiosJsonObject(FFBiosOptions* options, yyjson_val* module)
@@ -93,8 +97,9 @@ void ffGenerateBiosJsonConfig(FFBiosOptions* options, yyjson_mut_doc* doc, yyjso
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateBiosJsonResult(FF_MAYBE_UNUSED FFBiosOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateBiosJsonResult(FF_MAYBE_UNUSED FFBiosOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFBiosResult bios;
ffStrbufInit(&bios.date);
ffStrbufInit(&bios.release);
@@ -116,6 +121,7 @@ void ffGenerateBiosJsonResult(FF_MAYBE_UNUSED FFBiosOptions* options, yyjson_mut
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &bios.vendor);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &bios.version);
yyjson_mut_obj_add_strbuf(doc, obj, "type", &bios.type);
success = true;
exit:
ffStrbufDestroy(&bios.date);
@@ -123,6 +129,7 @@ exit:
ffStrbufDestroy(&bios.vendor);
ffStrbufDestroy(&bios.version);
ffStrbufDestroy(&bios.type);
return success;
}
void ffInitBiosOptions(FFBiosOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_BIOS_MODULE_NAME "BIOS"
void ffPrintBios(FFBiosOptions* options);
bool ffPrintBios(FFBiosOptions* options);
void ffInitBiosOptions(FFBiosOptions* options);
void ffDestroyBiosOptions(FFBiosOptions* options);
+22 -21
View File
@@ -56,7 +56,7 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* de
}
}
void ffPrintBluetooth(FFBluetoothOptions* options)
bool ffPrintBluetooth(FFBluetoothOptions* options)
{
FF_LIST_AUTO_DESTROY devices = ffListCreate(sizeof (FFBluetoothResult));
const char* error = ffDetectBluetooth(options, &devices);
@@ -64,29 +64,28 @@ void ffPrintBluetooth(FFBluetoothOptions* options)
if(error)
{
ffPrintError(FF_BLUETOOTH_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return false;
}
else
FF_LIST_AUTO_DESTROY filtered = ffListCreate(sizeof(FFBluetoothResult*));
FF_LIST_FOR_EACH(FFBluetoothResult, device, devices)
{
FF_LIST_AUTO_DESTROY filtered = ffListCreate(sizeof(FFBluetoothResult*));
if(!device->connected && !options->showDisconnected)
continue;
FF_LIST_FOR_EACH(FFBluetoothResult, device, devices)
{
if(!device->connected && !options->showDisconnected)
continue;
*(FFBluetoothResult**)ffListAdd(&filtered) = device;
}
*(FFBluetoothResult**)ffListAdd(&filtered) = device;
}
if(filtered.length == 0)
{
ffPrintError(FF_BLUETOOTH_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No bluetooth devices found");
}
if(filtered.length == 0)
{
ffPrintError(FF_BLUETOOTH_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No bluetooth devices found");
}
for(uint32_t i = 0; i < filtered.length; i++)
{
uint8_t index = (uint8_t) (filtered.length == 1 ? 0 : i + 1);
printDevice(options, *FF_LIST_GET(FFBluetoothResult*, filtered, i), index);
}
for(uint32_t i = 0; i < filtered.length; i++)
{
uint8_t index = (uint8_t) (filtered.length == 1 ? 0 : i + 1);
printDevice(options, *FF_LIST_GET(FFBluetoothResult*, filtered, i), index);
}
FF_LIST_FOR_EACH(FFBluetoothResult, device, devices)
@@ -95,6 +94,7 @@ void ffPrintBluetooth(FFBluetoothOptions* options)
ffStrbufDestroy(&device->type);
ffStrbufDestroy(&device->address);
}
return true;
}
void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module)
@@ -128,7 +128,7 @@ void ffGenerateBluetoothJsonConfig(FFBluetoothOptions* options, yyjson_mut_doc*
ffPercentGenerateJsonConfig(doc, module, options->percent);
}
void ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBluetoothResult));
@@ -136,7 +136,7 @@ void ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc*
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -157,6 +157,7 @@ void ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc*
ffStrbufDestroy(&device->type);
ffStrbufDestroy(&device->address);
}
return true;
}
void ffInitBluetoothOptions(FFBluetoothOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_BLUETOOTH_MODULE_NAME "Bluetooth"
void ffPrintBluetooth(FFBluetoothOptions* options);
bool ffPrintBluetooth(FFBluetoothOptions* options);
void ffInitBluetoothOptions(FFBluetoothOptions* options);
void ffDestroyBluetoothOptions(FFBluetoothOptions* options);
+21 -19
View File
@@ -67,7 +67,7 @@ static void printDevice(FFBluetoothRadioOptions* options, const FFBluetoothRadio
}
}
void ffPrintBluetoothRadio(FFBluetoothRadioOptions* options)
bool ffPrintBluetoothRadio(FFBluetoothRadioOptions* options)
{
FF_LIST_AUTO_DESTROY radios = ffListCreate(sizeof (FFBluetoothRadioResult));
const char* error = ffDetectBluetoothRadio(&radios);
@@ -75,26 +75,25 @@ void ffPrintBluetoothRadio(FFBluetoothRadioOptions* options)
if(error)
{
ffPrintError(FF_BLUETOOTHRADIO_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return false;
}
else
uint8_t index = 0;
FF_LIST_FOR_EACH(FFBluetoothRadioResult, radio, radios)
{
uint8_t index = 0;
FF_LIST_FOR_EACH(FFBluetoothRadioResult, radio, radios)
{
if (!radio->enabled)
continue;
if (!radio->enabled)
continue;
index++;
printDevice(options, radio, index);
}
index++;
printDevice(options, radio, index);
}
if (index == 0)
{
if (radios.length > 0)
ffPrintError(FF_BLUETOOTHRADIO_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Bluetooth radios found but none enabled");
else
ffPrintError(FF_BLUETOOTHRADIO_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No devices detected");
}
if (index == 0)
{
if (radios.length > 0)
ffPrintError(FF_BLUETOOTHRADIO_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Bluetooth radios found but none enabled");
else
ffPrintError(FF_BLUETOOTHRADIO_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No devices detected");
}
FF_LIST_FOR_EACH(FFBluetoothRadioResult, radio, radios)
@@ -103,6 +102,7 @@ void ffPrintBluetoothRadio(FFBluetoothRadioOptions* options)
ffStrbufDestroy(&radio->address);
ffStrbufDestroy(&radio->vendor);
}
return true;
}
void ffParseBluetoothRadioJsonObject(FFBluetoothRadioOptions* options, yyjson_val* module)
@@ -123,7 +123,7 @@ void ffGenerateBluetoothRadioJsonConfig(FFBluetoothRadioOptions* options, yyjson
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateBluetoothRadioJsonResult(FF_MAYBE_UNUSED FFBluetoothRadioOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateBluetoothRadioJsonResult(FF_MAYBE_UNUSED FFBluetoothRadioOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBluetoothRadioResult));
@@ -131,7 +131,7 @@ void ffGenerateBluetoothRadioJsonResult(FF_MAYBE_UNUSED FFBluetoothRadioOptions*
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -161,6 +161,8 @@ void ffGenerateBluetoothRadioJsonResult(FF_MAYBE_UNUSED FFBluetoothRadioOptions*
ffStrbufDestroy(&radio->address);
ffStrbufDestroy(&radio->vendor);
}
return true;
}
void ffInitBluetoothRadioOptions(FFBluetoothRadioOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_BLUETOOTHRADIO_MODULE_NAME "BluetoothRadio"
void ffPrintBluetoothRadio(FFBluetoothRadioOptions* options);
bool ffPrintBluetoothRadio(FFBluetoothRadioOptions* options);
void ffInitBluetoothRadioOptions(FFBluetoothRadioOptions* options);
void ffDestroyBluetoothRadioOptions(FFBluetoothRadioOptions* options);
+8 -2
View File
@@ -4,8 +4,9 @@
#include "modules/board/board.h"
#include "util/stringUtils.h"
void ffPrintBoard(FFBoardOptions* options)
bool ffPrintBoard(FFBoardOptions* options)
{
bool success = false;
FFBoardResult result;
ffStrbufInit(&result.name);
ffStrbufInit(&result.vendor);
@@ -42,12 +43,14 @@ void ffPrintBoard(FFBoardOptions* options)
FF_FORMAT_ARG(result.serial, "serial"),
}));
}
success = true;
exit:
ffStrbufDestroy(&result.name);
ffStrbufDestroy(&result.vendor);
ffStrbufDestroy(&result.version);
ffStrbufDestroy(&result.serial);
return success;
}
void ffParseBoardJsonObject(FFBoardOptions* options, yyjson_val* module)
@@ -68,8 +71,9 @@ void ffGenerateBoardJsonConfig(FFBoardOptions* options, yyjson_mut_doc* doc, yyj
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateBoardJsonResult(FF_MAYBE_UNUSED FFBoardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateBoardJsonResult(FF_MAYBE_UNUSED FFBoardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFBoardResult board;
ffStrbufInit(&board.name);
ffStrbufInit(&board.vendor);
@@ -95,12 +99,14 @@ void ffGenerateBoardJsonResult(FF_MAYBE_UNUSED FFBoardOptions* options, yyjson_m
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &board.vendor);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &board.version);
yyjson_mut_obj_add_strbuf(doc, obj, "serial", &board.serial);
success = true;
exit:
ffStrbufDestroy(&board.name);
ffStrbufDestroy(&board.vendor);
ffStrbufDestroy(&board.version);
ffStrbufDestroy(&board.serial);
return success;
}
void ffInitBoardOptions(FFBoardOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_BOARD_MODULE_NAME "Board"
void ffPrintBoard(FFBoardOptions* options);
bool ffPrintBoard(FFBoardOptions* options);
void ffInitBoardOptions(FFBoardOptions* options);
void ffDestroyBoardOptions(FFBoardOptions* options);
+38 -28
View File
@@ -4,8 +4,9 @@
#include "modules/bootmgr/bootmgr.h"
#include "util/stringUtils.h"
void ffPrintBootmgr(FFBootmgrOptions* options)
bool ffPrintBootmgr(FFBootmgrOptions* options)
{
bool success = false;
FFBootmgrResult bootmgr = {
.name = ffStrbufCreate(),
.firmware = ffStrbufCreate(),
@@ -16,38 +17,44 @@ void ffPrintBootmgr(FFBootmgrOptions* options)
if(error)
{
ffPrintError(FF_BOOTMGR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
}
FF_STRBUF_AUTO_DESTROY firmwareName = ffStrbufCreateCopy(&bootmgr.firmware);
#ifndef __APPLE__
ffStrbufSubstrAfterLastC(&firmwareName, '\\');
#else
ffStrbufSubstrAfterLastC(&firmwareName, '/');
#endif
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_BOOTMGR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&bootmgr.name, stdout);
if (firmwareName.length > 0)
printf(" - %s\n", firmwareName.chars);
else
putchar('\n');
goto exit;
}
else
{
FF_PRINT_FORMAT_CHECKED(FF_BOOTMGR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
FF_FORMAT_ARG(bootmgr.name, "name"),
FF_FORMAT_ARG(bootmgr.firmware, "firmware-path"),
FF_FORMAT_ARG(firmwareName, "firmware-name"),
FF_FORMAT_ARG(bootmgr.secureBoot, "secure-boot"),
FF_FORMAT_ARG(bootmgr.order, "order"),
}));
}
FF_STRBUF_AUTO_DESTROY firmwareName = ffStrbufCreateCopy(&bootmgr.firmware);
#ifndef __APPLE__
ffStrbufSubstrAfterLastC(&firmwareName, '\\');
#else
ffStrbufSubstrAfterLastC(&firmwareName, '/');
#endif
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_BOOTMGR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufWriteTo(&bootmgr.name, stdout);
if (firmwareName.length > 0)
printf(" - %s\n", firmwareName.chars);
else
putchar('\n');
}
else
{
FF_PRINT_FORMAT_CHECKED(FF_BOOTMGR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
FF_FORMAT_ARG(bootmgr.name, "name"),
FF_FORMAT_ARG(bootmgr.firmware, "firmware-path"),
FF_FORMAT_ARG(firmwareName, "firmware-name"),
FF_FORMAT_ARG(bootmgr.secureBoot, "secure-boot"),
FF_FORMAT_ARG(bootmgr.order, "order"),
}));
}
}
success = true;
exit:
ffStrbufDestroy(&bootmgr.name);
ffStrbufDestroy(&bootmgr.firmware);
return success;
}
void ffParseBootmgrJsonObject(FFBootmgrOptions* options, yyjson_val* module)
@@ -68,8 +75,9 @@ void ffGenerateBootmgrJsonConfig(FFBootmgrOptions* options, yyjson_mut_doc* doc,
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateBootmgrJsonResult(FF_MAYBE_UNUSED FFBootmgrOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateBootmgrJsonResult(FF_MAYBE_UNUSED FFBootmgrOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFBootmgrResult bootmgr = {
.name = ffStrbufCreate(),
.firmware = ffStrbufCreate(),
@@ -88,10 +96,12 @@ void ffGenerateBootmgrJsonResult(FF_MAYBE_UNUSED FFBootmgrOptions* options, yyjs
yyjson_mut_obj_add_strbuf(doc, obj, "firmware", &bootmgr.firmware);
yyjson_mut_obj_add_uint(doc, obj, "order", bootmgr.order);
yyjson_mut_obj_add_bool(doc, obj, "secureBoot", bootmgr.secureBoot);
success = true;
exit:
ffStrbufDestroy(&bootmgr.name);
ffStrbufDestroy(&bootmgr.firmware);
return success;
}
void ffInitBootmgrOptions(FFBootmgrOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_BOOTMGR_MODULE_NAME "Bootmgr"
void ffPrintBootmgr(FFBootmgrOptions* options);
bool ffPrintBootmgr(FFBootmgrOptions* options);
void ffInitBootmgrOptions(FFBootmgrOptions* options);
void ffDestroyBootmgrOptions(FFBootmgrOptions* options);
+2 -1
View File
@@ -2,10 +2,11 @@
#include "logo/logo.h"
#include "modules/break/break.h"
void ffPrintBreak(FF_MAYBE_UNUSED FFBreakOptions* options)
bool ffPrintBreak(FF_MAYBE_UNUSED FFBreakOptions* options)
{
ffLogoPrintLine();
putchar('\n');
return true;
}
void ffParseBreakJsonObject(FF_MAYBE_UNUSED FFBreakOptions* options, FF_MAYBE_UNUSED yyjson_val* module)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_BREAK_MODULE_NAME "Break"
void ffPrintBreak(FFBreakOptions* options);
bool ffPrintBreak(FFBreakOptions* options);
void ffInitBreakOptions(FFBreakOptions* options);
void ffDestroyBreakOptions(FFBreakOptions* options);
+10 -6
View File
@@ -5,7 +5,7 @@
#include "modules/brightness/brightness.h"
#include "util/stringUtils.h"
void ffPrintBrightness(FFBrightnessOptions* options)
bool ffPrintBrightness(FFBrightnessOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFBrightnessResult));
@@ -14,13 +14,13 @@ void ffPrintBrightness(FFBrightnessOptions* options)
if(error)
{
ffPrintError(FF_BRIGHTNESS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if(result.length == 0)
{
ffPrintError(FF_BRIGHTNESS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No result is detected.");
return;
return false;
}
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
@@ -40,7 +40,7 @@ void ffPrintBrightness(FFBrightnessOptions* options)
ffPrintLogoAndKey(FF_BRIGHTNESS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffStrbufPutTo(&str, stdout);
return;
return true;
}
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
@@ -110,6 +110,8 @@ void ffPrintBrightness(FFBrightnessOptions* options)
ffStrbufDestroy(&item->name);
++index;
}
return true;
}
void ffParseBrightnessJsonObject(FFBrightnessOptions* options, yyjson_val* module)
@@ -151,7 +153,7 @@ void ffGenerateBrightnessJsonConfig(FFBrightnessOptions* options, yyjson_mut_doc
yyjson_mut_obj_add_bool(doc, module, "compact", options->compact);
}
void ffGenerateBrightnessJsonResult(FF_MAYBE_UNUSED FFBrightnessOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateBrightnessJsonResult(FF_MAYBE_UNUSED FFBrightnessOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFBrightnessResult));
@@ -160,7 +162,7 @@ void ffGenerateBrightnessJsonResult(FF_MAYBE_UNUSED FFBrightnessOptions* options
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_arr(doc);
@@ -180,6 +182,8 @@ void ffGenerateBrightnessJsonResult(FF_MAYBE_UNUSED FFBrightnessOptions* options
{
ffStrbufDestroy(&item->name);
}
return true;
}
void ffInitBrightnessOptions(FFBrightnessOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_BRIGHTNESS_MODULE_NAME "Brightness"
void ffPrintBrightness(FFBrightnessOptions* options);
bool ffPrintBrightness(FFBrightnessOptions* options);
void ffInitBrightnessOptions(FFBrightnessOptions* options);
void ffDestroyBrightnessOptions(FFBrightnessOptions* options);
+9 -5
View File
@@ -97,7 +97,7 @@ static void printBtrfs(FFBtrfsOptions* options, FFBtrfsResult* result, uint8_t i
}
}
void ffPrintBtrfs(FFBtrfsOptions* options)
bool ffPrintBtrfs(FFBtrfsOptions* options)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBtrfsResult));
@@ -106,12 +106,12 @@ void ffPrintBtrfs(FFBtrfsOptions* options)
if (error)
{
ffPrintError(FF_BTRFS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if(results.length == 0)
{
ffPrintError(FF_BTRFS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", "No btrfs drive found");
return;
return false;
}
for(uint32_t i = 0; i < results.length; i++)
@@ -128,6 +128,8 @@ void ffPrintBtrfs(FFBtrfsOptions* options)
ffStrbufDestroy(&result->devices);
ffStrbufDestroy(&result->features);
}
return true;
}
void ffParseBtrfsJsonObject(FFBtrfsOptions* options, yyjson_val* module)
@@ -153,7 +155,7 @@ void ffGenerateBtrfsJsonConfig(FFBtrfsOptions* options, yyjson_mut_doc* doc, yyj
ffPercentGenerateJsonConfig(doc, module, options->percent);
}
void ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBtrfsResult));
@@ -161,7 +163,7 @@ void ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_m
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -195,6 +197,8 @@ void ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_m
ffStrbufDestroy(&btrfs->devices);
ffStrbufDestroy(&btrfs->features);
}
return true;
}
void ffInitBtrfsOptions(FFBtrfsOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_BTRFS_MODULE_NAME "Btrfs"
void ffPrintBtrfs(FFBtrfsOptions* options);
bool ffPrintBtrfs(FFBtrfsOptions* options);
void ffInitBtrfsOptions(FFBtrfsOptions* options);
void ffDestroyBtrfsOptions(FFBtrfsOptions* options);
+9 -5
View File
@@ -36,7 +36,7 @@ static void printDevice(FFCameraOptions* options, const FFCameraResult* device,
}
}
void ffPrintCamera(FFCameraOptions* options)
bool ffPrintCamera(FFCameraOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFCameraResult));
const char* error = ffDetectCamera(&result);
@@ -44,13 +44,13 @@ void ffPrintCamera(FFCameraOptions* options)
if (error)
{
ffPrintError(FF_CAMERA_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if (result.length == 0)
{
ffPrintError(FF_CAMERA_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No camera found");
return;
return false;
}
for(uint32_t i = 0; i < result.length; i++)
@@ -65,6 +65,8 @@ void ffPrintCamera(FFCameraOptions* options)
ffStrbufDestroy(&dev->id);
ffStrbufDestroy(&dev->colorspace);
}
return true;
}
void ffParseCameraJsonObject(FFCameraOptions* options, yyjson_val* module)
@@ -85,7 +87,7 @@ void ffGenerateCameraJsonConfig(FFCameraOptions* options, yyjson_mut_doc* doc, y
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateCameraJsonResult(FF_MAYBE_UNUSED FFCameraOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateCameraJsonResult(FF_MAYBE_UNUSED FFCameraOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFCameraResult));
const char* error = ffDetectCamera(&result);
@@ -93,7 +95,7 @@ void ffGenerateCameraJsonResult(FF_MAYBE_UNUSED FFCameraOptions* options, yyjson
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -115,6 +117,8 @@ void ffGenerateCameraJsonResult(FF_MAYBE_UNUSED FFCameraOptions* options, yyjson
ffStrbufDestroy(&dev->id);
ffStrbufDestroy(&dev->colorspace);
}
return true;
}
void ffInitCameraOptions(FFCameraOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_CAMERA_MODULE_NAME "Camera"
void ffPrintCamera(FFCameraOptions* options);
bool ffPrintCamera(FFCameraOptions* options);
void ffInitCameraOptions(FFCameraOptions* options);
void ffDestroyCameraOptions(FFCameraOptions* options);
+9 -2
View File
@@ -4,8 +4,10 @@
#include "modules/chassis/chassis.h"
#include "util/stringUtils.h"
void ffPrintChassis(FFChassisOptions* options)
bool ffPrintChassis(FFChassisOptions* options)
{
bool success = false;
FFChassisResult result;
ffStrbufInit(&result.type);
ffStrbufInit(&result.vendor);
@@ -43,12 +45,14 @@ void ffPrintChassis(FFChassisOptions* options)
FF_FORMAT_ARG(result.serial, "serial"),
}));
}
success = true;
exit:
ffStrbufDestroy(&result.type);
ffStrbufDestroy(&result.vendor);
ffStrbufDestroy(&result.version);
ffStrbufDestroy(&result.serial);
return success;
}
void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module)
@@ -69,8 +73,9 @@ void ffGenerateChassisJsonConfig(FFChassisOptions* options, yyjson_mut_doc* doc,
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateChassisJsonResult(FF_MAYBE_UNUSED FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateChassisJsonResult(FF_MAYBE_UNUSED FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFChassisResult result;
ffStrbufInit(&result.type);
ffStrbufInit(&result.vendor);
@@ -96,12 +101,14 @@ void ffGenerateChassisJsonResult(FF_MAYBE_UNUSED FFChassisOptions* options, yyjs
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &result.vendor);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version);
yyjson_mut_obj_add_strbuf(doc, obj, "serial", &result.serial);
success = true;
exit:
ffStrbufDestroy(&result.type);
ffStrbufDestroy(&result.vendor);
ffStrbufDestroy(&result.version);
ffStrbufDestroy(&result.serial);
return success;
}
void ffInitChassisOptions(FFChassisOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_CHASSIS_MODULE_NAME "Chassis"
void ffPrintChassis(FFChassisOptions* options);
bool ffPrintChassis(FFChassisOptions* options);
void ffInitChassisOptions(FFChassisOptions* options);
void ffDestroyChassisOptions(FFChassisOptions* options);
+4 -1
View File
@@ -15,7 +15,7 @@ static inline uint8_t max(uint8_t a, uint8_t b)
return a > b ? a : b;
}
void ffPrintColors(FFColorsOptions* options)
bool ffPrintColors(FFColorsOptions* options)
{
bool flag = false;
@@ -122,7 +122,10 @@ void ffPrintColors(FFColorsOptions* options)
if (!flag)
{
ffPrintError(FF_COLORS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", "Nothing to print");
return false;
}
return true;
}
void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_COLORS_MODULE_NAME "Colors"
void ffPrintColors(FFColorsOptions* options);
bool ffPrintColors(FFColorsOptions* options);
void ffInitColorsOptions(FFColorsOptions* options);
void ffDestroyColorsOptions(FFColorsOptions* options);
+12 -8
View File
@@ -4,7 +4,7 @@
#include "modules/command/command.h"
#include "util/stringUtils.h"
void ffPrintCommand(FFCommandOptions* options)
bool ffPrintCommand(FFCommandOptions* options)
{
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate();
const char* error = ffProcessAppendStdOut(&result, options->param.length ? (char* const[]){
@@ -21,13 +21,13 @@ void ffPrintCommand(FFCommandOptions* options)
if(error)
{
ffPrintError(FF_COMMAND_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if(!result.length)
{
ffPrintError(FF_COMMAND_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No result printed");
return;
ffPrintError(FF_COMMAND_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No result generated");
return false;
}
if (options->moduleArgs.outputFormat.length == 0)
@@ -41,6 +41,8 @@ void ffPrintCommand(FFCommandOptions* options)
FF_FORMAT_ARG(result, "result")
}));
}
return true;
}
void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module)
@@ -85,7 +87,7 @@ void ffGenerateCommandJsonConfig(FFCommandOptions* options, yyjson_mut_doc* doc,
yyjson_mut_obj_add_strbuf(doc, module, "text", &options->text);
}
void ffGenerateCommandJsonResult(FF_MAYBE_UNUSED FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateCommandJsonResult(FF_MAYBE_UNUSED FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate();
const char* error = ffProcessAppendStdOut(&result, options->param.length ? (char* const[]){
@@ -102,16 +104,18 @@ void ffGenerateCommandJsonResult(FF_MAYBE_UNUSED FFCommandOptions* options, yyjs
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
if(!result.length)
{
yyjson_mut_obj_add_str(doc, module, "error", "No result printed");
return;
yyjson_mut_obj_add_str(doc, module, "error", "No result generated");
return false;
}
yyjson_mut_obj_add_strbuf(doc, module, "result", &result);
return true;
}
void ffInitCommandOptions(FFCommandOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_COMMAND_MODULE_NAME "Command"
void ffPrintCommand(FFCommandOptions* options);
bool ffPrintCommand(FFCommandOptions* options);
void ffInitCommandOptions(FFCommandOptions* options);
void ffDestroyCommandOptions(FFCommandOptions* options);
+11 -2
View File
@@ -12,8 +12,9 @@ static int sortCores(const FFCPUCore* a, const FFCPUCore* b)
return (int)b->freq - (int)a->freq;
}
void ffPrintCPU(FFCPUOptions* options)
bool ffPrintCPU(FFCPUOptions* options)
{
bool success = false;
FFCPUResult cpu = {
.temperature = FF_CPU_TEMP_UNSET,
.frequencyMax = 0,
@@ -111,10 +112,13 @@ void ffPrintCPU(FFCPUOptions* options)
FF_FORMAT_ARG(cpu.packages, "packages"),
}));
}
success = true;
}
ffStrbufDestroy(&cpu.name);
ffStrbufDestroy(&cpu.vendor);
return success;
}
void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module)
@@ -154,8 +158,9 @@ void ffGenerateCPUJsonConfig(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
yyjson_mut_obj_add_bool(doc, module, "showPeCoreCount", options->showPeCoreCount);
}
void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFCPUResult cpu = {
.temperature = FF_CPU_TEMP_UNSET,
.frequencyMax = 0,
@@ -205,10 +210,14 @@ void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
yyjson_mut_obj_add_real(doc, obj, "temperature", cpu.temperature);
else
yyjson_mut_obj_add_null(doc, obj, "temperature");
success = true;
}
ffStrbufDestroy(&cpu.name);
ffStrbufDestroy(&cpu.vendor);
return success;
}
void ffInitCPUOptions(FFCPUOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_CPU_MODULE_NAME "CPU"
void ffPrintCPU(FFCPUOptions* options);
bool ffPrintCPU(FFCPUOptions* options);
void ffInitCPUOptions(FFCPUOptions* options);
void ffDestroyCPUOptions(FFCPUOptions* options);
+9 -2
View File
@@ -101,8 +101,9 @@ static void printCPUCacheCompact(const FFCPUCacheResult* result, FFCPUCacheOptio
}
}
void ffPrintCPUCache(FFCPUCacheOptions* options)
bool ffPrintCPUCache(FFCPUCacheOptions* options)
{
bool success = false;
FFCPUCacheResult result = {
.caches = {
ffListCreate(sizeof(FFCPUCache)),
@@ -124,12 +125,15 @@ void ffPrintCPUCache(FFCPUCacheOptions* options)
printCPUCacheNormal(&result, options);
else
printCPUCacheCompact(&result, options);
success = true;
exit:
ffListDestroy(&result.caches[0]);
ffListDestroy(&result.caches[1]);
ffListDestroy(&result.caches[2]);
ffListDestroy(&result.caches[3]);
return success;
}
void ffParseCPUCacheJsonObject(FFCPUCacheOptions* options, yyjson_val* module)
@@ -158,8 +162,9 @@ void ffGenerateCPUCacheJsonConfig(FFCPUCacheOptions* options, yyjson_mut_doc* do
yyjson_mut_obj_add_bool(doc, module, "compact", options->compact);
}
void ffGenerateCPUCacheJsonResult(FF_MAYBE_UNUSED FFCPUCacheOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateCPUCacheJsonResult(FF_MAYBE_UNUSED FFCPUCacheOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFCPUCacheResult result = {
.caches = {
ffListCreate(sizeof(FFCPUCache)),
@@ -199,12 +204,14 @@ void ffGenerateCPUCacheJsonResult(FF_MAYBE_UNUSED FFCPUCacheOptions* options, yy
yyjson_mut_obj_add_str(doc, item, "type", typeStr);
}
}
success = true;
exit:
ffListDestroy(&result.caches[0]);
ffListDestroy(&result.caches[1]);
ffListDestroy(&result.caches[2]);
ffListDestroy(&result.caches[3]);
return success;
}
void ffInitCPUCacheOptions(FFCPUCacheOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_CPUCACHE_MODULE_NAME "CPUCache"
void ffPrintCPUCache(FFCPUCacheOptions* options);
bool ffPrintCPUCache(FFCPUCacheOptions* options);
void ffInitCPUCacheOptions(FFCPUCacheOptions* options);
void ffDestroyCPUCacheOptions(FFCPUCacheOptions* options);
+8 -4
View File
@@ -7,7 +7,7 @@
#define FF_CPUUSAGE_DISPLAY_NAME "CPU Usage"
void ffPrintCPUUsage(FFCPUUsageOptions* options)
bool ffPrintCPUUsage(FFCPUUsageOptions* options)
{
FF_LIST_AUTO_DESTROY percentages = ffListCreate(sizeof(double));
const char* error = ffGetCpuUsageResult(options, &percentages);
@@ -15,7 +15,7 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
if(error)
{
ffPrintError(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
double maxValue = -999, minValue = 999, sumValue = 0;
@@ -114,6 +114,8 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options)
FF_FORMAT_ARG(minBar, "min-bar"),
}));
}
return true;
}
void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module)
@@ -155,7 +157,7 @@ void ffGenerateCPUUsageJsonConfig(FFCPUUsageOptions* options, yyjson_mut_doc* do
yyjson_mut_obj_add_uint(doc, module, "waitTime", options->waitTime);
}
void ffGenerateCPUUsageJsonResult(FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateCPUUsageJsonResult(FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY percentages = ffListCreate(sizeof(double));
const char* error = ffGetCpuUsageResult(options, &percentages);
@@ -163,13 +165,15 @@ void ffGenerateCPUUsageJsonResult(FFCPUUsageOptions* options, yyjson_mut_doc* do
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* result = yyjson_mut_obj_add_arr(doc, module, "result");
FF_LIST_FOR_EACH(double, percent, percentages)
{
yyjson_mut_arr_add_real(doc, result, *percent);
}
return true;
}
void ffInitCPUUsageOptions(FFCPUUsageOptions* options)
+1 -1
View File
@@ -6,7 +6,7 @@
void ffPrepareCPUUsage();
void ffPrintCPUUsage(FFCPUUsageOptions* options);
bool ffPrintCPUUsage(FFCPUUsageOptions* options);
void ffInitCPUUsageOptions(FFCPUUsageOptions* options);
void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options);
+11 -2
View File
@@ -4,8 +4,9 @@
#include "modules/cursor/cursor.h"
#include "util/stringUtils.h"
void ffPrintCursor(FFCursorOptions* options)
bool ffPrintCursor(FFCursorOptions* options)
{
bool success = false;
FFCursorResult result;
ffStrbufInit(&result.error);
ffStrbufInit(&result.theme);
@@ -41,11 +42,15 @@ void ffPrintCursor(FFCursorOptions* options)
FF_FORMAT_ARG(result.size, "size"),
}));
}
success = true;
}
ffStrbufDestroy(&result.error);
ffStrbufDestroy(&result.theme);
ffStrbufDestroy(&result.size);
return success;
}
void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module)
@@ -66,8 +71,9 @@ void ffGenerateCursorJsonConfig(FFCursorOptions* options, yyjson_mut_doc* doc, y
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateCursorJsonResult(FF_MAYBE_UNUSED FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateCursorJsonResult(FF_MAYBE_UNUSED FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFCursorResult result;
ffStrbufInit(&result.error);
ffStrbufInit(&result.theme);
@@ -84,11 +90,14 @@ void ffGenerateCursorJsonResult(FF_MAYBE_UNUSED FFCursorOptions* options, yyjson
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "theme", &result.theme);
yyjson_mut_obj_add_strbuf(doc, obj, "size", &result.size);
success = true;
}
ffStrbufDestroy(&result.error);
ffStrbufDestroy(&result.theme);
ffStrbufDestroy(&result.size);
return success;
}
void ffInitCursorOptions(FFCursorOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_CURSOR_MODULE_NAME "Cursor"
void ffPrintCursor(FFCursorOptions* options);
bool ffPrintCursor(FFCursorOptions* options);
void ffInitCursorOptions(FFCursorOptions* options);
void ffDestroyCursorOptions(FFCursorOptions* options);
+2 -1
View File
@@ -4,9 +4,10 @@
#include "util/textModifier.h"
#include "util/stringUtils.h"
void ffPrintCustom(FFCustomOptions* options)
bool ffPrintCustom(FFCustomOptions* options)
{
ffPrintFormat(FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, 0, ((FFformatarg[]) {}));
return true;
}
void ffGenerateCustomJsonConfig(FFCustomOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_CUSTOM_MODULE_NAME "Custom"
void ffPrintCustom(FFCustomOptions* options);
bool ffPrintCustom(FFCustomOptions* options);
void ffInitCustomOptions(FFCustomOptions* options);
void ffDestroyCustomOptions(FFCustomOptions* options);
+8 -6
View File
@@ -38,7 +38,7 @@ typedef struct FFDateTimeResult
char timezoneName[FASTFETCH_STRBUF_DEFAULT_ALLOC];
} FFDateTimeResult;
void ffPrintDateTimeFormat(struct tm* tm, const FFModuleArgs* moduleArgs)
static void printDateTimeFormat(struct tm* tm, const FFModuleArgs* moduleArgs)
{
FFDateTimeResult result;
@@ -93,7 +93,7 @@ void ffPrintDateTimeFormat(struct tm* tm, const FFModuleArgs* moduleArgs)
}));
}
void ffPrintDateTime(FFDateTimeOptions* options)
bool ffPrintDateTime(FFDateTimeOptions* options)
{
uint64_t msNow = ffTimeGetNow();
time_t sNow = (time_t) (msNow / 1000);
@@ -101,20 +101,21 @@ void ffPrintDateTime(FFDateTimeOptions* options)
if(options->moduleArgs.outputFormat.length > 0)
{
ffPrintDateTimeFormat(tm, &options->moduleArgs);
return;
printDateTimeFormat(tm, &options->moduleArgs);
return true;
}
char buffer[32];
if (strftime(buffer, ARRAY_SIZE(buffer), "%F %T", tm) == 0) //yyyy-MM-dd HH:mm:ss
{
ffPrintError(FF_DATETIME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "strftime() failed");
return;
return false;
}
ffPrintLogoAndKey(FF_DATETIME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
puts(buffer);
return true;
}
void ffParseDateTimeJsonObject(FFDateTimeOptions* options, yyjson_val* module)
@@ -135,9 +136,10 @@ void ffGenerateDateTimeJsonConfig(FFDateTimeOptions* options, yyjson_mut_doc* do
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateDateTimeJsonResult(FF_MAYBE_UNUSED FFDateTimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateDateTimeJsonResult(FF_MAYBE_UNUSED FFDateTimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
yyjson_mut_obj_add_strcpy(doc, module, "result", ffTimeToFullStr(ffTimeGetNow()));
return true;
}
void ffInitDateTimeOptions(FFDateTimeOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_DATETIME_MODULE_NAME "DateTime"
void ffPrintDateTime(FFDateTimeOptions* options);
bool ffPrintDateTime(FFDateTimeOptions* options);
void ffInitDateTimeOptions(FFDateTimeOptions* options);
void ffDestroyDateTimeOptions(FFDateTimeOptions* options);
+7 -4
View File
@@ -5,14 +5,14 @@
#include "modules/de/de.h"
#include "util/stringUtils.h"
void ffPrintDE(FFDEOptions* options)
bool ffPrintDE(FFDEOptions* options)
{
const FFDisplayServerResult* result = ffConnectDisplayServer();
if(result->dePrettyName.length == 0)
{
ffPrintError(FF_DE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No DE found");
return;
return false;
}
FF_STRBUF_AUTO_DESTROY version = ffStrbufCreate();
@@ -40,6 +40,8 @@ void ffPrintDE(FFDEOptions* options)
FF_FORMAT_ARG(version, "version")
}));
}
return true;
}
void ffParseDEJsonObject(FFDEOptions* options, yyjson_val* module)
@@ -68,14 +70,14 @@ void ffGenerateDEJsonConfig(FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mu
yyjson_mut_obj_add_bool(doc, module, "slowVersionDetection", options->slowVersionDetection);
}
void ffGenerateDEJsonResult(FF_MAYBE_UNUSED FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateDEJsonResult(FF_MAYBE_UNUSED FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
const FFDisplayServerResult* result = ffConnectDisplayServer();
if(result->dePrettyName.length == 0)
{
yyjson_mut_obj_add_str(doc, module, "error", "No DE found");
return;
return false;
}
FF_STRBUF_AUTO_DESTROY version = ffStrbufCreate();
@@ -85,6 +87,7 @@ void ffGenerateDEJsonResult(FF_MAYBE_UNUSED FFDEOptions* options, yyjson_mut_doc
yyjson_mut_obj_add_strbuf(doc, obj, "processName", &result->deProcessName);
yyjson_mut_obj_add_strbuf(doc, obj, "prettyName", &result->dePrettyName);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &version);
return true;
}
void ffInitDEOptions(FFDEOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_DE_MODULE_NAME "DE"
void ffPrintDE(FFDEOptions* options);
bool ffPrintDE(FFDEOptions* options);
void ffInitDEOptions(FFDEOptions* options);
void ffDestroyDEOptions(FFDEOptions* options);
+18 -15
View File
@@ -167,7 +167,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index
}
}
void ffPrintDisk(FFDiskOptions* options)
bool ffPrintDisk(FFDiskOptions* options)
{
FF_LIST_AUTO_DESTROY disks = ffListCreate(sizeof (FFDisk));
const char* error = ffDetectDisks(options, &disks);
@@ -175,23 +175,22 @@ void ffPrintDisk(FFDiskOptions* options)
if(error)
{
ffPrintError(FF_DISK_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return false;
}
else
uint32_t index = 0;
FF_LIST_FOR_EACH(FFDisk, disk, disks)
{
uint32_t index = 0;
FF_LIST_FOR_EACH(FFDisk, disk, disks)
{
if(__builtin_expect(options->folders.length == 0, 1) && (disk->type & ~options->showTypes))
continue;
if(__builtin_expect(options->folders.length == 0, 1) && (disk->type & ~options->showTypes))
continue;
if (options->hideFolders.length && ffDiskMatchMountpoint(&options->hideFolders, disk->mountpoint.chars))
continue;
if (options->hideFolders.length && ffDiskMatchMountpoint(&options->hideFolders, disk->mountpoint.chars))
continue;
if (options->hideFS.length && ffStrbufMatchSeparated(&disk->filesystem, &options->hideFS, ':'))
continue;
if (options->hideFS.length && ffStrbufMatchSeparated(&disk->filesystem, &options->hideFS, ':'))
continue;
printDisk(options, disk, ++index);
}
printDisk(options, disk, ++index);
}
FF_LIST_FOR_EACH(FFDisk, disk, disks)
@@ -201,6 +200,8 @@ void ffPrintDisk(FFDiskOptions* options)
ffStrbufDestroy(&disk->filesystem);
ffStrbufDestroy(&disk->name);
}
return true;
}
void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
@@ -327,7 +328,7 @@ void ffGenerateDiskJsonConfig(FFDiskOptions* options, yyjson_mut_doc* doc, yyjso
ffPercentGenerateJsonConfig(doc, module, options->percent);
}
void ffGenerateDiskJsonResult(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateDiskJsonResult(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY disks = ffListCreate(sizeof (FFDisk));
const char* error = ffDetectDisks(options, &disks);
@@ -335,7 +336,7 @@ void ffGenerateDiskJsonResult(FFDiskOptions* options, yyjson_mut_doc* doc, yyjso
if(error)
{
yyjson_mut_obj_add_str(doc, module, "result", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -394,6 +395,8 @@ void ffGenerateDiskJsonResult(FFDiskOptions* options, yyjson_mut_doc* doc, yyjso
ffStrbufDestroy(&item->filesystem);
ffStrbufDestroy(&item->name);
}
return true;
}
void ffInitDiskOptions(FFDiskOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_DISK_MODULE_NAME "Disk"
void ffPrintDisk(FFDiskOptions* options);
bool ffPrintDisk(FFDiskOptions* options);
void ffInitDiskOptions(FFDiskOptions* options);
void ffDestroyDiskOptions(FFDiskOptions* options);
+8 -4
View File
@@ -30,7 +30,7 @@ static void formatKey(const FFDiskIOOptions* options, FFDiskIOResult* dev, uint3
}
}
void ffPrintDiskIO(FFDiskIOOptions* options)
bool ffPrintDiskIO(FFDiskIOOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFDiskIOResult));
const char* error = ffDetectDiskIO(&result, options);
@@ -38,7 +38,7 @@ void ffPrintDiskIO(FFDiskIOOptions* options)
if(error)
{
ffPrintError(FF_DISKIO_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, "%s", error);
return;
return false;
}
ffListSort(&result, (const void*) sortDevices);
@@ -93,6 +93,8 @@ void ffPrintDiskIO(FFDiskIOOptions* options)
ffStrbufDestroy(&dev->name);
ffStrbufDestroy(&dev->devPath);
}
return true;
}
void ffParseDiskIOJsonObject(FFDiskIOOptions* options, yyjson_val* module)
@@ -137,7 +139,7 @@ void ffGenerateDiskIOJsonConfig(FFDiskIOOptions* options, yyjson_mut_doc* doc, y
yyjson_mut_obj_add_uint(doc, module, "waitTime", options->waitTime);
}
void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFDiskIOResult));
const char* error = ffDetectDiskIO(&result, options);
@@ -145,7 +147,7 @@ void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, y
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -165,6 +167,8 @@ void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, y
ffStrbufDestroy(&dev->name);
ffStrbufDestroy(&dev->devPath);
}
return true;
}
void ffInitDiskIOOptions(FFDiskIOOptions* options)
+1 -1
View File
@@ -6,7 +6,7 @@
void ffPrepareDiskIO(FFDiskIOOptions* options);
void ffPrintDiskIO(FFDiskIOOptions* options);
bool ffPrintDiskIO(FFDiskIOOptions* options);
void ffInitDiskIOOptions(FFDiskIOOptions* options);
void ffDestroyDiskIOOptions(FFDiskIOOptions* options);
+9 -5
View File
@@ -17,14 +17,14 @@ static int sortByNameDesc(FFDisplayResult* a, FFDisplayResult* b)
return -ffStrbufComp(&a->name, &b->name);
}
void ffPrintDisplay(FFDisplayOptions* options)
bool ffPrintDisplay(FFDisplayOptions* options)
{
const FFDisplayServerResult* dsResult = ffConnectDisplayServer();
if(dsResult->displays.length == 0)
{
ffPrintError(FF_DISPLAY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Couldn't detect display");
return;
return false;
}
if (options->order != FF_DISPLAY_ORDER_NONE)
@@ -68,7 +68,7 @@ void ffPrintDisplay(FFDisplayOptions* options)
ffStrbufTrimRight(&buffer, ' ');
ffStrbufTrimRight(&buffer, ',');
ffStrbufPutTo(&buffer, stdout);
return;
return true;
}
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
@@ -215,6 +215,8 @@ void ffPrintDisplay(FFDisplayOptions* options)
}));
}
}
return true;
}
void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module)
@@ -319,14 +321,14 @@ void ffGenerateDisplayJsonConfig(FFDisplayOptions* options, yyjson_mut_doc* doc,
}
}
void ffGenerateDisplayJsonResult(FF_MAYBE_UNUSED FFDisplayOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateDisplayJsonResult(FF_MAYBE_UNUSED FFDisplayOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
const FFDisplayServerResult* dsResult = ffConnectDisplayServer();
if(dsResult->displays.length == 0)
{
yyjson_mut_obj_add_str(doc, module, "error", "Couldn't detect display");
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -406,6 +408,8 @@ void ffGenerateDisplayJsonResult(FF_MAYBE_UNUSED FFDisplayOptions* options, yyjs
yyjson_mut_obj_add_str(doc, obj, "platformApi", item->platformApi);
}
return true;
}
void ffInitDisplayOptions(FFDisplayOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_DISPLAY_MODULE_NAME "Display"
void ffPrintDisplay(FFDisplayOptions* options);
bool ffPrintDisplay(FFDisplayOptions* options);
void ffInitDisplayOptions(FFDisplayOptions* options);
void ffDestroyDisplayOptions(FFDisplayOptions* options);
+9 -6
View File
@@ -4,7 +4,7 @@
#include "modules/dns/dns.h"
#include "util/stringUtils.h"
void ffPrintDNS(FFDNSOptions* options)
bool ffPrintDNS(FFDNSOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFstrbuf));
@@ -13,13 +13,13 @@ void ffPrintDNS(FFDNSOptions* options)
if (error)
{
ffPrintError(FF_DNS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if (result.length == 0)
{
ffPrintError(FF_DNS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "NO DNS servers detected");
return;
return false;
}
FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate();
@@ -55,6 +55,8 @@ void ffPrintDNS(FFDNSOptions* options)
{
ffStrbufDestroy(item);
}
return true;
}
void ffParseDNSJsonObject(FFDNSOptions* options, yyjson_val* module)
@@ -104,7 +106,7 @@ void ffGenerateDNSJsonConfig(FFDNSOptions* options, yyjson_mut_doc* doc, yyjson_
}
}
void ffGenerateDNSJsonResult(FFDNSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateDNSJsonResult(FFDNSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFstrbuf));
@@ -113,7 +115,7 @@ void ffGenerateDNSJsonResult(FFDNSOptions* options, yyjson_mut_doc* doc, yyjson_
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
goto exit;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -123,11 +125,12 @@ void ffGenerateDNSJsonResult(FFDNSOptions* options, yyjson_mut_doc* doc, yyjson_
yyjson_mut_arr_add_strbuf(doc, arr, item);
}
exit:
FF_LIST_FOR_EACH(FFstrbuf, item, result)
{
ffStrbufDestroy(item);
}
return true;
}
void ffInitDNSOptions(FFDNSOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_DNS_MODULE_NAME "DNS"
void ffPrintDNS(FFDNSOptions* options);
bool ffPrintDNS(FFDNSOptions* options);
void ffInitDNSOptions(FFDNSOptions* options);
void ffDestroyDNSOptions(FFDNSOptions* options);
+8 -4
View File
@@ -5,7 +5,7 @@
#include "modules/editor/editor.h"
#include "util/stringUtils.h"
void ffPrintEditor(FFEditorOptions* options)
bool ffPrintEditor(FFEditorOptions* options)
{
FFEditorResult result = {
.type = "Unknown",
@@ -19,7 +19,7 @@ void ffPrintEditor(FFEditorOptions* options)
if (error)
{
ffPrintError(FF_EDITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if (options->moduleArgs.outputFormat.length == 0)
@@ -52,6 +52,8 @@ void ffPrintEditor(FFEditorOptions* options)
ffStrbufDestroy(&result.path);
ffStrbufDestroy(&result.exe);
ffStrbufDestroy(&result.version);
return true;
}
void ffParseEditorJsonObject(FFEditorOptions* options, yyjson_val* module)
@@ -72,7 +74,7 @@ void ffGenerateEditorJsonConfig(FFEditorOptions* options, yyjson_mut_doc* doc, y
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateEditorJsonResult(FF_MAYBE_UNUSED FFEditorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateEditorJsonResult(FF_MAYBE_UNUSED FFEditorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFEditorResult result = {
.name = ffStrbufCreate(),
@@ -85,7 +87,7 @@ void ffGenerateEditorJsonResult(FF_MAYBE_UNUSED FFEditorOptions* options, yyjson
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
@@ -99,6 +101,8 @@ void ffGenerateEditorJsonResult(FF_MAYBE_UNUSED FFEditorOptions* options, yyjson
ffStrbufDestroy(&result.path);
ffStrbufDestroy(&result.exe);
ffStrbufDestroy(&result.version);
return true;
}
void ffInitEditorOptions(FFEditorOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_EDITOR_MODULE_NAME "Editor"
void ffPrintEditor(FFEditorOptions* options);
bool ffPrintEditor(FFEditorOptions* options);
void ffInitEditorOptions(FFEditorOptions* options);
void ffDestroyEditorOptions(FFEditorOptions* options);
+11 -2
View File
@@ -4,8 +4,9 @@
#include "modules/font/font.h"
#include "util/stringUtils.h"
void ffPrintFont(FFFontOptions* options)
bool ffPrintFont(FFFontOptions* options)
{
bool success = false;
FFFontResult font;
for(uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
ffStrbufInit(&font.fonts[i]);
@@ -34,11 +35,15 @@ void ffPrintFont(FFFontOptions* options)
FF_FORMAT_ARG(font.display, "combined"),
}));
}
success = true;
}
ffStrbufDestroy(&font.display);
for (uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
ffStrbufDestroy(&font.fonts[i]);
return success;
}
void ffParseFontJsonObject(FFFontOptions* options, yyjson_val* module)
@@ -59,8 +64,9 @@ void ffGenerateFontJsonConfig(FFFontOptions* options, yyjson_mut_doc* doc, yyjso
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateFontJsonResult(FF_MAYBE_UNUSED FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateFontJsonResult(FF_MAYBE_UNUSED FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFFontResult font;
for(uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
ffStrbufInit(&font.fonts[i]);
@@ -78,11 +84,14 @@ void ffGenerateFontJsonResult(FF_MAYBE_UNUSED FFFontOptions* options, yyjson_mut
yyjson_mut_val* fontsArr = yyjson_mut_obj_add_arr(doc, obj, "fonts");
for (uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
yyjson_mut_arr_add_strbuf(doc, fontsArr, &font.fonts[i]);
success = true;
}
ffStrbufDestroy(&font.display);
for (uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i)
ffStrbufDestroy(&font.fonts[i]);
return success;
}
void ffInitFontOptions(FFFontOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_FONT_MODULE_NAME "Font"
void ffPrintFont(FFFontOptions* options);
bool ffPrintFont(FFFontOptions* options);
void ffInitFontOptions(FFFontOptions* options);
void ffDestroyFontOptions(FFFontOptions* options);
+9 -5
View File
@@ -50,7 +50,7 @@ static void printDevice(FFGamepadOptions* options, const FFGamepadDevice* device
}
}
void ffPrintGamepad(FFGamepadOptions* options)
bool ffPrintGamepad(FFGamepadOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFGamepadDevice));
@@ -59,13 +59,13 @@ void ffPrintGamepad(FFGamepadOptions* options)
if(error)
{
ffPrintError(FF_GAMEPAD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if(!result.length)
{
ffPrintError(FF_GAMEPAD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No devices detected");
return;
return false;
}
uint8_t index = 0;
@@ -75,6 +75,8 @@ void ffPrintGamepad(FFGamepadOptions* options)
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->name);
}
return true;
}
void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module)
@@ -100,7 +102,7 @@ void ffGenerateGamepadJsonConfig(FFGamepadOptions* options, yyjson_mut_doc* doc,
ffPercentGenerateJsonConfig(doc, module, options->percent);
}
void ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFGamepadDevice));
@@ -109,7 +111,7 @@ void ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -125,6 +127,8 @@ void ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->name);
}
return true;
}
void ffInitGamepadOptions(FFGamepadOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_GAMEPAD_MODULE_NAME "Gamepad"
void ffPrintGamepad(FFGamepadOptions* options);
bool ffPrintGamepad(FFGamepadOptions* options);
void ffInitGamepadOptions(FFGamepadOptions* options);
void ffDestroyGamepadOptions(FFGamepadOptions* options);
+8 -4
View File
@@ -159,14 +159,14 @@ static void printGPUResult(FFGPUOptions* options, uint8_t index, const FFGPUResu
}
}
void ffPrintGPU(FFGPUOptions* options)
bool ffPrintGPU(FFGPUOptions* options)
{
FF_LIST_AUTO_DESTROY gpus = ffListCreate(sizeof (FFGPUResult));
const char* error = ffDetectGPU(options, &gpus);
if (error)
{
ffPrintError(FF_GPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
FF_LIST_AUTO_DESTROY selectedGPUs;
@@ -200,6 +200,8 @@ void ffPrintGPU(FFGPUOptions* options)
ffStrbufDestroy(&gpu->platformApi);
ffStrbufDestroy(&gpu->memoryType);
}
return true;
}
void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module)
@@ -313,14 +315,14 @@ void ffGenerateGPUJsonConfig(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
ffPercentGenerateJsonConfig(doc, module, options->percent);
}
void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY gpus = ffListCreate(sizeof (FFGPUResult));
const char* error = ffDetectGPU(options, &gpus);
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -408,6 +410,8 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_
ffStrbufDestroy(&gpu->platformApi);
ffStrbufDestroy(&gpu->memoryType);
}
return true;
}
void ffInitGPUOptions(FFGPUOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_GPU_MODULE_NAME "GPU"
void ffPrintGPU(FFGPUOptions* options);
bool ffPrintGPU(FFGPUOptions* options);
void ffInitGPUOptions(FFGPUOptions* options);
void ffDestroyGPUOptions(FFGPUOptions* options);
+10 -2
View File
@@ -4,8 +4,9 @@
#include "modules/host/host.h"
#include "util/stringUtils.h"
void ffPrintHost(FFHostOptions* options)
bool ffPrintHost(FFHostOptions* options)
{
bool success = false;
FFHostResult host;
ffStrbufInit(&host.family);
ffStrbufInit(&host.name);
@@ -56,6 +57,7 @@ void ffPrintHost(FFHostOptions* options)
FF_FORMAT_ARG(host.uuid, "uuid"),
}));
}
success = true;
exit:
ffStrbufDestroy(&host.family);
@@ -65,6 +67,8 @@ exit:
ffStrbufDestroy(&host.serial);
ffStrbufDestroy(&host.uuid);
ffStrbufDestroy(&host.vendor);
return success;
}
void ffParseHostJsonObject(FFHostOptions* options, yyjson_val* module)
@@ -85,8 +89,9 @@ void ffGenerateHostJsonConfig(FFHostOptions* options, yyjson_mut_doc* doc, yyjso
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateHostJsonResult(FF_MAYBE_UNUSED FFHostOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateHostJsonResult(FF_MAYBE_UNUSED FFHostOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFHostResult host;
ffStrbufInit(&host.family);
ffStrbufInit(&host.name);
@@ -117,6 +122,7 @@ void ffGenerateHostJsonResult(FF_MAYBE_UNUSED FFHostOptions* options, yyjson_mut
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &host.vendor);
yyjson_mut_obj_add_strbuf(doc, obj, "serial", &host.serial);
yyjson_mut_obj_add_strbuf(doc, obj, "uuid", &host.uuid);
success = true;
exit:
ffStrbufDestroy(&host.family);
@@ -126,6 +132,8 @@ exit:
ffStrbufDestroy(&host.serial);
ffStrbufDestroy(&host.uuid);
ffStrbufDestroy(&host.vendor);
return success;
}
void ffInitHostOptions(FFHostOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_HOST_MODULE_NAME "Host"
void ffPrintHost(FFHostOptions* options);
bool ffPrintHost(FFHostOptions* options);
void ffInitHostOptions(FFHostOptions* options);
void ffDestroyHostOptions(FFHostOptions* options);
+14 -4
View File
@@ -4,8 +4,9 @@
#include "modules/icons/icons.h"
#include "util/stringUtils.h"
void ffPrintIcons(FFIconsOptions* options)
bool ffPrintIcons(FFIconsOptions* options)
{
bool success = false;
FFIconsResult result = {
.icons1 = ffStrbufCreate(),
.icons2 = ffStrbufCreate(),
@@ -15,7 +16,7 @@ void ffPrintIcons(FFIconsOptions* options)
if(error)
{
ffPrintError(FF_ICONS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
goto exit;
}
if(options->moduleArgs.outputFormat.length == 0)
@@ -38,9 +39,13 @@ void ffPrintIcons(FFIconsOptions* options)
FF_FORMAT_ARG(result.icons2, "icons2"),
}));
}
success = true;
exit:
ffStrbufDestroy(&result.icons1);
ffStrbufDestroy(&result.icons2);
return success;
}
void ffParseIconsJsonObject(FFIconsOptions* options, yyjson_val* module)
@@ -61,8 +66,9 @@ void ffGenerateIconsJsonConfig(FFIconsOptions* options, yyjson_mut_doc* doc, yyj
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateIconsJsonResult(FF_MAYBE_UNUSED FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateIconsJsonResult(FF_MAYBE_UNUSED FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFIconsResult result = {
.icons1 = ffStrbufCreate(),
.icons2 = ffStrbufCreate()
@@ -72,15 +78,19 @@ void ffGenerateIconsJsonResult(FF_MAYBE_UNUSED FFIconsOptions* options, yyjson_m
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
goto exit;
}
yyjson_mut_val* icons = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, icons, "icons1", &result.icons1);
yyjson_mut_obj_add_strbuf(doc, icons, "icons2", &result.icons2);
success = true;
exit:
ffStrbufDestroy(&result.icons1);
ffStrbufDestroy(&result.icons2);
return success;
}
void ffInitIconsOptions(FFIconsOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_ICONS_MODULE_NAME "Icons"
void ffPrintIcons(FFIconsOptions* options);
bool ffPrintIcons(FFIconsOptions* options);
void ffInitIconsOptions(FFIconsOptions* options);
void ffDestroyIconsOptions(FFIconsOptions* options);
+9 -2
View File
@@ -6,8 +6,9 @@
#define FF_INITSYSTEM_DISPLAY_NAME "Init System"
void ffPrintInitSystem(FFInitSystemOptions* options)
bool ffPrintInitSystem(FFInitSystemOptions* options)
{
bool success = false;
FFInitSystemResult result = {
.name = ffStrbufCreate(),
.exe = ffStrbufCreate(),
@@ -41,11 +42,14 @@ void ffPrintInitSystem(FFInitSystemOptions* options)
FF_FORMAT_ARG(result.pid, "pid"),
}));
}
success = true;
exit:
ffStrbufDestroy(&result.name);
ffStrbufDestroy(&result.exe);
ffStrbufDestroy(&result.version);
return success;
}
void ffParseInitSystemJsonObject(FFInitSystemOptions* options, yyjson_val* module)
@@ -66,8 +70,9 @@ void ffGenerateInitSystemJsonConfig(FFInitSystemOptions* options, yyjson_mut_doc
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateInitSystemJsonResult(FF_MAYBE_UNUSED FFInitSystemOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateInitSystemJsonResult(FF_MAYBE_UNUSED FFInitSystemOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFInitSystemResult result = {
.name = ffStrbufCreate(),
.exe = ffStrbufCreate(),
@@ -88,11 +93,13 @@ void ffGenerateInitSystemJsonResult(FF_MAYBE_UNUSED FFInitSystemOptions* options
yyjson_mut_obj_add_strbuf(doc, obj, "exe", &result.exe);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version);
yyjson_mut_obj_add_uint(doc, obj, "pid", result.pid);
success = true;
exit:
ffStrbufDestroy(&result.name);
ffStrbufDestroy(&result.exe);
ffStrbufDestroy(&result.version);
return success;
}
void ffInitInitSystemOptions(FFInitSystemOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_INITSYSTEM_MODULE_NAME "InitSystem"
void ffPrintInitSystem(FFInitSystemOptions* options);
bool ffPrintInitSystem(FFInitSystemOptions* options);
void ffInitInitSystemOptions(FFInitSystemOptions* options);
void ffDestroyInitSystemOptions(FFInitSystemOptions* options);
+6 -2
View File
@@ -4,7 +4,7 @@
#include "modules/kernel/kernel.h"
#include "util/stringUtils.h"
void ffPrintKernel(FFKernelOptions* options)
bool ffPrintKernel(FFKernelOptions* options)
{
const FFPlatformSysinfo* info = &instance.state.platform.sysinfo;
if(options->moduleArgs.outputFormat.length == 0)
@@ -30,6 +30,8 @@ void ffPrintKernel(FFKernelOptions* options)
FF_FORMAT_ARG(str, "page-size"),
}));
}
return true;
}
void ffParseKernelJsonObject(FFKernelOptions* options, yyjson_val* module)
@@ -50,7 +52,7 @@ void ffGenerateKernelJsonConfig(FFKernelOptions* options, yyjson_mut_doc* doc, y
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateKernelJsonResult(FF_MAYBE_UNUSED FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateKernelJsonResult(FF_MAYBE_UNUSED FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
const FFPlatformSysinfo* info = &instance.state.platform.sysinfo;
@@ -61,6 +63,8 @@ void ffGenerateKernelJsonResult(FF_MAYBE_UNUSED FFKernelOptions* options, yyjson
yyjson_mut_obj_add_strbuf(doc, obj, "version", &info->version);
yyjson_mut_obj_add_strbuf(doc, obj, "displayVersion", &info->displayVersion);
yyjson_mut_obj_add_uint(doc, obj, "pageSize", info->pageSize);
return true;
}
void ffInitKernelOptions(FFKernelOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_KERNEL_MODULE_NAME "Kernel"
void ffPrintKernel(FFKernelOptions* options);
bool ffPrintKernel(FFKernelOptions* options);
void ffInitKernelOptions(FFKernelOptions* options);
void ffDestroyKernelOptions(FFKernelOptions* options);
+9 -5
View File
@@ -21,7 +21,7 @@ static void printDevice(FFKeyboardOptions* options, const FFKeyboardDevice* devi
}
}
void ffPrintKeyboard(FFKeyboardOptions* options)
bool ffPrintKeyboard(FFKeyboardOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFKeyboardDevice));
@@ -30,13 +30,13 @@ void ffPrintKeyboard(FFKeyboardOptions* options)
if(error)
{
ffPrintError(FF_KEYBOARD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if(!result.length)
{
ffPrintError(FF_KEYBOARD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No devices detected");
return;
return false;
}
uint8_t index = 0;
@@ -46,6 +46,8 @@ void ffPrintKeyboard(FFKeyboardOptions* options)
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->name);
}
return true;
}
void ffParseKeyboardJsonObject(FFKeyboardOptions* options, yyjson_val* module)
@@ -66,7 +68,7 @@ void ffGenerateKeyboardJsonConfig(FFKeyboardOptions* options, yyjson_mut_doc* do
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateKeyboardJsonResult(FF_MAYBE_UNUSED FFKeyboardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateKeyboardJsonResult(FF_MAYBE_UNUSED FFKeyboardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFKeyboardDevice));
@@ -75,7 +77,7 @@ void ffGenerateKeyboardJsonResult(FF_MAYBE_UNUSED FFKeyboardOptions* options, yy
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -91,6 +93,8 @@ void ffGenerateKeyboardJsonResult(FF_MAYBE_UNUSED FFKeyboardOptions* options, yy
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->name);
}
return true;
}
void ffInitKeyboardOptions(FFKeyboardOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_KEYBOARD_MODULE_NAME "Keyboard"
void ffPrintKeyboard(FFKeyboardOptions* options);
bool ffPrintKeyboard(FFKeyboardOptions* options);
void ffInitKeyboardOptions(FFKeyboardOptions* options);
void ffDestroyKeyboardOptions(FFKeyboardOptions* options);
+14 -4
View File
@@ -4,8 +4,9 @@
#include "modules/lm/lm.h"
#include "util/stringUtils.h"
void ffPrintLM(FFLMOptions* options)
bool ffPrintLM(FFLMOptions* options)
{
bool success = false;
FFLMResult result;
ffStrbufInit(&result.service);
ffStrbufInit(&result.type);
@@ -15,13 +16,13 @@ void ffPrintLM(FFLMOptions* options)
if(error)
{
ffPrintError(FF_LM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
goto exit;
}
if(result.service.length == 0)
{
ffPrintError(FF_LM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No LM service found");
return;
goto exit;
}
if(options->moduleArgs.outputFormat.length == 0)
@@ -42,9 +43,14 @@ void ffPrintLM(FFLMOptions* options)
FF_FORMAT_ARG(result.version, "version"),
}));
}
success = true;
exit:
ffStrbufDestroy(&result.service);
ffStrbufDestroy(&result.type);
ffStrbufDestroy(&result.version);
return success;
}
void ffParseLMJsonObject(FFLMOptions* options, yyjson_val* module)
@@ -65,8 +71,9 @@ void ffGenerateLMJsonConfig(FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mu
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateLMJsonResult(FF_MAYBE_UNUSED FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateLMJsonResult(FF_MAYBE_UNUSED FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFLMResult result;
ffStrbufInit(&result.service);
ffStrbufInit(&result.type);
@@ -89,11 +96,14 @@ void ffGenerateLMJsonResult(FF_MAYBE_UNUSED FFLMOptions* options, yyjson_mut_doc
yyjson_mut_obj_add_strbuf(doc, obj, "service", &result.service);
yyjson_mut_obj_add_strbuf(doc, obj, "type", &result.type);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &result.version);
success = true;
exit:
ffStrbufDestroy(&result.service);
ffStrbufDestroy(&result.type);
ffStrbufDestroy(&result.version);
return success;
}
void ffInitLMOptions(FFLMOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_LM_MODULE_NAME "LM"
void ffPrintLM(FFLMOptions* options);
bool ffPrintLM(FFLMOptions* options);
void ffInitLMOptions(FFLMOptions* options);
void ffDestroyLMOptions(FFLMOptions* options);
+8 -4
View File
@@ -6,7 +6,7 @@
#include "modules/loadavg/loadavg.h"
#include "util/stringUtils.h"
void ffPrintLoadavg(FFLoadavgOptions* options)
bool ffPrintLoadavg(FFLoadavgOptions* options)
{
double result[3] = { 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0 };
@@ -14,7 +14,7 @@ void ffPrintLoadavg(FFLoadavgOptions* options)
if(error)
{
ffPrintError(FF_LOADAVG_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if(options->moduleArgs.outputFormat.length == 0)
@@ -88,6 +88,8 @@ void ffPrintLoadavg(FFLoadavgOptions* options)
FF_FORMAT_ARG(result[2], "loadavg3"),
}));
}
return true;
}
void ffParseLoadavgJsonObject(FFLoadavgOptions* options, yyjson_val* module)
@@ -129,7 +131,7 @@ void ffGenerateLoadavgJsonConfig(FFLoadavgOptions* options, yyjson_mut_doc* doc,
ffPercentGenerateJsonConfig(doc, module, options->percent);
}
void ffGenerateLoadavgJsonResult(FF_MAYBE_UNUSED FFLoadavgOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateLoadavgJsonResult(FF_MAYBE_UNUSED FFLoadavgOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
double result[3] = { 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0 };
@@ -137,12 +139,14 @@ void ffGenerateLoadavgJsonResult(FF_MAYBE_UNUSED FFLoadavgOptions* options, yyjs
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
for (size_t i = 0; i < 3; i++)
yyjson_mut_arr_add_real(doc, arr, result[i]);
return true;
}
void ffInitLoadavgOptions(FFLoadavgOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_LOADAVG_MODULE_NAME "Loadavg"
void ffPrintLoadavg(FFLoadavgOptions* options);
bool ffPrintLoadavg(FFLoadavgOptions* options);
void ffInitLoadavgOptions(FFLoadavgOptions* options);
void ffDestroyLoadavgOptions(FFLoadavgOptions* options);
+8 -4
View File
@@ -4,7 +4,7 @@
#include "modules/locale/locale.h"
#include "util/stringUtils.h"
void ffPrintLocale(FFLocaleOptions* options)
bool ffPrintLocale(FFLocaleOptions* options)
{
FF_STRBUF_AUTO_DESTROY locale = ffStrbufCreate();
@@ -12,7 +12,7 @@ void ffPrintLocale(FFLocaleOptions* options)
if(locale.length == 0)
{
ffPrintError(FF_LOCALE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No locale found");
return;
return false;
}
if(options->moduleArgs.outputFormat.length == 0)
@@ -26,6 +26,8 @@ void ffPrintLocale(FFLocaleOptions* options)
FF_FORMAT_ARG(locale, "result")
}));
}
return true;
}
void ffParseLocaleJsonObject(FFLocaleOptions* options, yyjson_val* module)
@@ -46,7 +48,7 @@ void ffGenerateLocaleJsonConfig(FFLocaleOptions* options, yyjson_mut_doc* doc, y
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateLocaleJsonResult(FF_MAYBE_UNUSED FFLocaleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateLocaleJsonResult(FF_MAYBE_UNUSED FFLocaleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_STRBUF_AUTO_DESTROY locale = ffStrbufCreate();
@@ -54,10 +56,12 @@ void ffGenerateLocaleJsonResult(FF_MAYBE_UNUSED FFLocaleOptions* options, yyjson
if(locale.length == 0)
{
yyjson_mut_obj_add_str(doc, module, "error", "No locale found");
return;
return false;
}
yyjson_mut_obj_add_strbuf(doc, module, "result", &locale);
return true;
}
void ffInitLocaleOptions(FFLocaleOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_LOCALE_MODULE_NAME "Locale"
void ffPrintLocale(FFLocaleOptions* options);
bool ffPrintLocale(FFLocaleOptions* options);
void ffInitLocaleOptions(FFLocaleOptions* options);
void ffDestroyLocaleOptions(FFLocaleOptions* options);
+9 -5
View File
@@ -101,7 +101,7 @@ static void printIp(FFLocalIpResult* ip, bool markDefaultRoute, FFstrbuf* buffer
ffStrbufAppendS(buffer, " *");
}
void ffPrintLocalIp(FFLocalIpOptions* options)
bool ffPrintLocalIp(FFLocalIpOptions* options)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFLocalIpResult));
@@ -110,13 +110,13 @@ void ffPrintLocalIp(FFLocalIpOptions* options)
if(error)
{
ffPrintError(FF_LOCALIP_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if(results.length == 0)
{
ffPrintError(FF_LOCALIP_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Failed to detect any IPs");
return;
return false;
}
ffListSort(&results, (const void*) sortIps);
@@ -178,6 +178,8 @@ void ffPrintLocalIp(FFLocalIpOptions* options)
ffStrbufDestroy(&ip->mac);
ffStrbufDestroy(&ip->flags);
}
return true;
}
void ffParseLocalIpJsonObject(FFLocalIpOptions* options, yyjson_val* module)
@@ -327,7 +329,7 @@ void ffGenerateLocalIpJsonConfig(FFLocalIpOptions* options, yyjson_mut_doc* doc,
yyjson_mut_obj_add_strbuf(doc, module, "namePrefix", &options->namePrefix);
}
void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFLocalIpResult));
@@ -336,7 +338,7 @@ void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjs
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -374,6 +376,8 @@ void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjs
ffStrbufDestroy(&ip->mac);
ffStrbufDestroy(&ip->flags);
}
return true;
}
void ffInitLocalIpOptions(FFLocalIpOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_LOCALIP_MODULE_NAME "LocalIp"
void ffPrintLocalIp(FFLocalIpOptions* options);
bool ffPrintLocalIp(FFLocalIpOptions* options);
void ffInitLocalIpOptions(FFLocalIpOptions* options);
void ffDestroyLocalIpOptions(FFLocalIpOptions* options);
+8 -4
View File
@@ -41,14 +41,14 @@ static bool artistInSongTitle(const FFstrbuf* song, const FFstrbuf* artist)
return false;
}
void ffPrintMedia(FFMediaOptions* options)
bool ffPrintMedia(FFMediaOptions* options)
{
const FFMediaResult* media = ffDetectMedia();
if(media->error.length > 0)
{
ffPrintError(FF_MEDIA_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", media->error.chars);
return;
return false;
}
FF_STRBUF_AUTO_DESTROY songPretty = ffStrbufCreateCopy(&media->song);
@@ -104,6 +104,8 @@ void ffPrintMedia(FFMediaOptions* options)
FF_FORMAT_ARG(media->url, "url"),
}));
}
return true;
}
void ffParseMediaJsonObject(FFMediaOptions* options, yyjson_val* module)
@@ -124,14 +126,14 @@ void ffGenerateMediaJsonConfig(FFMediaOptions* options, yyjson_mut_doc* doc, yyj
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateMediaJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateMediaJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
const FFMediaResult* media = ffDetectMedia();
if(media->error.length > 0)
{
yyjson_mut_obj_add_strbuf(doc, module, "error", &media->error);
return;
return false;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
@@ -146,6 +148,8 @@ void ffGenerateMediaJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_m
yyjson_mut_obj_add_strbuf(doc, player, "name", &media->player);
yyjson_mut_obj_add_strbuf(doc, player, "id", &media->playerId);
yyjson_mut_obj_add_strbuf(doc, player, "url", &media->url);
return true;
}
void ffInitMediaOptions(FFMediaOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_MEDIA_MODULE_NAME "Media"
void ffPrintMedia(FFMediaOptions* options);
bool ffPrintMedia(FFMediaOptions* options);
void ffInitMediaOptions(FFMediaOptions* options);
void ffDestroyMediaOptions(FFMediaOptions* options);
+8 -4
View File
@@ -6,7 +6,7 @@
#include "modules/memory/memory.h"
#include "util/stringUtils.h"
void ffPrintMemory(FFMemoryOptions* options)
bool ffPrintMemory(FFMemoryOptions* options)
{
FFMemoryResult storage = {};
const char* error = ffDetectMemory(&storage);
@@ -14,7 +14,7 @@ void ffPrintMemory(FFMemoryOptions* options)
if(error)
{
ffPrintError(FF_MEMORY_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
FF_STRBUF_AUTO_DESTROY usedPretty = ffStrbufCreate();
@@ -69,6 +69,8 @@ void ffPrintMemory(FFMemoryOptions* options)
FF_FORMAT_ARG(percentageBar, "percentage-bar"),
}));
}
return true;
}
void ffParseMemoryJsonObject(FFMemoryOptions* options, yyjson_val* module)
@@ -94,7 +96,7 @@ void ffGenerateMemoryJsonConfig(FFMemoryOptions* options, yyjson_mut_doc* doc, y
ffPercentGenerateJsonConfig(doc, module, options->percent);
}
void ffGenerateMemoryJsonResult(FF_MAYBE_UNUSED FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateMemoryJsonResult(FF_MAYBE_UNUSED FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFMemoryResult storage = {};
const char* error = ffDetectMemory(&storage);
@@ -102,12 +104,14 @@ void ffGenerateMemoryJsonResult(FF_MAYBE_UNUSED FFMemoryOptions* options, yyjson
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_uint(doc, obj, "total", storage.bytesTotal);
yyjson_mut_obj_add_uint(doc, obj, "used", storage.bytesUsed);
return true;
}
void ffInitMemoryOptions(FFMemoryOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_MEMORY_MODULE_NAME "Memory"
void ffPrintMemory(FFMemoryOptions* options);
bool ffPrintMemory(FFMemoryOptions* options);
void ffInitMemoryOptions(FFMemoryOptions* options);
void ffDestroyMemoryOptions(FFMemoryOptions* options);
+6 -3
View File
@@ -6,14 +6,14 @@
#include <math.h>
void ffPrintMonitor(FFMonitorOptions* options)
bool ffPrintMonitor(FFMonitorOptions* options)
{
const FFDisplayServerResult* result = ffConnectDisplayServer();
if(!result->displays.length)
{
ffPrintError(FF_MONITOR_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No display detected");
return;
return false;
}
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
@@ -84,6 +84,8 @@ void ffPrintMonitor(FFMonitorOptions* options)
ffStrbufDestroy(&display->name);
++index;
}
return true;
}
void ffParseMonitorJsonObject(FFMonitorOptions* options, yyjson_val* module)
@@ -104,9 +106,10 @@ void ffGenerateMonitorJsonConfig(FFMonitorOptions* options, yyjson_mut_doc* doc,
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateMonitorJsonResult(FF_MAYBE_UNUSED FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateMonitorJsonResult(FF_MAYBE_UNUSED FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
yyjson_mut_obj_add_str(doc, module, "error", "Monitor module is an alias of Display module");
return false;
}
void ffInitMonitorOptions(FFMonitorOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_MONITOR_MODULE_NAME "Monitor"
void ffPrintMonitor(FFMonitorOptions* options);
bool ffPrintMonitor(FFMonitorOptions* options);
void ffInitMonitorOptions(FFMonitorOptions* options);
void ffDestroyMonitorOptions(FFMonitorOptions* options);
+9 -5
View File
@@ -21,7 +21,7 @@ static void printDevice(FFMouseOptions* options, const FFMouseDevice* device, ui
}
}
void ffPrintMouse(FFMouseOptions* options)
bool ffPrintMouse(FFMouseOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFMouseDevice));
@@ -30,13 +30,13 @@ void ffPrintMouse(FFMouseOptions* options)
if(error)
{
ffPrintError(FF_MOUSE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if(!result.length)
{
ffPrintError(FF_MOUSE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No devices detected");
return;
return false;
}
uint8_t index = 0;
@@ -46,6 +46,8 @@ void ffPrintMouse(FFMouseOptions* options)
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->name);
}
return true;
}
void ffParseMouseJsonObject(FFMouseOptions* options, yyjson_val* module)
@@ -66,7 +68,7 @@ void ffGenerateMouseJsonConfig(FFMouseOptions* options, yyjson_mut_doc* doc, yyj
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateMouseJsonResult(FF_MAYBE_UNUSED FFMouseOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateMouseJsonResult(FF_MAYBE_UNUSED FFMouseOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFMouseDevice));
@@ -75,7 +77,7 @@ void ffGenerateMouseJsonResult(FF_MAYBE_UNUSED FFMouseOptions* options, yyjson_m
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -91,6 +93,8 @@ void ffGenerateMouseJsonResult(FF_MAYBE_UNUSED FFMouseOptions* options, yyjson_m
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->name);
}
return true;
}
void ffInitMouseOptions(FFMouseOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_MOUSE_MODULE_NAME "Mouse"
void ffPrintMouse(FFMouseOptions* options);
bool ffPrintMouse(FFMouseOptions* options);
void ffInitMouseOptions(FFMouseOptions* options);
void ffDestroyMouseOptions(FFMouseOptions* options);
+8 -4
View File
@@ -32,7 +32,7 @@ static void formatKey(const FFNetIOOptions* options, FFNetIOResult* inf, uint32_
}
}
void ffPrintNetIO(FFNetIOOptions* options)
bool ffPrintNetIO(FFNetIOOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFNetIOResult));
const char* error = ffDetectNetIO(&result, options);
@@ -40,7 +40,7 @@ void ffPrintNetIO(FFNetIOOptions* options)
if(error)
{
ffPrintError(FF_NETIO_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
ffListSort(&result, (const void*) sortInfs);
@@ -101,6 +101,8 @@ void ffPrintNetIO(FFNetIOOptions* options)
{
ffStrbufDestroy(&inf->name);
}
return true;
}
void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module)
@@ -153,7 +155,7 @@ void ffGenerateNetIOJsonConfig(FFNetIOOptions* options, yyjson_mut_doc* doc, yyj
yyjson_mut_obj_add_uint(doc, module, "waitTime", options->waitTime);
}
void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFNetIOResult));
const char* error = ffDetectNetIO(&result, options);
@@ -161,7 +163,7 @@ void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyj
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -184,6 +186,8 @@ void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyj
{
ffStrbufDestroy(&inf->name);
}
return true;
}
void ffInitNetIOOptions(FFNetIOOptions* options)
+1 -1
View File
@@ -6,7 +6,7 @@
void ffPrepareNetIO(FFNetIOOptions* options);
void ffPrintNetIO(FFNetIOOptions* options);
bool ffPrintNetIO(FFNetIOOptions* options);
void ffInitNetIOOptions(FFNetIOOptions* options);
void ffDestroyNetIOOptions(FFNetIOOptions* options);
+8 -4
View File
@@ -5,14 +5,14 @@
#include "modules/opencl/opencl.h"
#include "util/stringUtils.h"
void ffPrintOpenCL(FFOpenCLOptions* options)
bool ffPrintOpenCL(FFOpenCLOptions* options)
{
FFOpenCLResult* result = ffDetectOpenCL();
if(result->error != NULL)
{
ffPrintError(FF_OPENCL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", result->error);
return;
return false;
}
if(options->moduleArgs.outputFormat.length == 0)
@@ -28,6 +28,8 @@ void ffPrintOpenCL(FFOpenCLOptions* options)
FF_FORMAT_ARG(result->vendor, "vendor"),
}));
}
return true;
}
void ffParseOpenCLJsonObject(FFOpenCLOptions* options, yyjson_val* module)
@@ -48,14 +50,14 @@ void ffGenerateOpenCLJsonConfig(FFOpenCLOptions* options, yyjson_mut_doc* doc, y
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateOpenCLJsonResult(FF_MAYBE_UNUSED FFOpenCLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateOpenCLJsonResult(FF_MAYBE_UNUSED FFOpenCLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFOpenCLResult* result = ffDetectOpenCL();
if(result->error != NULL)
{
yyjson_mut_obj_add_str(doc, module, "error", result->error);
return;
return false;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
@@ -109,6 +111,8 @@ void ffGenerateOpenCLJsonResult(FF_MAYBE_UNUSED FFOpenCLOptions* options, yyjson
yyjson_mut_obj_add_uint(doc, gpuObj, "deviceId", gpu->deviceId);
}
return true;
}
void ffInitOpenCLOptions(FFOpenCLOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_OPENCL_MODULE_NAME "OpenCL"
void ffPrintOpenCL(FFOpenCLOptions* options);
bool ffPrintOpenCL(FFOpenCLOptions* options);
void ffInitOpenCLOptions(FFOpenCLOptions* options);
void ffDestroyOpenCLOptions(FFOpenCLOptions* options);
+25 -16
View File
@@ -4,8 +4,9 @@
#include "modules/opengl/opengl.h"
#include "util/stringUtils.h"
void ffPrintOpenGL(FFOpenGLOptions* options)
bool ffPrintOpenGL(FFOpenGLOptions* options)
{
bool success = false;
FFOpenGLResult result;
ffStrbufInit(&result.version);
ffStrbufInit(&result.renderer);
@@ -17,23 +18,25 @@ void ffPrintOpenGL(FFOpenGLOptions* options)
if(error)
{
ffPrintError(FF_OPENGL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
}
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_OPENGL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
puts(result.version.chars);
}
else
{
FF_PRINT_FORMAT_CHECKED(FF_OPENGL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
FF_FORMAT_ARG(result.version, "version"),
FF_FORMAT_ARG(result.renderer, "renderer"),
FF_FORMAT_ARG(result.vendor, "vendor"),
FF_FORMAT_ARG(result.slv, "slv"),
FF_FORMAT_ARG(result.library, "library"),
}));
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_OPENGL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
puts(result.version.chars);
}
else
{
FF_PRINT_FORMAT_CHECKED(FF_OPENGL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
FF_FORMAT_ARG(result.version, "version"),
FF_FORMAT_ARG(result.renderer, "renderer"),
FF_FORMAT_ARG(result.vendor, "vendor"),
FF_FORMAT_ARG(result.slv, "slv"),
FF_FORMAT_ARG(result.library, "library"),
}));
}
success = true;
}
ffStrbufDestroy(&result.version);
@@ -41,6 +44,8 @@ void ffPrintOpenGL(FFOpenGLOptions* options)
ffStrbufDestroy(&result.vendor);
ffStrbufDestroy(&result.slv);
ffStrbufDestroy(&result.library);
return success;
}
void ffParseOpenGLJsonObject(FFOpenGLOptions* options, yyjson_val* module)
@@ -90,8 +95,9 @@ void ffGenerateOpenGLJsonConfig(FFOpenGLOptions* options, yyjson_mut_doc* doc, y
}
}
void ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
bool success = false;
FFOpenGLResult result;
ffStrbufInit(&result.version);
ffStrbufInit(&result.renderer);
@@ -112,6 +118,7 @@ void ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &result.vendor);
yyjson_mut_obj_add_strbuf(doc, obj, "slv", &result.slv);
yyjson_mut_obj_add_strbuf(doc, obj, "library", &result.library);
success = true;
}
ffStrbufDestroy(&result.version);
@@ -119,6 +126,8 @@ void ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson
ffStrbufDestroy(&result.vendor);
ffStrbufDestroy(&result.slv);
ffStrbufDestroy(&result.library);
return success;
}
void ffInitOpenGLOptions(FFOpenGLOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_OPENGL_MODULE_NAME "OpenGL"
void ffPrintOpenGL(FFOpenGLOptions* options);
bool ffPrintOpenGL(FFOpenGLOptions* options);
void ffInitOpenGLOptions(FFOpenGLOptions* options);
void ffDestroyOpenGLOptions(FFOpenGLOptions* options);
+8 -4
View File
@@ -53,14 +53,14 @@ static void buildOutputDefault(const FFOSResult* os, FFstrbuf* result)
}
}
void ffPrintOS(FFOSOptions* options)
bool ffPrintOS(FFOSOptions* options)
{
const FFOSResult* os = ffDetectOS();
if(os->name.length == 0 && os->prettyName.length == 0 && os->id.length == 0)
{
ffPrintError(FF_OS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Could not detect OS");
return;
return false;
}
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
@@ -113,6 +113,8 @@ void ffPrintOS(FFOSOptions* options)
FF_FORMAT_ARG(instance.state.platform.sysinfo.release, "kernel-release"),
}));
}
return true;
}
void ffParseOSJsonObject(FFOSOptions* options, yyjson_val* module)
@@ -133,14 +135,14 @@ void ffGenerateOSJsonConfig(FFOSOptions* options, yyjson_mut_doc* doc, yyjson_mu
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGenerateOSJsonResult(FF_MAYBE_UNUSED FFOSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGenerateOSJsonResult(FF_MAYBE_UNUSED FFOSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
const FFOSResult* os = ffDetectOS();
if(os->name.length == 0 && os->prettyName.length == 0 && os->id.length == 0)
{
yyjson_mut_obj_add_str(doc, module, "error", "Could not detect OS");
return;
return false;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
@@ -154,6 +156,8 @@ void ffGenerateOSJsonResult(FF_MAYBE_UNUSED FFOSOptions* options, yyjson_mut_doc
yyjson_mut_obj_add_strbuf(doc, obj, "variantID", &os->variantID);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &os->version);
yyjson_mut_obj_add_strbuf(doc, obj, "versionID", &os->versionID);
return true;
}
void ffInitOSOptions(FFOSOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_OS_MODULE_NAME "OS"
void ffPrintOS(FFOSOptions* options);
bool ffPrintOS(FFOSOptions* options);
void ffInitOSOptions(FFOSOptions* options);
void ffDestroyOSOptions(FFOSOptions* options);
+8 -4
View File
@@ -4,7 +4,7 @@
#include "modules/packages/packages.h"
#include "util/stringUtils.h"
void ffPrintPackages(FFPackagesOptions* options)
bool ffPrintPackages(FFPackagesOptions* options)
{
FFPackagesResult counts = {};
ffStrbufInit(&counts.pacmanBranch);
@@ -14,7 +14,7 @@ void ffPrintPackages(FFPackagesOptions* options)
if(error)
{
ffPrintError(FF_PACKAGES_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
uint32_t nixAll = counts.nixDefault + counts.nixSystem + counts.nixUser;
@@ -203,6 +203,8 @@ void ffPrintPackages(FFPackagesOptions* options)
}
ffStrbufDestroy(&counts.pacmanBranch);
return true;
}
void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module)
@@ -370,7 +372,7 @@ void ffGeneratePackagesJsonConfig(FFPackagesOptions* options, yyjson_mut_doc* do
yyjson_mut_obj_add_bool(doc, module, "combined", options->combined);
}
void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FFPackagesResult counts = {};
ffStrbufInit(&counts.pacmanBranch);
@@ -380,7 +382,7 @@ void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yy
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
@@ -427,6 +429,8 @@ void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yy
FF_APPEND_PACKAGE_COUNT(winget)
FF_APPEND_PACKAGE_COUNT(xbps)
yyjson_mut_obj_add_strbuf(doc, obj, "pacmanBranch", &counts.pacmanBranch);
return true;
}
void ffInitPackagesOptions(FFPackagesOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_PACKAGES_MODULE_NAME "Packages"
void ffPrintPackages(FFPackagesOptions* options);
bool ffPrintPackages(FFPackagesOptions* options);
void ffInitPackagesOptions(FFPackagesOptions* options);
void ffDestroyPackagesOptions(FFPackagesOptions* options);
+8 -4
View File
@@ -31,7 +31,7 @@ static void formatKey(const FFPhysicalDiskOptions* options, FFPhysicalDiskResult
}
}
void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options)
bool ffPrintPhysicalDisk(FFPhysicalDiskOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFPhysicalDiskResult));
const char* error = ffDetectPhysicalDisk(&result, options);
@@ -39,7 +39,7 @@ void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options)
if(error)
{
ffPrintError(FF_PHYSICALDISK_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
ffListSort(&result, (const void*) sortDevices);
@@ -131,6 +131,8 @@ void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options)
ffStrbufDestroy(&dev->serial);
ffStrbufDestroy(&dev->revision);
}
return true;
}
void ffParsePhysicalDiskJsonObject(FFPhysicalDiskOptions* options, yyjson_val* module)
@@ -164,7 +166,7 @@ void ffGeneratePhysicalDiskJsonConfig(FFPhysicalDiskOptions* options, yyjson_mut
ffTempsGenerateJsonConfig(doc, module, options->temp, options->tempConfig);
}
void ffGeneratePhysicalDiskJsonResult(FFPhysicalDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGeneratePhysicalDiskJsonResult(FFPhysicalDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFPhysicalDiskResult));
const char* error = ffDetectPhysicalDisk(&result, options);
@@ -172,7 +174,7 @@ void ffGeneratePhysicalDiskJsonResult(FFPhysicalDiskOptions* options, yyjson_mut
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -223,6 +225,8 @@ void ffGeneratePhysicalDiskJsonResult(FFPhysicalDiskOptions* options, yyjson_mut
ffStrbufDestroy(&dev->serial);
ffStrbufDestroy(&dev->revision);
}
return true;
}
void ffInitPhysicalDiskOptions(FFPhysicalDiskOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_PHYSICALDISK_MODULE_NAME "PhysicalDisk"
void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options);
bool ffPrintPhysicalDisk(FFPhysicalDiskOptions* options);
void ffInitPhysicalDiskOptions(FFPhysicalDiskOptions* options);
void ffDestroyPhysicalDiskOptions(FFPhysicalDiskOptions* options);
+9 -5
View File
@@ -8,7 +8,7 @@
#define FF_PHYSICALMEMORY_DISPLAY_NAME "Physical Memory"
void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
bool ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFPhysicalMemoryResult));
const char* error = ffDetectPhysicalMemory(&result);
@@ -16,13 +16,13 @@ void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
if(error)
{
ffPrintError(FF_PHYSICALMEMORY_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return;
return false;
}
if (result.length == 0)
{
ffPrintError(FF_PHYSICALMEMORY_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No physical memory detected");
return;
return false;
}
FF_STRBUF_AUTO_DESTROY prettySize = ffStrbufCreate();
@@ -78,6 +78,8 @@ void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options)
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->partNumber);
}
return true;
}
void ffParsePhysicalMemoryJsonObject(FFPhysicalMemoryOptions* options, yyjson_val* module)
@@ -98,7 +100,7 @@ void ffGeneratePhysicalMemoryJsonConfig(FFPhysicalMemoryOptions* options, yyjson
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGeneratePhysicalMemoryJsonResult(FF_MAYBE_UNUSED FFPhysicalMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGeneratePhysicalMemoryJsonResult(FF_MAYBE_UNUSED FFPhysicalMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFPhysicalMemoryResult));
const char* error = ffDetectPhysicalMemory(&result);
@@ -106,7 +108,7 @@ void ffGeneratePhysicalMemoryJsonResult(FF_MAYBE_UNUSED FFPhysicalMemoryOptions*
if(error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -134,6 +136,8 @@ void ffGeneratePhysicalMemoryJsonResult(FF_MAYBE_UNUSED FFPhysicalMemoryOptions*
ffStrbufDestroy(&device->serial);
ffStrbufDestroy(&device->partNumber);
}
return true;
}
void ffInitPhysicalMemoryOptions(FFPhysicalMemoryOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_PHYSICALMEMORY_MODULE_NAME "PhysicalMemory"
void ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options);
bool ffPrintPhysicalMemory(FFPhysicalMemoryOptions* options);
void ffInitPhysicalMemoryOptions(FFPhysicalMemoryOptions* options);
void ffDestroyPhysicalMemoryOptions(FFPhysicalMemoryOptions* options);
+7 -4
View File
@@ -8,20 +8,20 @@
#define FF_PLAYER_DISPLAY_NAME "Media Player"
void ffPrintPlayer(FFPlayerOptions* options)
bool ffPrintPlayer(FFPlayerOptions* options)
{
const FFMediaResult* media = ffDetectMedia();
if(media->error.length > 0)
{
ffPrintError(FF_PLAYER_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", media->error.chars);
return;
return false;
}
if (media->player.length == 0)
{
ffPrintError(FF_PLAYER_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No media player detected");
return;
return false;
}
FF_STRBUF_AUTO_DESTROY playerPretty = ffStrbufCreate();
@@ -79,6 +79,8 @@ void ffPrintPlayer(FFPlayerOptions* options)
FF_FORMAT_ARG(media->url, "url"),
}));
}
return true;
}
void ffParsePlayerJsonObject(FFPlayerOptions* options, yyjson_val* module)
@@ -99,9 +101,10 @@ void ffGeneratePlayerJsonConfig(FFPlayerOptions* options, yyjson_mut_doc* doc, y
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
void ffGeneratePlayerJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGeneratePlayerJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
yyjson_mut_obj_add_str(doc, module, "error", "Player module is an alias of Media module");
return false;
}
void ffInitPlayerOptions(FFPlayerOptions* options)
+1 -1
View File
@@ -5,7 +5,7 @@
#define FF_PLAYER_MODULE_NAME "Player"
void ffPrintPlayer(FFPlayerOptions* options);
bool ffPrintPlayer(FFPlayerOptions* options);
void ffInitPlayerOptions(FFPlayerOptions* options);
void ffDestroyPlayerOptions(FFPlayerOptions* options);
+37 -32
View File
@@ -6,7 +6,7 @@
#define FF_POWERADAPTER_DISPLAY_NAME "Power Adapter"
void ffPrintPowerAdapter(FFPowerAdapterOptions* options)
bool ffPrintPowerAdapter(FFPowerAdapterOptions* options)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFPowerAdapterResult));
@@ -15,45 +15,48 @@ void ffPrintPowerAdapter(FFPowerAdapterOptions* options)
if (error)
{
ffPrintError(FF_POWERADAPTER_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return false;
}
else if(results.length == 0)
if(results.length == 0)
{
ffPrintError(FF_POWERADAPTER_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No power adapters found");
return false;
}
else
for(uint8_t i = 0; i < (uint8_t) results.length; i++)
{
for(uint8_t i = 0; i < (uint8_t) results.length; i++)
FFPowerAdapterResult* result = FF_LIST_GET(FFPowerAdapterResult, results, i);
if(options->moduleArgs.outputFormat.length == 0)
{
FFPowerAdapterResult* result = FF_LIST_GET(FFPowerAdapterResult, results, i);
ffPrintLogoAndKey(FF_POWERADAPTER_DISPLAY_NAME, i, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_POWERADAPTER_DISPLAY_NAME, i, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
if(result->name.length > 0)
puts(result->name.chars);
else
printf("%dW\n", result->watts);
}
if(result->name.length > 0)
puts(result->name.chars);
else
{
FF_PRINT_FORMAT_CHECKED(FF_POWERADAPTER_DISPLAY_NAME, i, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){
FF_FORMAT_ARG(result->watts, "watts"),
FF_FORMAT_ARG(result->name, "name"),
FF_FORMAT_ARG(result->manufacturer, "manufacturer"),
FF_FORMAT_ARG(result->modelName, "model-name"),
FF_FORMAT_ARG(result->description, "description"),
FF_FORMAT_ARG(result->serial, "serial"),
}));
}
ffStrbufDestroy(&result->manufacturer);
ffStrbufDestroy(&result->description);
ffStrbufDestroy(&result->modelName);
ffStrbufDestroy(&result->name);
ffStrbufDestroy(&result->serial);
printf("%dW\n", result->watts);
}
else
{
FF_PRINT_FORMAT_CHECKED(FF_POWERADAPTER_DISPLAY_NAME, i, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){
FF_FORMAT_ARG(result->watts, "watts"),
FF_FORMAT_ARG(result->name, "name"),
FF_FORMAT_ARG(result->manufacturer, "manufacturer"),
FF_FORMAT_ARG(result->modelName, "model-name"),
FF_FORMAT_ARG(result->description, "description"),
FF_FORMAT_ARG(result->serial, "serial"),
}));
}
ffStrbufDestroy(&result->manufacturer);
ffStrbufDestroy(&result->description);
ffStrbufDestroy(&result->modelName);
ffStrbufDestroy(&result->name);
ffStrbufDestroy(&result->serial);
}
return true;
}
void ffGeneratePowerAdapterJsonConfig(FFPowerAdapterOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
@@ -74,7 +77,7 @@ void ffParsePowerAdapterJsonObject(FFPowerAdapterOptions* options, yyjson_val* m
}
}
void ffGeneratePowerAdapterJsonResult(FF_MAYBE_UNUSED FFPowerAdapterOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
bool ffGeneratePowerAdapterJsonResult(FF_MAYBE_UNUSED FFPowerAdapterOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFPowerAdapterResult));
@@ -83,7 +86,7 @@ void ffGeneratePowerAdapterJsonResult(FF_MAYBE_UNUSED FFPowerAdapterOptions* opt
if (error)
{
yyjson_mut_obj_add_str(doc, module, "error", error);
return;
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
@@ -106,6 +109,8 @@ void ffGeneratePowerAdapterJsonResult(FF_MAYBE_UNUSED FFPowerAdapterOptions* opt
ffStrbufDestroy(&item->name);
ffStrbufDestroy(&item->serial);
}
return true;
}
void ffInitPowerAdapterOptions(FFPowerAdapterOptions* options)
+1 -1
View File
@@ -4,7 +4,7 @@
#define FF_POWERADAPTER_MODULE_NAME "PowerAdapter"
void ffPrintPowerAdapter(FFPowerAdapterOptions* options);
bool ffPrintPowerAdapter(FFPowerAdapterOptions* options);
void ffInitPowerAdapterOptions(FFPowerAdapterOptions* options);
void ffDestroyPowerAdapterOptions(FFPowerAdapterOptions* options);

Some files were not shown because too many files have changed in this diff Show More