mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Global: formats code [ci skip]
This commit is contained in:
@@ -64,5 +64,18 @@ ForEachMacros:
|
||||
- yyjson_mut_obj_foreach
|
||||
- yyjson_mut_arr_foreach
|
||||
|
||||
AttributeMacros:
|
||||
- FF_A_FALLTHROUGH
|
||||
- FF_A_DEPRECATED
|
||||
- FF_A_CLEANUP
|
||||
- FF_A_NODISCARD
|
||||
- FF_A_PRINTF
|
||||
- FF_A_SCANF
|
||||
- FF_A_NONNULL
|
||||
- FF_A_RETURNS_NONNULL
|
||||
- FF_A_UNUSED
|
||||
- FF_A_PACKED
|
||||
- FF_A_WEAK_IMPORT
|
||||
|
||||
MaxEmptyLinesToKeep: 1
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
|
||||
@@ -47,8 +47,7 @@ void ffStrbufAppendC(FFstrbuf* strbuf, char c);
|
||||
void ffStrbufAppendNC(FFstrbuf* strbuf, uint32_t num, char c);
|
||||
void ffStrbufAppendNS(FFstrbuf* strbuf, uint32_t length, const char* value);
|
||||
void ffStrbufAppendTransformS(FFstrbuf* strbuf, const char* value, int (*transformFunc)(int));
|
||||
FF_A_PRINTF(2, 3)
|
||||
void ffStrbufAppendF(FFstrbuf* strbuf, const char* format, ...);
|
||||
FF_A_PRINTF(2, 3) void ffStrbufAppendF(FFstrbuf* strbuf, const char* format, ...);
|
||||
void ffStrbufAppendVF(FFstrbuf* strbuf, const char* format, va_list arguments);
|
||||
const char* ffStrbufAppendSUntilC(FFstrbuf* strbuf, const char* value, char until);
|
||||
|
||||
@@ -61,8 +60,7 @@ void ffStrbufInsertNC(FFstrbuf* strbuf, uint32_t index, uint32_t num, char c);
|
||||
// NOTE: Unlike ffStrbufAppend*, ffStrbufSet* functions may NOT reserve extra space
|
||||
void ffStrbufSet(FFstrbuf* strbuf, const FFstrbuf* value);
|
||||
void ffStrbufSetNS(FFstrbuf* strbuf, uint32_t length, const char* value);
|
||||
FF_A_PRINTF(2, 3)
|
||||
void ffStrbufSetF(FFstrbuf* strbuf, const char* format, ...);
|
||||
FF_A_PRINTF(2, 3) void ffStrbufSetF(FFstrbuf* strbuf, const char* format, ...);
|
||||
|
||||
void ffStrbufTrimLeft(FFstrbuf* strbuf, char c);
|
||||
void ffStrbufTrimRight(FFstrbuf* strbuf, char c);
|
||||
@@ -194,16 +192,15 @@ FF_A_NODISCARD static inline FFstrbuf ffStrbufCreateVF(const char* format, va_li
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
FF_A_PRINTF(2, 3)
|
||||
static inline void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...) {
|
||||
FF_A_PRINTF(2, 3) static inline void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...) {
|
||||
va_list arguments;
|
||||
va_start(arguments, format);
|
||||
ffStrbufInitVF(strbuf, format, arguments);
|
||||
va_end(arguments);
|
||||
}
|
||||
|
||||
FF_A_PRINTF(1, 2)
|
||||
FF_A_NODISCARD static inline FFstrbuf ffStrbufCreateF(const char* format, ...) {
|
||||
FF_A_PRINTF(1, 2) FF_A_NODISCARD static inline FFstrbuf
|
||||
ffStrbufCreateF(const char* format, ...) {
|
||||
FFstrbuf strbuf;
|
||||
|
||||
va_list arguments;
|
||||
|
||||
+18
-36
@@ -49,8 +49,7 @@ static inline bool ffIsValidNativeFD(FFNativeFD fd) {
|
||||
#endif
|
||||
}
|
||||
|
||||
FF_A_NONNULL(1)
|
||||
static inline bool wrapClose(FFNativeFD* pfd) {
|
||||
FF_A_NONNULL(1) static inline bool wrapClose(FFNativeFD* pfd) {
|
||||
assert(pfd);
|
||||
|
||||
if (!ffIsValidNativeFD(*pfd)) {
|
||||
@@ -75,8 +74,7 @@ static inline FFNativeFD FFUnixFD2NativeFD(int unixfd) {
|
||||
#endif
|
||||
}
|
||||
|
||||
FF_A_NONNULL(3)
|
||||
static inline bool ffWriteFDData(FFNativeFD fd, size_t dataSize, const void* data) {
|
||||
FF_A_NONNULL(3) static inline bool ffWriteFDData(FFNativeFD fd, size_t dataSize, const void* data) {
|
||||
#ifndef _WIN32
|
||||
return write(fd, data, dataSize) != -1;
|
||||
#else
|
||||
@@ -85,21 +83,17 @@ static inline bool ffWriteFDData(FFNativeFD fd, size_t dataSize, const void* dat
|
||||
#endif
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2)
|
||||
static inline bool ffWriteFDBuffer(FFNativeFD fd, const FFstrbuf* content) {
|
||||
FF_A_NONNULL(2) static inline bool ffWriteFDBuffer(FFNativeFD fd, const FFstrbuf* content) {
|
||||
return ffWriteFDData(fd, content->length, content->chars);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(1, 3)
|
||||
bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data);
|
||||
FF_A_NONNULL(1, 3) bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data);
|
||||
|
||||
FF_A_NONNULL(1, 2)
|
||||
static inline bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer) {
|
||||
FF_A_NONNULL(1, 2) static inline bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer) {
|
||||
return ffWriteFileData(fileName, buffer->length, buffer->chars);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(3)
|
||||
static inline ssize_t ffReadFDData(FFNativeFD fd, size_t dataSize, void* data) {
|
||||
FF_A_NONNULL(3) static inline ssize_t ffReadFDData(FFNativeFD fd, size_t dataSize, void* data) {
|
||||
#ifndef _WIN32
|
||||
return read(fd, data, dataSize);
|
||||
#else
|
||||
@@ -112,11 +106,9 @@ static inline ssize_t ffReadFDData(FFNativeFD fd, size_t dataSize, void* data) {
|
||||
#endif
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2)
|
||||
bool ffAppendFDBuffer(FFNativeFD fd, FFstrbuf* buffer);
|
||||
FF_A_NONNULL(2) bool ffAppendFDBuffer(FFNativeFD fd, FFstrbuf* buffer);
|
||||
|
||||
FF_A_NONNULL(1, 3)
|
||||
static inline ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data) {
|
||||
FF_A_NONNULL(1, 3) static inline ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data) {
|
||||
FFNativeFD FF_AUTO_CLOSE_FD fd =
|
||||
#ifndef _WIN32
|
||||
open(fileName, O_RDONLY | O_CLOEXEC);
|
||||
@@ -131,8 +123,7 @@ static inline ssize_t ffReadFileData(const char* fileName, size_t dataSize, void
|
||||
return ffReadFDData(fd, dataSize, data);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2, 4)
|
||||
static inline ssize_t ffReadFileDataRelative(FFNativeFD dfd, const char* fileName, size_t dataSize, void* data) {
|
||||
FF_A_NONNULL(2, 4) static inline ssize_t ffReadFileDataRelative(FFNativeFD dfd, const char* fileName, size_t dataSize, void* data) {
|
||||
FFNativeFD FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, O_RDONLY | O_CLOEXEC);
|
||||
if (!ffIsValidNativeFD(fd)) {
|
||||
return -1;
|
||||
@@ -141,8 +132,7 @@ static inline ssize_t ffReadFileDataRelative(FFNativeFD dfd, const char* fileNam
|
||||
return ffReadFDData(fd, dataSize, data);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(1, 2)
|
||||
static inline bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) {
|
||||
FF_A_NONNULL(1, 2) static inline bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) {
|
||||
FFNativeFD FF_AUTO_CLOSE_FD fd =
|
||||
#ifndef _WIN32
|
||||
open(fileName, O_RDONLY | O_CLOEXEC);
|
||||
@@ -157,8 +147,7 @@ static inline bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) {
|
||||
return ffAppendFDBuffer(fd, buffer);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2, 3)
|
||||
static inline bool ffAppendFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer) {
|
||||
FF_A_NONNULL(2, 3) static inline bool ffAppendFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer) {
|
||||
FFNativeFD FF_AUTO_CLOSE_FD fd = openat(dfd, fileName, O_RDONLY | O_CLOEXEC);
|
||||
if (!ffIsValidNativeFD(fd)) {
|
||||
return false;
|
||||
@@ -167,20 +156,17 @@ static inline bool ffAppendFileBufferRelative(FFNativeFD dfd, const char* fileNa
|
||||
return ffAppendFDBuffer(fd, buffer);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2)
|
||||
static inline bool ffReadFDBuffer(FFNativeFD fd, FFstrbuf* buffer) {
|
||||
FF_A_NONNULL(2) static inline bool ffReadFDBuffer(FFNativeFD fd, FFstrbuf* buffer) {
|
||||
ffStrbufClear(buffer);
|
||||
return ffAppendFDBuffer(fd, buffer);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(1, 2)
|
||||
static inline bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer) {
|
||||
FF_A_NONNULL(1, 2) static inline bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer) {
|
||||
ffStrbufClear(buffer);
|
||||
return ffAppendFileBuffer(fileName, buffer);
|
||||
}
|
||||
|
||||
FF_A_NONNULL(2, 3)
|
||||
static inline bool ffReadFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer) {
|
||||
FF_A_NONNULL(2, 3) static inline bool ffReadFileBufferRelative(FFNativeFD dfd, const char* fileName, FFstrbuf* buffer) {
|
||||
ffStrbufClear(buffer);
|
||||
return ffAppendFileBufferRelative(dfd, fileName, buffer);
|
||||
}
|
||||
@@ -192,8 +178,7 @@ typedef enum FF_A_PACKED FFPathType {
|
||||
FF_PATHTYPE_FORCE_UNSIGNED = UINT8_MAX,
|
||||
} FFPathType;
|
||||
|
||||
FF_A_NONNULL(1)
|
||||
static inline bool ffPathExists(const char* path, FFPathType pathType) {
|
||||
FF_A_NONNULL(1) static inline bool ffPathExists(const char* path, FFPathType pathType) {
|
||||
#ifdef _WIN32
|
||||
|
||||
wchar_t wPath[MAX_PATH];
|
||||
@@ -242,8 +227,7 @@ static inline bool ffPathExists(const char* path, FFPathType pathType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FF_A_NONNULL(1, 2)
|
||||
bool ffPathExpandEnv(const char* in, FFstrbuf* out);
|
||||
FF_A_NONNULL(1, 2) bool ffPathExpandEnv(const char* in, FFstrbuf* out);
|
||||
|
||||
#define FF_IO_TERM_RESP_WAIT_MS 100 // #554
|
||||
|
||||
@@ -266,8 +250,7 @@ static inline void ffUnsuppressIO(bool* suppressed) {
|
||||
|
||||
void ffListFilesRecursively(const char* path, bool pretty);
|
||||
|
||||
FF_A_NONNULL(1)
|
||||
static inline bool wrapFclose(FILE** pfile) {
|
||||
FF_A_NONNULL(1) static inline bool wrapFclose(FILE** pfile) {
|
||||
assert(pfile);
|
||||
if (!*pfile) {
|
||||
return false;
|
||||
@@ -299,8 +282,7 @@ static inline bool wrapClosedir(HANDLE* pdir) {
|
||||
#endif
|
||||
#define FF_AUTO_CLOSE_DIR FF_A_CLEANUP(wrapClosedir)
|
||||
|
||||
FF_A_NONNULL(1, 2, 3)
|
||||
static inline bool ffSearchUserConfigFile(const FFlist* configDirs, const char* fileSubpath, FFstrbuf* result) {
|
||||
FF_A_NONNULL(1, 2, 3) static inline bool ffSearchUserConfigFile(const FFlist* configDirs, const char* fileSubpath, FFstrbuf* result) {
|
||||
// configDirs is a list of FFstrbufs include the trailing slash
|
||||
FF_LIST_FOR_EACH (FFstrbuf, dir, *configDirs) {
|
||||
ffStrbufClear(result);
|
||||
|
||||
@@ -35,9 +35,9 @@ static inline void ffLibraryUnload(void** handle) {
|
||||
# define FF_LIBRARY_SYMBOL(symbolName) \
|
||||
__typeof__(&symbolName) ff##symbolName;
|
||||
|
||||
# define FF_LIBRARY_LOAD(libraryObjectName, returnValue, ...) \
|
||||
# define FF_LIBRARY_LOAD(libraryObjectName, returnValue, ...) \
|
||||
void* FF_A_CLEANUP(ffLibraryUnload) libraryObjectName = ffLibraryLoad(__VA_ARGS__, NULL); \
|
||||
if (libraryObjectName == NULL) \
|
||||
if (libraryObjectName == NULL) \
|
||||
return returnValue;
|
||||
|
||||
# define FF_LIBRARY_LOAD_MESSAGE(libraryObjectName, libraryFileName, maxVersion, ...) \
|
||||
|
||||
@@ -16,7 +16,6 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu
|
||||
void ffPrintFormat(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, uint32_t numArgs, const FFformatarg* arguments);
|
||||
#define FF_PRINT_FORMAT_CHECKED(moduleName, moduleIndex, moduleArgs, printType, arguments) \
|
||||
ffPrintFormat((moduleName), (moduleIndex), (moduleArgs), (printType), (sizeof(arguments) / sizeof(*arguments)), (arguments));
|
||||
FF_A_PRINTF(5, 6)
|
||||
void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, ...);
|
||||
FF_A_PRINTF(5, 6) void ffPrintError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, ...);
|
||||
void ffPrintColor(const FFstrbuf* colorValue);
|
||||
void ffPrintCharTimes(char c, uint32_t times);
|
||||
|
||||
@@ -164,7 +164,12 @@ static bool parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFl
|
||||
}
|
||||
|
||||
FF_DEBUG("Battery \"%s\": Capacity: %.2f%%, Status: \"%x\", Time Remaining: %d seconds, Temperature: %.1f°C, Cycle Count: %u",
|
||||
id, result->capacity, result->status, result->timeRemaining, result->temperature, result->cycleCount);
|
||||
id,
|
||||
result->capacity,
|
||||
result->status,
|
||||
result->timeRemaining,
|
||||
result->temperature,
|
||||
result->cycleCount);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -189,7 +194,7 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) {
|
||||
}
|
||||
|
||||
if (acConnected) {
|
||||
FF_LIST_FOR_EACH(FFBatteryResult, batt, *results) {
|
||||
FF_LIST_FOR_EACH (FFBatteryResult, batt, *results) {
|
||||
batt->status |= FF_BATTERY_STATUS_AC_CONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ typedef struct FFSmbiosSystemInfo {
|
||||
uint8_t ClockSeqLow;
|
||||
uint8_t Node[6];
|
||||
} FF_A_PACKED UUID; // varies
|
||||
uint8_t WakeUpType; // enum
|
||||
uint8_t WakeUpType; // enum
|
||||
|
||||
// 2.4+
|
||||
uint8_t SKUNumber; // string
|
||||
|
||||
@@ -78,13 +78,14 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
|
||||
if (deviceName.length == 0) {
|
||||
FF_CFTYPE_AUTO_RELEASE CFDictionaryRef deviceCharacteristics = IORegistryEntryCreateCFProperty(entryPhysical, CFSTR(kIOPropertyDeviceCharacteristicsKey), NULL, kNilOptions);
|
||||
if (deviceCharacteristics) {
|
||||
if (ffCfDictGetString(deviceCharacteristics, CFSTR(kIOPropertyVendorNameKey), &deviceName) == NULL &&deviceName.length > 0) {
|
||||
if (ffCfDictGetString(deviceCharacteristics, CFSTR(kIOPropertyVendorNameKey), &deviceName) == NULL && deviceName.length > 0) {
|
||||
ffStrbufAppendC(&deviceName, ' ');
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
|
||||
if (ffCfDictGetString(deviceCharacteristics, CFSTR(kIOPropertyProductNameKey), &name) == NULL)
|
||||
if (ffCfDictGetString(deviceCharacteristics, CFSTR(kIOPropertyProductNameKey), &name) == NULL) {
|
||||
ffStrbufAppend(&deviceName, &name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
#include "logo/logo.h"
|
||||
#include "modules/modules.h"
|
||||
|
||||
#define MODULE_OPTION(name) \
|
||||
#define MODULE_OPTION(name) \
|
||||
FF_A_CLEANUP(ffDestroy##name##Options) FF##name##Options options; \
|
||||
ffInit##name##Options(&options);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user