Banjo API 1.1.0-alpha
Low-level C99 game development API
Loading...
Searching...
No Matches
banjo-info.c

CLI tool to query Banjo build information.

CLI tool to query Banjo build information.This tool outputs version and build information in formats suitable for both human reading and scripting. Flags can be combined to build custom output strings with sensible separators.

Examples: banjo-info -nvs # banjo-1.0.0-rc.1 banjo-info -Nv # Banjo-1.0.0 banjo-info -a # banjo-1.0.0-rc.1 Debug Build, GCC 13 banjo-info -v # 1.0.0 banjo-info -b # x11 (one per line) banjo-info # full human-readable output

#include <banjo/api.h>
#include <banjo/cli.h>
#include <banjo/log.h>
#include <banjo/main.h>
#include <banjo/system.h>
#include <banjo/version.h>
#include <ctype.h>
#include <stdio.h>
// Output flags - set by CLI parser
static int flag_all = 0; // -a: all main info (shorthand for -nvsdc)
static int flag_name_lower = 0; // -n: lowercase name (banjo)
static int flag_name = 0; // -N: name (Banjo)
static int flag_version = 0; // -v: version (1.0.0)
static int flag_stage = 0; // -s: stage (rc.1)
static int flag_debug = 0; // -d: "Debug Build" if debug
static int flag_compiler = 0; // -c: compiler info
static int flag_backends = 0; // -b: list backends
// Helper: get stage type name from stage byte
static const char* stage_type_name(uint8_t stage) {
if (stage == BJ_VERSION_STABLE) return "stable";
switch (stage & 0xC0) {
case BJ_VERSION_ALPHA: return "alpha";
case BJ_VERSION_BETA: return "beta";
case BJ_VERSION_PREVIEW: return "preview";
case BJ_VERSION_RC: return "rc";
default: return "unknown";
}
}
// Helper: format stage string (e.g., "rc.2", "alpha", "stable")
static size_t format_stage(char* buffer, size_t bufsize, uint8_t stage) {
uint8_t num = stage & 0x3F;
if (stage == BJ_VERSION_STABLE || num == 0) {
return (size_t)snprintf(buffer, bufsize, "%s", stage_type_name(stage));
}
return (size_t)snprintf(buffer, bufsize, "%s.%u", stage_type_name(stage), num);
}
// Print full information (default when no flags)
static void print_all(const bj_build_info* info) {
char version_string[32];
bj_format_version(version_string, sizeof(version_string), info->version);
printf("%s version %s (0x%08X) [%s] %s build\n",
info->name,
version_string, info->version,
info->variant,
info->debug ? "Debug" : "Release"
);
printf("Compiler: %s %d\n", info->compiler_name, info->compiler_version);
printf("bj_real: %zu bytes\n", info->real_size);
printf("\nBackends:\n");
printf(" %c alsa\n", info->backend_alsa ? '+' : '-');
printf(" %c cocoa\n", info->backend_cocoa ? '+' : '-');
printf(" %c coreaudio\n", info->backend_coreaudio ? '+' : '-');
printf(" %c emscripten\n", info->backend_emscripten ? '+' : '-');
printf(" %c fake\n", info->backend_fake ? '+' : '-');
printf(" %c mme\n", info->backend_mme ? '+' : '-');
printf(" %c wayland\n", info->backend_wayland ? '+' : '-');
printf(" %c win32\n", info->backend_win32 ? '+' : '-');
printf(" %c x11\n", info->backend_x11 ? '+' : '-');
printf("\nConfiguration:\n");
printf(" %c checks_abort\n", info->checks_abort ? '+' : '-');
printf(" %c checks_log\n", info->checks_log ? '+' : '-');
printf(" %c fastmath\n", info->fastmath ? '+' : '-');
printf(" %c log_color\n", info->log_color ? '+' : '-');
printf(" %c pedantic\n", info->pedantic ? '+' : '-');
const size_t video_count = bj_video_backends(0, 0);
printf("\nActive video backends (%zu):\n", video_count);
const char* names[16];
size_t got = bj_video_backends(names, video_count < 16 ? video_count : 16);
for (size_t i = 0; i < got; ++i) {
printf(" %s\n", names[i]);
}
const size_t audio_count = bj_audio_backends(0, 0);
printf("\nActive audio backends (%zu):\n", audio_count);
got = bj_audio_backends(names, audio_count < 16 ? audio_count : 16);
for (size_t i = 0; i < got; ++i) {
printf(" %s\n", names[i]);
}
}
// Print combined output based on flags
static void print_combined(const bj_build_info* info) {
int printed = 0; // Track if anything printed on main line
// Identity segment: name and version components
for (size_t i = 0; info->name[i]; ++i) {
putchar(tolower((unsigned char)info->name[i]));
}
printed = 1;
} else if (flag_name) {
printf("%s", info->name);
printed = 1;
}
// Version and stage
if (printed) putchar('-');
}
if (flag_version) {
printf("%u.%u.%u",
printed = 1;
}
if (flag_stage) {
if (flag_version) putchar('-');
char stage_str[16];
format_stage(stage_str, sizeof(stage_str), BJ_VERSION_STAGE(info->version));
printf("%s", stage_str);
printed = 1;
}
// Build segment: debug and compiler
if (flag_debug && info->debug) {
if (printed) putchar(' ');
printf("Debug Build");
printed = 1;
}
if (printed) printf(", ");
printf("%s %d", info->compiler_name, info->compiler_version);
printed = 1;
}
// End main line if we printed anything
if (printed) {
putchar('\n');
}
// Backends segment: one per line
const size_t count = bj_video_backends(0, 0);
const char* names[16];
size_t got = bj_video_backends(names, count < 16 ? count : 16);
for (size_t i = 0; i < got; ++i) {
printf("%s\n", names[i]);
}
}
}
int main(int argc, char* argv[]) {
struct bj_cli_argument args[] = {
{
.name = "help",
.shortname = 'h',
.help = "Show this help message and exit",
},
{
.name = "all",
.shortname = 'a',
.help = "Print all info (shorthand for -nvsdc)",
.dest = &flag_all
},
{
.name = "name-lower",
.shortname = 'n',
.help = "Print lowercase name (banjo)",
.dest = &flag_name_lower
},
{
.name = "name",
.shortname = 'N',
.help = "Print name (Banjo)",
.dest = &flag_name
},
{
.name = "version",
.shortname = 'v',
.help = "Print version (1.0.0)",
.dest = &flag_version
},
{
.name = "stage",
.shortname = 's',
.help = "Print release stage (rc.1, alpha, stable)",
.dest = &flag_stage
},
{
.name = "debug",
.shortname = 'd',
.help = "Print 'Debug Build' if debug build",
.dest = &flag_debug
},
{
.name = "compiler",
.shortname = 'c',
.help = "Print compiler name and version",
.dest = &flag_compiler
},
{
.name = "backends",
.shortname = 'b',
.help = "Print available backends (one per line)",
.dest = &flag_backends
},
};
struct bj_cli parser = {
.prog = "banjo-info",
.description = "Query Banjo build information.\n"
"Flags can be combined to build custom output with sensible separators.\n"
"With no flags, prints full human-readable information.",
.epilog = "Examples:\n"
" banjo-info -nvs # banjo-1.0.0-rc.1\n"
" banjo-info -Nv # Banjo-1.0.0\n"
" banjo-info -a # banjo-1.0.0-rc.1 Debug Build, GCC 13\n"
" banjo-info -v # 1.0.0\n"
" banjo-info -b # list backends\n"
" banjo-info # full output",
.arguments_len = sizeof(args) / sizeof(args[0]),
.arguments = args,
};
if (!bj_parse_cli(&parser, argc, argv, 0)) {
return 1;
}
// Expand -a to -nvsdc
if (flag_all) {
}
// Check if any output flag was set
int any_flag = flag_name_lower || flag_name || flag_version || flag_stage ||
if (!any_flag) {
print_all(info);
} else {
}
return 0;
}
General-purpose definitions for Banjo API.
static int flag_version
Definition banjo-info.c:33
static int flag_backends
Definition banjo-info.c:37
static int flag_all
Definition banjo-info.c:30
static int flag_name_lower
Definition banjo-info.c:31
static void print_all(const bj_build_info *info)
Definition banjo-info.c:61
static int flag_stage
Definition banjo-info.c:34
static int flag_compiler
Definition banjo-info.c:36
static const char * stage_type_name(uint8_t stage)
Definition banjo-info.c:40
static int flag_name
Definition banjo-info.c:32
static void print_combined(const bj_build_info *info)
Definition banjo-info.c:110
static size_t format_stage(char *buffer, size_t bufsize, uint8_t stage)
Definition banjo-info.c:52
static int flag_debug
Definition banjo-info.c:35
POSIX/GNU-like command-line argument parser.
void bj_print_cli_help(const struct bj_cli *parser)
Print the help message to standard output.
bj_bool bj_parse_cli(struct bj_cli *parser, int argc, char *argv[], struct bj_error **error)
Parse command-line arguments according to parser configuration.
bj_bool bj_print_cli_help_action(const struct bj_cli *parser, const struct bj_cli_argument *arg, const char *value, void *dest, struct bj_error **error)
Print help argument action.
Parser context and argument list descriptor.
Definition cli.h:185
Descriptor for a single command line argument.
Definition cli.h:159
bj_bool checks_log
Checks log failures.
Definition api.h:303
size_t real_size
Size of bj_real in the library, in bytes (since 1.1).
Definition api.h:309
const char * name
API name (see BJ_NAME).
Definition api.h:289
bj_bool pedantic
Extra runtime checks enabled.
Definition api.h:306
uint32_t version
Packed API version (see BJ_VERSION).
Definition api.h:291
bj_bool backend_fake
Built with the fake video and audio backends (since 1.1).
Definition api.h:308
bj_bool log_color
Colored log output enabled.
Definition api.h:305
bj_bool backend_win32
Built with Win32 window support.
Definition api.h:300
bj_bool backend_coreaudio
Built with CoreAudio audio (since 1.1).
Definition api.h:307
bj_bool backend_alsa
Built with ALSA audio.
Definition api.h:295
bj_bool fastmath
Built with fast-math optimizations.
Definition api.h:304
bj_bool backend_wayland
Built with Wayland window support.
Definition api.h:299
const char * compiler_name
Compiler name string.
Definition api.h:292
bj_bool backend_x11
Built with X11 window support.
Definition api.h:301
bj_bool backend_emscripten
Built with Emscripten support.
Definition api.h:297
const char * variant
API name variant (see BJ_NAME_VARIANT).
Definition api.h:290
bj_bool debug
Non-zero if built with debug info: describes this library's own build, not the including program's ND...
Definition api.h:294
bj_bool backend_cocoa
Built with Cocoa/macOS support.
Definition api.h:296
bj_bool checks_abort
Built with BJ_CONFIG_CHECKS_ABORT, deprecated and without effect.
Definition api.h:302
int compiler_version
Compiler version number.
Definition api.h:293
bj_bool backend_mme
Built with Windows MME audio.
Definition api.h:298
const struct bj_build_info * bj_build_information(void)
Get runtime build information for the loaded Banjo binaries.
Structure holding build information of the binary.
Definition api.h:288
size_t bj_video_backends(const char **p_names, size_t cap)
Enumerate the video backends compiled into this build.
size_t bj_audio_backends(const char **p_names, size_t cap)
Enumerate the audio backends compiled into this build.
Logging utility functions.
Portable main() replacement with platform-aware entry shim.
Header file for system interactions.
int main(void)
32-bit packed version storage following the SemVer standard.
#define BJ_VERSION_PREVIEW
Preview (feature freeze, bug fixes only)
Definition version.h:53
#define BJ_VERSION_STAGE(version)
Extract the stage byte from a packed 32-bit version.
Definition version.h:94
#define BJ_VERSION_ALPHA
Version stage flags.
Definition version.h:51
size_t bj_format_version(char *buffer, size_t bufsize, uint32_t version)
Format a packed version number as a SemVer-compatible string.
#define BJ_VERSION_MINOR(version)
Extract the minor version from a packed 32-bit version.
Definition version.h:75
#define BJ_VERSION_MAJOR(version)
Extract the major version from a packed 32-bit version.
Definition version.h:66
#define BJ_VERSION_STABLE
Stable Release.
Definition version.h:55
#define BJ_VERSION_PATCH(version)
Extract the patch version from a packed 32-bit version.
Definition version.h:84
#define BJ_VERSION_RC
Release Candidate (critical fixes only)
Definition version.h:54
#define BJ_VERSION_BETA
Beta (maturing, can still add features)
Definition version.h:52