Banjo API 1.0.0-rc.2
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_help = 0;
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("\nBackends:\n");
printf(" %c alsa\n", info->backend_alsa ? '+' : '-');
printf(" %c cocoa\n", info->backend_cocoa ? '+' : '-');
printf(" %c emscripten\n", info->backend_emscripten ? '+' : '-');
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 count = bj_video_backends(0, 0);
printf("\nActive video backends (%zu):\n", count);
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]);
}
}
// 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[] = {
{
.shortname = 'h',
.name = "help",
.help = "Show this help message and exit",
.dest = &flag_help
},
{
.shortname = 'a',
.name = "all",
.help = "Print all info (shorthand for -nvsdc)",
.dest = &flag_all
},
{
.shortname = 'n',
.name = "name-lower",
.help = "Print lowercase name (banjo)",
.dest = &flag_name_lower
},
{
.shortname = 'N',
.name = "name",
.help = "Print name (Banjo)",
.dest = &flag_name
},
{
.shortname = 'v',
.name = "version",
.help = "Print version (1.0.0)",
.dest = &flag_version
},
{
.shortname = 's',
.name = "stage",
.help = "Print release stage (rc.1, alpha, stable)",
.dest = &flag_stage
},
{
.shortname = 'd',
.name = "debug",
.help = "Print 'Debug Build' if debug build",
.dest = &flag_debug
},
{
.shortname = 'c',
.name = "compiler",
.help = "Print compiler name and version",
.dest = &flag_compiler
},
{
.shortname = 'b',
.name = "backends",
.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.
int main(int argc, char *argv[])
Definition audio_pcm.c:177
static int flag_version
Definition banjo-info.c:34
static int flag_backends
Definition banjo-info.c:38
static int flag_all
Definition banjo-info.c:31
static int flag_name_lower
Definition banjo-info.c:32
static void print_all(const bj_build_info *info)
Definition banjo-info.c:62
static int flag_stage
Definition banjo-info.c:35
static int flag_compiler
Definition banjo-info.c:37
static const char * stage_type_name(uint8_t stage)
Definition banjo-info.c:41
static int flag_help
Definition banjo-info.c:30
static int flag_name
Definition banjo-info.c:33
static void print_combined(const bj_build_info *info)
Definition banjo-info.c:101
static size_t format_stage(char *buffer, size_t bufsize, uint8_t stage)
Definition banjo-info.c:53
static int flag_debug
Definition banjo-info.c:36
POSIX/GNU-like command-line argument parser.
void bj_print_cli_help(const struct bj_cli *parser)
Print help message using Banjo's logging system.
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:173
Descriptor for a single command line argument.
Definition cli.h:151
bj_bool checks_log
Checks log failures.
Definition api.h:293
const char * name
API name (see BJ_NAME).
Definition api.h:279
bj_bool pedantic
Extra runtime checks enabled.
Definition api.h:296
uint32_t version
Packed API version (see BJ_VERSION).
Definition api.h:281
bj_bool log_color
Colored log output enabled.
Definition api.h:295
bj_bool backend_win32
Built with Win32 window support.
Definition api.h:290
bj_bool backend_alsa
Built with ALSA audio.
Definition api.h:285
bj_bool fastmath
Built with fast-math optimizations.
Definition api.h:294
bj_bool backend_wayland
Built with Wayland window support.
Definition api.h:289
const char * compiler_name
Compiler name string.
Definition api.h:282
bj_bool backend_x11
Built with X11 window support.
Definition api.h:291
bj_bool backend_emscripten
Built with Emscripten support.
Definition api.h:287
const char * variant
API name variant (see BJ_NAME_VARIANT).
Definition api.h:280
bj_bool debug
Non-zero if built with debug info.
Definition api.h:284
bj_bool backend_cocoa
Built with Cocoa/macOS support.
Definition api.h:286
bj_bool checks_abort
Checks abort execution on failure.
Definition api.h:292
int compiler_version
Compiler version number.
Definition api.h:283
bj_bool backend_mme
Built with Windows MME audio.
Definition api.h:288
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:278
size_t bj_video_backends(const char **p_names, size_t cap)
Enumerate the video backends compiled into this build.
Logging utility functions.
Portable main() replacement with platform-aware entry shim.
Header file for system interactions.
32-bit packed version storage following the SemVer standard.
#define BJ_VERSION_PREVIEW
Preview (feature freeze, bug fixes only)
Definition version.h:51
#define BJ_VERSION_STAGE(version)
Extract the stage byte from a packed 32-bit version.
Definition version.h:92
#define BJ_VERSION_ALPHA
Version stage flags.
Definition version.h:49
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:73
#define BJ_VERSION_MAJOR(version)
Extract the major version from a packed 32-bit version.
Definition version.h:64
#define BJ_VERSION_STABLE
Stable Release.
Definition version.h:53
#define BJ_VERSION_PATCH(version)
Extract the patch version from a packed 32-bit version.
Definition version.h:82
#define BJ_VERSION_RC
Release Candidate (critical fixes only)
Definition version.h:52
#define BJ_VERSION_BETA
Beta (maturing, can still add features)
Definition version.h:50