mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-03 11:44:18 +01:00
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:
+42
-55
@@ -4,83 +4,79 @@
|
||||
#include "detection/dns/dns.h"
|
||||
#include "modules/dns/dns.h"
|
||||
|
||||
bool ffPrintDNS(FFDNSOptions* options)
|
||||
{
|
||||
bool ffPrintDNS(FFDNSOptions* options) {
|
||||
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFstrbuf));
|
||||
|
||||
const char* error = ffDetectDNS(options, &result);
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (error) {
|
||||
ffPrintError(FF_DNS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result.length == 0)
|
||||
{
|
||||
if (result.length == 0) {
|
||||
ffPrintError(FF_DNS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "NO DNS servers detected");
|
||||
return false;
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate();
|
||||
FF_LIST_FOR_EACH(FFstrbuf, item, result)
|
||||
{
|
||||
if (!ffStrbufContainC(item, '.')) continue; // IPv4
|
||||
if (buf.length)
|
||||
FF_LIST_FOR_EACH (FFstrbuf, item, result) {
|
||||
if (!ffStrbufContainC(item, '.')) {
|
||||
continue; // IPv4
|
||||
}
|
||||
if (buf.length) {
|
||||
ffStrbufAppendC(&buf, ' ');
|
||||
}
|
||||
ffStrbufAppend(&buf, item);
|
||||
}
|
||||
FF_LIST_FOR_EACH(FFstrbuf, item, result)
|
||||
{
|
||||
if (!ffStrbufContainC(item, ':')) continue; // IPv6
|
||||
if (buf.length)
|
||||
FF_LIST_FOR_EACH (FFstrbuf, item, result) {
|
||||
if (!ffStrbufContainC(item, ':')) {
|
||||
continue; // IPv6
|
||||
}
|
||||
if (buf.length) {
|
||||
ffStrbufAppendC(&buf, ' ');
|
||||
}
|
||||
ffStrbufAppend(&buf, item);
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
if (options->moduleArgs.outputFormat.length == 0) {
|
||||
ffPrintLogoAndKey(FF_DNS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
||||
|
||||
ffStrbufPutTo(&buf, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
FF_PRINT_FORMAT_CHECKED(FF_DNS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
|
||||
FF_ARG(buf, "result"),
|
||||
}));
|
||||
FF_ARG(buf, "result"),
|
||||
}));
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFstrbuf, item, result)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFstrbuf, item, result) {
|
||||
ffStrbufDestroy(item);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffParseDNSJsonObject(FFDNSOptions* options, yyjson_val* module)
|
||||
{
|
||||
void ffParseDNSJsonObject(FFDNSOptions* 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, "showType"))
|
||||
{
|
||||
if (unsafe_yyjson_equals_str(key, "showType")) {
|
||||
int value;
|
||||
const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) {
|
||||
{ "both", FF_DNS_TYPE_BOTH },
|
||||
{ "ipv4", FF_DNS_TYPE_IPV4_BIT },
|
||||
{ "ipv6", FF_DNS_TYPE_IPV6_BIT },
|
||||
{},
|
||||
});
|
||||
if (error)
|
||||
{"both", FF_DNS_TYPE_BOTH},
|
||||
{"ipv4", FF_DNS_TYPE_IPV4_BIT},
|
||||
{"ipv6", FF_DNS_TYPE_IPV6_BIT},
|
||||
{},
|
||||
});
|
||||
if (error) {
|
||||
ffPrintError(FF_DNS_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Invalid %s value: %s", unsafe_yyjson_get_str(key), error);
|
||||
else
|
||||
} else {
|
||||
options->showType = (FFDNSShowType) value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -88,12 +84,10 @@ void ffParseDNSJsonObject(FFDNSOptions* options, yyjson_val* module)
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateDNSJsonConfig(FFDNSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
void ffGenerateDNSJsonConfig(FFDNSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
||||
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
|
||||
|
||||
switch ((uint8_t) options->showType)
|
||||
{
|
||||
switch ((uint8_t) options->showType) {
|
||||
case FF_DNS_TYPE_IPV4_BIT:
|
||||
yyjson_mut_obj_add_str(doc, module, "showType", "ipv4");
|
||||
break;
|
||||
@@ -106,42 +100,36 @@ void ffGenerateDNSJsonConfig(FFDNSOptions* options, yyjson_mut_doc* doc, yyjson_
|
||||
}
|
||||
}
|
||||
|
||||
bool 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));
|
||||
|
||||
const char* error = ffDetectDNS(options, &result);
|
||||
|
||||
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(FFstrbuf, item, result)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFstrbuf, item, result) {
|
||||
yyjson_mut_arr_add_strbuf(doc, arr, item);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFstrbuf, item, result)
|
||||
{
|
||||
FF_LIST_FOR_EACH (FFstrbuf, item, result) {
|
||||
ffStrbufDestroy(item);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffInitDNSOptions(FFDNSOptions* options)
|
||||
{
|
||||
void ffInitDNSOptions(FFDNSOptions* options) {
|
||||
ffOptionInitModuleArg(&options->moduleArgs, "");
|
||||
|
||||
options->showType = FF_DNS_TYPE_BOTH;
|
||||
}
|
||||
|
||||
void ffDestroyDNSOptions(FFDNSOptions* options)
|
||||
{
|
||||
void ffDestroyDNSOptions(FFDNSOptions* options) {
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
@@ -156,5 +144,4 @@ FFModuleBaseInfo ffDNSModuleInfo = {
|
||||
.generateJsonConfig = (void*) ffGenerateDNSJsonConfig,
|
||||
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
|
||||
{"DNS result", "result"},
|
||||
}))
|
||||
};
|
||||
}))};
|
||||
|
||||
@@ -9,8 +9,7 @@ typedef enum __attribute__((__packed__)) FFDNSShowType {
|
||||
FF_DNS_TYPE_FORCE_UNSIGNED = UINT8_MAX,
|
||||
} FFDNSShowType;
|
||||
|
||||
typedef struct FFDNSOptions
|
||||
{
|
||||
typedef struct FFDNSOptions {
|
||||
FFModuleArgs moduleArgs;
|
||||
|
||||
FFDNSShowType showType;
|
||||
|
||||
Reference in New Issue
Block a user