diff --git a/client.c b/client.c index e7df3768..e76f2d51 100644 --- a/client.c +++ b/client.c @@ -22,7 +22,6 @@ #include "foot-features.h" #include "macros.h" #include "util.h" -#include "version.h" #include "xmalloc.h" extern char **environ; @@ -62,20 +61,6 @@ sendall(int sock, const void *_buf, size_t len) return len; } -static const char * -version_and_features(void) -{ - static char buf[256]; - snprintf(buf, sizeof(buf), - "version: %s %cpgo %cime %cgraphemes %cassertions", - FOOT_VERSION, - feature_pgo() ? '+' : '-', - feature_ime() ? '+' : '-', - feature_graphemes() ? '+' : '-', - feature_assertions() ? '+' : '-'); - return buf; -} - static void print_usage(const char *prog_name) { @@ -328,7 +313,7 @@ main(int argc, char *const *argv) break; case 'v': - printf("footclient %s\n", version_and_features()); + print_version_and_features("footclient "); ret = EXIT_SUCCESS; goto err; diff --git a/foot-features.c b/foot-features.c new file mode 100644 index 00000000..1b5bf7fd --- /dev/null +++ b/foot-features.c @@ -0,0 +1,30 @@ +#include "foot-features.h" +#include "version.h" + +const char version_and_features[] = + "version: " FOOT_VERSION + +#if defined(FOOT_PGO_ENABLED) && FOOT_PGO_ENABLED + " +pgo" +#else + " -pgo" +#endif + +#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED + " +ime" +#else + " -ime" +#endif + +#if defined(FOOT_GRAPHEME_CLUSTERING) && FOOT_GRAPHEME_CLUSTERING + " +graphemes" +#else + " -graphemes" +#endif + +#if !defined(NDEBUG) + " +assertions" +#else + " -assertions" +#endif +; diff --git a/foot-features.h b/foot-features.h index ad447767..49cc56ed 100644 --- a/foot-features.h +++ b/foot-features.h @@ -1,39 +1,13 @@ #pragma once -#include +#include -static inline bool feature_assertions(void) -{ -#if defined(NDEBUG) - return false; -#else - return true; -#endif -} +extern const char version_and_features[]; -static inline bool feature_ime(void) +static inline void +print_version_and_features(const char *prefix) { -#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED - return true; -#else - return false; -#endif -} - -static inline bool feature_pgo(void) -{ -#if defined(FOOT_PGO_ENABLED) && FOOT_PGO_ENABLED - return true; -#else - return false; -#endif -} - -static inline bool feature_graphemes(void) -{ -#if defined(FOOT_GRAPHEME_CLUSTERING) && FOOT_GRAPHEME_CLUSTERING - return true; -#else - return false; -#endif + fputs(prefix, stdout); + fputs(version_and_features, stdout); + fputc('\n', stdout); } diff --git a/main.c b/main.c index 7e07038f..b9404503 100644 --- a/main.c +++ b/main.c @@ -31,7 +31,6 @@ #include "shm.h" #include "terminal.h" #include "util.h" -#include "version.h" #include "xmalloc.h" #include "xsnprintf.h" @@ -46,20 +45,6 @@ fdm_sigint(struct fdm *fdm, int signo, void *data) return true; } -static const char * -version_and_features(void) -{ - static char buf[256]; - snprintf(buf, sizeof(buf), - "version: %s %cpgo %cime %cgraphemes %cassertions", - FOOT_VERSION, - feature_pgo() ? '+' : '-', - feature_ime() ? '+' : '-', - feature_graphemes() ? '+' : '-', - feature_assertions() ? '+' : '-'); - return buf; -} - static void print_usage(const char *prog_name) { @@ -377,7 +362,7 @@ main(int argc, char *const *argv) break; case 'v': - printf("foot %s\n", version_and_features()); + print_version_and_features("foot "); return EXIT_SUCCESS; case 'h': @@ -405,7 +390,7 @@ main(int argc, char *const *argv) argv += optind; } - LOG_INFO("%s", version_and_features()); + LOG_INFO("%s", version_and_features); { struct utsname name; diff --git a/meson.build b/meson.build index 3d2ce91a..c8f23dfc 100644 --- a/meson.build +++ b/meson.build @@ -295,7 +295,7 @@ executable( 'commands.c', 'commands.h', 'extract.c', 'extract.h', 'fdm.c', 'fdm.h', - 'foot-features.h', + 'foot-features.c', 'foot-features.h', 'ime.c', 'ime.h', 'input.c', 'input.h', 'key-binding.c', 'key-binding.h', @@ -323,7 +323,7 @@ executable( executable( 'footclient', 'client.c', 'client-protocol.h', - 'foot-features.h', + 'foot-features.c', 'foot-features.h', 'macros.h', 'util.h', version,