291char *
get_required_argument(
const char *opt_value,
char *buffer,
size_t buffer_size,
const char *option_name,
498#define USAGE_INDENT " "
501#define USAGE_HELP_LINE USAGE_INDENT "-h --help " USAGE_INDENT "print this help\n"
502#define USAGE_VERSION_LINE USAGE_INDENT "-v --version " USAGE_INDENT "print version information\n"
505#define USAGE_PORT_LINE \
506 USAGE_INDENT "-p --port PORT " USAGE_INDENT "TCP port to listen on (default: %d)\n"
507#define USAGE_PORT_CLIENT_LINE \
508 USAGE_INDENT "-p --port PORT " USAGE_INDENT "override port from address (default: 27224)\n"
509#define USAGE_RECONNECT_LINE \
510 USAGE_INDENT " --reconnect VALUE " USAGE_INDENT \
511 "reconnection behavior: off, auto, or 1-999 (default: auto)\n"
514#define USAGE_MAX_CLIENTS_LINE \
515 USAGE_INDENT " --max-clients N " USAGE_INDENT "maximum simultaneous clients (1-9, default: 9)\n"
516#define USAGE_NO_AUDIO_MIXER_LINE \
517 USAGE_INDENT " --no-audio-mixer " USAGE_INDENT "disable audio mixer - send silence (debug mode only)\n"
520#define USAGE_WIDTH_LINE \
521 USAGE_INDENT "-x --width WIDTH " USAGE_INDENT "render width (default: [auto-set])\n"
522#define USAGE_HEIGHT_LINE \
523 USAGE_INDENT "-y --height HEIGHT " USAGE_INDENT "render height (default: [auto-set])\n"
526#define USAGE_WEBCAM_INDEX_LINE \
527 USAGE_INDENT "-c --webcam-index CAMERA " USAGE_INDENT "webcam device index (0-based) (default: 0)\n"
528#define USAGE_LIST_WEBCAMS_LINE \
529 USAGE_INDENT " --list-webcams " USAGE_INDENT "list available webcam devices and exit\n"
530#define USAGE_WEBCAM_FLIP_LINE \
531 USAGE_INDENT "-f --webcam-flip " USAGE_INDENT \
532 "toggle horizontal flip of webcam image (default: flipped)\n"
533#define USAGE_TEST_PATTERN_CLIENT_LINE \
534 USAGE_INDENT " --test-pattern " USAGE_INDENT \
535 "use test pattern instead of webcam (for testing multiple clients)\n"
536#define USAGE_TEST_PATTERN_MIRROR_LINE \
537 USAGE_INDENT " --test-pattern " USAGE_INDENT "use test pattern instead of webcam (for testing)\n"
540#define USAGE_FPS_WIN_LINE \
541 USAGE_INDENT " --fps FPS " USAGE_INDENT "desired frame rate 1-144 (default: 30 for Windows)\n"
542#define USAGE_FPS_UNIX_LINE \
543 USAGE_INDENT " --fps FPS " USAGE_INDENT "desired frame rate 1-144 (default: 60 for Unix)\n"
544#define USAGE_COLOR_MODE_LINE \
545 USAGE_INDENT " --color-mode MODE " USAGE_INDENT \
546 "color modes: auto, none, 16, 256, truecolor (default: auto)\n"
547#define USAGE_SHOW_CAPABILITIES_LINE \
548 USAGE_INDENT " --show-capabilities " USAGE_INDENT "show detected terminal capabilities and exit\n"
549#define USAGE_UTF8_LINE \
550 USAGE_INDENT " --utf8 " USAGE_INDENT "force enable UTF-8/Unicode support (default: [unset])\n"
551#define USAGE_RENDER_MODE_LINE \
552 USAGE_INDENT "-M --render-mode MODE " USAGE_INDENT \
553 "Rendering modes: foreground, background, half-block (default: foreground)\n"
554#define USAGE_PALETTE_LINE \
555 USAGE_INDENT "-P --palette PALETTE " USAGE_INDENT \
556 "ASCII character palette: standard, blocks, digital, minimal, cool, custom (default: standard)\n"
557#define USAGE_PALETTE_CHARS_LINE \
558 USAGE_INDENT "-C --palette-chars CHARS " USAGE_INDENT \
559 "Custom palette characters (implies --palette=custom) (default: [unset])\n"
560#define USAGE_STRETCH_LINE \
561 USAGE_INDENT "-s --stretch " USAGE_INDENT \
562 "stretch or shrink video to fit (ignore aspect ratio) (default: [unset])\n"
565#define USAGE_SNAPSHOT_LINE \
566 USAGE_INDENT "-S --snapshot " USAGE_INDENT "capture single frame and exit (default: [unset])\n"
567#define USAGE_SNAPSHOT_DELAY_LINE \
568 USAGE_INDENT "-D --snapshot-delay SECONDS " USAGE_INDENT "delay SECONDS before snapshot (default: %.1f)\n"
569#define USAGE_STRIP_ANSI_LINE \
570 USAGE_INDENT " --strip-ansi " USAGE_INDENT \
571 "remove all ANSI escape codes from output (default: [unset])\n"
574#define USAGE_AUDIO_LINE \
575 USAGE_INDENT "-A --audio " USAGE_INDENT "enable audio capture and playback (default: [unset])\n"
576#define USAGE_AUDIO_ANALYSIS_LINE \
577 USAGE_INDENT " --audio-analysis " USAGE_INDENT \
578 "track and report audio quality metrics (with --audio) (default: [unset])\n"
579#define USAGE_NO_AUDIO_PLAYBACK_LINE \
580 USAGE_INDENT " --no-audio-playback " USAGE_INDENT \
581 "disable speaker playback but keep recording received audio (debug mode) (default: [unset])\n"
582#define USAGE_LIST_MICROPHONES_LINE \
583 USAGE_INDENT " --list-microphones " USAGE_INDENT "list available audio input devices and exit\n"
584#define USAGE_LIST_SPEAKERS_LINE \
585 USAGE_INDENT " --list-speakers " USAGE_INDENT "list available audio output devices and exit\n"
586#define USAGE_MICROPHONE_INDEX_LINE \
587 USAGE_INDENT " --microphone-index INDEX " USAGE_INDENT "microphone device index (-1 for default) (default: -1)\n"
588#define USAGE_SPEAKERS_INDEX_LINE \
589 USAGE_INDENT " --speakers-index INDEX " USAGE_INDENT "speakers device index (-1 for default) (default: -1)\n"
592#define USAGE_ENCRYPT_LINE \
593 USAGE_INDENT "-E --encrypt " USAGE_INDENT "enable packet encryption (default: [unset])\n"
594#define USAGE_KEY_SERVER_LINE \
595 USAGE_INDENT "-K --key KEY " USAGE_INDENT \
596 "SSH/GPG key file for authentication: /path/to/key, gpg:keyid, github:user, gitlab:user, or 'ssh' " \
597 "(implies --encrypt) (default: [unset])\n"
598#define USAGE_KEY_CLIENT_LINE \
599 USAGE_INDENT "-K --key KEY " USAGE_INDENT \
600 "SSH/GPG key file for authentication: /path/to/key, gpg:keyid, github:user, gitlab:user, or 'ssh' for " \
601 "auto-detect (implies --encrypt) (default: [unset])\n"
602#define USAGE_PASSWORD_LINE \
603 USAGE_INDENT " --password [PASS] " USAGE_INDENT \
604 "password for connection encryption (prompts if not provided) (implies --encrypt) (default: [unset])\n"
605#define USAGE_KEYFILE_LINE \
606 USAGE_INDENT "-F --keyfile FILE " USAGE_INDENT \
607 "read encryption key from FILE (implies --encrypt) (default: [unset])\n"
608#define USAGE_NO_ENCRYPT_LINE \
609 USAGE_INDENT " --no-encrypt " USAGE_INDENT "disable encryption (default: [unset])\n"
610#define USAGE_SERVER_KEY_LINE \
611 USAGE_INDENT " --server-key KEY " USAGE_INDENT \
612 "expected server public key for verification (default: [unset])\n"
613#define USAGE_CLIENT_KEYS_LINE \
614 USAGE_INDENT " --client-keys KEYS" USAGE_INDENT \
615 "allowed client public keys (comma-separated, supports github:user, gitlab:user, gpg:keyid, or SSH " \
616 "pubkey) (default: [unset])\n"
619#define USAGE_COMPRESSION_LEVEL_LINE \
620 USAGE_INDENT " --compression-level N " USAGE_INDENT "zstd compression level 1-9 (default: 1)\n"
621#define USAGE_NO_COMPRESS_LINE \
622 USAGE_INDENT " --no-compress " USAGE_INDENT "disable frame compression (default: [unset])\n"
623#define USAGE_ENCODE_AUDIO_LINE \
624 USAGE_INDENT " --encode-audio " USAGE_INDENT "enable Opus audio encoding (default: enabled)\n"
625#define USAGE_NO_ENCODE_AUDIO_LINE USAGE_INDENT " --no-encode-audio " USAGE_INDENT "disable Opus audio encoding\n"
629#define USAGE_DATABASE_LINE \
630 USAGE_INDENT "-d --db PATH " USAGE_INDENT \
631 "SQLite database path (default: %APPDATA%\\ascii-chat\\acds.db)\n"
633#define USAGE_DATABASE_LINE \
634 USAGE_INDENT "-d --db PATH " USAGE_INDENT \
635 "SQLite database path (default: ~/.config/ascii-chat/acds.db)\n"
637#define USAGE_LOG_FILE_LINE USAGE_INDENT "-L --log-file FILE " USAGE_INDENT "log file path (default: stderr)\n"
638#define USAGE_LOG_LEVEL_LINE \
639 USAGE_INDENT "-l --log-level LEVEL " USAGE_INDENT \
640 "log level: dev, debug, info, warn, error, fatal (default: info)\n"
asciichat_error_t
Error and exit codes - unified status values (0-255)
asciichat_mode_t
Mode type for options parsing.
char * strip_equals_prefix(const char *opt_value, char *buffer, size_t buffer_size)
Strip equals sign prefix from option argument.
char * validate_required_argument(const char *optarg, char *argbuf, size_t argbuf_size, const char *option_name, asciichat_mode_t mode)
Validate and retrieve required argument for an option.
const char * find_similar_option(const char *unknown_opt, const struct option *options)
Find a similar option name for typo suggestions.
asciichat_error_t parse_render_mode_option(const char *value_str, options_t *opts)
Parse –render-mode option and set opts->render_mode.
int strtoint_safe(const char *str)
Safely parse string to integer with validation.
void update_dimensions_to_terminal_size(options_t *opts)
Update dimensions to current terminal size.
asciichat_error_t parse_width_option(const char *value_str, options_t *opts)
Parse –width option and set opts->width.
asciichat_error_t detect_default_ssh_key(char *key_path, size_t path_size)
Detect default SSH key path for the current user.
char * read_password_from_stdin(const char *prompt)
Read password from stdin with prompt.
bool validate_port_opt(const char *value_str, uint16_t *out_port)
Validate port number (1-65535)
asciichat_error_t parse_height_option(const char *value_str, options_t *opts)
Parse –height option and set opts->height.
bool validate_fps_opt(const char *value_str, int *out_fps)
Validate FPS value (1-144)
asciichat_error_t parse_palette_chars_option(const char *value_str, options_t *opts)
Parse –palette-chars option and set opt_palette_custom.
asciichat_error_t parse_palette_option(const char *value_str, options_t *opts)
Parse –palette option and set opt_palette_type.
asciichat_error_t parse_log_level_option(const char *value_str, options_t *opts)
Parse –log-level option and set opt_log_level.
bool validate_positive_int_opt(const char *value_str, int *out_value, const char *param_name)
Validate a positive integer value.
asciichat_error_t parse_color_mode_option(const char *value_str, options_t *opts)
Parse –color-mode option and set opts->color_mode.
asciichat_error_t parse_snapshot_delay_option(const char *value_str, options_t *opts)
Parse –snapshot-delay option and set opts->snapshot_delay.
char * get_required_argument(const char *opt_value, char *buffer, size_t buffer_size, const char *option_name, asciichat_mode_t mode)
Handle required arguments with consistent error messages.
asciichat_error_t parse_webcam_index_option(const char *value_str, options_t *opts)
Parse –webcam-index option and set opts->webcam_index.
bool validate_webcam_index(const char *value_str, unsigned short int *out_index)
Validate webcam index using the common device index validator.
void update_dimensions_for_full_height(options_t *opts)
Update dimensions for full-height mode.
⚙️ Command-line options parsing and configuration management for ascii-chat
Consolidated options structure.