mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
main/client: simplify code for printing --version string
This commit is contained in:
parent
d48a1c53f5
commit
eb9357709b
5 changed files with 42 additions and 68 deletions
17
client.c
17
client.c
|
|
@ -22,7 +22,6 @@
|
||||||
#include "foot-features.h"
|
#include "foot-features.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "version.h"
|
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
@ -62,20 +61,6 @@ sendall(int sock, const void *_buf, size_t len)
|
||||||
return 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
|
static void
|
||||||
print_usage(const char *prog_name)
|
print_usage(const char *prog_name)
|
||||||
{
|
{
|
||||||
|
|
@ -328,7 +313,7 @@ main(int argc, char *const *argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
printf("footclient %s\n", version_and_features());
|
print_version_and_features("footclient ");
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
|
|
||||||
30
foot-features.c
Normal file
30
foot-features.c
Normal file
|
|
@ -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
|
||||||
|
;
|
||||||
|
|
@ -1,39 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static inline bool feature_assertions(void)
|
extern const char version_and_features[];
|
||||||
{
|
|
||||||
#if defined(NDEBUG)
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool feature_ime(void)
|
static inline void
|
||||||
|
print_version_and_features(const char *prefix)
|
||||||
{
|
{
|
||||||
#if defined(FOOT_IME_ENABLED) && FOOT_IME_ENABLED
|
fputs(prefix, stdout);
|
||||||
return true;
|
fputs(version_and_features, stdout);
|
||||||
#else
|
fputc('\n', stdout);
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
main.c
19
main.c
|
|
@ -31,7 +31,6 @@
|
||||||
#include "shm.h"
|
#include "shm.h"
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "version.h"
|
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
#include "xsnprintf.h"
|
#include "xsnprintf.h"
|
||||||
|
|
||||||
|
|
@ -46,20 +45,6 @@ fdm_sigint(struct fdm *fdm, int signo, void *data)
|
||||||
return true;
|
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
|
static void
|
||||||
print_usage(const char *prog_name)
|
print_usage(const char *prog_name)
|
||||||
{
|
{
|
||||||
|
|
@ -377,7 +362,7 @@ main(int argc, char *const *argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
printf("foot %s\n", version_and_features());
|
print_version_and_features("foot ");
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
|
|
@ -405,7 +390,7 @@ main(int argc, char *const *argv)
|
||||||
argv += optind;
|
argv += optind;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("%s", version_and_features());
|
LOG_INFO("%s", version_and_features);
|
||||||
|
|
||||||
{
|
{
|
||||||
struct utsname name;
|
struct utsname name;
|
||||||
|
|
|
||||||
|
|
@ -295,7 +295,7 @@ executable(
|
||||||
'commands.c', 'commands.h',
|
'commands.c', 'commands.h',
|
||||||
'extract.c', 'extract.h',
|
'extract.c', 'extract.h',
|
||||||
'fdm.c', 'fdm.h',
|
'fdm.c', 'fdm.h',
|
||||||
'foot-features.h',
|
'foot-features.c', 'foot-features.h',
|
||||||
'ime.c', 'ime.h',
|
'ime.c', 'ime.h',
|
||||||
'input.c', 'input.h',
|
'input.c', 'input.h',
|
||||||
'key-binding.c', 'key-binding.h',
|
'key-binding.c', 'key-binding.h',
|
||||||
|
|
@ -323,7 +323,7 @@ executable(
|
||||||
executable(
|
executable(
|
||||||
'footclient',
|
'footclient',
|
||||||
'client.c', 'client-protocol.h',
|
'client.c', 'client-protocol.h',
|
||||||
'foot-features.h',
|
'foot-features.c', 'foot-features.h',
|
||||||
'macros.h',
|
'macros.h',
|
||||||
'util.h',
|
'util.h',
|
||||||
version,
|
version,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue