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
+74 -57
View File
@@ -7,93 +7,105 @@
#include <stdlib.h>
static bool extractNvimVersionFromBinary(const char* str, FF_MAYBE_UNUSED uint32_t len, void* userdata)
{
if (!ffStrStartsWith(str, "NVIM v")) return true;
static bool extractNvimVersionFromBinary(const char* str, FF_MAYBE_UNUSED uint32_t len, void* userdata) {
if (!ffStrStartsWith(str, "NVIM v")) {
return true;
}
ffStrbufSetS((FFstrbuf*) userdata, str + strlen("NVIM v"));
return false;
}
static bool extractVimVersionFromBinary(const char* str, FF_MAYBE_UNUSED uint32_t len, void* userdata)
{
if (!ffStrStartsWith(str, "VIM - Vi IMproved ")) return true;
static bool extractVimVersionFromBinary(const char* str, FF_MAYBE_UNUSED uint32_t len, void* userdata) {
if (!ffStrStartsWith(str, "VIM - Vi IMproved ")) {
return true;
}
ffStrbufSetS((FFstrbuf*) userdata, str + strlen("VIM - Vi IMproved "));
ffStrbufSubstrBeforeFirstC(userdata, ' ');
return false;
}
static bool extractNanoVersionFromBinary(const char* str, FF_MAYBE_UNUSED uint32_t len, void* userdata)
{
if (!ffStrStartsWith(str, "GNU nano ")) return true;
static bool extractNanoVersionFromBinary(const char* str, FF_MAYBE_UNUSED uint32_t len, void* userdata) {
if (!ffStrStartsWith(str, "GNU nano ")) {
return true;
}
ffStrbufSetS((FFstrbuf*) userdata, str + strlen("GNU nano "));
return false;
}
const char* ffDetectEditor(FFEditorResult* result)
{
const char* ffDetectEditor(FFEditorResult* result) {
ffStrbufSetS(&result->name, getenv("VISUAL"));
if (result->name.length)
if (result->name.length) {
result->type = "Visual";
else
{
} else {
ffStrbufSetS(&result->name, getenv("EDITOR"));
if (result->name.length)
if (result->name.length) {
result->type = "Editor";
else
} else {
return "$VISUAL or $EDITOR not set";
}
}
if (ffIsAbsolutePath(result->name.chars))
if (ffIsAbsolutePath(result->name.chars)) {
ffStrbufSet(&result->path, &result->name);
else
{
} else {
const char* error = ffFindExecutableInPath(result->name.chars, &result->path);
if (error) return NULL;
if (error) {
return NULL;
}
}
{
char buf[PATH_MAX + 1];
if (!realpath(result->path.chars, buf))
if (!realpath(result->path.chars, buf)) {
return NULL;
}
// WIN32: Should we handle scoop shim exe here?
#ifdef __linux__
#ifdef __linux__
if (!ffStrEndsWith(buf, "/snap"))
#endif
#endif
ffStrbufSetS(&result->path, buf);
}
{
uint32_t index = ffStrbufLastIndexC(&result->path,
#ifndef _WIN32
#ifndef _WIN32
'/'
#else
#else
'\\'
#endif
#endif
);
if (index == result->path.length)
if (index == result->path.length) {
return NULL;
}
ffStrbufSetS(&result->exe, &result->path.chars[index + 1]);
if (!result->exe.length)
if (!result->exe.length) {
return NULL;
}
#ifdef _WIN32
if (ffStrbufEndsWithS(&result->exe, ".exe"))
#ifdef _WIN32
if (ffStrbufEndsWithS(&result->exe, ".exe")) {
ffStrbufSubstrBefore(&result->exe, result->exe.length - 4);
#endif
}
#endif
}
if (!instance.config.general.detectVersion) return NULL;
if (!instance.config.general.detectVersion) {
return NULL;
}
if (ffStrbufEqualS(&result->exe, "nvim"))
if (ffStrbufEqualS(&result->exe, "nvim")) {
ffBinaryExtractStrings(result->path.chars, extractNvimVersionFromBinary, &result->version, (uint32_t) strlen("NVIM v0.0.0"));
else if (ffStrbufEqualS(&result->exe, "vim") || ffStrbufStartsWithS(&result->exe, "vim."))
} else if (ffStrbufEqualS(&result->exe, "vim") || ffStrbufStartsWithS(&result->exe, "vim.")) {
ffBinaryExtractStrings(result->path.chars, extractVimVersionFromBinary, &result->version, (uint32_t) strlen("VIM - Vi IMproved 0.0"));
else if (ffStrbufEqualS(&result->exe, "nano"))
} else if (ffStrbufEqualS(&result->exe, "nano")) {
ffBinaryExtractStrings(result->path.chars, extractNanoVersionFromBinary, &result->version, (uint32_t) strlen("GNU nano 0.0"));
}
if (result->version.length > 0) return NULL;
if (result->version.length > 0) {
return NULL;
}
const char* param = NULL;
if (
@@ -108,35 +120,40 @@ const char* ffDetectEditor(FFEditorResult* result)
ffStrbufEqualS(&result->exe, "code") ||
ffStrbufEqualS(&result->exe, "pluma") ||
ffStrbufEqualS(&result->exe, "sublime_text") ||
ffStrbufEqualS(&result->exe, "zeditor")
) param = "--version";
else if (
ffStrbufEqualS(&result->exe, "zeditor")) {
param = "--version";
} else if (
ffStrbufEqualS(&result->exe, "kak") ||
ffStrbufEqualS(&result->exe, "pico")
) param = "-version";
else if (
ffStrbufEqualS(&result->exe, "ne")
) param = "-h";
else return NULL;
ffProcessAppendStdOut(&result->version, (char* const[]){
result->path.chars,
(char*) param,
NULL,
});
if (result->version.length == 0)
ffStrbufEqualS(&result->exe, "pico")) {
param = "-version";
} else if (
ffStrbufEqualS(&result->exe, "ne")) {
param = "-h";
} else {
return NULL;
}
ffProcessAppendStdOut(&result->version, (char* const[]) {
result->path.chars,
(char*) param,
NULL,
});
if (result->version.length == 0) {
return NULL;
}
ffStrbufSubstrBeforeFirstC(&result->version, '\n');
const char* versionStart = strpbrk(result->version.chars, "0123456789");
if (versionStart != NULL) {
const char* versionEnd = strpbrk(versionStart, " \t\v\f\r");
if (versionEnd != NULL)
ffStrbufSubstrBefore(&result->version, (uint32_t)(versionEnd - result->version.chars));
if (versionEnd != NULL) {
ffStrbufSubstrBefore(&result->version, (uint32_t) (versionEnd - result->version.chars));
}
if (versionStart != result->version.chars)
ffStrbufSubstrAfter(&result->version, (uint32_t)(versionStart - result->version.chars - 1));
if (versionStart != result->version.chars) {
ffStrbufSubstrAfter(&result->version, (uint32_t) (versionStart - result->version.chars - 1));
}
}
return NULL;
+1 -2
View File
@@ -3,8 +3,7 @@
#include "fastfetch.h"
#include "modules/editor/option.h"
typedef struct FFEditorResult
{
typedef struct FFEditorResult {
const char* type;
FFstrbuf name;
FFstrbuf exe;