diff --git a/src/common/option.h b/src/common/option.h index a47b9b504..4b8ea3eab 100644 --- a/src/common/option.h +++ b/src/common/option.h @@ -29,11 +29,12 @@ typedef struct FFModuleBaseInfo // This is UB, because `void*` is not compatible with `FF*Options*`. // However we can't do it better unless we move to C++, so that `option` becomes a `this` pointer // https://stackoverflow.com/questions/559581/casting-a-function-pointer-to-another-type + void (*initOptions)(void* options); void (*destroyOptions)(void* options); void (*parseJsonObject)(void* options, struct yyjson_val *module); - void (*printModule)(void* options); - void (*generateJsonResult)(void* options, struct yyjson_mut_doc* doc, struct yyjson_mut_val* module); + bool (*printModule)(void* options); // true on success + bool (*generateJsonResult)(void* options, struct yyjson_mut_doc* doc, struct yyjson_mut_val* module); // true on success void (*generateJsonConfig)(void* options, struct yyjson_mut_doc* doc, struct yyjson_mut_val* obj); FFModuleFormatArgList formatArgs; } FFModuleBaseInfo; diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index 99bf86873..dc87a3269 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -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) diff --git a/src/modules/battery/battery.h b/src/modules/battery/battery.h index 820a7bc7c..16ad027d8 100644 --- a/src/modules/battery/battery.h +++ b/src/modules/battery/battery.h @@ -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); diff --git a/src/modules/bios/bios.c b/src/modules/bios/bios.c index d2f59629e..4eee62730 100644 --- a/src/modules/bios/bios.c +++ b/src/modules/bios/bios.c @@ -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) diff --git a/src/modules/bios/bios.h b/src/modules/bios/bios.h index 22b35edda..d3b077e4d 100644 --- a/src/modules/bios/bios.h +++ b/src/modules/bios/bios.h @@ -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); diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index b5e05f21b..ad6bcd064 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -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) diff --git a/src/modules/bluetooth/bluetooth.h b/src/modules/bluetooth/bluetooth.h index 889be9690..d9aa059e3 100644 --- a/src/modules/bluetooth/bluetooth.h +++ b/src/modules/bluetooth/bluetooth.h @@ -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); diff --git a/src/modules/bluetoothradio/bluetoothradio.c b/src/modules/bluetoothradio/bluetoothradio.c index 810b5f438..b127f9349 100644 --- a/src/modules/bluetoothradio/bluetoothradio.c +++ b/src/modules/bluetoothradio/bluetoothradio.c @@ -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) diff --git a/src/modules/bluetoothradio/bluetoothradio.h b/src/modules/bluetoothradio/bluetoothradio.h index 9d63525fe..4707f1ba5 100644 --- a/src/modules/bluetoothradio/bluetoothradio.h +++ b/src/modules/bluetoothradio/bluetoothradio.h @@ -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); diff --git a/src/modules/board/board.c b/src/modules/board/board.c index a9cf573f6..9f572e69f 100644 --- a/src/modules/board/board.c +++ b/src/modules/board/board.c @@ -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) diff --git a/src/modules/board/board.h b/src/modules/board/board.h index 3fdea021d..eae3d73c1 100644 --- a/src/modules/board/board.h +++ b/src/modules/board/board.h @@ -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); diff --git a/src/modules/bootmgr/bootmgr.c b/src/modules/bootmgr/bootmgr.c index 350499530..d953a1503 100644 --- a/src/modules/bootmgr/bootmgr.c +++ b/src/modules/bootmgr/bootmgr.c @@ -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) diff --git a/src/modules/bootmgr/bootmgr.h b/src/modules/bootmgr/bootmgr.h index 9150f5218..4f6a2bac2 100644 --- a/src/modules/bootmgr/bootmgr.h +++ b/src/modules/bootmgr/bootmgr.h @@ -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); diff --git a/src/modules/break/break.c b/src/modules/break/break.c index 34fb4c2ad..e3b958782 100644 --- a/src/modules/break/break.c +++ b/src/modules/break/break.c @@ -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) diff --git a/src/modules/break/break.h b/src/modules/break/break.h index 772d19744..f611b7379 100644 --- a/src/modules/break/break.h +++ b/src/modules/break/break.h @@ -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); diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index c3855b07d..cc758e285 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -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) diff --git a/src/modules/brightness/brightness.h b/src/modules/brightness/brightness.h index 3b443425f..085366141 100644 --- a/src/modules/brightness/brightness.h +++ b/src/modules/brightness/brightness.h @@ -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); diff --git a/src/modules/btrfs/btrfs.c b/src/modules/btrfs/btrfs.c index e337d4c72..e021d8035 100644 --- a/src/modules/btrfs/btrfs.c +++ b/src/modules/btrfs/btrfs.c @@ -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) diff --git a/src/modules/btrfs/btrfs.h b/src/modules/btrfs/btrfs.h index 3cd77df32..fc0c6abf4 100644 --- a/src/modules/btrfs/btrfs.h +++ b/src/modules/btrfs/btrfs.h @@ -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); diff --git a/src/modules/camera/camera.c b/src/modules/camera/camera.c index d12d7a662..19c28e95a 100644 --- a/src/modules/camera/camera.c +++ b/src/modules/camera/camera.c @@ -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) diff --git a/src/modules/camera/camera.h b/src/modules/camera/camera.h index 1de49bdca..e8b356040 100644 --- a/src/modules/camera/camera.h +++ b/src/modules/camera/camera.h @@ -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); diff --git a/src/modules/chassis/chassis.c b/src/modules/chassis/chassis.c index e1344ab2b..068e51cc0 100644 --- a/src/modules/chassis/chassis.c +++ b/src/modules/chassis/chassis.c @@ -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) diff --git a/src/modules/chassis/chassis.h b/src/modules/chassis/chassis.h index 47a80d6ff..d3ba4892c 100644 --- a/src/modules/chassis/chassis.h +++ b/src/modules/chassis/chassis.h @@ -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); diff --git a/src/modules/colors/colors.c b/src/modules/colors/colors.c index 27dae0f40..e3e9e04a7 100644 --- a/src/modules/colors/colors.c +++ b/src/modules/colors/colors.c @@ -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) diff --git a/src/modules/colors/colors.h b/src/modules/colors/colors.h index 3581dabd9..c88ccd7a5 100644 --- a/src/modules/colors/colors.h +++ b/src/modules/colors/colors.h @@ -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); diff --git a/src/modules/command/command.c b/src/modules/command/command.c index 5a92d3cea..a46d77115 100644 --- a/src/modules/command/command.c +++ b/src/modules/command/command.c @@ -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) diff --git a/src/modules/command/command.h b/src/modules/command/command.h index dd28a8056..204553747 100644 --- a/src/modules/command/command.h +++ b/src/modules/command/command.h @@ -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); diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index 857cdd2ab..69e0f3476 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -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) diff --git a/src/modules/cpu/cpu.h b/src/modules/cpu/cpu.h index c6be13500..33fff6bf5 100644 --- a/src/modules/cpu/cpu.h +++ b/src/modules/cpu/cpu.h @@ -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); diff --git a/src/modules/cpucache/cpucache.c b/src/modules/cpucache/cpucache.c index aeb9422b4..e3664909a 100644 --- a/src/modules/cpucache/cpucache.c +++ b/src/modules/cpucache/cpucache.c @@ -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) diff --git a/src/modules/cpucache/cpucache.h b/src/modules/cpucache/cpucache.h index 22987a857..5061b4441 100644 --- a/src/modules/cpucache/cpucache.h +++ b/src/modules/cpucache/cpucache.h @@ -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); diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index a86f78e20..8c2ffab57 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -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) diff --git a/src/modules/cpuusage/cpuusage.h b/src/modules/cpuusage/cpuusage.h index 221e74778..efa8b485c 100644 --- a/src/modules/cpuusage/cpuusage.h +++ b/src/modules/cpuusage/cpuusage.h @@ -6,7 +6,7 @@ void ffPrepareCPUUsage(); -void ffPrintCPUUsage(FFCPUUsageOptions* options); +bool ffPrintCPUUsage(FFCPUUsageOptions* options); void ffInitCPUUsageOptions(FFCPUUsageOptions* options); void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options); diff --git a/src/modules/cursor/cursor.c b/src/modules/cursor/cursor.c index d8ce2c26e..93e14dcbb 100644 --- a/src/modules/cursor/cursor.c +++ b/src/modules/cursor/cursor.c @@ -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) diff --git a/src/modules/cursor/cursor.h b/src/modules/cursor/cursor.h index c74031cfa..e7695692c 100644 --- a/src/modules/cursor/cursor.h +++ b/src/modules/cursor/cursor.h @@ -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); diff --git a/src/modules/custom/custom.c b/src/modules/custom/custom.c index 4c2b8137d..bee9ed21f 100644 --- a/src/modules/custom/custom.c +++ b/src/modules/custom/custom.c @@ -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) diff --git a/src/modules/custom/custom.h b/src/modules/custom/custom.h index f4dfefab0..628a621a3 100644 --- a/src/modules/custom/custom.h +++ b/src/modules/custom/custom.h @@ -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); diff --git a/src/modules/datetime/datetime.c b/src/modules/datetime/datetime.c index 213b3bfdc..233f11cf7 100644 --- a/src/modules/datetime/datetime.c +++ b/src/modules/datetime/datetime.c @@ -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) diff --git a/src/modules/datetime/datetime.h b/src/modules/datetime/datetime.h index bdf8f732d..29c6f54e4 100644 --- a/src/modules/datetime/datetime.h +++ b/src/modules/datetime/datetime.h @@ -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); diff --git a/src/modules/de/de.c b/src/modules/de/de.c index ac901566d..60870e3c9 100644 --- a/src/modules/de/de.c +++ b/src/modules/de/de.c @@ -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) diff --git a/src/modules/de/de.h b/src/modules/de/de.h index ca945380b..8aaf642d0 100644 --- a/src/modules/de/de.h +++ b/src/modules/de/de.h @@ -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); diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index ea74e4ef3..dd36da493 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -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) diff --git a/src/modules/disk/disk.h b/src/modules/disk/disk.h index c96155fe1..5f7820ac7 100644 --- a/src/modules/disk/disk.h +++ b/src/modules/disk/disk.h @@ -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); diff --git a/src/modules/diskio/diskio.c b/src/modules/diskio/diskio.c index 5fa60982e..e353d95f5 100644 --- a/src/modules/diskio/diskio.c +++ b/src/modules/diskio/diskio.c @@ -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) diff --git a/src/modules/diskio/diskio.h b/src/modules/diskio/diskio.h index ba3977bae..7fba81c9d 100644 --- a/src/modules/diskio/diskio.h +++ b/src/modules/diskio/diskio.h @@ -6,7 +6,7 @@ void ffPrepareDiskIO(FFDiskIOOptions* options); -void ffPrintDiskIO(FFDiskIOOptions* options); +bool ffPrintDiskIO(FFDiskIOOptions* options); void ffInitDiskIOOptions(FFDiskIOOptions* options); void ffDestroyDiskIOOptions(FFDiskIOOptions* options); diff --git a/src/modules/display/display.c b/src/modules/display/display.c index 33b48e911..c8f81f84e 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -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) diff --git a/src/modules/display/display.h b/src/modules/display/display.h index 8b9f41941..a0a4b3095 100644 --- a/src/modules/display/display.h +++ b/src/modules/display/display.h @@ -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); diff --git a/src/modules/dns/dns.c b/src/modules/dns/dns.c index aa36ceacb..a92784df6 100644 --- a/src/modules/dns/dns.c +++ b/src/modules/dns/dns.c @@ -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) diff --git a/src/modules/dns/dns.h b/src/modules/dns/dns.h index e33763775..aec4e85fc 100644 --- a/src/modules/dns/dns.h +++ b/src/modules/dns/dns.h @@ -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); diff --git a/src/modules/editor/editor.c b/src/modules/editor/editor.c index e001d22e8..6e1551402 100644 --- a/src/modules/editor/editor.c +++ b/src/modules/editor/editor.c @@ -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) diff --git a/src/modules/editor/editor.h b/src/modules/editor/editor.h index 0e5be29e1..293d0a6e1 100644 --- a/src/modules/editor/editor.h +++ b/src/modules/editor/editor.h @@ -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); diff --git a/src/modules/font/font.c b/src/modules/font/font.c index eedf32c4e..b85a9e94d 100644 --- a/src/modules/font/font.c +++ b/src/modules/font/font.c @@ -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) diff --git a/src/modules/font/font.h b/src/modules/font/font.h index 9d3630bd2..b793b9fdd 100644 --- a/src/modules/font/font.h +++ b/src/modules/font/font.h @@ -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); diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index 5b1b6f7d5..087e7dc35 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -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) diff --git a/src/modules/gamepad/gamepad.h b/src/modules/gamepad/gamepad.h index 7d252d8c0..395c90b2e 100644 --- a/src/modules/gamepad/gamepad.h +++ b/src/modules/gamepad/gamepad.h @@ -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); diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index d128ac6fb..64fb14380 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -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) diff --git a/src/modules/gpu/gpu.h b/src/modules/gpu/gpu.h index afc952d6c..e2a6f1424 100644 --- a/src/modules/gpu/gpu.h +++ b/src/modules/gpu/gpu.h @@ -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); diff --git a/src/modules/host/host.c b/src/modules/host/host.c index 9a265c058..b86e37d54 100644 --- a/src/modules/host/host.c +++ b/src/modules/host/host.c @@ -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) diff --git a/src/modules/host/host.h b/src/modules/host/host.h index 79f22e527..1f98fd406 100644 --- a/src/modules/host/host.h +++ b/src/modules/host/host.h @@ -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); diff --git a/src/modules/icons/icons.c b/src/modules/icons/icons.c index c1347790e..b50b85363 100644 --- a/src/modules/icons/icons.c +++ b/src/modules/icons/icons.c @@ -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) diff --git a/src/modules/icons/icons.h b/src/modules/icons/icons.h index 6f2bb877c..a583a2257 100644 --- a/src/modules/icons/icons.h +++ b/src/modules/icons/icons.h @@ -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); diff --git a/src/modules/initsystem/initsystem.c b/src/modules/initsystem/initsystem.c index 28ad9ba80..d32f7a6dd 100644 --- a/src/modules/initsystem/initsystem.c +++ b/src/modules/initsystem/initsystem.c @@ -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) diff --git a/src/modules/initsystem/initsystem.h b/src/modules/initsystem/initsystem.h index 37b601481..381b95543 100644 --- a/src/modules/initsystem/initsystem.h +++ b/src/modules/initsystem/initsystem.h @@ -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); diff --git a/src/modules/kernel/kernel.c b/src/modules/kernel/kernel.c index 042ef3735..62254b22c 100644 --- a/src/modules/kernel/kernel.c +++ b/src/modules/kernel/kernel.c @@ -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) diff --git a/src/modules/kernel/kernel.h b/src/modules/kernel/kernel.h index 743ac2148..010ec54c4 100644 --- a/src/modules/kernel/kernel.h +++ b/src/modules/kernel/kernel.h @@ -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); diff --git a/src/modules/keyboard/keyboard.c b/src/modules/keyboard/keyboard.c index ed67bf569..c02c8653b 100644 --- a/src/modules/keyboard/keyboard.c +++ b/src/modules/keyboard/keyboard.c @@ -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) diff --git a/src/modules/keyboard/keyboard.h b/src/modules/keyboard/keyboard.h index fee46ccb1..bd6e69c56 100644 --- a/src/modules/keyboard/keyboard.h +++ b/src/modules/keyboard/keyboard.h @@ -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); diff --git a/src/modules/lm/lm.c b/src/modules/lm/lm.c index df67aa076..0b17f3744 100644 --- a/src/modules/lm/lm.c +++ b/src/modules/lm/lm.c @@ -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) diff --git a/src/modules/lm/lm.h b/src/modules/lm/lm.h index 950ca6ad1..1ec33b649 100644 --- a/src/modules/lm/lm.h +++ b/src/modules/lm/lm.h @@ -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); diff --git a/src/modules/loadavg/loadavg.c b/src/modules/loadavg/loadavg.c index 8d1d76ead..793786e04 100644 --- a/src/modules/loadavg/loadavg.c +++ b/src/modules/loadavg/loadavg.c @@ -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) diff --git a/src/modules/loadavg/loadavg.h b/src/modules/loadavg/loadavg.h index 8ee495bf8..9af2786f9 100644 --- a/src/modules/loadavg/loadavg.h +++ b/src/modules/loadavg/loadavg.h @@ -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); diff --git a/src/modules/locale/locale.c b/src/modules/locale/locale.c index 1dc81d342..a5bc15a43 100644 --- a/src/modules/locale/locale.c +++ b/src/modules/locale/locale.c @@ -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) diff --git a/src/modules/locale/locale.h b/src/modules/locale/locale.h index a56a612ae..fd86e42c3 100644 --- a/src/modules/locale/locale.h +++ b/src/modules/locale/locale.h @@ -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); diff --git a/src/modules/localip/localip.c b/src/modules/localip/localip.c index 6892305ec..95c94d506 100644 --- a/src/modules/localip/localip.c +++ b/src/modules/localip/localip.c @@ -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) diff --git a/src/modules/localip/localip.h b/src/modules/localip/localip.h index 616469975..f9e9c4e43 100644 --- a/src/modules/localip/localip.h +++ b/src/modules/localip/localip.h @@ -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); diff --git a/src/modules/media/media.c b/src/modules/media/media.c index 1a175008f..f82b4b856 100644 --- a/src/modules/media/media.c +++ b/src/modules/media/media.c @@ -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) diff --git a/src/modules/media/media.h b/src/modules/media/media.h index af18735b9..8320227d8 100644 --- a/src/modules/media/media.h +++ b/src/modules/media/media.h @@ -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); diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index 659c44013..182d55567 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -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) diff --git a/src/modules/memory/memory.h b/src/modules/memory/memory.h index 5c43b4f75..7ed026fc3 100644 --- a/src/modules/memory/memory.h +++ b/src/modules/memory/memory.h @@ -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); diff --git a/src/modules/monitor/monitor.c b/src/modules/monitor/monitor.c index 65af67a12..46a4ad78e 100644 --- a/src/modules/monitor/monitor.c +++ b/src/modules/monitor/monitor.c @@ -6,14 +6,14 @@ #include -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) diff --git a/src/modules/monitor/monitor.h b/src/modules/monitor/monitor.h index 17320b22e..82f9491fe 100644 --- a/src/modules/monitor/monitor.h +++ b/src/modules/monitor/monitor.h @@ -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); diff --git a/src/modules/mouse/mouse.c b/src/modules/mouse/mouse.c index 00ce7d4ba..f7afcccb0 100644 --- a/src/modules/mouse/mouse.c +++ b/src/modules/mouse/mouse.c @@ -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) diff --git a/src/modules/mouse/mouse.h b/src/modules/mouse/mouse.h index 796c998e9..afbc20ff9 100644 --- a/src/modules/mouse/mouse.h +++ b/src/modules/mouse/mouse.h @@ -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); diff --git a/src/modules/netio/netio.c b/src/modules/netio/netio.c index 8e932d405..fd5c90349 100644 --- a/src/modules/netio/netio.c +++ b/src/modules/netio/netio.c @@ -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) diff --git a/src/modules/netio/netio.h b/src/modules/netio/netio.h index b5468347e..653b7e97c 100644 --- a/src/modules/netio/netio.h +++ b/src/modules/netio/netio.h @@ -6,7 +6,7 @@ void ffPrepareNetIO(FFNetIOOptions* options); -void ffPrintNetIO(FFNetIOOptions* options); +bool ffPrintNetIO(FFNetIOOptions* options); void ffInitNetIOOptions(FFNetIOOptions* options); void ffDestroyNetIOOptions(FFNetIOOptions* options); diff --git a/src/modules/opencl/opencl.c b/src/modules/opencl/opencl.c index 64f0ba63e..fd35e5bf5 100644 --- a/src/modules/opencl/opencl.c +++ b/src/modules/opencl/opencl.c @@ -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) diff --git a/src/modules/opencl/opencl.h b/src/modules/opencl/opencl.h index bf47c6fbe..aafab369f 100644 --- a/src/modules/opencl/opencl.h +++ b/src/modules/opencl/opencl.h @@ -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); diff --git a/src/modules/opengl/opengl.c b/src/modules/opengl/opengl.c index 9dc99887e..5dcc55540 100644 --- a/src/modules/opengl/opengl.c +++ b/src/modules/opengl/opengl.c @@ -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) diff --git a/src/modules/opengl/opengl.h b/src/modules/opengl/opengl.h index f60938d1e..8caffa5a5 100644 --- a/src/modules/opengl/opengl.h +++ b/src/modules/opengl/opengl.h @@ -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); diff --git a/src/modules/os/os.c b/src/modules/os/os.c index c3b3efd66..62ad4909c 100644 --- a/src/modules/os/os.c +++ b/src/modules/os/os.c @@ -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) diff --git a/src/modules/os/os.h b/src/modules/os/os.h index bf6ebf9d6..a53d28516 100644 --- a/src/modules/os/os.h +++ b/src/modules/os/os.h @@ -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); diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index d17911de0..1d1094ae7 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -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) diff --git a/src/modules/packages/packages.h b/src/modules/packages/packages.h index 8b904d48d..4e5876870 100644 --- a/src/modules/packages/packages.h +++ b/src/modules/packages/packages.h @@ -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); diff --git a/src/modules/physicaldisk/physicaldisk.c b/src/modules/physicaldisk/physicaldisk.c index 72ffe85f0..e6dca99d1 100644 --- a/src/modules/physicaldisk/physicaldisk.c +++ b/src/modules/physicaldisk/physicaldisk.c @@ -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) diff --git a/src/modules/physicaldisk/physicaldisk.h b/src/modules/physicaldisk/physicaldisk.h index e73b3f358..aaad8883e 100644 --- a/src/modules/physicaldisk/physicaldisk.h +++ b/src/modules/physicaldisk/physicaldisk.h @@ -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); diff --git a/src/modules/physicalmemory/physicalmemory.c b/src/modules/physicalmemory/physicalmemory.c index 09534595d..81e593f3f 100644 --- a/src/modules/physicalmemory/physicalmemory.c +++ b/src/modules/physicalmemory/physicalmemory.c @@ -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) diff --git a/src/modules/physicalmemory/physicalmemory.h b/src/modules/physicalmemory/physicalmemory.h index 7df2b6c94..feb3d1d29 100644 --- a/src/modules/physicalmemory/physicalmemory.h +++ b/src/modules/physicalmemory/physicalmemory.h @@ -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); diff --git a/src/modules/player/player.c b/src/modules/player/player.c index 347a2977e..69002cb48 100644 --- a/src/modules/player/player.c +++ b/src/modules/player/player.c @@ -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) diff --git a/src/modules/player/player.h b/src/modules/player/player.h index b99a6da6b..8b18d2982 100644 --- a/src/modules/player/player.h +++ b/src/modules/player/player.h @@ -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); diff --git a/src/modules/poweradapter/poweradapter.c b/src/modules/poweradapter/poweradapter.c index 00c96ab0e..1361bc60d 100644 --- a/src/modules/poweradapter/poweradapter.c +++ b/src/modules/poweradapter/poweradapter.c @@ -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) diff --git a/src/modules/poweradapter/poweradapter.h b/src/modules/poweradapter/poweradapter.h index 165060a5e..3e6102550 100644 --- a/src/modules/poweradapter/poweradapter.h +++ b/src/modules/poweradapter/poweradapter.h @@ -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); diff --git a/src/modules/processes/processes.c b/src/modules/processes/processes.c index e7740a448..fcec4c041 100644 --- a/src/modules/processes/processes.c +++ b/src/modules/processes/processes.c @@ -4,7 +4,7 @@ #include "modules/processes/processes.h" #include "util/stringUtils.h" -void ffPrintProcesses(FFProcessesOptions* options) +bool ffPrintProcesses(FFProcessesOptions* options) { uint32_t numProcesses = 0; const char* error = ffDetectProcesses(&numProcesses); @@ -12,7 +12,7 @@ void ffPrintProcesses(FFProcessesOptions* options) if(error) { ffPrintError(FF_PROCESSES_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + return false; } if(options->moduleArgs.outputFormat.length == 0) @@ -27,6 +27,8 @@ void ffPrintProcesses(FFProcessesOptions* options) FF_FORMAT_ARG(numProcesses, "result") })); } + + return true; } void ffParseProcessesJsonObject(FFProcessesOptions* options, yyjson_val* module) @@ -47,7 +49,7 @@ void ffGenerateProcessesJsonConfig(FFProcessesOptions* options, yyjson_mut_doc* ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateProcessesJsonResult(FF_MAYBE_UNUSED FFProcessesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateProcessesJsonResult(FF_MAYBE_UNUSED FFProcessesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { uint32_t result; const char* error = ffDetectProcesses(&result); @@ -55,10 +57,12 @@ void ffGenerateProcessesJsonResult(FF_MAYBE_UNUSED FFProcessesOptions* options, if(error) { yyjson_mut_obj_add_str(doc, module, "error", error); - return; + return false; } yyjson_mut_obj_add_uint(doc, module, "result", result); + + return true; } void ffInitProcessesOptions(FFProcessesOptions* options) diff --git a/src/modules/processes/processes.h b/src/modules/processes/processes.h index d9f0ae3d8..0220c17dd 100644 --- a/src/modules/processes/processes.h +++ b/src/modules/processes/processes.h @@ -4,7 +4,7 @@ #define FF_PROCESSES_MODULE_NAME "Processes" -void ffPrintProcesses(FFProcessesOptions* options); +bool ffPrintProcesses(FFProcessesOptions* options); void ffInitProcessesOptions(FFProcessesOptions* options); void ffDestroyProcessesOptions(FFProcessesOptions* options); diff --git a/src/modules/publicip/publicip.c b/src/modules/publicip/publicip.c index e52696dd6..493d3d531 100644 --- a/src/modules/publicip/publicip.c +++ b/src/modules/publicip/publicip.c @@ -6,7 +6,7 @@ #define FF_PUBLICIP_DISPLAY_NAME "Public IP" -void ffPrintPublicIp(FFPublicIPOptions* options) +bool ffPrintPublicIp(FFPublicIPOptions* options) { FFPublicIpResult result; ffStrbufInit(&result.ip); @@ -16,7 +16,7 @@ void ffPrintPublicIp(FFPublicIPOptions* options) if (error) { ffPrintError(FF_PUBLICIP_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + return false; } if (options->moduleArgs.outputFormat.length == 0) @@ -37,6 +37,8 @@ void ffPrintPublicIp(FFPublicIPOptions* options) ffStrbufDestroy(&result.ip); ffStrbufDestroy(&result.location); + + return true; } void ffParsePublicIpJsonObject(FFPublicIPOptions* options, yyjson_val* module) @@ -81,7 +83,7 @@ void ffGeneratePublicIpJsonConfig(FFPublicIPOptions* options, yyjson_mut_doc* do yyjson_mut_obj_add_bool(doc, module, "ipv6", options->ipv6); } -void ffGeneratePublicIpJsonResult(FFPublicIPOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGeneratePublicIpJsonResult(FFPublicIPOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFPublicIpResult result; ffStrbufInit(&result.ip); @@ -91,7 +93,7 @@ void ffGeneratePublicIpJsonResult(FFPublicIPOptions* options, yyjson_mut_doc* do 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"); @@ -100,6 +102,8 @@ void ffGeneratePublicIpJsonResult(FFPublicIPOptions* options, yyjson_mut_doc* do ffStrbufDestroy(&result.ip); ffStrbufDestroy(&result.location); + + return true; } void ffInitPublicIpOptions(FFPublicIPOptions* options) diff --git a/src/modules/publicip/publicip.h b/src/modules/publicip/publicip.h index 5fd70ab4f..92768cbb6 100644 --- a/src/modules/publicip/publicip.h +++ b/src/modules/publicip/publicip.h @@ -6,7 +6,7 @@ void ffPreparePublicIp(FFPublicIPOptions* options); -void ffPrintPublicIp(FFPublicIPOptions* options); +bool ffPrintPublicIp(FFPublicIPOptions* options); void ffInitPublicIpOptions(FFPublicIPOptions* options); void ffDestroyPublicIpOptions(FFPublicIPOptions* options); diff --git a/src/modules/separator/separator.c b/src/modules/separator/separator.c index 4e31590c7..79ca19f96 100644 --- a/src/modules/separator/separator.c +++ b/src/modules/separator/separator.c @@ -33,7 +33,7 @@ static inline uint32_t getWcsWidth(const FFstrbuf* mbstr, wchar_t* wstr, mbstate return result > 0 ? (uint32_t) result : mbstr->length; } -void ffPrintSeparator(FFSeparatorOptions* options) +bool ffPrintSeparator(FFSeparatorOptions* options) { ffLogoPrintLine(); @@ -111,6 +111,8 @@ void ffPrintSeparator(FFSeparatorOptions* options) if(options->outputColor.length && !instance.config.display.pipe) fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); putchar('\n'); + + return true; } void ffParseSeparatorJsonObject(FFSeparatorOptions* options, yyjson_val* module) diff --git a/src/modules/separator/separator.h b/src/modules/separator/separator.h index d23fc6c94..eebf39af3 100644 --- a/src/modules/separator/separator.h +++ b/src/modules/separator/separator.h @@ -4,7 +4,7 @@ #define FF_SEPARATOR_MODULE_NAME "Separator" -void ffPrintSeparator(FFSeparatorOptions* options); +bool ffPrintSeparator(FFSeparatorOptions* options); void ffInitSeparatorOptions(FFSeparatorOptions* options); void ffDestroySeparatorOptions(FFSeparatorOptions* options); diff --git a/src/modules/shell/shell.c b/src/modules/shell/shell.c index 42bb9149d..73feb0119 100644 --- a/src/modules/shell/shell.c +++ b/src/modules/shell/shell.c @@ -4,14 +4,14 @@ #include "modules/shell/shell.h" #include "util/stringUtils.h" -void ffPrintShell(FFShellOptions* options) +bool ffPrintShell(FFShellOptions* options) { const FFShellResult* result = ffDetectShell(); if(result->processName.length == 0) { ffPrintError(FF_SHELL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Couldn't detect shell"); - return; + return false; } if(options->moduleArgs.outputFormat.length == 0) @@ -40,6 +40,8 @@ void ffPrintShell(FFShellOptions* options) FF_FORMAT_ARG(result->tty, "tty"), })); } + + return true; } void ffParseShellJsonObject(FFShellOptions* options, yyjson_val* module) @@ -60,14 +62,14 @@ void ffGenerateShellJsonConfig(FFShellOptions* options, yyjson_mut_doc* doc, yyj ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateShellJsonResult(FF_MAYBE_UNUSED FFShellOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateShellJsonResult(FF_MAYBE_UNUSED FFShellOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFShellResult* result = ffDetectShell(); if(result->processName.length == 0) { yyjson_mut_obj_add_str(doc, module, "error", "Couldn't detect shell"); - return; + return false; } yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); @@ -83,6 +85,8 @@ void ffGenerateShellJsonResult(FF_MAYBE_UNUSED FFShellOptions* options, yyjson_m yyjson_mut_obj_add_int(doc, obj, "tty", result->tty); else yyjson_mut_obj_add_null(doc, obj, "tty"); + + return true; } void ffInitShellOptions(FFShellOptions* options) diff --git a/src/modules/shell/shell.h b/src/modules/shell/shell.h index db39aa964..50a094c80 100644 --- a/src/modules/shell/shell.h +++ b/src/modules/shell/shell.h @@ -4,7 +4,7 @@ #define FF_SHELL_MODULE_NAME "Shell" -void ffPrintShell(FFShellOptions* options); +bool ffPrintShell(FFShellOptions* options); void ffInitShellOptions(FFShellOptions* options); void ffDestroyShellOptions(FFShellOptions* options); diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index 1b4d0285c..e87af35d6 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -66,8 +66,9 @@ static void printDevice(FFSoundOptions* options, const FFSoundDevice* device, ui } } -void ffPrintSound(FFSoundOptions* options) +bool ffPrintSound(FFSoundOptions* options) { + bool success = false; FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFSoundDevice)); const char* error = ffDetectSound(&result); @@ -75,41 +76,47 @@ void ffPrintSound(FFSoundOptions* options) if(error) { ffPrintError(FF_SOUND_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + goto exit; } - FF_LIST_AUTO_DESTROY filtered = ffListCreate(sizeof(FFSoundDevice*)); - - FF_LIST_FOR_EACH(FFSoundDevice, device, result) { - switch (options->soundType) + FF_LIST_AUTO_DESTROY filtered = ffListCreate(sizeof(FFSoundDevice*)); + + FF_LIST_FOR_EACH(FFSoundDevice, device, result) { - case FF_SOUND_TYPE_MAIN: if (!device->main) continue; break; - case FF_SOUND_TYPE_ACTIVE: if (!device->active) continue; break; - case FF_SOUND_TYPE_ALL: break; + switch (options->soundType) + { + case FF_SOUND_TYPE_MAIN: if (!device->main) continue; break; + case FF_SOUND_TYPE_ACTIVE: if (!device->active) continue; break; + case FF_SOUND_TYPE_ALL: break; + } + + *(FFSoundDevice**)ffListAdd(&filtered) = device; } - *(FFSoundDevice**)ffListAdd(&filtered) = device; - } + if(filtered.length == 0) + { + ffPrintError(FF_SOUND_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No active sound devices found"); + goto exit; + } - if(filtered.length == 0) - { - ffPrintError(FF_SOUND_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No active sound devices found"); - return; - } - - uint8_t index = 1; - FF_LIST_FOR_EACH(FFSoundDevice*, device, filtered) - { - printDevice(options, *device, filtered.length == 1 ? 0 : index++); + uint8_t index = 1; + FF_LIST_FOR_EACH(FFSoundDevice*, device, filtered) + { + printDevice(options, *device, filtered.length == 1 ? 0 : index++); + } } + success = true; +exit: FF_LIST_FOR_EACH(FFSoundDevice, device, result) { ffStrbufDestroy(&device->identifier); ffStrbufDestroy(&device->name); ffStrbufDestroy(&device->platformApi); } + + return success; } void ffParseSoundJsonObject(FFSoundOptions* options, yyjson_val* module) @@ -164,7 +171,7 @@ void ffGenerateSoundJsonConfig(FFSoundOptions* options, yyjson_mut_doc* doc, yyj ffPercentGenerateJsonConfig(doc, module, options->percent); } -void ffGenerateSoundJsonResult(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateSoundJsonResult(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFSoundDevice)); const char* error = ffDetectSound(&result); @@ -172,7 +179,7 @@ void ffGenerateSoundJsonResult(FF_MAYBE_UNUSED FFSoundOptions* 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"); @@ -198,6 +205,8 @@ void ffGenerateSoundJsonResult(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_m ffStrbufDestroy(&device->name); ffStrbufDestroy(&device->platformApi); } + + return true; } void ffInitSoundOptions(FFSoundOptions* options) diff --git a/src/modules/sound/sound.h b/src/modules/sound/sound.h index 80766b5ae..a23f8d5e1 100644 --- a/src/modules/sound/sound.h +++ b/src/modules/sound/sound.h @@ -4,7 +4,7 @@ #define FF_SOUND_MODULE_NAME "Sound" -void ffPrintSound(FFSoundOptions* options); +bool ffPrintSound(FFSoundOptions* options); void ffInitSoundOptions(FFSoundOptions* options); void ffDestroySoundOptions(FFSoundOptions* options); diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index 45e01c77b..d336cf972 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -91,7 +91,7 @@ void printSwap(FFSwapOptions* options, uint8_t index, FFSwapResult* storage) } } -void ffPrintSwap(FFSwapOptions* options) +bool ffPrintSwap(FFSwapOptions* options) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFSwapResult)); const char* error = ffDetectSwap(&result); @@ -99,7 +99,7 @@ void ffPrintSwap(FFSwapOptions* options) if(error) { ffPrintError(FF_SWAP_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + return false; } if (options->separate) @@ -129,6 +129,8 @@ void ffPrintSwap(FFSwapOptions* options) { ffStrbufDestroy(&storage->name); } + + return true; } void ffParseSwapJsonObject(FFSwapOptions* options, yyjson_val* module) @@ -161,7 +163,7 @@ void ffGenerateSwapJsonConfig(FFSwapOptions* options, yyjson_mut_doc* doc, yyjso yyjson_mut_obj_add_bool(doc, module, "separate", options->separate); } -void ffGenerateSwapJsonResult(FF_MAYBE_UNUSED FFSwapOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateSwapJsonResult(FF_MAYBE_UNUSED FFSwapOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFSwapResult)); const char* error = ffDetectSwap(&result); @@ -169,7 +171,7 @@ void ffGenerateSwapJsonResult(FF_MAYBE_UNUSED FFSwapOptions* 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"); @@ -185,6 +187,8 @@ void ffGenerateSwapJsonResult(FF_MAYBE_UNUSED FFSwapOptions* options, yyjson_mut { ffStrbufDestroy(&storage->name); } + + return true; } void ffInitSwapOptions(FFSwapOptions* options) diff --git a/src/modules/swap/swap.h b/src/modules/swap/swap.h index 7f31ecd01..e6b9a8b8e 100644 --- a/src/modules/swap/swap.h +++ b/src/modules/swap/swap.h @@ -4,7 +4,7 @@ #define FF_SWAP_MODULE_NAME "Swap" -void ffPrintSwap(FFSwapOptions* options); +bool ffPrintSwap(FFSwapOptions* options); void ffInitSwapOptions(FFSwapOptions* options); void ffDestroySwapOptions(FFSwapOptions* options); diff --git a/src/modules/terminal/terminal.c b/src/modules/terminal/terminal.c index f5085421d..fdaf93dcc 100644 --- a/src/modules/terminal/terminal.c +++ b/src/modules/terminal/terminal.c @@ -4,14 +4,14 @@ #include "modules/terminal/terminal.h" #include "util/stringUtils.h" -void ffPrintTerminal(FFTerminalOptions* options) +bool ffPrintTerminal(FFTerminalOptions* options) { const FFTerminalResult* result = ffDetectTerminal(); if(result->processName.length == 0) { ffPrintError(FF_TERMINAL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Couldn't detect terminal"); - return; + return false; } if(options->moduleArgs.outputFormat.length == 0) @@ -36,6 +36,8 @@ void ffPrintTerminal(FFTerminalOptions* options) FF_FORMAT_ARG(result->tty, "tty"), })); } + + return true; } void ffParseTerminalJsonObject(FFTerminalOptions* options, yyjson_val* module) @@ -56,14 +58,14 @@ void ffGenerateTerminalJsonConfig(FFTerminalOptions* options, yyjson_mut_doc* do ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateTerminalJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateTerminalJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFTerminalResult* result = ffDetectTerminal(); if(result->processName.length == 0) { yyjson_mut_obj_add_str(doc, module, "error", "Couldn't detect terminal"); - return; + return false; } yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); @@ -76,6 +78,8 @@ void ffGenerateTerminalJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yy yyjson_mut_obj_add_strbuf(doc, obj, "prettyName", &result->prettyName); yyjson_mut_obj_add_strbuf(doc, obj, "version", &result->version); yyjson_mut_obj_add_strbuf(doc, obj, "tty", &result->tty); + + return true; } void ffInitTerminalOptions(FFTerminalOptions* options) diff --git a/src/modules/terminal/terminal.h b/src/modules/terminal/terminal.h index df30bfadf..bb7c9a10d 100644 --- a/src/modules/terminal/terminal.h +++ b/src/modules/terminal/terminal.h @@ -4,7 +4,7 @@ #define FF_TERMINAL_MODULE_NAME "Terminal" -void ffPrintTerminal(FFTerminalOptions* options); +bool ffPrintTerminal(FFTerminalOptions* options); void ffInitTerminalOptions(FFTerminalOptions* options); void ffDestroyTerminalOptions(FFTerminalOptions* options); diff --git a/src/modules/terminalfont/terminalfont.c b/src/modules/terminalfont/terminalfont.c index 7ba2fc673..b99ed6eda 100644 --- a/src/modules/terminalfont/terminalfont.c +++ b/src/modules/terminalfont/terminalfont.c @@ -6,8 +6,9 @@ #define FF_TERMINALFONT_DISPLAY_NAME "Terminal Font" -void ffPrintTerminalFont(FFTerminalFontOptions* options) +bool ffPrintTerminalFont(FFTerminalFontOptions* options) { + bool success = false; FFTerminalFontResult terminalFont; ffFontInit(&terminalFont.font); ffFontInit(&terminalFont.fallback); @@ -39,11 +40,14 @@ void ffPrintTerminalFont(FFTerminalFontOptions* options) FF_FORMAT_ARG(terminalFont.font.styles, "styles"), })); } + success = true; } ffStrbufDestroy(&terminalFont.error); ffFontDestroy(&terminalFont.font); ffFontDestroy(&terminalFont.fallback); + + return success; } void ffParseTerminalFontJsonObject(FFTerminalFontOptions* options, yyjson_val* module) @@ -64,8 +68,9 @@ void ffGenerateTerminalFontJsonConfig(FFTerminalFontOptions* options, yyjson_mut ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateTerminalFontJsonResult(FF_MAYBE_UNUSED FFTerminalFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateTerminalFontJsonResult(FF_MAYBE_UNUSED FFTerminalFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { + bool success = false; FFTerminalFontResult result; ffFontInit(&result.font); ffFontInit(&result.fallback); @@ -96,11 +101,13 @@ void ffGenerateTerminalFontJsonResult(FF_MAYBE_UNUSED FFTerminalFontOptions* opt yyjson_mut_arr_add_strbuf(doc, fallbackStyles, style); } yyjson_mut_obj_add_strbuf(doc, fallback, "pretty", &result.fallback.pretty); + success = true; } ffStrbufDestroy(&result.error); ffFontDestroy(&result.font); ffFontDestroy(&result.fallback); + return success; } void ffInitTerminalFontOptions(FFTerminalFontOptions* options) diff --git a/src/modules/terminalfont/terminalfont.h b/src/modules/terminalfont/terminalfont.h index c1716912a..04987a61e 100644 --- a/src/modules/terminalfont/terminalfont.h +++ b/src/modules/terminalfont/terminalfont.h @@ -4,7 +4,7 @@ #define FF_TERMINALFONT_MODULE_NAME "TerminalFont" -void ffPrintTerminalFont(FFTerminalFontOptions* options); +bool ffPrintTerminalFont(FFTerminalFontOptions* options); void ffInitTerminalFontOptions(FFTerminalFontOptions* options); void ffDestroyTerminalFontOptions(FFTerminalFontOptions* options); diff --git a/src/modules/terminalsize/terminalsize.c b/src/modules/terminalsize/terminalsize.c index bc220107e..b604c597c 100644 --- a/src/modules/terminalsize/terminalsize.c +++ b/src/modules/terminalsize/terminalsize.c @@ -6,36 +6,36 @@ #define FF_TERMINALSIZE_DISPLAY_NAME "Terminal Size" -void ffPrintTerminalSize(FFTerminalSizeOptions* options) +bool ffPrintTerminalSize(FFTerminalSizeOptions* options) { FFTerminalSizeResult result = {}; if(!ffDetectTerminalSize(&result)) { ffPrintError(FF_TERMINALSIZE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Failed to detect terminal size"); + return false; + } + + if(options->moduleArgs.outputFormat.length == 0) + { + ffPrintLogoAndKey(FF_TERMINALSIZE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + printf("%u columns x %u rows", result.columns, result.rows); + + if (result.width != 0 && result.height != 0) + printf(" (%upx x %upx)", result.width, result.height); + + putchar('\n'); } else { - if(options->moduleArgs.outputFormat.length == 0) - { - ffPrintLogoAndKey(FF_TERMINALSIZE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); - printf("%u columns x %u rows", result.columns, result.rows); - - if (result.width != 0 && result.height != 0) - printf(" (%upx x %upx)", result.width, result.height); - - putchar('\n'); - } - else - { - FF_PRINT_FORMAT_CHECKED(FF_TERMINALSIZE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){ - FF_FORMAT_ARG(result.rows, "rows"), - FF_FORMAT_ARG(result.columns, "columns"), - FF_FORMAT_ARG(result.width, "width"), - FF_FORMAT_ARG(result.height, "height"), - })); - } + FF_PRINT_FORMAT_CHECKED(FF_TERMINALSIZE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){ + FF_FORMAT_ARG(result.rows, "rows"), + FF_FORMAT_ARG(result.columns, "columns"), + FF_FORMAT_ARG(result.width, "width"), + FF_FORMAT_ARG(result.height, "height"), + })); } + return true; } void ffParseTerminalSizeJsonObject(FFTerminalSizeOptions* options, yyjson_val* module) @@ -56,14 +56,14 @@ void ffGenerateTerminalSizeJsonConfig(FFTerminalSizeOptions* options, yyjson_mut ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateTerminalSizeJsonResult(FF_MAYBE_UNUSED FFTerminalSizeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateTerminalSizeJsonResult(FF_MAYBE_UNUSED FFTerminalSizeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFTerminalSizeResult result; if(!ffDetectTerminalSize(&result)) { yyjson_mut_obj_add_str(doc, module, "error", "Failed to detect terminal size"); - return; + return false; } yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); @@ -71,6 +71,8 @@ void ffGenerateTerminalSizeJsonResult(FF_MAYBE_UNUSED FFTerminalSizeOptions* opt yyjson_mut_obj_add_uint(doc, obj, "rows", result.rows); yyjson_mut_obj_add_uint(doc, obj, "width", result.width); yyjson_mut_obj_add_uint(doc, obj, "height", result.height); + + return true; } void ffInitTerminalSizeOptions(FFTerminalSizeOptions* options) diff --git a/src/modules/terminalsize/terminalsize.h b/src/modules/terminalsize/terminalsize.h index 859d09b0c..3cd05d5b2 100644 --- a/src/modules/terminalsize/terminalsize.h +++ b/src/modules/terminalsize/terminalsize.h @@ -4,7 +4,7 @@ #define FF_TERMINALSIZE_MODULE_NAME "TerminalSize" -void ffPrintTerminalSize(FFTerminalSizeOptions* options); +bool ffPrintTerminalSize(FFTerminalSizeOptions* options); void ffInitTerminalSizeOptions(FFTerminalSizeOptions* options); void ffDestroyTerminalSizeOptions(FFTerminalSizeOptions* options); diff --git a/src/modules/terminaltheme/terminaltheme.c b/src/modules/terminaltheme/terminaltheme.c index e6286dd6a..f77d5e60c 100644 --- a/src/modules/terminaltheme/terminaltheme.c +++ b/src/modules/terminaltheme/terminaltheme.c @@ -8,39 +8,40 @@ #define FF_TERMINALTHEME_DISPLAY_NAME "Terminal Theme" -void ffPrintTerminalTheme(FFTerminalThemeOptions* options) +bool ffPrintTerminalTheme(FFTerminalThemeOptions* options) { FFTerminalThemeResult result = {}; if(!ffDetectTerminalTheme(&result, false)) { ffPrintError(FF_TERMINALTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Failed to detect terminal theme"); + return false; + } + + if(options->moduleArgs.outputFormat.length == 0) + { + ffPrintLogoAndKey(FF_TERMINALTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + printf("#%02" PRIX16 "%02" PRIX16 "%02" PRIX16 " (FG) - #%02" PRIX16 "%02" PRIX16 "%02" PRIX16 " (BG) [%s]\n", + result.fg.r, result.fg.g, result.fg.b, + result.bg.r, result.bg.g, result.bg.b, + result.bg.dark ? "Dark" : "Light"); } else { - if(options->moduleArgs.outputFormat.length == 0) - { - ffPrintLogoAndKey(FF_TERMINALTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); - printf("#%02" PRIX16 "%02" PRIX16 "%02" PRIX16 " (FG) - #%02" PRIX16 "%02" PRIX16 "%02" PRIX16 " (BG) [%s]\n", - result.fg.r, result.fg.g, result.fg.b, - result.bg.r, result.bg.g, result.bg.b, - result.bg.dark ? "Dark" : "Light"); - } - else - { - char fg[32], bg[32]; - const char* fgType = result.fg.dark ? "Dark" : "Light"; - const char* bgType = result.bg.dark ? "Dark" : "Light"; - snprintf(fg, ARRAY_SIZE(fg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.fg.r, result.fg.g, result.fg.b); - snprintf(bg, ARRAY_SIZE(bg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.bg.r, result.bg.g, result.bg.b); - FF_PRINT_FORMAT_CHECKED(FF_TERMINALTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){ - FF_FORMAT_ARG(fg, "fg-color"), - FF_FORMAT_ARG(fgType, "fg-type"), - FF_FORMAT_ARG(bg, "bg-color"), - FF_FORMAT_ARG(bgType, "bg-type"), - })); - } + char fg[32], bg[32]; + const char* fgType = result.fg.dark ? "Dark" : "Light"; + const char* bgType = result.bg.dark ? "Dark" : "Light"; + snprintf(fg, ARRAY_SIZE(fg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.fg.r, result.fg.g, result.fg.b); + snprintf(bg, ARRAY_SIZE(bg), "#%02" PRIX16 "%02" PRIX16 "%02" PRIX16, result.bg.r, result.bg.g, result.bg.b); + FF_PRINT_FORMAT_CHECKED(FF_TERMINALTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){ + FF_FORMAT_ARG(fg, "fg-color"), + FF_FORMAT_ARG(fgType, "fg-type"), + FF_FORMAT_ARG(bg, "bg-color"), + FF_FORMAT_ARG(bgType, "bg-type"), + })); } + + return true; } void ffParseTerminalThemeJsonObject(FFTerminalThemeOptions* options, yyjson_val* module) @@ -61,14 +62,14 @@ void ffGenerateTerminalThemeJsonConfig(FFTerminalThemeOptions* options, yyjson_m ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateTerminalThemeJsonResult(FF_MAYBE_UNUSED FFTerminalThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateTerminalThemeJsonResult(FF_MAYBE_UNUSED FFTerminalThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFTerminalThemeResult result = {}; if(!ffDetectTerminalTheme(&result, false)) { yyjson_mut_obj_add_str(doc, module, "error", "Failed to detect terminal theme"); - return; + return false; } yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); @@ -84,6 +85,8 @@ void ffGenerateTerminalThemeJsonResult(FF_MAYBE_UNUSED FFTerminalThemeOptions* o yyjson_mut_obj_add_uint(doc, bg, "g", result.bg.g); yyjson_mut_obj_add_uint(doc, bg, "b", result.bg.b); yyjson_mut_obj_add_bool(doc, bg, "dark", result.bg.dark); + + return true; } void ffInitTerminalThemeOptions(FFTerminalThemeOptions* options) diff --git a/src/modules/terminaltheme/terminaltheme.h b/src/modules/terminaltheme/terminaltheme.h index dbe6ac192..db120f74c 100644 --- a/src/modules/terminaltheme/terminaltheme.h +++ b/src/modules/terminaltheme/terminaltheme.h @@ -4,7 +4,7 @@ #define FF_TERMINALTHEME_MODULE_NAME "TerminalTheme" -void ffPrintTerminalTheme(FFTerminalThemeOptions* options); +bool ffPrintTerminalTheme(FFTerminalThemeOptions* options); void ffInitTerminalThemeOptions(FFTerminalThemeOptions* options); void ffDestroyTerminalThemeOptions(FFTerminalThemeOptions* options); diff --git a/src/modules/theme/theme.c b/src/modules/theme/theme.c index d0945fb0d..89cd332d2 100644 --- a/src/modules/theme/theme.c +++ b/src/modules/theme/theme.c @@ -4,7 +4,7 @@ #include "modules/theme/theme.h" #include "util/stringUtils.h" -void ffPrintTheme(FFThemeOptions* options) +bool ffPrintTheme(FFThemeOptions* options) { FFThemeResult result = { .theme1 = ffStrbufCreate(), @@ -15,7 +15,7 @@ void ffPrintTheme(FFThemeOptions* options) if(error) { ffPrintError(FF_THEME_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + return false; } if(options->moduleArgs.outputFormat.length == 0) @@ -41,6 +41,7 @@ void ffPrintTheme(FFThemeOptions* options) ffStrbufDestroy(&result.theme1); ffStrbufDestroy(&result.theme2); + return true; } void ffParseThemeJsonObject(FFThemeOptions* options, yyjson_val* module) @@ -61,7 +62,7 @@ void ffGenerateThemeJsonConfig(FFThemeOptions* options, yyjson_mut_doc* doc, yyj ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateThemeJsonResult(FF_MAYBE_UNUSED FFThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateThemeJsonResult(FF_MAYBE_UNUSED FFThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFThemeResult result = { .theme1 = ffStrbufCreate(), @@ -72,7 +73,7 @@ void ffGenerateThemeJsonResult(FF_MAYBE_UNUSED FFThemeOptions* options, yyjson_m if(error) { yyjson_mut_obj_add_str(doc, module, "error", error); - return; + return false; } yyjson_mut_val* theme = yyjson_mut_obj_add_obj(doc, module, "result"); @@ -81,6 +82,8 @@ void ffGenerateThemeJsonResult(FF_MAYBE_UNUSED FFThemeOptions* options, yyjson_m ffStrbufDestroy(&result.theme1); ffStrbufDestroy(&result.theme2); + + return true; } void ffInitThemeOptions(FFThemeOptions* options) diff --git a/src/modules/theme/theme.h b/src/modules/theme/theme.h index 6d677a2d0..56ba49c81 100644 --- a/src/modules/theme/theme.h +++ b/src/modules/theme/theme.h @@ -4,7 +4,7 @@ #define FF_THEME_MODULE_NAME "Theme" -void ffPrintTheme(FFThemeOptions* options); +bool ffPrintTheme(FFThemeOptions* options); void ffInitThemeOptions(FFThemeOptions* options); void ffDestroyThemeOptions(FFThemeOptions* options); diff --git a/src/modules/title/title.c b/src/modules/title/title.c index d05a86b62..dd8519208 100644 --- a/src/modules/title/title.c +++ b/src/modules/title/title.c @@ -21,7 +21,7 @@ static void appendText(FFstrbuf* output, const FFstrbuf* text, const FFstrbuf* c ffStrbufAppendS(output, FASTFETCH_TEXT_MODIFIER_RESET); } -void ffPrintTitle(FFTitleOptions* options) +bool ffPrintTitle(FFTitleOptions* options) { FF_STRBUF_AUTO_DESTROY userNameColored = ffStrbufCreate(); appendText(&userNameColored, &instance.state.platform.userName, &options->colorUser); @@ -66,6 +66,8 @@ void ffPrintTitle(FFTitleOptions* options) FF_FORMAT_ARG(instance.state.platform.fullUserName, "full-user-name"), })); } + + return true; } void ffParseTitleJsonObject(FFTitleOptions* options, yyjson_val* module) @@ -116,7 +118,7 @@ void ffGenerateTitleJsonConfig(FFTitleOptions* options, yyjson_mut_doc* doc, yyj yyjson_mut_obj_add_strbuf(doc, color, "host", &options->colorHost); } -void ffGenerateTitleJsonResult(FF_MAYBE_UNUSED FFTitleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateTitleJsonResult(FF_MAYBE_UNUSED FFTitleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); yyjson_mut_obj_add_strbuf(doc, obj, "userName", &instance.state.platform.userName); @@ -125,6 +127,8 @@ void ffGenerateTitleJsonResult(FF_MAYBE_UNUSED FFTitleOptions* options, yyjson_m yyjson_mut_obj_add_strbuf(doc, obj, "homeDir", &instance.state.platform.homeDir); yyjson_mut_obj_add_strbuf(doc, obj, "exePath", &instance.state.platform.exePath); yyjson_mut_obj_add_strbuf(doc, obj, "userShell", &instance.state.platform.userShell); + + return true; } void ffInitTitleOptions(FFTitleOptions* options) diff --git a/src/modules/title/title.h b/src/modules/title/title.h index 4a41bcfe6..83c949654 100644 --- a/src/modules/title/title.h +++ b/src/modules/title/title.h @@ -4,7 +4,7 @@ #define FF_TITLE_MODULE_NAME "Title" -void ffPrintTitle(FFTitleOptions* options); +bool ffPrintTitle(FFTitleOptions* options); void ffInitTitleOptions(FFTitleOptions* options); void ffDestroyTitleOptions(FFTitleOptions* options); diff --git a/src/modules/tpm/tpm.c b/src/modules/tpm/tpm.c index ad540bf12..b3f4e53cf 100644 --- a/src/modules/tpm/tpm.c +++ b/src/modules/tpm/tpm.c @@ -4,7 +4,7 @@ #include "modules/tpm/tpm.h" #include "util/stringUtils.h" -void ffPrintTPM(FFTPMOptions* options) +bool ffPrintTPM(FFTPMOptions* options) { FFTPMResult result = { .version = ffStrbufCreate(), @@ -15,7 +15,7 @@ void ffPrintTPM(FFTPMOptions* options) if(error) { ffPrintError(FF_TPM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + return false; } if(options->moduleArgs.outputFormat.length == 0) @@ -36,6 +36,8 @@ void ffPrintTPM(FFTPMOptions* options) ffStrbufDestroy(&result.version); ffStrbufDestroy(&result.description); + + return true; } void ffParseTPMJsonObject(FFTPMOptions* options, yyjson_val* module) @@ -56,7 +58,7 @@ void ffGenerateTPMJsonConfig(FFTPMOptions* options, yyjson_mut_doc* doc, yyjson_ ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateTPMJsonResult(FF_MAYBE_UNUSED FFTPMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateTPMJsonResult(FF_MAYBE_UNUSED FFTPMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFTPMResult result = { .version = ffStrbufCreate(), @@ -67,7 +69,7 @@ void ffGenerateTPMJsonResult(FF_MAYBE_UNUSED FFTPMOptions* options, yyjson_mut_d 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"); @@ -76,6 +78,8 @@ void ffGenerateTPMJsonResult(FF_MAYBE_UNUSED FFTPMOptions* options, yyjson_mut_d ffStrbufDestroy(&result.version); ffStrbufDestroy(&result.description); + + return true; } void ffInitTPMOptions(FFTPMOptions* options) diff --git a/src/modules/tpm/tpm.h b/src/modules/tpm/tpm.h index c5ef666df..215f8c98a 100644 --- a/src/modules/tpm/tpm.h +++ b/src/modules/tpm/tpm.h @@ -4,7 +4,7 @@ #define FF_TPM_MODULE_NAME "TPM" -void ffPrintTPM(FFTPMOptions* options); +bool ffPrintTPM(FFTPMOptions* options); void ffInitTPMOptions(FFTPMOptions* options); void ffDestroyTPMOptions(FFTPMOptions* options); diff --git a/src/modules/uptime/uptime.c b/src/modules/uptime/uptime.c index ca64ec572..e1cbd9a8c 100644 --- a/src/modules/uptime/uptime.c +++ b/src/modules/uptime/uptime.c @@ -6,7 +6,7 @@ #include "modules/uptime/uptime.h" #include "util/stringUtils.h" -void ffPrintUptime(FFUptimeOptions* options) +bool ffPrintUptime(FFUptimeOptions* options) { FFUptimeResult result = {}; @@ -15,7 +15,7 @@ void ffPrintUptime(FFUptimeOptions* options) if(error) { ffPrintError(FF_UPTIME_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + return false; } uint64_t uptime = result.uptime; @@ -54,6 +54,8 @@ void ffPrintUptime(FFUptimeOptions* options) FF_FORMAT_ARG(buffer, "formatted") })); } + + return true; } void ffParseUptimeJsonObject(FFUptimeOptions* options, yyjson_val* module) @@ -74,7 +76,7 @@ void ffGenerateUptimeJsonConfig(FFUptimeOptions* options, yyjson_mut_doc* doc, y ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateUptimeJsonResult(FF_MAYBE_UNUSED FFUptimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateUptimeJsonResult(FF_MAYBE_UNUSED FFUptimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFUptimeResult result; const char* error = ffDetectUptime(&result); @@ -82,12 +84,14 @@ void ffGenerateUptimeJsonResult(FF_MAYBE_UNUSED FFUptimeOptions* 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, "uptime", result.uptime); yyjson_mut_obj_add_strcpy(doc, obj, "bootTime", ffTimeToFullStr(result.bootTime)); + + return true; } void ffInitUptimeOptions(FFUptimeOptions* options) diff --git a/src/modules/uptime/uptime.h b/src/modules/uptime/uptime.h index a12fcd549..dec5f95e5 100644 --- a/src/modules/uptime/uptime.h +++ b/src/modules/uptime/uptime.h @@ -4,7 +4,7 @@ #define FF_UPTIME_MODULE_NAME "Uptime" -void ffPrintUptime(FFUptimeOptions* options); +bool ffPrintUptime(FFUptimeOptions* options); void ffInitUptimeOptions(FFUptimeOptions* options); void ffDestroyUptimeOptions(FFUptimeOptions* options); diff --git a/src/modules/users/users.c b/src/modules/users/users.c index fce2dc7ef..751816179 100644 --- a/src/modules/users/users.c +++ b/src/modules/users/users.c @@ -7,7 +7,7 @@ #pragma GCC diagnostic ignored "-Wformat" // warning: unknown conversion type character 'F' in format -void ffPrintUsers(FFUsersOptions* options) +bool ffPrintUsers(FFUsersOptions* options) { FF_LIST_AUTO_DESTROY users = ffListCreate(sizeof(FFUserResult)); @@ -16,13 +16,13 @@ void ffPrintUsers(FFUsersOptions* options) if(error) { ffPrintError(FF_USERS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + return false; } if(users.length == 0) { ffPrintError(FF_USERS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", "Unable to detect any users"); - return; + return false; } if(options->moduleArgs.outputFormat.length == 0) @@ -105,6 +105,8 @@ void ffPrintUsers(FFUsersOptions* options) ffStrbufDestroy(&user->sessionName); ffStrbufDestroy(&user->name); } + + return true; } void ffParseUsersJsonObject(FFUsersOptions* options, yyjson_val* module) @@ -144,7 +146,7 @@ void ffGenerateUsersJsonConfig(FFUsersOptions* options, yyjson_mut_doc* doc, yyj yyjson_mut_obj_add_bool(doc, module, "myselfOnly", options->myselfOnly); } -void ffGenerateUsersJsonResult(FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateUsersJsonResult(FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFUserResult)); @@ -153,7 +155,7 @@ void ffGenerateUsersJsonResult(FFUsersOptions* 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"); @@ -178,6 +180,8 @@ void ffGenerateUsersJsonResult(FFUsersOptions* options, yyjson_mut_doc* doc, yyj ffStrbufDestroy(&user->sessionName); ffStrbufDestroy(&user->name); } + + return true; } void ffInitUsersOptions(FFUsersOptions* options) diff --git a/src/modules/users/users.h b/src/modules/users/users.h index bc249bda1..44c8b01d7 100644 --- a/src/modules/users/users.h +++ b/src/modules/users/users.h @@ -4,7 +4,7 @@ #define FF_USERS_MODULE_NAME "Users" -void ffPrintUsers(FFUsersOptions* options); +bool ffPrintUsers(FFUsersOptions* options); void ffInitUsersOptions(FFUsersOptions* options); void ffDestroyUsersOptions(FFUsersOptions* options); diff --git a/src/modules/version/version.c b/src/modules/version/version.c index 15f519c12..4350e7170 100644 --- a/src/modules/version/version.c +++ b/src/modules/version/version.c @@ -5,7 +5,7 @@ #include "modules/version/version.h" #include "util/stringUtils.h" -void ffPrintVersion(FFVersionOptions* options) +bool ffPrintVersion(FFVersionOptions* options) { FFVersionResult* result = &ffVersionResult; @@ -42,6 +42,8 @@ void ffPrintVersion(FFVersionOptions* options) FF_FORMAT_ARG(buf, "libc"), })); } + + return true; } void ffParseVersionJsonObject(FFVersionOptions* options, yyjson_val* module) @@ -62,7 +64,7 @@ void ffGenerateVersionJsonConfig(FFVersionOptions* options, yyjson_mut_doc* doc, ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateVersionJsonResult(FF_MAYBE_UNUSED FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateVersionJsonResult(FF_MAYBE_UNUSED FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFVersionResult* result = &ffVersionResult; @@ -92,6 +94,8 @@ void ffGenerateVersionJsonResult(FF_MAYBE_UNUSED FFVersionOptions* options, yyjs } yyjson_mut_obj_add_strbuf(doc, obj, "libc", &buf); } + + return true; } void ffInitVersionOptions(FFVersionOptions* options) diff --git a/src/modules/version/version.h b/src/modules/version/version.h index 1135e5394..add5e1198 100644 --- a/src/modules/version/version.h +++ b/src/modules/version/version.h @@ -4,7 +4,7 @@ #define FF_VERSION_MODULE_NAME "Version" -void ffPrintVersion(FFVersionOptions* options); +bool ffPrintVersion(FFVersionOptions* options); void ffInitVersionOptions(FFVersionOptions* options); void ffDestroyVersionOptions(FFVersionOptions* options); diff --git a/src/modules/vulkan/vulkan.c b/src/modules/vulkan/vulkan.c index 429df582c..d77400725 100644 --- a/src/modules/vulkan/vulkan.c +++ b/src/modules/vulkan/vulkan.c @@ -5,14 +5,14 @@ #include "modules/vulkan/vulkan.h" #include "util/stringUtils.h" -void ffPrintVulkan(FFVulkanOptions* options) +bool ffPrintVulkan(FFVulkanOptions* options) { const FFVulkanResult* vulkan = ffDetectVulkan(); if(vulkan->error) { ffPrintError(FF_VULKAN_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", vulkan->error); - return; + return false; } if(options->moduleArgs.outputFormat.length == 0) @@ -23,21 +23,22 @@ void ffPrintVulkan(FFVulkanOptions* options) { ffStrbufWriteTo(&vulkan->instanceVersion, stdout); puts(" [Software only]"); - return; } - - if(vulkan->apiVersion.length > 0) + else { - ffStrbufWriteTo(&vulkan->apiVersion, stdout); + if(vulkan->apiVersion.length > 0) + { + ffStrbufWriteTo(&vulkan->apiVersion, stdout); + + if(vulkan->driver.length > 0) + fputs(" - ", stdout); + } if(vulkan->driver.length > 0) - fputs(" - ", stdout); + ffStrbufWriteTo(&vulkan->driver, stdout); + + putchar('\n'); } - - if(vulkan->driver.length > 0) - ffStrbufWriteTo(&vulkan->driver, stdout); - - putchar('\n'); } else { @@ -48,6 +49,8 @@ void ffPrintVulkan(FFVulkanOptions* options) FF_FORMAT_ARG(vulkan->instanceVersion, "instance-version"), })); } + + return true; } void ffParseVulkanJsonObject(FFVulkanOptions* options, yyjson_val* module) @@ -68,14 +71,14 @@ void ffGenerateVulkanJsonConfig(FFVulkanOptions* options, yyjson_mut_doc* doc, y ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateVulkanJsonResult(FF_MAYBE_UNUSED FFVulkanOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateVulkanJsonResult(FF_MAYBE_UNUSED FFVulkanOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFVulkanResult* result = ffDetectVulkan(); if(result->error) { 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"); @@ -123,6 +126,8 @@ void ffGenerateVulkanJsonResult(FF_MAYBE_UNUSED FFVulkanOptions* options, yyjson yyjson_mut_obj_add_uint(doc, gpuObj, "deviceId", vulkanGpu->deviceId); } + + return true; } void ffInitVulkanOptions(FFVulkanOptions* options) diff --git a/src/modules/vulkan/vulkan.h b/src/modules/vulkan/vulkan.h index 7a5d0f29d..c838028c5 100644 --- a/src/modules/vulkan/vulkan.h +++ b/src/modules/vulkan/vulkan.h @@ -4,7 +4,7 @@ #define FF_VULKAN_MODULE_NAME "Vulkan" -void ffPrintVulkan(FFVulkanOptions* options); +bool ffPrintVulkan(FFVulkanOptions* options); void ffInitVulkanOptions(FFVulkanOptions* options); void ffDestroyVulkanOptions(FFVulkanOptions* options); diff --git a/src/modules/wallpaper/wallpaper.c b/src/modules/wallpaper/wallpaper.c index 6c6466b38..61098f278 100644 --- a/src/modules/wallpaper/wallpaper.c +++ b/src/modules/wallpaper/wallpaper.c @@ -4,7 +4,7 @@ #include "modules/wallpaper/wallpaper.h" #include "util/stringUtils.h" -void ffPrintWallpaper(FFWallpaperOptions* options) +bool ffPrintWallpaper(FFWallpaperOptions* options) { FF_STRBUF_AUTO_DESTROY fullpath = ffStrbufCreate(); const char* error = ffDetectWallpaper(&fullpath); @@ -23,7 +23,7 @@ void ffPrintWallpaper(FFWallpaperOptions* options) if(error) { ffPrintError(FF_WALLPAPER_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + return false; } if(options->moduleArgs.outputFormat.length == 0) @@ -38,6 +38,8 @@ void ffPrintWallpaper(FFWallpaperOptions* options) FF_FORMAT_ARG(fullpath, "full-path"), })); } + + return true; } void ffParseWallpaperJsonObject(FFWallpaperOptions* options, yyjson_val* module) @@ -58,16 +60,18 @@ void ffGenerateWallpaperJsonConfig(FFWallpaperOptions* options, yyjson_mut_doc* ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateWallpaperJsonResult(FF_MAYBE_UNUSED FFWallpaperOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateWallpaperJsonResult(FF_MAYBE_UNUSED FFWallpaperOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY fullpath = ffStrbufCreate(); const char* error = ffDetectWallpaper(&fullpath); if(error) { yyjson_mut_obj_add_str(doc, module, "error", error); - return; + return false; } yyjson_mut_obj_add_strbuf(doc, module, "result", &fullpath); + + return true; } void ffInitWallpaperOptions(FFWallpaperOptions* options) diff --git a/src/modules/wallpaper/wallpaper.h b/src/modules/wallpaper/wallpaper.h index 3ca28bfcd..c3e72911b 100644 --- a/src/modules/wallpaper/wallpaper.h +++ b/src/modules/wallpaper/wallpaper.h @@ -4,7 +4,7 @@ #define FF_WALLPAPER_MODULE_NAME "Wallpaper" -void ffPrintWallpaper(FFWallpaperOptions* options); +bool ffPrintWallpaper(FFWallpaperOptions* options); void ffInitWallpaperOptions(FFWallpaperOptions* options); void ffDestroyWallpaperOptions(FFWallpaperOptions* options); diff --git a/src/modules/weather/weather.c b/src/modules/weather/weather.c index fec43ff5d..3fc3d3a48 100644 --- a/src/modules/weather/weather.c +++ b/src/modules/weather/weather.c @@ -4,7 +4,7 @@ #include "modules/weather/weather.h" #include "util/stringUtils.h" -void ffPrintWeather(FFWeatherOptions* options) +bool ffPrintWeather(FFWeatherOptions* options) { FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate(); const char* error = ffDetectWeather(options, &result); @@ -12,10 +12,9 @@ void ffPrintWeather(FFWeatherOptions* options) if(error) { ffPrintError(FF_WEATHER_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + return false; } - if(options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(FF_WEATHER_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); @@ -27,6 +26,8 @@ void ffPrintWeather(FFWeatherOptions* options) FF_FORMAT_ARG(result, "result"), })); } + + return true; } void ffParseWeatherJsonObject(FFWeatherOptions* options, yyjson_val* module) @@ -71,7 +72,7 @@ void ffGenerateWeatherJsonConfig(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_obj_add_uint(doc, module, "timeout", options->timeout); } -void ffGenerateWeatherJsonResult(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateWeatherJsonResult(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate(); const char* error = ffDetectWeather(options, &result); @@ -79,10 +80,12 @@ void ffGenerateWeatherJsonResult(FFWeatherOptions* options, yyjson_mut_doc* doc, if (error) { yyjson_mut_obj_add_str(doc, module, "error", error); - return; + return false; } yyjson_mut_obj_add_strbuf(doc, module, "result", &result); + + return true; } void ffInitWeatherOptions(FFWeatherOptions* options) diff --git a/src/modules/weather/weather.h b/src/modules/weather/weather.h index 5b3c9739b..f28a4c233 100644 --- a/src/modules/weather/weather.h +++ b/src/modules/weather/weather.h @@ -6,7 +6,7 @@ void ffPrepareWeather(FFWeatherOptions* options); -void ffPrintWeather(FFWeatherOptions* options); +bool ffPrintWeather(FFWeatherOptions* options); void ffInitWeatherOptions(FFWeatherOptions* options); void ffDestroyWeatherOptions(FFWeatherOptions* options); diff --git a/src/modules/wifi/wifi.c b/src/modules/wifi/wifi.c index 69df42cf5..136211418 100644 --- a/src/modules/wifi/wifi.c +++ b/src/modules/wifi/wifi.c @@ -4,7 +4,7 @@ #include "modules/wifi/wifi.h" #include "util/stringUtils.h" -void ffPrintWifi(FFWifiOptions* options) +bool ffPrintWifi(FFWifiOptions* options) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFWifiResult)); @@ -12,12 +12,12 @@ void ffPrintWifi(FFWifiOptions* options) if(error) { ffPrintError(FF_WIFI_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + return false; } if(!result.length) { ffPrintError(FF_WIFI_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No Wifi interfaces found"); - return; + return false; } FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type; @@ -125,7 +125,10 @@ void ffPrintWifi(FFWifiOptions* options) FF_FORMAT_ARG(bandStr, "band"), })); } + } + FF_LIST_FOR_EACH(FFWifiResult, item, result) + { ffStrbufDestroy(&item->inf.description); ffStrbufDestroy(&item->inf.status); ffStrbufDestroy(&item->conn.status); @@ -134,6 +137,8 @@ void ffPrintWifi(FFWifiOptions* options) ffStrbufDestroy(&item->conn.protocol); ffStrbufDestroy(&item->conn.security); } + + return true; } void ffParseWifiJsonObject(FFWifiOptions* options, yyjson_val* module) @@ -159,14 +164,14 @@ void ffGenerateWifiJsonConfig(FFWifiOptions* options, yyjson_mut_doc* doc, yyjso ffPercentGenerateJsonConfig(doc, module, options->percent); } -void ffGenerateWifiJsonResult(FF_MAYBE_UNUSED FFWifiOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateWifiJsonResult(FF_MAYBE_UNUSED FFWifiOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFWifiResult)); const char* error = ffDetectWifi(&result); 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"); @@ -210,6 +215,8 @@ void ffGenerateWifiJsonResult(FF_MAYBE_UNUSED FFWifiOptions* options, yyjson_mut ffStrbufDestroy(&item->conn.protocol); ffStrbufDestroy(&item->conn.security); } + + return true; } void ffInitWifiOptions(FFWifiOptions* options) diff --git a/src/modules/wifi/wifi.h b/src/modules/wifi/wifi.h index 0fcef5f1c..506e1e22a 100644 --- a/src/modules/wifi/wifi.h +++ b/src/modules/wifi/wifi.h @@ -4,7 +4,7 @@ #define FF_WIFI_MODULE_NAME "Wifi" -void ffPrintWifi(FFWifiOptions* options); +bool ffPrintWifi(FFWifiOptions* options); void ffInitWifiOptions(FFWifiOptions* options); void ffDestroyWifiOptions(FFWifiOptions* options); diff --git a/src/modules/wm/wm.c b/src/modules/wm/wm.c index 6753ce2da..23c724fb6 100644 --- a/src/modules/wm/wm.c +++ b/src/modules/wm/wm.c @@ -5,14 +5,14 @@ #include "modules/wm/wm.h" #include "util/stringUtils.h" -void ffPrintWM(FFWMOptions* options) +bool ffPrintWM(FFWMOptions* options) { const FFDisplayServerResult* result = ffConnectDisplayServer(); if(result->wmPrettyName.length == 0) { ffPrintError(FF_WM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No WM found"); - return; + return false; } FF_STRBUF_AUTO_DESTROY pluginName = ffStrbufCreate(); @@ -61,6 +61,8 @@ void ffPrintWM(FFWMOptions* options) FF_FORMAT_ARG(version, "version"), })); } + + return true; } void ffParseWMJsonObject(FFWMOptions* options, yyjson_val* module) @@ -89,14 +91,14 @@ void ffGenerateWMJsonConfig(FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mu yyjson_mut_obj_add_bool(doc, module, "detectPlugin", options->detectPlugin); } -void ffGenerateWMJsonResult(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateWMJsonResult(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFDisplayServerResult* result = ffConnectDisplayServer(); if(result->wmPrettyName.length == 0) { yyjson_mut_obj_add_str(doc, module, "error", "No WM found"); - return; + return false; } FF_STRBUF_AUTO_DESTROY pluginName = ffStrbufCreate(); @@ -113,6 +115,8 @@ void ffGenerateWMJsonResult(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc yyjson_mut_obj_add_strbuf(doc, obj, "protocolName", &result->wmProtocolName); yyjson_mut_obj_add_strbuf(doc, obj, "pluginName", &pluginName); yyjson_mut_obj_add_strbuf(doc, obj, "version", &version); + + return true; } void ffInitWMOptions(FFWMOptions* options) diff --git a/src/modules/wm/wm.h b/src/modules/wm/wm.h index 5b6556806..4819d7394 100644 --- a/src/modules/wm/wm.h +++ b/src/modules/wm/wm.h @@ -4,7 +4,7 @@ #define FF_WM_MODULE_NAME "WM" -void ffPrintWM(FFWMOptions* options); +bool ffPrintWM(FFWMOptions* options); void ffInitWMOptions(FFWMOptions* options); void ffDestroyWMOptions(FFWMOptions* options); diff --git a/src/modules/wmtheme/wmtheme.c b/src/modules/wmtheme/wmtheme.c index d40ab821e..eee270df2 100644 --- a/src/modules/wmtheme/wmtheme.c +++ b/src/modules/wmtheme/wmtheme.c @@ -6,27 +6,28 @@ #define FF_WMTHEME_DISPLAY_NAME "WM Theme" -void ffPrintWMTheme(FFWMThemeOptions* options) +bool ffPrintWMTheme(FFWMThemeOptions* options) { FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate(); - if(ffDetectWmTheme(&themeOrError)) + if(!ffDetectWmTheme(&themeOrError)) { - if(options->moduleArgs.outputFormat.length == 0) - { - ffPrintLogoAndKey(FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); - puts(themeOrError.chars); - } - else - { - FF_PRINT_FORMAT_CHECKED(FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){ - FF_FORMAT_ARG(themeOrError, "result"), - })); - } + ffPrintError(FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", themeOrError.chars); + return false; + } + + if(options->moduleArgs.outputFormat.length == 0) + { + ffPrintLogoAndKey(FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + puts(themeOrError.chars); } else { - ffPrintError(FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%*s", themeOrError.length, themeOrError.chars); + FF_PRINT_FORMAT_CHECKED(FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){ + FF_FORMAT_ARG(themeOrError, "result"), + })); } + + return true; } void ffParseWMThemeJsonObject(FFWMThemeOptions* options, yyjson_val* module) @@ -47,16 +48,17 @@ void ffGenerateWMThemeJsonConfig(FFWMThemeOptions* options, yyjson_mut_doc* doc, ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs); } -void ffGenerateWMThemeJsonResult(FF_MAYBE_UNUSED FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateWMThemeJsonResult(FF_MAYBE_UNUSED FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate(); if(!ffDetectWmTheme(&themeOrError)) { yyjson_mut_obj_add_strbuf(doc, module, "error", &themeOrError); - return; + return false; } yyjson_mut_obj_add_strbuf(doc, module, "result", &themeOrError); + return true; } void ffInitWMThemeOptions(FFWMThemeOptions* options) diff --git a/src/modules/wmtheme/wmtheme.h b/src/modules/wmtheme/wmtheme.h index e3bad8ee0..5142ca42c 100644 --- a/src/modules/wmtheme/wmtheme.h +++ b/src/modules/wmtheme/wmtheme.h @@ -4,7 +4,7 @@ #define FF_WMTHEME_MODULE_NAME "WMTheme" -void ffPrintWMTheme(FFWMThemeOptions* options); +bool ffPrintWMTheme(FFWMThemeOptions* options); void ffInitWMThemeOptions(FFWMThemeOptions* options); void ffDestroyWMThemeOptions(FFWMThemeOptions* options); diff --git a/src/modules/zpool/zpool.c b/src/modules/zpool/zpool.c index 9efddacdb..4193a25b9 100644 --- a/src/modules/zpool/zpool.c +++ b/src/modules/zpool/zpool.c @@ -76,7 +76,7 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i } } -void ffPrintZpool(FFZpoolOptions* options) +bool ffPrintZpool(FFZpoolOptions* options) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFZpoolResult)); @@ -85,12 +85,12 @@ void ffPrintZpool(FFZpoolOptions* options) if (error) { ffPrintError(FF_ZPOOL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); - return; + return false; } if(results.length == 0) { ffPrintError(FF_ZPOOL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", "No zpool found"); - return; + return false; } for(uint32_t i = 0; i < results.length; i++) @@ -105,6 +105,7 @@ void ffPrintZpool(FFZpoolOptions* options) ffStrbufDestroy(&result->name); ffStrbufDestroy(&result->state); } + return true; } void ffParseZpoolJsonObject(FFZpoolOptions* options, yyjson_val* module) @@ -130,7 +131,7 @@ void ffGenerateZpoolJsonConfig(FFZpoolOptions* options, yyjson_mut_doc* doc, yyj ffPercentGenerateJsonConfig(doc, module, options->percent); } -void ffGenerateZpoolJsonResult(FF_MAYBE_UNUSED FFZpoolOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +bool ffGenerateZpoolJsonResult(FF_MAYBE_UNUSED FFZpoolOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFZpoolResult)); @@ -138,7 +139,7 @@ void ffGenerateZpoolJsonResult(FF_MAYBE_UNUSED FFZpoolOptions* 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"); @@ -162,6 +163,7 @@ void ffGenerateZpoolJsonResult(FF_MAYBE_UNUSED FFZpoolOptions* options, yyjson_m ffStrbufDestroy(&zpool->name); ffStrbufDestroy(&zpool->state); } + return true; } void ffInitZpoolOptions(FFZpoolOptions* options) diff --git a/src/modules/zpool/zpool.h b/src/modules/zpool/zpool.h index 7f282f253..35706bb35 100644 --- a/src/modules/zpool/zpool.h +++ b/src/modules/zpool/zpool.h @@ -4,7 +4,7 @@ #define FF_ZPOOL_MODULE_NAME "Zpool" -void ffPrintZpool(FFZpoolOptions* options); +bool ffPrintZpool(FFZpoolOptions* options); void ffInitZpoolOptions(FFZpoolOptions* options); void ffDestroyZpoolOptions(FFZpoolOptions* options);