From b57766522d49dde9e61b2bf9fa676b118a498caf Mon Sep 17 00:00:00 2001 From: Carter Li Date: Wed, 23 Oct 2024 14:36:12 +0800 Subject: [PATCH 01/72] Packaging: update debian stuff [ci skip] --- debian/changelog | 6 ++++++ debian/files | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 42685d71b..d7fed4125 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +fastfetch (2.28.0) jammy; urgency=medium + + * Update to 2.28.0 + + -- Carter Li Wed, 23 Oct 2024 10:18:59 +0800 + fastfetch (2.27.1) jammy; urgency=medium * Update to 2.27.1 diff --git a/debian/files b/debian/files index a5daf6ddf..386b6ac11 100644 --- a/debian/files +++ b/debian/files @@ -1 +1 @@ -fastfetch_2.27.1_source.buildinfo universe/utils optional +fastfetch_2.28.0_source.buildinfo universe/utils optional From 0bdb097592da7b9c5169861e7793f51c3f664914 Mon Sep 17 00:00:00 2001 From: apocelipes Date: Thu, 24 Oct 2024 09:43:23 +0800 Subject: [PATCH 02/72] Editor: optimize editor version parsing (#1355) --- src/detection/editor/editor.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/detection/editor/editor.c b/src/detection/editor/editor.c index 8a0e58cd6..381528e89 100644 --- a/src/detection/editor/editor.c +++ b/src/detection/editor/editor.c @@ -134,24 +134,14 @@ const char* ffDetectEditor(FFEditorResult* result) return NULL; ffStrbufSubstrBeforeFirstC(&result->version, '\n'); - for (uint32_t iStart = 0; iStart < result->version.length; ++iStart) - { - char c = result->version.chars[iStart]; - if (ffCharIsDigit(c)) - { - for (uint32_t iEnd = iStart + 1; iEnd < result->version.length; ++iEnd) - { - char c = result->version.chars[iEnd]; - if (isspace(c)) - { - ffStrbufSubstrBefore(&result->version, iEnd); - break; - } - } - if (iStart > 0) - ffStrbufSubstrAfter(&result->version, iStart - 1); - break; - } + 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 (versionStart != result->version.chars) + ffStrbufSubstrAfter(&result->version, (uint32_t)(versionStart - result->version.chars - 1)); } return NULL; From f3f8601a60b6937f4e529fceec41c0d6e4c49172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 23 Oct 2024 16:09:27 +0800 Subject: [PATCH 03/72] CMake: use 64bit time_t on Linux --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a63bb64d..b732017c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1043,7 +1043,7 @@ if(FreeBSD AND EXISTS "/usr/local/bin/objdump") endif() if(LINUX) - target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _ATFILE_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64) # "$<$:_FORTIFY_SOURCE=3>" + target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _ATFILE_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 _TIME_BITS=64) # "$<$:_FORTIFY_SOURCE=3>" elseif(ANDROID) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _FILE_OFFSET_BITS=64 "$<$:__BIONIC_FORTIFY>" "$<$:__BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED>") elseif(WIN32) From 19902fa18caccf52ad371af7328c22696106e228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 24 Oct 2024 15:21:29 +0800 Subject: [PATCH 04/72] CMake: define `NOMINMAX` on Windows --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b732017c8..1e5cfede6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1047,7 +1047,7 @@ if(LINUX) elseif(ANDROID) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _FILE_OFFSET_BITS=64 "$<$:__BIONIC_FORTIFY>" "$<$:__BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED>") elseif(WIN32) - target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE WIN32_LEAN_AND_MEAN=1 _WIN32_WINNT=0x0A00) # "$<$:_FORTIFY_SOURCE=3>" + target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE WIN32_LEAN_AND_MEAN=1 _WIN32_WINNT=0x0A00 NOMINMAX) # "$<$:_FORTIFY_SOURCE=3>" elseif(APPLE) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 _DARWIN_C_SOURCE) elseif(OpenBSD) From 53e0861b03ccabfd1006cffac2b7e5efe78fb8d5 Mon Sep 17 00:00:00 2001 From: apocelipes Date: Sat, 26 Oct 2024 11:08:18 +0800 Subject: [PATCH 05/72] Editor: fix the Vim version detection (#1356) --- src/detection/editor/editor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/detection/editor/editor.c b/src/detection/editor/editor.c index 381528e89..1566cfbb1 100644 --- a/src/detection/editor/editor.c +++ b/src/detection/editor/editor.c @@ -95,7 +95,7 @@ const char* ffDetectEditor(FFEditorResult* result) 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")) + 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")) ffBinaryExtractStrings(result->path.chars, extractNanoVersionFromBinary, &result->version, (uint32_t) strlen("GNU nano 0.0")); @@ -106,6 +106,7 @@ const char* ffDetectEditor(FFEditorResult* result) if ( ffStrbufEqualS(&result->exe, "nano") || ffStrbufEqualS(&result->exe, "vim") || + ffStrbufStartsWithS(&result->exe, "vim.") || // vim.basic/vim.tiny ffStrbufEqualS(&result->exe, "nvim") || ffStrbufEqualS(&result->exe, "micro") || ffStrbufEqualS(&result->exe, "emacs") || From 6dc6fd8b249d6a1f79748950d1aaa602949d21e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 25 Oct 2024 14:27:24 +0800 Subject: [PATCH 06/72] 3rdparty: add stb_sprintf --- src/3rdparty/stb/repo.json | 9 + src/3rdparty/stb/stb_sprintf.h | 1906 ++++++++++++++++++++++++++++++++ 2 files changed, 1915 insertions(+) create mode 100644 src/3rdparty/stb/repo.json create mode 100644 src/3rdparty/stb/stb_sprintf.h diff --git a/src/3rdparty/stb/repo.json b/src/3rdparty/stb/repo.json new file mode 100644 index 000000000..0d5ca80db --- /dev/null +++ b/src/3rdparty/stb/repo.json @@ -0,0 +1,9 @@ +{ + "home": "https://github.com/nothings/stb/blob/master/stb_sprintf.h", + "license": "MIT or Public domain (embed in source)", + "version": "v1.10", + "author": "nothings", + "patches": [ + "https://github.com/nothings/stb/pull/1695" + ] +} diff --git a/src/3rdparty/stb/stb_sprintf.h b/src/3rdparty/stb/stb_sprintf.h new file mode 100644 index 000000000..70ed4e0e4 --- /dev/null +++ b/src/3rdparty/stb/stb_sprintf.h @@ -0,0 +1,1906 @@ +// stb_sprintf - v1.10 - public domain snprintf() implementation +// originally by Jeff Roberts / RAD Game Tools, 2015/10/20 +// http://github.com/nothings/stb +// +// allowed types: sc uidBboXx p AaGgEef n +// lengths : hh h ll j z t I64 I32 I +// +// Contributors: +// Fabian "ryg" Giesen (reformatting) +// github:aganm (attribute format) +// +// Contributors (bugfixes): +// github:d26435 +// github:trex78 +// github:account-login +// Jari Komppa (SI suffixes) +// Rohit Nirmal +// Marcin Wojdyr +// Leonard Ritter +// Stefano Zanotti +// Adam Allison +// Arvid Gerstmann +// Markus Kolb +// +// LICENSE: +// +// See end of file for license information. + +#ifndef STB_SPRINTF_H_INCLUDE +#define STB_SPRINTF_H_INCLUDE + +/* +Single file sprintf replacement. + +Originally written by Jeff Roberts at RAD Game Tools - 2015/10/20. +Hereby placed in public domain. + +This is a full sprintf replacement that supports everything that +the C runtime sprintfs support, including float/double, 64-bit integers, +hex floats, field parameters (%*.*d stuff), length reads backs, etc. + +Why would you need this if sprintf already exists? Well, first off, +it's *much* faster (see below). It's also much smaller than the CRT +versions code-space-wise. We've also added some simple improvements +that are super handy (commas in thousands, callbacks at buffer full, +for example). Finally, the format strings for MSVC and GCC differ +for 64-bit integers (among other small things), so this lets you use +the same format strings in cross platform code. + +It uses the standard single file trick of being both the header file +and the source itself. If you just include it normally, you just get +the header file function definitions. To get the code, you include +it from a C or C++ file and define STB_SPRINTF_IMPLEMENTATION first. + +It only uses va_args macros from the C runtime to do it's work. It +does cast doubles to S64s and shifts and divides U64s, which does +drag in CRT code on most platforms. + +It compiles to roughly 8K with float support, and 4K without. +As a comparison, when using MSVC static libs, calling sprintf drags +in 16K. + +API: +==== +int stbsp_sprintf( char * buf, char const * fmt, ... ) +int stbsp_snprintf( char * buf, int count, char const * fmt, ... ) + Convert an arg list into a buffer. stbsp_snprintf always returns + a zero-terminated string (unlike regular snprintf). + +int stbsp_vsprintf( char * buf, char const * fmt, va_list va ) +int stbsp_vsnprintf( char * buf, int count, char const * fmt, va_list va ) + Convert a va_list arg list into a buffer. stbsp_vsnprintf always returns + a zero-terminated string (unlike regular snprintf). + +int stbsp_vsprintfcb( STBSP_SPRINTFCB * callback, void * user, char * buf, char const * fmt, va_list va ) + typedef char * STBSP_SPRINTFCB( char const * buf, void * user, int len ); + Convert into a buffer, calling back every STB_SPRINTF_MIN chars. + Your callback can then copy the chars out, print them or whatever. + This function is actually the workhorse for everything else. + The buffer you pass in must hold at least STB_SPRINTF_MIN characters. + // you return the next buffer to use or 0 to stop converting + +void stbsp_set_separators( char comma, char period ) + Set the comma and period characters to use. + +FLOATS/DOUBLES: +=============== +This code uses a internal float->ascii conversion method that uses +doubles with error correction (double-doubles, for ~105 bits of +precision). This conversion is round-trip perfect - that is, an atof +of the values output here will give you the bit-exact double back. + +One difference is that our insignificant digits will be different than +with MSVC or GCC (but they don't match each other either). We also +don't attempt to find the minimum length matching float (pre-MSVC15 +doesn't either). + +If you don't need float or doubles at all, define STB_SPRINTF_NOFLOAT +and you'll save 4K of code space. + +64-BIT INTS: +============ +This library also supports 64-bit integers and you can use MSVC style or +GCC style indicators (%I64d or %lld). It supports the C99 specifiers +for size_t and ptr_diff_t (%jd %zd) as well. + +EXTRAS: +======= +Like some GCCs, for integers and floats, you can use a ' (single quote) +specifier and commas will be inserted on the thousands: "%'d" on 12345 +would print 12,345. + +For integers and floats, you can use a "$" specifier and the number +will be converted to float and then divided to get kilo, mega, giga or +tera and then printed, so "%$d" 1000 is "1.0 k", "%$.2d" 2536000 is +"2.53 M", etc. For byte values, use two $:s, like "%$$d" to turn +2536000 to "2.42 Mi". If you prefer JEDEC suffixes to SI ones, use three +$:s: "%$$$d" -> "2.42 M". To remove the space between the number and the +suffix, add "_" specifier: "%_$d" -> "2.53M". + +In addition to octal and hexadecimal conversions, you can print +integers in binary: "%b" for 256 would print 100. + +PERFORMANCE vs MSVC 2008 32-/64-bit (GCC is even slower than MSVC): +=================================================================== +"%d" across all 32-bit ints (4.8x/4.0x faster than 32-/64-bit MSVC) +"%24d" across all 32-bit ints (4.5x/4.2x faster) +"%x" across all 32-bit ints (4.5x/3.8x faster) +"%08x" across all 32-bit ints (4.3x/3.8x faster) +"%f" across e-10 to e+10 floats (7.3x/6.0x faster) +"%e" across e-10 to e+10 floats (8.1x/6.0x faster) +"%g" across e-10 to e+10 floats (10.0x/7.1x faster) +"%f" for values near e-300 (7.9x/6.5x faster) +"%f" for values near e+300 (10.0x/9.1x faster) +"%e" for values near e-300 (10.1x/7.0x faster) +"%e" for values near e+300 (9.2x/6.0x faster) +"%.320f" for values near e-300 (12.6x/11.2x faster) +"%a" for random values (8.6x/4.3x faster) +"%I64d" for 64-bits with 32-bit values (4.8x/3.4x faster) +"%I64d" for 64-bits > 32-bit values (4.9x/5.5x faster) +"%s%s%s" for 64 char strings (7.1x/7.3x faster) +"...512 char string..." ( 35.0x/32.5x faster!) +*/ + +#if defined(__clang__) + #if defined(__has_feature) && defined(__has_attribute) + #if __has_feature(address_sanitizer) + #if __has_attribute(__no_sanitize__) + #define STBSP__ASAN __attribute__((__no_sanitize__("address"))) + #elif __has_attribute(__no_sanitize_address__) + #define STBSP__ASAN __attribute__((__no_sanitize_address__)) + #elif __has_attribute(__no_address_safety_analysis__) + #define STBSP__ASAN __attribute__((__no_address_safety_analysis__)) + #endif + #endif + #endif +#elif defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) + #if defined(__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__ + #define STBSP__ASAN __attribute__((__no_sanitize_address__)) + #endif +#endif + +#ifndef STBSP__ASAN +#define STBSP__ASAN +#endif + +#ifdef STB_SPRINTF_STATIC +#define STBSP__PUBLICDEC static +#define STBSP__PUBLICDEF static STBSP__ASAN +#else +#ifdef __cplusplus +#define STBSP__PUBLICDEC extern "C" +#define STBSP__PUBLICDEF extern "C" STBSP__ASAN +#else +#define STBSP__PUBLICDEC extern +#define STBSP__PUBLICDEF STBSP__ASAN +#endif +#endif + +#if defined(__has_attribute) + #if __has_attribute(format) + #define STBSP__ATTRIBUTE_FORMAT(fmt,va) __attribute__((format(printf,fmt,va))) + #endif +#endif + +#ifndef STBSP__ATTRIBUTE_FORMAT +#define STBSP__ATTRIBUTE_FORMAT(fmt,va) +#endif + +#ifdef _MSC_VER +#define STBSP__NOTUSED(v) (void)(v) +#else +#define STBSP__NOTUSED(v) (void)sizeof(v) +#endif + +#include // for va_arg(), va_list() +#include // size_t, ptrdiff_t + +#ifndef STB_SPRINTF_MIN +#define STB_SPRINTF_MIN 512 // how many characters per callback +#endif +typedef char *STBSP_SPRINTFCB(const char *buf, void *user, int len); + +#ifndef STB_SPRINTF_DECORATE +#define STB_SPRINTF_DECORATE(name) stbsp_##name // define this before including if you want to change the names +#endif + +STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsprintf)(char *buf, char const *fmt, va_list va); +STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsnprintf)(char *buf, int count, char const *fmt, va_list va); +STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(sprintf)(char *buf, char const *fmt, ...) STBSP__ATTRIBUTE_FORMAT(2,3); +STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(snprintf)(char *buf, int count, char const *fmt, ...) STBSP__ATTRIBUTE_FORMAT(3,4); + +STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, void *user, char *buf, char const *fmt, va_list va); +STBSP__PUBLICDEC void STB_SPRINTF_DECORATE(set_separators)(char comma, char period); + +#endif // STB_SPRINTF_H_INCLUDE + +#ifdef STB_SPRINTF_IMPLEMENTATION + +#define stbsp__uint32 unsigned int +#define stbsp__int32 signed int + +#ifdef _MSC_VER +#define stbsp__uint64 unsigned __int64 +#define stbsp__int64 signed __int64 +#else +#define stbsp__uint64 unsigned long long +#define stbsp__int64 signed long long +#endif +#define stbsp__uint16 unsigned short + +#ifndef stbsp__uintptr +#if defined(__ppc64__) || defined(__powerpc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) || defined(__s390x__)|| defined(_M_ARM64) +#define stbsp__uintptr stbsp__uint64 +#else +#define stbsp__uintptr stbsp__uint32 +#endif +#endif + +#ifndef STB_SPRINTF_MSVC_MODE // used for MSVC2013 and earlier (MSVC2015 matches GCC) +#if defined(_MSC_VER) && (_MSC_VER < 1900) +#define STB_SPRINTF_MSVC_MODE +#endif +#endif + +#ifdef STB_SPRINTF_NOUNALIGNED // define this before inclusion to force stbsp_sprintf to always use aligned accesses +#define STBSP__UNALIGNED(code) +#else +#define STBSP__UNALIGNED(code) code +#endif + +#ifndef STB_SPRINTF_NOFLOAT +// internal float utility functions +static stbsp__int32 stbsp__real_to_str(char const **start, stbsp__uint32 *len, char *out, stbsp__int32 *decimal_pos, double value, stbsp__uint32 frac_digits); +static stbsp__int32 stbsp__real_to_parts(stbsp__int64 *bits, stbsp__int32 *expo, double value); +#define STBSP__SPECIAL 0x7000 +#endif + +static char stbsp__period = '.'; +static char stbsp__comma = ','; +static struct +{ + short temp; // force next field to be 2-byte aligned + char pair[201]; +} stbsp__digitpair = +{ + 0, + "00010203040506070809101112131415161718192021222324" + "25262728293031323334353637383940414243444546474849" + "50515253545556575859606162636465666768697071727374" + "75767778798081828384858687888990919293949596979899" +}; + +STBSP__PUBLICDEF void STB_SPRINTF_DECORATE(set_separators)(char pcomma, char pperiod) +{ + stbsp__period = pperiod; + stbsp__comma = pcomma; +} + +#define STBSP__LEFTJUST 1 +#define STBSP__LEADINGPLUS 2 +#define STBSP__LEADINGSPACE 4 +#define STBSP__LEADING_0X 8 +#define STBSP__LEADINGZERO 16 +#define STBSP__INTMAX 32 +#define STBSP__TRIPLET_COMMA 64 +#define STBSP__NEGATIVE 128 +#define STBSP__METRIC_SUFFIX 256 +#define STBSP__HALFWIDTH 512 +#define STBSP__METRIC_NOSPACE 1024 +#define STBSP__METRIC_1024 2048 +#define STBSP__METRIC_JEDEC 4096 + +static void stbsp__lead_sign(stbsp__uint32 fl, char *sign) +{ + sign[0] = 0; + if (fl & STBSP__NEGATIVE) { + sign[0] = 1; + sign[1] = '-'; + } else if (fl & STBSP__LEADINGSPACE) { + sign[0] = 1; + sign[1] = ' '; + } else if (fl & STBSP__LEADINGPLUS) { + sign[0] = 1; + sign[1] = '+'; + } +} + +static STBSP__ASAN stbsp__uint32 stbsp__strlen_limited(char const *s, stbsp__uint32 limit) +{ + char const * sn = s; + + // get up to 4-byte alignment + for (;;) { + if (((stbsp__uintptr)sn & 3) == 0) + break; + + if (!limit || *sn == 0) + return (stbsp__uint32)(sn - s); + + ++sn; + --limit; + } + + // scan over 4 bytes at a time to find terminating 0 + // this will intentionally scan up to 3 bytes past the end of buffers, + // but becase it works 4B aligned, it will never cross page boundaries + // (hence the STBSP__ASAN markup; the over-read here is intentional + // and harmless) + while (limit >= 4) { + stbsp__uint32 v = *(stbsp__uint32 *)sn; + // bit hack to find if there's a 0 byte in there + if ((v - 0x01010101) & (~v) & 0x80808080UL) + break; + + sn += 4; + limit -= 4; + } + + // handle the last few characters to find actual size + while (limit && *sn) { + ++sn; + --limit; + } + + return (stbsp__uint32)(sn - s); +} + +STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, void *user, char *buf, char const *fmt, va_list va) +{ + static char hex[] = "0123456789abcdefxp"; + static char hexu[] = "0123456789ABCDEFXP"; + char *bf; + char const *f; + int tlen = 0; + + bf = buf; + f = fmt; + for (;;) { + stbsp__int32 fw, pr, tz; + stbsp__uint32 fl; + + // macros for the callback buffer stuff + #define stbsp__chk_cb_bufL(bytes) \ + { \ + int len = (int)(bf - buf); \ + if ((len + (bytes)) >= STB_SPRINTF_MIN) { \ + tlen += len; \ + if (0 == (bf = buf = callback(buf, user, len))) \ + goto done; \ + } \ + } + #define stbsp__chk_cb_buf(bytes) \ + { \ + if (callback) { \ + stbsp__chk_cb_bufL(bytes); \ + } \ + } + #define stbsp__flush_cb() \ + { \ + stbsp__chk_cb_bufL(STB_SPRINTF_MIN - 1); \ + } // flush if there is even one byte in the buffer + #define stbsp__cb_buf_clamp(cl, v) \ + cl = v; \ + if (callback) { \ + int lg = STB_SPRINTF_MIN - (int)(bf - buf); \ + if (cl > lg) \ + cl = lg; \ + } + + // fast copy everything up to the next % (or end of string) + for (;;) { + while (((stbsp__uintptr)f) & 3) { + schk1: + if (f[0] == '%') + goto scandd; + schk2: + if (f[0] == 0) + goto endfmt; + stbsp__chk_cb_buf(1); + *bf++ = f[0]; + ++f; + } + for (;;) { + // Check if the next 4 bytes contain %(0x25) or end of string. + // Using the 'hasless' trick: + // https://graphics.stanford.edu/~seander/bithacks.html#HasLessInWord + stbsp__uint32 v, c; + v = *(stbsp__uint32 *)f; + c = (~v) & 0x80808080; + if (((v ^ 0x25252525) - 0x01010101) & c) + goto schk1; + if ((v - 0x01010101) & c) + goto schk2; + if (callback) + if ((STB_SPRINTF_MIN - (int)(bf - buf)) < 4) + goto schk1; + #ifdef STB_SPRINTF_NOUNALIGNED + if(((stbsp__uintptr)bf) & 3) { + bf[0] = f[0]; + bf[1] = f[1]; + bf[2] = f[2]; + bf[3] = f[3]; + } else + #endif + { + *(stbsp__uint32 *)bf = v; + } + bf += 4; + f += 4; + } + } + scandd: + + ++f; + + // ok, we have a percent, read the modifiers first + fw = 0; + pr = -1; + fl = 0; + tz = 0; + + // flags + for (;;) { + switch (f[0]) { + // if we have left justify + case '-': + fl |= STBSP__LEFTJUST; + ++f; + continue; + // if we have leading plus + case '+': + fl |= STBSP__LEADINGPLUS; + ++f; + continue; + // if we have leading space + case ' ': + fl |= STBSP__LEADINGSPACE; + ++f; + continue; + // if we have leading 0x + case '#': + fl |= STBSP__LEADING_0X; + ++f; + continue; + // if we have thousand commas + case '\'': + fl |= STBSP__TRIPLET_COMMA; + ++f; + continue; + // if we have kilo marker (none->kilo->kibi->jedec) + case '$': + if (fl & STBSP__METRIC_SUFFIX) { + if (fl & STBSP__METRIC_1024) { + fl |= STBSP__METRIC_JEDEC; + } else { + fl |= STBSP__METRIC_1024; + } + } else { + fl |= STBSP__METRIC_SUFFIX; + } + ++f; + continue; + // if we don't want space between metric suffix and number + case '_': + fl |= STBSP__METRIC_NOSPACE; + ++f; + continue; + // if we have leading zero + case '0': + fl |= STBSP__LEADINGZERO; + ++f; + goto flags_done; + default: goto flags_done; + } + } + flags_done: + + // get the field width + if (f[0] == '*') { + fw = va_arg(va, stbsp__uint32); + ++f; + } else { + while ((f[0] >= '0') && (f[0] <= '9')) { + fw = fw * 10 + f[0] - '0'; + f++; + } + } + // get the precision + if (f[0] == '.') { + ++f; + if (f[0] == '*') { + pr = va_arg(va, stbsp__uint32); + ++f; + } else { + pr = 0; + while ((f[0] >= '0') && (f[0] <= '9')) { + pr = pr * 10 + f[0] - '0'; + f++; + } + } + } + + // handle integer size overrides + switch (f[0]) { + // are we halfwidth? + case 'h': + fl |= STBSP__HALFWIDTH; + ++f; + if (f[0] == 'h') + ++f; // QUARTERWIDTH + break; + // are we 64-bit (unix style) + case 'l': + fl |= ((sizeof(long) == 8) ? STBSP__INTMAX : 0); + ++f; + if (f[0] == 'l') { + fl |= STBSP__INTMAX; + ++f; + } + break; + // are we 64-bit on intmax? (c99) + case 'j': + fl |= (sizeof(size_t) == 8) ? STBSP__INTMAX : 0; + ++f; + break; + // are we 64-bit on size_t or ptrdiff_t? (c99) + case 'z': + fl |= (sizeof(ptrdiff_t) == 8) ? STBSP__INTMAX : 0; + ++f; + break; + case 't': + fl |= (sizeof(ptrdiff_t) == 8) ? STBSP__INTMAX : 0; + ++f; + break; + // are we 64-bit (msft style) + case 'I': + if ((f[1] == '6') && (f[2] == '4')) { + fl |= STBSP__INTMAX; + f += 3; + } else if ((f[1] == '3') && (f[2] == '2')) { + f += 3; + } else { + fl |= ((sizeof(void *) == 8) ? STBSP__INTMAX : 0); + ++f; + } + break; + default: break; + } + + // handle each replacement + switch (f[0]) { + #define STBSP__NUMSZ 512 // big enough for e308 (with commas) or e-307 + char num[STBSP__NUMSZ]; + char lead[8]; + char tail[8]; + char *s; + char const *h; + stbsp__uint32 l, n, cs; + stbsp__uint64 n64; +#ifndef STB_SPRINTF_NOFLOAT + double fv; +#endif + stbsp__int32 dp; + char const *sn; + + case 's': + // get the string + s = va_arg(va, char *); + if (s == 0) + s = (char *)"null"; + // get the length, limited to desired precision + // always limit to ~0u chars since our counts are 32b + l = stbsp__strlen_limited(s, (pr >= 0) ? pr : ~0u); + lead[0] = 0; + tail[0] = 0; + pr = 0; + dp = 0; + cs = 0; + // copy the string in + goto scopy; + + case 'c': // char + // get the character + s = num + STBSP__NUMSZ - 1; + *s = (char)va_arg(va, int); + l = 1; + lead[0] = 0; + tail[0] = 0; + pr = 0; + dp = 0; + cs = 0; + goto scopy; + + case 'n': // weird write-bytes specifier + { + int *d = va_arg(va, int *); + *d = tlen + (int)(bf - buf); + } break; + +#ifdef STB_SPRINTF_NOFLOAT + case 'A': // float + case 'a': // hex float + case 'G': // float + case 'g': // float + case 'E': // float + case 'e': // float + case 'f': // float + va_arg(va, double); // eat it + s = (char *)"No float"; + l = 8; + lead[0] = 0; + tail[0] = 0; + pr = 0; + cs = 0; + STBSP__NOTUSED(dp); + goto scopy; +#else + case 'A': // hex float + case 'a': // hex float + h = (f[0] == 'A') ? hexu : hex; + fv = va_arg(va, double); + if (pr == -1) + pr = 6; // default is 6 + // read the double into a string + if (stbsp__real_to_parts((stbsp__int64 *)&n64, &dp, fv)) + fl |= STBSP__NEGATIVE; + + s = num + 64; + + stbsp__lead_sign(fl, lead); + + if (dp == -1023) + dp = (n64) ? -1022 : 0; + else + n64 |= (((stbsp__uint64)1) << 52); + n64 <<= (64 - 56); + if (pr < 15) + n64 += ((((stbsp__uint64)8) << 56) >> (pr * 4)); +// add leading chars + +#ifdef STB_SPRINTF_MSVC_MODE + *s++ = '0'; + *s++ = 'x'; +#else + lead[1 + lead[0]] = '0'; + lead[2 + lead[0]] = 'x'; + lead[0] += 2; +#endif + *s++ = h[(n64 >> 60) & 15]; + n64 <<= 4; + if (pr) + *s++ = stbsp__period; + sn = s; + + // print the bits + n = pr; + if (n > 13) + n = 13; + if (pr > (stbsp__int32)n) + tz = pr - n; + pr = 0; + while (n--) { + *s++ = h[(n64 >> 60) & 15]; + n64 <<= 4; + } + + // print the expo + tail[1] = h[17]; + if (dp < 0) { + tail[2] = '-'; + dp = -dp; + } else + tail[2] = '+'; + n = (dp >= 1000) ? 6 : ((dp >= 100) ? 5 : ((dp >= 10) ? 4 : 3)); + tail[0] = (char)n; + for (;;) { + tail[n] = '0' + dp % 10; + if (n <= 3) + break; + --n; + dp /= 10; + } + + dp = (int)(s - sn); + l = (int)(s - (num + 64)); + s = num + 64; + cs = 1 + (3 << 24); + goto scopy; + + case 'G': // float + case 'g': // float + h = (f[0] == 'G') ? hexu : hex; + fv = va_arg(va, double); + if (pr == -1) + pr = 6; + else if (pr == 0) + pr = 1; // default is 6 + // read the double into a string + if (stbsp__real_to_str(&sn, &l, num, &dp, fv, (pr - 1) | 0x80000000)) + fl |= STBSP__NEGATIVE; + + // clamp the precision and delete extra zeros after clamp + n = pr; + if (l > (stbsp__uint32)pr) + l = pr; + while ((l > 1) && (pr) && (sn[l - 1] == '0')) { + --pr; + --l; + } + + // should we use %e + if ((dp <= -4) || (dp > (stbsp__int32)n)) { + if (pr > (stbsp__int32)l) + pr = l - 1; + else if (pr) + --pr; // when using %e, there is one digit before the decimal + goto doexpfromg; + } + // this is the insane action to get the pr to match %g semantics for %f + if (dp > 0) { + pr = (dp < (stbsp__int32)l) ? l - dp : 0; + } else { + pr = -dp + ((pr > (stbsp__int32)l) ? (stbsp__int32) l : pr); + } + goto dofloatfromg; + + case 'E': // float + case 'e': // float + h = (f[0] == 'E') ? hexu : hex; + fv = va_arg(va, double); + if (pr == -1) + pr = 6; // default is 6 + // read the double into a string + if (stbsp__real_to_str(&sn, &l, num, &dp, fv, pr | 0x80000000)) + fl |= STBSP__NEGATIVE; + doexpfromg: + tail[0] = 0; + stbsp__lead_sign(fl, lead); + if (dp == STBSP__SPECIAL) { + s = (char *)sn; + cs = 0; + pr = 0; + goto scopy; + } + s = num + 64; + // handle leading chars + *s++ = sn[0]; + + if (pr) + *s++ = stbsp__period; + + // handle after decimal + if ((l - 1) > (stbsp__uint32)pr) + l = pr + 1; + for (n = 1; n < l; n++) + *s++ = sn[n]; + // trailing zeros + tz = pr - (l - 1); + pr = 0; + // dump expo + tail[1] = h[0xe]; + dp -= 1; + if (dp < 0) { + tail[2] = '-'; + dp = -dp; + } else + tail[2] = '+'; +#ifdef STB_SPRINTF_MSVC_MODE + n = 5; +#else + n = (dp >= 100) ? 5 : 4; +#endif + tail[0] = (char)n; + for (;;) { + tail[n] = '0' + dp % 10; + if (n <= 3) + break; + --n; + dp /= 10; + } + cs = 1 + (3 << 24); // how many tens + goto flt_lead; + + case 'f': // float + fv = va_arg(va, double); + doafloat: + // do kilos + if (fl & STBSP__METRIC_SUFFIX) { + double divisor; + divisor = 1000.0f; + if (fl & STBSP__METRIC_1024) + divisor = 1024.0; + while (fl < 0x4000000) { + if ((fv < divisor) && (fv > -divisor)) + break; + fv /= divisor; + fl += 0x1000000; + } + } + if (pr == -1) + pr = 6; // default is 6 + // read the double into a string + if (stbsp__real_to_str(&sn, &l, num, &dp, fv, pr)) + fl |= STBSP__NEGATIVE; + dofloatfromg: + tail[0] = 0; + stbsp__lead_sign(fl, lead); + if (dp == STBSP__SPECIAL) { + s = (char *)sn; + cs = 0; + pr = 0; + goto scopy; + } + s = num + 64; + + // handle the three decimal varieties + if (dp <= 0) { + stbsp__int32 i; + // handle 0.000*000xxxx + *s++ = '0'; + if (pr) + *s++ = stbsp__period; + n = -dp; + if ((stbsp__int32)n > pr) + n = pr; + i = n; + while (i) { + if ((((stbsp__uintptr)s) & 3) == 0) + break; + *s++ = '0'; + --i; + } + while (i >= 4) { + *(stbsp__uint32 *)s = 0x30303030; + s += 4; + i -= 4; + } + while (i) { + *s++ = '0'; + --i; + } + if ((stbsp__int32)(l + n) > pr) + l = pr - n; + i = l; + while (i) { + *s++ = *sn++; + --i; + } + tz = pr - (n + l); + cs = 1 + (3 << 24); // how many tens did we write (for commas below) + } else { + cs = (fl & STBSP__TRIPLET_COMMA) ? ((600 - (stbsp__uint32)dp) % 3) : 0; + if ((stbsp__uint32)dp >= l) { + // handle xxxx000*000.0 + n = 0; + for (;;) { + if ((fl & STBSP__TRIPLET_COMMA) && (++cs == 4)) { + cs = 0; + *s++ = stbsp__comma; + } else { + *s++ = sn[n]; + ++n; + if (n >= l) + break; + } + } + if (n < (stbsp__uint32)dp) { + n = dp - n; + if ((fl & STBSP__TRIPLET_COMMA) == 0) { + while (n) { + if ((((stbsp__uintptr)s) & 3) == 0) + break; + *s++ = '0'; + --n; + } + while (n >= 4) { + *(stbsp__uint32 *)s = 0x30303030; + s += 4; + n -= 4; + } + } + while (n) { + if ((fl & STBSP__TRIPLET_COMMA) && (++cs == 4)) { + cs = 0; + *s++ = stbsp__comma; + } else { + *s++ = '0'; + --n; + } + } + } + cs = (int)(s - (num + 64)) + (3 << 24); // cs is how many tens + if (pr) { + *s++ = stbsp__period; + tz = pr; + } + } else { + // handle xxxxx.xxxx000*000 + n = 0; + for (;;) { + if ((fl & STBSP__TRIPLET_COMMA) && (++cs == 4)) { + cs = 0; + *s++ = stbsp__comma; + } else { + *s++ = sn[n]; + ++n; + if (n >= (stbsp__uint32)dp) + break; + } + } + cs = (int)(s - (num + 64)) + (3 << 24); // cs is how many tens + if (pr) + *s++ = stbsp__period; + if ((l - dp) > (stbsp__uint32)pr) + l = pr + dp; + while (n < l) { + *s++ = sn[n]; + ++n; + } + tz = pr - (l - dp); + } + } + pr = 0; + + // handle k,m,g,t + if (fl & STBSP__METRIC_SUFFIX) { + char idx; + idx = 1; + if (fl & STBSP__METRIC_NOSPACE) + idx = 0; + tail[0] = idx; + tail[1] = ' '; + { + if (fl >> 24) { // SI kilo is 'k', JEDEC and SI kibits are 'K'. + if (fl & STBSP__METRIC_1024) + tail[idx + 1] = "_KMGT"[fl >> 24]; + else + tail[idx + 1] = "_kMGT"[fl >> 24]; + idx++; + // If printing kibits and not in jedec, add the 'i'. + if (fl & STBSP__METRIC_1024 && !(fl & STBSP__METRIC_JEDEC)) { + tail[idx + 1] = 'i'; + idx++; + } + tail[0] = idx; + } + } + }; + + flt_lead: + // get the length that we copied + l = (stbsp__uint32)(s - (num + 64)); + s = num + 64; + goto scopy; +#endif + + case 'B': // upper binary + case 'b': // lower binary + h = (f[0] == 'B') ? hexu : hex; + lead[0] = 0; + if (fl & STBSP__LEADING_0X) { + lead[0] = 2; + lead[1] = '0'; + lead[2] = h[0xb]; + } + l = (8 << 4) | (1 << 8); + goto radixnum; + + case 'o': // octal + h = hexu; + lead[0] = 0; + if (fl & STBSP__LEADING_0X) { + lead[0] = 1; + lead[1] = '0'; + } + l = (3 << 4) | (3 << 8); + goto radixnum; + + case 'p': // pointer + fl |= (sizeof(void *) == 8) ? STBSP__INTMAX : 0; + pr = sizeof(void *) * 2; + fl &= ~STBSP__LEADINGZERO; // 'p' only prints the pointer with zeros + // fall through - to X + + case 'X': // upper hex + case 'x': // lower hex + h = (f[0] == 'X') ? hexu : hex; + l = (4 << 4) | (4 << 8); + lead[0] = 0; + if (fl & STBSP__LEADING_0X) { + lead[0] = 2; + lead[1] = '0'; + lead[2] = h[16]; + } + radixnum: + // get the number + if (fl & STBSP__INTMAX) + n64 = va_arg(va, stbsp__uint64); + else + n64 = va_arg(va, stbsp__uint32); + + s = num + STBSP__NUMSZ; + dp = 0; + // clear tail, and clear leading if value is zero + tail[0] = 0; + if (n64 == 0) { + lead[0] = 0; + if (pr == 0) { + l = 0; + cs = 0; + goto scopy; + } + } + // convert to string + for (;;) { + *--s = h[n64 & ((1 << (l >> 8)) - 1)]; + n64 >>= (l >> 8); + if (!((n64) || ((stbsp__int32)((num + STBSP__NUMSZ) - s) < pr))) + break; + if (fl & STBSP__TRIPLET_COMMA) { + ++l; + if ((l & 15) == ((l >> 4) & 15)) { + l &= ~15; + *--s = stbsp__comma; + } + } + }; + // get the tens and the comma pos + cs = (stbsp__uint32)((num + STBSP__NUMSZ) - s) + ((((l >> 4) & 15)) << 24); + // get the length that we copied + l = (stbsp__uint32)((num + STBSP__NUMSZ) - s); + // copy it + goto scopy; + + case 'u': // unsigned + case 'i': + case 'd': // integer + // get the integer and abs it + if (fl & STBSP__INTMAX) { + stbsp__int64 i64 = va_arg(va, stbsp__int64); + n64 = (stbsp__uint64)i64; + if ((f[0] != 'u') && (i64 < 0)) { + n64 = (stbsp__uint64)-i64; + fl |= STBSP__NEGATIVE; + } + } else { + stbsp__int32 i = va_arg(va, stbsp__int32); + n64 = (stbsp__uint32)i; + if ((f[0] != 'u') && (i < 0)) { + n64 = (stbsp__uint32)-i; + fl |= STBSP__NEGATIVE; + } + } + +#ifndef STB_SPRINTF_NOFLOAT + if (fl & STBSP__METRIC_SUFFIX) { + if (n64 < 1024) + pr = 0; + else if (pr == -1) + pr = 1; + fv = (double)(stbsp__int64)n64; + goto doafloat; + } +#endif + + // convert to string + s = num + STBSP__NUMSZ; + l = 0; + + for (;;) { + // do in 32-bit chunks (avoid lots of 64-bit divides even with constant denominators) + char *o = s - 8; + if (n64 >= 100000000) { + n = (stbsp__uint32)(n64 % 100000000); + n64 /= 100000000; + } else { + n = (stbsp__uint32)n64; + n64 = 0; + } + if ((fl & STBSP__TRIPLET_COMMA) == 0) { + do { + s -= 2; + *(stbsp__uint16 *)s = *(stbsp__uint16 *)&stbsp__digitpair.pair[(n % 100) * 2]; + n /= 100; + } while (n); + } + while (n) { + if ((fl & STBSP__TRIPLET_COMMA) && (l++ == 3)) { + l = 0; + *--s = stbsp__comma; + --o; + } else { + *--s = (char)(n % 10) + '0'; + n /= 10; + } + } + if (n64 == 0) { + if ((s[0] == '0') && (s != (num + STBSP__NUMSZ))) + ++s; + break; + } + while (s != o) + if ((fl & STBSP__TRIPLET_COMMA) && (l++ == 3)) { + l = 0; + *--s = stbsp__comma; + --o; + } else { + *--s = '0'; + } + } + + tail[0] = 0; + stbsp__lead_sign(fl, lead); + + // get the length that we copied + l = (stbsp__uint32)((num + STBSP__NUMSZ) - s); + if (l == 0) { + *--s = '0'; + l = 1; + } + cs = l + (3 << 24); + if (pr < 0) + pr = 0; + + scopy: + // get fw=leading/trailing space, pr=leading zeros + if (pr < (stbsp__int32)l) + pr = l; + n = pr + lead[0] + tail[0] + tz; + if (fw < (stbsp__int32)n) + fw = n; + fw -= n; + pr -= l; + + // handle right justify and leading zeros + if ((fl & STBSP__LEFTJUST) == 0) { + if (fl & STBSP__LEADINGZERO) // if leading zeros, everything is in pr + { + pr = (fw > pr) ? fw : pr; + fw = 0; + } else { + fl &= ~STBSP__TRIPLET_COMMA; // if no leading zeros, then no commas + } + } + + // copy the spaces and/or zeros + if (fw + pr) { + stbsp__int32 i; + stbsp__uint32 c; + + // copy leading spaces (or when doing %8.4d stuff) + if ((fl & STBSP__LEFTJUST) == 0) + while (fw > 0) { + stbsp__cb_buf_clamp(i, fw); + fw -= i; + while (i) { + if ((((stbsp__uintptr)bf) & 3) == 0) + break; + *bf++ = ' '; + --i; + } + while (i >= 4) { + *(stbsp__uint32 *)bf = 0x20202020; + bf += 4; + i -= 4; + } + while (i) { + *bf++ = ' '; + --i; + } + stbsp__chk_cb_buf(1); + } + + // copy leader + sn = lead + 1; + while (lead[0]) { + stbsp__cb_buf_clamp(i, lead[0]); + lead[0] -= (char)i; + while (i) { + *bf++ = *sn++; + --i; + } + stbsp__chk_cb_buf(1); + } + + // copy leading zeros + c = cs >> 24; + cs &= 0xffffff; + cs = (fl & STBSP__TRIPLET_COMMA) ? ((stbsp__uint32)(c - ((pr + cs) % (c + 1)))) : 0; + while (pr > 0) { + stbsp__cb_buf_clamp(i, pr); + pr -= i; + if ((fl & STBSP__TRIPLET_COMMA) == 0) { + while (i) { + if ((((stbsp__uintptr)bf) & 3) == 0) + break; + *bf++ = '0'; + --i; + } + while (i >= 4) { + *(stbsp__uint32 *)bf = 0x30303030; + bf += 4; + i -= 4; + } + } + while (i) { + if ((fl & STBSP__TRIPLET_COMMA) && (cs++ == c)) { + cs = 0; + *bf++ = stbsp__comma; + } else + *bf++ = '0'; + --i; + } + stbsp__chk_cb_buf(1); + } + } + + // copy leader if there is still one + sn = lead + 1; + while (lead[0]) { + stbsp__int32 i; + stbsp__cb_buf_clamp(i, lead[0]); + lead[0] -= (char)i; + while (i) { + *bf++ = *sn++; + --i; + } + stbsp__chk_cb_buf(1); + } + + // copy the string + n = l; + while (n) { + stbsp__int32 i; + stbsp__cb_buf_clamp(i, n); + n -= i; + STBSP__UNALIGNED(while (i >= 4) { + *(stbsp__uint32 volatile *)bf = *(stbsp__uint32 volatile *)s; + bf += 4; + s += 4; + i -= 4; + }) + while (i) { + *bf++ = *s++; + --i; + } + stbsp__chk_cb_buf(1); + } + + // copy trailing zeros + while (tz) { + stbsp__int32 i; + stbsp__cb_buf_clamp(i, tz); + tz -= i; + while (i) { + if ((((stbsp__uintptr)bf) & 3) == 0) + break; + *bf++ = '0'; + --i; + } + while (i >= 4) { + *(stbsp__uint32 *)bf = 0x30303030; + bf += 4; + i -= 4; + } + while (i) { + *bf++ = '0'; + --i; + } + stbsp__chk_cb_buf(1); + } + + // copy tail if there is one + sn = tail + 1; + while (tail[0]) { + stbsp__int32 i; + stbsp__cb_buf_clamp(i, tail[0]); + tail[0] -= (char)i; + while (i) { + *bf++ = *sn++; + --i; + } + stbsp__chk_cb_buf(1); + } + + // handle the left justify + if (fl & STBSP__LEFTJUST) + if (fw > 0) { + while (fw) { + stbsp__int32 i; + stbsp__cb_buf_clamp(i, fw); + fw -= i; + while (i) { + if ((((stbsp__uintptr)bf) & 3) == 0) + break; + *bf++ = ' '; + --i; + } + while (i >= 4) { + *(stbsp__uint32 *)bf = 0x20202020; + bf += 4; + i -= 4; + } + while (i--) + *bf++ = ' '; + stbsp__chk_cb_buf(1); + } + } + break; + + default: // unknown, just copy code + s = num + STBSP__NUMSZ - 1; + *s = f[0]; + l = 1; + fw = fl = 0; + lead[0] = 0; + tail[0] = 0; + pr = 0; + dp = 0; + cs = 0; + goto scopy; + } + ++f; + } +endfmt: + + if (!callback) + *bf = 0; + else + stbsp__flush_cb(); + +done: + return tlen + (int)(bf - buf); +} + +// cleanup +#undef STBSP__LEFTJUST +#undef STBSP__LEADINGPLUS +#undef STBSP__LEADINGSPACE +#undef STBSP__LEADING_0X +#undef STBSP__LEADINGZERO +#undef STBSP__INTMAX +#undef STBSP__TRIPLET_COMMA +#undef STBSP__NEGATIVE +#undef STBSP__METRIC_SUFFIX +#undef STBSP__NUMSZ +#undef stbsp__chk_cb_bufL +#undef stbsp__chk_cb_buf +#undef stbsp__flush_cb +#undef stbsp__cb_buf_clamp + +// ============================================================================ +// wrapper functions + +STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(sprintf)(char *buf, char const *fmt, ...) +{ + int result; + va_list va; + va_start(va, fmt); + result = STB_SPRINTF_DECORATE(vsprintfcb)(0, 0, buf, fmt, va); + va_end(va); + return result; +} + +typedef struct stbsp__context { + char *buf; + int count; + int length; + char tmp[STB_SPRINTF_MIN]; +} stbsp__context; + +static char *stbsp__clamp_callback(const char *buf, void *user, int len) +{ + stbsp__context *c = (stbsp__context *)user; + c->length += len; + + if (len > c->count) + len = c->count; + + if (len) { + if (buf != c->buf) { + const char *s, *se; + char *d; + d = c->buf; + s = buf; + se = buf + len; + do { + *d++ = *s++; + } while (s < se); + } + c->buf += len; + c->count -= len; + } + + if (c->count <= 0) + return c->tmp; + return (c->count >= STB_SPRINTF_MIN) ? c->buf : c->tmp; // go direct into buffer if you can +} + +static char * stbsp__count_clamp_callback( const char * buf, void * user, int len ) +{ + stbsp__context * c = (stbsp__context*)user; + (void) sizeof(buf); + + c->length += len; + return c->tmp; // go direct into buffer if you can +} + +STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( vsnprintf )( char * buf, int count, char const * fmt, va_list va ) +{ + stbsp__context c; + + if ( (count == 0) && !buf ) + { + c.length = 0; + + STB_SPRINTF_DECORATE( vsprintfcb )( stbsp__count_clamp_callback, &c, c.tmp, fmt, va ); + } + else + { + int l; + + c.buf = buf; + c.count = count; + c.length = 0; + + STB_SPRINTF_DECORATE( vsprintfcb )( stbsp__clamp_callback, &c, stbsp__clamp_callback(0,&c,0), fmt, va ); + + // zero-terminate + l = (int)( c.buf - buf ); + if ( l >= count ) // should never be greater, only equal (or less) than count + l = count - 1; + buf[l] = 0; + } + + return c.length; +} + +STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(snprintf)(char *buf, int count, char const *fmt, ...) +{ + int result; + va_list va; + va_start(va, fmt); + + result = STB_SPRINTF_DECORATE(vsnprintf)(buf, count, fmt, va); + va_end(va); + + return result; +} + +STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintf)(char *buf, char const *fmt, va_list va) +{ + return STB_SPRINTF_DECORATE(vsprintfcb)(0, 0, buf, fmt, va); +} + +// ======================================================================= +// low level float utility functions + +#ifndef STB_SPRINTF_NOFLOAT + +// copies d to bits w/ strict aliasing (this compiles to nothing on /Ox) +#define STBSP__COPYFP(dest, src) \ + { \ + int cn; \ + for (cn = 0; cn < 8; cn++) \ + ((char *)&dest)[cn] = ((char *)&src)[cn]; \ + } + +// get float info +static stbsp__int32 stbsp__real_to_parts(stbsp__int64 *bits, stbsp__int32 *expo, double value) +{ + double d; + stbsp__int64 b = 0; + + // load value and round at the frac_digits + d = value; + + STBSP__COPYFP(b, d); + + *bits = b & ((((stbsp__uint64)1) << 52) - 1); + *expo = (stbsp__int32)(((b >> 52) & 2047) - 1023); + + return (stbsp__int32)((stbsp__uint64) b >> 63); +} + +static double const stbsp__bot[23] = { + 1e+000, 1e+001, 1e+002, 1e+003, 1e+004, 1e+005, 1e+006, 1e+007, 1e+008, 1e+009, 1e+010, 1e+011, + 1e+012, 1e+013, 1e+014, 1e+015, 1e+016, 1e+017, 1e+018, 1e+019, 1e+020, 1e+021, 1e+022 +}; +static double const stbsp__negbot[22] = { + 1e-001, 1e-002, 1e-003, 1e-004, 1e-005, 1e-006, 1e-007, 1e-008, 1e-009, 1e-010, 1e-011, + 1e-012, 1e-013, 1e-014, 1e-015, 1e-016, 1e-017, 1e-018, 1e-019, 1e-020, 1e-021, 1e-022 +}; +static double const stbsp__negboterr[22] = { + -5.551115123125783e-018, -2.0816681711721684e-019, -2.0816681711721686e-020, -4.7921736023859299e-021, -8.1803053914031305e-022, 4.5251888174113741e-023, + 4.5251888174113739e-024, -2.0922560830128471e-025, -6.2281591457779853e-026, -3.6432197315497743e-027, 6.0503030718060191e-028, 2.0113352370744385e-029, + -3.0373745563400371e-030, 1.1806906454401013e-032, -7.7705399876661076e-032, 2.0902213275965398e-033, -7.1542424054621921e-034, -7.1542424054621926e-035, + 2.4754073164739869e-036, 5.4846728545790429e-037, 9.2462547772103625e-038, -4.8596774326570872e-039 +}; +static double const stbsp__top[13] = { + 1e+023, 1e+046, 1e+069, 1e+092, 1e+115, 1e+138, 1e+161, 1e+184, 1e+207, 1e+230, 1e+253, 1e+276, 1e+299 +}; +static double const stbsp__negtop[13] = { + 1e-023, 1e-046, 1e-069, 1e-092, 1e-115, 1e-138, 1e-161, 1e-184, 1e-207, 1e-230, 1e-253, 1e-276, 1e-299 +}; +static double const stbsp__toperr[13] = { + 8388608, + 6.8601809640529717e+028, + -7.253143638152921e+052, + -4.3377296974619174e+075, + -1.5559416129466825e+098, + -3.2841562489204913e+121, + -3.7745893248228135e+144, + -1.7356668416969134e+167, + -3.8893577551088374e+190, + -9.9566444326005119e+213, + 6.3641293062232429e+236, + -5.2069140800249813e+259, + -5.2504760255204387e+282 +}; +static double const stbsp__negtoperr[13] = { + 3.9565301985100693e-040, -2.299904345391321e-063, 3.6506201437945798e-086, 1.1875228833981544e-109, + -5.0644902316928607e-132, -6.7156837247865426e-155, -2.812077463003139e-178, -5.7778912386589953e-201, + 7.4997100559334532e-224, -4.6439668915134491e-247, -6.3691100762962136e-270, -9.436808465446358e-293, + 8.0970921678014997e-317 +}; + +#if defined(_MSC_VER) && (_MSC_VER <= 1200) +static stbsp__uint64 const stbsp__powten[20] = { + 1, + 10, + 100, + 1000, + 10000, + 100000, + 1000000, + 10000000, + 100000000, + 1000000000, + 10000000000, + 100000000000, + 1000000000000, + 10000000000000, + 100000000000000, + 1000000000000000, + 10000000000000000, + 100000000000000000, + 1000000000000000000, + 10000000000000000000U +}; +#define stbsp__tento19th ((stbsp__uint64)1000000000000000000) +#else +static stbsp__uint64 const stbsp__powten[20] = { + 1, + 10, + 100, + 1000, + 10000, + 100000, + 1000000, + 10000000, + 100000000, + 1000000000, + 10000000000ULL, + 100000000000ULL, + 1000000000000ULL, + 10000000000000ULL, + 100000000000000ULL, + 1000000000000000ULL, + 10000000000000000ULL, + 100000000000000000ULL, + 1000000000000000000ULL, + 10000000000000000000ULL +}; +#define stbsp__tento19th (1000000000000000000ULL) +#endif + +#define stbsp__ddmulthi(oh, ol, xh, yh) \ + { \ + double ahi = 0, alo, bhi = 0, blo; \ + stbsp__int64 bt; \ + oh = xh * yh; \ + STBSP__COPYFP(bt, xh); \ + bt &= ((~(stbsp__uint64)0) << 27); \ + STBSP__COPYFP(ahi, bt); \ + alo = xh - ahi; \ + STBSP__COPYFP(bt, yh); \ + bt &= ((~(stbsp__uint64)0) << 27); \ + STBSP__COPYFP(bhi, bt); \ + blo = yh - bhi; \ + ol = ((ahi * bhi - oh) + ahi * blo + alo * bhi) + alo * blo; \ + } + +#define stbsp__ddtoS64(ob, xh, xl) \ + { \ + double ahi = 0, alo, vh, t; \ + ob = (stbsp__int64)xh; \ + vh = (double)ob; \ + ahi = (xh - vh); \ + t = (ahi - xh); \ + alo = (xh - (ahi - t)) - (vh + t); \ + ob += (stbsp__int64)(ahi + alo + xl); \ + } + +#define stbsp__ddrenorm(oh, ol) \ + { \ + double s; \ + s = oh + ol; \ + ol = ol - (s - oh); \ + oh = s; \ + } + +#define stbsp__ddmultlo(oh, ol, xh, xl, yh, yl) ol = ol + (xh * yl + xl * yh); + +#define stbsp__ddmultlos(oh, ol, xh, yl) ol = ol + (xh * yl); + +static void stbsp__raise_to_power10(double *ohi, double *olo, double d, stbsp__int32 power) // power can be -323 to +350 +{ + double ph, pl; + if ((power >= 0) && (power <= 22)) { + stbsp__ddmulthi(ph, pl, d, stbsp__bot[power]); + } else { + stbsp__int32 e, et, eb; + double p2h, p2l; + + e = power; + if (power < 0) + e = -e; + et = (e * 0x2c9) >> 14; /* %23 */ + if (et > 13) + et = 13; + eb = e - (et * 23); + + ph = d; + pl = 0.0; + if (power < 0) { + if (eb) { + --eb; + stbsp__ddmulthi(ph, pl, d, stbsp__negbot[eb]); + stbsp__ddmultlos(ph, pl, d, stbsp__negboterr[eb]); + } + if (et) { + stbsp__ddrenorm(ph, pl); + --et; + stbsp__ddmulthi(p2h, p2l, ph, stbsp__negtop[et]); + stbsp__ddmultlo(p2h, p2l, ph, pl, stbsp__negtop[et], stbsp__negtoperr[et]); + ph = p2h; + pl = p2l; + } + } else { + if (eb) { + e = eb; + if (eb > 22) + eb = 22; + e -= eb; + stbsp__ddmulthi(ph, pl, d, stbsp__bot[eb]); + if (e) { + stbsp__ddrenorm(ph, pl); + stbsp__ddmulthi(p2h, p2l, ph, stbsp__bot[e]); + stbsp__ddmultlos(p2h, p2l, stbsp__bot[e], pl); + ph = p2h; + pl = p2l; + } + } + if (et) { + stbsp__ddrenorm(ph, pl); + --et; + stbsp__ddmulthi(p2h, p2l, ph, stbsp__top[et]); + stbsp__ddmultlo(p2h, p2l, ph, pl, stbsp__top[et], stbsp__toperr[et]); + ph = p2h; + pl = p2l; + } + } + } + stbsp__ddrenorm(ph, pl); + *ohi = ph; + *olo = pl; +} + +// given a float value, returns the significant bits in bits, and the position of the +// decimal point in decimal_pos. +/-INF and NAN are specified by special values +// returned in the decimal_pos parameter. +// frac_digits is absolute normally, but if you want from first significant digits (got %g and %e), or in 0x80000000 +static stbsp__int32 stbsp__real_to_str(char const **start, stbsp__uint32 *len, char *out, stbsp__int32 *decimal_pos, double value, stbsp__uint32 frac_digits) +{ + double d; + stbsp__int64 bits = 0; + stbsp__int32 expo, e, ng, tens; + + d = value; + STBSP__COPYFP(bits, d); + expo = (stbsp__int32)((bits >> 52) & 2047); + ng = (stbsp__int32)((stbsp__uint64) bits >> 63); + if (ng) + d = -d; + + if (expo == 2047) // is nan or inf? + { + *start = (bits & ((((stbsp__uint64)1) << 52) - 1)) ? "NaN" : "Inf"; + *decimal_pos = STBSP__SPECIAL; + *len = 3; + return ng; + } + + if (expo == 0) // is zero or denormal + { + if (((stbsp__uint64) bits << 1) == 0) // do zero + { + *decimal_pos = 1; + *start = out; + out[0] = '0'; + *len = 1; + return ng; + } + // find the right expo for denormals + { + stbsp__int64 v = ((stbsp__uint64)1) << 51; + while ((bits & v) == 0) { + --expo; + v >>= 1; + } + } + } + + // find the decimal exponent as well as the decimal bits of the value + { + double ph, pl; + + // log10 estimate - very specifically tweaked to hit or undershoot by no more than 1 of log10 of all expos 1..2046 + tens = expo - 1023; + tens = (tens < 0) ? ((tens * 617) / 2048) : (((tens * 1233) / 4096) + 1); + + // move the significant bits into position and stick them into an int + stbsp__raise_to_power10(&ph, &pl, d, 18 - tens); + + // get full as much precision from double-double as possible + stbsp__ddtoS64(bits, ph, pl); + + // check if we undershot + if (((stbsp__uint64)bits) >= stbsp__tento19th) + ++tens; + } + + // now do the rounding in integer land + frac_digits = (frac_digits & 0x80000000) ? ((frac_digits & 0x7ffffff) + 1) : (tens + frac_digits); + if ((frac_digits < 24)) { + stbsp__uint32 dg = 1; + if ((stbsp__uint64)bits >= stbsp__powten[9]) + dg = 10; + while ((stbsp__uint64)bits >= stbsp__powten[dg]) { + ++dg; + if (dg == 20) + goto noround; + } + if (frac_digits < dg) { + stbsp__uint64 r; + // add 0.5 at the right position and round + e = dg - frac_digits; + if ((stbsp__uint32)e >= 24) + goto noround; + r = stbsp__powten[e]; + bits = bits + (r / 2); + if ((stbsp__uint64)bits >= stbsp__powten[dg]) + ++tens; + bits /= r; + } + noround:; + } + + // kill long trailing runs of zeros + if (bits) { + stbsp__uint32 n; + for (;;) { + if (bits <= 0xffffffff) + break; + if (bits % 1000) + goto donez; + bits /= 1000; + } + n = (stbsp__uint32)bits; + while ((n % 1000) == 0) + n /= 1000; + bits = n; + donez:; + } + + // convert to string + out += 64; + e = 0; + for (;;) { + stbsp__uint32 n; + char *o = out - 8; + // do the conversion in chunks of U32s (avoid most 64-bit divides, worth it, constant denomiators be damned) + if (bits >= 100000000) { + n = (stbsp__uint32)(bits % 100000000); + bits /= 100000000; + } else { + n = (stbsp__uint32)bits; + bits = 0; + } + while (n) { + out -= 2; + *(stbsp__uint16 *)out = *(stbsp__uint16 *)&stbsp__digitpair.pair[(n % 100) * 2]; + n /= 100; + e += 2; + } + if (bits == 0) { + if ((e) && (out[0] == '0')) { + ++out; + --e; + } + break; + } + while (out != o) { + *--out = '0'; + ++e; + } + } + + *decimal_pos = tens; + *start = out; + *len = e; + return ng; +} + +#undef stbsp__ddmulthi +#undef stbsp__ddrenorm +#undef stbsp__ddmultlo +#undef stbsp__ddmultlos +#undef STBSP__SPECIAL +#undef STBSP__COPYFP + +#endif // STB_SPRINTF_NOFLOAT + +// clean up +#undef stbsp__uint16 +#undef stbsp__uint32 +#undef stbsp__int32 +#undef stbsp__uint64 +#undef stbsp__int64 +#undef STBSP__UNALIGNED + +#endif // STB_SPRINTF_IMPLEMENTATION + +/* +------------------------------------------------------------------------------ +This software is available under 2 licenses -- choose whichever you prefer. +------------------------------------------------------------------------------ +ALTERNATIVE A - MIT License +Copyright (c) 2017 Sean Barrett +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +------------------------------------------------------------------------------ +ALTERNATIVE B - Public Domain (www.unlicense.org) +This is free and unencumbered software released into the public domain. +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this +software, either in source code form or as a compiled binary, for any purpose, +commercial or non-commercial, and by any means. +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and to +the detriment of our heirs and successors. We intend this dedication to be an +overt act of relinquishment in perpetuity of all present and future rights to +this software under copyright law. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------------ +*/ From fd26373c8f5b0534e61961c3dcb856971c043fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 25 Oct 2024 14:48:11 +0800 Subject: [PATCH 07/72] Global: overall optimization --- src/common/font.c | 10 +- src/common/format.c | 6 +- src/common/modules.c | 146 ++++++++++---------- src/common/parsing.c | 2 +- src/detection/bootmgr/bootmgr.c | 4 +- src/detection/cpuusage/cpuusage.c | 8 +- src/detection/disk/disk_linux.c | 4 +- src/detection/disk/disk_sunos.c | 4 +- src/detection/diskio/diskio.c | 4 +- src/detection/displayserver/displayserver.c | 2 +- src/detection/netio/netio.c | 4 +- src/fastfetch.c | 2 +- src/fastfetch.h | 4 +- src/modules/bluetooth/bluetooth.c | 2 +- src/modules/display/display.c | 2 +- src/modules/gpu/gpu.c | 2 +- src/modules/poweradapter/poweradapter.c | 2 +- src/modules/users/users.c | 6 +- src/modules/wifi/wifi.c | 2 +- src/util/FFlist.c | 19 --- src/util/FFlist.h | 22 ++- 21 files changed, 126 insertions(+), 131 deletions(-) diff --git a/src/common/font.c b/src/common/font.c index 80a67144c..13264f577 100644 --- a/src/common/font.c +++ b/src/common/font.c @@ -51,7 +51,7 @@ static void fontInitPretty(FFfont* font) for(uint32_t i = 0; i < font->styles.length; i++) { - ffStrbufAppend(&font->pretty, ffListGet(&font->styles, i)); + ffStrbufAppend(&font->pretty, FF_LIST_GET(FFstrbuf, font->styles, i)); if(i < font->styles.length - 1) ffStrbufAppendS(&font->pretty, ", "); @@ -86,7 +86,7 @@ void ffFontInitQt(FFfont* font, const char* data) { do { - FFstrbuf* style = ffListAdd(&font->styles); + FFstrbuf* style = (FFstrbuf*) ffListAdd(&font->styles); ffStrbufInit(style); data = ffStrbufAppendSUntilC(style, data, ' '); if (data) data++; @@ -142,7 +142,7 @@ static void fontPangoParseWord(const char** data, FFfont* font, FFstrbuf* altern ) { if(alternativeBuffer == NULL) { - alternativeBuffer = ffListAdd(&font->styles); + alternativeBuffer = (FFstrbuf*) ffListAdd(&font->styles); ffStrbufInit(alternativeBuffer); } @@ -215,7 +215,7 @@ void ffFontDestroy(FFfont* font) ffStrbufDestroy(&font->name); ffStrbufDestroy(&font->size); - for(uint32_t i = 0; i < font->styles.length; i++) - ffStrbufDestroy(ffListGet(&font->styles, i)); + FF_LIST_FOR_EACH(FFstrbuf, str, font->styles) + ffStrbufDestroy(str); ffListDestroy(&font->styles); } diff --git a/src/common/format.c b/src/common/format.c index 1e8c92702..19564a3fb 100644 --- a/src/common/format.c +++ b/src/common/format.c @@ -42,10 +42,10 @@ void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg) break; case FF_FORMAT_ARG_TYPE_LIST: { - const FFlist* list = formatarg->value; + const FFlist* list = (const FFlist*) formatarg->value; for(uint32_t i = 0; i < list->length; i++) { - ffStrbufAppend(buffer, ffListGet(list, i)); + ffStrbufAppend(buffer, FF_LIST_GET(FFstrbuf, *list, i)); if(i < list->length - 1) ffStrbufAppendS(buffer, ", "); } @@ -110,7 +110,7 @@ static inline bool formatArgSet(const FFformatarg* arg) (arg->type == FF_FORMAT_ARG_TYPE_DOUBLE && *(double*)arg->value > 0.0) || //Also is false for NaN (arg->type == FF_FORMAT_ARG_TYPE_INT && *(int*)arg->value > 0) || (arg->type == FF_FORMAT_ARG_TYPE_STRBUF && ((FFstrbuf*)arg->value)->length > 0) || - (arg->type == FF_FORMAT_ARG_TYPE_STRING && ffStrSet(arg->value)) || + (arg->type == FF_FORMAT_ARG_TYPE_STRING && ffStrSet((char*)arg->value)) || (arg->type == FF_FORMAT_ARG_TYPE_UINT8 && *(uint8_t*)arg->value > 0) || (arg->type == FF_FORMAT_ARG_TYPE_UINT16 && *(uint16_t*)arg->value > 0) || (arg->type == FF_FORMAT_ARG_TYPE_UINT && *(uint32_t*)arg->value > 0) || diff --git a/src/common/modules.c b/src/common/modules.c index ce649cfc9..724c1aa49 100644 --- a/src/common/modules.c +++ b/src/common/modules.c @@ -5,65 +5,65 @@ static FFModuleBaseInfo* A[] = { }; static FFModuleBaseInfo* B[] = { - (void*) &instance.config.modules.battery, - (void*) &instance.config.modules.bios, - (void*) &instance.config.modules.bluetooth, - (void*) &instance.config.modules.bluetoothRadio, - (void*) &instance.config.modules.board, - (void*) &instance.config.modules.bootmgr, - (void*) &instance.config.modules.break_, - (void*) &instance.config.modules.brightness, - (void*) &instance.config.modules.btrfs, + (FFModuleBaseInfo*) &instance.config.modules.battery, + (FFModuleBaseInfo*) &instance.config.modules.bios, + (FFModuleBaseInfo*) &instance.config.modules.bluetooth, + (FFModuleBaseInfo*) &instance.config.modules.bluetoothRadio, + (FFModuleBaseInfo*) &instance.config.modules.board, + (FFModuleBaseInfo*) &instance.config.modules.bootmgr, + (FFModuleBaseInfo*) &instance.config.modules.break_, + (FFModuleBaseInfo*) &instance.config.modules.brightness, + (FFModuleBaseInfo*) &instance.config.modules.btrfs, NULL, }; static FFModuleBaseInfo* C[] = { - (void*) &instance.config.modules.camera, - (void*) &instance.config.modules.chassis, - (void*) &instance.config.modules.command, - (void*) &instance.config.modules.colors, - (void*) &instance.config.modules.cpu, - (void*) &instance.config.modules.cpuCache, - (void*) &instance.config.modules.cpuUsage, - (void*) &instance.config.modules.cursor, - (void*) &instance.config.modules.custom, + (FFModuleBaseInfo*) &instance.config.modules.camera, + (FFModuleBaseInfo*) &instance.config.modules.chassis, + (FFModuleBaseInfo*) &instance.config.modules.command, + (FFModuleBaseInfo*) &instance.config.modules.colors, + (FFModuleBaseInfo*) &instance.config.modules.cpu, + (FFModuleBaseInfo*) &instance.config.modules.cpuCache, + (FFModuleBaseInfo*) &instance.config.modules.cpuUsage, + (FFModuleBaseInfo*) &instance.config.modules.cursor, + (FFModuleBaseInfo*) &instance.config.modules.custom, NULL, }; static FFModuleBaseInfo* D[] = { - (void*) &instance.config.modules.dateTime, - (void*) &instance.config.modules.de, - (void*) &instance.config.modules.display, - (void*) &instance.config.modules.disk, - (void*) &instance.config.modules.diskIo, - (void*) &instance.config.modules.dns, + (FFModuleBaseInfo*) &instance.config.modules.dateTime, + (FFModuleBaseInfo*) &instance.config.modules.de, + (FFModuleBaseInfo*) &instance.config.modules.display, + (FFModuleBaseInfo*) &instance.config.modules.disk, + (FFModuleBaseInfo*) &instance.config.modules.diskIo, + (FFModuleBaseInfo*) &instance.config.modules.dns, NULL, }; static FFModuleBaseInfo* E[] = { - (void*) &instance.config.modules.editor, + (FFModuleBaseInfo*) &instance.config.modules.editor, NULL, }; static FFModuleBaseInfo* F[] = { - (void*) &instance.config.modules.font, + (FFModuleBaseInfo*) &instance.config.modules.font, NULL, }; static FFModuleBaseInfo* G[] = { - (void*) &instance.config.modules.gamepad, - (void*) &instance.config.modules.gpu, + (FFModuleBaseInfo*) &instance.config.modules.gamepad, + (FFModuleBaseInfo*) &instance.config.modules.gpu, NULL, }; static FFModuleBaseInfo* H[] = { - (void*) &instance.config.modules.host, + (FFModuleBaseInfo*) &instance.config.modules.host, NULL, }; static FFModuleBaseInfo* I[] = { - (void*) &instance.config.modules.icons, - (void*) &instance.config.modules.initSystem, + (FFModuleBaseInfo*) &instance.config.modules.icons, + (FFModuleBaseInfo*) &instance.config.modules.initSystem, NULL, }; @@ -72,47 +72,47 @@ static FFModuleBaseInfo* J[] = { }; static FFModuleBaseInfo* K[] = { - (void*) &instance.config.modules.kernel, - (void*) &instance.config.modules.keyboard, + (FFModuleBaseInfo*) &instance.config.modules.kernel, + (FFModuleBaseInfo*) &instance.config.modules.keyboard, NULL, }; static FFModuleBaseInfo* L[] = { - (void*) &instance.config.modules.lm, - (void*) &instance.config.modules.loadavg, - (void*) &instance.config.modules.locale, - (void*) &instance.config.modules.localIP, + (FFModuleBaseInfo*) &instance.config.modules.lm, + (FFModuleBaseInfo*) &instance.config.modules.loadavg, + (FFModuleBaseInfo*) &instance.config.modules.locale, + (FFModuleBaseInfo*) &instance.config.modules.localIP, NULL, }; static FFModuleBaseInfo* M[] = { - (void*) &instance.config.modules.media, - (void*) &instance.config.modules.memory, - (void*) &instance.config.modules.monitor, - (void*) &instance.config.modules.mouse, + (FFModuleBaseInfo*) &instance.config.modules.media, + (FFModuleBaseInfo*) &instance.config.modules.memory, + (FFModuleBaseInfo*) &instance.config.modules.monitor, + (FFModuleBaseInfo*) &instance.config.modules.mouse, NULL, }; static FFModuleBaseInfo* N[] = { - (void*) &instance.config.modules.netIo, + (FFModuleBaseInfo*) &instance.config.modules.netIo, NULL, }; static FFModuleBaseInfo* O[] = { - (void*) &instance.config.modules.openCL, - (void*) &instance.config.modules.openGL, - (void*) &instance.config.modules.os, + (FFModuleBaseInfo*) &instance.config.modules.openCL, + (FFModuleBaseInfo*) &instance.config.modules.openGL, + (FFModuleBaseInfo*) &instance.config.modules.os, NULL, }; static FFModuleBaseInfo* P[] = { - (void*) &instance.config.modules.packages, - (void*) &instance.config.modules.physicalDisk, - (void*) &instance.config.modules.physicalMemory, - (void*) &instance.config.modules.player, - (void*) &instance.config.modules.powerAdapter, - (void*) &instance.config.modules.processes, - (void*) &instance.config.modules.publicIP, + (FFModuleBaseInfo*) &instance.config.modules.packages, + (FFModuleBaseInfo*) &instance.config.modules.physicalDisk, + (FFModuleBaseInfo*) &instance.config.modules.physicalMemory, + (FFModuleBaseInfo*) &instance.config.modules.player, + (FFModuleBaseInfo*) &instance.config.modules.powerAdapter, + (FFModuleBaseInfo*) &instance.config.modules.processes, + (FFModuleBaseInfo*) &instance.config.modules.publicIP, NULL, }; @@ -125,42 +125,42 @@ static FFModuleBaseInfo* R[] = { }; static FFModuleBaseInfo* S[] = { - (void*) &instance.config.modules.separator, - (void*) &instance.config.modules.shell, - (void*) &instance.config.modules.sound, - (void*) &instance.config.modules.swap, + (FFModuleBaseInfo*) &instance.config.modules.separator, + (FFModuleBaseInfo*) &instance.config.modules.shell, + (FFModuleBaseInfo*) &instance.config.modules.sound, + (FFModuleBaseInfo*) &instance.config.modules.swap, NULL, }; static FFModuleBaseInfo* T[] = { - (void*) &instance.config.modules.terminal, - (void*) &instance.config.modules.terminalFont, - (void*) &instance.config.modules.terminalSize, - (void*) &instance.config.modules.terminalTheme, - (void*) &instance.config.modules.title, - (void*) &instance.config.modules.theme, - (void*) &instance.config.modules.tpm, + (FFModuleBaseInfo*) &instance.config.modules.terminal, + (FFModuleBaseInfo*) &instance.config.modules.terminalFont, + (FFModuleBaseInfo*) &instance.config.modules.terminalSize, + (FFModuleBaseInfo*) &instance.config.modules.terminalTheme, + (FFModuleBaseInfo*) &instance.config.modules.title, + (FFModuleBaseInfo*) &instance.config.modules.theme, + (FFModuleBaseInfo*) &instance.config.modules.tpm, NULL, }; static FFModuleBaseInfo* U[] = { - (void*) &instance.config.modules.uptime, - (void*) &instance.config.modules.users, + (FFModuleBaseInfo*) &instance.config.modules.uptime, + (FFModuleBaseInfo*) &instance.config.modules.users, NULL, }; static FFModuleBaseInfo* V[] = { - (void*) &instance.config.modules.version, - (void*) &instance.config.modules.vulkan, + (FFModuleBaseInfo*) &instance.config.modules.version, + (FFModuleBaseInfo*) &instance.config.modules.vulkan, NULL, }; static FFModuleBaseInfo* W[] = { - (void*) &instance.config.modules.wallpaper, - (void*) &instance.config.modules.weather, - (void*) &instance.config.modules.wm, - (void*) &instance.config.modules.wifi, - (void*) &instance.config.modules.wmTheme, + (FFModuleBaseInfo*) &instance.config.modules.wallpaper, + (FFModuleBaseInfo*) &instance.config.modules.weather, + (FFModuleBaseInfo*) &instance.config.modules.wm, + (FFModuleBaseInfo*) &instance.config.modules.wifi, + (FFModuleBaseInfo*) &instance.config.modules.wmTheme, NULL, }; @@ -173,7 +173,7 @@ static FFModuleBaseInfo* Y[] = { }; static FFModuleBaseInfo* Z[] = { - (void*) &instance.config.modules.zpool, + (FFModuleBaseInfo*) &instance.config.modules.zpool, NULL, }; diff --git a/src/common/parsing.c b/src/common/parsing.c index 50f1a54aa..dce4cef02 100644 --- a/src/common/parsing.c +++ b/src/common/parsing.c @@ -72,7 +72,7 @@ static void parseSize(FFstrbuf* result, uint64_t bytes, uint32_t base, const cha } if(counter == 0) - ffStrbufAppendF(result, "%"PRIu64" %s", bytes, prefixes[0]); + ffStrbufAppendF(result, "%" PRIu64 " %s", bytes, prefixes[0]); else ffStrbufAppendF(result, "%.*f %s", instance.config.display.sizeNdigits, size, prefixes[counter]); } diff --git a/src/detection/bootmgr/bootmgr.c b/src/detection/bootmgr/bootmgr.c index 9d4dfa838..47c9a418a 100644 --- a/src/detection/bootmgr/bootmgr.c +++ b/src/detection/bootmgr/bootmgr.c @@ -34,9 +34,9 @@ bool ffEfiFillLoadOption(const FFEfiLoadOption* efiOption, FFBootmgrResult* resu ffEfiUcs2ToUtf8(efiOption->Description, &result->name); for ( - ffEfiDevicePathProtocol* filePathList = (void*) &efiOption->Description[descLen + 1]; + ffEfiDevicePathProtocol* filePathList = (ffEfiDevicePathProtocol*) &efiOption->Description[descLen + 1]; filePathList->Type != 0x7F; // End of Hardware Device Path - filePathList = (void*) ((uint8_t*) filePathList + filePathList->Length)) + filePathList = (ffEfiDevicePathProtocol*) ((uint8_t*) filePathList + filePathList->Length)) { if (filePathList->Type == 4 && filePathList->SubType == 4) { diff --git a/src/detection/cpuusage/cpuusage.c b/src/detection/cpuusage/cpuusage.c index f6cfd37ce..d89c54919 100644 --- a/src/detection/cpuusage/cpuusage.c +++ b/src/detection/cpuusage/cpuusage.c @@ -36,8 +36,8 @@ retry: for (uint32_t i = 0; i < cpuTimes1.length; ++i) { - FFCpuUsageInfo* cpuTime1 = ffListGet(&cpuTimes1, i); - FFCpuUsageInfo* cpuTime2 = ffListGet(&cpuTimes2, i); + FFCpuUsageInfo* cpuTime1 = FF_LIST_GET(FFCpuUsageInfo, cpuTimes1, i); + FFCpuUsageInfo* cpuTime2 = FF_LIST_GET(FFCpuUsageInfo, cpuTimes2, i); if (cpuTime2->totalAll <= cpuTime1->totalAll) { if (++retryCount <= 3) @@ -51,8 +51,8 @@ retry: for (uint32_t i = 0; i < cpuTimes1.length; ++i) { - FFCpuUsageInfo* cpuTime1 = ffListGet(&cpuTimes1, i); - FFCpuUsageInfo* cpuTime2 = ffListGet(&cpuTimes2, i); + FFCpuUsageInfo* cpuTime1 = FF_LIST_GET(FFCpuUsageInfo, cpuTimes1, i); + FFCpuUsageInfo* cpuTime2 = FF_LIST_GET(FFCpuUsageInfo, cpuTimes2, i); *(double*) ffListAdd(result) = (double)(cpuTime2->inUseAll - cpuTime1->inUseAll) / (double)(cpuTime2->totalAll - cpuTime1->totalAll) * 100; cpuTime1->inUseAll = cpuTime2->inUseAll; cpuTime1->totalAll = cpuTime2->totalAll; diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index 41600e7ef..4480d4d23 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -176,7 +176,7 @@ static bool isSubvolume(const FFlist* disks, FFDisk* currentDisk) FF_STRBUF_AUTO_DESTROY zpoolName = ffStrbufCreateNS(index, currentDisk->mountFrom.chars); for(uint32_t i = 0; i < disks->length - 1; i++) { - const FFDisk* otherDevice = ffListGet(disks, i); + const FFDisk* otherDevice = FF_LIST_GET(FFDisk, *disks, i); if(ffStrbufEqualS(&otherDevice->filesystem, "zfs") && ffStrbufStartsWith(&otherDevice->mountFrom, &zpoolName)) return true; } @@ -188,7 +188,7 @@ static bool isSubvolume(const FFlist* disks, FFDisk* currentDisk) //Filter all disks which device was already found. This catches BTRFS subvolumes. for(uint32_t i = 0; i < disks->length - 1; i++) { - const FFDisk* otherDevice = ffListGet(disks, i); + const FFDisk* otherDevice = FF_LIST_GET(FFDisk, *disks, i); if(ffStrbufEqual(¤tDisk->mountFrom, &otherDevice->mountFrom)) return true; diff --git a/src/detection/disk/disk_sunos.c b/src/detection/disk/disk_sunos.c index e2d6d714e..af19d74d4 100644 --- a/src/detection/disk/disk_sunos.c +++ b/src/detection/disk/disk_sunos.c @@ -48,7 +48,7 @@ static bool isSubvolume(const FFlist* disks, FFDisk* currentDisk) FF_STRBUF_AUTO_DESTROY zpoolName = ffStrbufCreateNS(index, currentDisk->mountFrom.chars); for(uint32_t i = 0; i < disks->length - 1; i++) { - const FFDisk* otherDevice = ffListGet(disks, i); + const FFDisk* otherDevice = FF_LIST_GET(FFDisk, *disks, i); if(ffStrbufEqualS(&otherDevice->filesystem, "zfs") && ffStrbufStartsWith(&otherDevice->mountFrom, &zpoolName)) return true; } @@ -60,7 +60,7 @@ static bool isSubvolume(const FFlist* disks, FFDisk* currentDisk) //Filter all disks which device was already found. This catches BTRFS subvolumes. for(uint32_t i = 0; i < disks->length - 1; i++) { - const FFDisk* otherDevice = ffListGet(disks, i); + const FFDisk* otherDevice = FF_LIST_GET(FFDisk, *disks, i); if(ffStrbufEqual(¤tDisk->mountFrom, &otherDevice->mountFrom)) return true; diff --git a/src/detection/diskio/diskio.c b/src/detection/diskio/diskio.c index 4c129d794..1677c5cf2 100644 --- a/src/detection/diskio/diskio.c +++ b/src/detection/diskio/diskio.c @@ -56,8 +56,8 @@ const char* ffDetectDiskIO(FFlist* result, FFDiskIOOptions* options) for (uint32_t i = 0; i < result->length; ++i) { - FFDiskIOResult* icPrev = (FFDiskIOResult*)ffListGet(&ioCounters1, i); - FFDiskIOResult* icCurr = (FFDiskIOResult*)ffListGet(result, i); + FFDiskIOResult* icPrev = FF_LIST_GET(FFDiskIOResult, ioCounters1, i); + FFDiskIOResult* icCurr = FF_LIST_GET(FFDiskIOResult, *result, i); if (!ffStrbufEqual(&icPrev->devPath, &icCurr->devPath)) return "Physical disk device path changed"; diff --git a/src/detection/displayserver/displayserver.c b/src/detection/displayserver/displayserver.c index 235c00dc2..c2ba3e593 100644 --- a/src/detection/displayserver/displayserver.c +++ b/src/detection/displayserver/displayserver.c @@ -19,7 +19,7 @@ FFDisplayResult* ffdsAppendDisplay( if(width == 0 || height == 0) return NULL; - FFDisplayResult* display = ffListAdd(&result->displays); + FFDisplayResult* display = (FFDisplayResult*) ffListAdd(&result->displays); display->width = width; display->height = height; display->refreshRate = refreshRate; diff --git a/src/detection/netio/netio.c b/src/detection/netio/netio.c index bcb64bca0..0c4084388 100644 --- a/src/detection/netio/netio.c +++ b/src/detection/netio/netio.c @@ -56,8 +56,8 @@ const char* ffDetectNetIO(FFlist* result, FFNetIOOptions* options) for (uint32_t i = 0; i < result->length; ++i) { - FFNetIOResult* icPrev = (FFNetIOResult*)ffListGet(&ioCounters1, i); - FFNetIOResult* icCurr = (FFNetIOResult*)ffListGet(result, i); + FFNetIOResult* icPrev = FF_LIST_GET(FFNetIOResult, ioCounters1, i); + FFNetIOResult* icCurr = FF_LIST_GET(FFNetIOResult, *result, i); if (!ffStrbufEqual(&icPrev->name, &icCurr->name)) return "Network interface name changed"; diff --git a/src/fastfetch.c b/src/fastfetch.c index 8be2ab211..07acf68a5 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -370,7 +370,7 @@ static void generateConfigFile(bool force, const char* filePath) { if (!filePath) { - ffStrbufSet(&instance.state.genConfigPath, (FFstrbuf*) ffListGet(&instance.state.platform.configDirs, 0)); + ffStrbufSet(&instance.state.genConfigPath, FF_LIST_GET(FFstrbuf, instance.state.platform.configDirs, 0)); ffStrbufAppendS(&instance.state.genConfigPath, "fastfetch/config.jsonc"); } else diff --git a/src/fastfetch.h b/src/fastfetch.h index ae9d0657f..a95ab7501 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -27,11 +27,11 @@ #ifdef __has_builtin #if __has_builtin(__builtin_types_compatible_p) - #define ARRAY_SIZE(x) ({ static_assert(!__builtin_types_compatible_p(__typeof__(x), __typeof__(&*(x))), "Must not be a pointer"); sizeof(x) / sizeof(*(x)); }) + #define ARRAY_SIZE(x) ({ static_assert(!__builtin_types_compatible_p(__typeof__(x), __typeof__(&*(x))), "Must not be a pointer"); (uint32_t) (sizeof(x) / sizeof(*(x))); }) #endif #endif #ifndef ARRAY_SIZE - #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) + #define ARRAY_SIZE(x) ((uint32_t) (sizeof(x) / sizeof(*(x)))) #endif diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index a6bca3bce..b00ff013c 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -74,7 +74,7 @@ void ffPrintBluetooth(FFBluetoothOptions* options) for(uint32_t i = 0; i < filtered.length; i++) { uint8_t index = (uint8_t) (filtered.length == 1 ? 0 : i + 1); - printDevice(options, *(FFBluetoothResult**)ffListGet(&filtered, i), index); + printDevice(options, *FF_LIST_GET(FFBluetoothResult*, filtered, i), index); } } diff --git a/src/modules/display/display.c b/src/modules/display/display.c index e845ff164..98255ed46 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -75,7 +75,7 @@ void ffPrintDisplay(FFDisplayOptions* options) for(uint32_t i = 0; i < dsResult->displays.length; i++) { - FFDisplayResult* result = ffListGet(&dsResult->displays, i); + FFDisplayResult* result = FF_LIST_GET(FFDisplayResult, dsResult->displays, i); uint32_t moduleIndex = dsResult->displays.length == 1 ? 0 : i + 1; const char* displayType = result->type == FF_DISPLAY_TYPE_UNKNOWN ? NULL : result->type == FF_DISPLAY_TYPE_BUILTIN ? "built-in" : "external"; diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index 1d449d33a..57a7b9a8a 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -133,7 +133,7 @@ void ffPrintGPU(FFGPUOptions* options) } for(uint32_t i = 0; i < selectedGPUs.length; i++) - printGPUResult(options, selectedGPUs.length == 1 ? 0 : (uint8_t) (i + 1), * (const FFGPUResult**) ffListGet(&selectedGPUs, i)); + printGPUResult(options, selectedGPUs.length == 1 ? 0 : (uint8_t) (i + 1), *FF_LIST_GET(const FFGPUResult*, selectedGPUs, i)); if(selectedGPUs.length == 0) ffPrintError(FF_GPU_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No GPUs found"); diff --git a/src/modules/poweradapter/poweradapter.c b/src/modules/poweradapter/poweradapter.c index 3445f7c35..76745e6e1 100644 --- a/src/modules/poweradapter/poweradapter.c +++ b/src/modules/poweradapter/poweradapter.c @@ -25,7 +25,7 @@ void ffPrintPowerAdapter(FFPowerAdapterOptions* options) { for(uint8_t i = 0; i < (uint8_t) results.length; i++) { - FFPowerAdapterResult* result = ffListGet(&results, i); + FFPowerAdapterResult* result = FF_LIST_GET(FFPowerAdapterResult, results, i); if(options->moduleArgs.outputFormat.length == 0) { diff --git a/src/modules/users/users.c b/src/modules/users/users.c index 3c7db48e0..7be21109b 100644 --- a/src/modules/users/users.c +++ b/src/modules/users/users.c @@ -38,7 +38,7 @@ void ffPrintUsers(FFUsersOptions* options) { if(i > 0) ffStrbufAppendS(&result, ", "); - FFUserResult* user = (FFUserResult*)ffListGet(&users, i); + FFUserResult* user = FF_LIST_GET(FFUserResult, users, i); ffStrbufAppend(&result, &user->name); } ffStrbufPutTo(&result, stdout); @@ -47,7 +47,7 @@ void ffPrintUsers(FFUsersOptions* options) { for(uint32_t i = 0; i < users.length; ++i) { - FFUserResult* user = (FFUserResult*)ffListGet(&users, i); + FFUserResult* user = FF_LIST_GET(FFUserResult, users, i); ffPrintLogoAndKey(FF_USERS_MODULE_NAME, users.length == 1 ? 0 : (uint8_t) (i + 1), &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); @@ -66,7 +66,7 @@ void ffPrintUsers(FFUsersOptions* options) { for(uint32_t i = 0; i < users.length; ++i) { - FFUserResult* user = (FFUserResult*)ffListGet(&users, i); + FFUserResult* user = FF_LIST_GET(FFUserResult, users, i); FF_PRINT_FORMAT_CHECKED(FF_USERS_MODULE_NAME, users.length == 1 ? 0 : (uint8_t) (i + 1), &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, FF_USERS_NUM_FORMAT_ARGS, ((FFformatarg[]){ FF_FORMAT_ARG(user->name, "name"), diff --git a/src/modules/wifi/wifi.c b/src/modules/wifi/wifi.c index ace8340a1..d000c7e6b 100644 --- a/src/modules/wifi/wifi.c +++ b/src/modules/wifi/wifi.c @@ -24,7 +24,7 @@ void ffPrintWifi(FFWifiOptions* options) for(uint32_t index = 0; index < result.length; ++index) { - FFWifiResult* item = (FFWifiResult*)ffListGet(&result, index); + FFWifiResult* item = FF_LIST_GET(FFWifiResult, result, index); uint8_t moduleIndex = result.length == 1 ? 0 : (uint8_t)(index + 1); if(options->moduleArgs.outputFormat.length == 0) diff --git a/src/util/FFlist.c b/src/util/FFlist.c index 59f5a8b56..e640f507e 100644 --- a/src/util/FFlist.c +++ b/src/util/FFlist.c @@ -3,14 +3,6 @@ #include #include -void ffListInitA(FFlist* list, uint32_t elementSize, uint32_t capacity) -{ - list->elementSize = elementSize; - list->capacity = capacity; - list->length = 0; - list->data = capacity == 0 ? NULL : malloc((size_t)list->capacity * list->elementSize); -} - void* ffListAdd(FFlist* list) { if(list->length == list->capacity) @@ -24,17 +16,6 @@ void* ffListAdd(FFlist* list) return ffListGet(list, list->length - 1); } -uint32_t ffListFirstIndexComp(const FFlist* list, void* compElement, bool(*compFunc)(const void*, const void*)) -{ - for(uint32_t i = 0; i < list->length; i++) - { - if(compFunc(ffListGet(list, i), compElement)) - return i; - } - - return list->length; -} - bool ffListShift(FFlist* list, void* result) { if(list->length == 0) diff --git a/src/util/FFlist.h b/src/util/FFlist.h index c3fd451e5..a4b2f64c4 100644 --- a/src/util/FFlist.h +++ b/src/util/FFlist.h @@ -17,12 +17,8 @@ typedef struct FFlist uint32_t capacity; } FFlist; -void ffListInitA(FFlist* list, uint32_t elementSize, uint32_t capacity); - void* ffListAdd(FFlist* list); -FF_C_NODISCARD uint32_t ffListFirstIndexComp(const FFlist* list, void* compElement, bool(*compFunc)(const void*, const void*)); - // Removes the first element, and copy its value to `*result` bool ffListShift(FFlist* list, void* result); // Removes the last element, and copy its value to `*result` @@ -37,6 +33,13 @@ static inline void ffListInit(FFlist* list, uint32_t elementSize) list->data = NULL; } +static inline void ffListInitA(FFlist* list, uint32_t elementSize, uint32_t capacity) +{ + ffListInit(list, elementSize); + list->capacity = capacity; + list->data = __builtin_expect(capacity == 0, 0) ? NULL : (char*) malloc((size_t)list->capacity * list->elementSize); +} + static inline FFlist ffListCreate(uint32_t elementSize) { FFlist result; @@ -50,6 +53,17 @@ static inline void* ffListGet(const FFlist* list, uint32_t index) return list->data + (index * list->elementSize); } +FF_C_NODISCARD static inline uint32_t ffListFirstIndexComp(const FFlist* list, void* compElement, bool(*compFunc)(const void*, const void*)) +{ + for(uint32_t i = 0; i < list->length; i++) + { + if(compFunc(ffListGet(list, i), compElement)) + return i; + } + + return list->length; +} + static inline bool ffListContains(const FFlist* list, void* compElement, bool(*compFunc)(const void*, const void*)) { return ffListFirstIndexComp(list, compElement, compFunc) != list->length; From 20f9ff9baec5f801da83a2dfe6b74929707def42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 26 Oct 2024 11:39:31 +0800 Subject: [PATCH 08/72] Logo (Builtin): update OpenSuse Tumbleweed Fix #1357 --- src/logo/ascii/opensuse_tumbleweed.txt | 34 +++++++++++++--------- src/logo/ascii/opensuse_tumbleweed_old.txt | 13 +++++++++ src/logo/builtin.c | 13 ++++++++- 3 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 src/logo/ascii/opensuse_tumbleweed_old.txt diff --git a/src/logo/ascii/opensuse_tumbleweed.txt b/src/logo/ascii/opensuse_tumbleweed.txt index fefdeee4a..bf857a76a 100644 --- a/src/logo/ascii/opensuse_tumbleweed.txt +++ b/src/logo/ascii/opensuse_tumbleweed.txt @@ -1,13 +1,21 @@ - ...... - .,cdxxxoc,. .:kKMMMNWMMMNk:. - cKMMN0OOOKWMMXo. A ;0MWk:' ':OMMk. - ;WMK;' 'lKMMNM, :NMK' 'OMW; - cMW; WMMMN ,XMK' oMM. -.MMc ''^*~l. xMN: KM0 -'MM. .NMO oMM -.MM, .kMMl xMN - KM0 .kMM0' .dl>~,. .WMd - 'XM0. ,OMMK' OMMM7' .XMK - *WMO:. .;xNMMk' NNNMKl. .xWMx - ^ONMMNXMMMKx; V 'xNMWKkxllox0NMWk' - ''''' ':dOOXXKOxl' \ No newline at end of file + .,:looooooc;. + ,ool oo,;oo: + .lo' oo. oo: + oo. oo. oo: +:ol oo. 'oo +:oo .oo. .oo. +.oooooooooooooo. .oo. + ;oo. .oo. + oo, .oo. + .ooc,'..........:ooc.......... + .cooooooooooooooooooooooooool;. + .oo. .oo; + .oo. .oo. + .oo. oooooooooo:ooo. + .oo. .oo. col + oo' .oo col + coo .oo oo' + coc .oo lo, + .oo, .oo .:oo + .oooooc,,,:lol + ,clc' \ No newline at end of file diff --git a/src/logo/ascii/opensuse_tumbleweed_old.txt b/src/logo/ascii/opensuse_tumbleweed_old.txt new file mode 100644 index 000000000..fefdeee4a --- /dev/null +++ b/src/logo/ascii/opensuse_tumbleweed_old.txt @@ -0,0 +1,13 @@ + ...... + .,cdxxxoc,. .:kKMMMNWMMMNk:. + cKMMN0OOOKWMMXo. A ;0MWk:' ':OMMk. + ;WMK;' 'lKMMNM, :NMK' 'OMW; + cMW; WMMMN ,XMK' oMM. +.MMc ''^*~l. xMN: KM0 +'MM. .NMO oMM +.MM, .kMMl xMN + KM0 .kMM0' .dl>~,. .WMd + 'XM0. ,OMMK' OMMM7' .XMK + *WMO:. .;xNMMk' NNNMKl. .xWMx + ^ONMMNXMMMKx; V 'xNMWKkxllox0NMWk' + ''''' ':dOOXXKOxl' \ No newline at end of file diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 7ef6ce8fb..7b9198f4d 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -3206,7 +3206,7 @@ static const FFlogo O[] = { }, // OpenSuseTumbleweed { - .names = {"opensuse_tumbleweed", "open_suse_tumbleweed", "opensuse-tumbleweed", "open-suse-tumbleweed", "suse_tumbleweed", "suse-tumbleweed", "opensusetumbleweed"}, + .names = {"opensuse-tumbleweed", "opensuse_tumbleweed"}, .lines = FASTFETCH_DATATEXT_LOGO_OPENSUSE_TUMBLEWEED, .colors = { FF_COLOR_FG_WHITE, @@ -3214,6 +3214,17 @@ static const FFlogo O[] = { .colorKeys = FF_COLOR_FG_GREEN, .colorTitle = FF_COLOR_FG_GREEN, }, + // OpenSuseTumbleweedOld + { + .names = {"opensuse-tumbleweed-old", "opensuse_tumbleweed-old"}, + .lines = FASTFETCH_DATATEXT_LOGO_OPENSUSE_TUMBLEWEED_OLD, + .type = FF_LOGO_LINE_TYPE_ALTER_BIT, + .colors = { + FF_COLOR_FG_WHITE, + }, + .colorKeys = FF_COLOR_FG_GREEN, + .colorTitle = FF_COLOR_FG_GREEN, + }, // openSUSESlowroll { .names = {"opensuse_slowroll", "opensuse-slowroll", "opensuse-tumbleweed-slowroll"}, From 2dc8ac6a515352c5c6cb0bffa6ed3667d5f18aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 26 Oct 2024 22:27:09 +0800 Subject: [PATCH 09/72] Logo (Builtin): add XCP-ng Fix #1359 --- src/logo/ascii/xcp_ng.txt | 15 +++++++++++++++ src/logo/builtin.c | 13 +++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/logo/ascii/xcp_ng.txt diff --git a/src/logo/ascii/xcp_ng.txt b/src/logo/ascii/xcp_ng.txt new file mode 100644 index 000000000..4d33560b8 --- /dev/null +++ b/src/logo/ascii/xcp_ng.txt @@ -0,0 +1,15 @@ + ${c3}%${c4}# + ${c1}((((${c3}%%%%%${c4}&& + ${c1}#((((((((((${c4}&&&& + ${c1}(((((((((((${c2}#####${c4}&& + ${c1}(((((${c5}%.....${c2}%####### + ${c1}(((( ((((((${c5}%.......${c2}%####, + ${c1}%((((((& ((((((((${c5}%.....${c2}%#### + ${c1}((((((((((((((${c2}########### + ${c1}(((( (((((((${c2}########### + ${c1}( /((((${c2}########### + ${c6},,*..${c2}########## + ${c6},,,******${c2}## ###### + ${c6},,,*,,,, ${c2}## ###### +${c6}. .,,,, ${c2}### ## + ${c6}... \ No newline at end of file diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 7b9198f4d..c5c02bdee 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -4821,6 +4821,19 @@ static const FFlogo X[] = { FF_COLOR_FG_RED, } }, + // XCP-ng + { + .names = {"XCP-ng", "xenenterprise"}, + .lines = FASTFETCH_DATATEXT_LOGO_XCP_NG, + .colors = { + FF_COLOR_FG_RED, + FF_COLOR_FG_RED, + FF_COLOR_FG_BLACK, + FF_COLOR_FG_BLACK, + FF_COLOR_FG_BLUE, + FF_COLOR_FG_YELLOW, + } + }, // Xferience { .names = {"Xferience"}, From 26920d49f5ac70bfa64ef41cda65b745ed8e78ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 26 Oct 2024 22:45:32 +0800 Subject: [PATCH 10/72] Logo (Builtin): add SummitOS Fix #1352 --- src/logo/ascii/summitos.txt | 22 ++++++++++++++++++++++ src/logo/builtin.c | 10 ++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/logo/ascii/summitos.txt diff --git a/src/logo/ascii/summitos.txt b/src/logo/ascii/summitos.txt new file mode 100644 index 000000000..ff875cb27 --- /dev/null +++ b/src/logo/ascii/summitos.txt @@ -0,0 +1,22 @@ + :~^ + ~5PPJ + :5555P7 + .Y55555P~ + ?P5555555^ + 7P55555555Y. + ~5555555555PJ$2 7YJ^ + $1^555555555555P7$2 7GGGP^ + $1.Y5555555555555P!$2 ~PPPPP5. + $1JP555555555555555^$2 ^PPPPPPGY + $17P5555555555555555Y$2^5PPPPPPPG? + $1~P55555555555555555$2^PPPPPPPPPPP! + $1^555555555555555555$2^PPPPPPPPPPPPP^ + $1.Y555555555555P$3G$1P55$2^PPPPPPPPPPPPPP5: + $1JP55555555555P$3GGG$1P$2^PPPPPPPPPPPPPPPGY + $17P555555555555$3GGGGG$2PPPPPPPPPPPPPPPPPG? + $1!P555555555555$3GGGGGGG$2PPPPPPPPPPPPPPPPPG! + $1^5555555555555$3PGGGGGGGG$2PPPPPPPPPPPPPPPPPP^ + $1:Y555555555555$3PGGGGGGGGGG$2PPPPPPPPPPPPPPPPP5: +$1.JP55555555555$3PGGGGGGGGGGGG$2PPPPPPPPPPPPPPPPGY. +$1?PPPPPPPPPPPP$3GGBBBBBBBBBBBBB$2GGGGGGGGGGGGGGGGGJ +$1^~~~~~~~~~~~$3!!!!!!!!!!!!!!!!!$2!!!!!!!!!!!!!!!!~ diff --git a/src/logo/builtin.c b/src/logo/builtin.c index c5c02bdee..545e92e42 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -4262,6 +4262,16 @@ static const FFlogo S[] = { FF_COLOR_FG_WHITE, }, }, + // SummitOS + { + .names = {"SummitOS"}, + .lines = FASTFETCH_DATATEXT_LOGO_SUMMITOS, + .colors = { + FF_COLOR_FG_RGB "143;191;80", + FF_COLOR_FG_RGB "160;205;102", + FF_COLOR_FG_RGB "181;225;102", + }, + }, // Suse { .names = {"suse", "suse-linux"}, From 2fe6e60d98f01eaf8abed720ea44c835d6c238ae Mon Sep 17 00:00:00 2001 From: ferrreo Date: Sun, 27 Oct 2024 01:40:49 +0000 Subject: [PATCH 11/72] Logo (Builtin): update PikaOS (#1361) --- src/logo/ascii/pikaos.txt | 46 +++++++++++++++------------------------ 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/logo/ascii/pikaos.txt b/src/logo/ascii/pikaos.txt index ea477a258..ae19ee461 100644 --- a/src/logo/ascii/pikaos.txt +++ b/src/logo/ascii/pikaos.txt @@ -1,28 +1,18 @@ - '',,, ,,,d, - ',, ,,' - ', ,. - ., ' - . . - ' . - .. oddddkdlc:;,.. .. - . ............lllc, . - . ....................: . - . . .................... - '. ..........'o........d0XX0. - ....lllllllcOOOcllllll............cxlxc...;okkkx. - ..................................';lc'...lo. - .'''''''''''''.....................,;,....... - ',,,,,,,,,,,,,,,,''...............dkkkd...... - ',,,,,,,,,,,,,,,,,,,'............;okkkd;.... - .,,,,,,,,,,,,,,,,,,,,,............;cll;..... - ,,,,,,,,,,,,,,,,,,,,'....................:d, - ,,,,,,,,,,,,,,,,,,,....................oxxx: - .,,,,,,,,,,,,,,,,,'..................oxxxxx. . - .,,,,,,,,,,,,,,'.......... ,oxxxxxxx . - .;,,,,,,,,,,,,'.. 'cxxxxxxxxx, - :dl:,'',,'.... .;lxxxxxxxxxd; - ,codol:;'. ...,;cldxxxxxxxxxoc. - .:cxxxxxdlccccc:ccldxxxxxxxxxxxxxx::. - .'::dxxxxxxxxxxxxxxxxxxxxxxxd::'. - ..,::cdxxxxxxxxxxxxxdc::,.. - ...,;:::::::;,... \ No newline at end of file + - + ---------------- + ------------------ + ------------------- + -- -----------=*-=----##### + -----------------------------####--=###### + ------------------------------++---+#### + =============----------------=+=----- + =================-----------####+---- + ==================----------*###=---- + ===================----------------- + ==================----------------- + =================---------------- + ===============------------:::: + ============-::::::::::::::: + =======--::::::::::::::: + .::::::::::::::::. + ::::::: \ No newline at end of file From 4665fdd1459a3ac769e987b50160283678a99fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 27 Oct 2024 11:43:36 +0800 Subject: [PATCH 12/72] Global: make it compile on NetBSD Doesn't work yet. --- .gitignore | 1 + CMakeLists.txt | 87 +++++++++++++++++++ src/common/init.c | 2 +- src/common/processing_linux.c | 55 ++++++++++-- src/detection/bios/bios_nbsd.c | 15 ++++ src/detection/board/board_nbsd.c | 15 ++++ src/detection/chassis/chassis_nbsd.c | 15 ++++ src/detection/cpu/cpu_bsd.c | 7 +- src/detection/host/host_nbsd.c | 17 ++++ src/detection/loadavg/loadavg_bsd.c | 2 +- src/detection/localip/localip_linux.c | 8 +- src/detection/memory/memory_bsd.c | 8 +- src/detection/os/os_nbsd.c | 7 ++ src/detection/processes/processes_nosupport.c | 6 ++ src/detection/terminalshell/terminalshell.c | 8 +- .../terminalshell/terminalshell_linux.c | 4 +- src/options/general.c | 6 +- src/options/general.h | 2 +- src/util/binary_linux.c | 2 +- src/util/platform/FFPlatform_unix.c | 12 ++- 20 files changed, 252 insertions(+), 27 deletions(-) create mode 100644 src/detection/bios/bios_nbsd.c create mode 100644 src/detection/board/board_nbsd.c create mode 100644 src/detection/chassis/chassis_nbsd.c create mode 100644 src/detection/host/host_nbsd.c create mode 100644 src/detection/os/os_nbsd.c create mode 100644 src/detection/processes/processes_nosupport.c diff --git a/.gitignore b/.gitignore index 2d69a508f..35828e870 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ tags fastfetch.kdev4 *.user *.user.* +*.swp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e5cfede6..c3d69a628 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,8 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") set(FreeBSD TRUE CACHE BOOL "..." FORCE) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD") set(OpenBSD TRUE CACHE BOOL "..." FORCE) +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "NetBSD") + set(NetBSD TRUE CACHE BOOL "..." FORCE) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") set(SunOS TRUE CACHE BOOL "..." FORCE) elseif(NOT APPLE AND NOT WIN32) @@ -663,6 +665,88 @@ elseif(FreeBSD) src/util/platform/FFPlatform_unix.c src/util/binary_linux.c ) +elseif(NetBSD) + list(APPEND LIBFASTFETCH_SRC + src/common/dbus.c + src/common/io/io_unix.c + src/common/netif/netif_bsd.c + src/common/networking_linux.c + src/common/processing_linux.c + src/common/sysctl.c + src/detection/battery/battery_nosupport.c + src/detection/bios/bios_nbsd.c + src/detection/bluetooth/bluetooth_linux.c + src/detection/bluetoothradio/bluetoothradio_linux.c + src/detection/board/board_nbsd.c + src/detection/bootmgr/bootmgr_nosupport.c + src/detection/brightness/brightness_bsd.c + src/detection/btrfs/btrfs_nosupport.c + src/detection/chassis/chassis_nbsd.c + src/detection/cpu/cpu_bsd.c + src/detection/cpucache/cpucache_nosupport.c + src/detection/cpuusage/cpuusage_nosupport.c + src/detection/cursor/cursor_linux.c + src/detection/disk/disk_nosupport.c + src/detection/dns/dns_linux.c + src/detection/physicaldisk/physicaldisk_nosupport.c + src/detection/physicalmemory/physicalmemory_nosupport.c + src/detection/diskio/diskio_nosupport.c + src/detection/displayserver/linux/displayserver_linux.c + src/detection/displayserver/linux/drm.c + src/detection/displayserver/linux/wayland/wayland.c + src/detection/displayserver/linux/wayland/global-output.c + src/detection/displayserver/linux/wayland/zwlr-output.c + src/detection/displayserver/linux/wayland/kde-output.c + src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c + src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c + src/detection/displayserver/linux/wayland/kde-output-order-v1-protocol.c + src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c + src/detection/displayserver/linux/wmde.c + src/detection/displayserver/linux/xcb.c + src/detection/displayserver/linux/xlib.c + src/detection/font/font_linux.c + src/detection/gpu/gpu_nosupport.c + src/detection/gpu/gpu_pci.c + src/detection/gtk_qt/gtk.c + src/detection/host/host_nbsd.c + src/detection/lm/lm_linux.c + src/detection/icons/icons_linux.c + src/detection/initsystem/initsystem_linux.c + src/detection/keyboard/keyboard_nosupport.c + src/detection/libc/libc_nosupport.c + src/detection/loadavg/loadavg_bsd.c + src/detection/locale/locale_linux.c + src/detection/localip/localip_linux.c + src/detection/gamepad/gamepad_nosupport.c + src/detection/media/media_linux.c + src/detection/memory/memory_bsd.c + src/detection/mouse/mouse_nosupport.c + src/detection/netio/netio_nosupport.c + src/detection/opengl/opengl_linux.c + src/detection/os/os_nbsd.c + src/detection/packages/packages_nosupport.c + src/detection/poweradapter/poweradapter_nosupport.c + src/detection/processes/processes_nosupport.c + src/detection/gtk_qt/qt.c + src/detection/sound/sound_nosupport.c + src/detection/swap/swap_nosupport.c + src/detection/terminalfont/terminalfont_linux.c + src/detection/terminalshell/terminalshell_linux.c + src/detection/terminalsize/terminalsize_linux.c + src/detection/theme/theme_linux.c + src/detection/tpm/tpm_nosupport.c + src/detection/uptime/uptime_bsd.c + src/detection/users/users_linux.c + src/detection/wallpaper/wallpaper_linux.c + src/detection/wifi/wifi_nosupport.c + src/detection/wm/wm_nosupport.c + src/detection/de/de_linux.c + src/detection/wmtheme/wmtheme_linux.c + src/detection/camera/camera_linux.c + src/detection/zpool/zpool_linux.c + src/util/platform/FFPlatform_unix.c + src/util/binary_linux.c + ) elseif(OpenBSD) list(APPEND LIBFASTFETCH_SRC src/common/dbus.c @@ -1054,6 +1138,9 @@ elseif(OpenBSD) target_compile_definitions(libfastfetch PUBLIC _XOPEN_SOURCE=700 _FILE_OFFSET_BITS=64 _BSD_SOURCE) elseif(SunOS) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 __EXTENSIONS__ _POSIX_C_SOURCE) +elseif(NetBSD) + target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-char-subscripts") endif() if(HAVE_STATX) diff --git a/src/common/init.c b/src/common/init.c index 643f94a94..96117c66e 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -245,7 +245,7 @@ void ffListFeatures(void) #if FF_HAVE_DDCUTIL "libddcutil\n" #endif - #if FF_HAVE_ELF || __sun || __FreeBSD__ || __OpenBSD__ + #if FF_HAVE_ELF || __sun || __FreeBSD__ || __OpenBSD__ || __NetBSD__ "libelf\n" #endif #if FF_HAVE_LIBZFS diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index 0e6a243ce..b9045bb6c 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -23,9 +23,12 @@ #elif defined(__sun) #include #elif defined(__OpenBSD__) -#include -#include -#include + #include + #include + #include +#elif defined(__NetBSD__) + #include + #include #endif enum { FF_PIPE_BUFSIZ = 8192 }; @@ -202,7 +205,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons } } - #elif defined(__FreeBSD__) + #elif defined(__FreeBSD__) || defined(__NetBSD__) size_t size = ARG_MAX; FF_AUTO_FREE char* args = malloc(size); @@ -210,7 +213,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons static_assert(ARG_MAX > PATH_MAX, ""); if(exePath && sysctl( - (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid}, 4, + (int[]){CTL_KERN, + #if __FreeBSD__ + KERN_PROC, + #else + KERN_PROC_ARGS, + #endif + KERN_PROC_PATHNAME, pid}, 4, args, &size, NULL, 0 ) == 0) @@ -218,7 +227,13 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons size = ARG_MAX; if(sysctl( - (int[]){CTL_KERN, KERN_PROC, KERN_PROC_ARGS, pid}, 4, + (int[]){CTL_KERN, + #if __FreeBSD__ + KERN_PROC, KERN_PROC_ARGS, + #else + KERN_PROC_ARGS, KERN_PROC_ARGV, + #endif + pid}, 4, args, &size, NULL, 0 ) == 0) @@ -378,6 +393,34 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i *tty = -1; } + #elif defined(__NetBSD__) + + struct kinfo_proc2 proc; + size_t size = sizeof(proc); + if(sysctl( + (int[]){CTL_KERN, KERN_PROC2, KERN_PROC_PID, pid}, 4, + &proc, &size, + NULL, 0 + )) + return "sysctl(KERN_PROC_PID) failed"; + + ffStrbufSetS(name, proc.p_comm); + if (ppid) + *ppid = (pid_t)proc.p_ppid; + if (tty) + { + if (proc.p_flag & P_CONTROLT) + { + const char* ttyName = devname(proc.p_tdev, S_IFCHR); + if (ffStrStartsWith(ttyName, "pts/")) + *tty = (int32_t) strtol(ttyName + strlen("pts/"), NULL, 10); + else + *tty = -1; + } + else + *tty = -1; + } + #elif defined(__sun) char path[128]; snprintf(path, sizeof(path), "/proc/%d/psinfo", (int) pid); diff --git a/src/detection/bios/bios_nbsd.c b/src/detection/bios/bios_nbsd.c new file mode 100644 index 000000000..056eb2d41 --- /dev/null +++ b/src/detection/bios/bios_nbsd.c @@ -0,0 +1,15 @@ +#include "bios.h" +#include "common/sysctl.h" +#include "util/smbiosHelper.h" + +const char* ffDetectBios(FFBiosResult* bios) +{ + if (ffSysctlGetString("machdep.dmi.bios-date", &bios->date) == NULL) + ffCleanUpSmbiosValue(&bios->date); + if (ffSysctlGetString("machdep.dmi.bios-version", &bios->version) == NULL) + ffCleanUpSmbiosValue(&bios->version); + if (ffSysctlGetString("machdep.dmi.bios-vendor", &bios->vendor) == NULL) + ffCleanUpSmbiosValue(&bios->vendor); + + return NULL; +} diff --git a/src/detection/board/board_nbsd.c b/src/detection/board/board_nbsd.c new file mode 100644 index 000000000..9557cc339 --- /dev/null +++ b/src/detection/board/board_nbsd.c @@ -0,0 +1,15 @@ +#include "board.h" +#include "common/sysctl.h" +#include "util/smbiosHelper.h" + +const char* ffDetectBoard(FFBoardResult* board) +{ + if (ffSysctlGetString("machdep.dmi.board-product", &board->name) == NULL) + ffCleanUpSmbiosValue(&board->name); + if (ffSysctlGetString("machdep.dmi.board-version", &board->version) == NULL) + ffCleanUpSmbiosValue(&board->version); + if (ffSysctlGetString("machdep.dmi.board-vendor", &board->vendor) == NULL) + ffCleanUpSmbiosValue(&board->vendor); + + return NULL; +} diff --git a/src/detection/chassis/chassis_nbsd.c b/src/detection/chassis/chassis_nbsd.c new file mode 100644 index 000000000..796c241a9 --- /dev/null +++ b/src/detection/chassis/chassis_nbsd.c @@ -0,0 +1,15 @@ +#include "chassis.h" +#include "common/sysctl.h" +#include "util/smbiosHelper.h" + +const char* ffDetectChassis(FFChassisResult* chassis) +{ + if (ffSysctlGetString("machdep.dmi.chassis-type", &chassis->type) == NULL) + ffCleanUpSmbiosValue(&chassis->type); + if (ffSysctlGetString("machdep.dmi.chassis-version", &chassis->version) == NULL) + ffCleanUpSmbiosValue(&chassis->version); + if (ffSysctlGetString("machdep.dmi.chassis-vendor", &chassis->vendor) == NULL) + ffCleanUpSmbiosValue(&chassis->vendor); + + return NULL; +} diff --git a/src/detection/cpu/cpu_bsd.c b/src/detection/cpu/cpu_bsd.c index 961cb8478..7bf464072 100644 --- a/src/detection/cpu/cpu_bsd.c +++ b/src/detection/cpu/cpu_bsd.c @@ -25,8 +25,13 @@ static const char* detectThermalTemp(double* current) const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) { - if (ffSysctlGetString("hw.model", &cpu->name)) + #if __NetBSD__ + if (ffSysctlGetString("machdep.cpu_brand", &cpu->name) != NULL) + return "sysctlbyname(machdep.cpu_brand) failed"; + #else + if (ffSysctlGetString("hw.model", &cpu->name) != NULL) return "sysctlbyname(hw.model) failed"; + #endif cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1); cpu->coresLogical = cpu->coresPhysical; diff --git a/src/detection/host/host_nbsd.c b/src/detection/host/host_nbsd.c new file mode 100644 index 000000000..947198cb6 --- /dev/null +++ b/src/detection/host/host_nbsd.c @@ -0,0 +1,17 @@ +#include "host.h" +#include "common/sysctl.h" +#include "util/smbiosHelper.h" + +const char* ffDetectHost(FFHostResult* host) +{ + const char* error = NULL; + if ((error = ffSysctlGetString("machdep.dmi.system-product", &host->name))) + return error; + ffCleanUpSmbiosValue(&host->name); + if (ffSysctlGetString("machdep.dmi.system-vendor", &host->vendor) == NULL) + ffCleanUpSmbiosValue(&host->vendor); + if (ffSysctlGetString("machdep.dmi.system-version", &host->version) == NULL) + ffCleanUpSmbiosValue(&host->version); + + return NULL; +} diff --git a/src/detection/loadavg/loadavg_bsd.c b/src/detection/loadavg/loadavg_bsd.c index 3a0b6bca5..ca7b17caf 100644 --- a/src/detection/loadavg/loadavg_bsd.c +++ b/src/detection/loadavg/loadavg_bsd.c @@ -2,7 +2,7 @@ #include -#if __FreeBSD__ || __OpenBSD__ +#if __FreeBSD__ || __OpenBSD__ || __NetBSD__ #include #include #if __FreeBSD__ diff --git a/src/detection/localip/localip_linux.c b/src/detection/localip/localip_linux.c index adf5713da..87d4acb2f 100644 --- a/src/detection/localip/localip_linux.c +++ b/src/detection/localip/localip_linux.c @@ -18,7 +18,7 @@ #include #endif -#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__) #include #include #else @@ -52,7 +52,7 @@ static const FFLocalIpNIFlag niFlagOptions[] = { { IFF_DORMANT, "DORMANT" }, { IFF_ECHO, "ECHO" }, #endif -#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) { IFF_OACTIVE, "OACTIVE" }, { IFF_SIMPLEX, "SIMPLEX" }, { IFF_LINK0, "LINK0" }, @@ -190,7 +190,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) addNewIp(results, ifa->ifa_name, addressBuffer, AF_INET6, isDefaultRoute, flags, !(options->showType & FF_LOCALIP_TYPE_ALL_IPS_BIT)); } - #if __FreeBSD__ || __OpenBSD__ || __APPLE__ + #if __FreeBSD__ || __OpenBSD__ || __APPLE__ || __NetBSD__ else if (ifa->ifa_addr->sa_family == AF_LINK) { if (!(options->showType & FF_LOCALIP_TYPE_MAC_BIT)) @@ -246,7 +246,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) ifr.ifr_data = (void*) &edata; if (ioctl(sockfd, SIOCETHTOOL, &ifr) == 0) iface->speed = (edata.speed_hi << 16) | edata.speed; // ethtool_cmd_speed is not available on Android - #elif __FreeBSD__ || __APPLE__ || __OpenBSD__ + #elif __FreeBSD__ || __APPLE__ || __OpenBSD__ || __NetBSD__ struct ifmediareq ifmr = {}; ffStrCopyN(ifmr.ifm_name, iface->name.chars, IFNAMSIZ); if (ioctl(sockfd, SIOCGIFMEDIA, &ifmr) == 0 && (IFM_TYPE(ifmr.ifm_active) & IFM_ETHER)) diff --git a/src/detection/memory/memory_bsd.c b/src/detection/memory/memory_bsd.c index 0db20527a..587ca7f1f 100644 --- a/src/detection/memory/memory_bsd.c +++ b/src/detection/memory/memory_bsd.c @@ -4,7 +4,13 @@ const char* ffDetectMemory(FFMemoryResult* ram) { size_t length = sizeof(ram->bytesTotal); - if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0)) + if (sysctl((int[]){ CTL_HW, +#if __NetBSD__ + HW_PHYSMEM64 +#else + HW_PHYSMEM +#endif + }, 2, &ram->bytesTotal, &length, NULL, 0)) return "Failed to read hw.physmem"; // vm.stats.vm.* are int values diff --git a/src/detection/os/os_nbsd.c b/src/detection/os/os_nbsd.c new file mode 100644 index 000000000..229df96d1 --- /dev/null +++ b/src/detection/os/os_nbsd.c @@ -0,0 +1,7 @@ +#include "os.h" + +void ffDetectOSImpl(FFOSResult* os) +{ + ffStrbufSetStatic(&os->name, "NetBSD"); + ffStrbufSet(&os->version, &instance.state.platform.sysinfo.release); +} diff --git a/src/detection/processes/processes_nosupport.c b/src/detection/processes/processes_nosupport.c new file mode 100644 index 000000000..e1774dd04 --- /dev/null +++ b/src/detection/processes/processes_nosupport.c @@ -0,0 +1,6 @@ +#include "processes.h" + +const char* ffDetectProcesses(uint32_t* result) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index a68e33517..f2d322b79 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -10,6 +10,8 @@ #include #elif __OpenBSD__ #define _PATH_LOCALBASE "/usr/local" +#elif __NetBSD__ + #define _PATH_LOCALBASE "/usr/pkg" #endif #ifdef _WIN32 @@ -121,7 +123,7 @@ static bool getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version) static bool getShellVersionKsh(FFstrbuf* exe, FFstrbuf* version) { -#if __OpenBSD__ +#if __OpenBSD__ || __NetBSD__ if(ffProcessAppendStdOut(version, (char* const[]) { exe->chars, "-c", @@ -575,7 +577,7 @@ static bool getTerminalVersionZed(FFstrbuf* exe, FFstrbuf* version) #ifndef _WIN32 static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version) { - #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) char buffer[1024] = {}; if ( #ifdef __linux__ @@ -678,7 +680,7 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe #endif - #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) if(ffStrbufStartsWithIgnCaseS(processName, "gnome-terminal")) return getTerminalVersionGnome(exe, version); diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index c29d97742..5d63236f8 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -236,7 +236,7 @@ static void getTerminalFromEnv(FFTerminalResult* result) } #endif - #if defined(__linux__) || defined(__FreeBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) //Konsole else if( getenv("KONSOLE_VERSION") != NULL @@ -329,7 +329,7 @@ static void setTerminalInfoDetails(FFTerminalResult* result) else if(ffStrbufEqualS(&result->processName, "com.termux")) ffStrbufInitStatic(&result->prettyName, "Termux"); - #elif defined(__linux__) || defined(__FreeBSD__) + #elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) else if(ffStrbufStartsWithS(&result->processName, "gnome-terminal")) ffStrbufInitStatic(&result->prettyName, "GNOME Terminal"); diff --git a/src/options/general.c b/src/options/general.c index a29c21960..6f088256f 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -39,7 +39,7 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va else if (ffStrEqualsIgnCase(key, "detectVersion")) options->detectVersion = yyjson_get_bool(val); - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) else if (ffStrEqualsIgnCase(key, "escapeBedrock")) options->escapeBedrock = yyjson_get_bool(val); else if (ffStrEqualsIgnCase(key, "playerName")) @@ -84,7 +84,7 @@ bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key else if(ffStrEqualsIgnCase(key, "--detect-version")) options->detectVersion = ffOptionParseBoolean(value); - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) else if(ffStrEqualsIgnCase(key, "--escape-bedrock")) options->escapeBedrock = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--player-name")) @@ -115,7 +115,7 @@ void ffOptionsInitGeneral(FFOptionsGeneral* options) options->multithreading = true; options->detectVersion = true; - #if defined(__linux__) || defined(__FreeBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) options->escapeBedrock = true; ffStrbufInit(&options->playerName); options->dsForceDrm = FF_DS_FORCE_DRM_TYPE_FALSE; diff --git a/src/options/general.h b/src/options/general.h index 0a85df767..f1f0f3ff8 100644 --- a/src/options/general.h +++ b/src/options/general.h @@ -16,7 +16,7 @@ typedef struct FFOptionsGeneral bool detectVersion; // Module options that cannot be put in module option structure - #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) FFstrbuf playerName; bool escapeBedrock; FFDsForceDrmType dsForceDrm; diff --git a/src/util/binary_linux.c b/src/util/binary_linux.c index b9c521ca9..1d520ca3b 100644 --- a/src/util/binary_linux.c +++ b/src/util/binary_linux.c @@ -1,6 +1,6 @@ #include "binary.h" -#if defined(FF_HAVE_ELF) || defined(__sun) || defined(__FreeBSD__) || defined(__OpenBSD__) +#if defined(FF_HAVE_ELF) || defined(__sun) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #include "common/io/io.h" #include "common/library.h" diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index 9eaeae38a..ff5fe5b7b 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -12,7 +12,7 @@ #ifdef __APPLE__ #include #include -#elif defined(__FreeBSD__) || defined(__OpenBSD__) +#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #include #endif @@ -24,10 +24,16 @@ static void getExePath(FFPlatform* platform) exePath[exePathLen] = '\0'; #elif defined(__APPLE__) int exePathLen = proc_pidpath((int) getpid(), exePath, sizeof(exePath)); - #elif defined(__FreeBSD__) + #elif defined(__FreeBSD__) || defined(__NetBSD__) size_t exePathLen = sizeof(exePath); if(sysctl( - (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, (int) getpid()}, 4, + (int[]){CTL_KERN, + #ifdef __FreeBSD__ + KERN_PROC, + #else + KERN_PROC_ARGS, + #endif + KERN_PROC_PATHNAME, (int) getpid()}, 4, exePath, &exePathLen, NULL, 0 ) < 0) From bdd87a6ce7b46b5b08fbfbf65fc2c1e5885326c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 27 Oct 2024 11:50:30 +0800 Subject: [PATCH 13/72] CI: try adding netbsd --- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 4 ++++ 2 files changed, 40 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7de15b0a5..fd2f10ca9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -433,6 +433,42 @@ jobs: name: fastfetch-openbsd-amd64 path: ./fastfetch-*.* + netbsd-amd64: + name: NetBSD-amd64 + runs-on: ubuntu-latest + permissions: + security-events: write + contents: read + steps: + - name: checkout repository + uses: actions/checkout@v4 + + - name: run VM + uses: cross-platform-actions/action@master + with: + operating_system: netbsd + architecture: x86-64 + cpu_count: 4 + shell: bash + version: '10.0' + run: | + uname -a + sudo pkgin -y install cmake git pkgconf + cmake -DSET_TWEAK=Off -DBUILD_TESTS=On . + cmake --build . --target package --verbose -j4 + ./fastfetch --list-features + time ./fastfetch -c presets/ci.jsonc --stat false + time ./fastfetch -c presets/ci.jsonc --format json + time ./flashfetch + ldd fastfetch + ctest + + - name: upload artifacts + uses: actions/upload-artifact@v4 + with: + name: fastfetch-openbsd-amd64 + path: ./fastfetch-*.* + windows-amd64: name: Windows-amd64 runs-on: windows-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index c3d69a628..2bd8fbbaa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1417,6 +1417,10 @@ elseif(OpenBSD) PRIVATE "m" PRIVATE "kvm" ) +elseif(NetBSD) + target_link_libraries(libfastfetch + PRIVATE "m" + ) elseif(SunOS) target_link_libraries(libfastfetch PRIVATE "m" From 32939eababa49bd8cf39ed6f13cf23e397a54cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 27 Oct 2024 12:19:48 +0800 Subject: [PATCH 14/72] Uptime (NetBSD): fix invalid result --- src/detection/uptime/uptime_bsd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/detection/uptime/uptime_bsd.c b/src/detection/uptime/uptime_bsd.c index 47202544a..446a95e25 100644 --- a/src/detection/uptime/uptime_bsd.c +++ b/src/detection/uptime/uptime_bsd.c @@ -6,7 +6,11 @@ const char* ffDetectUptime(FFUptimeResult* result) { + #if __NetBSD__ + struct timespec bootTime; + #else struct timeval bootTime; + #endif size_t bootTimeSize = sizeof(bootTime); if(sysctl( (int[]) {CTL_KERN, KERN_BOOTTIME}, 2, @@ -15,7 +19,11 @@ const char* ffDetectUptime(FFUptimeResult* result) ) != 0) return "sysctl({CTL_KERN, KERN_BOOTTIME}) failed"; + #if __NetBSD__ + result->bootTime = (uint64_t) bootTime.tv_sec * 1000 + (uint64_t) bootTime.tv_nsec / 10000000; + #else result->bootTime = (uint64_t) bootTime.tv_sec * 1000 + (uint64_t) bootTime.tv_usec / 1000; + #endif result->uptime = ffTimeGetNow() - result->bootTime; return NULL; From 332ddfc6ed97e4bfa60e2a4115ee1f1403461c7f Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 27 Oct 2024 14:05:18 +0800 Subject: [PATCH 15/72] CI: fix a copy-paste error --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd2f10ca9..7a85e59b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -466,7 +466,7 @@ jobs: - name: upload artifacts uses: actions/upload-artifact@v4 with: - name: fastfetch-openbsd-amd64 + name: fastfetch-netbsd-amd64 path: ./fastfetch-*.* windows-amd64: From e19ed4c8f663ec44eed93deff5d8eb5d6cfbd8c9 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 28 Oct 2024 14:47:08 +0800 Subject: [PATCH 16/72] CMake: allow to replace native *printf to stb_*printf --- CMakeLists.txt | 9 ++++++ src/3rdparty/stb/stb_sprintf.h | 8 +++--- src/common/init.c | 3 ++ src/common/time.h | 2 ++ src/util/FFstrbuf.c | 7 +++++ src/util/FFstrbuf.h | 2 ++ src/util/stb_printf.c | 3 ++ src/util/stb_printf.h | 50 ++++++++++++++++++++++++++++++++++ 8 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/util/stb_printf.c create mode 100644 src/util/stb_printf.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bd8fbbaa..5359ee9e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ cmake_dependent_option(ENABLE_LIBZFS "Enable libzfs" ON "LINUX OR FreeBSD OR Sun option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF) option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF) option(ENABLE_LTO "Enable link-time optimization in release mode if supported" ON) +option(ENABLE_STBPRINTF "Enable stb_printf" OFF) option(BUILD_TESTS "Build tests" OFF) # Also create test executables option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds option(IS_MUSL "Build with musl libc" OFF) # Used by Github Actions @@ -1052,6 +1053,10 @@ elseif(SunOS) ) endif() +if(ENABLE_STBPRINTF) + list(APPEND LIBFASTFETCH_SRC src/util/stb_printf.c) +endif() + if(ENABLE_DIRECTX_HEADERS) message(STATUS "Enabling DirectX headers for WSL") list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_wsl.cpp) @@ -1092,6 +1097,10 @@ add_library(libfastfetch OBJECT ${LIBFASTFETCH_SRC} ) +if(ENABLE_STBPRINTF) + target_compile_definitions(libfastfetch PUBLIC FF_USE_STBPRINTF) +endif() + if(yyjson_FOUND) target_compile_definitions(libfastfetch PUBLIC FF_USE_SYSTEM_YYJSON) target_link_libraries(libfastfetch PUBLIC yyjson::yyjson) diff --git a/src/3rdparty/stb/stb_sprintf.h b/src/3rdparty/stb/stb_sprintf.h index 70ed4e0e4..7e9d5e78c 100644 --- a/src/3rdparty/stb/stb_sprintf.h +++ b/src/3rdparty/stb/stb_sprintf.h @@ -591,7 +591,7 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, s = (char *)"null"; // get the length, limited to desired precision // always limit to ~0u chars since our counts are 32b - l = stbsp__strlen_limited(s, (pr >= 0) ? pr : ~0u); + l = stbsp__strlen_limited(s, (pr >= 0) ? (unsigned) pr : ~0u); lead[0] = 0; tail[0] = 0; pr = 0; @@ -695,7 +695,7 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, n = (dp >= 1000) ? 6 : ((dp >= 100) ? 5 : ((dp >= 10) ? 4 : 3)); tail[0] = (char)n; for (;;) { - tail[n] = '0' + dp % 10; + tail[n] = (char)('0' + dp % 10); if (n <= 3) break; --n; @@ -793,7 +793,7 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, #endif tail[0] = (char)n; for (;;) { - tail[n] = '0' + dp % 10; + tail[n] = (char)('0' + dp % 10); if (n <= 3) break; --n; @@ -1431,7 +1431,7 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( vsnprintf )( char * buf, int count, c { stbsp__context c; - if ( (count == 0) && !buf ) + if ( count == 0 ) { c.length = 0; diff --git a/src/common/init.c b/src/common/init.c index 96117c66e..f27052fdb 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -266,6 +266,9 @@ void ffListFeatures(void) #if FF_HAVE_EMBEDDED_PCIIDS "Embedded pciids\n" #endif + #if FF_USE_STBPRINTF + "stb_printf\n" + #endif "" , stdout); } diff --git a/src/common/time.h b/src/common/time.h index 588ba7847..76bdcc094 100644 --- a/src/common/time.h +++ b/src/common/time.h @@ -9,6 +9,8 @@ #include #endif +#include "util/stb_printf.h" + static inline double ffTimeGetTick(void) //In msec { #ifdef _WIN32 diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 4387a5d7b..21c722fae 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -20,8 +20,15 @@ void ffStrbufInitVF(FFstrbuf* strbuf, const char* format, va_list arguments) { assert(format != NULL); + #ifndef FF_USE_STBPRINTF int len = vasprintf(&strbuf->chars, format, arguments); assert(len >= 0); + #else + int len = vsnprintf(NULL, 0, format, arguments); + assert(len >= 0); + strbuf->chars = (char*) malloc(sizeof(char) * (len + 1)); + vsnprintf(strbuf->chars, len + 1, format, arguments); + #endif strbuf->allocated = (uint32_t)(len + 1); strbuf->length = (uint32_t)len; diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index fa4a9da87..243437e9d 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -18,6 +18,8 @@ #define FASTFETCH_STRBUF_DEFAULT_ALLOC 32 +#include "stb_printf.h" + typedef struct FFstrbuf { uint32_t allocated; diff --git a/src/util/stb_printf.c b/src/util/stb_printf.c new file mode 100644 index 000000000..0f5212efb --- /dev/null +++ b/src/util/stb_printf.c @@ -0,0 +1,3 @@ +#define STB_SPRINTF_IMPLEMENTATION 1 +#pragma GCC diagnostic ignored "-Wsign-conversion" +#include "3rdparty/stb/stb_sprintf.h" diff --git a/src/util/stb_printf.h b/src/util/stb_printf.h new file mode 100644 index 000000000..62250d171 --- /dev/null +++ b/src/util/stb_printf.h @@ -0,0 +1,50 @@ +#pragma once + +#ifdef FF_USE_STBPRINTF + +#include +#include +#include "3rdparty/stb/stb_sprintf.h" + +static inline char *STB_SPRINTF_DECORATE(printf_callback)(const char* __restrict buf, void* __restrict user, int len) +{ + fwrite(buf, 1, (uint32_t) len, (FILE *)user); + return (char *) buf; +} + +static inline int STB_SPRINTF_DECORATE(vfprintf)(FILE* file, char const* __restrict fmt, va_list va) +{ + char tmp[STB_SPRINTF_MIN]; + return STB_SPRINTF_DECORATE(vsprintfcb)(STB_SPRINTF_DECORATE(printf_callback), file, tmp, fmt, va); +} +#define vfprintf(...) STB_SPRINTF_DECORATE(vfprintf)(__VA_ARGS__) + +static inline int STBSP__ATTRIBUTE_FORMAT(1,2) STB_SPRINTF_DECORATE(printf)(char const* __restrict fmt, ...) +{ + va_list va; + va_start(va, fmt); + int result = STB_SPRINTF_DECORATE(vfprintf)(stdout, fmt, va); + va_end(va); + return result; +} +#define printf(...) STB_SPRINTF_DECORATE(printf)(__VA_ARGS__) + +static inline int STBSP__ATTRIBUTE_FORMAT(2,3) STB_SPRINTF_DECORATE(fprintf)(FILE* __restrict file, char const* __restrict fmt, ...) +{ + va_list va; + va_start(va, fmt); + int result = STB_SPRINTF_DECORATE(vfprintf)(file, fmt, va); + va_end(va); + return result; +} +#define fprintf(...) STB_SPRINTF_DECORATE(fprintf)(__VA_ARGS__) + +#define vsprintf(...) STB_SPRINTF_DECORATE(vsprintf)(__VA_ARGS__) + +#define vsnprintf(...) STB_SPRINTF_DECORATE(vsnprintf)(__VA_ARGS__) + +#define sprintf(...) STB_SPRINTF_DECORATE(sprintf)(__VA_ARGS__) + +#define snprintf(...) STB_SPRINTF_DECORATE(snprintf)(__VA_ARGS__) + +#endif From e7630aef3411a93dee70e7e809c9183f0560af3f Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 28 Oct 2024 15:19:05 +0800 Subject: [PATCH 17/72] NetBSD: support CPUUsage / Memory / Swap --- CMakeLists.txt | 6 +++--- src/detection/cpuusage/cpuusage_bsd.c | 12 ++++++++---- src/detection/memory/memory_obsd.c | 4 ++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5359ee9e6..e4d2281d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -685,7 +685,7 @@ elseif(NetBSD) src/detection/chassis/chassis_nbsd.c src/detection/cpu/cpu_bsd.c src/detection/cpucache/cpucache_nosupport.c - src/detection/cpuusage/cpuusage_nosupport.c + src/detection/cpuusage/cpuusage_bsd.c src/detection/cursor/cursor_linux.c src/detection/disk/disk_nosupport.c src/detection/dns/dns_linux.c @@ -720,7 +720,7 @@ elseif(NetBSD) src/detection/localip/localip_linux.c src/detection/gamepad/gamepad_nosupport.c src/detection/media/media_linux.c - src/detection/memory/memory_bsd.c + src/detection/memory/memory_obsd.c src/detection/mouse/mouse_nosupport.c src/detection/netio/netio_nosupport.c src/detection/opengl/opengl_linux.c @@ -730,7 +730,7 @@ elseif(NetBSD) src/detection/processes/processes_nosupport.c src/detection/gtk_qt/qt.c src/detection/sound/sound_nosupport.c - src/detection/swap/swap_nosupport.c + src/detection/swap/swap_obsd.c src/detection/terminalfont/terminalfont_linux.c src/detection/terminalshell/terminalshell_linux.c src/detection/terminalsize/terminalsize_linux.c diff --git a/src/detection/cpuusage/cpuusage_bsd.c b/src/detection/cpuusage/cpuusage_bsd.c index a04c05b75..5b9312d9e 100644 --- a/src/detection/cpuusage/cpuusage_bsd.c +++ b/src/detection/cpuusage/cpuusage_bsd.c @@ -6,15 +6,19 @@ #include #include -#ifdef __OpenBSD__ +#if __OpenBSD__ || __NetBSD__ #include #endif const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { size_t neededLength = 0; -#ifdef __OpenBSD__ - int ctls[] = {CTL_KERN, KERN_CPTIME}; +#if __OpenBSD__|| __NetBSD__ + #ifdef KERN_CPTIME + int ctls[] = {CTL_KERN, KERN_CPTIME}; + #else + int ctls[] = {CTL_KERN, KERN_CP_TIME}; + #endif if (sysctl(ctls, 2, NULL, &neededLength, NULL, 0) != 0) return "sysctl({CTL_KERN, KERN_CPTIME}, 2, NULL) failed"; #else @@ -27,7 +31,7 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) FF_AUTO_FREE uint64_t (*cpTimes)[CPUSTATES] = malloc(neededLength); -#ifdef __OpenBSD__ +#if __OpenBSD__ || __NetBSD__ if (sysctl(ctls, 2, cpTimes, &neededLength, NULL, 0) != 0) return "sysctl({CTL_KERN, KERN_CPTIME}, 2, NULL) failed"; #else diff --git a/src/detection/memory/memory_obsd.c b/src/detection/memory/memory_obsd.c index 9efc21ead..3dda7656a 100644 --- a/src/detection/memory/memory_obsd.c +++ b/src/detection/memory/memory_obsd.c @@ -3,6 +3,10 @@ #include +#if __NetBSD__ + #include +#endif + const char* ffDetectMemory(FFMemoryResult* ram) { struct uvmexp buf; From 081e8ea39fde4fef2a69fe43360b7b14dcc76cc7 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 28 Oct 2024 15:48:43 +0800 Subject: [PATCH 18/72] Disk: support NetBSD, improve hidden partition detection --- CMakeLists.txt | 2 +- src/detection/disk/disk_bsd.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e4d2281d0..40a3325e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -687,7 +687,7 @@ elseif(NetBSD) src/detection/cpucache/cpucache_nosupport.c src/detection/cpuusage/cpuusage_bsd.c src/detection/cursor/cursor_linux.c - src/detection/disk/disk_nosupport.c + src/detection/disk/disk_bsd.c src/detection/dns/dns_linux.c src/detection/physicaldisk/physicaldisk_nosupport.c src/detection/physicalmemory/physicalmemory_nosupport.c diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index 4060669c3..f26d5f18d 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -5,6 +5,14 @@ #include #include +#ifdef __NetBSD__ +#include +#include +#define getfsstat(...) getvfsstat(__VA_ARGS__) +#define statfs statvfs +#define f_flags f_flag +#endif + #ifdef __FreeBSD__ #include @@ -51,7 +59,7 @@ static void detectFsInfo(struct statfs* fs, FFDisk* disk) ? FF_DISK_VOLUME_TYPE_REGULAR_BIT : FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT; } - else if(ffStrbufStartsWithS(&disk->mountpoint, "/boot") || ffStrbufStartsWithS(&disk->mountpoint, "/efi")) + else if(fs->f_flags & MNT_IGNORE) disk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT; else if(!(fs->f_flags & MNT_LOCAL)) disk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT; @@ -95,7 +103,12 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk) #else static void detectFsInfo(struct statfs* fs, FFDisk* disk) { - FF_UNUSED(fs, disk); + if(fs->f_flags & MNT_IGNORE) + disk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT; + else if(!(fs->f_flags & MNT_LOCAL)) + disk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT; + else + disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT; } #endif From 82fc27f259cae6e7aeeb9d798ee4e46f7574c2ed Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 28 Oct 2024 16:07:22 +0800 Subject: [PATCH 19/72] CMake (NetBSD): detect X11 and other packages --- CMakeLists.txt | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40a3325e1..8874c1010 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,30 +48,30 @@ include(CheckIncludeFile) include(CMakeDependentOption) -cmake_dependent_option(ENABLE_VULKAN "Enable vulkan" ON "LINUX OR APPLE OR FreeBSD OR OpenBSD OR WIN32 OR ANDROID OR SunOS" OFF) -cmake_dependent_option(ENABLE_WAYLAND "Enable wayland-client" ON "LINUX OR FreeBSD OR OpenBSD" OFF) -cmake_dependent_option(ENABLE_XCB_RANDR "Enable xcb-randr" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_XCB "Enable xcb" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_X11 "Enable x11" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_VULKAN "Enable vulkan" ON "LINUX OR APPLE OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS" OFF) +cmake_dependent_option(ENABLE_WAYLAND "Enable wayland-client" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD" OFF) +cmake_dependent_option(ENABLE_XCB_RANDR "Enable xcb-randr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_XCB "Enable xcb" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_X11 "Enable x11" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_DRM_AMDGPU "Enable libdrm_amdgpu" ON "LINUX" OFF) -cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_DBUS "Enable dbus-1" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_XFCONF "Enable libxfconf-0" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR FreeBSD OR APPLE OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_DBUS "Enable dbus-1" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_XFCONF "Enable libxfconf-0" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR FreeBSD OR APPLE OR OpenBSD OR NetBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_RPM "Enable rpm" ON "LINUX" OFF) -cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR FreeBSD OR OpenBSD OR APPLE OR WIN32 OR SunOS" OFF) -cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR FreeBSD OR OpenBSD OR APPLE OR SunOS" OFF) +cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR APPLE OR WIN32 OR SunOS" OFF) +cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR APPLE OR SunOS" OFF) cmake_dependent_option(ENABLE_CHAFA "Enable chafa" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF) cmake_dependent_option(ENABLE_ZLIB "Enable zlib" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF) -cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR FreeBSD OR OpenBSD OR WIN32 OR SunOS" OFF) -cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR FreeBSD OR OpenBSD OR WIN32 OR ANDROID OR SunOS" OFF) +cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR SunOS" OFF) +cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS" OFF) cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF) -cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR OpenBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR OpenBSD OR NetBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF) cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF) cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID" OFF) @@ -729,7 +729,7 @@ elseif(NetBSD) src/detection/poweradapter/poweradapter_nosupport.c src/detection/processes/processes_nosupport.c src/detection/gtk_qt/qt.c - src/detection/sound/sound_nosupport.c + src/detection/sound/sound_linux.c src/detection/swap/swap_obsd.c src/detection/terminalfont/terminalfont_linux.c src/detection/terminalshell/terminalshell_linux.c From bc550a5ea7abc0529a39b3ccb1ac4f13c346a67c Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 28 Oct 2024 16:27:29 +0800 Subject: [PATCH 20/72] Disk (OpenBSD): fix build --- src/detection/disk/disk_bsd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index f26d5f18d..659314040 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -103,9 +103,12 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk) #else static void detectFsInfo(struct statfs* fs, FFDisk* disk) { + #ifdef MNT_IGNORE if(fs->f_flags & MNT_IGNORE) disk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT; - else if(!(fs->f_flags & MNT_LOCAL)) + else + #endif + if(!(fs->f_flags & MNT_LOCAL)) disk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT; else disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT; From a3a042f02be97f30673b5908c71f9a4ed9073fec Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 29 Oct 2024 08:51:17 +0800 Subject: [PATCH 21/72] Global: remove stb_printf Doesn't gain any performance boost --- CMakeLists.txt | 9 - src/3rdparty/stb/repo.json | 9 - src/3rdparty/stb/stb_sprintf.h | 1906 -------------------------------- src/common/init.c | 3 - src/common/time.h | 2 - src/util/FFstrbuf.c | 7 - src/util/FFstrbuf.h | 2 - src/util/stb_printf.c | 3 - src/util/stb_printf.h | 50 - 9 files changed, 1991 deletions(-) delete mode 100644 src/3rdparty/stb/repo.json delete mode 100644 src/3rdparty/stb/stb_sprintf.h delete mode 100644 src/util/stb_printf.c delete mode 100644 src/util/stb_printf.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8874c1010..a14439f50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,6 @@ cmake_dependent_option(ENABLE_LIBZFS "Enable libzfs" ON "LINUX OR FreeBSD OR Sun option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF) option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF) option(ENABLE_LTO "Enable link-time optimization in release mode if supported" ON) -option(ENABLE_STBPRINTF "Enable stb_printf" OFF) option(BUILD_TESTS "Build tests" OFF) # Also create test executables option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds option(IS_MUSL "Build with musl libc" OFF) # Used by Github Actions @@ -1053,10 +1052,6 @@ elseif(SunOS) ) endif() -if(ENABLE_STBPRINTF) - list(APPEND LIBFASTFETCH_SRC src/util/stb_printf.c) -endif() - if(ENABLE_DIRECTX_HEADERS) message(STATUS "Enabling DirectX headers for WSL") list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_wsl.cpp) @@ -1097,10 +1092,6 @@ add_library(libfastfetch OBJECT ${LIBFASTFETCH_SRC} ) -if(ENABLE_STBPRINTF) - target_compile_definitions(libfastfetch PUBLIC FF_USE_STBPRINTF) -endif() - if(yyjson_FOUND) target_compile_definitions(libfastfetch PUBLIC FF_USE_SYSTEM_YYJSON) target_link_libraries(libfastfetch PUBLIC yyjson::yyjson) diff --git a/src/3rdparty/stb/repo.json b/src/3rdparty/stb/repo.json deleted file mode 100644 index 0d5ca80db..000000000 --- a/src/3rdparty/stb/repo.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "home": "https://github.com/nothings/stb/blob/master/stb_sprintf.h", - "license": "MIT or Public domain (embed in source)", - "version": "v1.10", - "author": "nothings", - "patches": [ - "https://github.com/nothings/stb/pull/1695" - ] -} diff --git a/src/3rdparty/stb/stb_sprintf.h b/src/3rdparty/stb/stb_sprintf.h deleted file mode 100644 index 7e9d5e78c..000000000 --- a/src/3rdparty/stb/stb_sprintf.h +++ /dev/null @@ -1,1906 +0,0 @@ -// stb_sprintf - v1.10 - public domain snprintf() implementation -// originally by Jeff Roberts / RAD Game Tools, 2015/10/20 -// http://github.com/nothings/stb -// -// allowed types: sc uidBboXx p AaGgEef n -// lengths : hh h ll j z t I64 I32 I -// -// Contributors: -// Fabian "ryg" Giesen (reformatting) -// github:aganm (attribute format) -// -// Contributors (bugfixes): -// github:d26435 -// github:trex78 -// github:account-login -// Jari Komppa (SI suffixes) -// Rohit Nirmal -// Marcin Wojdyr -// Leonard Ritter -// Stefano Zanotti -// Adam Allison -// Arvid Gerstmann -// Markus Kolb -// -// LICENSE: -// -// See end of file for license information. - -#ifndef STB_SPRINTF_H_INCLUDE -#define STB_SPRINTF_H_INCLUDE - -/* -Single file sprintf replacement. - -Originally written by Jeff Roberts at RAD Game Tools - 2015/10/20. -Hereby placed in public domain. - -This is a full sprintf replacement that supports everything that -the C runtime sprintfs support, including float/double, 64-bit integers, -hex floats, field parameters (%*.*d stuff), length reads backs, etc. - -Why would you need this if sprintf already exists? Well, first off, -it's *much* faster (see below). It's also much smaller than the CRT -versions code-space-wise. We've also added some simple improvements -that are super handy (commas in thousands, callbacks at buffer full, -for example). Finally, the format strings for MSVC and GCC differ -for 64-bit integers (among other small things), so this lets you use -the same format strings in cross platform code. - -It uses the standard single file trick of being both the header file -and the source itself. If you just include it normally, you just get -the header file function definitions. To get the code, you include -it from a C or C++ file and define STB_SPRINTF_IMPLEMENTATION first. - -It only uses va_args macros from the C runtime to do it's work. It -does cast doubles to S64s and shifts and divides U64s, which does -drag in CRT code on most platforms. - -It compiles to roughly 8K with float support, and 4K without. -As a comparison, when using MSVC static libs, calling sprintf drags -in 16K. - -API: -==== -int stbsp_sprintf( char * buf, char const * fmt, ... ) -int stbsp_snprintf( char * buf, int count, char const * fmt, ... ) - Convert an arg list into a buffer. stbsp_snprintf always returns - a zero-terminated string (unlike regular snprintf). - -int stbsp_vsprintf( char * buf, char const * fmt, va_list va ) -int stbsp_vsnprintf( char * buf, int count, char const * fmt, va_list va ) - Convert a va_list arg list into a buffer. stbsp_vsnprintf always returns - a zero-terminated string (unlike regular snprintf). - -int stbsp_vsprintfcb( STBSP_SPRINTFCB * callback, void * user, char * buf, char const * fmt, va_list va ) - typedef char * STBSP_SPRINTFCB( char const * buf, void * user, int len ); - Convert into a buffer, calling back every STB_SPRINTF_MIN chars. - Your callback can then copy the chars out, print them or whatever. - This function is actually the workhorse for everything else. - The buffer you pass in must hold at least STB_SPRINTF_MIN characters. - // you return the next buffer to use or 0 to stop converting - -void stbsp_set_separators( char comma, char period ) - Set the comma and period characters to use. - -FLOATS/DOUBLES: -=============== -This code uses a internal float->ascii conversion method that uses -doubles with error correction (double-doubles, for ~105 bits of -precision). This conversion is round-trip perfect - that is, an atof -of the values output here will give you the bit-exact double back. - -One difference is that our insignificant digits will be different than -with MSVC or GCC (but they don't match each other either). We also -don't attempt to find the minimum length matching float (pre-MSVC15 -doesn't either). - -If you don't need float or doubles at all, define STB_SPRINTF_NOFLOAT -and you'll save 4K of code space. - -64-BIT INTS: -============ -This library also supports 64-bit integers and you can use MSVC style or -GCC style indicators (%I64d or %lld). It supports the C99 specifiers -for size_t and ptr_diff_t (%jd %zd) as well. - -EXTRAS: -======= -Like some GCCs, for integers and floats, you can use a ' (single quote) -specifier and commas will be inserted on the thousands: "%'d" on 12345 -would print 12,345. - -For integers and floats, you can use a "$" specifier and the number -will be converted to float and then divided to get kilo, mega, giga or -tera and then printed, so "%$d" 1000 is "1.0 k", "%$.2d" 2536000 is -"2.53 M", etc. For byte values, use two $:s, like "%$$d" to turn -2536000 to "2.42 Mi". If you prefer JEDEC suffixes to SI ones, use three -$:s: "%$$$d" -> "2.42 M". To remove the space between the number and the -suffix, add "_" specifier: "%_$d" -> "2.53M". - -In addition to octal and hexadecimal conversions, you can print -integers in binary: "%b" for 256 would print 100. - -PERFORMANCE vs MSVC 2008 32-/64-bit (GCC is even slower than MSVC): -=================================================================== -"%d" across all 32-bit ints (4.8x/4.0x faster than 32-/64-bit MSVC) -"%24d" across all 32-bit ints (4.5x/4.2x faster) -"%x" across all 32-bit ints (4.5x/3.8x faster) -"%08x" across all 32-bit ints (4.3x/3.8x faster) -"%f" across e-10 to e+10 floats (7.3x/6.0x faster) -"%e" across e-10 to e+10 floats (8.1x/6.0x faster) -"%g" across e-10 to e+10 floats (10.0x/7.1x faster) -"%f" for values near e-300 (7.9x/6.5x faster) -"%f" for values near e+300 (10.0x/9.1x faster) -"%e" for values near e-300 (10.1x/7.0x faster) -"%e" for values near e+300 (9.2x/6.0x faster) -"%.320f" for values near e-300 (12.6x/11.2x faster) -"%a" for random values (8.6x/4.3x faster) -"%I64d" for 64-bits with 32-bit values (4.8x/3.4x faster) -"%I64d" for 64-bits > 32-bit values (4.9x/5.5x faster) -"%s%s%s" for 64 char strings (7.1x/7.3x faster) -"...512 char string..." ( 35.0x/32.5x faster!) -*/ - -#if defined(__clang__) - #if defined(__has_feature) && defined(__has_attribute) - #if __has_feature(address_sanitizer) - #if __has_attribute(__no_sanitize__) - #define STBSP__ASAN __attribute__((__no_sanitize__("address"))) - #elif __has_attribute(__no_sanitize_address__) - #define STBSP__ASAN __attribute__((__no_sanitize_address__)) - #elif __has_attribute(__no_address_safety_analysis__) - #define STBSP__ASAN __attribute__((__no_address_safety_analysis__)) - #endif - #endif - #endif -#elif defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) - #if defined(__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__ - #define STBSP__ASAN __attribute__((__no_sanitize_address__)) - #endif -#endif - -#ifndef STBSP__ASAN -#define STBSP__ASAN -#endif - -#ifdef STB_SPRINTF_STATIC -#define STBSP__PUBLICDEC static -#define STBSP__PUBLICDEF static STBSP__ASAN -#else -#ifdef __cplusplus -#define STBSP__PUBLICDEC extern "C" -#define STBSP__PUBLICDEF extern "C" STBSP__ASAN -#else -#define STBSP__PUBLICDEC extern -#define STBSP__PUBLICDEF STBSP__ASAN -#endif -#endif - -#if defined(__has_attribute) - #if __has_attribute(format) - #define STBSP__ATTRIBUTE_FORMAT(fmt,va) __attribute__((format(printf,fmt,va))) - #endif -#endif - -#ifndef STBSP__ATTRIBUTE_FORMAT -#define STBSP__ATTRIBUTE_FORMAT(fmt,va) -#endif - -#ifdef _MSC_VER -#define STBSP__NOTUSED(v) (void)(v) -#else -#define STBSP__NOTUSED(v) (void)sizeof(v) -#endif - -#include // for va_arg(), va_list() -#include // size_t, ptrdiff_t - -#ifndef STB_SPRINTF_MIN -#define STB_SPRINTF_MIN 512 // how many characters per callback -#endif -typedef char *STBSP_SPRINTFCB(const char *buf, void *user, int len); - -#ifndef STB_SPRINTF_DECORATE -#define STB_SPRINTF_DECORATE(name) stbsp_##name // define this before including if you want to change the names -#endif - -STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsprintf)(char *buf, char const *fmt, va_list va); -STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsnprintf)(char *buf, int count, char const *fmt, va_list va); -STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(sprintf)(char *buf, char const *fmt, ...) STBSP__ATTRIBUTE_FORMAT(2,3); -STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(snprintf)(char *buf, int count, char const *fmt, ...) STBSP__ATTRIBUTE_FORMAT(3,4); - -STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, void *user, char *buf, char const *fmt, va_list va); -STBSP__PUBLICDEC void STB_SPRINTF_DECORATE(set_separators)(char comma, char period); - -#endif // STB_SPRINTF_H_INCLUDE - -#ifdef STB_SPRINTF_IMPLEMENTATION - -#define stbsp__uint32 unsigned int -#define stbsp__int32 signed int - -#ifdef _MSC_VER -#define stbsp__uint64 unsigned __int64 -#define stbsp__int64 signed __int64 -#else -#define stbsp__uint64 unsigned long long -#define stbsp__int64 signed long long -#endif -#define stbsp__uint16 unsigned short - -#ifndef stbsp__uintptr -#if defined(__ppc64__) || defined(__powerpc64__) || defined(__aarch64__) || defined(_M_X64) || defined(__x86_64__) || defined(__x86_64) || defined(__s390x__)|| defined(_M_ARM64) -#define stbsp__uintptr stbsp__uint64 -#else -#define stbsp__uintptr stbsp__uint32 -#endif -#endif - -#ifndef STB_SPRINTF_MSVC_MODE // used for MSVC2013 and earlier (MSVC2015 matches GCC) -#if defined(_MSC_VER) && (_MSC_VER < 1900) -#define STB_SPRINTF_MSVC_MODE -#endif -#endif - -#ifdef STB_SPRINTF_NOUNALIGNED // define this before inclusion to force stbsp_sprintf to always use aligned accesses -#define STBSP__UNALIGNED(code) -#else -#define STBSP__UNALIGNED(code) code -#endif - -#ifndef STB_SPRINTF_NOFLOAT -// internal float utility functions -static stbsp__int32 stbsp__real_to_str(char const **start, stbsp__uint32 *len, char *out, stbsp__int32 *decimal_pos, double value, stbsp__uint32 frac_digits); -static stbsp__int32 stbsp__real_to_parts(stbsp__int64 *bits, stbsp__int32 *expo, double value); -#define STBSP__SPECIAL 0x7000 -#endif - -static char stbsp__period = '.'; -static char stbsp__comma = ','; -static struct -{ - short temp; // force next field to be 2-byte aligned - char pair[201]; -} stbsp__digitpair = -{ - 0, - "00010203040506070809101112131415161718192021222324" - "25262728293031323334353637383940414243444546474849" - "50515253545556575859606162636465666768697071727374" - "75767778798081828384858687888990919293949596979899" -}; - -STBSP__PUBLICDEF void STB_SPRINTF_DECORATE(set_separators)(char pcomma, char pperiod) -{ - stbsp__period = pperiod; - stbsp__comma = pcomma; -} - -#define STBSP__LEFTJUST 1 -#define STBSP__LEADINGPLUS 2 -#define STBSP__LEADINGSPACE 4 -#define STBSP__LEADING_0X 8 -#define STBSP__LEADINGZERO 16 -#define STBSP__INTMAX 32 -#define STBSP__TRIPLET_COMMA 64 -#define STBSP__NEGATIVE 128 -#define STBSP__METRIC_SUFFIX 256 -#define STBSP__HALFWIDTH 512 -#define STBSP__METRIC_NOSPACE 1024 -#define STBSP__METRIC_1024 2048 -#define STBSP__METRIC_JEDEC 4096 - -static void stbsp__lead_sign(stbsp__uint32 fl, char *sign) -{ - sign[0] = 0; - if (fl & STBSP__NEGATIVE) { - sign[0] = 1; - sign[1] = '-'; - } else if (fl & STBSP__LEADINGSPACE) { - sign[0] = 1; - sign[1] = ' '; - } else if (fl & STBSP__LEADINGPLUS) { - sign[0] = 1; - sign[1] = '+'; - } -} - -static STBSP__ASAN stbsp__uint32 stbsp__strlen_limited(char const *s, stbsp__uint32 limit) -{ - char const * sn = s; - - // get up to 4-byte alignment - for (;;) { - if (((stbsp__uintptr)sn & 3) == 0) - break; - - if (!limit || *sn == 0) - return (stbsp__uint32)(sn - s); - - ++sn; - --limit; - } - - // scan over 4 bytes at a time to find terminating 0 - // this will intentionally scan up to 3 bytes past the end of buffers, - // but becase it works 4B aligned, it will never cross page boundaries - // (hence the STBSP__ASAN markup; the over-read here is intentional - // and harmless) - while (limit >= 4) { - stbsp__uint32 v = *(stbsp__uint32 *)sn; - // bit hack to find if there's a 0 byte in there - if ((v - 0x01010101) & (~v) & 0x80808080UL) - break; - - sn += 4; - limit -= 4; - } - - // handle the last few characters to find actual size - while (limit && *sn) { - ++sn; - --limit; - } - - return (stbsp__uint32)(sn - s); -} - -STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback, void *user, char *buf, char const *fmt, va_list va) -{ - static char hex[] = "0123456789abcdefxp"; - static char hexu[] = "0123456789ABCDEFXP"; - char *bf; - char const *f; - int tlen = 0; - - bf = buf; - f = fmt; - for (;;) { - stbsp__int32 fw, pr, tz; - stbsp__uint32 fl; - - // macros for the callback buffer stuff - #define stbsp__chk_cb_bufL(bytes) \ - { \ - int len = (int)(bf - buf); \ - if ((len + (bytes)) >= STB_SPRINTF_MIN) { \ - tlen += len; \ - if (0 == (bf = buf = callback(buf, user, len))) \ - goto done; \ - } \ - } - #define stbsp__chk_cb_buf(bytes) \ - { \ - if (callback) { \ - stbsp__chk_cb_bufL(bytes); \ - } \ - } - #define stbsp__flush_cb() \ - { \ - stbsp__chk_cb_bufL(STB_SPRINTF_MIN - 1); \ - } // flush if there is even one byte in the buffer - #define stbsp__cb_buf_clamp(cl, v) \ - cl = v; \ - if (callback) { \ - int lg = STB_SPRINTF_MIN - (int)(bf - buf); \ - if (cl > lg) \ - cl = lg; \ - } - - // fast copy everything up to the next % (or end of string) - for (;;) { - while (((stbsp__uintptr)f) & 3) { - schk1: - if (f[0] == '%') - goto scandd; - schk2: - if (f[0] == 0) - goto endfmt; - stbsp__chk_cb_buf(1); - *bf++ = f[0]; - ++f; - } - for (;;) { - // Check if the next 4 bytes contain %(0x25) or end of string. - // Using the 'hasless' trick: - // https://graphics.stanford.edu/~seander/bithacks.html#HasLessInWord - stbsp__uint32 v, c; - v = *(stbsp__uint32 *)f; - c = (~v) & 0x80808080; - if (((v ^ 0x25252525) - 0x01010101) & c) - goto schk1; - if ((v - 0x01010101) & c) - goto schk2; - if (callback) - if ((STB_SPRINTF_MIN - (int)(bf - buf)) < 4) - goto schk1; - #ifdef STB_SPRINTF_NOUNALIGNED - if(((stbsp__uintptr)bf) & 3) { - bf[0] = f[0]; - bf[1] = f[1]; - bf[2] = f[2]; - bf[3] = f[3]; - } else - #endif - { - *(stbsp__uint32 *)bf = v; - } - bf += 4; - f += 4; - } - } - scandd: - - ++f; - - // ok, we have a percent, read the modifiers first - fw = 0; - pr = -1; - fl = 0; - tz = 0; - - // flags - for (;;) { - switch (f[0]) { - // if we have left justify - case '-': - fl |= STBSP__LEFTJUST; - ++f; - continue; - // if we have leading plus - case '+': - fl |= STBSP__LEADINGPLUS; - ++f; - continue; - // if we have leading space - case ' ': - fl |= STBSP__LEADINGSPACE; - ++f; - continue; - // if we have leading 0x - case '#': - fl |= STBSP__LEADING_0X; - ++f; - continue; - // if we have thousand commas - case '\'': - fl |= STBSP__TRIPLET_COMMA; - ++f; - continue; - // if we have kilo marker (none->kilo->kibi->jedec) - case '$': - if (fl & STBSP__METRIC_SUFFIX) { - if (fl & STBSP__METRIC_1024) { - fl |= STBSP__METRIC_JEDEC; - } else { - fl |= STBSP__METRIC_1024; - } - } else { - fl |= STBSP__METRIC_SUFFIX; - } - ++f; - continue; - // if we don't want space between metric suffix and number - case '_': - fl |= STBSP__METRIC_NOSPACE; - ++f; - continue; - // if we have leading zero - case '0': - fl |= STBSP__LEADINGZERO; - ++f; - goto flags_done; - default: goto flags_done; - } - } - flags_done: - - // get the field width - if (f[0] == '*') { - fw = va_arg(va, stbsp__uint32); - ++f; - } else { - while ((f[0] >= '0') && (f[0] <= '9')) { - fw = fw * 10 + f[0] - '0'; - f++; - } - } - // get the precision - if (f[0] == '.') { - ++f; - if (f[0] == '*') { - pr = va_arg(va, stbsp__uint32); - ++f; - } else { - pr = 0; - while ((f[0] >= '0') && (f[0] <= '9')) { - pr = pr * 10 + f[0] - '0'; - f++; - } - } - } - - // handle integer size overrides - switch (f[0]) { - // are we halfwidth? - case 'h': - fl |= STBSP__HALFWIDTH; - ++f; - if (f[0] == 'h') - ++f; // QUARTERWIDTH - break; - // are we 64-bit (unix style) - case 'l': - fl |= ((sizeof(long) == 8) ? STBSP__INTMAX : 0); - ++f; - if (f[0] == 'l') { - fl |= STBSP__INTMAX; - ++f; - } - break; - // are we 64-bit on intmax? (c99) - case 'j': - fl |= (sizeof(size_t) == 8) ? STBSP__INTMAX : 0; - ++f; - break; - // are we 64-bit on size_t or ptrdiff_t? (c99) - case 'z': - fl |= (sizeof(ptrdiff_t) == 8) ? STBSP__INTMAX : 0; - ++f; - break; - case 't': - fl |= (sizeof(ptrdiff_t) == 8) ? STBSP__INTMAX : 0; - ++f; - break; - // are we 64-bit (msft style) - case 'I': - if ((f[1] == '6') && (f[2] == '4')) { - fl |= STBSP__INTMAX; - f += 3; - } else if ((f[1] == '3') && (f[2] == '2')) { - f += 3; - } else { - fl |= ((sizeof(void *) == 8) ? STBSP__INTMAX : 0); - ++f; - } - break; - default: break; - } - - // handle each replacement - switch (f[0]) { - #define STBSP__NUMSZ 512 // big enough for e308 (with commas) or e-307 - char num[STBSP__NUMSZ]; - char lead[8]; - char tail[8]; - char *s; - char const *h; - stbsp__uint32 l, n, cs; - stbsp__uint64 n64; -#ifndef STB_SPRINTF_NOFLOAT - double fv; -#endif - stbsp__int32 dp; - char const *sn; - - case 's': - // get the string - s = va_arg(va, char *); - if (s == 0) - s = (char *)"null"; - // get the length, limited to desired precision - // always limit to ~0u chars since our counts are 32b - l = stbsp__strlen_limited(s, (pr >= 0) ? (unsigned) pr : ~0u); - lead[0] = 0; - tail[0] = 0; - pr = 0; - dp = 0; - cs = 0; - // copy the string in - goto scopy; - - case 'c': // char - // get the character - s = num + STBSP__NUMSZ - 1; - *s = (char)va_arg(va, int); - l = 1; - lead[0] = 0; - tail[0] = 0; - pr = 0; - dp = 0; - cs = 0; - goto scopy; - - case 'n': // weird write-bytes specifier - { - int *d = va_arg(va, int *); - *d = tlen + (int)(bf - buf); - } break; - -#ifdef STB_SPRINTF_NOFLOAT - case 'A': // float - case 'a': // hex float - case 'G': // float - case 'g': // float - case 'E': // float - case 'e': // float - case 'f': // float - va_arg(va, double); // eat it - s = (char *)"No float"; - l = 8; - lead[0] = 0; - tail[0] = 0; - pr = 0; - cs = 0; - STBSP__NOTUSED(dp); - goto scopy; -#else - case 'A': // hex float - case 'a': // hex float - h = (f[0] == 'A') ? hexu : hex; - fv = va_arg(va, double); - if (pr == -1) - pr = 6; // default is 6 - // read the double into a string - if (stbsp__real_to_parts((stbsp__int64 *)&n64, &dp, fv)) - fl |= STBSP__NEGATIVE; - - s = num + 64; - - stbsp__lead_sign(fl, lead); - - if (dp == -1023) - dp = (n64) ? -1022 : 0; - else - n64 |= (((stbsp__uint64)1) << 52); - n64 <<= (64 - 56); - if (pr < 15) - n64 += ((((stbsp__uint64)8) << 56) >> (pr * 4)); -// add leading chars - -#ifdef STB_SPRINTF_MSVC_MODE - *s++ = '0'; - *s++ = 'x'; -#else - lead[1 + lead[0]] = '0'; - lead[2 + lead[0]] = 'x'; - lead[0] += 2; -#endif - *s++ = h[(n64 >> 60) & 15]; - n64 <<= 4; - if (pr) - *s++ = stbsp__period; - sn = s; - - // print the bits - n = pr; - if (n > 13) - n = 13; - if (pr > (stbsp__int32)n) - tz = pr - n; - pr = 0; - while (n--) { - *s++ = h[(n64 >> 60) & 15]; - n64 <<= 4; - } - - // print the expo - tail[1] = h[17]; - if (dp < 0) { - tail[2] = '-'; - dp = -dp; - } else - tail[2] = '+'; - n = (dp >= 1000) ? 6 : ((dp >= 100) ? 5 : ((dp >= 10) ? 4 : 3)); - tail[0] = (char)n; - for (;;) { - tail[n] = (char)('0' + dp % 10); - if (n <= 3) - break; - --n; - dp /= 10; - } - - dp = (int)(s - sn); - l = (int)(s - (num + 64)); - s = num + 64; - cs = 1 + (3 << 24); - goto scopy; - - case 'G': // float - case 'g': // float - h = (f[0] == 'G') ? hexu : hex; - fv = va_arg(va, double); - if (pr == -1) - pr = 6; - else if (pr == 0) - pr = 1; // default is 6 - // read the double into a string - if (stbsp__real_to_str(&sn, &l, num, &dp, fv, (pr - 1) | 0x80000000)) - fl |= STBSP__NEGATIVE; - - // clamp the precision and delete extra zeros after clamp - n = pr; - if (l > (stbsp__uint32)pr) - l = pr; - while ((l > 1) && (pr) && (sn[l - 1] == '0')) { - --pr; - --l; - } - - // should we use %e - if ((dp <= -4) || (dp > (stbsp__int32)n)) { - if (pr > (stbsp__int32)l) - pr = l - 1; - else if (pr) - --pr; // when using %e, there is one digit before the decimal - goto doexpfromg; - } - // this is the insane action to get the pr to match %g semantics for %f - if (dp > 0) { - pr = (dp < (stbsp__int32)l) ? l - dp : 0; - } else { - pr = -dp + ((pr > (stbsp__int32)l) ? (stbsp__int32) l : pr); - } - goto dofloatfromg; - - case 'E': // float - case 'e': // float - h = (f[0] == 'E') ? hexu : hex; - fv = va_arg(va, double); - if (pr == -1) - pr = 6; // default is 6 - // read the double into a string - if (stbsp__real_to_str(&sn, &l, num, &dp, fv, pr | 0x80000000)) - fl |= STBSP__NEGATIVE; - doexpfromg: - tail[0] = 0; - stbsp__lead_sign(fl, lead); - if (dp == STBSP__SPECIAL) { - s = (char *)sn; - cs = 0; - pr = 0; - goto scopy; - } - s = num + 64; - // handle leading chars - *s++ = sn[0]; - - if (pr) - *s++ = stbsp__period; - - // handle after decimal - if ((l - 1) > (stbsp__uint32)pr) - l = pr + 1; - for (n = 1; n < l; n++) - *s++ = sn[n]; - // trailing zeros - tz = pr - (l - 1); - pr = 0; - // dump expo - tail[1] = h[0xe]; - dp -= 1; - if (dp < 0) { - tail[2] = '-'; - dp = -dp; - } else - tail[2] = '+'; -#ifdef STB_SPRINTF_MSVC_MODE - n = 5; -#else - n = (dp >= 100) ? 5 : 4; -#endif - tail[0] = (char)n; - for (;;) { - tail[n] = (char)('0' + dp % 10); - if (n <= 3) - break; - --n; - dp /= 10; - } - cs = 1 + (3 << 24); // how many tens - goto flt_lead; - - case 'f': // float - fv = va_arg(va, double); - doafloat: - // do kilos - if (fl & STBSP__METRIC_SUFFIX) { - double divisor; - divisor = 1000.0f; - if (fl & STBSP__METRIC_1024) - divisor = 1024.0; - while (fl < 0x4000000) { - if ((fv < divisor) && (fv > -divisor)) - break; - fv /= divisor; - fl += 0x1000000; - } - } - if (pr == -1) - pr = 6; // default is 6 - // read the double into a string - if (stbsp__real_to_str(&sn, &l, num, &dp, fv, pr)) - fl |= STBSP__NEGATIVE; - dofloatfromg: - tail[0] = 0; - stbsp__lead_sign(fl, lead); - if (dp == STBSP__SPECIAL) { - s = (char *)sn; - cs = 0; - pr = 0; - goto scopy; - } - s = num + 64; - - // handle the three decimal varieties - if (dp <= 0) { - stbsp__int32 i; - // handle 0.000*000xxxx - *s++ = '0'; - if (pr) - *s++ = stbsp__period; - n = -dp; - if ((stbsp__int32)n > pr) - n = pr; - i = n; - while (i) { - if ((((stbsp__uintptr)s) & 3) == 0) - break; - *s++ = '0'; - --i; - } - while (i >= 4) { - *(stbsp__uint32 *)s = 0x30303030; - s += 4; - i -= 4; - } - while (i) { - *s++ = '0'; - --i; - } - if ((stbsp__int32)(l + n) > pr) - l = pr - n; - i = l; - while (i) { - *s++ = *sn++; - --i; - } - tz = pr - (n + l); - cs = 1 + (3 << 24); // how many tens did we write (for commas below) - } else { - cs = (fl & STBSP__TRIPLET_COMMA) ? ((600 - (stbsp__uint32)dp) % 3) : 0; - if ((stbsp__uint32)dp >= l) { - // handle xxxx000*000.0 - n = 0; - for (;;) { - if ((fl & STBSP__TRIPLET_COMMA) && (++cs == 4)) { - cs = 0; - *s++ = stbsp__comma; - } else { - *s++ = sn[n]; - ++n; - if (n >= l) - break; - } - } - if (n < (stbsp__uint32)dp) { - n = dp - n; - if ((fl & STBSP__TRIPLET_COMMA) == 0) { - while (n) { - if ((((stbsp__uintptr)s) & 3) == 0) - break; - *s++ = '0'; - --n; - } - while (n >= 4) { - *(stbsp__uint32 *)s = 0x30303030; - s += 4; - n -= 4; - } - } - while (n) { - if ((fl & STBSP__TRIPLET_COMMA) && (++cs == 4)) { - cs = 0; - *s++ = stbsp__comma; - } else { - *s++ = '0'; - --n; - } - } - } - cs = (int)(s - (num + 64)) + (3 << 24); // cs is how many tens - if (pr) { - *s++ = stbsp__period; - tz = pr; - } - } else { - // handle xxxxx.xxxx000*000 - n = 0; - for (;;) { - if ((fl & STBSP__TRIPLET_COMMA) && (++cs == 4)) { - cs = 0; - *s++ = stbsp__comma; - } else { - *s++ = sn[n]; - ++n; - if (n >= (stbsp__uint32)dp) - break; - } - } - cs = (int)(s - (num + 64)) + (3 << 24); // cs is how many tens - if (pr) - *s++ = stbsp__period; - if ((l - dp) > (stbsp__uint32)pr) - l = pr + dp; - while (n < l) { - *s++ = sn[n]; - ++n; - } - tz = pr - (l - dp); - } - } - pr = 0; - - // handle k,m,g,t - if (fl & STBSP__METRIC_SUFFIX) { - char idx; - idx = 1; - if (fl & STBSP__METRIC_NOSPACE) - idx = 0; - tail[0] = idx; - tail[1] = ' '; - { - if (fl >> 24) { // SI kilo is 'k', JEDEC and SI kibits are 'K'. - if (fl & STBSP__METRIC_1024) - tail[idx + 1] = "_KMGT"[fl >> 24]; - else - tail[idx + 1] = "_kMGT"[fl >> 24]; - idx++; - // If printing kibits and not in jedec, add the 'i'. - if (fl & STBSP__METRIC_1024 && !(fl & STBSP__METRIC_JEDEC)) { - tail[idx + 1] = 'i'; - idx++; - } - tail[0] = idx; - } - } - }; - - flt_lead: - // get the length that we copied - l = (stbsp__uint32)(s - (num + 64)); - s = num + 64; - goto scopy; -#endif - - case 'B': // upper binary - case 'b': // lower binary - h = (f[0] == 'B') ? hexu : hex; - lead[0] = 0; - if (fl & STBSP__LEADING_0X) { - lead[0] = 2; - lead[1] = '0'; - lead[2] = h[0xb]; - } - l = (8 << 4) | (1 << 8); - goto radixnum; - - case 'o': // octal - h = hexu; - lead[0] = 0; - if (fl & STBSP__LEADING_0X) { - lead[0] = 1; - lead[1] = '0'; - } - l = (3 << 4) | (3 << 8); - goto radixnum; - - case 'p': // pointer - fl |= (sizeof(void *) == 8) ? STBSP__INTMAX : 0; - pr = sizeof(void *) * 2; - fl &= ~STBSP__LEADINGZERO; // 'p' only prints the pointer with zeros - // fall through - to X - - case 'X': // upper hex - case 'x': // lower hex - h = (f[0] == 'X') ? hexu : hex; - l = (4 << 4) | (4 << 8); - lead[0] = 0; - if (fl & STBSP__LEADING_0X) { - lead[0] = 2; - lead[1] = '0'; - lead[2] = h[16]; - } - radixnum: - // get the number - if (fl & STBSP__INTMAX) - n64 = va_arg(va, stbsp__uint64); - else - n64 = va_arg(va, stbsp__uint32); - - s = num + STBSP__NUMSZ; - dp = 0; - // clear tail, and clear leading if value is zero - tail[0] = 0; - if (n64 == 0) { - lead[0] = 0; - if (pr == 0) { - l = 0; - cs = 0; - goto scopy; - } - } - // convert to string - for (;;) { - *--s = h[n64 & ((1 << (l >> 8)) - 1)]; - n64 >>= (l >> 8); - if (!((n64) || ((stbsp__int32)((num + STBSP__NUMSZ) - s) < pr))) - break; - if (fl & STBSP__TRIPLET_COMMA) { - ++l; - if ((l & 15) == ((l >> 4) & 15)) { - l &= ~15; - *--s = stbsp__comma; - } - } - }; - // get the tens and the comma pos - cs = (stbsp__uint32)((num + STBSP__NUMSZ) - s) + ((((l >> 4) & 15)) << 24); - // get the length that we copied - l = (stbsp__uint32)((num + STBSP__NUMSZ) - s); - // copy it - goto scopy; - - case 'u': // unsigned - case 'i': - case 'd': // integer - // get the integer and abs it - if (fl & STBSP__INTMAX) { - stbsp__int64 i64 = va_arg(va, stbsp__int64); - n64 = (stbsp__uint64)i64; - if ((f[0] != 'u') && (i64 < 0)) { - n64 = (stbsp__uint64)-i64; - fl |= STBSP__NEGATIVE; - } - } else { - stbsp__int32 i = va_arg(va, stbsp__int32); - n64 = (stbsp__uint32)i; - if ((f[0] != 'u') && (i < 0)) { - n64 = (stbsp__uint32)-i; - fl |= STBSP__NEGATIVE; - } - } - -#ifndef STB_SPRINTF_NOFLOAT - if (fl & STBSP__METRIC_SUFFIX) { - if (n64 < 1024) - pr = 0; - else if (pr == -1) - pr = 1; - fv = (double)(stbsp__int64)n64; - goto doafloat; - } -#endif - - // convert to string - s = num + STBSP__NUMSZ; - l = 0; - - for (;;) { - // do in 32-bit chunks (avoid lots of 64-bit divides even with constant denominators) - char *o = s - 8; - if (n64 >= 100000000) { - n = (stbsp__uint32)(n64 % 100000000); - n64 /= 100000000; - } else { - n = (stbsp__uint32)n64; - n64 = 0; - } - if ((fl & STBSP__TRIPLET_COMMA) == 0) { - do { - s -= 2; - *(stbsp__uint16 *)s = *(stbsp__uint16 *)&stbsp__digitpair.pair[(n % 100) * 2]; - n /= 100; - } while (n); - } - while (n) { - if ((fl & STBSP__TRIPLET_COMMA) && (l++ == 3)) { - l = 0; - *--s = stbsp__comma; - --o; - } else { - *--s = (char)(n % 10) + '0'; - n /= 10; - } - } - if (n64 == 0) { - if ((s[0] == '0') && (s != (num + STBSP__NUMSZ))) - ++s; - break; - } - while (s != o) - if ((fl & STBSP__TRIPLET_COMMA) && (l++ == 3)) { - l = 0; - *--s = stbsp__comma; - --o; - } else { - *--s = '0'; - } - } - - tail[0] = 0; - stbsp__lead_sign(fl, lead); - - // get the length that we copied - l = (stbsp__uint32)((num + STBSP__NUMSZ) - s); - if (l == 0) { - *--s = '0'; - l = 1; - } - cs = l + (3 << 24); - if (pr < 0) - pr = 0; - - scopy: - // get fw=leading/trailing space, pr=leading zeros - if (pr < (stbsp__int32)l) - pr = l; - n = pr + lead[0] + tail[0] + tz; - if (fw < (stbsp__int32)n) - fw = n; - fw -= n; - pr -= l; - - // handle right justify and leading zeros - if ((fl & STBSP__LEFTJUST) == 0) { - if (fl & STBSP__LEADINGZERO) // if leading zeros, everything is in pr - { - pr = (fw > pr) ? fw : pr; - fw = 0; - } else { - fl &= ~STBSP__TRIPLET_COMMA; // if no leading zeros, then no commas - } - } - - // copy the spaces and/or zeros - if (fw + pr) { - stbsp__int32 i; - stbsp__uint32 c; - - // copy leading spaces (or when doing %8.4d stuff) - if ((fl & STBSP__LEFTJUST) == 0) - while (fw > 0) { - stbsp__cb_buf_clamp(i, fw); - fw -= i; - while (i) { - if ((((stbsp__uintptr)bf) & 3) == 0) - break; - *bf++ = ' '; - --i; - } - while (i >= 4) { - *(stbsp__uint32 *)bf = 0x20202020; - bf += 4; - i -= 4; - } - while (i) { - *bf++ = ' '; - --i; - } - stbsp__chk_cb_buf(1); - } - - // copy leader - sn = lead + 1; - while (lead[0]) { - stbsp__cb_buf_clamp(i, lead[0]); - lead[0] -= (char)i; - while (i) { - *bf++ = *sn++; - --i; - } - stbsp__chk_cb_buf(1); - } - - // copy leading zeros - c = cs >> 24; - cs &= 0xffffff; - cs = (fl & STBSP__TRIPLET_COMMA) ? ((stbsp__uint32)(c - ((pr + cs) % (c + 1)))) : 0; - while (pr > 0) { - stbsp__cb_buf_clamp(i, pr); - pr -= i; - if ((fl & STBSP__TRIPLET_COMMA) == 0) { - while (i) { - if ((((stbsp__uintptr)bf) & 3) == 0) - break; - *bf++ = '0'; - --i; - } - while (i >= 4) { - *(stbsp__uint32 *)bf = 0x30303030; - bf += 4; - i -= 4; - } - } - while (i) { - if ((fl & STBSP__TRIPLET_COMMA) && (cs++ == c)) { - cs = 0; - *bf++ = stbsp__comma; - } else - *bf++ = '0'; - --i; - } - stbsp__chk_cb_buf(1); - } - } - - // copy leader if there is still one - sn = lead + 1; - while (lead[0]) { - stbsp__int32 i; - stbsp__cb_buf_clamp(i, lead[0]); - lead[0] -= (char)i; - while (i) { - *bf++ = *sn++; - --i; - } - stbsp__chk_cb_buf(1); - } - - // copy the string - n = l; - while (n) { - stbsp__int32 i; - stbsp__cb_buf_clamp(i, n); - n -= i; - STBSP__UNALIGNED(while (i >= 4) { - *(stbsp__uint32 volatile *)bf = *(stbsp__uint32 volatile *)s; - bf += 4; - s += 4; - i -= 4; - }) - while (i) { - *bf++ = *s++; - --i; - } - stbsp__chk_cb_buf(1); - } - - // copy trailing zeros - while (tz) { - stbsp__int32 i; - stbsp__cb_buf_clamp(i, tz); - tz -= i; - while (i) { - if ((((stbsp__uintptr)bf) & 3) == 0) - break; - *bf++ = '0'; - --i; - } - while (i >= 4) { - *(stbsp__uint32 *)bf = 0x30303030; - bf += 4; - i -= 4; - } - while (i) { - *bf++ = '0'; - --i; - } - stbsp__chk_cb_buf(1); - } - - // copy tail if there is one - sn = tail + 1; - while (tail[0]) { - stbsp__int32 i; - stbsp__cb_buf_clamp(i, tail[0]); - tail[0] -= (char)i; - while (i) { - *bf++ = *sn++; - --i; - } - stbsp__chk_cb_buf(1); - } - - // handle the left justify - if (fl & STBSP__LEFTJUST) - if (fw > 0) { - while (fw) { - stbsp__int32 i; - stbsp__cb_buf_clamp(i, fw); - fw -= i; - while (i) { - if ((((stbsp__uintptr)bf) & 3) == 0) - break; - *bf++ = ' '; - --i; - } - while (i >= 4) { - *(stbsp__uint32 *)bf = 0x20202020; - bf += 4; - i -= 4; - } - while (i--) - *bf++ = ' '; - stbsp__chk_cb_buf(1); - } - } - break; - - default: // unknown, just copy code - s = num + STBSP__NUMSZ - 1; - *s = f[0]; - l = 1; - fw = fl = 0; - lead[0] = 0; - tail[0] = 0; - pr = 0; - dp = 0; - cs = 0; - goto scopy; - } - ++f; - } -endfmt: - - if (!callback) - *bf = 0; - else - stbsp__flush_cb(); - -done: - return tlen + (int)(bf - buf); -} - -// cleanup -#undef STBSP__LEFTJUST -#undef STBSP__LEADINGPLUS -#undef STBSP__LEADINGSPACE -#undef STBSP__LEADING_0X -#undef STBSP__LEADINGZERO -#undef STBSP__INTMAX -#undef STBSP__TRIPLET_COMMA -#undef STBSP__NEGATIVE -#undef STBSP__METRIC_SUFFIX -#undef STBSP__NUMSZ -#undef stbsp__chk_cb_bufL -#undef stbsp__chk_cb_buf -#undef stbsp__flush_cb -#undef stbsp__cb_buf_clamp - -// ============================================================================ -// wrapper functions - -STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(sprintf)(char *buf, char const *fmt, ...) -{ - int result; - va_list va; - va_start(va, fmt); - result = STB_SPRINTF_DECORATE(vsprintfcb)(0, 0, buf, fmt, va); - va_end(va); - return result; -} - -typedef struct stbsp__context { - char *buf; - int count; - int length; - char tmp[STB_SPRINTF_MIN]; -} stbsp__context; - -static char *stbsp__clamp_callback(const char *buf, void *user, int len) -{ - stbsp__context *c = (stbsp__context *)user; - c->length += len; - - if (len > c->count) - len = c->count; - - if (len) { - if (buf != c->buf) { - const char *s, *se; - char *d; - d = c->buf; - s = buf; - se = buf + len; - do { - *d++ = *s++; - } while (s < se); - } - c->buf += len; - c->count -= len; - } - - if (c->count <= 0) - return c->tmp; - return (c->count >= STB_SPRINTF_MIN) ? c->buf : c->tmp; // go direct into buffer if you can -} - -static char * stbsp__count_clamp_callback( const char * buf, void * user, int len ) -{ - stbsp__context * c = (stbsp__context*)user; - (void) sizeof(buf); - - c->length += len; - return c->tmp; // go direct into buffer if you can -} - -STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( vsnprintf )( char * buf, int count, char const * fmt, va_list va ) -{ - stbsp__context c; - - if ( count == 0 ) - { - c.length = 0; - - STB_SPRINTF_DECORATE( vsprintfcb )( stbsp__count_clamp_callback, &c, c.tmp, fmt, va ); - } - else - { - int l; - - c.buf = buf; - c.count = count; - c.length = 0; - - STB_SPRINTF_DECORATE( vsprintfcb )( stbsp__clamp_callback, &c, stbsp__clamp_callback(0,&c,0), fmt, va ); - - // zero-terminate - l = (int)( c.buf - buf ); - if ( l >= count ) // should never be greater, only equal (or less) than count - l = count - 1; - buf[l] = 0; - } - - return c.length; -} - -STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(snprintf)(char *buf, int count, char const *fmt, ...) -{ - int result; - va_list va; - va_start(va, fmt); - - result = STB_SPRINTF_DECORATE(vsnprintf)(buf, count, fmt, va); - va_end(va); - - return result; -} - -STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintf)(char *buf, char const *fmt, va_list va) -{ - return STB_SPRINTF_DECORATE(vsprintfcb)(0, 0, buf, fmt, va); -} - -// ======================================================================= -// low level float utility functions - -#ifndef STB_SPRINTF_NOFLOAT - -// copies d to bits w/ strict aliasing (this compiles to nothing on /Ox) -#define STBSP__COPYFP(dest, src) \ - { \ - int cn; \ - for (cn = 0; cn < 8; cn++) \ - ((char *)&dest)[cn] = ((char *)&src)[cn]; \ - } - -// get float info -static stbsp__int32 stbsp__real_to_parts(stbsp__int64 *bits, stbsp__int32 *expo, double value) -{ - double d; - stbsp__int64 b = 0; - - // load value and round at the frac_digits - d = value; - - STBSP__COPYFP(b, d); - - *bits = b & ((((stbsp__uint64)1) << 52) - 1); - *expo = (stbsp__int32)(((b >> 52) & 2047) - 1023); - - return (stbsp__int32)((stbsp__uint64) b >> 63); -} - -static double const stbsp__bot[23] = { - 1e+000, 1e+001, 1e+002, 1e+003, 1e+004, 1e+005, 1e+006, 1e+007, 1e+008, 1e+009, 1e+010, 1e+011, - 1e+012, 1e+013, 1e+014, 1e+015, 1e+016, 1e+017, 1e+018, 1e+019, 1e+020, 1e+021, 1e+022 -}; -static double const stbsp__negbot[22] = { - 1e-001, 1e-002, 1e-003, 1e-004, 1e-005, 1e-006, 1e-007, 1e-008, 1e-009, 1e-010, 1e-011, - 1e-012, 1e-013, 1e-014, 1e-015, 1e-016, 1e-017, 1e-018, 1e-019, 1e-020, 1e-021, 1e-022 -}; -static double const stbsp__negboterr[22] = { - -5.551115123125783e-018, -2.0816681711721684e-019, -2.0816681711721686e-020, -4.7921736023859299e-021, -8.1803053914031305e-022, 4.5251888174113741e-023, - 4.5251888174113739e-024, -2.0922560830128471e-025, -6.2281591457779853e-026, -3.6432197315497743e-027, 6.0503030718060191e-028, 2.0113352370744385e-029, - -3.0373745563400371e-030, 1.1806906454401013e-032, -7.7705399876661076e-032, 2.0902213275965398e-033, -7.1542424054621921e-034, -7.1542424054621926e-035, - 2.4754073164739869e-036, 5.4846728545790429e-037, 9.2462547772103625e-038, -4.8596774326570872e-039 -}; -static double const stbsp__top[13] = { - 1e+023, 1e+046, 1e+069, 1e+092, 1e+115, 1e+138, 1e+161, 1e+184, 1e+207, 1e+230, 1e+253, 1e+276, 1e+299 -}; -static double const stbsp__negtop[13] = { - 1e-023, 1e-046, 1e-069, 1e-092, 1e-115, 1e-138, 1e-161, 1e-184, 1e-207, 1e-230, 1e-253, 1e-276, 1e-299 -}; -static double const stbsp__toperr[13] = { - 8388608, - 6.8601809640529717e+028, - -7.253143638152921e+052, - -4.3377296974619174e+075, - -1.5559416129466825e+098, - -3.2841562489204913e+121, - -3.7745893248228135e+144, - -1.7356668416969134e+167, - -3.8893577551088374e+190, - -9.9566444326005119e+213, - 6.3641293062232429e+236, - -5.2069140800249813e+259, - -5.2504760255204387e+282 -}; -static double const stbsp__negtoperr[13] = { - 3.9565301985100693e-040, -2.299904345391321e-063, 3.6506201437945798e-086, 1.1875228833981544e-109, - -5.0644902316928607e-132, -6.7156837247865426e-155, -2.812077463003139e-178, -5.7778912386589953e-201, - 7.4997100559334532e-224, -4.6439668915134491e-247, -6.3691100762962136e-270, -9.436808465446358e-293, - 8.0970921678014997e-317 -}; - -#if defined(_MSC_VER) && (_MSC_VER <= 1200) -static stbsp__uint64 const stbsp__powten[20] = { - 1, - 10, - 100, - 1000, - 10000, - 100000, - 1000000, - 10000000, - 100000000, - 1000000000, - 10000000000, - 100000000000, - 1000000000000, - 10000000000000, - 100000000000000, - 1000000000000000, - 10000000000000000, - 100000000000000000, - 1000000000000000000, - 10000000000000000000U -}; -#define stbsp__tento19th ((stbsp__uint64)1000000000000000000) -#else -static stbsp__uint64 const stbsp__powten[20] = { - 1, - 10, - 100, - 1000, - 10000, - 100000, - 1000000, - 10000000, - 100000000, - 1000000000, - 10000000000ULL, - 100000000000ULL, - 1000000000000ULL, - 10000000000000ULL, - 100000000000000ULL, - 1000000000000000ULL, - 10000000000000000ULL, - 100000000000000000ULL, - 1000000000000000000ULL, - 10000000000000000000ULL -}; -#define stbsp__tento19th (1000000000000000000ULL) -#endif - -#define stbsp__ddmulthi(oh, ol, xh, yh) \ - { \ - double ahi = 0, alo, bhi = 0, blo; \ - stbsp__int64 bt; \ - oh = xh * yh; \ - STBSP__COPYFP(bt, xh); \ - bt &= ((~(stbsp__uint64)0) << 27); \ - STBSP__COPYFP(ahi, bt); \ - alo = xh - ahi; \ - STBSP__COPYFP(bt, yh); \ - bt &= ((~(stbsp__uint64)0) << 27); \ - STBSP__COPYFP(bhi, bt); \ - blo = yh - bhi; \ - ol = ((ahi * bhi - oh) + ahi * blo + alo * bhi) + alo * blo; \ - } - -#define stbsp__ddtoS64(ob, xh, xl) \ - { \ - double ahi = 0, alo, vh, t; \ - ob = (stbsp__int64)xh; \ - vh = (double)ob; \ - ahi = (xh - vh); \ - t = (ahi - xh); \ - alo = (xh - (ahi - t)) - (vh + t); \ - ob += (stbsp__int64)(ahi + alo + xl); \ - } - -#define stbsp__ddrenorm(oh, ol) \ - { \ - double s; \ - s = oh + ol; \ - ol = ol - (s - oh); \ - oh = s; \ - } - -#define stbsp__ddmultlo(oh, ol, xh, xl, yh, yl) ol = ol + (xh * yl + xl * yh); - -#define stbsp__ddmultlos(oh, ol, xh, yl) ol = ol + (xh * yl); - -static void stbsp__raise_to_power10(double *ohi, double *olo, double d, stbsp__int32 power) // power can be -323 to +350 -{ - double ph, pl; - if ((power >= 0) && (power <= 22)) { - stbsp__ddmulthi(ph, pl, d, stbsp__bot[power]); - } else { - stbsp__int32 e, et, eb; - double p2h, p2l; - - e = power; - if (power < 0) - e = -e; - et = (e * 0x2c9) >> 14; /* %23 */ - if (et > 13) - et = 13; - eb = e - (et * 23); - - ph = d; - pl = 0.0; - if (power < 0) { - if (eb) { - --eb; - stbsp__ddmulthi(ph, pl, d, stbsp__negbot[eb]); - stbsp__ddmultlos(ph, pl, d, stbsp__negboterr[eb]); - } - if (et) { - stbsp__ddrenorm(ph, pl); - --et; - stbsp__ddmulthi(p2h, p2l, ph, stbsp__negtop[et]); - stbsp__ddmultlo(p2h, p2l, ph, pl, stbsp__negtop[et], stbsp__negtoperr[et]); - ph = p2h; - pl = p2l; - } - } else { - if (eb) { - e = eb; - if (eb > 22) - eb = 22; - e -= eb; - stbsp__ddmulthi(ph, pl, d, stbsp__bot[eb]); - if (e) { - stbsp__ddrenorm(ph, pl); - stbsp__ddmulthi(p2h, p2l, ph, stbsp__bot[e]); - stbsp__ddmultlos(p2h, p2l, stbsp__bot[e], pl); - ph = p2h; - pl = p2l; - } - } - if (et) { - stbsp__ddrenorm(ph, pl); - --et; - stbsp__ddmulthi(p2h, p2l, ph, stbsp__top[et]); - stbsp__ddmultlo(p2h, p2l, ph, pl, stbsp__top[et], stbsp__toperr[et]); - ph = p2h; - pl = p2l; - } - } - } - stbsp__ddrenorm(ph, pl); - *ohi = ph; - *olo = pl; -} - -// given a float value, returns the significant bits in bits, and the position of the -// decimal point in decimal_pos. +/-INF and NAN are specified by special values -// returned in the decimal_pos parameter. -// frac_digits is absolute normally, but if you want from first significant digits (got %g and %e), or in 0x80000000 -static stbsp__int32 stbsp__real_to_str(char const **start, stbsp__uint32 *len, char *out, stbsp__int32 *decimal_pos, double value, stbsp__uint32 frac_digits) -{ - double d; - stbsp__int64 bits = 0; - stbsp__int32 expo, e, ng, tens; - - d = value; - STBSP__COPYFP(bits, d); - expo = (stbsp__int32)((bits >> 52) & 2047); - ng = (stbsp__int32)((stbsp__uint64) bits >> 63); - if (ng) - d = -d; - - if (expo == 2047) // is nan or inf? - { - *start = (bits & ((((stbsp__uint64)1) << 52) - 1)) ? "NaN" : "Inf"; - *decimal_pos = STBSP__SPECIAL; - *len = 3; - return ng; - } - - if (expo == 0) // is zero or denormal - { - if (((stbsp__uint64) bits << 1) == 0) // do zero - { - *decimal_pos = 1; - *start = out; - out[0] = '0'; - *len = 1; - return ng; - } - // find the right expo for denormals - { - stbsp__int64 v = ((stbsp__uint64)1) << 51; - while ((bits & v) == 0) { - --expo; - v >>= 1; - } - } - } - - // find the decimal exponent as well as the decimal bits of the value - { - double ph, pl; - - // log10 estimate - very specifically tweaked to hit or undershoot by no more than 1 of log10 of all expos 1..2046 - tens = expo - 1023; - tens = (tens < 0) ? ((tens * 617) / 2048) : (((tens * 1233) / 4096) + 1); - - // move the significant bits into position and stick them into an int - stbsp__raise_to_power10(&ph, &pl, d, 18 - tens); - - // get full as much precision from double-double as possible - stbsp__ddtoS64(bits, ph, pl); - - // check if we undershot - if (((stbsp__uint64)bits) >= stbsp__tento19th) - ++tens; - } - - // now do the rounding in integer land - frac_digits = (frac_digits & 0x80000000) ? ((frac_digits & 0x7ffffff) + 1) : (tens + frac_digits); - if ((frac_digits < 24)) { - stbsp__uint32 dg = 1; - if ((stbsp__uint64)bits >= stbsp__powten[9]) - dg = 10; - while ((stbsp__uint64)bits >= stbsp__powten[dg]) { - ++dg; - if (dg == 20) - goto noround; - } - if (frac_digits < dg) { - stbsp__uint64 r; - // add 0.5 at the right position and round - e = dg - frac_digits; - if ((stbsp__uint32)e >= 24) - goto noround; - r = stbsp__powten[e]; - bits = bits + (r / 2); - if ((stbsp__uint64)bits >= stbsp__powten[dg]) - ++tens; - bits /= r; - } - noround:; - } - - // kill long trailing runs of zeros - if (bits) { - stbsp__uint32 n; - for (;;) { - if (bits <= 0xffffffff) - break; - if (bits % 1000) - goto donez; - bits /= 1000; - } - n = (stbsp__uint32)bits; - while ((n % 1000) == 0) - n /= 1000; - bits = n; - donez:; - } - - // convert to string - out += 64; - e = 0; - for (;;) { - stbsp__uint32 n; - char *o = out - 8; - // do the conversion in chunks of U32s (avoid most 64-bit divides, worth it, constant denomiators be damned) - if (bits >= 100000000) { - n = (stbsp__uint32)(bits % 100000000); - bits /= 100000000; - } else { - n = (stbsp__uint32)bits; - bits = 0; - } - while (n) { - out -= 2; - *(stbsp__uint16 *)out = *(stbsp__uint16 *)&stbsp__digitpair.pair[(n % 100) * 2]; - n /= 100; - e += 2; - } - if (bits == 0) { - if ((e) && (out[0] == '0')) { - ++out; - --e; - } - break; - } - while (out != o) { - *--out = '0'; - ++e; - } - } - - *decimal_pos = tens; - *start = out; - *len = e; - return ng; -} - -#undef stbsp__ddmulthi -#undef stbsp__ddrenorm -#undef stbsp__ddmultlo -#undef stbsp__ddmultlos -#undef STBSP__SPECIAL -#undef STBSP__COPYFP - -#endif // STB_SPRINTF_NOFLOAT - -// clean up -#undef stbsp__uint16 -#undef stbsp__uint32 -#undef stbsp__int32 -#undef stbsp__uint64 -#undef stbsp__int64 -#undef STBSP__UNALIGNED - -#endif // STB_SPRINTF_IMPLEMENTATION - -/* ------------------------------------------------------------------------------- -This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------- -ALTERNATIVE A - MIT License -Copyright (c) 2017 Sean Barrett -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. ------------------------------------------------------------------------------- -ALTERNATIVE B - Public Domain (www.unlicense.org) -This is free and unencumbered software released into the public domain. -Anyone is free to copy, modify, publish, use, compile, sell, or distribute this -software, either in source code form or as a compiled binary, for any purpose, -commercial or non-commercial, and by any means. -In jurisdictions that recognize copyright laws, the author or authors of this -software dedicate any and all copyright interest in the software to the public -domain. We make this dedication for the benefit of the public at large and to -the detriment of our heirs and successors. We intend this dedication to be an -overt act of relinquishment in perpetuity of all present and future rights to -this software under copyright law. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- -*/ diff --git a/src/common/init.c b/src/common/init.c index f27052fdb..96117c66e 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -266,9 +266,6 @@ void ffListFeatures(void) #if FF_HAVE_EMBEDDED_PCIIDS "Embedded pciids\n" #endif - #if FF_USE_STBPRINTF - "stb_printf\n" - #endif "" , stdout); } diff --git a/src/common/time.h b/src/common/time.h index 76bdcc094..588ba7847 100644 --- a/src/common/time.h +++ b/src/common/time.h @@ -9,8 +9,6 @@ #include #endif -#include "util/stb_printf.h" - static inline double ffTimeGetTick(void) //In msec { #ifdef _WIN32 diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 21c722fae..4387a5d7b 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -20,15 +20,8 @@ void ffStrbufInitVF(FFstrbuf* strbuf, const char* format, va_list arguments) { assert(format != NULL); - #ifndef FF_USE_STBPRINTF int len = vasprintf(&strbuf->chars, format, arguments); assert(len >= 0); - #else - int len = vsnprintf(NULL, 0, format, arguments); - assert(len >= 0); - strbuf->chars = (char*) malloc(sizeof(char) * (len + 1)); - vsnprintf(strbuf->chars, len + 1, format, arguments); - #endif strbuf->allocated = (uint32_t)(len + 1); strbuf->length = (uint32_t)len; diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index 243437e9d..fa4a9da87 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -18,8 +18,6 @@ #define FASTFETCH_STRBUF_DEFAULT_ALLOC 32 -#include "stb_printf.h" - typedef struct FFstrbuf { uint32_t allocated; diff --git a/src/util/stb_printf.c b/src/util/stb_printf.c deleted file mode 100644 index 0f5212efb..000000000 --- a/src/util/stb_printf.c +++ /dev/null @@ -1,3 +0,0 @@ -#define STB_SPRINTF_IMPLEMENTATION 1 -#pragma GCC diagnostic ignored "-Wsign-conversion" -#include "3rdparty/stb/stb_sprintf.h" diff --git a/src/util/stb_printf.h b/src/util/stb_printf.h deleted file mode 100644 index 62250d171..000000000 --- a/src/util/stb_printf.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#ifdef FF_USE_STBPRINTF - -#include -#include -#include "3rdparty/stb/stb_sprintf.h" - -static inline char *STB_SPRINTF_DECORATE(printf_callback)(const char* __restrict buf, void* __restrict user, int len) -{ - fwrite(buf, 1, (uint32_t) len, (FILE *)user); - return (char *) buf; -} - -static inline int STB_SPRINTF_DECORATE(vfprintf)(FILE* file, char const* __restrict fmt, va_list va) -{ - char tmp[STB_SPRINTF_MIN]; - return STB_SPRINTF_DECORATE(vsprintfcb)(STB_SPRINTF_DECORATE(printf_callback), file, tmp, fmt, va); -} -#define vfprintf(...) STB_SPRINTF_DECORATE(vfprintf)(__VA_ARGS__) - -static inline int STBSP__ATTRIBUTE_FORMAT(1,2) STB_SPRINTF_DECORATE(printf)(char const* __restrict fmt, ...) -{ - va_list va; - va_start(va, fmt); - int result = STB_SPRINTF_DECORATE(vfprintf)(stdout, fmt, va); - va_end(va); - return result; -} -#define printf(...) STB_SPRINTF_DECORATE(printf)(__VA_ARGS__) - -static inline int STBSP__ATTRIBUTE_FORMAT(2,3) STB_SPRINTF_DECORATE(fprintf)(FILE* __restrict file, char const* __restrict fmt, ...) -{ - va_list va; - va_start(va, fmt); - int result = STB_SPRINTF_DECORATE(vfprintf)(file, fmt, va); - va_end(va); - return result; -} -#define fprintf(...) STB_SPRINTF_DECORATE(fprintf)(__VA_ARGS__) - -#define vsprintf(...) STB_SPRINTF_DECORATE(vsprintf)(__VA_ARGS__) - -#define vsnprintf(...) STB_SPRINTF_DECORATE(vsnprintf)(__VA_ARGS__) - -#define sprintf(...) STB_SPRINTF_DECORATE(sprintf)(__VA_ARGS__) - -#define snprintf(...) STB_SPRINTF_DECORATE(snprintf)(__VA_ARGS__) - -#endif From 544333415680b5affcba83463c686c984b5231da Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 29 Oct 2024 08:51:44 +0800 Subject: [PATCH 22/72] DisplayServer (Linux): silense compiler warnings --- src/detection/displayserver/linux/wayland/kde-output.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/detection/displayserver/linux/wayland/kde-output.c b/src/detection/displayserver/linux/wayland/kde-output.c index 1c4576dd4..beac7b635 100644 --- a/src/detection/displayserver/linux/wayland/kde-output.c +++ b/src/detection/displayserver/linux/wayland/kde-output.c @@ -113,7 +113,11 @@ static void waylandKdeNameListener(void* data, FF_MAYBE_UNUSED struct kde_output WaylandDisplay* display = data; display->type = ffdsGetDisplayType(name); // As display->id is used as an internal identifier, we don't need it to be NUL terminated + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstringop-truncation" strncpy((char*) &display->id, name, sizeof(display->id)); + #pragma GCC diagnostic pop + ffStrbufAppendS(&display->name, name); } From 0406f5c2b2fbbcc2e50aa9c6b2c1e7198a32e126 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 29 Oct 2024 09:08:09 +0800 Subject: [PATCH 23/72] CI (NetBSD): add more dependencies --- .github/workflows/ci.yml | 4 ++-- CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a85e59b5..12baae96d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -381,7 +381,7 @@ jobs: run: | uname -a sudo pkg update - sudo pkg install -y cmake git pkgconf binutils wayland vulkan-headers vulkan-loader libxcb libXrandr libX11 libdrm libelf glib dconf dbus sqlite3-tcl xfce4-conf egl libosmesa opencl ocl-icd v4l_compat py311-requests + sudo pkg install -y cmake git pkgconf binutils wayland vulkan-headers vulkan-loader libxcb libXrandr libX11 libdrm glib dconf dbus sqlite3-tcl xfce4-conf egl libosmesa opencl ocl-icd v4l_compat py311-requests cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On . cmake --build . --target package --verbose -j4 ./fastfetch --list-features @@ -453,7 +453,7 @@ jobs: version: '10.0' run: | uname -a - sudo pkgin -y install cmake git pkgconf + sudo pkgin -y install cmake git pkgconf wayland vulkan-headers dconf dbus sqlite3 ImageMagick chafa pulseaudio opencl-headers ocl-icd libv4l py312-requests cmake -DSET_TWEAK=Off -DBUILD_TESTS=On . cmake --build . --target package --verbose -j4 ./fastfetch --list-features diff --git a/CMakeLists.txt b/CMakeLists.txt index a14439f50..e7c280b8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1286,7 +1286,7 @@ ff_lib_enable(EGL "egl" "EGL" ) -if(NOT OpenBSD) +if(NOT OpenBSD AND NOT NetBSD) ff_lib_enable(GLX "glx" "GLX" From e22b58b26e15b11241620d3a90b31407b490ab69 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 29 Oct 2024 09:13:59 +0800 Subject: [PATCH 24/72] CI (NetBSD): try fixing build --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 12baae96d..7b4133656 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -453,7 +453,7 @@ jobs: version: '10.0' run: | uname -a - sudo pkgin -y install cmake git pkgconf wayland vulkan-headers dconf dbus sqlite3 ImageMagick chafa pulseaudio opencl-headers ocl-icd libv4l py312-requests + sudo pkgin -y install cmake git pkgconf wayland vulkan-headers dconf dbus sqlite3 ImageMagick pulseaudio opencl-headers ocl-icd libv4l py312-requests cmake -DSET_TWEAK=Off -DBUILD_TESTS=On . cmake --build . --target package --verbose -j4 ./fastfetch --list-features From c6c680340375defad086ea05046c2d7325aa7bfa Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 29 Oct 2024 09:22:09 +0800 Subject: [PATCH 25/72] CMake (*BSD): detect videodev2 --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b4133656..fee767f1a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -417,7 +417,7 @@ jobs: version: '7.5' run: | uname -a - sudo pkg_add -r cmake git pkgconf wayland vulkan-headers vulkan-loader glib2 dconf dbus sqlite3 xfconf imagemagick chafa pulseaudio + sudo pkg_add -r cmake git pkgconf wayland vulkan-headers vulkan-loader glib2 dconf dbus sqlite3 xfconf imagemagick chafa pulseaudio libv4l cmake -DSET_TWEAK=Off -DBUILD_TESTS=On . cmake --build . --target package --verbose -j4 ./fastfetch --list-features diff --git a/CMakeLists.txt b/CMakeLists.txt index e7c280b8c..be038300b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1473,9 +1473,9 @@ if(WIN32) set(CMAKE_CXX_STANDARD 17) endif() if(FreeBSD) - set(CMAKE_REQUIRED_INCLUDES "/usr/local/include" "/usr/include") + set(CMAKE_REQUIRED_INCLUDES "/usr/local/include" "/usr/include") endif() -if(LINUX OR FreeBSD) +if(LINUX OR FreeBSD OR OpenBSD OR NetBSD) CHECK_INCLUDE_FILE("linux/videodev2.h" HAVE_LINUX_VIDEODEV2) if(HAVE_LINUX_VIDEODEV2) target_compile_definitions(libfastfetch PRIVATE FF_HAVE_LINUX_VIDEODEV2=1) From 6ccc6124d0324ccc705a22e1b20c4accc33bf6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 30 Oct 2024 09:28:18 +0800 Subject: [PATCH 26/72] Keyboard (Linux): silence compiler warnings --- src/detection/keyboard/keyboard_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/detection/keyboard/keyboard_linux.c b/src/detection/keyboard/keyboard_linux.c index 8952ca674..e2d482150 100644 --- a/src/detection/keyboard/keyboard_linux.c +++ b/src/detection/keyboard/keyboard_linux.c @@ -31,9 +31,9 @@ const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) if (pend == eventid) continue; // Ignore duplicate entries - if (flags & (1 << index)) + if (flags & (1UL << index)) continue; - flags |= (1 << index); + flags |= (1UL << index); ffStrbufSetF(&path, "/sys/class/input/event%s/device/name", eventid); From 3f41306c9170747009afaba9d64b45aee8f3fbc6 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Wed, 30 Oct 2024 22:42:46 +0800 Subject: [PATCH 27/72] Packages (NetBSD): add support --- CMakeLists.txt | 2 +- src/detection/packages/packages_obsd.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index be038300b..f024d55a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -724,7 +724,7 @@ elseif(NetBSD) src/detection/netio/netio_nosupport.c src/detection/opengl/opengl_linux.c src/detection/os/os_nbsd.c - src/detection/packages/packages_nosupport.c + src/detection/packages/packages_obsd.c src/detection/poweradapter/poweradapter_nosupport.c src/detection/processes/processes_nosupport.c src/detection/gtk_qt/qt.c diff --git a/src/detection/packages/packages_obsd.c b/src/detection/packages/packages_obsd.c index c7fadcbdf..79d383ed4 100644 --- a/src/detection/packages/packages_obsd.c +++ b/src/detection/packages/packages_obsd.c @@ -26,6 +26,12 @@ void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options) { if (!(options->disabled & FF_PACKAGES_FLAG_PKG_BIT)) { - result->pkg = getNumElementsImpl(FASTFETCH_TARGET_DIR_ROOT "/var/db/pkg", DT_DIR); + result->pkg = getNumElementsImpl(FASTFETCH_TARGET_DIR_ROOT + #if __OpenBSD + "/var/db/pkg" + #else + "/usr/pkg/pkgdb" + #endif + , DT_DIR); } } From 229d5f899c9af643f0398404628e5e7207a68ee6 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Wed, 30 Oct 2024 23:29:05 +0800 Subject: [PATCH 28/72] CPU (NetBSD): add support --- CMakeLists.txt | 2 +- src/detection/cpu/cpu_bsd.c | 5 ---- src/detection/cpu/cpu_nbsd.c | 57 ++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 src/detection/cpu/cpu_nbsd.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f024d55a6..17568c9af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -682,7 +682,7 @@ elseif(NetBSD) src/detection/brightness/brightness_bsd.c src/detection/btrfs/btrfs_nosupport.c src/detection/chassis/chassis_nbsd.c - src/detection/cpu/cpu_bsd.c + src/detection/cpu/cpu_nbsd.c src/detection/cpucache/cpucache_nosupport.c src/detection/cpuusage/cpuusage_bsd.c src/detection/cursor/cursor_linux.c diff --git a/src/detection/cpu/cpu_bsd.c b/src/detection/cpu/cpu_bsd.c index 7bf464072..7a5b72144 100644 --- a/src/detection/cpu/cpu_bsd.c +++ b/src/detection/cpu/cpu_bsd.c @@ -25,13 +25,8 @@ static const char* detectThermalTemp(double* current) const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) { - #if __NetBSD__ - if (ffSysctlGetString("machdep.cpu_brand", &cpu->name) != NULL) - return "sysctlbyname(machdep.cpu_brand) failed"; - #else if (ffSysctlGetString("hw.model", &cpu->name) != NULL) return "sysctlbyname(hw.model) failed"; - #endif cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1); cpu->coresLogical = cpu->coresPhysical; diff --git a/src/detection/cpu/cpu_nbsd.c b/src/detection/cpu/cpu_nbsd.c new file mode 100644 index 000000000..0a78ed146 --- /dev/null +++ b/src/detection/cpu/cpu_nbsd.c @@ -0,0 +1,57 @@ +#include "cpu.h" +#include "common/sysctl.h" +#include + +static const char* detectCpuTemp(double* current) +{ + int temp = ffSysctlGetInt("dev.cpu.0.temperature", -999999); + if (temp == -999999) + return "ffSysctlGetInt(\"dev.cpu.0.temperature\") failed"; + + // In tenth of degrees Kelvin + *current = (double) temp / 10 - 273.15; + return NULL; +} + +static const char* detectThermalTemp(double* current) +{ + int temp = ffSysctlGetInt("hw.acpi.thermal.tz0.temperature", -999999); + if (temp == -999999) + return "ffSysctlGetInt(\"hw.acpi.thermal.tz0.temperature\") failed"; + + // In tenth of degrees Kelvin + *current = (double) temp / 10 - 273.15; + return NULL; +} + +const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) +{ + if (ffSysctlGetString("machdep.cpu_brand", &cpu->name) != NULL) + { + if (ffSysctlGetString("machdep.dmi.processor-version", &cpu->name) != NULL) + return "sysctlbyname(machdep.cpu_brand) failed"; + } + + cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1); + cpu->coresLogical = cpu->coresPhysical; + cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.ncpuonline", cpu->coresLogical); + + ffCPUDetectSpeedByCpuid(cpu); + + { + struct clockinfo info; + size_t length = sizeof(info); + if (sysctl((int[]) {CTL_KERN, KERN_CLOCKRATE}, 2, &info, &length, NULL, 0) == 0) + cpu->frequencyBase = (uint32_t) info.hz / 1000; + } + + cpu->temperature = FF_CPU_TEMP_UNSET; + + if (options->temp) + { + if (detectCpuTemp(&cpu->temperature) != NULL) + detectThermalTemp(&cpu->temperature); + } + + return NULL; +} From 49902d8c2f4fe852a9286063c206fce5b9132b00 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Wed, 30 Oct 2024 23:46:40 +0800 Subject: [PATCH 29/72] Disk (NetBSD): fix disk size detection --- src/detection/disk/disk_bsd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index 659314040..9fa19e311 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -11,6 +11,7 @@ #define getfsstat(...) getvfsstat(__VA_ARGS__) #define statfs statvfs #define f_flags f_flag +#define f_bsize f_frsize #endif #ifdef __FreeBSD__ From c3d04d067d02df02e5bc3b3698fd6404fdd3a2b8 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 31 Oct 2024 00:06:37 +0800 Subject: [PATCH 30/72] Platform (NetBSD): fix exe path detection --- src/util/platform/FFPlatform_unix.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index ff5fe5b7b..b0d0ac1bd 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -29,11 +29,11 @@ static void getExePath(FFPlatform* platform) if(sysctl( (int[]){CTL_KERN, #ifdef __FreeBSD__ - KERN_PROC, + KERN_PROC, KERN_PROC_PATHNAME, (int) getpid() #else - KERN_PROC_ARGS, + KERN_PROC_ARGS, (int) getpid(), KERN_PROC_PATHNAME #endif - KERN_PROC_PATHNAME, (int) getpid()}, 4, + }, 4, exePath, &exePathLen, NULL, 0 ) < 0) @@ -185,7 +185,7 @@ static void getSysinfo(FFPlatformSysinfo* info, const struct utsname* uts) ffStrbufAppendS(&info->architecture, uts->machine); ffStrbufInit(&info->displayVersion); - #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) + #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) size_t length = sizeof(info->pageSize); sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &info->pageSize, &length, NULL, 0); #else From cae8286621195fce45c9f0d7409b0c994013aae5 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 31 Oct 2024 00:25:40 +0800 Subject: [PATCH 31/72] Shell / Terminal: fix proc path detection --- src/common/processing_linux.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index b9045bb6c..718879999 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -215,11 +215,11 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons if(exePath && sysctl( (int[]){CTL_KERN, #if __FreeBSD__ - KERN_PROC, + KERN_PROC, KERN_PROC_PATHNAME, pid #else - KERN_PROC_ARGS, + KERN_PROC_ARGS, pid, KERN_PROC_PATHNAME #endif - KERN_PROC_PATHNAME, pid}, 4, + }, 4, args, &size, NULL, 0 ) == 0) @@ -229,11 +229,11 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons if(sysctl( (int[]){CTL_KERN, #if __FreeBSD__ - KERN_PROC, KERN_PROC_ARGS, + KERN_PROC, KERN_PROC_ARGS, pid #else - KERN_PROC_ARGS, KERN_PROC_ARGV, + KERN_PROC_ARGS, pid, KERN_PROC_ARGV, #endif - pid}, 4, + }, 4, args, &size, NULL, 0 ) == 0) @@ -398,10 +398,10 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i struct kinfo_proc2 proc; size_t size = sizeof(proc); if(sysctl( - (int[]){CTL_KERN, KERN_PROC2, KERN_PROC_PID, pid}, 4, + (int[]){CTL_KERN, KERN_PROC2, KERN_PROC_PID, pid, sizeof(proc), 1}, 6, &proc, &size, NULL, 0 - )) + ) != 0) return "sysctl(KERN_PROC_PID) failed"; ffStrbufSetS(name, proc.p_comm); From c693e5ab5f480a13c53c7e4520e4a6bfcd469bb3 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 31 Oct 2024 00:40:29 +0800 Subject: [PATCH 32/72] Bios (NetBSD): try detecting boot method --- src/detection/bios/bios_nbsd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/bios/bios_nbsd.c b/src/detection/bios/bios_nbsd.c index 056eb2d41..3330a74f4 100644 --- a/src/detection/bios/bios_nbsd.c +++ b/src/detection/bios/bios_nbsd.c @@ -10,6 +10,6 @@ const char* ffDetectBios(FFBiosResult* bios) ffCleanUpSmbiosValue(&bios->version); if (ffSysctlGetString("machdep.dmi.bios-vendor", &bios->vendor) == NULL) ffCleanUpSmbiosValue(&bios->vendor); - + ffSysctlGetString("machdep.bootmethod", &bios->type); return NULL; } From d4c7b53ded9e27d8ea661e5bbf586f0471c83012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 31 Oct 2024 09:33:23 +0800 Subject: [PATCH 33/72] CPU (Android): add QS8E --- src/detection/cpu/cpu_linux.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/detection/cpu/cpu_linux.c b/src/detection/cpu/cpu_linux.c index 9533effd5..91c8ba46f 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -89,7 +89,9 @@ static void detectQualcomm(FFCPUResult* cpu) { // https://en.wikipedia.org/wiki/List_of_Qualcomm_Snapdragon_systems_on_chips - if (ffStrbufEqualS(&cpu->name, "SM8635")) + if (ffStrbufEqualS(&cpu->name, "SM8750")) + ffStrbufSetStatic(&cpu->name, "Qualcomm Snapdragon 8 Elite [SM8750]"); + else if (ffStrbufEqualS(&cpu->name, "SM8635")) ffStrbufSetStatic(&cpu->name, "Qualcomm Snapdragon 8s Gen 3 [SM8635]"); else if (ffStrbufEqualS(&cpu->name, "SM8650-AC")) ffStrbufSetStatic(&cpu->name, "Qualcomm Snapdragon 8 Gen 3 for Galaxy [SM8650-AC]"); From 2bc66d7f27a8dc2be585f8e2051617fb0c25e54f Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 31 Oct 2024 22:39:25 +0800 Subject: [PATCH 34/72] CMake (NetBSD): set rpath --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 17568c9af..b70e223b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1136,11 +1136,13 @@ elseif(APPLE) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 _DARWIN_C_SOURCE) elseif(OpenBSD) target_compile_definitions(libfastfetch PUBLIC _XOPEN_SOURCE=700 _FILE_OFFSET_BITS=64 _BSD_SOURCE) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R6/lib") # detect x11 lib path automatically elseif(SunOS) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 __EXTENSIONS__ _POSIX_C_SOURCE) elseif(NetBSD) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-char-subscripts") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R7/lib") # ditto endif() if(HAVE_STATX) From cb403be8e52b4b3ad2050660573c3613eca9e2dc Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 31 Oct 2024 23:51:58 +0800 Subject: [PATCH 35/72] GPU: use `pciaccess` to enumerate PCI devices --- CMakeLists.txt | 10 ++++-- src/detection/gpu/gpu.h | 2 +- src/detection/gpu/gpu_general.c | 63 +++++++++++++++++++++++++++++++++ src/detection/gpu/gpu_pci.c | 4 +++ 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/detection/gpu/gpu_general.c diff --git a/CMakeLists.txt b/CMakeLists.txt index b70e223b4..d7bcb0f7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,7 @@ cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" O cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID" OFF) cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF) cmake_dependent_option(ENABLE_LIBZFS "Enable libzfs" ON "LINUX OR FreeBSD OR SunOS" OFF) +cmake_dependent_option(ENABLE_PCIACCESS "Enable libpciaccess" ON "NetBSD OR OpenBSD OR SunOS" OFF) option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF) option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF) @@ -705,7 +706,7 @@ elseif(NetBSD) src/detection/displayserver/linux/xcb.c src/detection/displayserver/linux/xlib.c src/detection/font/font_linux.c - src/detection/gpu/gpu_nosupport.c + src/detection/gpu/gpu_general.c src/detection/gpu/gpu_pci.c src/detection/gtk_qt/gtk.c src/detection/host/host_nbsd.c @@ -787,7 +788,8 @@ elseif(OpenBSD) src/detection/displayserver/linux/xcb.c src/detection/displayserver/linux/xlib.c src/detection/font/font_linux.c - src/detection/gpu/gpu_nosupport.c + src/detection/gpu/gpu_pci.c + src/detection/gpu/gpu_general.c src/detection/gtk_qt/gtk.c src/detection/host/host_obsd.c src/detection/lm/lm_nosupport.c @@ -1327,6 +1329,10 @@ ff_lib_enable(DIRECTX_HEADERS "DirectX-Headers" "DirectX-Headers" ) +ff_lib_enable(PCIACCESS + "pciaccess" + "pciaccess" +) # The system is only usable on SunOS. We provide our local copy of it so it's always available. if(ENABLE_LIBZFS) if(BINARY_LINK_TYPE STREQUAL "dlopen") diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index 3edd78fc1..5ccd33dd8 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -48,6 +48,6 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus); const char* ffGetGPUVendorString(unsigned vendorId); -#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__NetBSD__) || defined(__OpenBSD__) void ffGPUFillVendorAndName(uint8_t subclass, uint16_t vendor, uint16_t device, FFGPUResult* gpu); #endif diff --git a/src/detection/gpu/gpu_general.c b/src/detection/gpu/gpu_general.c new file mode 100644 index 000000000..c978bd829 --- /dev/null +++ b/src/detection/gpu/gpu_general.c @@ -0,0 +1,63 @@ +#include "gpu.h" + +#ifdef FF_HAVE_PCIACCESS + +#include "common/properties.h" +#include "common/io/io.h" +#include "common/library.h" + +#include + +const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpus) +{ + FF_LIBRARY_LOAD(pciaccess, "Failed to load libpciaccess" FF_LIBRARY_EXTENSION, "libpciaccess" FF_LIBRARY_EXTENSION, 0) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pciaccess, pci_system_init) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pciaccess, pci_slot_match_iterator_create) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pciaccess, pci_device_next) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pciaccess, pci_system_cleanup) + + { + // Requires root access + // Same behavior can be observed with `cp $(which scanpci) /tmp/ && /tmp/scanpci` + FF_SUPPRESS_IO(); + if (ffpci_system_init() < 0) + return "pci_system_init() failed"; + } + + struct pci_device_iterator* iter = ffpci_slot_match_iterator_create(NULL); + for (struct pci_device* dev = NULL; (dev = ffpci_device_next(iter)); ) + { + if (dev->device_class >> 16 != 0x03 /*PCI_BASE_CLASS_DISPLAY*/) + continue; + + FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus); + ffStrbufInitStatic(&gpu->vendor, ffGetGPUVendorString(dev->vendor_id)); + ffStrbufInit(&gpu->name); + ffStrbufInit(&gpu->driver); + ffStrbufInit(&gpu->platformApi); + gpu->temperature = FF_GPU_TEMP_UNSET; + gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; + gpu->type = FF_GPU_TYPE_UNKNOWN; + gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET; + gpu->deviceId = ((uint64_t) dev->domain << 6) | ((uint64_t) dev->bus << 4) | ((uint64_t) dev->dev << 2) | (uint64_t) dev->func; + gpu->frequency = FF_GPU_FREQUENCY_UNSET; + + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD) + { + char query[32]; + snprintf(query, sizeof(query), "%X,\t%X,", (unsigned) dev->device_id, (unsigned) dev->revision); + ffParsePropFileData("libdrm/amdgpu.ids", query, &gpu->name); + } + + if (gpu->name.length == 0) + { + ffGPUFillVendorAndName((dev->device_class >> 8) & 8, dev->vendor_id, dev->device_id, gpu); + } + } + + ffpci_system_cleanup(); + return NULL; +} + +#else +#endif diff --git a/src/detection/gpu/gpu_pci.c b/src/detection/gpu/gpu_pci.c index fe0f0c939..52dabb49c 100644 --- a/src/detection/gpu/gpu_pci.c +++ b/src/detection/gpu/gpu_pci.c @@ -41,6 +41,10 @@ static const FFstrbuf* loadPciIds() ffReadFileBuffer(FASTFETCH_TARGET_DIR_USR "/share/pciids/pci.ids", &pciids); #elif __sun ffReadFileBuffer(FASTFETCH_TARGET_DIR_ROOT "/usr/share/hwdata/pci.ids", &pciids); + #elif __OpenBSD__ + ffReadFileBuffer(FASTFETCH_TARGET_DIR_ROOT "/usr/local/share/pci.ids", &pciids); + #elif __NetBSD__ + ffReadFileBuffer(FASTFETCH_TARGET_DIR_ROOT "/usr/pkg/share/pciutils/pci.ids", &pciids); #endif #endif // FF_CUSTOM_PCI_IDS_PATH From b410710903e99f444a3c94f5d3ea666932ba8de2 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Fri, 1 Nov 2024 00:20:51 +0800 Subject: [PATCH 36/72] Processes (NetBSD): add support --- CMakeLists.txt | 2 +- src/detection/processes/processes_nbsd.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/detection/processes/processes_nbsd.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d7bcb0f7c..b678c9cad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -727,7 +727,7 @@ elseif(NetBSD) src/detection/os/os_nbsd.c src/detection/packages/packages_obsd.c src/detection/poweradapter/poweradapter_nosupport.c - src/detection/processes/processes_nosupport.c + src/detection/processes/processes_nbsd.c src/detection/gtk_qt/qt.c src/detection/sound/sound_linux.c src/detection/swap/swap_obsd.c diff --git a/src/detection/processes/processes_nbsd.c b/src/detection/processes/processes_nbsd.c new file mode 100644 index 000000000..cf16a04cd --- /dev/null +++ b/src/detection/processes/processes_nbsd.c @@ -0,0 +1,15 @@ +#include "processes.h" + +#include + +const char* ffDetectProcesses(uint32_t* result) +{ + int request[] = {CTL_KERN, KERN_PROC2, KERN_PROC_ALL, -1, sizeof(struct kinfo_proc2), 0}; + size_t length = 0; + + if(sysctl(request, ARRAY_SIZE(request), NULL, &length, NULL, 0) != 0) + return "sysctl({CTL_KERN, KERN_PROC2, KERN_PROC_ALL}) failed"; + + *result = (uint32_t)(length / sizeof(struct kinfo_proc2)); + return NULL; +} From e0acce9646d7cd0b45506cf618d0401974b57875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 1 Nov 2024 00:03:51 +0800 Subject: [PATCH 37/72] CI (OpenBSD / NetBSD): embed pci.ids --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fee767f1a..e234cd66c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -417,8 +417,8 @@ jobs: version: '7.5' run: | uname -a - sudo pkg_add -r cmake git pkgconf wayland vulkan-headers vulkan-loader glib2 dconf dbus sqlite3 xfconf imagemagick chafa pulseaudio libv4l - cmake -DSET_TWEAK=Off -DBUILD_TESTS=On . + sudo pkg_add -r cmake git pkgconf wayland vulkan-headers vulkan-loader glib2 dconf dbus sqlite3 xfconf imagemagick chafa pulseaudio libv4l py3-requests + cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=ON . cmake --build . --target package --verbose -j4 ./fastfetch --list-features time ./fastfetch -c presets/ci.jsonc --stat false @@ -454,7 +454,7 @@ jobs: run: | uname -a sudo pkgin -y install cmake git pkgconf wayland vulkan-headers dconf dbus sqlite3 ImageMagick pulseaudio opencl-headers ocl-icd libv4l py312-requests - cmake -DSET_TWEAK=Off -DBUILD_TESTS=On . + cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=ON . cmake --build . --target package --verbose -j4 ./fastfetch --list-features time ./fastfetch -c presets/ci.jsonc --stat false From 7d46b2ada5909faba043c645a1af5574f1a634df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 1 Nov 2024 08:38:48 +0800 Subject: [PATCH 38/72] Logo (Builtin): make aperture colorable Fix #1368 --- src/logo/ascii/aperture.txt | 38 ++++++++++++++++++------------------- src/logo/builtin.c | 7 +++++++ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/logo/ascii/aperture.txt b/src/logo/ascii/aperture.txt index 778779e1b..59a9a77d0 100644 --- a/src/logo/ascii/aperture.txt +++ b/src/logo/ascii/aperture.txt @@ -1,20 +1,20 @@ .,-:;//;:=, - . :H@@@MM@M#H/.,+%;, - ,/X+ +M@@M@MM%=,-%HMMM@X/, - -+@MM; SM@@MH+-,;XMMMM@MMMM@+- - ;@M@@M- XM@X;. -+XXXXXHHH@M@M#@/. - ,%MM@@MH ,@%= .---=-=:=,. - =@#@@@MX., -%HXSS%%%:; - =-./@M@MS .;@MMMM@MM: - X@/ -SMM/ . +MM@@@MS -,@M@H: :@: . =X#@@@@- -,@@@MMX, . /H- ;@M@M= -.H@@@@M@+, %MM+..%#S. - /MMMM@MMH/. XM@MH; =; - /%+%SXHH@S= , .H@@@@MX, - .=--------. -%H.,@@@@@MX, - .%MM@@@HHHXXSSS%+- .:SMMX =M@@MM%. - =XMMM@MM@MM#H;,-+HMM@M+ /MMMX= - =%@M@M#@S-.=S@MM@@@M; %M%= - ,:+S+-,/H#MMMMMMM@= =, - =++%%%%+/:-. \ No newline at end of file + $8. $1:H@@@MM@M#H/.$2,+%;, + $8,/X+ $1+M@@M@MM%=,$2-%HMMM@X/, + $8-+@MM; $1$$M@@MH+-,$2;XMMMM@MMMM@+- + $8;@M@@M- $1XM@X;. $2-+XXXXXHHH@M@M#@/. + $8,%MM@@MH $1,@%= $2.---=-=:=,. + $8=@#@@@MX., $3-%HX$$$$%%%:; + $7=-$8./@M@M$$ $3.;@MMMM@MM: + $7X@/$8 -$$MM/ $3. +MM@@@M$$ +$7,@M@H:$8 :@: $4. $3=X#@@@@- +$7,@@@MMX,$8 . $4/H- $3;@M@M= +$7.H@@@@M@+, $4%MM+. $3%#$. + $7/MMMM@MMH/. $4XM@MH; $3=; + $7/%+%$$XHH@$$= $5, $4.H@@@@MX, + $6=----------. $5-%H.$4,@@@@@MX, + $6.%MM@@@HHHXX$$$$$$%+- $5.:$$MMX$4 =M@@MM%. + $6=XMMM@MM@MM#H;$5,-+HMM@M+$4 /MMMX= + $6=%@M@M#@$$-$5.=$@MM@@@M;$4 %M%= + $6,:+$$+-$5,/H#MMMMMMM@=$4 =, + $5=++%%%%+/:-. \ No newline at end of file diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 545e92e42..b72a65bdc 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -258,6 +258,13 @@ static const FFlogo A[] = { .lines = FASTFETCH_DATATEXT_LOGO_APERTURE, .colors = { FF_COLOR_FG_CYAN, + FF_COLOR_FG_CYAN, + FF_COLOR_FG_CYAN, + FF_COLOR_FG_CYAN, + FF_COLOR_FG_CYAN, + FF_COLOR_FG_CYAN, + FF_COLOR_FG_CYAN, + FF_COLOR_FG_CYAN, }, .colorKeys = FF_COLOR_FG_CYAN, .colorTitle = FF_COLOR_FG_WHITE, From 0f3ce426e9213333ad228ced872ebc91f84ab789 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Fri, 1 Nov 2024 15:02:47 +0800 Subject: [PATCH 39/72] DiskIO (NetBSD): add support --- CMakeLists.txt | 2 +- src/detection/diskio/diskio_nbsd.c | 38 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/detection/diskio/diskio_nbsd.c diff --git a/CMakeLists.txt b/CMakeLists.txt index b678c9cad..29338ec9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -691,7 +691,7 @@ elseif(NetBSD) src/detection/dns/dns_linux.c src/detection/physicaldisk/physicaldisk_nosupport.c src/detection/physicalmemory/physicalmemory_nosupport.c - src/detection/diskio/diskio_nosupport.c + src/detection/diskio/diskio_nbsd.c src/detection/displayserver/linux/displayserver_linux.c src/detection/displayserver/linux/drm.c src/detection/displayserver/linux/wayland/wayland.c diff --git a/src/detection/diskio/diskio_nbsd.c b/src/detection/diskio/diskio_nbsd.c new file mode 100644 index 000000000..8d537045a --- /dev/null +++ b/src/detection/diskio/diskio_nbsd.c @@ -0,0 +1,38 @@ +#include "diskio.h" +#include "util/stringUtils.h" +#include "util/mallocHelper.h" + +#include +#include + +const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) +{ + int mib[] = {CTL_HW, HW_IOSTATS, sizeof(struct io_sysctl)}; + size_t len; + if (sysctl(mib, ARRAY_SIZE(mib), NULL, &len, NULL, 0) < 0) + return "sysctl({HW_IOSTATS}, NULL) failed"; + uint32_t nDrive = (uint32_t) (len / sizeof(struct io_sysctl)); + + struct io_sysctl* stats = malloc(len); + + if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, NULL, 0) < 0) + return "sysctl({HW_IOSTATS}, stats) failed"; + + for (uint32_t i = 0; i < nDrive; ++i) + { + struct io_sysctl* st = &stats[i]; + + if (options->namePrefix.length && strncmp(st->name, options->namePrefix.chars, options->namePrefix.length) != 0) + continue; + + FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result); + ffStrbufInitF(&device->devPath, "/dev/%s", st->name); + ffStrbufInitS(&device->name, st->name); + device->bytesRead = st->rbytes; + device->readCount = st->rxfer; + device->bytesWritten = st->wbytes; + device->writeCount = st->wxfer; + } + + return NULL; +} From b05023fb8b13820af38d47415b5c9f43786ff646 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Fri, 1 Nov 2024 15:21:47 +0800 Subject: [PATCH 40/72] DiskIO (OpenBSD): add support --- CMakeLists.txt | 2 +- src/detection/diskio/diskio_obsd.c | 40 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/detection/diskio/diskio_obsd.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 29338ec9d..73e32122c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -773,7 +773,7 @@ elseif(OpenBSD) src/detection/dns/dns_linux.c src/detection/physicaldisk/physicaldisk_nosupport.c src/detection/physicalmemory/physicalmemory_nosupport.c - src/detection/diskio/diskio_nosupport.c + src/detection/diskio/diskio_obsd.c src/detection/displayserver/linux/displayserver_linux.c src/detection/displayserver/linux/drm.c src/detection/displayserver/linux/wayland/wayland.c diff --git a/src/detection/diskio/diskio_obsd.c b/src/detection/diskio/diskio_obsd.c new file mode 100644 index 000000000..b00b733a2 --- /dev/null +++ b/src/detection/diskio/diskio_obsd.c @@ -0,0 +1,40 @@ +#include "diskio.h" +#include "util/stringUtils.h" +#include "util/mallocHelper.h" + +#include +#include + +const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) +{ + int mib[] = {CTL_HW, HW_DISKSTATS}; + size_t len; + if (sysctl(mib, ARRAY_SIZE(mib), NULL, &len, NULL, 0) < 0) + return "sysctl({HW_DISKSTATS}, NULL) failed"; + uint32_t nDrive = (uint32_t) (len / sizeof(struct diskstats)); + + printf("C: %d\n", nDrive); + + struct diskstats* stats = malloc(len); + + if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, NULL, 0) < 0) + return "sysctl({HW_DISKSTATS}, stats) failed"; + + for (uint32_t i = 0; i < nDrive; ++i) + { + struct diskstats* st = &stats[i]; + + if (options->namePrefix.length && strncmp(st->ds_name, options->namePrefix.chars, options->namePrefix.length) != 0) + continue; + + FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result); + ffStrbufInitF(&device->devPath, "/dev/%s", st->ds_name); + ffStrbufInitS(&device->name, st->ds_name); + device->bytesRead = st->ds_rbytes; + device->readCount = st->ds_rxfer; + device->bytesWritten = st->ds_wbytes; + device->writeCount = st->ds_wxfer; + } + + return NULL; +} From 090b6d741c39f28456e7b6d39115e1edd0864880 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Fri, 1 Nov 2024 15:31:54 +0800 Subject: [PATCH 41/72] DiskIO (SunOS): remove dev path --- src/detection/diskio/diskio_sunos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/detection/diskio/diskio_sunos.c b/src/detection/diskio/diskio_sunos.c index 26a3350ff..a6bb0b311 100644 --- a/src/detection/diskio/diskio_sunos.c +++ b/src/detection/diskio/diskio_sunos.c @@ -27,12 +27,12 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) continue; FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result); - ffStrbufInitS(&device->devPath, ks->ks_name); + ffStrbufInit(&device->devPath); + ffStrbufInitS(&device->name, ks->ks_name); device->bytesRead = kio.nread; device->readCount = kio.reads; device->bytesWritten = kio.nwritten; device->writeCount = kio.writes; - ffStrbufInitS(&device->name, ks->ks_name); } return NULL; From 254f1216ecfb07ff39d070a444e251f0b883a72d Mon Sep 17 00:00:00 2001 From: Carter Li Date: Fri, 1 Nov 2024 18:44:09 +0800 Subject: [PATCH 42/72] Users (OpenBSD): add support --- CMakeLists.txt | 2 +- src/detection/users/users_obsd.c | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/detection/users/users_obsd.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 73e32122c..89ae8800e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -819,7 +819,7 @@ elseif(OpenBSD) src/detection/theme/theme_linux.c src/detection/tpm/tpm_nosupport.c src/detection/uptime/uptime_bsd.c - src/detection/users/users_nosupport.c + src/detection/users/users_obsd.c src/detection/wallpaper/wallpaper_linux.c src/detection/wifi/wifi_nosupport.c src/detection/wm/wm_nosupport.c diff --git a/src/detection/users/users_obsd.c b/src/detection/users/users_obsd.c new file mode 100644 index 000000000..db7a89467 --- /dev/null +++ b/src/detection/users/users_obsd.c @@ -0,0 +1,36 @@ +#include "fastfetch.h" +#include "users.h" +#include "common/io/io.h" + +#include + +const char* ffDetectUsers(FF_MAYBE_UNUSED FFUsersOptions* options, FFlist* users) +{ + FF_AUTO_CLOSE_FILE FILE* fp = fopen(_PATH_UTMP, "r"); + if (!fp) return "fopen(_PATH_UTMP, r) failed"; + + struct utmp n; +next: + while (fread(&n, sizeof(n), 1, fp) == 1) + { + if (!n.ut_name[0]) continue; + + if (options->myselfOnly && !ffStrbufEqualS(&instance.state.platform.userName, n.ut_name)) + continue; + + FF_LIST_FOR_EACH(FFUserResult, user, *users) + { + if (ffStrbufEqualS(&user->name, n.ut_name)) + goto next; + } + + FFUserResult* user = (FFUserResult*) ffListAdd(users); + ffStrbufInitS(&user->name, n.ut_name); + ffStrbufInitS(&user->hostName, n.ut_host); + ffStrbufInitS(&user->sessionName, n.ut_line); + ffStrbufInit(&user->clientIp); + user->loginTime = (uint64_t) n.ut_time * 1000; + } + + return NULL; +} From 0110584e3912c3be9cd32628128caa46d4740ed2 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Fri, 1 Nov 2024 18:51:59 +0800 Subject: [PATCH 43/72] NetIO (*BSD): support OpenBSD & NetBSD --- CMakeLists.txt | 4 ++-- src/detection/netio/netio_bsd.c | 4 ++++ src/modules/netio/netio.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89ae8800e..7e4ae502f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -722,7 +722,7 @@ elseif(NetBSD) src/detection/media/media_linux.c src/detection/memory/memory_obsd.c src/detection/mouse/mouse_nosupport.c - src/detection/netio/netio_nosupport.c + src/detection/netio/netio_bsd.c src/detection/opengl/opengl_linux.c src/detection/os/os_nbsd.c src/detection/packages/packages_obsd.c @@ -804,7 +804,7 @@ elseif(OpenBSD) src/detection/media/media_linux.c src/detection/memory/memory_obsd.c src/detection/mouse/mouse_nosupport.c - src/detection/netio/netio_nosupport.c + src/detection/netio/netio_bsd.c src/detection/opengl/opengl_linux.c src/detection/os/os_obsd.c src/detection/packages/packages_obsd.c diff --git a/src/detection/netio/netio_bsd.c b/src/detection/netio/netio_bsd.c index 6bf9a8ce6..5328949a9 100644 --- a/src/detection/netio/netio_bsd.c +++ b/src/detection/netio/netio_bsd.c @@ -48,7 +48,11 @@ const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) .rxPackets = ifm->ifm_data.ifi_ipackets, .txErrors = ifm->ifm_data.ifi_oerrors, .rxErrors = ifm->ifm_data.ifi_ierrors, + #ifdef _IFI_OQDROPS + .txDrops = if2m->ifm_data.ifi_oqdrops, + #else .txDrops = 0, // unsupported + #endif .rxDrops = ifm->ifm_data.ifi_iqdrops, .defaultRoute = sdl->sdl_index == defaultRouteIfIndex, }; diff --git a/src/modules/netio/netio.c b/src/modules/netio/netio.c index 89113c375..6dd3e8a98 100644 --- a/src/modules/netio/netio.c +++ b/src/modules/netio/netio.c @@ -264,7 +264,7 @@ void ffInitNetIOOptions(FFNetIOOptions* options) ffStrbufInit(&options->namePrefix); options->defaultRouteOnly = - #ifdef __ANDROID__ + #if __ANDROID__ || __OpenBSD__ false #else true From 7ffffda50437413d1fe74dbb8df6fc02c3fe2355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 1 Nov 2024 22:00:21 +0800 Subject: [PATCH 44/72] CI: remove libv4l We need libv4l2 instead of libv4l(1) --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e234cd66c..17a089148 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -417,7 +417,7 @@ jobs: version: '7.5' run: | uname -a - sudo pkg_add -r cmake git pkgconf wayland vulkan-headers vulkan-loader glib2 dconf dbus sqlite3 xfconf imagemagick chafa pulseaudio libv4l py3-requests + sudo pkg_add -r cmake git pkgconf wayland vulkan-headers vulkan-loader glib2 dconf dbus sqlite3 xfconf imagemagick chafa pulseaudio py3-requests cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=ON . cmake --build . --target package --verbose -j4 ./fastfetch --list-features @@ -453,7 +453,7 @@ jobs: version: '10.0' run: | uname -a - sudo pkgin -y install cmake git pkgconf wayland vulkan-headers dconf dbus sqlite3 ImageMagick pulseaudio opencl-headers ocl-icd libv4l py312-requests + sudo pkgin -y install cmake git pkgconf wayland vulkan-headers dconf dbus sqlite3 ImageMagick pulseaudio opencl-headers ocl-icd py312-requests cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=ON . cmake --build . --target package --verbose -j4 ./fastfetch --list-features From 565afa1e5111eaf0e4d0463f518bdb6ed96e85b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 1 Nov 2024 22:05:36 +0800 Subject: [PATCH 45/72] CI (NetBSD): release NetBSD --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17a089148..64ff3fac4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -617,6 +617,7 @@ jobs: - macos-universal - freebsd-amd64 - openbsd-amd64 + - netbsd-amd64 - sunos-amd64 - windows-amd64 - windows-i686 From efe06768315294fa099cbd505890d6b411580e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 1 Nov 2024 22:16:29 +0800 Subject: [PATCH 46/72] Logo (Builtin): update OpenSUSE Leap --- src/logo/ascii/opensuse_leap.txt | 34 +++++++++++++++------------- src/logo/ascii/opensuse_leap_old.txt | 16 +++++++++++++ src/logo/builtin.c | 13 ++++++++++- 3 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 src/logo/ascii/opensuse_leap_old.txt diff --git a/src/logo/ascii/opensuse_leap.txt b/src/logo/ascii/opensuse_leap.txt index e0d8cddc8..fa96b3f89 100644 --- a/src/logo/ascii/opensuse_leap.txt +++ b/src/logo/ascii/opensuse_leap.txt @@ -1,16 +1,18 @@ - .-++:. - ./oooooo/- - `:oooooooooooo:. - -+oooooooooooooooo+-` - ./oooooooooooooooooooooo/- - :oooooooooooooooooooooooooo: - ` `-+oooooooooooooooooooo/- ` - `:oo/- .:ooooooooooooooo+:` `-+oo/. -`/oooooo:. -/oooooooooo/. ./oooooo/. - `:+ooooo+-` `:+oooo+- `:oooooo+:` - .:oooooo/. .::` -+oooooo/. - -/oooooo:. ./oooooo+- - `:+ooooo+-:+oooooo:` - ./oooooooooo/. - -/oooo+:` - `:/. \ No newline at end of file + ==== + ====== + ==== ====+ + +==== +==== + +===+ ==== + ==== ==== ++=== +==== +==== +==== + ===== ==== + +===+ ===== +==+ ===== +===+ === +==== ==== ===== ===== + ==== ======= ==== + ==== === ==== + ====+ ==== + ==== ===== + ====== + == \ No newline at end of file diff --git a/src/logo/ascii/opensuse_leap_old.txt b/src/logo/ascii/opensuse_leap_old.txt new file mode 100644 index 000000000..e0d8cddc8 --- /dev/null +++ b/src/logo/ascii/opensuse_leap_old.txt @@ -0,0 +1,16 @@ + .-++:. + ./oooooo/- + `:oooooooooooo:. + -+oooooooooooooooo+-` + ./oooooooooooooooooooooo/- + :oooooooooooooooooooooooooo: + ` `-+oooooooooooooooooooo/- ` + `:oo/- .:ooooooooooooooo+:` `-+oo/. +`/oooooo:. -/oooooooooo/. ./oooooo/. + `:+ooooo+-` `:+oooo+- `:oooooo+:` + .:oooooo/. .::` -+oooooo/. + -/oooooo:. ./oooooo+- + `:+ooooo+-:+oooooo:` + ./oooooooooo/. + -/oooo+:` + `:/. \ No newline at end of file diff --git a/src/logo/builtin.c b/src/logo/builtin.c index b72a65bdc..374bce375 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -3203,7 +3203,7 @@ static const FFlogo O[] = { }, // OpenSuseLeap { - .names = {"opensuse_leap", "open_suse_leap", "opensuse-leap", "open-suse-leap", "suse_leap", "suse-leap", "opensuseleap"}, + .names = {"opensuse_leap", "opensuse leap"}, .lines = FASTFETCH_DATATEXT_LOGO_OPENSUSE_LEAP, .colors = { FF_COLOR_FG_WHITE, @@ -3211,6 +3211,17 @@ static const FFlogo O[] = { .colorKeys = FF_COLOR_FG_GREEN, .colorTitle = FF_COLOR_FG_GREEN, }, + // OpenSuseLeapOld + { + .names = {"opensuse_leap_old", "opensuse leap_old"}, + .lines = FASTFETCH_DATATEXT_LOGO_OPENSUSE_LEAP_OLD, + .type = FF_LOGO_LINE_TYPE_ALTER_BIT, + .colors = { + FF_COLOR_FG_WHITE, + }, + .colorKeys = FF_COLOR_FG_GREEN, + .colorTitle = FF_COLOR_FG_GREEN, + }, // OpenSuseTumbleweed { .names = {"opensuse-tumbleweed", "opensuse_tumbleweed"}, From fe8595a054087781e521f4f5cbfeb64372e83dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 1 Nov 2024 22:18:59 +0800 Subject: [PATCH 47/72] Doc: update changelog --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 556a6a852..9b9a5ee7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +# 2.29.0 + +Features: +* Port to NetBSD +* Support DiskIO, NetIO, GPU and Users module on OpenBSD +* Report SD8E (CPU, Android) + +Bugfixes: +* Fix the VIM version detection on Ubuntu (Editor, Linux) + +Logo: +* Update OpenSuse Tumbleweed +* Add XCP-ng +* Add SummitOS +* Update PikaOS +* Update OpenSUSE Leap +* Update aperture + # 2.28.0 Features: From 540239fe0374bcc1985b093635f2c25a21fceeb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 1 Nov 2024 22:33:28 +0800 Subject: [PATCH 48/72] Brightness (NetBSD): disable --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e4ae502f..781888f4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -680,7 +680,7 @@ elseif(NetBSD) src/detection/bluetoothradio/bluetoothradio_linux.c src/detection/board/board_nbsd.c src/detection/bootmgr/bootmgr_nosupport.c - src/detection/brightness/brightness_bsd.c + src/detection/brightness/brightness_nosupport.c src/detection/btrfs/btrfs_nosupport.c src/detection/chassis/chassis_nbsd.c src/detection/cpu/cpu_nbsd.c From f7288fec01b4bdec63f1741e9701db3df9142e51 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 3 Nov 2024 08:35:11 +0800 Subject: [PATCH 49/72] Global: support DragonFly BSD --- CMakeLists.txt | 13 +++++++++++-- src/common/init.c | 2 +- src/common/netif/netif_bsd.c | 2 +- src/common/processing_linux.c | 7 +++++++ src/detection/battery/battery_bsd.c | 12 ++++++++++++ src/detection/disk/disk_bsd.c | 12 ++++++++++-- src/detection/diskio/diskio_bsd.c | 9 +++++++++ src/detection/displayserver/linux/wmde.c | 4 ++++ src/detection/gamepad/gamepad_bsd.c | 7 ++++++- src/detection/gpu/gpu_bsd.c | 8 +++++--- src/detection/gpu/gpu_pci.c | 3 +++ src/detection/keyboard/keyboard_bsd.c | 7 ++++++- src/detection/localip/localip_linux.c | 6 +++--- src/detection/mouse/mouse_bsd.c | 7 ++++++- src/detection/physicaldisk/physicaldisk_bsd.c | 9 +++++++++ src/detection/sound/sound_bsd.c | 3 +++ src/detection/terminalshell/terminalshell.c | 3 +++ src/modules/localip/localip.c | 2 +- src/util/binary_linux.c | 2 +- 19 files changed, 101 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 781888f4f..ea929c28d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,9 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD") set(OpenBSD TRUE CACHE BOOL "..." FORCE) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "NetBSD") set(NetBSD TRUE CACHE BOOL "..." FORCE) +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly") + set(FreeBSD TRUE CACHE BOOL "..." FORCE) + set(DragonFly TRUE CACHE BOOL "..." FORCE) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") set(SunOS TRUE CACHE BOOL "..." FORCE) elseif(NOT APPLE AND NOT WIN32) @@ -74,7 +77,7 @@ cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF) cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR OpenBSD OR NetBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF) cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF) -cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID" OFF) +cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID OR DragonFly" OFF) cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF) cmake_dependent_option(ENABLE_LIBZFS "Enable libzfs" ON "LINUX OR FreeBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_PCIACCESS "Enable libpciaccess" ON "NetBSD OR OpenBSD OR SunOS" OFF) @@ -1139,6 +1142,8 @@ elseif(APPLE) elseif(OpenBSD) target_compile_definitions(libfastfetch PUBLIC _XOPEN_SOURCE=700 _FILE_OFFSET_BITS=64 _BSD_SOURCE) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R6/lib") # detect x11 lib path automatically +elseif(DragonFly) + target_compile_definitions(libfastfetch PUBLIC __FreeBSD__) elseif(SunOS) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 __EXTENSIONS__ _POSIX_C_SOURCE) elseif(NetBSD) @@ -1418,8 +1423,12 @@ elseif(FreeBSD) target_link_libraries(libfastfetch PRIVATE "m" PRIVATE "usbhid" - PRIVATE "geom" ) + if(NOT DragonFly) + target_link_libraries(libfastfetch + PRIVATE "geom" + ) + endif() elseif(OpenBSD) target_link_libraries(libfastfetch PRIVATE "m" diff --git a/src/common/init.c b/src/common/init.c index 96117c66e..8f8dfea24 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -245,7 +245,7 @@ void ffListFeatures(void) #if FF_HAVE_DDCUTIL "libddcutil\n" #endif - #if FF_HAVE_ELF || __sun || __FreeBSD__ || __OpenBSD__ || __NetBSD__ + #if FF_HAVE_ELF || __sun || (__FreeBSD__ && !__DragonFly__) || __OpenBSD__ || __NetBSD__ "libelf\n" #endif #if FF_HAVE_LIBZFS diff --git a/src/common/netif/netif_bsd.c b/src/common/netif/netif_bsd.c index b01ef2040..ee084e011 100644 --- a/src/common/netif/netif_bsd.c +++ b/src/common/netif/netif_bsd.c @@ -91,7 +91,7 @@ bool ffNetifGetDefaultRouteImpl(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex) if (rtmsg.hdr.rtm_seq == 1 && rtmsg.hdr.rtm_pid == pid) { struct sockaddr_dl* sdl = (struct sockaddr_dl *)get_rt_address(&rtmsg.hdr, RTA_IFP); - if (sdl) + if (sdl && sdl->sdl_len) { assert(sdl->sdl_nlen <= IF_NAMESIZE); memcpy(iface, sdl->sdl_data, sdl->sdl_nlen); diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index 718879999..fb5db6260 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -367,6 +367,13 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i #elif defined(__FreeBSD__) + #ifdef __DragonFly__ + #define ki_comm kp_comm + #define ki_ppid kp_ppid + #define ki_tdev kp_tdev + #define ki_flag kp_flags + #endif + struct kinfo_proc proc; size_t size = sizeof(proc); if(sysctl( diff --git a/src/detection/battery/battery_bsd.c b/src/detection/battery/battery_bsd.c index 228d6aa36..2997070cd 100644 --- a/src/detection/battery/battery_bsd.c +++ b/src/detection/battery/battery_bsd.c @@ -70,14 +70,26 @@ const char* ffDetectBattery(FF_MAYBE_UNUSED FFBatteryOptions* options, FFlist* r ffStrbufTrimRight(&battery->status, ','); } + #ifdef ACPIIO_BATT_GET_BIX battio.unit = i; if (ioctl(acpifd, ACPIIO_BATT_GET_BIX, &battio) >= 0) { ffStrbufAppendS(&battery->manufacturer, battio.bix.oeminfo); ffStrbufAppendS(&battery->modelName, battio.bix.model); ffStrbufAppendS(&battery->technology, battio.bix.type); + ffStrbufAppendS(&battery->serial, battio.bix.serial); battery->cycleCount = battio.bix.cycles; } + #elif defined(ACPIIO_BATT_GET_BIF) + battio.unit = i; + if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) >= 0) + { + ffStrbufAppendS(&battery->manufacturer, battio.bif.oeminfo); + ffStrbufAppendS(&battery->modelName, battio.bif.model); + ffStrbufAppendS(&battery->technology, battio.bif.type); + ffStrbufAppendS(&battery->serial, battio.bif.serial); + } + #endif } return NULL; } diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index 9fa19e311..957314f10 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -15,6 +15,7 @@ #endif #ifdef __FreeBSD__ +#if __has_include() #include static const char* detectFsLabel(struct statfs* fs, FFDisk* disk) @@ -51,6 +52,12 @@ static const char* detectFsLabel(struct statfs* fs, FFDisk* disk) return NULL; } +#else +static const char* detectFsLabel(struct statfs* fs, FFDisk* disk) +{ + return "Fastfetch was compiled without libgeom support"; +} +#endif static void detectFsInfo(struct statfs* fs, FFDisk* disk) { @@ -134,7 +141,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) if(!ffDiskMatchMountpoint(options, fs->f_mntonname)) continue; } - else if(!ffStrStartsWith(fs->f_mntfromname, "/dev/") && !ffStrEquals(fs->f_fstypename, "zfs")) + else if(!ffStrEquals(fs->f_mntonname, "/") && !ffStrStartsWith(fs->f_mntfromname, "/dev/") && !ffStrEquals(fs->f_fstypename, "zfs")) continue; #ifdef __FreeBSD__ @@ -168,10 +175,11 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) #ifdef __OpenBSD__ #define st_birthtimespec __st_birthtim #endif - + #ifndef __DragonFly__ struct stat st; if(stat(fs->f_mntonname, &st) == 0 && st.st_birthtimespec.tv_sec > 0) disk->createTime = (uint64_t)((st.st_birthtimespec.tv_sec * 1000) + (st.st_birthtimespec.tv_nsec / 1000000)); + #endif } return NULL; diff --git a/src/detection/diskio/diskio_bsd.c b/src/detection/diskio/diskio_bsd.c index 08ecb47cf..42d2ab920 100644 --- a/src/detection/diskio/diskio_bsd.c +++ b/src/detection/diskio/diskio_bsd.c @@ -1,4 +1,7 @@ #include "diskio.h" + +#if __has_include() + #include "util/stringUtils.h" #include @@ -58,3 +61,9 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) return NULL; } +#else +const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) +{ + return "Fastfetch was compiled without libgeom support"; +} +#endif diff --git a/src/detection/displayserver/linux/wmde.c b/src/detection/displayserver/linux/wmde.c index 5502da78a..aa1f0eafd 100644 --- a/src/detection/displayserver/linux/wmde.c +++ b/src/detection/displayserver/linux/wmde.c @@ -257,6 +257,10 @@ static const char* getFromProcesses(FFDisplayServerResult* result) uint32_t userId = getuid(); #if __FreeBSD__ + #ifdef __DragonFly__ + #define ki_comm kp_comm + #endif + int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_UID, (int) userId}; size_t length = 0; diff --git a/src/detection/gamepad/gamepad_bsd.c b/src/detection/gamepad/gamepad_bsd.c index a84f4f42c..fa68b46fc 100644 --- a/src/detection/gamepad/gamepad_bsd.c +++ b/src/detection/gamepad/gamepad_bsd.c @@ -4,7 +4,12 @@ #include #include #include -#include + +#if __has_include() +#include // FreeBSD +#else +#include // DragonFly +#endif #define MAX_UHID_JOYS 64 diff --git a/src/detection/gpu/gpu_bsd.c b/src/detection/gpu/gpu_bsd.c index b64935df4..49218e13f 100644 --- a/src/detection/gpu/gpu_bsd.c +++ b/src/detection/gpu/gpu_bsd.c @@ -2,12 +2,14 @@ #include "common/io/io.h" #include "common/properties.h" -#include "util/mallocHelper.h" -#include "util/stringUtils.h" -#include #include #include +#if __has_include() + #include // FreeBSD +#else + #include // DragonFly +#endif const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus) { diff --git a/src/detection/gpu/gpu_pci.c b/src/detection/gpu/gpu_pci.c index 52dabb49c..2de51a2ca 100644 --- a/src/detection/gpu/gpu_pci.c +++ b/src/detection/gpu/gpu_pci.c @@ -4,6 +4,9 @@ #include #ifdef __FreeBSD__ #include + #ifndef _PATH_LOCALBASE + #define _PATH_LOCALBASE "/usr/local" + #endif #endif #if FF_HAVE_EMBEDDED_PCIIDS diff --git a/src/detection/keyboard/keyboard_bsd.c b/src/detection/keyboard/keyboard_bsd.c index 4f424ba70..31dc3aa24 100644 --- a/src/detection/keyboard/keyboard_bsd.c +++ b/src/detection/keyboard/keyboard_bsd.c @@ -4,7 +4,12 @@ #include #include #include -#include + +#if __has_include() + #include // FreeBSD +#else + #include // DragonFly +#endif #define MAX_UHID_JOYS 64 diff --git a/src/detection/localip/localip_linux.c b/src/detection/localip/localip_linux.c index 87d4acb2f..00e64b990 100644 --- a/src/detection/localip/localip_linux.c +++ b/src/detection/localip/localip_linux.c @@ -39,7 +39,7 @@ static const FFLocalIpNIFlag niFlagOptions[] = { { IFF_PROMISC, "PROMISC" }, { IFF_ALLMULTI, "ALLMULTI" }, { IFF_MULTICAST, "MULTICAST" }, -#if defined(__linux__) || defined(__APPLE__) || defined(__sun) +#ifdef IFF_NOTRAILERS { IFF_NOTRAILERS, "NOTRAILERS" }, #endif #ifdef __linux__ @@ -59,10 +59,10 @@ static const FFLocalIpNIFlag niFlagOptions[] = { { IFF_LINK1, "LINK1" }, { IFF_LINK2, "LINK2" }, #endif -#if defined(__FreeBSD__) || defined(__APPLE__) +#ifdef IFF_ALTPHYS { IFF_ALTPHYS, "ALTPHYS" }, #endif -#ifdef __FreeBSD__ +#ifdef IFF_CANTCONFIG { IFF_CANTCONFIG, "CANTCONFIG" }, #endif // sentinel diff --git a/src/detection/mouse/mouse_bsd.c b/src/detection/mouse/mouse_bsd.c index 6018d1893..cb99a47cf 100644 --- a/src/detection/mouse/mouse_bsd.c +++ b/src/detection/mouse/mouse_bsd.c @@ -4,7 +4,12 @@ #include #include #include -#include + +#if __has_include() +#include // FreeBSD +#else +#include // DragonFly +#endif #define MAX_UHID_JOYS 64 diff --git a/src/detection/physicaldisk/physicaldisk_bsd.c b/src/detection/physicaldisk/physicaldisk_bsd.c index 99dbaf9cc..42918ff95 100644 --- a/src/detection/physicaldisk/physicaldisk_bsd.c +++ b/src/detection/physicaldisk/physicaldisk_bsd.c @@ -1,4 +1,7 @@ #include "physicaldisk.h" + +#if __has_include() + #include "util/stringUtils.h" #include @@ -92,3 +95,9 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) return NULL; } +#else +const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) +{ + return "Fastfetch was compiled without libgeom support"; +} +#endif diff --git a/src/detection/sound/sound_bsd.c b/src/detection/sound/sound_bsd.c index 3053c14d5..4a30c5ae7 100644 --- a/src/detection/sound/sound_bsd.c +++ b/src/detection/sound/sound_bsd.c @@ -10,6 +10,9 @@ const char* ffDetectSound(FFlist* devices) char path[] = "/dev/mixer0"; int defaultDev = ffSysctlGetInt("hw.snd.default_unit", -1); + if (defaultDev == -1) + return "sysctl(hw.snd.default_unit) failed"; + for (int idev = 0; idev <= 9; ++idev) { path[strlen("/dev/mixer")] = (char) ('0' + idev); diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index f2d322b79..b8f6e1159 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -8,6 +8,9 @@ #include #ifdef __FreeBSD__ #include + #ifndef _PATH_LOCALBASE + #define _PATH_LOCALBASE "/usr/local" + #endif #elif __OpenBSD__ #define _PATH_LOCALBASE "/usr/local" #elif __NetBSD__ diff --git a/src/modules/localip/localip.c b/src/modules/localip/localip.c index a6bcd261a..9e3f88e1b 100644 --- a/src/modules/localip/localip.c +++ b/src/modules/localip/localip.c @@ -530,7 +530,7 @@ void ffInitLocalIpOptions(FFLocalIpOptions* options) ffOptionInitModuleArg(&options->moduleArgs, "󰩟"); options->showType = FF_LOCALIP_TYPE_IPV4_BIT | FF_LOCALIP_TYPE_PREFIX_LEN_BIT - #if !__ANDROID__ /*Permission denied*/ && !__OpenBSD__ /*Report invalid argument for some reason*/ + #if !__ANDROID__ /*Permission denied*/ && !__OpenBSD__ /*Report invalid argument for some reason*/ && !__DragonFly__ /*Doesn't work*/ | FF_LOCALIP_TYPE_DEFAULT_ROUTE_ONLY_BIT #endif ; diff --git a/src/util/binary_linux.c b/src/util/binary_linux.c index 1d520ca3b..3b6ccca35 100644 --- a/src/util/binary_linux.c +++ b/src/util/binary_linux.c @@ -1,6 +1,6 @@ #include "binary.h" -#if defined(FF_HAVE_ELF) || defined(__sun) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) +#if defined(FF_HAVE_ELF) || defined(__sun) || (defined(__FreeBSD__) && !defined(__DragonFly__)) || defined(__OpenBSD__) || defined(__NetBSD__) #include "common/io/io.h" #include "common/library.h" From dab02f176fb372b51ad7b232999f0eff0a4b2dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 3 Nov 2024 09:51:13 +0800 Subject: [PATCH 50/72] OS (Linux): improve performance of proxmox version detection Fix #1370 --- src/detection/os/os_linux.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/detection/os/os_linux.c b/src/detection/os/os_linux.c index c7ede9b16..700e18e76 100644 --- a/src/detection/os/os_linux.c +++ b/src/detection/os/os_linux.c @@ -186,13 +186,13 @@ static bool detectDebianDerived(FFOSResult* result) ffStrbufSetS(&result->name, "Proxmox VE"); ffStrbufClear(&result->versionID); if (ffProcessAppendStdOut(&result->versionID, (char* const[]) { - "/usr/bin/pveversion", + "/usr/bin/dpkg-query", + "--showformat=${version}", + "--show", + "pve-manager", NULL, - }) == NULL) // pve-manager/8.2.2/9355359cd7afbae4 (running kernel: 6.8.4-2-pve) - { - ffStrbufSubstrBeforeLastC(&result->versionID, '/'); - ffStrbufSubstrAfterFirstC(&result->versionID, '/'); - } + }) == NULL) // 8.2.2 + ffStrbufTrimRightSpace(&result->versionID); ffStrbufSetF(&result->prettyName, "Proxmox VE %s", result->versionID.chars); return true; } From 3c04b0ae65e0beb4a7b358ab63ca994525ddfa50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 3 Nov 2024 09:54:04 +0800 Subject: [PATCH 51/72] Doc: update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b9a5ee7a..d567d206f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,11 @@ Features: * Port to NetBSD * Support DiskIO, NetIO, GPU and Users module on OpenBSD -* Report SD8E (CPU, Android) +* Report SD8E SOC name (CPU, Android) Bugfixes: * Fix the VIM version detection on Ubuntu (Editor, Linux) +* Improve performance of OS version detection on Proxmox (#1370, OS, Linux) Logo: * Update OpenSuse Tumbleweed From 5c21931a097def94a1424938723434791c13c2c2 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 3 Nov 2024 18:05:56 +0800 Subject: [PATCH 52/72] DiskIO (DragonFly): add support --- CMakeLists.txt | 4 +++ src/detection/diskio/diskio_bsd.c | 42 ++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea929c28d..6cb725dba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1428,6 +1428,10 @@ elseif(FreeBSD) target_link_libraries(libfastfetch PRIVATE "geom" ) + else() + target_link_libraries(libfastfetch + PRIVATE "devstat" + ) endif() elseif(OpenBSD) target_link_libraries(libfastfetch diff --git a/src/detection/diskio/diskio_bsd.c b/src/detection/diskio/diskio_bsd.c index 42d2ab920..afb271a10 100644 --- a/src/detection/diskio/diskio_bsd.c +++ b/src/detection/diskio/diskio_bsd.c @@ -61,9 +61,49 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) return NULL; } + #else + +#include +#include + const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { - return "Fastfetch was compiled without libgeom support"; + if (checkversion() < 0) + return "checkversion() failed"; + + struct statinfo stats = { + .dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo)), + }; + if (getdevs(&stats) < 0) + return "getdevs() failed"; + + for (int i = 0; i < stats.dinfo->numdevs; i++) + { + struct devstat* current = &stats.dinfo->devices[i]; + if (current->device_type & DEVSTAT_TYPE_PASS) + continue; + + char deviceName[128]; + snprintf(deviceName, sizeof(deviceName), "%s%d", current->device_name, current->unit_number); + + if (options->namePrefix.length && strncmp(deviceName, options->namePrefix.chars, options->namePrefix.length) != 0) + continue; + + FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result); + ffStrbufInitS(&device->name, deviceName); + ffStrbufInitF(&device->devPath, "/dev/%s", deviceName); + device->bytesRead = current->bytes_read; + device->readCount = current->num_reads; + device->bytesWritten = current->bytes_written; + device->writeCount = current->num_writes; + } + + if (stats.dinfo->mem_ptr) + free(stats.dinfo->mem_ptr); + free(stats.dinfo); + + return NULL; } + #endif From d1ef454ae83629875f1f8f99a1c1957388defeed Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 3 Nov 2024 18:40:59 +0800 Subject: [PATCH 53/72] Sound (DragonFly): add support --- src/detection/sound/sound_bsd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/detection/sound/sound_bsd.c b/src/detection/sound/sound_bsd.c index 4a30c5ae7..af601b5a5 100644 --- a/src/detection/sound/sound_bsd.c +++ b/src/detection/sound/sound_bsd.c @@ -26,8 +26,7 @@ const char* ffDetectSound(FFlist* devices) continue; uint32_t mutemask = 0; - if (ioctl(fd, SOUND_MIXER_READ_MUTE, &mutemask) < 0) - continue; + ioctl(fd, SOUND_MIXER_READ_MUTE, &mutemask); // doesn't seem to be available on DragonFly struct oss_card_info ci = { .card = idev }; if (ioctl(fd, SNDCTL_CARDINFO, &ci) < 0) From 282ed9b40bde29d7a30e6a2400b3dcf02335d645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 3 Nov 2024 11:01:27 +0800 Subject: [PATCH 54/72] Netif (SunOS): fix compiling --- src/common/netif/netif_bsd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/netif/netif_bsd.c b/src/common/netif/netif_bsd.c index ee084e011..91a270905 100644 --- a/src/common/netif/netif_bsd.c +++ b/src/common/netif/netif_bsd.c @@ -91,7 +91,11 @@ bool ffNetifGetDefaultRouteImpl(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex) if (rtmsg.hdr.rtm_seq == 1 && rtmsg.hdr.rtm_pid == pid) { struct sockaddr_dl* sdl = (struct sockaddr_dl *)get_rt_address(&rtmsg.hdr, RTA_IFP); - if (sdl && sdl->sdl_len) + if (sdl + #ifndef __sun + && sdl->sdl_len + #endif + ) { assert(sdl->sdl_nlen <= IF_NAMESIZE); memcpy(iface, sdl->sdl_data, sdl->sdl_nlen); From 9610912c1fbe7cb9dafa10d560e7ba363c5d7c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 3 Nov 2024 11:12:58 +0800 Subject: [PATCH 55/72] CI: build on DragonFly --- .github/workflows/ci.yml | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64ff3fac4..e00e5a3ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -381,7 +381,7 @@ jobs: run: | uname -a sudo pkg update - sudo pkg install -y cmake git pkgconf binutils wayland vulkan-headers vulkan-loader libxcb libXrandr libX11 libdrm glib dconf dbus sqlite3-tcl xfce4-conf egl libosmesa opencl ocl-icd v4l_compat py311-requests + sudo pkg install -y cmake git pkgconf binutils wayland vulkan-headers vulkan-loader libxcb libXrandr libX11 libdrm glib dconf dbus sqlite3-tcl xfce4-conf egl libosmesa opencl ocl-icd v4l_compat py311-requests chafa cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On . cmake --build . --target package --verbose -j4 ./fastfetch --list-features @@ -397,6 +397,41 @@ jobs: name: fastfetch-freebsd-amd64 path: ./fastfetch-*.* + dragonfly-amd64: + name: DragonFly-amd64 + runs-on: ubuntu-latest + permissions: + security-events: write + contents: read + steps: + - name: checkout repository + uses: actions/checkout@v4 + + - name: run VM + uses: vmactions/dragonflybsd-vm@v1 + with: + usesh: yes + prepare: | + uname -a + pkg update + pkg install -y cmake git pkgconf binutils wayland vulkan-headers vulkan-loader libxcb libXrandr libX11 libdrm glib dconf dbus sqlite3-tcl xfce4-conf egl libosmesa opencl ocl-icd v4l_compat py39-requests + + run: | + cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On . + cmake --build . --target package --verbose -j4 + ./fastfetch --list-features + time ./fastfetch -c presets/ci.jsonc --stat false + time ./fastfetch -c presets/ci.jsonc --format json + time ./flashfetch + ldd fastfetch + ctest + + - name: upload artifacts + uses: actions/upload-artifact@v4 + with: + name: fastfetch-dragonfly-amd64 + path: ./fastfetch-*.* + openbsd-amd64: name: OpenBSD-amd64 runs-on: ubuntu-latest @@ -618,6 +653,7 @@ jobs: - freebsd-amd64 - openbsd-amd64 - netbsd-amd64 + - dragonfly-amd64 - sunos-amd64 - windows-amd64 - windows-i686 From 743babda1094f7b38c0f2b462b7faef54aad2ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 3 Nov 2024 11:47:24 +0800 Subject: [PATCH 56/72] Libc (DragonFly): add support --- CMakeLists.txt | 9 ++++++++- src/detection/libc/libc_bsd.c | 11 +++++++++-- src/detection/version/version.c | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cb725dba..85cabdb60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1124,12 +1124,19 @@ if(APPLE AND EXISTS "/usr/bin/otool") endif() endif() if(FreeBSD AND EXISTS "/usr/local/bin/objdump") - execute_process(COMMAND /bin/sh -c "/usr/local/bin/objdump -T /lib/libc.so.* | grep 'FBSD_[^ )]*' -o | sort -Vru | head -1" + execute_process(COMMAND /bin/sh -c "/usr/local/bin/objdump -T /lib/libc.so.* | grep 'FBSD_[0-9][0-9]*\\.[0-9][0-9]*' -o | sort -Vru | head -1" OUTPUT_VARIABLE OBJDUMP_T_RESULT) if("${OBJDUMP_T_RESULT}" MATCHES "FBSD_([0-9]+\\.[0-9]+)") target_compile_definitions(libfastfetch PUBLIC FF_FBSD_VERSION="${CMAKE_MATCH_1}") endif() endif() +if(DragonFly AND EXISTS "/usr/local/bin/objdump") + execute_process(COMMAND /bin/sh -c "/usr/local/bin/objdump -T /lib/libc.so.* | grep 'DF[0-9][0-9]*\\.[0-9][0-9]*' -o | sort -Vru | head -1" + OUTPUT_VARIABLE OBJDUMP_T_RESULT) + if("${OBJDUMP_T_RESULT}" MATCHES "DF([0-9]+\\.[0-9]+)") + target_compile_definitions(libfastfetch PUBLIC FF_DF_VERSION="${CMAKE_MATCH_1}") + endif() +endif() if(LINUX) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _ATFILE_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 _TIME_BITS=64) # "$<$:_FORTIFY_SOURCE=3>" diff --git a/src/detection/libc/libc_bsd.c b/src/detection/libc/libc_bsd.c index 0b6ee4943..20bdbe108 100644 --- a/src/detection/libc/libc_bsd.c +++ b/src/detection/libc/libc_bsd.c @@ -2,11 +2,18 @@ const char* ffDetectLibc(FFLibcResult* result) { +#ifdef __DragonFly__ // We define `__FreeBSD__` on DragonFly BSD for simplification + result->name = "DF"; + #ifdef FF_DF_VERSION + result->version = FF_DF_VERSION; + #endif +#elif __FreeBSD__ result->name = "FBSD"; - -#ifdef FF_FBSD_VERSION + #ifdef FF_FBSD_VERSION result->version = FF_FBSD_VERSION; + #endif #else + result->name = "Unknown"; result->version = NULL; #endif return NULL; diff --git a/src/detection/version/version.c b/src/detection/version/version.c index 6e89c3b66..8b230eecb 100644 --- a/src/detection/version/version.c +++ b/src/detection/version/version.c @@ -26,6 +26,8 @@ #define FF_SYSNAME "Android" #elif defined(__linux__) #define FF_SYSNAME "Linux" +#elif defined(__DragonFly__) // We define `__FreeBSD__` on DragonFly BSD for simplification + #define FF_SYSNAME "DragonFly" #elif defined(__FreeBSD__) #define FF_SYSNAME "FreeBSD" #elif defined(__APPLE__) From d2163912787be2976a3ca9559a464bdbb008e6ed Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 3 Nov 2024 18:00:45 +0800 Subject: [PATCH 57/72] Libc (BSD): always initialize variables --- src/detection/libc/libc_bsd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/detection/libc/libc_bsd.c b/src/detection/libc/libc_bsd.c index 20bdbe108..7c80e1181 100644 --- a/src/detection/libc/libc_bsd.c +++ b/src/detection/libc/libc_bsd.c @@ -2,6 +2,9 @@ const char* ffDetectLibc(FFLibcResult* result) { + result->name = "Unknown"; + result->version = NULL; + #ifdef __DragonFly__ // We define `__FreeBSD__` on DragonFly BSD for simplification result->name = "DF"; #ifdef FF_DF_VERSION @@ -12,9 +15,7 @@ const char* ffDetectLibc(FFLibcResult* result) #ifdef FF_FBSD_VERSION result->version = FF_FBSD_VERSION; #endif -#else - result->name = "Unknown"; - result->version = NULL; #endif + return NULL; } From 534aa09d865febb94ff690b8b0f629b01dea43fe Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 3 Nov 2024 18:09:08 +0800 Subject: [PATCH 58/72] CI (DragonFly): build with chafa & libelf --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e00e5a3ff..e79b18c99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -414,7 +414,7 @@ jobs: prepare: | uname -a pkg update - pkg install -y cmake git pkgconf binutils wayland vulkan-headers vulkan-loader libxcb libXrandr libX11 libdrm glib dconf dbus sqlite3-tcl xfce4-conf egl libosmesa opencl ocl-icd v4l_compat py39-requests + pkg install -y cmake git pkgconf binutils wayland vulkan-headers vulkan-loader libxcb libXrandr libX11 libdrm glib dconf dbus sqlite3-tcl xfce4-conf egl libosmesa opencl ocl-icd v4l_compat py39-requests chafa libelf run: | cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On . From 8f2d51c698589836c24c778ee40c123b28ae5a55 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 3 Nov 2024 18:09:18 +0800 Subject: [PATCH 59/72] Doc: update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d567d206f..d0d852820 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # 2.29.0 Features: -* Port to NetBSD +* Port to NetBSD and DragonFly BSD + * Fastfetch now supports all major BSD variants * Support DiskIO, NetIO, GPU and Users module on OpenBSD * Report SD8E SOC name (CPU, Android) From 91fdc8114f036be129a8dd33c1ab6644bdae6a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 4 Nov 2024 09:08:10 +0800 Subject: [PATCH 60/72] CI: remove windows-i686 --- .github/workflows/ci.yml | 71 ---------------------------------------- CHANGELOG.md | 4 +++ 2 files changed, 4 insertions(+), 71 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e79b18c99..7140fbd5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -569,76 +569,6 @@ jobs: name: fastfetch-windows-amd64 path: ./fastfetch-windows-amd64.* - windows-i686: - name: Windows-i686 - runs-on: windows-latest - permissions: - security-events: write - contents: read - defaults: - run: - shell: msys2 {0} - steps: - - name: checkout repository - uses: actions/checkout@v4 - - - name: setup-msys2 - uses: msys2/setup-msys2@v2 - with: - msystem: MINGW32 - update: true - install: git p7zip mingw-w64-i686-cmake mingw-w64-i686-clang mingw-w64-i686-vulkan-loader mingw-w64-i686-vulkan-headers mingw-w64-i686-opencl-icd mingw-w64-i686-opencl-headers - - - name: print msys version - run: uname -a - - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: c, cpp - - - name: configure project - run: env PKG_CONFIG_PATH=/mingw32/lib/pkgconfig/:$PKG_CONFIG_PATH cmake -DSET_TWEAK=Off -DBUILD_TESTS=On . - - - name: build project - run: cmake --build . --verbose -j4 - - - name: perform CodeQL analysis - uses: github/codeql-action/analyze@v3 - - - name: copy necessary dlls - run: cp /mingw32/bin/{OpenCL,vulkan-1}.dll . - - - name: download amd_ags - run: curl -LO https://github.com/GPUOpen-LibrariesAndSDKs/AGS_SDK/raw/master/ags_lib/lib/amd_ags_x86.dll - - - name: run fastfetch - run: time ./fastfetch -c presets/ci.jsonc --stat false - - - name: run fastfetch --format json - run: time ./fastfetch -c presets/ci.jsonc --format json - - - name: run flashfetch - run: time ./flashfetch - - - name: print dependencies - run: ldd fastfetch - - - name: run tests - run: ctest - - - name: create zip archive - run: 7z a -tzip -mx9 -bd -y fastfetch-windows-i686.zip LICENSE *.dll fastfetch.exe flashfetch.exe presets - - - name: create 7z archive - run: 7z a -t7z -mx9 -bd -y fastfetch-windows-i686.7z LICENSE *.dll fastfetch.exe flashfetch.exe presets - - - name: upload artifacts - uses: actions/upload-artifact@v4 - with: - name: fastfetch-windows-i686 - path: ./fastfetch-windows-i686.* - release: if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'fastfetch-cli/fastfetch' name: Release @@ -656,7 +586,6 @@ jobs: - dragonfly-amd64 - sunos-amd64 - windows-amd64 - - windows-i686 permissions: contents: write steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index d0d852820..83c10b6ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 2.29.0 +Changes: +* Due to [the upstream removal of MSYS2 CLANG32 environment](https://www.msys2.org/news/#2024-09-23-starting-to-drop-the-clang32-environment), we dropped fastfetch-windows-i686 support. v2.27.1 was the last version supporting it. + * Note: fastfetch built with MSVCRT has known bug that DateTime module doesn't work because of its bad support of [strftime](https://en.cppreference.com/w/c/chrono/strftime). Don't use it. + Features: * Port to NetBSD and DragonFly BSD * Fastfetch now supports all major BSD variants From a7f881522b13000b90419f99991737af3d864620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 4 Nov 2024 09:19:53 +0800 Subject: [PATCH 61/72] OS (Linux): detect Lilidog --- src/detection/os/os_linux.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/detection/os/os_linux.c b/src/detection/os/os_linux.c index 700e18e76..b5b9e67ca 100644 --- a/src/detection/os/os_linux.c +++ b/src/detection/os/os_linux.c @@ -179,6 +179,13 @@ static bool detectDebianDerived(FFOSResult* result) ffStrbufSetS(&result->idLike, "debian"); return true; } + else if (ffStrbufStartsWith(&result->name, "Lilidog GNU/Linux")) + { + // https://github.com/fastfetch-cli/fastfetch/issues/1373 + ffStrbufSetS(&result->id, "lilidog"); + ffStrbufSetS(&result->idLike, "debian"); + return true; + } else if (access("/usr/bin/pveversion", X_OK) == 0) { ffStrbufSetS(&result->id, "pve"); From b5545c926f334d583c6734be6dd6ef1a5195f59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 4 Nov 2024 09:20:33 +0800 Subject: [PATCH 62/72] Logo (Builtin): add Lilidog Fix #1373 --- CHANGELOG.md | 1 + src/logo/ascii/lilidog.txt | 16 ++++++++++++++++ src/logo/builtin.c | 10 ++++++++++ 3 files changed, 27 insertions(+) create mode 100644 src/logo/ascii/lilidog.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 83c10b6ea..00d326396 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Logo: * Update OpenSuse Tumbleweed * Add XCP-ng * Add SummitOS +* Add Lilidog * Update PikaOS * Update OpenSUSE Leap * Update aperture diff --git a/src/logo/ascii/lilidog.txt b/src/logo/ascii/lilidog.txt new file mode 100644 index 000000000..abc6c2f93 --- /dev/null +++ b/src/logo/ascii/lilidog.txt @@ -0,0 +1,16 @@ + +DDDL+ +LDDDDD+ + LD++++D+D+::::::+D + D+-::::=D+::::::::+LLDD+ + D=::::::=L=-::::::=LL++=+D + D-:::::=LDD=-::-=+L=-::::=D + L+--==+++===++LDD+:::::::-D + DL+++==:::::::::-+D-:::::::=D + D=:::::::::::::::::++:::::-+D +D+::::::::::::::::::+D++==+LD+ + D=:::::::::::::::::+LD+=--:-+D + L+=-::::::::::::::L+-::::::=D + DLL++-::::::::::-D:::::::-+D + DL+:::::::::+D=-:::-=+D + D=:::::::-D +LDLLD+ + L+--::-=D + +LDLDD+ \ No newline at end of file diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 374bce375..c20cbc927 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -2389,6 +2389,16 @@ static const FFlogo L[] = { .colorKeys = FF_COLOR_FG_GREEN, .colorTitle = FF_COLOR_FG_YELLOW, }, + // Lilidog + { + .names = {"Lilidog"}, + .lines = FASTFETCH_DATATEXT_LOGO_LIBREELEC, + .colors = { + FF_COLOR_FG_BLUE, + }, + .colorKeys = FF_COLOR_FG_RED, + .colorTitle = FF_COLOR_FG_WHITE, + }, // Lingmo OS { .names = {"Lingmo", "lingmo", "LingmoOS", "lingmoos"}, From 17d6153353259613ba41d27e575ca448494bfca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 4 Nov 2024 09:30:13 +0800 Subject: [PATCH 63/72] Vulkan: drop windows-i686 support --- src/common/library.h | 20 -------------------- src/detection/vulkan/vulkan.c | 8 ++++---- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/common/library.h b/src/common/library.h index 1f9154bd2..849b89ee3 100644 --- a/src/common/library.h +++ b/src/common/library.h @@ -43,11 +43,6 @@ static inline void ffLibraryUnload(void** handle) if(symbolMapping == NULL) \ return returnValue; -#define FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, symbolMapping, symbolName, alternateName, returnValue) \ - symbolMapping = dlsym(library, #symbolName); \ - if(symbolMapping == NULL && !(symbolMapping = (__typeof__(&symbolName)) dlsym(library, #alternateName))) \ - return returnValue; - #define FF_LIBRARY_LOAD_SYMBOL(library, symbolName, returnValue) \ __typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff ## symbolName, symbolName, returnValue); @@ -57,18 +52,12 @@ static inline void ffLibraryUnload(void** handle) #define FF_LIBRARY_LOAD_SYMBOL_MESSAGE(library, symbolName) \ __typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff ## symbolName, symbolName, "dlsym " #symbolName " failed"); -#define FF_LIBRARY_LOAD_SYMBOL_MESSAGE2(library, symbolName, alternateName) \ - __typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, ff ## symbolName, symbolName, alternateName, "dlsym " #symbolName " failed"); - #define FF_LIBRARY_LOAD_SYMBOL_VAR(library, varName, symbolName, returnValue) \ FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName).ff ## symbolName, symbolName, returnValue); #define FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(library, varName, symbolName) \ FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName).ff ## symbolName, symbolName, "dlsym " #symbolName " failed"); -#define FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE2(library, varName, symbolName, alternateName) \ - FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, (varName).ff ## symbolName, symbolName, alternateName, "dlsym " #symbolName " failed"); - #define FF_LIBRARY_LOAD_SYMBOL_PTR(library, varName, symbolName, returnValue) \ FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName)->ff ## symbolName, symbolName, returnValue); @@ -87,9 +76,6 @@ void* ffLibraryLoad(const char* path, int maxVersion, ...); #define FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, symbolMapping, symbolName, returnValue) \ symbolMapping = (__typeof__(&symbolName)) &symbolName -#define FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, symbolMapping, symbolName, alternateName, returnValue) \ - symbolMapping = (__typeof__(&symbolName)) &symbolName - #define FF_LIBRARY_LOAD_SYMBOL(library, symbolName, returnValue) \ FF_MAYBE_UNUSED __typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff ## symbolName, symbolName, returnValue); @@ -99,18 +85,12 @@ void* ffLibraryLoad(const char* path, int maxVersion, ...); #define FF_LIBRARY_LOAD_SYMBOL_MESSAGE(library, symbolName) \ FF_MAYBE_UNUSED __typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, ff ## symbolName, symbolName, "dlsym " #symbolName " failed"); -#define FF_LIBRARY_LOAD_SYMBOL_MESSAGE2(library, symbolName, alternateName) \ - FF_MAYBE_UNUSED __typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, ff ## symbolName, symbolName, alternateName, "dlsym " #symbolName " failed"); - #define FF_LIBRARY_LOAD_SYMBOL_VAR(library, varName, symbolName, returnValue) \ FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName).ff ## symbolName, symbolName, returnValue); #define FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(library, varName, symbolName) \ FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName).ff ## symbolName, symbolName, "dlsym " #symbolName " failed"); -#define FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE2(library, varName, symbolName, alternateName) \ - FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, (varName).ff ## symbolName, symbolName, alternateName, "dlsym " #symbolName " failed"); - #define FF_LIBRARY_LOAD_SYMBOL_PTR(library, varName, symbolName, returnValue) \ FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName)->ff ## symbolName, symbolName, returnValue); diff --git a/src/detection/vulkan/vulkan.c b/src/detection/vulkan/vulkan.c index caa6e68d3..3f26b747e 100644 --- a/src/detection/vulkan/vulkan.c +++ b/src/detection/vulkan/vulkan.c @@ -48,10 +48,10 @@ static const char* detectVulkan(FFVulkanResult* result) "libvulkan"FF_LIBRARY_EXTENSION, 2 #endif ) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE2(vulkan, vkGetInstanceProcAddr, vkGetInstanceProcAddr@8) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE2(vulkan, vkCreateInstance, vkCreateInstance@12) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE2(vulkan, vkDestroyInstance, vkDestroyInstance@8) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE2(vulkan, vkEnumeratePhysicalDevices, vkEnumeratePhysicalDevices@12) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(vulkan, vkGetInstanceProcAddr) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(vulkan, vkCreateInstance) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(vulkan, vkDestroyInstance) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(vulkan, vkEnumeratePhysicalDevices) //Some drivers (nvdc) print messages to stdout //and that is the best way I found to disable that From 47b9d0a3a4ce2f56290660fd1b7e71e6bdfb38a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 4 Nov 2024 09:56:44 +0800 Subject: [PATCH 64/72] Library (Windows): load dlls at current exe path --- CHANGELOG.md | 2 ++ src/common/library.c | 11 +++++++++++ src/util/FFstrbuf.h | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00d326396..9a3c50f40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ Features: * Fastfetch now supports all major BSD variants * Support DiskIO, NetIO, GPU and Users module on OpenBSD * Report SD8E SOC name (CPU, Android) +* On Windows, try loading dlls from current exe path (Windows) + * Fix Media module when installed with winget Bugfixes: * Fix the VIM version detection on Ubuntu (Editor, Linux) diff --git a/src/common/library.c b/src/common/library.c index 7bb30c14b..27bac3b82 100644 --- a/src/common/library.c +++ b/src/common/library.c @@ -29,6 +29,17 @@ static void* libraryLoad(const char* path, int maxVersion) // libX.dll.1 never exists on Windows, while libX-1.dll may exist FF_UNUSED(maxVersion) + if(result != NULL) + return result; + + uint32_t pathLen = ffStrbufLastIndexC(&instance.state.platform.exePath, '/'); + if (pathLen == instance.state.platform.exePath.length) + return result; + + char absPath[MAX_PATH + 1]; + strcpy(mempcpy(absPath, instance.state.platform.exePath.chars, pathLen + 1), path); + return dlopen(absPath, FF_DLOPEN_FLAGS); + #else if(result != NULL || maxVersion < 0) diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index fa4a9da87..c40f411e5 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -379,7 +379,7 @@ static inline FF_C_NODISCARD uint32_t ffStrbufFirstIndexS(const FFstrbuf* strbuf static inline FF_C_NODISCARD uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, char c) { if(strbuf->length == 0) - return strbuf->length; + return 0; return ffStrbufPreviousIndexC(strbuf, strbuf->length - 1, c); } From 1487c91f3f791ccba6e8e8f9709fb83e9e8e492e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 4 Nov 2024 10:42:45 +0800 Subject: [PATCH 65/72] OS (Linux): fix build oops --- src/detection/os/os_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/os/os_linux.c b/src/detection/os/os_linux.c index b5b9e67ca..9b00e6cf6 100644 --- a/src/detection/os/os_linux.c +++ b/src/detection/os/os_linux.c @@ -179,7 +179,7 @@ static bool detectDebianDerived(FFOSResult* result) ffStrbufSetS(&result->idLike, "debian"); return true; } - else if (ffStrbufStartsWith(&result->name, "Lilidog GNU/Linux")) + else if (ffStrbufStartsWithS(&result->name, "Lilidog GNU/Linux")) { // https://github.com/fastfetch-cli/fastfetch/issues/1373 ffStrbufSetS(&result->id, "lilidog"); From 7f56928cf0c074a49d43696279926d9b05ba6317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 4 Nov 2024 10:47:52 +0800 Subject: [PATCH 66/72] OS (BSD): don't check for debian and ubuntu variants --- src/detection/os/os_linux.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/detection/os/os_linux.c b/src/detection/os/os_linux.c index 9b00e6cf6..cab2cef8a 100644 --- a/src/detection/os/os_linux.c +++ b/src/detection/os/os_linux.c @@ -46,7 +46,7 @@ static bool parseOsRelease(const char* fileName, FFOSResult* result) }); } -static void getUbuntuFlavour(FFOSResult* result) +FF_MAYBE_UNUSED static void getUbuntuFlavour(FFOSResult* result) { const char* xdgConfigDirs = getenv("XDG_CONFIG_DIRS"); if(!ffStrSet(xdgConfigDirs)) @@ -143,7 +143,7 @@ static void getUbuntuFlavour(FFOSResult* result) } } -static void getDebianVersion(FFOSResult* result) +FF_MAYBE_UNUSED static void getDebianVersion(FFOSResult* result) { FF_STRBUF_AUTO_DESTROY debianVersion = ffStrbufCreate(); ffAppendFileBuffer("/etc/debian_version", &debianVersion); @@ -153,7 +153,7 @@ static void getDebianVersion(FFOSResult* result) ffStrbufSet(&result->versionID, &debianVersion); } -static bool detectDebianDerived(FFOSResult* result) +FF_MAYBE_UNUSED static bool detectDebianDerived(FFOSResult* result) { if (ffStrbufStartsWithS(&result->prettyName, "Armbian ")) // Armbian 24.2.1 bookworm { @@ -265,6 +265,7 @@ void ffDetectOSImpl(FFOSResult* os) { detectOS(os); + #ifdef __linux__ if(ffStrbufIgnCaseEqualS(&os->id, "ubuntu")) getUbuntuFlavour(os); else if(ffStrbufIgnCaseEqualS(&os->id, "debian")) @@ -272,4 +273,5 @@ void ffDetectOSImpl(FFOSResult* os) if (!detectDebianDerived(os)) getDebianVersion(os); } + #endif } From 3c6214d90f2102c8479a4cc6e66ecc29cf8b3e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 4 Nov 2024 10:48:38 +0800 Subject: [PATCH 67/72] Release: 2.29.0 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85cabdb60..b868e4a01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url project(fastfetch - VERSION 2.28.0 + VERSION 2.29.0 LANGUAGES C DESCRIPTION "Fast neofetch-like system information tool" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch" From 02e133bf35ecbe1d9dddf58b2024791619ae8fdd Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 29 Oct 2024 09:34:25 +0800 Subject: [PATCH 68/72] OpenGL (NetBSD): use correct so file --- src/detection/opengl/opengl_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/opengl/opengl_linux.c b/src/detection/opengl/opengl_linux.c index 05a72bf25..452d3e6bd 100644 --- a/src/detection/opengl/opengl_linux.c +++ b/src/detection/opengl/opengl_linux.c @@ -120,7 +120,7 @@ static const char* detectByGlx(FFOpenGLResult* result) GLXData data; FF_LIBRARY_LOAD(glx, "dlopen glx failed", - #if !__OpenBSD__ + #if !__OpenBSD__ && !__NetBSD__ "libGLX" #else "libGL" From 991ebfbc4a22a5e4b92ad4c08a7ab2e18b7add0e Mon Sep 17 00:00:00 2001 From: Carter Li Date: Tue, 29 Oct 2024 09:34:43 +0800 Subject: [PATCH 69/72] Camera (OpenBSD): add support (?) --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b868e4a01..a6081229b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -828,7 +828,7 @@ elseif(OpenBSD) src/detection/wm/wm_nosupport.c src/detection/de/de_linux.c src/detection/wmtheme/wmtheme_linux.c - src/detection/camera/camera_nosupport.c + src/detection/camera/camera_linux.c src/detection/zpool/zpool_nosupport.c src/util/platform/FFPlatform_unix.c src/util/binary_linux.c From e4b98b3494ecd5e80cca716d70140ac8e6aec56d Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 4 Nov 2024 21:59:41 +0800 Subject: [PATCH 70/72] GPU: fix build if libpciaccess is not available --- src/detection/gpu/gpu_general.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/detection/gpu/gpu_general.c b/src/detection/gpu/gpu_general.c index c978bd829..31d7bac3e 100644 --- a/src/detection/gpu/gpu_general.c +++ b/src/detection/gpu/gpu_general.c @@ -60,4 +60,9 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* } #else + +const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FF_MAYBE_UNUSED FFlist* gpus) +{ + return "Fastfetch was built without libpciaccess support"; +} #endif From 7ceabcc03e7e34f34c87035b40a702949376fdae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 4 Nov 2024 14:27:43 +0800 Subject: [PATCH 71/72] CMake (NetBSD): add `/usr/pkg/lib` to rpath --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6081229b..54060ff02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1156,7 +1156,7 @@ elseif(SunOS) elseif(NetBSD) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-char-subscripts") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R7/lib") # ditto + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R7/lib -Wl,-rpath,/usr/pkg/lib") # ditto endif() if(HAVE_STATX) From 55909c480e3149ff13ed5b68ddf03f22743bf12e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 4 Nov 2024 14:47:38 +0800 Subject: [PATCH 72/72] CMake (OpenBSD): enable bluetooth detection I don't think it work, though --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54060ff02..cc33bf5be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -761,8 +761,8 @@ elseif(OpenBSD) src/common/sysctl.c src/detection/battery/battery_nosupport.c src/detection/bios/bios_nosupport.c - src/detection/bluetooth/bluetooth_nosupport.c - src/detection/bluetoothradio/bluetoothradio_nosupport.c + src/detection/bluetooth/bluetooth_linux.c + src/detection/bluetoothradio/bluetoothradio_linux.c src/detection/board/board_nosupport.c src/detection/bootmgr/bootmgr_nosupport.c src/detection/brightness/brightness_nosupport.c