|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
⚙️ The command-line flags available More...
Files | |
| file | acds.c |
| ACDS mode option parsing and help text. | |
| file | acds.h |
| ACDS (Discovery Service) mode option parsing. | |
| file | actions.c |
| Action option callbacks for ascii-chat. | |
| file | actions.h |
| Action option callbacks for ascii-chat. | |
| file | builder.c |
| Implementation of options builder API. | |
| file | builder.h |
| Options builder API for flexible command-line option configuration. | |
| file | client.c |
| Client mode option parsing and help text. | |
| file | client.h |
| Client mode option parsing. | |
| file | common.c |
| Common utilities and helpers for option parsing. | |
| file | common.h |
| Common utilities and helpers for option parsing. | |
| file | levenshtein.h |
| Levenshtein distance algorithm for fuzzy string matching. | |
| file | mirror.c |
| Mirror mode option parsing and help text. | |
| file | mirror.h |
| Mirror mode option parsing. | |
| file | options.c |
| ⚙️ Unified command-line argument parser with built-in mode detection | |
| file | options.h |
| ⚙️ Command-line options parsing and configuration management for ascii-chat | |
| file | parsers.c |
| Custom option parsers implementation. | |
| file | parsers.h |
| Custom option parsers for enum types. | |
| file | presets.c |
| Preset option configurations for ascii-chat modes. | |
| file | server.c |
| Server mode option parsing and help text. | |
| file | server.h |
| Server mode option parsing. | |
| file | validation.h |
| Validation functions for options parsing. | |
Data Structures | |
| struct | options_state |
| Consolidated options structure. More... | |
Macros | |
| #define | LEVENSHTEIN_SUGGESTION_THRESHOLD 3 |
| Maximum edit distance to suggest an option. | |
| #define | COLOR_MODE_AUTO TERM_COLOR_AUTO |
| Backward compatibility aliases for color mode enum values. | |
| #define | COLOR_MODE_NONE TERM_COLOR_NONE |
| Monochrome mode. | |
| #define | COLOR_MODE_16 TERM_COLOR_16 |
| 16-color mode (alias) | |
| #define | COLOR_MODE_16_COLOR TERM_COLOR_16 |
| 16-color mode (full name) | |
| #define | COLOR_MODE_256 TERM_COLOR_256 |
| 256-color mode (alias) | |
| #define | COLOR_MODE_256_COLOR TERM_COLOR_256 |
| 256-color mode (full name) | |
| #define | COLOR_MODE_TRUECOLOR TERM_COLOR_TRUECOLOR |
| 24-bit truecolor mode | |
| #define | ASCIICHAT_BINARY_OPTIONS_STRUCT |
| Binary-level options (parsed before mode selection) | |
| #define | ASCIICHAT_COMMON_OPTIONS_STRUCT |
| Common options (all modes after binary parsing) | |
| #define | ASCIICHAT_SERVER_OPTIONS_STRUCT |
| Server mode options. | |
| #define | ASCIICHAT_CLIENT_OPTIONS_STRUCT |
| Client mode options. | |
| #define | ASCIICHAT_MIRROR_OPTIONS_STRUCT |
| Mirror mode options. | |
| #define | ASCIICHAT_ACDS_OPTIONS_STRUCT |
| ACDS mode options. | |
| #define | GET_OPTION(field) |
| Safely get a specific option field (lock-free read) | |
Typedefs | |
| typedef struct options_state | options_t |
| Consolidated options structure. | |
Enumerations | |
| enum | asciichat_mode_t { MODE_SERVER , MODE_CLIENT , MODE_MIRROR , MODE_ACDS } |
| Mode type for options parsing. More... | |
Functions | |
| ASCIICHAT_API size_t | levenshtein (const char *a, const char *b) |
| Calculate Levenshtein distance between two strings. | |
| ASCIICHAT_API size_t | levenshtein_n (const char *a, const size_t length, const char *b, const size_t bLength) |
| Calculate Levenshtein distance with explicit string lengths. | |
| ASCIICHAT_API const char * | levenshtein_find_similar (const char *unknown, const char *const *candidates) |
| Find the most similar string from a NULL-terminated array. | |
| const options_t * | options_get (void) |
| Get current options (lock-free read) | |
| asciichat_error_t | options_update (void(*updater)(options_t *, void *), void *context) |
| Update options using copy-on-write (thread-safe) | |
| asciichat_error_t | options_set_dimensions (unsigned short int width, unsigned short int height) |
| Update terminal dimensions. | |
| asciichat_error_t | options_set_color_mode (terminal_color_mode_t mode) |
| Update color mode. | |
| asciichat_error_t | options_set_render_mode (render_mode_t mode) |
| Update render mode. | |
| asciichat_error_t | options_set_log_level (log_level_t level) |
| Update log level. | |
Variables | |
| ASCIICHAT_API int | opt_acds_port |
| TCP listen port (ACDS mode only) | |
| ASCIICHAT_API char | opt_acds_database_path [OPTIONS_BUFF_SIZE] |
| SQLite database path (ACDS mode only) | |
| ASCIICHAT_API char | opt_acds_key_path [OPTIONS_BUFF_SIZE] |
| Ed25519 identity key path (ACDS mode only) | |
| const float | weight_red |
| const float | weight_green |
| Green weight for luminance calculation. | |
| const float | weight_blue |
| Blue weight for luminance calculation. | |
| unsigned short int | RED [] |
| Red channel lookup table. | |
| unsigned short int | GREEN [] |
| Green channel lookup table. | |
| unsigned short int | BLUE [] |
| Blue channel lookup table. | |
| unsigned short int | GRAY [] |
| Grayscale lookup table. | |
Utility Functions | |
| int | strtoint_safe (const char *str) |
| Safely parse string to integer with validation. | |
Option Parsing Functions | |
| asciichat_error_t | options_init (int argc, char **argv) |
| Initialize options by parsing command-line arguments. | |
| void | usage (FILE *desc, asciichat_mode_t mode) |
| Print usage information for client, server, or mirror mode. | |
| void | usage_client (FILE *desc) |
| Print client usage information. | |
| void | usage_server (FILE *desc) |
| Print server usage information. | |
| void | usage_mirror (FILE *desc) |
| Print mirror usage information. | |
| void | usage_acds (FILE *desc) |
| Print ACDS usage information. | |
Dimension Update Functions | |
| void | update_dimensions_for_full_height (options_t *opts) |
| Update dimensions for full height display. | |
| void | update_dimensions_to_terminal_size (options_t *opts) |
| Update dimensions to match terminal size. | |
Validation Functions | |
| ASCIICHAT_API int | validate_opt_port (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate port number (1-65535) | |
| ASCIICHAT_API int | validate_opt_positive_int (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate positive integer. | |
| ASCIICHAT_API int | validate_opt_non_negative_int (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate non-negative integer. | |
| ASCIICHAT_API int | validate_opt_color_mode (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate color mode string. | |
| ASCIICHAT_API int | validate_opt_render_mode (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate render mode string. | |
| ASCIICHAT_API int | validate_opt_palette (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate palette type string. | |
| ASCIICHAT_API int | validate_opt_log_level (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate log level string. | |
| ASCIICHAT_API int | validate_opt_ip_address (const char *value_str, char *parsed_address, size_t address_size, bool is_client, char *error_msg, size_t error_msg_size) |
| Validate IP address or hostname. | |
| ASCIICHAT_API float | validate_opt_float_non_negative (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate non-negative float value. | |
| ASCIICHAT_API int | validate_opt_fps (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate FPS value (1-144) | |
| ASCIICHAT_API int | validate_opt_max_clients (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate max clients value (1-32) | |
| ASCIICHAT_API int | validate_opt_compression_level (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate compression level (1-9) | |
| ASCIICHAT_API int | validate_opt_reconnect (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate reconnect value. | |
| ASCIICHAT_API int | validate_opt_device_index (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate device index (-1 for default, 0+ for specific device) | |
| ASCIICHAT_API int | validate_opt_password (const char *value_str, char *error_msg, size_t error_msg_size) |
| Validate password (8-256 characters) | |
Configuration Constants | |
| #define | OPTIONS_BUFF_SIZE 256 |
| Buffer size for option string values. | |
| #define | OPT_WIDTH_DEFAULT 110 |
| Default terminal width in characters. | |
| #define | OPT_HEIGHT_DEFAULT 70 |
| Default terminal height in characters. | |
| #define | SNAPSHOT_DELAY_DEFAULT 3.0f |
| Default snapshot delay in seconds. | |
| #define | OPT_PORT_DEFAULT "27224" |
| Default TCP port for client/server communication. | |
| #define | OPT_ADDRESS_DEFAULT "localhost" |
| Default server address for client connections. | |
| #define | OPT_ADDRESS6_DEFAULT "::1" |
| Default IPv6 server address. | |
| #define | OPT_MAX_CLIENTS_DEFAULT 9 |
| Default maximum concurrent clients (server only) | |
| #define | OPT_COMPRESSION_LEVEL_DEFAULT 1 |
| Default compression level (1-9) | |
| #define | OPT_FPS_DEFAULT 60 |
| Default FPS (frames per second) | |
| #define | OPT_WEBCAM_INDEX_DEFAULT 0 |
| Default webcam device index. | |
| #define | OPT_MICROPHONE_INDEX_DEFAULT (-1) |
| Default microphone device index (-1 means system default) | |
| #define | OPT_SPEAKERS_INDEX_DEFAULT (-1) |
| Default speakers device index (-1 means system default) | |
| #define | OPT_RECONNECT_ATTEMPTS_DEFAULT (-1) |
| Default reconnect attempts (-1 means auto/infinite) | |
| #define | OPT_WEBCAM_FLIP_DEFAULT true |
| Default webcam flip state (true = horizontally flipped) | |
| #define | OPT_COLOR_MODE_DEFAULT COLOR_MODE_AUTO |
| Default color mode (auto-detect terminal capabilities) | |
| #define | OPT_RENDER_MODE_DEFAULT RENDER_MODE_FOREGROUND |
| Default render mode (foreground characters only) | |
| #define | OPT_ENCODE_AUDIO_DEFAULT true |
| Default audio encoding state (true = Opus encoding enabled) | |
⚙️ The command-line flags available
MIT licensed. Copyright (c) 2015 Titus Wormer titus.nosp@m.worm.nosp@m.er@gm.nosp@m.ail..nosp@m.com From: https://github.com/wooorm/levenshtein.c
This header provides comprehensive functionality for parsing command-line arguments and managing configuration settings for both client and server modes of ascii-chat. It serves as the central configuration system, parsing user preferences and providing defaults for all application settings.
Design Philosophy:
The options system follows a global configuration pattern where all options are stored in global variables that can be accessed throughout the application. This design:
Option Categories:
Options are organized into logical categories:
Option Parsing:
Options are parsed using the standard POSIX getopt() interface (with Windows compatibility via platform/windows/getopt.h). The parser:
-w 80) and long (--width 80) option formats--helpDefault Values:
All options have sensible defaults that work out-of-the-box:
localhost:27224 (IPv4)--key or --password)Option Lifecycle:
options_init() at program startupoptions_init() parses command-line argumentsUsage Example:
Command-Line Options:
Common options (see usage() function for complete list):
--width, -w: Set terminal width in characters--height, -h: Set terminal height in characters--address, -a: Bind address (server only)--port, -p: Server port (or override positional argument port for client)--key, -k: SSH key file path for encryption--password: Password for authentication--color, --256, --truecolor: Force color mode--palette: Select ASCII palette--help: Print usage information and exitClient address syntax (positional argument, not option flag):
ascii-chat client → connects to localhost:27224ascii-chat client example.com → connects to example.com:27224ascii-chat client 192.168.1.1:8080 → connects to 192.168.1.1:8080ascii-chat client [::1]:8080 → connects to IPv6 [::1]:8080Thread Safety:
Options are parsed once at startup in the main thread before any worker threads are created. After parsing, options are effectively read-only (with some exceptions for dynamic updates like terminal dimensions). Therefore, thread safety is not a concern for most options. If options need to be modified at runtime, ensure proper synchronization.
Option Validation:
The parser validates:
Invalid options result in ERROR_USAGE being returned, and usage information is printed to help the user correct their command line.
options_init(). This header provides validation functions used during command-line option parsing and configuration file loading. These functions validate user input and provide detailed error messages for invalid values.
All validation functions follow a consistent pattern:
The Options system provides command-line argument parsing support for ascii-chat. It handles server and client options, validates settings, and manages application configuration.
Implementation: lib/options.h, lib/config.h
Key Features:
Server Mode:
Client Mode:
Network Options:
[address][:port] (positional for client) - Server address with optional port (default: localhost:27224)[address1] [address2] (positional for server) - Bind addresses, 0-2 IPv4/IPv6 addresses--port PORT - Server port (default: 27224)Display Options:
--width WIDTH - Terminal width (default: auto-detect)--height HEIGHT - Terminal height (default: auto-detect)--color - Enable color output--stretch - Stretch video to fill terminal--half-block - Use half-block rendering (2x vertical resolution)Video Options:
--webcam INDEX - Webcam device index (default: 0)--webcam-flip - Flip webcam horizontally--test-pattern - Use test pattern instead of webcam--snapshot - Capture single frame and exit--snapshot-delay SEC - Delay before snapshot (default: 1.0)Audio Options:
--audio - Enable audio (client only, server always has audio)--no-audio - Disable audioCrypto Options:
--key PATH - SSH private key for authentication--server-key KEY - Server public key or github:username--password PASS - Shared password for encryption--insecure - Skip host identity verification (NOT RECOMMENDED)--client-keys KEYS - Whitelist of allowed client keys (comma-separated)Logging Options:
--log-file PATH - Write logs to file--log-level LEVEL - Set log level (0-4)Configuration Options:
--config PATH - Load configuration from TOML file--config-create [PATH] - Create default config file and exitBasic Server:
Server with Authentication:
Server with Custom Port:
Server with Logging:
Basic Client:
Connect to Remote Server:
Client with Audio and Color:
Client with Custom Webcam:
Snapshot Mode:
Client with Server Verification:
Parse Options:
Error Handling:
Show Help:
Help Output:
| #define ASCIICHAT_ACDS_OPTIONS_STRUCT |
#include <options.h>
ACDS mode options.
Complete set of options for ACDS (discovery service) mode.
Definition at line 407 of file options.h.
| #define ASCIICHAT_BINARY_OPTIONS_STRUCT |
#include <options.h>
Binary-level options (parsed before mode selection)
These options are common to all modes and parsed first.
| #define ASCIICHAT_CLIENT_OPTIONS_STRUCT |
#include <options.h>
Client mode options.
Complete set of options for client mode.
| #define ASCIICHAT_COMMON_OPTIONS_STRUCT |
#include <options.h>
Common options (all modes after binary parsing)
These options extend binary options with terminal dimensions.
| #define ASCIICHAT_MIRROR_OPTIONS_STRUCT |
#include <options.h>
Mirror mode options.
Complete set of options for mirror mode (local webcam viewing).
| #define ASCIICHAT_SERVER_OPTIONS_STRUCT |
#include <options.h>
Server mode options.
Complete set of options for server mode.
| #define COLOR_MODE_16 TERM_COLOR_16 |
| #define COLOR_MODE_16_COLOR TERM_COLOR_16 |
| #define COLOR_MODE_256 TERM_COLOR_256 |
| #define COLOR_MODE_256_COLOR TERM_COLOR_256 |
| #define COLOR_MODE_AUTO TERM_COLOR_AUTO |
| #define COLOR_MODE_NONE TERM_COLOR_NONE |
| #define COLOR_MODE_TRUECOLOR TERM_COLOR_TRUECOLOR |
| #define GET_OPTION | ( | field | ) |
#include <options.h>
Safely get a specific option field (lock-free read)
Convenience macro for accessing individual option fields without storing the entire options pointer. Includes NULL check with warning log for safety.
Usage Examples:
Design: This macro eliminates the need to store const options_t *opts pointers around the codebase, reducing clutter and making code more readable.
Safety: If options_get() returns NULL (shouldn't happen after initialization), the macro will log a warning and return a zero-initialized field.
Performance: Equivalent cost to direct options_get()->field access.
| field | The field name to access (e.g., address, port, width, etc.) |
Definition at line 644 of file options.h.
| #define LEVENSHTEIN_SUGGESTION_THRESHOLD 3 |
#include <levenshtein.h>
Maximum edit distance to suggest an option.
Threshold of 2 catches most typos (single char errors, transpositions) without suggesting unrelated options.
Definition at line 29 of file levenshtein.h.
| #define OPT_ADDRESS6_DEFAULT "::1" |
| #define OPT_ADDRESS_DEFAULT "localhost" |
| #define OPT_COLOR_MODE_DEFAULT COLOR_MODE_AUTO |
| #define OPT_COMPRESSION_LEVEL_DEFAULT 1 |
| #define OPT_ENCODE_AUDIO_DEFAULT true |
| #define OPT_FPS_DEFAULT 60 |
| #define OPT_HEIGHT_DEFAULT 70 |
#include <options.h>
Default terminal height in characters.
Default height used when terminal size cannot be detected or when auto-detection is disabled. This default provides a reasonable size for ASCII art display.
--height is not specified and auto-detection fails. | #define OPT_MAX_CLIENTS_DEFAULT 9 |
| #define OPT_MICROPHONE_INDEX_DEFAULT (-1) |
| #define OPT_PORT_DEFAULT "27224" |
| #define OPT_RECONNECT_ATTEMPTS_DEFAULT (-1) |
| #define OPT_RENDER_MODE_DEFAULT RENDER_MODE_FOREGROUND |
| #define OPT_SPEAKERS_INDEX_DEFAULT (-1) |
| #define OPT_WEBCAM_FLIP_DEFAULT true |
| #define OPT_WEBCAM_INDEX_DEFAULT 0 |
| #define OPT_WIDTH_DEFAULT 110 |
#include <options.h>
Default terminal width in characters.
Default width used when terminal size cannot be detected or when auto-detection is disabled. This default provides a reasonable size for ASCII art display.
--width is not specified and auto-detection fails. | #define OPTIONS_BUFF_SIZE 256 |
| #define SNAPSHOT_DELAY_DEFAULT 3.0f |
| typedef struct options_state options_t |
#include <options.h>
Consolidated options structure.
All options from the scattered extern globals are now in a single struct. This struct is immutable once published via RCU - modifications create a new copy.
| enum asciichat_mode_t |
#include <options.h>
Mode type for options parsing.
Determines which set of options to use when parsing command-line arguments.
| ASCIICHAT_API size_t levenshtein | ( | const char * | a, |
| const char * | b | ||
| ) |
#include <levenshtein.h>
Calculate Levenshtein distance between two strings.
The Levenshtein distance is the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.
| a | First string |
| b | Second string |
Definition at line 72 of file levenshtein.c.
References levenshtein_n().
Referenced by find_similar_option(), and levenshtein_find_similar().
| ASCIICHAT_API const char * levenshtein_find_similar | ( | const char * | unknown, |
| const char *const * | candidates | ||
| ) |
#include <levenshtein.h>
Find the most similar string from a NULL-terminated array.
Searches through an array of candidate strings to find the one most similar to the input string, using Levenshtein distance.
| unknown | The string to match against |
| candidates | NULL-terminated array of candidate strings |
Definition at line 82 of file levenshtein.c.
References levenshtein(), and LEVENSHTEIN_SUGGESTION_THRESHOLD.
| ASCIICHAT_API size_t levenshtein_n | ( | const char * | a, |
| const size_t | length, | ||
| const char * | b, | ||
| const size_t | bLength | ||
| ) |
#include <levenshtein.h>
Calculate Levenshtein distance with explicit string lengths.
| a | First string |
| length | Length of first string |
| b | Second string |
| bLength | Length of second string |
Definition at line 20 of file levenshtein.c.
References SAFE_CALLOC, and SAFE_FREE.
Referenced by levenshtein().
| const options_t * options_get | ( | void | ) |
#include <options.h>
Get current options (lock-free read)
Returns a pointer to the current options struct. This pointer is guaranteed to remain valid for the lifetime of your function (no one will free it under you).
Performance: Single atomic pointer load (~1-2ns on modern CPUs)
Definition at line 222 of file rcu.c.
References log_fatal, and log_warn.
Referenced by asciichat_shared_init(), client_crypto_init(), client_main(), log_set_terminal_output(), main(), main(), server_crypto_handshake(), tcp_client_send_terminal_capabilities(), and threaded_send_terminal_size_with_auto_detect().
| asciichat_error_t options_init | ( | int | argc, |
| char ** | argv | ||
| ) |
#include <options.h>
Initialize options by parsing command-line arguments.
| argc | Argument count from main() |
| argv | Argument vector from main() |
| is_client | true if parsing client options, false for server options |
Parses command-line arguments and initializes all option global variables. This function must be called once at program startup before accessing any options.
Parsing Process:
Special Return Values:
ASCIICHAT_OK: Parsing succeeded (normal case)ASCIICHAT_OK: Also returned for --help and --version (after printing info)ERROR_USAGE: Parse error or invalid option (usage info should be printed)Mode-Specific Behavior:
is_client = true): Parses client-specific options (color mode, webcam, snapshot mode, etc.)is_client = false): Parses server-specific options (bind address, client keys whitelist, etc.)Validation:
Default Value Application: After parsing, unspecified options are set to defaults:
OPT_WIDTH_DEFAULT/OPT_HEIGHT_DEFAULTlocalhost:27224Environment Variables: The following environment variables are checked during option parsing:
WEBCAM_DISABLED: When set to "1", "true", "yes", or "on", automatically enables test pattern mode (opt_test_pattern = true). Useful for CI/CD environments and testing without a physical webcam.ERROR_USAGE for invalid options (caller should print usage) --help and --version cause early exit (function still returns ASCIICHAT_OK)Initialize options by parsing command-line arguments with unified mode detection
Unified options initialization that handles:
The detected mode is stored in options_t->detected_mode for retrieval via options_get()->detected_mode after this function returns.
Mode Detection Priority:
Definition at line 144 of file options.c.
References options_state::address, options_state::address6, ASCIICHAT_OK, options_state::auto_height, options_state::auto_width, options_state::client_keys, options_state::color_mode, options_state::compression_level, config_create_default(), config_load_system_and_user(), asciichat_error_context_t::context_message, options_state::detected_mode, options_state::encode_audio, options_state::encrypt_key, options_state::encrypt_keyfile, ERROR_CONFIG, ERROR_INVALID_PARAM, ERROR_MEMORY, get_config_dir(), get_log_dir(), HAS_ERRNO, options_state::height, options_state::help, log_debug, LOG_DEV, log_error, options_state::log_file, log_get_level(), log_set_level(), options_state::max_clients, options_state::microphone_index, MODE_ACDS, MODE_CLIENT, MODE_MIRROR, MODE_SERVER, options_state::no_compress, options_state::no_encrypt, OPT_COLOR_MODE_DEFAULT, OPT_COMPRESSION_LEVEL_DEFAULT, OPT_ENCODE_AUDIO_DEFAULT, OPT_HEIGHT_DEFAULT, OPT_MAX_CLIENTS_DEFAULT, OPT_MICROPHONE_INDEX_DEFAULT, OPT_PORT_DEFAULT, OPT_RECONNECT_ATTEMPTS_DEFAULT, OPT_RENDER_MODE_DEFAULT, OPT_SPEAKERS_INDEX_DEFAULT, OPT_WEBCAM_FLIP_DEFAULT, OPT_WIDTH_DEFAULT, OPTIONS_BUFF_SIZE, options_state_init(), options_state_set(), options_state::palette_custom, parse_acds_options(), parse_client_options(), parse_mirror_options(), parse_server_options(), options_state::password, PATH_ROLE_LOG_FILE, PATH_SEPARATOR_STR, path_validate_user_path(), PLATFORM_MAX_PATH_LENGTH, platform_strcasecmp(), options_state::port, options_state::reconnect_attempts, options_state::render_mode, SAFE_FREE, SAFE_GETENV, SAFE_MALLOC, SAFE_SNPRINTF, safe_snprintf(), SAFE_STRNCPY, options_state::server_key, options_state::session_string, SET_ERRNO, options_state::speakers_index, options_state::test_pattern, update_dimensions_for_full_height(), update_dimensions_to_terminal_size(), options_state::verbose_level, options_state::version, options_state::webcam_flip, and options_state::width.
| asciichat_error_t options_set_color_mode | ( | terminal_color_mode_t | mode | ) |
#include <options.h>
Update color mode.
Thread-safe setter for color mode. Uses RCU update internally.
| mode | New color mode |
Definition at line 304 of file rcu.c.
References options_update().
| asciichat_error_t options_set_dimensions | ( | unsigned short int | width, |
| unsigned short int | height | ||
| ) |
#include <options.h>
Update terminal dimensions.
Thread-safe setter for width/height. Uses RCU update internally.
| width | New terminal width in characters |
| height | New terminal height in characters |
Definition at line 294 of file rcu.c.
References dimensions_update_ctx::height, options_update(), and dimensions_update_ctx::width.
| asciichat_error_t options_set_log_level | ( | log_level_t | level | ) |
#include <options.h>
Update log level.
Thread-safe setter for log level. Uses RCU update internally.
| level | New log level |
Definition at line 322 of file rcu.c.
References options_update().
| asciichat_error_t options_set_render_mode | ( | render_mode_t | mode | ) |
#include <options.h>
Update render mode.
Thread-safe setter for render mode. Uses RCU update internally.
| mode | New render mode |
Definition at line 313 of file rcu.c.
References options_update().
| asciichat_error_t options_update | ( | void(*)(options_t *, void *) | updater, |
| void * | context | ||
| ) |
#include <options.h>
Update options using copy-on-write (thread-safe)
Callback-based update interface. Allocates a new options struct, copies current values, calls your callback to modify the copy, then atomically swaps the global pointer.
Thread Safety: Multiple writers are serialized with a mutex. Readers are never blocked.
| updater | Callback function that modifies the new options struct |
| context | User context pointer passed to callback (can be NULL) |
Definition at line 237 of file rcu.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, ERROR_MEMORY, log_debug, mutex_lock, mutex_unlock, SAFE_MALLOC, and SET_ERRNO.
Referenced by main(), options_set_color_mode(), options_set_dimensions(), options_set_log_level(), and options_set_render_mode().
| int strtoint_safe | ( | const char * | str | ) |
#include <options.h>
Safely parse string to integer with validation.
| str | String to parse (must not be NULL) |
Parses a string to an integer with comprehensive validation:
This function is used internally by the options parser to safely convert command-line argument strings to integer values with proper error handling.
Parses a string to integer using parse_int32() with full range checking. Returns INT_MIN on error (NULL input, empty string, invalid format, out of range).
| str | String to parse |
Example:
Definition at line 67 of file options/common.c.
References ASCIICHAT_OK, and parse_int32().
Referenced by client_crypto_init(), server_main(), validate_fps_opt(), validate_opt_compression_level(), validate_opt_device_index(), validate_opt_fps(), validate_opt_max_clients(), validate_opt_non_negative_int(), validate_opt_positive_int(), validate_opt_reconnect(), and validate_positive_int_opt().
| void update_dimensions_for_full_height | ( | options_t * | opts | ) |
#include <options.h>
Update dimensions for full height display.
Adjusts opt_width and opt_height to use the full terminal height while maintaining the original aspect ratio. Useful for maximizing vertical space usage when the terminal is resized.
Calculation:
opt_width and opt_height global variablesUsage: Call this function when terminal is resized or when you want to maximize vertical space usage while preserving aspect ratio.
Example: If terminal is 120×40 and original dimensions were 80×30:
opt_width and opt_height Update dimensions for full height display.
Sets opt_height to terminal height when auto-detected. Used during initialization to maximize vertical space usage.
Behavior:
Example:
Definition at line 535 of file options/common.c.
References ASCIICHAT_OK, options_state::auto_height, options_state::auto_width, get_terminal_size(), options_state::height, and options_state::width.
Referenced by options_init().
| void update_dimensions_to_terminal_size | ( | options_t * | opts | ) |
#include <options.h>
Update dimensions to match terminal size.
Sets opt_width and opt_height to exactly match the current terminal dimensions. This function queries the terminal for its size and updates the option variables accordingly.
Detection: Uses platform-specific terminal size detection:
TIOCGWINSZ ioctl on stdoutGetConsoleScreenBufferInfo$COLUMNS, $LINES)OPT_WIDTH_DEFAULT, OPT_HEIGHT_DEFAULT)Usage: Call this function:
Example: Terminal is 160×60:
opt_width is set to 160opt_height is set to 60opt_width and opt_height Update dimensions to match terminal size.
Updates opt_width and opt_height to current terminal size for auto-detected dimensions. Used after logging is initialized (can use log_debug).
Behavior:
Example:
Definition at line 564 of file options/common.c.
References ASCIICHAT_OK, options_state::auto_height, options_state::auto_width, get_terminal_size(), options_state::height, log_debug, and options_state::width.
Referenced by options_init().
| void usage | ( | FILE * | desc, |
| asciichat_mode_t | mode | ||
| ) |
#include <options.h>
Print usage information for client, server, or mirror mode.
| desc | File descriptor to write to (typically stdout or stderr) |
| mode | Mode to show usage for (MODE_SERVER, MODE_CLIENT, or MODE_MIRROR) |
Prints comprehensive usage information including:
Usage: Called automatically by options_init() for --help, or manually by application code when ERROR_USAGE is returned.
Output: Formatted usage text including:
stderr for error cases, stdout for --help Definition at line 592 of file options/common.c.
References MODE_ACDS, MODE_CLIENT, MODE_MIRROR, MODE_SERVER, usage_acds(), usage_client(), usage_mirror(), and usage_server().
Referenced by main().
| void usage_acds | ( | FILE * | desc | ) |
#include <options.h>
Print ACDS usage information.
| desc | File descriptor to write to (typically stdout or stderr) |
Prints ACDS (ASCII Chat Discovery Service) specific usage information.
Usage: Called when displaying ACDS help or error messages.
Includes: All ACDS-specific options:
Definition at line 109 of file acds.c.
References options_config_t::description, positional_arg_descriptor_t::examples, positional_arg_descriptor_t::num_examples, options_config_t::num_positional_args, options_config_destroy(), options_config_print_usage(), options_preset_acds(), options_config_t::positional_args, options_config_t::program_name, and positional_arg_descriptor_t::section_heading.
Referenced by usage().
| void usage_client | ( | FILE * | desc | ) |
#include <options.h>
Print client usage information.
| desc | File descriptor to write to (typically stdout or stderr) |
Convenience function that prints client-specific usage information. Equivalent to usage(desc, true).
Usage: Called when displaying client help or error messages.
Includes: All client-specific options:
Print client usage information.
Displays comprehensive help for all client options, including:
Output Format:
| stream | Output stream (stdout for –help, stderr for errors) |
Example usage:
Definition at line 86 of file lib/options/client.c.
References options_config_t::description, positional_arg_descriptor_t::examples, positional_arg_descriptor_t::num_examples, options_config_t::num_positional_args, options_config_destroy(), options_config_print_usage(), options_preset_client(), options_config_t::positional_args, options_config_t::program_name, and positional_arg_descriptor_t::section_heading.
Referenced by action_help_client(), and usage().
| void usage_mirror | ( | FILE * | desc | ) |
#include <options.h>
Print mirror usage information.
| desc | File descriptor to write to (typically stdout or stderr) |
Prints mirror mode (local webcam preview) usage information.
Usage: Called when displaying mirror help or error messages.
Includes: Mirror-specific options:
Print mirror usage information.
Displays comprehensive help for all mirror options, including:
Output Format:
| stream | Output stream (stdout for –help, stderr for errors) |
Example usage:
Definition at line 71 of file mirror.c.
References options_config_t::description, options_config_destroy(), options_config_print_usage(), options_preset_mirror(), and options_config_t::program_name.
Referenced by action_help_mirror(), and usage().
| void usage_server | ( | FILE * | desc | ) |
#include <options.h>
Print server usage information.
| desc | File descriptor to write to (typically stdout or stderr) |
Convenience function that prints server-specific usage information. Equivalent to usage(desc, false).
Usage: Called when displaying server help or error messages.
Includes: All server-specific options:
Definition at line 80 of file lib/options/server.c.
References options_config_t::description, positional_arg_descriptor_t::examples, positional_arg_descriptor_t::num_examples, options_config_t::num_positional_args, options_config_destroy(), options_config_print_usage(), options_preset_server(), options_config_t::positional_args, options_config_t::program_name, and positional_arg_descriptor_t::section_heading.
Referenced by action_help_server(), and usage().
| ASCIICHAT_API int validate_opt_color_mode | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate color mode string.
| value_str | Color mode value as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Valid values: auto, none, mono, 16, 16color, 256, 256color, truecolor, 24bit
Validate color mode string Returns parsed color mode on success, -1 on error
Definition at line 94 of file validation.c.
References COLOR_MODE_16_COLOR, COLOR_MODE_256_COLOR, COLOR_MODE_AUTO, COLOR_MODE_NONE, COLOR_MODE_TRUECOLOR, and SAFE_SNPRINTF.
| ASCIICHAT_API int validate_opt_compression_level | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate compression level (1-9)
| value_str | Compression level as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Validates zstd compression level in range 1-9.
Validate compression level (1-9) Returns parsed value on success, -1 on error
Definition at line 327 of file validation.c.
References SAFE_SNPRINTF, and strtoint_safe().
| ASCIICHAT_API int validate_opt_device_index | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate device index (-1 for default, 0+ for specific device)
| value_str | Device index as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Used for microphone-index, speakers-index, webcam-index. -1 means use system default device.
Validate device index (-1 for default, or 0+ for specific device) Returns parsed value on success, INT_MIN on error
Definition at line 422 of file validation.c.
References SAFE_SNPRINTF, and strtoint_safe().
Referenced by validate_webcam_index().
| ASCIICHAT_API float validate_opt_float_non_negative | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate non-negative float value.
| value_str | Float value as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Validates that the string is a valid non-negative floating-point number.
Validate float value (non-negative) Returns parsed value on success, returns -1.0f on error (caller must check)
Definition at line 276 of file validation.c.
References SAFE_SNPRINTF.
| ASCIICHAT_API int validate_opt_fps | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate FPS value (1-144)
| value_str | FPS value as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Validates that the FPS is in the valid range of 1-144.
Validate FPS value (1-144) Returns parsed value on success, -1 on error
Definition at line 349 of file validation.c.
References SAFE_SNPRINTF, and strtoint_safe().
| ASCIICHAT_API int validate_opt_ip_address | ( | const char * | value_str, |
| char * | parsed_address, | ||
| size_t | address_size, | ||
| bool | is_client, | ||
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate IP address or hostname.
| value_str | IP address or hostname as string |
| parsed_address | Buffer to store resolved/parsed address |
| address_size | Size of parsed_address buffer |
| is_client | True if client mode (for error messages) |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Validates IPv4, IPv6 addresses, or resolves hostname to IP.
Validate IP address or hostname Returns 0 on success, -1 on error Sets parsed_address on success (resolved if hostname)
Definition at line 224 of file validation.c.
References is_valid_ipv4(), is_valid_ipv6(), OPTIONS_BUFF_SIZE, parse_ipv6_address(), platform_resolve_hostname_to_ipv4(), and SAFE_SNPRINTF.
| ASCIICHAT_API int validate_opt_log_level | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate log level string.
| value_str | Log level as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Valid values (case-insensitive): dev, debug, info, warn, error, fatal
Validate log level string Returns parsed log level on success, -1 on error
Definition at line 190 of file validation.c.
References LOG_DEBUG, LOG_DEV, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_WARN, platform_strcasecmp(), and SAFE_SNPRINTF.
Referenced by parse_log_level_option().
| ASCIICHAT_API int validate_opt_max_clients | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate max clients value (1-32)
| value_str | Max clients value as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Validates that the max clients is in the valid range of 1-32.
Validate max clients (1-32) Returns parsed value on success, -1 on error
Definition at line 305 of file validation.c.
References SAFE_SNPRINTF, and strtoint_safe().
| ASCIICHAT_API int validate_opt_non_negative_int | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate non-negative integer.
| value_str | Integer value as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Validates that the string is a non-negative integer (>= 0).
Validate non-negative integer Returns parsed value on success, -1 on error
Definition at line 72 of file validation.c.
References SAFE_SNPRINTF, and strtoint_safe().
| ASCIICHAT_API int validate_opt_palette | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate palette type string.
| value_str | Palette type as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Valid values: standard, blocks, digital, minimal, cool, custom
Validate palette type string Returns parsed palette type on success, -1 on error
Definition at line 156 of file validation.c.
References PALETTE_BLOCKS, PALETTE_COOL, PALETTE_CUSTOM, PALETTE_DIGITAL, PALETTE_MINIMAL, PALETTE_STANDARD, and SAFE_SNPRINTF.
| ASCIICHAT_API int validate_opt_password | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate password (8-256 characters)
| value_str | Password string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Validates password length is 8-256 characters and contains no null bytes.
Validate password (8-256 characters, no null bytes) Returns 0 on success, -1 on error
Definition at line 454 of file validation.c.
References SAFE_SNPRINTF.
| ASCIICHAT_API int validate_opt_port | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate port number (1-65535)
| value_str | Port number as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Validates that the port string is a valid number in the range 1-65535.
Validate port number (1-65535) Returns 0 on success, non-zero on error
Definition at line 26 of file validation.c.
References ASCIICHAT_OK, parse_port(), and SAFE_SNPRINTF.
| ASCIICHAT_API int validate_opt_positive_int | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate positive integer.
| value_str | Integer value as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Validates that the string is a positive integer (> 0).
Validate positive integer Returns parsed value on success, -1 on error
Definition at line 50 of file validation.c.
References SAFE_SNPRINTF, and strtoint_safe().
| ASCIICHAT_API int validate_opt_reconnect | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate reconnect value.
| value_str | Reconnect value as string ("off", "auto", or 0-999) |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Valid values:
Validate reconnect value (off, auto, 0, -1, or 1-999) Returns: 0 for "off" (no retries) -1 for "auto" (unlimited retries) 1-999 for specific retry count INT_MIN on parse error
Definition at line 375 of file validation.c.
References platform_strcasecmp(), SAFE_SNPRINTF, and strtoint_safe().
| ASCIICHAT_API int validate_opt_render_mode | ( | const char * | value_str, |
| char * | error_msg, | ||
| size_t | error_msg_size | ||
| ) |
#include <validation.h>
Validate render mode string.
| value_str | Render mode value as string |
| error_msg | Buffer for error message (can be NULL) |
| error_msg_size | Size of error message buffer |
Valid values: foreground, fg, background, bg, half-block, halfblock
Validate render mode string Returns parsed render mode on success, -1 on error
Definition at line 128 of file validation.c.
References RENDER_MODE_BACKGROUND, RENDER_MODE_FOREGROUND, RENDER_MODE_HALF_BLOCK, and SAFE_SNPRINTF.
|
extern |
#include <options.h>
Blue channel lookup table.
Lookup table for blue channel values. See RED[] for details.
Definition at line 354 of file options/common.c.
Referenced by precalc_rgb_palettes().
|
extern |
#include <options.h>
Grayscale lookup table.
Lookup table for grayscale values. Used for monochrome ASCII conversion when color information is not needed or available.
Definition at line 355 of file options/common.c.
Referenced by precalc_rgb_palettes().
|
extern |
#include <options.h>
Green channel lookup table.
Lookup table for green channel values. See RED[] for details.
Definition at line 353 of file options/common.c.
Referenced by precalc_rgb_palettes().
|
extern |
#include <acds.h>
SQLite database path (ACDS mode only)
Path to SQLite database for session storage and management.
Default: ~/.config/ascii-chat/acds.db
Command-line: --database <path> or -d <path>
Definition at line 41 of file acds.c.
Referenced by main(), and parse_acds_options().
|
extern |
#include <acds.h>
Ed25519 identity key path (ACDS mode only)
Path to Ed25519 identity key for server identity.
Default: ~/.config/ascii-chat/acds_identity
Command-line: --key <path> or -k <path>
Definition at line 42 of file acds.c.
Referenced by main(), and parse_acds_options().
|
extern |
|
extern |
#include <options.h>
Red channel lookup table.
Lookup table for red channel values. Used for efficient color-to-ASCII character mapping. Precomputed table for fast palette lookups.
Usage: These lookup tables are used internally by the ASCII conversion algorithm for efficient color mapping.
Definition at line 352 of file options/common.c.
Referenced by precalc_rgb_palettes().
|
extern |
#include <options.h>
Blue weight for luminance calculation.
Weight for blue channel in luminance calculation. See weight_red for details.
Default: Typically 0.114 (standard ITU-R BT.601 weights)
Definition at line 348 of file options/common.c.
Referenced by server_main().
|
extern |
#include <options.h>
Green weight for luminance calculation.
Weight for green channel in luminance calculation. See weight_red for details.
Default: Typically 0.587 (standard ITU-R BT.601 weights)
Definition at line 347 of file options/common.c.
Referenced by server_main().
|
extern |