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
+73 -92
View File
@@ -6,13 +6,11 @@
#include "detection/cpu/cpu.h"
#include "modules/cpu/cpu.h"
static int sortCores(const FFCPUCore* a, const FFCPUCore* b)
{
return (int)b->freq - (int)a->freq;
static int sortCores(const FFCPUCore* a, const FFCPUCore* b) {
return (int) b->freq - (int) a->freq;
}
bool ffPrintCPU(FFCPUOptions* options)
{
bool ffPrintCPU(FFCPUOptions* options) {
bool success = false;
FFCPUResult cpu = {
.temperature = FF_CPU_TEMP_UNSET,
@@ -24,73 +22,66 @@ bool ffPrintCPU(FFCPUOptions* options)
const char* error = ffDetectCPU(options, &cpu);
if(error)
{
if (error) {
ffPrintError(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
}
else if(cpu.vendor.length == 0 && cpu.name.length == 0 && cpu.coresOnline <= 1)
{
} else if (cpu.vendor.length == 0 && cpu.name.length == 0 && cpu.coresOnline <= 1) {
ffPrintError(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No CPU detected");
}
else
{
} else {
FF_STRBUF_AUTO_DESTROY coreTypes = ffStrbufCreate();
if (options->showPeCoreCount)
{
if (options->showPeCoreCount) {
uint32_t typeCount = 0;
while (cpu.coreTypes[typeCount].count != 0 && typeCount < ARRAY_SIZE(cpu.coreTypes)) typeCount++;
if (typeCount > 0)
{
while (cpu.coreTypes[typeCount].count != 0 && typeCount < ARRAY_SIZE(cpu.coreTypes)) {
typeCount++;
}
if (typeCount > 0) {
qsort(cpu.coreTypes, typeCount, sizeof(cpu.coreTypes[0]), (void*) sortCores);
for (uint32_t i = 0; i < typeCount; i++)
for (uint32_t i = 0; i < typeCount; i++) {
ffStrbufAppendF(&coreTypes, "%s%u", i == 0 ? "" : "+", cpu.coreTypes[i].count);
}
}
}
if(options->moduleArgs.outputFormat.length == 0)
{
if (options->moduleArgs.outputFormat.length == 0) {
ffPrintLogoAndKey(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
if(cpu.packages > 1)
if (cpu.packages > 1) {
ffStrbufAppendF(&str, "%u x ", cpu.packages);
}
if(cpu.name.length > 0)
if (cpu.name.length > 0) {
ffStrbufAppend(&str, &cpu.name);
else if(cpu.vendor.length > 0)
{
} else if (cpu.vendor.length > 0) {
ffStrbufAppend(&str, &cpu.vendor);
ffStrbufAppendS(&str, " CPU");
}
else
} else {
ffStrbufAppendS(&str, "Unknown");
}
if(coreTypes.length > 0)
if (coreTypes.length > 0) {
ffStrbufAppendF(&str, " (%s)", coreTypes.chars);
else if(cpu.coresOnline > 1)
} else if (cpu.coresOnline > 1) {
ffStrbufAppendF(&str, " (%u)", cpu.coresOnline);
}
uint32_t freq = cpu.frequencyMax;
if(freq == 0)
if (freq == 0) {
freq = cpu.frequencyBase;
if(freq > 0)
{
}
if (freq > 0) {
ffStrbufAppendS(&str, " @ ");
ffFreqAppendNum(freq, &str);
}
if(cpu.temperature != FF_CPU_TEMP_UNSET)
{
if (cpu.temperature != FF_CPU_TEMP_UNSET) {
ffStrbufAppendS(&str, " - ");
ffTempsAppendNum(cpu.temperature, &str, options->tempConfig, &options->moduleArgs);
}
ffStrbufPutTo(&str, stdout);
}
else
{
} else {
FF_STRBUF_AUTO_DESTROY freqBase = ffStrbufCreate();
ffFreqAppendNum(cpu.frequencyBase, &freqBase);
FF_STRBUF_AUTO_DESTROY freqMax = ffStrbufCreate();
@@ -98,20 +89,20 @@ bool ffPrintCPU(FFCPUOptions* options)
FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate();
ffTempsAppendNum(cpu.temperature, &tempStr, options->tempConfig, &options->moduleArgs);
FF_PRINT_FORMAT_CHECKED(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){
FF_ARG(cpu.name, "name"),
FF_ARG(cpu.vendor, "vendor"),
FF_ARG(cpu.coresPhysical, "cores-physical"),
FF_ARG(cpu.coresLogical, "cores-logical"),
FF_ARG(cpu.coresOnline, "cores-online"),
FF_ARG(freqBase, "freq-base"),
FF_ARG(freqMax, "freq-max"),
FF_ARG(tempStr, "temperature"),
FF_ARG(coreTypes, "core-types"),
FF_ARG(cpu.packages, "packages"),
FF_ARG(cpu.march, "march"),
FF_ARG(cpu.numaNodes, "numa-nodes"),
}));
FF_PRINT_FORMAT_CHECKED(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
FF_ARG(cpu.name, "name"),
FF_ARG(cpu.vendor, "vendor"),
FF_ARG(cpu.coresPhysical, "cores-physical"),
FF_ARG(cpu.coresLogical, "cores-logical"),
FF_ARG(cpu.coresOnline, "cores-online"),
FF_ARG(freqBase, "freq-base"),
FF_ARG(freqMax, "freq-max"),
FF_ARG(tempStr, "temperature"),
FF_ARG(coreTypes, "core-types"),
FF_ARG(cpu.packages, "packages"),
FF_ARG(cpu.march, "march"),
FF_ARG(cpu.numaNodes, "numa-nodes"),
}));
}
success = true;
}
@@ -122,32 +113,29 @@ bool ffPrintCPU(FFCPUOptions* options)
return success;
}
void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module)
{
void ffParseCPUJsonObject(FFCPUOptions* 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 (ffTempsParseJsonObject(key, val, &options->temp, &options->tempConfig))
if (ffTempsParseJsonObject(key, val, &options->temp, &options->tempConfig)) {
continue;
}
if (unsafe_yyjson_equals_str(key, "tempSensor"))
{
if (unsafe_yyjson_equals_str(key, "tempSensor")) {
ffStrbufSetJsonVal(&options->tempSensor, val);
continue;
}
if (unsafe_yyjson_equals_str(key, "freqNdigits"))
{
if (unsafe_yyjson_equals_str(key, "freqNdigits")) {
ffPrintError(FF_CPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "modules.CPU.freqNdigits has been moved to display.freq.ndigits");
continue;
}
if (unsafe_yyjson_equals_str(key, "showPeCoreCount"))
{
if (unsafe_yyjson_equals_str(key, "showPeCoreCount")) {
options->showPeCoreCount = yyjson_get_bool(val);
continue;
}
@@ -156,8 +144,7 @@ void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module)
}
}
void ffGenerateCPUJsonConfig(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
void ffGenerateCPUJsonConfig(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
ffTempsGenerateJsonConfig(doc, module, options->temp, options->tempConfig);
@@ -165,8 +152,7 @@ void ffGenerateCPUJsonConfig(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
yyjson_mut_obj_add_bool(doc, module, "showPeCoreCount", options->showPeCoreCount);
}
bool 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,
@@ -178,23 +164,19 @@ bool ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
const char* error = ffDetectCPU(options, &cpu);
if(error)
{
if (error) {
yyjson_mut_obj_add_str(doc, module, "error", error);
}
else if(cpu.vendor.length == 0 && cpu.name.length == 0 && cpu.coresOnline <= 1)
{
} else if (cpu.vendor.length == 0 && cpu.name.length == 0 && cpu.coresOnline <= 1) {
yyjson_mut_obj_add_str(doc, module, "error", "No CPU detected");
}
else
{
} else {
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "cpu", &cpu.name);
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &cpu.vendor);
if (cpu.packages == 0)
if (cpu.packages == 0) {
yyjson_mut_obj_add_null(doc, obj, "packages");
else
} else {
yyjson_mut_obj_add_uint(doc, obj, "packages", cpu.packages);
}
yyjson_mut_val* cores = yyjson_mut_obj_add_obj(doc, obj, "cores");
yyjson_mut_obj_add_uint(doc, cores, "physical", cpu.coresPhysical);
@@ -206,27 +188,29 @@ bool ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
yyjson_mut_obj_add_uint(doc, frequency, "max", cpu.frequencyMax);
yyjson_mut_val* coreTypes = yyjson_mut_obj_add_arr(doc, obj, "coreTypes");
for (uint32_t i = 0; i < ARRAY_SIZE(cpu.coreTypes) && cpu.coreTypes[i].count > 0; i++)
{
for (uint32_t i = 0; i < ARRAY_SIZE(cpu.coreTypes) && cpu.coreTypes[i].count > 0; i++) {
yyjson_mut_val* core = yyjson_mut_arr_add_obj(doc, coreTypes);
yyjson_mut_obj_add_uint(doc, core, "count", cpu.coreTypes[i].count);
yyjson_mut_obj_add_uint(doc, core, "freq", cpu.coreTypes[i].freq);
}
if (cpu.temperature != FF_CPU_TEMP_UNSET)
if (cpu.temperature != FF_CPU_TEMP_UNSET) {
yyjson_mut_obj_add_real(doc, obj, "temperature", cpu.temperature);
else
} else {
yyjson_mut_obj_add_null(doc, obj, "temperature");
}
if (cpu.march)
if (cpu.march) {
yyjson_mut_obj_add_str(doc, obj, "march", cpu.march);
else
} else {
yyjson_mut_obj_add_null(doc, obj, "march");
}
if (cpu.numaNodes > 0)
if (cpu.numaNodes > 0) {
yyjson_mut_obj_add_uint(doc, obj, "numaNodes", cpu.numaNodes);
else
} else {
yyjson_mut_obj_add_null(doc, obj, "numaNodes");
}
success = true;
}
@@ -237,17 +221,15 @@ bool ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
return success;
}
void ffInitCPUOptions(FFCPUOptions* options)
{
void ffInitCPUOptions(FFCPUOptions* options) {
ffOptionInitModuleArg(&options->moduleArgs, "");
ffStrbufInit(&options->tempSensor);
options->temp = false;
options->tempConfig = (FFColorRangeConfig) { 60, 80 };
options->tempConfig = (FFColorRangeConfig) {60, 80};
options->showPeCoreCount = false;
}
void ffDestroyCPUOptions(FFCPUOptions* options)
{
void ffDestroyCPUOptions(FFCPUOptions* options) {
ffOptionDestroyModuleArg(&options->moduleArgs);
ffStrbufDestroy(&options->tempSensor);
}
@@ -274,5 +256,4 @@ FFModuleBaseInfo ffCPUModuleInfo = {
{"Processor package count", "packages"},
{"CPU microarchitecture", "march"},
{"NUMA node count", "numa-nodes"},
}))
};
}))};
+1 -2
View File
@@ -2,8 +2,7 @@
#include "common/option.h"
typedef struct FFCPUOptions
{
typedef struct FFCPUOptions {
FFModuleArgs moduleArgs;
FFstrbuf tempSensor;