ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
builder.h File Reference

Options builder API for flexible command-line option configuration. More...

Go to the source code of this file.

Data Structures

 Completion metadata attached to one option descriptor. More...
struct  option_descriptor_t
 The complete registry entry for one command-line/configuration option. More...
struct  usage_descriptor_t
 The complete registry entry for one command-line/configuration option. More...
struct  example_descriptor_t
 Example descriptor for programmatic EXAMPLES generation. More...
struct  help_mode_descriptor_t
 Mode descriptor for programmatic MODES generation (for help output). More...
struct  option_dependency_t
 A rule connecting one option to another during validation. More...
struct  positional_arg_descriptor_t
 Describes one non-option command-line argument and how the parser consumes it. More...
struct  custom_section_descriptor_t
 Describes one non-option command-line argument and how the parser consumes it. More...
struct  options_config_t
 Immutable parsing tables produced from an options builder. More...
struct  options_builder_t
 Immutable parsing tables produced from an options builder. More...

Enumerations

enum  option_type_t {
  OPTION_TYPE_BOOL , OPTION_TYPE_INT , OPTION_TYPE_STRING , OPTION_TYPE_DOUBLE ,
  OPTION_TYPE_CALLBACK , OPTION_TYPE_ACTION
}
 Custom help section descriptor. More...
enum  option_input_type_t {
  OPTION_INPUT_NONE , OPTION_INPUT_ENUM , OPTION_INPUT_NUMERIC , OPTION_INPUT_STRING ,
  OPTION_INPUT_FILEPATH , OPTION_INPUT_CHOICE
}
 Completion input type for smart shell completions. More...
enum  dependency_type_t { DEPENDENCY_REQUIRES , DEPENDENCY_CONFLICTS , DEPENDENCY_IMPLIES }
 Completion metadata attached to one option descriptor. More...

Functions

options_builder_t * options_builder_create (size_t struct_size)
 Mutable owner used to assemble option descriptors, dependencies, help sections, and examples before building a config.
options_builder_t * options_builder_from_preset (const options_config_t *preset)
 Create builder from preset config.
void options_builder_destroy (options_builder_t *builder)
 Free options builder.
options_config_t * options_builder_build (options_builder_t *builder)
 Build immutable options config.
void options_config_destroy (options_config_t *config)
 Free options config.
void options_builder_add_bool (options_builder_t *builder, const char *long_name, char short_name, size_t offset, bool default_value, const char *help_text, const char *group, bool required, const char *env_var_name)
 Add boolean flag option.
void options_builder_add_int (options_builder_t *builder, const char *long_name, char short_name, size_t offset, int default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *options_struct))
 Add integer option.
void options_builder_add_int_with_metadata (options_builder_t *builder, const char *long_name, char short_name, size_t offset, int default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *options_struct), const option_metadata_t *metadata)
 Add integer option with metadata (for numeric ranges and examples).
void options_builder_add_string (options_builder_t *builder, const char *long_name, char short_name, size_t offset, const char *default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *options_struct))
 Add string option.
void options_builder_add_double (options_builder_t *builder, const char *long_name, char short_name, size_t offset, double default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *options_struct), bool optional_arg)
 Add double/float option.
void options_builder_add_double_with_metadata (options_builder_t *builder, const char *long_name, char short_name, size_t offset, double default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *options_struct), const option_metadata_t *metadata, bool optional_arg)
void options_builder_add_callback (options_builder_t *builder, const char *long_name, char short_name, size_t offset, const void *default_value, size_t value_size, bool(*parse_fn)(const char *arg, void *dest, char **error_msg), const char *help_text, const char *group, bool required, const char *env_var_name)
 Add option with custom callback parser.
void options_builder_add_callback_optional (options_builder_t *builder, const char *long_name, char short_name, size_t offset, const void *default_value, size_t value_size, bool(*parse_fn)(const char *arg, void *dest, char **error_msg), const char *help_text, const char *group, bool required, const char *env_var_name, bool optional_arg)
 Add option with custom callback parser that supports optional arguments.
void options_builder_add_callback_with_metadata (options_builder_t *builder, const char *long_name, char short_name, size_t offset, const void *default_value, size_t value_size, bool(*parse_fn)(const char *arg, void *dest, char **error_msg), const char *help_text, const char *group, bool required, const char *env_var_name, bool optional_arg, const option_metadata_t *metadata)
 Add callback option with full metadata (for enums, ranges, examples, etc.).
void options_builder_add_action (options_builder_t *builder, const char *long_name, char short_name, void(*action_fn)(void), const char *help_text, const char *group)
 Add action option (executes action and may exit).
void options_builder_set_mode_bitmask (options_builder_t *builder, option_mode_bitmask_t mode_bitmask)
 Set mode bitmask on the last added option descriptor.
void options_builder_set_arg_placeholder (options_builder_t *builder, const char *arg_placeholder)
 Set custom argument placeholder on the last added option descriptor.
void options_builder_set_enum_values (options_builder_t *builder, const char *option_name, const char **values, const char **descriptions)
 Set enum values with descriptions for an option.
void options_builder_set_numeric_range (options_builder_t *builder, const char *option_name, int min, int max, int step)
 Set numeric range for an option.
void options_builder_set_examples (options_builder_t *builder, const char *option_name, const char **examples)
 Set example values for an option.
void options_builder_set_input_type (options_builder_t *builder, const char *option_name, option_input_type_t input_type)
 Set input type for an option.
void options_builder_mark_as_list (options_builder_t *builder, const char *option_name)
 Mark option as accepting multiple values.
void options_builder_set_default_value_display (options_builder_t *builder, const char *option_name, const char *default_value)
 Set default value string in metadata.
void options_builder_add_descriptor (options_builder_t *builder, const option_descriptor_t *descriptor)
 Add full option descriptor (advanced).
void options_builder_add_dependency_requires (options_builder_t *builder, const char *option_name, const char *depends_on, const char *error_message)
 Add dependency: if option_name is set, depends_on must be set.
void options_builder_add_dependency_conflicts (options_builder_t *builder, const char *option_name, const char *conflicts_with, const char *error_message)
 Add anti-dependency: if option_name is set, conflicts_with must NOT be set.
void options_builder_add_dependency_implies (options_builder_t *builder, const char *option_name, const char *implies, const char *error_message)
 Add implication: if option_name is set, implies defaults to true.
void options_builder_add_dependency (options_builder_t *builder, const option_dependency_t *dependency)
 Add full dependency (advanced).
void options_builder_mark_binary_only (options_builder_t *builder, const char *option_name)
 Mark an option as binary-level only (hide from mode-specific help).
void options_builder_add_positional (options_builder_t *builder, const char *name, const char *help_text, bool required, const char *section_heading, const char **examples, size_t num_examples, option_mode_bitmask_t mode_bitmask, int(*parse_fn)(const char *arg, void *config, char **remaining, int num_remaining, char **error_msg))
 Add positional argument descriptor.
asciichat_error_t options_config_parse_positional (const options_config_t *config, int remaining_argc, char **remaining_argv, void *options_struct)
 Parse positional arguments.
void options_builder_add_usage (options_builder_t *builder, const char *mode, const char *positional, bool show_options, const char *description)
 Add usage line descriptor.
void options_builder_add_example (options_builder_t *builder, uint32_t mode_bitmask, const char *args, const char *description, bool owns_args)
 Add example descriptor.
void options_builder_add_example_utility (options_builder_t *builder, uint32_t mode_bitmask, const char *args, const char *description, bool is_utility_command)
 Add an example with utility command support.
void options_builder_add_mode (options_builder_t *builder, const char *name, const char *description)
 Add mode descriptor.
void options_builder_add_custom_section (options_builder_t *builder, const char *heading, const char *content, option_mode_bitmask_t mode_bitmask)
 Add a custom help section.
options_config_t * options_preset_unified (const char *program_name, const char *description)
 Get binary-level options preset.
asciichat_error_t options_config_set_defaults (const options_config_t *config, void *options_struct)
 Set default values in options struct.
asciichat_error_t options_config_parse (const options_config_t *config, int argc, char **argv, void *options_struct, option_mode_bitmask_t detected_mode, int *remaining_argc, char ***remaining_argv)
 Parse command-line arguments.
asciichat_error_t options_config_validate (const options_config_t *config, const void *options_struct, char **error_message)
 Validate options struct.
int options_config_calculate_max_col_width (const options_config_t *config)
 Calculate global max column width for help output alignment.
void options_config_print_usage (const options_config_t *config, FILE *stream)
 Print usage/help text.
void options_config_print_usage_section (const options_config_t *config, FILE *stream)
 Print only the USAGE section.
void options_config_print_options_sections_with_width (const options_config_t *config, FILE *stream, int max_col_width, asciichat_mode_t mode)
 Print everything except the USAGE section.
void options_config_print_options_sections (const options_config_t *config, FILE *stream, asciichat_mode_t mode)
 Print everything except the USAGE section (backward compatibility).
void options_print_help_for_mode (const options_config_t *config, asciichat_mode_t mode, const char *program_name, const char *description, FILE *desc)
 Print help for a specific mode or binary level (unified function).
void options_struct_destroy (const options_config_t *config, void *options_struct)
 Clean up memory owned by options struct.
const char * options_get_type_placeholder (option_type_t type)
 Get placeholder string for option type.
int options_format_default_value (option_type_t type, const void *default_value, char *buf, size_t bufsize)
 Format option default value to string.
const char * find_similar_option_with_mode (const char *unknown_opt, const options_config_t *config, option_mode_bitmask_t current_mode_bitmask)
 Find similar option across all modes and suggest with mode information.
void options_builder_set_string_parser (options_builder_t *builder, bool(*parser)(const char *, void *, char **))

Detailed Description

Options builder API for flexible command-line option configuration.

This module provides a builder pattern for constructing option configurations that can be used by library consumers to create custom tools based on ascii-chat modes or build entirely custom option sets from scratch.

Integration with Registry and RCU

The builder pattern works together with:

  • Registry (registry.h): Centralized option definitions. Use options_registry_add_all_to_builder() to populate builder with registered options.
  • RCU Thread-Safety (rcu.h): Lock-free access to parsed options. Built configs are used by options_init() to parse and publish to RCU.
  • Mode Bitmasks: Each option includes a mode_bitmask indicating which modes it applies to (SERVER, CLIENT, MIRROR, DISCOVERY_SVC, BINARY, etc.).

Features:

  • Three-tier parsing (binary → mode → mode-specific)
  • Required fields with environment variable fallbacks
  • Option dependencies (REQUIRES, CONFLICTS, IMPLIES)
  • Cross-field validation (validators receive full options struct)
  • Automatic string memory management (auto-strdup, cleanup)
  • Grouped help output with semantic coloring
  • Mode-aware option filtering and applicability
  • Smart shell completion metadata (enums, ranges, examples, filepath hints)
  • Preset configs for server/client/mirror/acds modes

Builder Pattern Workflow

CREATE BUILDER
↓
ADD OPTIONS (with mode bitmasks)
↓
ADD DEPENDENCIES (REQUIRES, CONFLICTS, IMPLIES)
↓
BUILD IMMUTABLE CONFIG
↓
PARSE COMMAND LINE (options are mode-filtered)
↓
VALIDATE (required, dependencies, custom validators)
↓
PUBLISH TO RCU (lock-free thread-safe access)
#define ADD(a, b)
Definition vector.h:58

Builder Usage Patterns

Pattern 1: Start from Registry

// Use registered options as base
options_registry_add_all_to_builder(builder); // Add all registered options
options_config_t * options_builder_build(options_builder_t *builder)
Build immutable options config.
options_builder_t * options_builder_create(size_t struct_size)
Mutable owner used to assemble option descriptors, dependencies, help sections, and examples before b...
struct options_state options_t
Immutable, RCU-published snapshot of the application's runtime configuration.
asciichat_error_t options_registry_add_all_to_builder(options_builder_t *builder)
Add all options from registry to builder.
Definition public_api.c:20
Immutable parsing tables produced from an options builder.
Definition builder.h:457
Immutable parsing tables produced from an options builder.
Definition builder.h:414

Pattern 2: Start from Preset

// Start with unified preset (standard multi-mode setup)
options_config_t *preset = options_preset_unified("ascii-chat", "Terminal video chat");
// Add custom options or modify
options_builder_t * options_builder_from_preset(const options_config_t *preset)
Create builder from preset config.
options_config_t * options_preset_unified(const char *program_name, const char *description)
Build unified options config with ALL options (binary + all modes).
Definition presets.c:58

Pattern 3: Custom Builder from Scratch

// Build entirely custom config
options_builder_t *builder = options_builder_create(sizeof(my_options_t));
options_builder_add_bool(builder, "verbose", 'v', offsetof(my_options_t, verbose), ...);
options_builder_add_int(builder, "port", 'p', offsetof(my_options_t, port), ...);
options_builder_set_mode_bitmask(builder, OPTION_MODE_SERVER); // For last added option
void options_builder_set_mode_bitmask(options_builder_t *builder, option_mode_bitmask_t mode_bitmask)
Set mode bitmask on the last added option descriptor.
void options_builder_add_bool(options_builder_t *builder, const char *long_name, char short_name, size_t offset, bool default_value, const char *help_text, const char *group, bool required, const char *env_var_name)
Add boolean flag option.
void options_builder_add_int(options_builder_t *builder, const char *long_name, char short_name, size_t offset, int default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *options_struct))
Add integer option.
@ OPTION_MODE_SERVER
Server mode (bit 0).
Definition options.h:938

Mode Bitmask System

Options are filtered based on mode using bitmasks:

Each option's mode_bitmask field controls where it appears in:

  • Help output (mode-specific or binary-level)
  • Shell completions
  • Parsing (only options matching detected mode are parsed)

Setting Mode Bitmask:

options_builder_add_int(builder, "max-clients", 'm', ...);
options_builder_set_mode_bitmask(builder, OPTION_MODE_SERVER); // Server-only option

Option Types and Parsing

Option Dependencies

Enforce relationships between options during validation:

Adding Dependencies:

options_builder_add_dependency_requires(builder, "tls-cert", "tls-enabled", NULL);
options_builder_add_dependency_conflicts(builder, "no-crypto", "key-file", NULL);
options_builder_add_dependency_implies(builder, "secure", "tls-enabled", NULL);
void options_builder_add_dependency_requires(options_builder_t *builder, const char *option_name, const char *depends_on, const char *error_message)
Add dependency: if option_name is set, depends_on must be set.
void options_builder_add_dependency_conflicts(options_builder_t *builder, const char *option_name, const char *conflicts_with, const char *error_message)
Add anti-dependency: if option_name is set, conflicts_with must NOT be set.
void options_builder_add_dependency_implies(options_builder_t *builder, const char *option_name, const char *implies, const char *error_message)
Add implication: if option_name is set, implies defaults to true.

RCU Integration

After building and parsing, options are published to RCU for thread-safe access:

options_config_parse(config, argc, argv, &opts, MODE_DETECTION_RESULT, ...);
options_config_validate(config, &opts, NULL);
// Publish to RCU before spawning worker threads
// Now worker threads can safely read options lock-free
const options_t *current_opts = options_get();
int port = current_opts->port; // No locks needed!
asciichat_error_t options_config_parse(const options_config_t *config, int argc, char **argv, void *options_struct, option_mode_bitmask_t detected_mode, int *remaining_argc, char ***remaining_argv)
Parse command-line arguments.
asciichat_error_t options_config_validate(const options_config_t *config, const void *options_struct, char **error_message)
Validate options struct.
const options_t * options_get(void)
Get pointer to current options struct (lock-free, thread-safe).
Definition rcu.c:511
options_t options_t_new(void)
Initialize options by parsing command-line arguments.
Definition options.c:547
asciichat_error_t options_state_init(void)
Initialize RCU options system.
Definition rcu.c:380
asciichat_error_t options_state_set(const options_t *opts)
Set options from a parsed options struct.
Definition rcu.c:450
int port
Server port number.
Definition options.h:1009
See also
registry.h - Central registry of all option definitions
rcu.h - Thread-safe RCU-based access to published Options Module
options.h - Unified Options Module parsing system (uses builder internally)
Author
Zachary Fogg me@zf.nosp@m.o.gg
Date
December 2025

Definition in file builder.h.

Enumeration Type Documentation

◆ dependency_type_t

Completion metadata attached to one option descriptor.

Option dependency types

Defines relationships between options.

Enumerator
DEPENDENCY_REQUIRES 

If A is set, B must be set.

DEPENDENCY_CONFLICTS 

If A is set, B must NOT be set.

DEPENDENCY_IMPLIES 

If A is set, B defaults to true/enabled.

Definition at line 236 of file builder.h.

236 {
dependency_type_t
Completion metadata attached to one option descriptor.
Definition builder.h:236
@ DEPENDENCY_IMPLIES
If A is set, B defaults to true/enabled.
Definition builder.h:239
@ DEPENDENCY_CONFLICTS
If A is set, B must NOT be set.
Definition builder.h:238
@ DEPENDENCY_REQUIRES
If A is set, B must be set.
Definition builder.h:237

◆ option_input_type_t

Completion input type for smart shell completions.

Specifies the kind of input an option expects, used to generate better completions with value suggestions, ranges, and examples.

Enumerator
OPTION_INPUT_NONE 

No input (boolean flag).

OPTION_INPUT_ENUM 

Choose from fixed set of enum values.

OPTION_INPUT_NUMERIC 

Numeric value with optional min/max/step.

OPTION_INPUT_STRING 

Free-form text input.

OPTION_INPUT_FILEPATH 

File path completion.

OPTION_INPUT_CHOICE 

Dynamic choice (e.g., from system).

Definition at line 181 of file builder.h.

181 {
option_input_type_t
Completion input type for smart shell completions.
Definition builder.h:181
@ OPTION_INPUT_STRING
Free-form text input.
Definition builder.h:185
@ OPTION_INPUT_CHOICE
Dynamic choice (e.g., from system).
Definition builder.h:187
@ OPTION_INPUT_NUMERIC
Numeric value with optional min/max/step.
Definition builder.h:184
@ OPTION_INPUT_NONE
No input (boolean flag).
Definition builder.h:182
@ OPTION_INPUT_FILEPATH
File path completion.
Definition builder.h:186
@ OPTION_INPUT_ENUM
Choose from fixed set of enum values.
Definition builder.h:183

◆ option_type_t

Custom help section descriptor.

Example descriptor for programmatic EXAMPLES generation

Mode descriptor for programmatic MODES generation (for help output)

A rule connecting one option to another during validation

Usage line descriptor for programmatic USAGE generation

Option value types

Defines the type of value an option accepts.

Enumerator
OPTION_TYPE_BOOL 

Boolean flag (–flag, no value).

OPTION_TYPE_INT 

Integer value (–count 42).

OPTION_TYPE_STRING 

String value (–name foo).

OPTION_TYPE_DOUBLE 

Floating point (–ratio 1.5).

OPTION_TYPE_CALLBACK 

Custom parser function.

OPTION_TYPE_ACTION 

Action that executes and may exit (–list-webcams, etc.).

Definition at line 166 of file builder.h.

166 {
option_type_t
Custom help section descriptor.
Definition builder.h:166
@ OPTION_TYPE_INT
Integer value (–count 42).
Definition builder.h:168
@ OPTION_TYPE_DOUBLE
Floating point (–ratio 1.5).
Definition builder.h:170
@ OPTION_TYPE_STRING
String value (–name foo).
Definition builder.h:169
@ OPTION_TYPE_ACTION
Action that executes and may exit (–list-webcams, etc.).
Definition builder.h:172
@ OPTION_TYPE_CALLBACK
Custom parser function.
Definition builder.h:171
@ OPTION_TYPE_BOOL
Boolean flag (–flag, no value).
Definition builder.h:167

Function Documentation

◆ find_similar_option_with_mode()

const char * find_similar_option_with_mode ( const char * unknown_opt,
const options_config_t * config,
option_mode_bitmask_t current_mode_bitmask )

Find similar option across all modes and suggest with mode information.

Searches for options matching the unknown option using Levenshtein distance. If found and available in a different mode, suggests it with mode information. For discovery mode, displays it as "the default mode (ascii-chat)".

Parameters
unknown_optUnknown option name (with – prefix)
configOptions configuration (has all descriptors across modes)
current_mode_bitmaskCurrent mode bitmask for filtering
Returns
Formatted suggestion with mode info, or NULL if no good match

Example:

const char *suggestion = find_similar_option_with_mode("--prot", config, current_mode);
if (suggestion) {
log_error("%s", suggestion); // "Did you mean '--port' (available in server mode)?"
}
#define log_error(...)
Log an ERROR message.
Definition log/log.h:634
const char * find_similar_option_with_mode(const char *unknown_opt, const options_config_t *config, option_mode_bitmask_t current_mode_bitmask)
Find similar option across all modes and suggest with mode information.

Definition at line 121 of file options/common.c.

122 {
123 if (!unknown_opt || !config) {
124 return NULL;
125 }
126
127 // Extract the option name without dashes
128 const char *opt_name = unknown_opt;
129 if (strncmp(opt_name, "--", 2) == 0) {
130 opt_name += 2;
131 } else if (strncmp(opt_name, "-", 1) == 0) {
132 opt_name += 1;
133 } else {
134 return NULL; // Not an option format
135 }
136
137 const option_descriptor_t *best_match = NULL;
138 size_t best_distance = SIZE_MAX;
139
140 // Search through all descriptors
141 for (size_t i = 0; i < config->num_descriptors; i++) {
142 const option_descriptor_t *desc = &config->descriptors[i];
143 if (!desc->long_name)
144 continue;
145
146 // Calculate distance to the long name
147 size_t dist = levenshtein(opt_name, desc->long_name);
148 if (dist < best_distance) {
149 best_distance = dist;
150 best_match = desc;
151 }
152 }
153
154 // Only suggest if the distance is within our threshold
155 if (best_distance > LEVENSHTEIN_SUGGESTION_THRESHOLD || !best_match) {
156 return NULL;
157 }
158
159 // Check if the option is not available in current mode
160 bool available_in_current_mode = (best_match->mode_bitmask & current_mode_bitmask) != 0;
161
162 static char suggestion[OPTIONS_COMMON_SUGGESTION_BUFFER_SIZE];
163 if (available_in_current_mode) {
164 // Option exists but user typed it wrong - just suggest the correct spelling
165 safe_snprintf(suggestion, sizeof(suggestion), "Did you mean '--%s'?", best_match->long_name);
166 } else {
167 // Option exists but in a different mode - show all available modes
168 const char *modes_str = format_available_modes(best_match->mode_bitmask);
169 safe_snprintf(suggestion, sizeof(suggestion), "Did you mean '--%s' (available in modes: %s)?",
170 best_match->long_name, modes_str);
171 }
172
173 return suggestion;
174}
size_t levenshtein(const char *a, const char *b)
Calculate Levenshtein distance between two strings.
Definition levenshtein.c:75
#define LEVENSHTEIN_SUGGESTION_THRESHOLD
Maximum edit distance to suggest an option.
Definition levenshtein.h:32
int safe_snprintf(char *buffer, size_t buffer_size, const char *format,...)
Platform-safe snprintf wrapper.
#define OPTIONS_COMMON_SUGGESTION_BUFFER_SIZE
const char * format_available_modes(option_mode_bitmask_t mode_bitmask)
Format all available modes for an option as comma-separated list.
The complete registry entry for one command-line/configuration option.
Definition builder.h:249
option_mode_bitmask_t mode_bitmask
Which modes this option applies to.
Definition builder.h:286
const char * long_name
Long option name (e.g., "port").
Definition builder.h:251
option_descriptor_t * descriptors
Array of option descriptors.
Definition builder.h:415
size_t num_descriptors
Number of descriptors.
Definition builder.h:416

References options_config_t::descriptors, format_available_modes(), levenshtein(), LEVENSHTEIN_SUGGESTION_THRESHOLD, option_descriptor_t::long_name, option_descriptor_t::mode_bitmask, options_config_t::num_descriptors, OPTIONS_COMMON_SUGGESTION_BUFFER_SIZE, and safe_snprintf().

◆ options_builder_add_action()

void options_builder_add_action ( options_builder_t * builder,
const char * long_name,
char short_name,
void(* action_fn )(void),
const char * help_text,
const char * group )

Add action option (executes action and may exit).

Action options execute a callback function when encountered during parsing. The callback may exit the program (e.g., –list-webcams, –version).

Parameters
builderBuilder to add to
long_nameLong option name
short_nameShort option char (or '\0')
action_fnAction callback to execute
help_textHelp description
groupGroup name for help

Referenced by options_registry_add_all_to_builder().

◆ options_builder_add_bool()

void options_builder_add_bool ( options_builder_t * builder,
const char * long_name,
char short_name,
size_t offset,
bool default_value,
const char * help_text,
const char * group,
bool required,
const char * env_var_name )

Add boolean flag option.

Parameters
builderBuilder to add to
long_nameLong option name (e.g., "verbose")
short_nameShort option char (e.g., 'v', or '\0' if none)
offsetoffsetof(struct, field)
default_valueDefault value
help_textHelp description
groupGroup name for help (e.g., "OUTPUT OPTIONS")
requiredIf true, option must be provided
env_var_nameEnvironment variable fallback (or NULL)

Referenced by options_registry_add_all_to_builder().

◆ options_builder_add_callback()

void options_builder_add_callback ( options_builder_t * builder,
const char * long_name,
char short_name,
size_t offset,
const void * default_value,
size_t value_size,
bool(* parse_fn )(const char *arg, void *dest, char **error_msg),
const char * help_text,
const char * group,
bool required,
const char * env_var_name )

Add option with custom callback parser.

Parameters
builderBuilder to add to
long_nameLong option name
short_nameShort option char (or '\0')
offsetoffsetof(struct, field)
default_valuePointer to default value (or NULL)
value_sizesizeof(field_type)
parse_fnCustom parser function
help_textHelp description
groupGroup name for help
requiredIf true, option must be provided
env_var_nameEnvironment variable fallback (or NULL)

◆ options_builder_add_callback_optional()

void options_builder_add_callback_optional ( options_builder_t * builder,
const char * long_name,
char short_name,
size_t offset,
const void * default_value,
size_t value_size,
bool(* parse_fn )(const char *arg, void *dest, char **error_msg),
const char * help_text,
const char * group,
bool required,
const char * env_var_name,
bool optional_arg )

Add option with custom callback parser that supports optional arguments.

Allows the callback to receive NULL if no argument is provided (when next arg is a flag).

Parameters
builderBuilder to add to
long_nameLong option name
short_nameShort option char (or '\0')
offsetoffsetof(struct, field)
default_valuePointer to default value (or NULL)
value_sizesizeof(field_type)
parse_fnCustom parser function (receives NULL if arg not provided)
help_textHelp description
groupGroup name for help
requiredIf true, option must be provided
env_var_nameEnvironment variable fallback (or NULL)
optional_argIf true, argument is optional for this callback

◆ options_builder_add_callback_with_metadata()

void options_builder_add_callback_with_metadata ( options_builder_t * builder,
const char * long_name,
char short_name,
size_t offset,
const void * default_value,
size_t value_size,
bool(* parse_fn )(const char *arg, void *dest, char **error_msg),
const char * help_text,
const char * group,
bool required,
const char * env_var_name,
bool optional_arg,
const option_metadata_t * metadata )

Add callback option with full metadata (for enums, ranges, examples, etc.).

Adds a callback-based option with complete metadata information for help and shell completions.

Parameters
builderBuilder to add to
long_nameLong option name
short_nameShort option char (or '\0')
offsetoffsetof(struct, field)
default_valuePointer to default value
value_sizesizeof(field_type)
parse_fnCustom parser function
help_textHelp description
groupGroup name for help
requiredIf true, option must be provided
env_var_nameEnvironment variable fallback (or NULL)
optional_argIf true, argument is optional for this callback
metadataCompletion metadata (enums, ranges, examples, etc.)

Referenced by options_registry_add_all_to_builder().

◆ options_builder_add_custom_section()

void options_builder_add_custom_section ( options_builder_t * builder,
const char * heading,
const char * content,
option_mode_bitmask_t mode_bitmask )

Add a custom help section.

Adds a custom section to help output that appears after EXAMPLES but before OPTIONS.

Parameters
[in]builderOptions builder
[in]headingSection heading (e.g., "INTERACTIVE CONTROLS")
[in]contentSection content
[in]mode_bitmaskWhich modes show this section (use MODE_BITMASK_* constants)

Referenced by options_preset_unified().

◆ options_builder_add_dependency()

void options_builder_add_dependency ( options_builder_t * builder,
const option_dependency_t * dependency )

Add full dependency (advanced).

Parameters
builderBuilder to add to
dependencyDependency to copy

◆ options_builder_add_dependency_conflicts()

void options_builder_add_dependency_conflicts ( options_builder_t * builder,
const char * option_name,
const char * conflicts_with,
const char * error_message )

Add anti-dependency: if option_name is set, conflicts_with must NOT be set.

Parameters
builderBuilder to add to
option_nameOption that has the conflict
conflicts_withOption it conflicts with
error_messageCustom error message (or NULL for default)

Referenced by options_preset_unified().

◆ options_builder_add_dependency_implies()

void options_builder_add_dependency_implies ( options_builder_t * builder,
const char * option_name,
const char * implies,
const char * error_message )

Add implication: if option_name is set, implies defaults to true.

Parameters
builderBuilder to add to
option_nameOption that implies another
impliesOption that is implied
error_messageCustom message (rarely used, can be NULL)

◆ options_builder_add_dependency_requires()

void options_builder_add_dependency_requires ( options_builder_t * builder,
const char * option_name,
const char * depends_on,
const char * error_message )

Add dependency: if option_name is set, depends_on must be set.

Parameters
builderBuilder to add to
option_nameOption that has the dependency
depends_onOption it depends on
error_messageCustom error message (or NULL for default)

Referenced by options_preset_unified().

◆ options_builder_add_descriptor()

void options_builder_add_descriptor ( options_builder_t * builder,
const option_descriptor_t * descriptor )

Add full option descriptor (advanced).

Parameters
builderBuilder to add to
descriptorDescriptor to copy

◆ options_builder_add_double()

void options_builder_add_double ( options_builder_t * builder,
const char * long_name,
char short_name,
size_t offset,
double default_value,
const char * help_text,
const char * group,
bool required,
const char * env_var_name,
bool(* validate )(const void *options_struct),
bool optional_arg )

Add double/float option.

Parameters
builderBuilder to add to
long_nameLong option name
short_nameShort option char (or '\0')
offsetoffsetof(struct, field)
default_valueDefault value
help_textHelp description
groupGroup name for help
requiredIf true, option must be provided
env_var_nameEnvironment variable fallback (or NULL)
validateValidator function receiving full struct (or NULL)

Referenced by options_registry_add_all_to_builder().

◆ options_builder_add_double_with_metadata()

void options_builder_add_double_with_metadata ( options_builder_t * builder,
const char * long_name,
char short_name,
size_t offset,
double default_value,
const char * help_text,
const char * group,
bool required,
const char * env_var_name,
bool(* validate )(const void *options_struct),
const option_metadata_t * metadata,
bool optional_arg )

◆ options_builder_add_example()

void options_builder_add_example ( options_builder_t * builder,
uint32_t mode_bitmask,
const char * args,
const char * description,
bool owns_args )

Add example descriptor.

Adds an example command to be printed in the EXAMPLES section. Components are colored separately during printing:

  • mode: magenta
  • args: green
Parameters
builderBuilder instance
modeMode name (NULL or "server", "client", "mirror", etc.)
argsArguments (NULL or "example.com", "swift-river-mountain", etc.)
descriptionHelp text for this example

Example:

"Start new session");
options_builder_add_example(b, "server", NULL,
"Run as dedicated server");
options_builder_add_example(b, "client", "example.com",
"Connect to specific server");
void options_builder_add_example(options_builder_t *builder, uint32_t mode_bitmask, const char *args, const char *description, bool owns_args)
Add example descriptor.

Add an example to the help output

Parameters
builderBuilder instance
mode_bitmaskBitmask of modes (OPTION_MODE_SERVER | OPTION_MODE_CLIENT, etc.) Use OPTION_MODE_BINARY for binary-level examples
argsArguments (NULL or "example.com", etc.)
descriptionHelp text for this example
owns_argsIf true, duplicate and track the args string

References args.

Referenced by options_preset_unified().

◆ options_builder_add_example_utility()

void options_builder_add_example_utility ( options_builder_t * builder,
uint32_t mode_bitmask,
const char * args,
const char * description,
bool is_utility_command )

Add an example with utility command support.

Utility commands (like pbpaste, cat, etc.) that shouldn't be prepended with program name or mode in help output.

Parameters
builderBuilder instance
mode_bitmaskBitmask of modes (OPTION_MODE_MIRROR, etc.)
argsArguments (e.g., "pbpaste | cat -", "cat video.avi | ascii-chat mirror -f '-'")
descriptionHelp text for this example
is_utility_commandMust be true for utility commands

References args.

Referenced by options_preset_unified().

◆ options_builder_add_int()

void options_builder_add_int ( options_builder_t * builder,
const char * long_name,
char short_name,
size_t offset,
int default_value,
const char * help_text,
const char * group,
bool required,
const char * env_var_name,
bool(* validate )(const void *options_struct) )

Add integer option.

Parameters
builderBuilder to add to
long_nameLong option name
short_nameShort option char (or '\0')
offsetoffsetof(struct, field)
default_valueDefault value
help_textHelp description
groupGroup name for help
requiredIf true, option must be provided
env_var_nameEnvironment variable fallback (or NULL)
validateValidator function receiving full struct (or NULL)

Referenced by options_registry_add_all_to_builder().

◆ options_builder_add_int_with_metadata()

void options_builder_add_int_with_metadata ( options_builder_t * builder,
const char * long_name,
char short_name,
size_t offset,
int default_value,
const char * help_text,
const char * group,
bool required,
const char * env_var_name,
bool(* validate )(const void *options_struct),
const option_metadata_t * metadata )

Add integer option with metadata (for numeric ranges and examples).

Like options_builder_add_int() but also includes metadata for numeric ranges, examples, and completions.

Parameters
metadataPointer to option_metadata_t with numeric_range, examples, etc. (can be NULL)

Referenced by options_registry_add_all_to_builder().

◆ options_builder_add_mode()

void options_builder_add_mode ( options_builder_t * builder,
const char * name,
const char * description )

Add mode descriptor.

Adds a mode to be printed in the MODES section. The mode name is colored magenta during printing.

Parameters
builderBuilder instance
nameMode name (e.g., "server", "client", "mirror")
descriptionMode description

Example:

options_builder_add_mode(b, "server", "Run as multi-client video chat server");
options_builder_add_mode(b, "client", "Run as video chat client (connect to server)");
options_builder_add_mode(b, "mirror", "View local webcam as ASCII art (no server)");
void options_builder_add_mode(options_builder_t *builder, const char *name, const char *description)
Add mode descriptor.

Referenced by options_preset_unified().

◆ options_builder_add_positional()

void options_builder_add_positional ( options_builder_t * builder,
const char * name,
const char * help_text,
bool required,
const char * section_heading,
const char ** examples,
size_t num_examples,
option_mode_bitmask_t mode_bitmask,
int(* parse_fn )(const char *arg, void *config, char **remaining, int num_remaining, char **error_msg) )

Add positional argument descriptor.

Positional arguments are parsed after getopt finishes, from the remaining argv elements that don't start with '-'. They are parsed in the order they are added to the builder.

Example (client mode):

builder,
"address",
"[address][:port] - Server address (IPv4, IPv6, or hostname) with optional port",
false, // Not required (defaults to localhost)
parse_client_address_arg
);
void options_builder_add_positional(options_builder_t *builder, const char *name, const char *help_text, bool required, const char *section_heading, const char **examples, size_t num_examples, option_mode_bitmask_t mode_bitmask, int(*parse_fn)(const char *arg, void *config, char **remaining, int num_remaining, char **error_msg))
Add positional argument descriptor.

Example (server mode):

builder,
"bind-addr",
"Bind address (IPv4 or IPv6) - can specify 0-2 addresses",
false, // Not required (defaults to localhost dual-stack)
parse_server_bind_addr
);
Parameters
builderBuilder to add to
nameName for help text (e.g., "address")
help_textDescription for usage message
requiredIf true, this positional arg must be provided
section_headingOptional section heading for examples (e.g., "ADDRESS FORMATS")
examplesOptional array of example strings with descriptions
num_examplesNumber of examples in array
mode_bitmaskWhich modes this positional arg applies to
parse_fnCustom parser (receives arg, config, remaining args, error_msg) Returns number of args consumed (usually 1), or -1 on error

Referenced by options_preset_unified().

◆ options_builder_add_string()

void options_builder_add_string ( options_builder_t * builder,
const char * long_name,
char short_name,
size_t offset,
const char * default_value,
const char * help_text,
const char * group,
bool required,
const char * env_var_name,
bool(* validate )(const void *options_struct) )

Add string option.

Strings are automatically strdup'd during parsing and freed during cleanup.

Parameters
builderBuilder to add to
long_nameLong option name
short_nameShort option char (or '\0')
offsetoffsetof(struct, field)
default_valueDefault value (will be strdup'd, or NULL)
help_textHelp description
groupGroup name for help
requiredIf true, option must be provided
env_var_nameEnvironment variable fallback (or NULL)
validateValidator function receiving full struct (or NULL)

Referenced by options_registry_add_all_to_builder().

◆ options_builder_add_usage()

void options_builder_add_usage ( options_builder_t * builder,
const char * mode,
const char * positional,
bool show_options,
const char * description )

Add usage line descriptor.

Adds a usage line to be printed in the USAGE section. Components are colored separately during printing:

  • mode: magenta
  • positional: green
  • "[options...]": yellow
Parameters
builderBuilder instance
modeMode name (NULL for binary-level, or "server", "<mode>", etc.)
positionalPositional args (NULL or "[bind-addr]", "<session-string>", etc.)
show_optionsTrue to append "[options...]" or "[mode-options...]"
descriptionHelp text for this usage pattern

Example:

options_builder_add_usage(b, NULL, NULL, true,
"Start a new session");
options_builder_add_usage(b, NULL, "<session-string>", true,
"Join an existing session");
options_builder_add_usage(b, "<mode>", NULL, true,
"Run in a specific mode");
void options_builder_add_usage(options_builder_t *builder, const char *mode, const char *positional, bool show_options, const char *description)
Add usage line descriptor.

Referenced by options_preset_unified().

◆ options_builder_build()

options_config_t * options_builder_build ( options_builder_t * builder)

Build immutable options config.

Creates final config from builder. Builder is NOT consumed - you must still call options_builder_destroy().

Parameters
builderBuilder with options and dependencies
Returns
Immutable config (must be freed with options_config_destroy)

Referenced by options_builder_generate_manpage_template(), and options_preset_unified().

◆ options_builder_create()

options_builder_t * options_builder_create ( size_t struct_size)

Mutable owner used to assemble option descriptors, dependencies, help sections, and examples before building a config.

Create empty options builder

Parameters
struct_sizesizeof(your_options_t) for the target options struct
Returns
New builder (must be freed with options_builder_destroy)

Referenced by options_preset_unified().

◆ options_builder_destroy()

void options_builder_destroy ( options_builder_t * builder)

Free options builder.

Parameters
builderBuilder to free (can be NULL)

Referenced by options_preset_unified().

◆ options_builder_from_preset()

options_builder_t * options_builder_from_preset ( const options_config_t * preset)

Create builder from preset config.

Copies all descriptors and dependencies from the preset.

Parameters
presetPreset configuration to copy
Returns
New builder (must be freed with options_builder_destroy)

◆ options_builder_mark_as_list()

void options_builder_mark_as_list ( options_builder_t * builder,
const char * option_name )

Mark option as accepting multiple values.

Indicates the option accepts comma-separated or space-separated values.

Parameters
builderOptions builder
option_nameLong name of option to mark

Example:

options_builder_mark_as_list(builder, "stun-servers"); // Accepts comma-separated URLs
void options_builder_mark_as_list(options_builder_t *builder, const char *option_name)
Mark option as accepting multiple values.

◆ options_builder_mark_binary_only()

void options_builder_mark_binary_only ( options_builder_t * builder,
const char * option_name )

Mark an option as binary-level only (hide from mode-specific help).

Binary-level options are still parsed by mode-specific parsers (so they work anywhere in the command line), but they don't appear in mode-specific –help. They should only be documented in the top-level binary help.

Parameters
builderBuilder containing the option
option_nameLong name of the option to mark

Example:

options_builder_add_string(b, "log-file", 'L', ...);
void options_builder_mark_binary_only(options_builder_t *builder, const char *option_name)
Mark an option as binary-level only (hide from mode-specific help).
void options_builder_add_string(options_builder_t *builder, const char *long_name, char short_name, size_t offset, const char *default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *options_struct))
Add string option.

◆ options_builder_set_arg_placeholder()

void options_builder_set_arg_placeholder ( options_builder_t * builder,
const char * arg_placeholder )

Set custom argument placeholder on the last added option descriptor.

Sets the arg_placeholder field on the most recently added option descriptor. This allows customizing the placeholder text shown in help (e.g., "SHELL [FILE]" instead of "STR").

Parameters
builderOptions builder
arg_placeholderCustom placeholder text (e.g., "SHELL [FILE]"), or NULL to use type-based placeholder

Referenced by options_registry_add_all_to_builder().

◆ options_builder_set_default_value_display()

void options_builder_set_default_value_display ( options_builder_t * builder,
const char * option_name,
const char * default_value )

Set default value string in metadata.

Sets the default value string for display in completions (informational, separate from the descriptor's default_value which is used for parsing).

Parameters
builderOptions builder
option_nameLong name of option to set metadata for
default_valueDefault value as string for display

◆ options_builder_set_enum_values()

void options_builder_set_enum_values ( options_builder_t * builder,
const char * option_name,
const char ** values,
const char ** descriptions )

Set enum values with descriptions for an option.

Populates the metadata with enum values and descriptions for shell completion. Both arrays must have the same length.

Parameters
builderOptions builder
option_nameLong name of option to set metadata for
valuesArray of enum value strings (e.g., {"auto", "none", "16", "256", "truecolor"})
descriptionsArray of descriptions parallel to values
countNumber of values/descriptions

Example:

const char *color_values[] = {"auto", "none", "16", "256", "truecolor"};
const char *color_descs[] = {
"Auto-detect from terminal",
"Monochrome only",
"16 colors (ANSI)",
"256 colors (xterm)",
"24-bit truecolor (modern terminals)"
};
options_builder_set_enum_values(builder, "color-mode", color_values, color_descs, 5);
void options_builder_set_enum_values(options_builder_t *builder, const char *option_name, const char **values, const char **descriptions)
Set enum values with descriptions for an option.
void options_builder_set_input_type(options_builder_t *builder, const char *option_name, option_input_type_t input_type)
Set input type for an option.

Referenced by options_registry_add_all_to_builder().

◆ options_builder_set_examples()

void options_builder_set_examples ( options_builder_t * builder,
const char * option_name,
const char ** examples )

Set example values for an option.

Provides example values or command invocations for help display and completion suggestions.

Parameters
builderOptions builder
option_nameLong name of option to set metadata for
examplesArray of example strings (must be null-terminated, may be values or full commands)

Example:

const char *fps_examples[] = {"30", "60", "144", NULL};
options_builder_set_examples(builder, "fps", fps_examples);
void options_builder_set_examples(options_builder_t *builder, const char *option_name, const char **examples)
Set example values for an option.

◆ options_builder_set_input_type()

void options_builder_set_input_type ( options_builder_t * builder,
const char * option_name,
option_input_type_t input_type )

Set input type for an option.

Specifies what kind of input the option expects (enum, numeric, filepath, etc.) for generating appropriate shell completions.

Parameters
builderOptions builder
option_nameLong name of option to set metadata for
input_typeThe input type (OPTION_INPUT_ENUM, OPTION_INPUT_NUMERIC, etc.)

Example:

Referenced by options_registry_add_all_to_builder().

◆ options_builder_set_mode_bitmask()

void options_builder_set_mode_bitmask ( options_builder_t * builder,
option_mode_bitmask_t mode_bitmask )

Set mode bitmask on the last added option descriptor.

Sets the mode_bitmask field on the most recently added option descriptor. This allows setting mode applicability after adding an option.

Parameters
builderOptions builder
mode_bitmaskBitmask indicating which modes this option applies to

Referenced by options_registry_add_all_to_builder().

◆ options_builder_set_numeric_range()

void options_builder_set_numeric_range ( options_builder_t * builder,
const char * option_name,
int min,
int max,
int step )

Set numeric range for an option.

Specifies minimum, maximum, and optional step for numeric input completions.

Parameters
builderOptions builder
option_nameLong name of option to set metadata for
minMinimum value (0 = no limit)
maxMaximum value (0 = no limit)
stepStep size (0 = continuous, no step)

Example:

options_builder_set_numeric_range(builder, "compression-level", 1, 9, 1);
void options_builder_set_numeric_range(options_builder_t *builder, const char *option_name, int min, int max, int step)
Set numeric range for an option.

◆ options_builder_set_string_parser()

void options_builder_set_string_parser ( options_builder_t * builder,
bool(* parser )(const char *, void *, char **) )

Set the CLI parser for the last added string option; environment strings remain scalar.

Referenced by options_registry_add_all_to_builder().

◆ options_config_calculate_max_col_width()

int options_config_calculate_max_col_width ( const options_config_t * config)

Calculate global max column width for help output alignment.

Calculates the maximum width needed for proper alignment across all help sections (USAGE, EXAMPLES, OPTIONS, MODES).

Parameters
configOptions configuration
Returns
Maximum column width needed for alignment

◆ options_config_destroy()

void options_config_destroy ( options_config_t * config)

Free options config.

Frees the config structure. Does NOT free strings in the options struct - use options_config_destroy() for that.

Parameters
configConfig to free (can be NULL)

Referenced by config_create_default(), options_init(), and usage().

◆ options_config_parse()

asciichat_error_t options_config_parse ( const options_config_t * config,
int argc,
char ** argv,
void * options_struct,
option_mode_bitmask_t detected_mode,
int * remaining_argc,
char *** remaining_argv )

Parse command-line arguments.

Parses argv using the option descriptors. Strings are automatically strdup'd. Environment variables are checked for missing options.

Parameters
configOptions configuration
argcArgument count
argvArgument vector
options_structOptions struct to fill
remaining_argcOptional: receives count of non-option args
remaining_argvOptional: receives array of non-option args
Returns
ASCIICHAT_OK on success, ERROR_USAGE on parse errors

◆ options_config_parse_positional()

asciichat_error_t options_config_parse_positional ( const options_config_t * config,
int remaining_argc,
char ** remaining_argv,
void * options_struct )

Parse positional arguments.

Parses positional arguments from remaining_argv after getopt processing. Calls each positional arg descriptor's parse_fn in order.

This is called automatically by options_config_parse(), but can also be called separately if you want custom control over the parsing flow.

Parameters
configOptions configuration
remaining_argcCount of remaining args
remaining_argvArray of remaining args
options_structOptions struct to fill
Returns
ASCIICHAT_OK on success, ERROR_USAGE on parse errors

◆ options_config_print_options_sections()

void options_config_print_options_sections ( const options_config_t * config,
FILE * stream,
asciichat_mode_t mode )

Print everything except the USAGE section (backward compatibility).

Wrapper for options_config_print_options_sections_with_width with auto-calculation.

Parameters
configOptions configuration
streamOutput stream (stdout or stderr)
modeOptional mode to filter by (if provided, filters by mode_bitmask)

◆ options_config_print_options_sections_with_width()

void options_config_print_options_sections_with_width ( const options_config_t * config,
FILE * stream,
int max_col_width,
asciichat_mode_t mode )

Print everything except the USAGE section.

Prints MODES, MODE-OPTIONS, EXAMPLES, and OPTIONS sections. Used with options_config_print_usage_section to allow custom content in between.

Parameters
configOptions configuration (should be unified preset with all options)
streamOutput stream (stdout or stderr)
max_col_widthOptional pre-calculated column width (0 = auto-calculate)
modeOptional mode to filter by (if MODE_SERVER, MODE_CLIENT, etc., filters by mode_bitmask) If NULL or invalid, shows all options (for binary-level help)

◆ options_config_print_usage()

void options_config_print_usage ( const options_config_t * config,
FILE * stream )

Print usage/help text.

Generates formatted help with grouped options.

Parameters
configOptions configuration
streamOutput stream (stdout or stderr)

◆ options_config_print_usage_section()

void options_config_print_usage_section ( const options_config_t * config,
FILE * stream )

Print only the USAGE section.

Prints just the USAGE section. Useful for inserting other content (like positional argument examples) between USAGE and other sections.

Parameters
configOptions configuration
streamOutput stream (stdout or stderr)

◆ options_config_set_defaults()

asciichat_error_t options_config_set_defaults ( const options_config_t * config,
void * options_struct )

Set default values in options struct.

Sets defaults from descriptors, checking environment variables for options with env_var_name set.

Parameters
configOptions configuration
options_structOptions struct to initialize
Returns
ASCIICHAT_OK on success, error code on failure

◆ options_config_validate()

asciichat_error_t options_config_validate ( const options_config_t * config,
const void * options_struct,
char ** error_message )

Validate options struct.

Checks:

  • Required fields are set
  • Dependencies are satisfied
  • Custom validators pass
Parameters
configOptions configuration
options_structOptions struct to validate
error_messageOptional: receives detailed error message (must free)
Returns
ASCIICHAT_OK if valid, error code otherwise

Referenced by validate_options_and_report().

◆ options_format_default_value()

int options_format_default_value ( option_type_t type,
const void * default_value,
char * buf,
size_t bufsize )

Format option default value to string.

Formats default value according to option type:

  • BOOL: "true" or "false"
  • INT: "%d" format
  • STRING: raw string (caller applies escaping if needed)
  • DOUBLE: "%.2f" format
Parameters
typeOption type enum value
default_valuePointer to default value (type-specific)
bufOutput buffer
bufsizeSize of output buffer
Returns
Number of characters written, or 0 on error

Definition at line 590 of file options/common.c.

590 {
591 if (!default_value || !buf || bufsize == 0) {
592 return 0;
593 }
594
595 switch (type) {
596 case OPTION_TYPE_BOOL:
597 return safe_snprintf(buf, bufsize, "%s", *(const bool *)default_value ? OPT_VALUE_TRUE : OPT_VALUE_FALSE);
598 case OPTION_TYPE_INT: {
599 int int_val = 0;
600 memcpy(&int_val, default_value, sizeof(int));
601 return safe_snprintf(buf, bufsize, "%d", int_val);
602 }
604 return safe_snprintf(buf, bufsize, "%s", *(const char *const *)default_value);
605 case OPTION_TYPE_DOUBLE: {
606 double double_val = 0.0;
607 memcpy(&double_val, default_value, sizeof(double));
608 return safe_snprintf(buf, bufsize, "%.2f", double_val);
609 }
610 default:
611 // OPTION_TYPE_CALLBACK and OPTION_TYPE_ACTION don't have defaults to display
612 return 0;
613 }
614}
#define OPT_VALUE_FALSE
Definition enums.h:79
#define OPT_VALUE_TRUE
Definition enums.h:78

References OPT_VALUE_FALSE, OPT_VALUE_TRUE, OPTION_TYPE_BOOL, OPTION_TYPE_DOUBLE, OPTION_TYPE_INT, OPTION_TYPE_STRING, and safe_snprintf().

Referenced by manpage_content_generate_options().

◆ options_get_type_placeholder()

const char * options_get_type_placeholder ( option_type_t type)

Get placeholder string for option type.

Returns standardized placeholder strings for use in help text and man pages:

  • INT/DOUBLE → "NUM"
  • STRING → "STR"
  • CALLBACK → "VAL"
  • BOOL/ACTION → "" (empty string)
Parameters
typeOption type enum value
Returns
Pointer to string literal (never NULL, may be empty)

Definition at line 572 of file options/common.c.

572 {
573 switch (type) {
574 case OPTION_TYPE_INT:
575 return "INTEGER";
577 return "NUMBER";
579 return "STRING";
581 return "VALUE";
582 case OPTION_TYPE_BOOL:
583 return "BOOLEAN";
585 default:
586 return "";
587 }
588}

References OPTION_TYPE_ACTION, OPTION_TYPE_BOOL, OPTION_TYPE_CALLBACK, OPTION_TYPE_DOUBLE, OPTION_TYPE_INT, and OPTION_TYPE_STRING.

Referenced by manpage_content_generate_options().

◆ options_preset_unified()

options_config_t * options_preset_unified ( const char * program_name,
const char * description )

Get binary-level options preset.

Binary options are parsed BEFORE mode selection. Includes: –help, –version, –log-file, –log-level, etc.

Parameters
program_nameOptional program name (defaults to "ascii-chat")
descriptionOptional program description
Returns
Preset config (caller must free after use)

Get binary-level options preset.

This is the single source of truth for all options. Each option has a mode_bitmask indicating which modes it applies to. The config includes all options, and validation happens after parsing based on detected mode.

Definition at line 58 of file presets.c.

58 {
60 if (!b) {
61 SET_ERRNO(ERROR_MEMORY, "Failed to create options builder");
62 return NULL;
63 }
64
65 b->program_name = program_name ? program_name : "ascii-chat";
66 b->description = description ? description : "Video chat in your terminal";
67
68 // Add ALL options from registry (binary + all modes)
70 if (err != ASCIICHAT_OK) {
72 SET_ERRNO(err, "Failed to add all options to builder");
73 return NULL;
74 }
75
76 // Add positional arguments for each mode
77 // These allow parsing of positional arguments like "192.168.1.1" for client mode
78 // and "[bind-address]" for server mode
79
80 // Generate random session strings for examples
81 // Use static buffers so they persist after the function returns
82 static char session_buf1[SESSION_STRING_BUFFER_SIZE];
83 static char session_buf2[SESSION_STRING_BUFFER_SIZE];
84 static char session_buf3[SESSION_STRING_BUFFER_SIZE];
85 static char session_buf4[SESSION_STRING_BUFFER_SIZE];
86 static char session_buf5[SESSION_STRING_BUFFER_SIZE];
87 static char session_buf6[SESSION_STRING_BUFFER_SIZE];
88 static char session_buf7[SESSION_STRING_BUFFER_SIZE];
89 static char session_buf8[SESSION_STRING_BUFFER_SIZE];
90 static char session_buf9[SESSION_STRING_BUFFER_SIZE];
91 static char session_buf10[SESSION_STRING_BUFFER_SIZE];
92
93 // Fallback strings if generation fails
94 char *example_session_string1 = "adjective-noun-noun";
95 char *example_session_string2 = "adjective-noun-noun";
96 char *example_session_string3 = "adjective-noun-noun";
97 char *example_session_string4 = "adjective-noun-noun";
98 char *example_session_string5 = "adjective-noun-noun";
99 char *example_session_string6 = "adjective-noun-noun";
100 char *example_session_string7 = "adjective-noun-noun";
101 char *example_session_string8 = "adjective-noun-noun";
102 char *example_session_string9 = "adjective-noun-noun";
103 char *example_session_string10 = "adjective-noun-noun";
104
105 // Generate session strings for examples (sodium_init called as needed by acds_string_generate)
106 acds_string_generate(session_buf1, sizeof(session_buf1));
107 if (session_buf1[0] != '\0') {
108 example_session_string1 = session_buf1;
109 }
110 acds_string_generate(session_buf2, sizeof(session_buf2));
111 if (session_buf2[0] != '\0') {
112 example_session_string2 = session_buf2;
113 }
114 acds_string_generate(session_buf3, sizeof(session_buf3));
115 if (session_buf3[0] != '\0') {
116 example_session_string3 = session_buf3;
117 }
118 acds_string_generate(session_buf4, sizeof(session_buf4));
119 if (session_buf4[0] != '\0') {
120 example_session_string4 = session_buf4;
121 }
122 acds_string_generate(session_buf5, sizeof(session_buf5));
123 if (session_buf5[0] != '\0') {
124 example_session_string5 = session_buf5;
125 }
126 acds_string_generate(session_buf6, sizeof(session_buf6));
127 if (session_buf6[0] != '\0') {
128 example_session_string6 = session_buf6;
129 }
130 acds_string_generate(session_buf7, sizeof(session_buf7));
131 if (session_buf7[0] != '\0') {
132 example_session_string7 = session_buf7;
133 }
134 acds_string_generate(session_buf8, sizeof(session_buf8));
135 if (session_buf8[0] != '\0') {
136 example_session_string8 = session_buf8;
137 }
138 acds_string_generate(session_buf9, sizeof(session_buf9));
139 if (session_buf9[0] != '\0') {
140 example_session_string9 = session_buf9;
141 }
142 acds_string_generate(session_buf10, sizeof(session_buf10));
143 if (session_buf10[0] != '\0') {
144 example_session_string10 = session_buf10;
145 }
146
147 // Build session string examples dynamically for discovery mode
148 // These appear at the beginning of the examples section, right after "start new session"
149 static char example_buf1[SESSION_STRING_BUFFER_SIZE];
150 static char example_buf2[SESSION_STRING_BUFFER_SIZE];
151 static char example_buf3[SESSION_STRING_BUFFER_SIZE];
152 static char example_buf4[SESSION_STRING_BUFFER_SIZE];
153 static char example_buf5[SESSION_STRING_BUFFER_SIZE];
154 static char example_buf6[SESSION_STRING_BUFFER_SIZE];
155 static char example_buf7[SESSION_STRING_BUFFER_SIZE];
156 static char example_buf8[SESSION_STRING_BUFFER_SIZE];
157 static char example_buf9[SESSION_STRING_BUFFER_SIZE];
158 static char example_buf10[SESSION_STRING_BUFFER_SIZE];
159
160 safe_snprintf(example_buf1, sizeof(example_buf1), "%s", example_session_string1);
161 safe_snprintf(example_buf2, sizeof(example_buf2), "%s", example_session_string2);
162 safe_snprintf(example_buf3, sizeof(example_buf3), "%s", example_session_string3);
163 safe_snprintf(example_buf4, sizeof(example_buf4), "%s", example_session_string4);
164 safe_snprintf(example_buf5, sizeof(example_buf5), "%s", example_session_string5);
165 safe_snprintf(example_buf6, sizeof(example_buf6), "%s", example_session_string6);
166 safe_snprintf(example_buf7, sizeof(example_buf7), "%s", example_session_string7);
167 safe_snprintf(example_buf8, sizeof(example_buf8), "%s", example_session_string8);
168 safe_snprintf(example_buf9, sizeof(example_buf9), "%s", example_session_string9);
169 safe_snprintf(example_buf10, sizeof(example_buf10), "%s", example_session_string10);
170
171 // Client mode: [address] - can be IP, hostname, hostname:port, or WebSocket URL
172 static const char *client_examples[] = {"localhost",
173 "ascii-chat.com",
174 "0.0.0.0",
175 "::",
176 "192.168.1.1:8080",
177 "[2001:db8::42]:27224",
178 "233.27.48.203:27224",
179 "62fb:759e:2bce:21d7:9e5d:13f8:3c11:5084:27224",
180 "ws://example.com:8080",
181 "wss://secure.example.com:443"};
182 // Discovery mode: [session-string] - session string or empty to start new session
183 // Use simple static examples for positional arguments section (dynamic strings shown in examples section)
184 static const char *discovery_examples[] = {
185 "(empty/unset) start new session. generates a session string to give someone to connect to you.",
186 (const char *)example_buf7, (const char *)example_buf8, (const char *)example_buf9, (const char *)example_buf10};
188 b, "session-string", "(optional) Random three words in format adjective-noun-noun that connect you to a call.",
189 false, "POSITIONAL ARGUMENTS", discovery_examples, ARRAY_SIZE(discovery_examples), OPTION_MODE_DISCOVERY,
191
192 // Server and Discovery Service modes: [bind-address] [bind-address] - can be IP or hostname, up to 2 for IPv4/IPv6
193 static const char *server_examples[] = {"localhost",
194 "ascii-chat.com",
195 "0.0.0.0",
196 "::",
197 "234.50.188.236",
198 "9631:54e7:5b5c:80dc:0f62:1f01:7ccf:5512",
199 "105.137.19.11 3a08:7276:ccb4:7b31:e934:5330:9b3a:9598",
200 "::1 192.168.1.100"};
202 b, "bind-address", "(optional) 0-2 addresses for a server to bind to, one IPv4 and the other IPv6.", false,
203 "POSITIONAL ARGUMENTS", server_examples, ARRAY_SIZE(server_examples),
205
206 options_builder_add_positional(b, "address", "(optional) Server address for client to connect to.", false,
207 "POSITIONAL ARGUMENTS", client_examples, ARRAY_SIZE(client_examples),
209
210 // Mirror mode: [file|url] - file path or URL to stream
211 static const char *mirror_media_examples[] = {"/path/to/video.mp4", "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
212 "https://example.com/stream.m3u8"};
213 options_builder_add_positional(b, "file|url",
214 "(optional) Media file path or URL to stream. If omitted, uses webcam. "
215 "Cannot be combined with --file or --url.",
216 false, "POSITIONAL ARGUMENTS", mirror_media_examples,
217 ARRAY_SIZE(mirror_media_examples), OPTION_MODE_MIRROR, parse_mirror_media);
218
219 // Add usage lines for all modes
220 options_builder_add_usage(b, NULL, NULL, true, "Start a new session (share the session string)");
221 options_builder_add_usage(b, NULL, "<session-string>", true, "Join an existing session");
222 options_builder_add_usage(b, NULL, "<mode>", true, "Run in a specific mode");
223 options_builder_add_usage(b, "mcp-server", "[--transport http|stdio] [--server] [bind-address] [bind-address]", true,
224 "MCP rendering tools (stdio locally, HTTP with --transport http, default port 27228)");
225 options_builder_add_example(b, OPTION_MODE_MCP_SERVER, "", "Local MCP tools over stdio", false);
226 options_builder_add_example(b, OPTION_MODE_MCP_SERVER, "--transport http --address 127.0.0.1 --port 27228",
227 "Local MCP tools over Streamable HTTP", false);
228 options_builder_add_usage(b, "server", "[bind-address] [bind-address]", true,
229 "Start server (can specify 0-2 bind addresses, one IPv4 and the other IPv6)");
230 options_builder_add_usage(b, "client", "[address]", true, "Connect to server (defaults to localhost:27224)");
231 options_builder_add_usage(b, "mirror", "[file|url]", true, "View local webcam or media file or URL as ASCII art");
232 options_builder_add_usage(b, "discovery-service", "[bind-address] [bind-address]", true,
233 "Start discovery service (can specify 0-2 bind addresses, one IPv4 and the other IPv6)");
234 options_builder_add_usage(b, NULL, "[mode] --help", false, "Show help for a specific mode");
235
236 // Add examples for binary-level help and discovery mode
237 options_builder_add_example(b, OPTION_MODE_BINARY, NULL, "Start new session (share the session string)", false);
238 options_builder_add_example(b, OPTION_MODE_BINARY, example_buf1, "Join a session using the session string", true);
239
240 // Build combined examples with session string + flags
241 static char combined_buf1[OPTIONS_CONFIG_PRESETS_COMBINED_BUF1_BUFFER_SIZE];
242 static char combined_buf2[OPTIONS_CONFIG_PRESETS_COMBINED_BUF2_BUFFER_SIZE];
243 static char combined_buf3[OPTIONS_CONFIG_PRESETS_COMBINED_BUF3_BUFFER_SIZE];
244 static char combined_buf4[OPTIONS_CONFIG_PRESETS_COMBINED_BUF4_BUFFER_SIZE];
245 static char combined_buf5[OPTIONS_CONFIG_PRESETS_COMBINED_BUF5_BUFFER_SIZE];
246 safe_snprintf(combined_buf1, sizeof(combined_buf1), "%s --file video.mp4", example_buf3);
247 safe_snprintf(combined_buf2, sizeof(combined_buf2), "%s --url 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'",
248 example_buf4);
249 safe_snprintf(combined_buf3, sizeof(combined_buf3), "%s -f -", example_buf5);
250 safe_snprintf(combined_buf4, sizeof(combined_buf4), "%s --palette-chars '@%%#*+=-:. '", example_buf6);
251 safe_snprintf(combined_buf5, sizeof(combined_buf5), "%s --discovery-service --discovery-service-port 27225",
252 example_buf2);
253
254 options_builder_add_example(b, OPTION_MODE_BINARY, combined_buf1, "Join session and stream from local video file",
255 false);
256 options_builder_add_example(b, OPTION_MODE_BINARY, combined_buf2, "Join session and stream from YouTube video",
257 false);
258 options_builder_add_example(b, OPTION_MODE_BINARY, combined_buf3, "Join session and stream media from stdin", false);
259 options_builder_add_example(b, OPTION_MODE_BINARY, combined_buf4, "Join session with custom ASCII palette characters",
260 false);
261 options_builder_add_example(b, OPTION_MODE_BINARY, combined_buf5, "Join session via custom discovery server", false);
262
263 // Add examples for server-like modes (server + discovery-service)
264 options_builder_add_example(b, OPTION_MODE_SERVER_LIKE, NULL, "Start on localhost (127.0.0.1 and ::1)", false);
265 options_builder_add_example(b, OPTION_MODE_SERVER_LIKE, "0.0.0.0", "Start on all IPv4 interfaces", false);
267 "0.0.0.0 ::", "Start on all IPv4 and IPv6 interfaces (dual-stack)", false);
268 options_builder_add_example(b, OPTION_MODE_SERVER_LIKE, "--port 8080", "Start on custom port", false);
269
270 // Server-specific examples
271 options_builder_add_example(b, OPTION_MODE_SERVER, "--key ~/.ssh/id_ed25519 --discovery",
272 "Start with identity key and discovery registration", false);
273
274 // Add examples for client-like modes (client + mirror)
275 options_builder_add_example(b, OPTION_MODE_CLIENT_LIKE, "--url 'https://youtu.be/7ynHVGCehoM'",
276 "Stream from YouTube URL (also supports RTSP, HTTP, and HTTPS URLs)", false);
277 options_builder_add_example(b, OPTION_MODE_CLIENT_LIKE, "--url 'https://www.twitch.tv/ludwig'",
278 "Stream Ludwig from videogames on Twitch", false);
279 options_builder_add_example(b, OPTION_MODE_CLIENT_LIKE, "-f video.mp4", "Stream from local video file", false);
280 options_builder_add_example(b, OPTION_MODE_CLIENT_LIKE, "--palette-chars '@%#*+=-:. '",
281 "Custom palette characters to use. UTF-8 is allowed.", false);
283 b, OPTION_MODE_CLIENT_LIKE, "--snapshot",
284 "Print ascii art for --snapshot-delay's value of seconds then print the last frame and exit. "
285 "In snapshot mode, --width, --height, and --color are NOT autodetected when piping stdin in or redirecting "
286 "output.",
287 false);
288 options_builder_add_example(b, OPTION_MODE_CLIENT_LIKE, "--color-filter cyan --palette cool",
289 "Apply cyan color filter and cool palette", false);
290
291 // Client-specific examples
292 options_builder_add_example(b, OPTION_MODE_CLIENT, "example.com", "Connect to remote server", false);
293 options_builder_add_example(b, OPTION_MODE_CLIENT, "example.com:8080", "Connect to remote server on custom port",
294 false);
295 options_builder_add_example(b, OPTION_MODE_CLIENT, "--color-mode mono --render-mode half-block --width 120",
296 "Connect with custom display options", false);
297
298 // Mirror-specific examples (unique to mirror mode)
300 b, OPTION_MODE_MIRROR, NULL,
301 "View the webcam or files or URLs as ASCII art. Like client mode but without network connectivity or a server.",
302 false);
303 options_builder_add_example(b, OPTION_MODE_MIRROR, "--color-mode mono", "View webcam in black and white", false);
304 options_builder_add_example(b, OPTION_MODE_MIRROR, "--color-filter green",
305 "View webcam with green monochromatic color filter", false);
306 options_builder_add_example(b, OPTION_MODE_MIRROR, "--matrix --color-filter rainbow",
307 "Matrix rain effect with rainbow colors cycling over 3.5s", false);
309 "Stream media from stdin (cat file.gif | ascii-chat mirror -f '-')", false);
310 options_builder_add_example_utility(b, OPTION_MODE_MIRROR, "cat video.avi | ascii-chat mirror -f '-' -l -s 00:30",
311 "Stream .avi from stdin, looped, seeking to 00:30", true);
312 options_builder_add_example(b, OPTION_MODE_MIRROR, "--file video.mov --seek 22:10",
313 "Start playback at exactly 22:10 (also works with --url)", false);
314 options_builder_add_example(b, OPTION_MODE_MIRROR, "-f 'https://youtu.be/LS9W8SO-Two' -S -D 0 -s 5:12",
315 "Print a single frame from a YouTube video at exactly 5:12 and exit", false);
316 options_builder_add_example(b, OPTION_MODE_MIRROR, "-S -D 0 | tee frame.txt | pbcopy",
317 "Capture single ASCII frame to clipboard (macOS) and file", false);
319 "View ASCII frame from clipboard (macOS)", true);
320
321 // Discovery-service specific examples
322 options_builder_add_example(b, OPTION_MODE_DISCOVERY_SVC, "--require-server-identity --require-client-identity",
323 "Enforce identity verification for all parties", false);
324
325 // Add mode descriptions
327 b, "default",
328 "When the ascii-chat binary is used without a mode, it operates as either client or server automatically and "
329 "uses the discovery-service to make peer connections with session strings");
330 options_builder_add_mode(b, "server", "Run as multi-client video chat server");
331 options_builder_add_mode(b, "client", "Run as video chat client (connect to server)");
332 options_builder_add_mode(b, "mirror", "View local media as ASCII art (no server)");
333 options_builder_add_mode(b, "discovery-service", "Secure P2P session signalling");
334 options_builder_add_mode(b, "mcp-server", "MCP media rendering tools");
335 options_builder_add_mode(b, "api-server", "HTTP image-to-ASCII API");
336
337 // Add custom help sections for interactive modes (client, mirror, and discovery)
338 options_builder_add_custom_section(b, "KEYBINDINGS",
339 "Available in ascii-chat client, mirror, and discovery modes. "
340 "While rendering, press '?' to display a keyboard shortcuts help menu showing:\n"
341 " - Available keybindings (?, Space, arrows, m, c, f, r, -)\n"
342 " - Press - to toggle the FPS counter (always visible in keyboard help).\n"
343 " - Current settings (volume, color mode, audio status, etc.)",
345
346 // Add environment variables section (all modes)
348 b, "ENVIRONMENT",
349 "All command-line flags that accept values have corresponding environment variables.\n"
350 " Format: ASCII_CHAT_<FLAG_NAME> where FLAG_NAME is uppercase with hyphens replaced by underscores\n"
351 " Example: --color-filter maps to ASCII_CHAT_COLOR_FILTER\n"
352 "\n"
353 " Configuration precedence (lowest to highest):\n"
354 " 1. Config file values (~/.ascii-chat/config.toml)\n"
355 " 2. Environment variables (ASCII_CHAT_*)\n"
356 " 3. Command-line flags (--flag-name)\n"
357 "\n"
358 " Additional environment variables are documented in the ascii-chat(1) man page.",
360
361 // Add common dependencies (these will be validated after parsing)
362 // Note: Dependencies are validated at runtime, so we add them here for documentation
363
364 // ============================================================================
365 // Media Source Conflicts
366 // ============================================================================
367 // URL conflicts: --url cannot be used with --file or --loop
369 "Option --url cannot be used with --file (--url takes priority)");
371 b, "url", "loop", "Option --url cannot be used with --loop (network streams cannot be looped)");
372
373 // ============================================================================
374 // Encryption & Authentication Conflicts
375 // ============================================================================
376 // Reject contradictory CLI requests before initializing transport security.
377 options_builder_add_dependency_conflicts(b, "no-encrypt", "encrypt", "Cannot use --no-encrypt with --encrypt");
378
379 // Authentication material conflicts with explicitly disabling authentication.
381 "Cannot use --no-auth with --key (key requires authentication)");
382 options_builder_add_dependency_conflicts(b, "no-auth", "password",
383 "Cannot use --no-auth with --password (password requires authentication)");
385 b, "no-auth", "client-keys", "Cannot use --no-auth with --client-keys (key list requires authentication)");
387 b, "no-auth", "server-key", "Cannot use --no-auth with --server-key (verification requires authentication)");
388
389 // Identity and verification keys can be combined, including with --no-encrypt.
390
391 // ============================================================================
392 // Compression Conflicts
393 // ============================================================================
394 // Cannot use --no-compress with --compression-level
395 options_builder_add_dependency_conflicts(b, "no-compress", "compression-level",
396 "Cannot use --no-compress with --compression-level");
397
398 // ============================================================================
399 // Audio Encoding Conflicts
400 // ============================================================================
401 // Cannot use both --encode-audio and --no-encode-audio
402 options_builder_add_dependency_conflicts(b, "encode-audio", "no-encode-audio",
403 "Cannot use both --encode-audio and --no-encode-audio");
404
405 // ============================================================================
406 // Display & Screen Conflicts
407 // ============================================================================
408 options_builder_add_dependency_conflicts(b, "waveform", "matrix", "Option --waveform cannot be used with --matrix");
409 options_builder_add_dependency_conflicts(b, "fft", "matrix", "Option --fft cannot be used with --matrix");
410 options_builder_add_dependency_conflicts(b, "waveform", "fft",
411 "Options --waveform and --fft cannot be used together");
412 options_builder_add_dependency_conflicts(b, "waveform", "audio",
413 "Option --waveform requires audio; remove --audio=false");
414 options_builder_add_dependency_conflicts(b, "fft", "audio", "Option --fft requires audio; remove --audio=false");
415 options_builder_add_dependency_conflicts(b, "waveform", "stretch", "Option --waveform cannot be used with --stretch");
416 options_builder_add_dependency_conflicts(b, "fft", "stretch", "Option --fft cannot be used with --stretch");
417
418 // ============================================================================
419 // Requirements (dependencies that must be satisfied)
420 // ============================================================================
421 // --snapshot-delay requires --snapshot
422 options_builder_add_dependency_requires(b, "snapshot-delay", "snapshot",
423 "Option --snapshot-delay requires --snapshot");
424
425 // --loop requires --file (can't loop network streams)
426 options_builder_add_dependency_requires(b, "loop", "file", "Option --loop requires --file");
427
428 const options_config_t *config = options_builder_build(b);
430 return config;
431}
#define SET_ERRNO(code,...)
void options_builder_add_custom_section(options_builder_t *builder, const char *heading, const char *content, option_mode_bitmask_t mode_bitmask)
Add a custom help section.
void options_builder_destroy(options_builder_t *builder)
Free options builder.
void options_builder_add_example_utility(options_builder_t *builder, uint32_t mode_bitmask, const char *args, const char *description, bool is_utility_command)
Add an example with utility command support.
asciichat_error_t acds_string_generate(char *output, size_t output_size)
Generate random session string.
#define ARRAY_SIZE(arr)
Calculate the number of elements in an array.
Definition common.h:180
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
@ ERROR_MEMORY
Definition error_codes.h:51
@ ASCIICHAT_OK
Definition error_codes.h:46
#define OPTION_MODE_CLIENT_LIKE
Definition options.h:956
#define OPTION_MODE_SERVER_LIKE
Mode group macros for examples.
Definition options.h:955
@ OPTION_MODE_ALL
All modes + binary.
Definition options.h:946
@ OPTION_MODE_BINARY
Binary-level options (parsed before mode detection).
Definition options.h:945
@ OPTION_MODE_CLIENT
Client mode (bit 1).
Definition options.h:939
@ OPTION_MODE_DISCOVERY
Discovery mode (bit 4).
Definition options.h:942
@ OPTION_MODE_MIRROR
Mirror mode (bit 2).
Definition options.h:940
@ OPTION_MODE_MCP_SERVER
Definition options.h:943
@ OPTION_MODE_DISCOVERY_SVC
Discovery server mode (bit 3).
Definition options.h:941
int parse_server_bind_address(const char *arg, void *config, char **remaining, int num_remaining, char **error_msg)
Parse server bind address positional argument.
Definition parsers.c:514
int parse_mirror_media(const char *arg, void *config, char **remaining, int num_remaining, char **error_msg)
Parse mirror mode positional argument (file path or URL).
Definition parsers.c:825
int parse_client_address(const char *arg, void *config, char **remaining, int num_remaining, char **error_msg)
Parse client address positional argument.
Definition parsers.c:636
#define OPTIONS_CONFIG_PRESETS_COMBINED_BUF1_BUFFER_SIZE
Definition presets.c:8
#define OPTIONS_CONFIG_PRESETS_COMBINED_BUF4_BUFFER_SIZE
Definition presets.c:11
#define OPTIONS_CONFIG_PRESETS_COMBINED_BUF2_BUFFER_SIZE
Definition presets.c:9
#define OPTIONS_CONFIG_PRESETS_COMBINED_BUF3_BUFFER_SIZE
Definition presets.c:10
#define OPTIONS_CONFIG_PRESETS_COMBINED_BUF5_BUFFER_SIZE
Definition presets.c:12
#define SESSION_STRING_BUFFER_SIZE
const char * program_name
Definition builder.h:487
const char * description
Definition builder.h:488

◆ options_print_help_for_mode()

void options_print_help_for_mode ( const options_config_t * config,
asciichat_mode_t mode,
const char * program_name,
const char * description,
FILE * desc )

Print help for a specific mode or binary level (unified function).

This is the single unified function for all help output (binary level and all modes). It handles all layout logic, terminal detection, and section printing.

Parameters
configOptions config with all options
modeMode to show help for (-1 for binary-level help)
program_nameFull program name (e.g., "ascii-chat server")
descriptionBrief description
descOutput file stream

Referenced by usage().

◆ options_struct_destroy()

void options_struct_destroy ( const options_config_t * config,
void * options_struct )

Clean up memory owned by options struct.

Frees all auto-duplicated strings and sets pointers to NULL. Call this before freeing the options struct.

Parameters
configOptions configuration
options_structOptions struct to clean up