Chore: run clang-format

```bash
find . -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) ! -path "src/3rdparty/*" -print0 | xargs -0 clang-format -i
```
This commit is contained in:
李通洲
2026-03-29 09:28:49 +08:00
parent cdd4cee968
commit e0eba8ce21
690 changed files with 28093 additions and 30062 deletions
+48 -63
View File
@@ -5,91 +5,85 @@
#include "detection/bluetooth/bluetooth.h"
#include "modules/bluetooth/bluetooth.h"
static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* device, uint8_t index)
{
static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* device, uint8_t index) {
FFPercentageTypeFlags percentType = options->percent.type == 0 ? instance.config.display.percentType : options->percent.type;
if(options->moduleArgs.outputFormat.length == 0)
{
if (options->moduleArgs.outputFormat.length == 0) {
ffPrintLogoAndKey(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
bool showBatteryLevel = device->battery > 0 && device->battery <= 100;
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_BAR_BIT))
{
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_BAR_BIT)) {
ffPercentAppendBar(&buffer, device->battery, options->percent, &options->moduleArgs);
ffStrbufAppendC(&buffer, ' ');
}
if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT))
if (!(percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) {
ffStrbufAppend(&buffer, &device->name);
}
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_NUM_BIT))
{
if (buffer.length)
if (showBatteryLevel && (percentType & FF_PERCENTAGE_TYPE_NUM_BIT)) {
if (buffer.length) {
ffStrbufAppendC(&buffer, ' ');
}
ffPercentAppendNum(&buffer, device->battery, options->percent, buffer.length > 0, &options->moduleArgs);
}
if (!device->connected)
if (!device->connected) {
ffStrbufAppendS(&buffer, " [disconnected]");
}
ffStrbufPutTo(&buffer, stdout);
}
else
{
} else {
FF_STRBUF_AUTO_DESTROY percentageNum = ffStrbufCreate();
if(percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT) {
ffPercentAppendNum(&percentageNum, device->battery, options->percent, false, &options->moduleArgs);
}
FF_STRBUF_AUTO_DESTROY percentageBar = ffStrbufCreate();
if(percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT) {
ffPercentAppendBar(&percentageBar, device->battery, options->percent, &options->moduleArgs);
}
FF_PRINT_FORMAT_CHECKED(FF_BLUETOOTH_MODULE_NAME, index, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
FF_ARG(device->name, "name"),
FF_ARG(device->address, "address"),
FF_ARG(device->type, "type"),
FF_ARG(percentageNum, "battery-percentage"),
FF_ARG(device->connected, "connected"),
FF_ARG(percentageBar, "battery-percentage-bar"),
}));
FF_ARG(device->name, "name"),
FF_ARG(device->address, "address"),
FF_ARG(device->type, "type"),
FF_ARG(percentageNum, "battery-percentage"),
FF_ARG(device->connected, "connected"),
FF_ARG(percentageBar, "battery-percentage-bar"),
}));
}
}
bool ffPrintBluetooth(FFBluetoothOptions* options)
{
FF_LIST_AUTO_DESTROY devices = ffListCreate(sizeof (FFBluetoothResult));
bool ffPrintBluetooth(FFBluetoothOptions* options) {
FF_LIST_AUTO_DESTROY devices = ffListCreate(sizeof(FFBluetoothResult));
const char* error = ffDetectBluetooth(options, &devices);
if(error)
{
if (error) {
ffPrintError(FF_BLUETOOTH_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
return false;
}
FF_LIST_AUTO_DESTROY filtered = ffListCreate(sizeof(FFBluetoothResult*));
FF_LIST_FOR_EACH(FFBluetoothResult, device, devices)
{
if(!device->connected && !options->showDisconnected)
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)
{
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++)
{
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)
{
FF_LIST_FOR_EACH (FFBluetoothResult, device, devices) {
ffStrbufDestroy(&device->name);
ffStrbufDestroy(&device->type);
ffStrbufDestroy(&device->address);
@@ -97,30 +91,28 @@ bool ffPrintBluetooth(FFBluetoothOptions* options)
return true;
}
void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module)
{
void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module) {
yyjson_val *key, *val;
size_t idx, max;
yyjson_obj_foreach(module, idx, max, key, val)
{
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
yyjson_obj_foreach (module, idx, max, key, val) {
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
continue;
}
if (unsafe_yyjson_equals_str(key, "showDisconnected"))
{
if (unsafe_yyjson_equals_str(key, "showDisconnected")) {
options->showDisconnected = yyjson_get_bool(val);
continue;
}
if (ffPercentParseJsonObject(key, val, &options->percent))
if (ffPercentParseJsonObject(key, val, &options->percent)) {
continue;
}
ffPrintError(FF_BLUETOOTH_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
}
}
void ffGenerateBluetoothJsonConfig(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
void ffGenerateBluetoothJsonConfig(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
yyjson_mut_obj_add_bool(doc, module, "showDisconnected", options->showDisconnected);
@@ -128,21 +120,18 @@ void ffGenerateBluetoothJsonConfig(FFBluetoothOptions* options, yyjson_mut_doc*
ffPercentGenerateJsonConfig(doc, module, options->percent);
}
bool 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));
const char* error = ffDetectBluetooth(options, &results);
if (error)
{
if (error) {
yyjson_mut_obj_add_str(doc, module, "error", error);
return false;
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
FF_LIST_FOR_EACH(FFBluetoothResult, item, results)
{
FF_LIST_FOR_EACH (FFBluetoothResult, item, results) {
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
yyjson_mut_obj_add_strbuf(doc, obj, "address", &item->address);
yyjson_mut_obj_add_uint(doc, obj, "battery", item->battery);
@@ -151,8 +140,7 @@ bool ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc*
yyjson_mut_obj_add_strbuf(doc, obj, "type", &item->type);
}
FF_LIST_FOR_EACH(FFBluetoothResult, device, results)
{
FF_LIST_FOR_EACH (FFBluetoothResult, device, results) {
ffStrbufDestroy(&device->name);
ffStrbufDestroy(&device->type);
ffStrbufDestroy(&device->address);
@@ -160,15 +148,13 @@ bool ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc*
return true;
}
void ffInitBluetoothOptions(FFBluetoothOptions* options)
{
void ffInitBluetoothOptions(FFBluetoothOptions* options) {
ffOptionInitModuleArg(&options->moduleArgs, "");
options->showDisconnected = false;
options->percent = (FFPercentageModuleConfig) { 50, 20, 0 };
options->percent = (FFPercentageModuleConfig) {50, 20, 0};
}
void ffDestroyBluetoothOptions(FFBluetoothOptions* options)
{
void ffDestroyBluetoothOptions(FFBluetoothOptions* options) {
ffOptionDestroyModuleArg(&options->moduleArgs);
}
@@ -188,5 +174,4 @@ FFModuleBaseInfo ffBluetoothModuleInfo = {
{"Battery percentage number", "battery-percentage"},
{"Is connected", "connected"},
{"Battery percentage bar", "battery-percentage-bar"},
}))
};
}))};