|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
Common utilities and helpers for option parsing. More...
Go to the source code of this file.
Macros | |
| #define | USAGE_INDENT " " |
| #define | USAGE_HELP_LINE USAGE_INDENT "-h --help " USAGE_INDENT "print this help\n" |
| #define | USAGE_VERSION_LINE USAGE_INDENT "-v --version " USAGE_INDENT "print version information\n" |
| #define | USAGE_PORT_LINE USAGE_INDENT "-p --port PORT " USAGE_INDENT "TCP port to listen on (default: %d)\n" |
| #define | USAGE_PORT_CLIENT_LINE USAGE_INDENT "-p --port PORT " USAGE_INDENT "override port from address (default: 27224)\n" |
| #define | USAGE_RECONNECT_LINE |
| #define | USAGE_MAX_CLIENTS_LINE USAGE_INDENT " --max-clients N " USAGE_INDENT "maximum simultaneous clients (1-9, default: 9)\n" |
| #define | USAGE_NO_AUDIO_MIXER_LINE USAGE_INDENT " --no-audio-mixer " USAGE_INDENT "disable audio mixer - send silence (debug mode only)\n" |
| #define | USAGE_WIDTH_LINE USAGE_INDENT "-x --width WIDTH " USAGE_INDENT "render width (default: [auto-set])\n" |
| #define | USAGE_HEIGHT_LINE USAGE_INDENT "-y --height HEIGHT " USAGE_INDENT "render height (default: [auto-set])\n" |
| #define | USAGE_WEBCAM_INDEX_LINE USAGE_INDENT "-c --webcam-index CAMERA " USAGE_INDENT "webcam device index (0-based) (default: 0)\n" |
| #define | USAGE_LIST_WEBCAMS_LINE USAGE_INDENT " --list-webcams " USAGE_INDENT "list available webcam devices and exit\n" |
| #define | USAGE_WEBCAM_FLIP_LINE |
| #define | USAGE_TEST_PATTERN_CLIENT_LINE |
| #define | USAGE_TEST_PATTERN_MIRROR_LINE USAGE_INDENT " --test-pattern " USAGE_INDENT "use test pattern instead of webcam (for testing)\n" |
| #define | USAGE_FPS_WIN_LINE USAGE_INDENT " --fps FPS " USAGE_INDENT "desired frame rate 1-144 (default: 30 for Windows)\n" |
| #define | USAGE_FPS_UNIX_LINE USAGE_INDENT " --fps FPS " USAGE_INDENT "desired frame rate 1-144 (default: 60 for Unix)\n" |
| #define | USAGE_COLOR_MODE_LINE |
| #define | USAGE_SHOW_CAPABILITIES_LINE USAGE_INDENT " --show-capabilities " USAGE_INDENT "show detected terminal capabilities and exit\n" |
| #define | USAGE_UTF8_LINE USAGE_INDENT " --utf8 " USAGE_INDENT "force enable UTF-8/Unicode support (default: [unset])\n" |
| #define | USAGE_RENDER_MODE_LINE |
| #define | USAGE_PALETTE_LINE |
| #define | USAGE_PALETTE_CHARS_LINE |
| #define | USAGE_STRETCH_LINE |
| #define | USAGE_SNAPSHOT_LINE USAGE_INDENT "-S --snapshot " USAGE_INDENT "capture single frame and exit (default: [unset])\n" |
| #define | USAGE_SNAPSHOT_DELAY_LINE USAGE_INDENT "-D --snapshot-delay SECONDS " USAGE_INDENT "delay SECONDS before snapshot (default: %.1f)\n" |
| #define | USAGE_STRIP_ANSI_LINE |
| #define | USAGE_AUDIO_LINE USAGE_INDENT "-A --audio " USAGE_INDENT "enable audio capture and playback (default: [unset])\n" |
| #define | USAGE_AUDIO_ANALYSIS_LINE |
| #define | USAGE_NO_AUDIO_PLAYBACK_LINE |
| #define | USAGE_LIST_MICROPHONES_LINE USAGE_INDENT " --list-microphones " USAGE_INDENT "list available audio input devices and exit\n" |
| #define | USAGE_LIST_SPEAKERS_LINE USAGE_INDENT " --list-speakers " USAGE_INDENT "list available audio output devices and exit\n" |
| #define | USAGE_MICROPHONE_INDEX_LINE USAGE_INDENT " --microphone-index INDEX " USAGE_INDENT "microphone device index (-1 for default) (default: -1)\n" |
| #define | USAGE_SPEAKERS_INDEX_LINE USAGE_INDENT " --speakers-index INDEX " USAGE_INDENT "speakers device index (-1 for default) (default: -1)\n" |
| #define | USAGE_ENCRYPT_LINE USAGE_INDENT "-E --encrypt " USAGE_INDENT "enable packet encryption (default: [unset])\n" |
| #define | USAGE_KEY_SERVER_LINE |
| #define | USAGE_KEY_CLIENT_LINE |
| #define | USAGE_PASSWORD_LINE |
| #define | USAGE_KEYFILE_LINE |
| #define | USAGE_NO_ENCRYPT_LINE USAGE_INDENT " --no-encrypt " USAGE_INDENT "disable encryption (default: [unset])\n" |
| #define | USAGE_SERVER_KEY_LINE |
| #define | USAGE_CLIENT_KEYS_LINE |
| #define | USAGE_COMPRESSION_LEVEL_LINE USAGE_INDENT " --compression-level N " USAGE_INDENT "zstd compression level 1-9 (default: 1)\n" |
| #define | USAGE_NO_COMPRESS_LINE USAGE_INDENT " --no-compress " USAGE_INDENT "disable frame compression (default: [unset])\n" |
| #define | USAGE_ENCODE_AUDIO_LINE USAGE_INDENT " --encode-audio " USAGE_INDENT "enable Opus audio encoding (default: enabled)\n" |
| #define | USAGE_NO_ENCODE_AUDIO_LINE USAGE_INDENT " --no-encode-audio " USAGE_INDENT "disable Opus audio encoding\n" |
| #define | USAGE_DATABASE_LINE |
| #define | USAGE_LOG_FILE_LINE USAGE_INDENT "-L --log-file FILE " USAGE_INDENT "log file path (default: stderr)\n" |
| #define | USAGE_LOG_LEVEL_LINE |
Functions | |
| const char * | find_similar_option (const char *unknown_opt, const struct option *options) |
| Find a similar option name for typo suggestions. | |
| int | strtoint_safe (const char *str) |
| Safely parse string to integer with validation. | |
| 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. | |
| bool | validate_positive_int_opt (const char *value_str, int *out_value, const char *param_name) |
| Validate a positive integer value. | |
| bool | validate_port_opt (const char *value_str, uint16_t *out_port) |
| Validate port number (1-65535) | |
| bool | validate_fps_opt (const char *value_str, int *out_fps) |
| Validate FPS value (1-144) | |
| bool | validate_webcam_index (const char *value_str, unsigned short int *out_index) |
| Validate webcam index using the common device index validator. | |
| asciichat_error_t | detect_default_ssh_key (char *key_path, size_t path_size) |
| Detect default SSH key path for the current user. | |
| char * | strip_equals_prefix (const char *opt_value, char *buffer, size_t buffer_size) |
| Strip equals sign prefix from option argument. | |
| 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. | |
| char * | read_password_from_stdin (const char *prompt) |
| Read password from stdin with prompt. | |
| 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_render_mode_option (const char *value_str, options_t *opts) |
| Parse –render-mode option and set opts->render_mode. | |
| 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_palette_chars_option (const char *value_str, options_t *opts) |
| Parse –palette-chars option and set opt_palette_custom. | |
| asciichat_error_t | parse_width_option (const char *value_str, options_t *opts) |
| Parse –width option and set opts->width. | |
| asciichat_error_t | parse_height_option (const char *value_str, options_t *opts) |
| Parse –height option and set opts->height. | |
| asciichat_error_t | parse_webcam_index_option (const char *value_str, options_t *opts) |
| Parse –webcam-index option and set opts->webcam_index. | |
| asciichat_error_t | parse_snapshot_delay_option (const char *value_str, options_t *opts) |
| Parse –snapshot-delay option and set opts->snapshot_delay. | |
| asciichat_error_t | parse_log_level_option (const char *value_str, options_t *opts) |
| Parse –log-level option and set opt_log_level. | |
| void | update_dimensions_for_full_height (options_t *opts) |
| Update dimensions for full-height mode. | |
| void | update_dimensions_to_terminal_size (options_t *opts) |
| Update dimensions to current terminal size. | |
Common utilities and helpers for option parsing.
Shared helper functions, validators, and utilities used by client.c, server.c, and mirror.c option parsing modules. This module provides:
Design Philosophy:
Definition in file options/common.h.
| #define USAGE_AUDIO_ANALYSIS_LINE |
Definition at line 576 of file options/common.h.
| #define USAGE_AUDIO_LINE USAGE_INDENT "-A --audio " USAGE_INDENT "enable audio capture and playback (default: [unset])\n" |
Definition at line 574 of file options/common.h.
| #define USAGE_CLIENT_KEYS_LINE |
Definition at line 613 of file options/common.h.
| #define USAGE_COLOR_MODE_LINE |
Definition at line 544 of file options/common.h.
| #define USAGE_COMPRESSION_LEVEL_LINE USAGE_INDENT " --compression-level N " USAGE_INDENT "zstd compression level 1-9 (default: 1)\n" |
Definition at line 619 of file options/common.h.
| #define USAGE_DATABASE_LINE |
Definition at line 633 of file options/common.h.
| #define USAGE_ENCODE_AUDIO_LINE USAGE_INDENT " --encode-audio " USAGE_INDENT "enable Opus audio encoding (default: enabled)\n" |
Definition at line 623 of file options/common.h.
| #define USAGE_ENCRYPT_LINE USAGE_INDENT "-E --encrypt " USAGE_INDENT "enable packet encryption (default: [unset])\n" |
Definition at line 592 of file options/common.h.
| #define USAGE_FPS_UNIX_LINE USAGE_INDENT " --fps FPS " USAGE_INDENT "desired frame rate 1-144 (default: 60 for Unix)\n" |
Definition at line 542 of file options/common.h.
| #define USAGE_FPS_WIN_LINE USAGE_INDENT " --fps FPS " USAGE_INDENT "desired frame rate 1-144 (default: 30 for Windows)\n" |
Definition at line 540 of file options/common.h.
| #define USAGE_HEIGHT_LINE USAGE_INDENT "-y --height HEIGHT " USAGE_INDENT "render height (default: [auto-set])\n" |
Definition at line 522 of file options/common.h.
| #define USAGE_HELP_LINE USAGE_INDENT "-h --help " USAGE_INDENT "print this help\n" |
Definition at line 501 of file options/common.h.
| #define USAGE_INDENT " " |
Definition at line 498 of file options/common.h.
| #define USAGE_KEY_CLIENT_LINE |
Definition at line 598 of file options/common.h.
| #define USAGE_KEY_SERVER_LINE |
Definition at line 594 of file options/common.h.
| #define USAGE_KEYFILE_LINE |
Definition at line 605 of file options/common.h.
| #define USAGE_LIST_MICROPHONES_LINE USAGE_INDENT " --list-microphones " USAGE_INDENT "list available audio input devices and exit\n" |
Definition at line 582 of file options/common.h.
| #define USAGE_LIST_SPEAKERS_LINE USAGE_INDENT " --list-speakers " USAGE_INDENT "list available audio output devices and exit\n" |
Definition at line 584 of file options/common.h.
| #define USAGE_LIST_WEBCAMS_LINE USAGE_INDENT " --list-webcams " USAGE_INDENT "list available webcam devices and exit\n" |
Definition at line 528 of file options/common.h.
| #define USAGE_LOG_FILE_LINE USAGE_INDENT "-L --log-file FILE " USAGE_INDENT "log file path (default: stderr)\n" |
Definition at line 637 of file options/common.h.
| #define USAGE_LOG_LEVEL_LINE |
Definition at line 638 of file options/common.h.
| #define USAGE_MAX_CLIENTS_LINE USAGE_INDENT " --max-clients N " USAGE_INDENT "maximum simultaneous clients (1-9, default: 9)\n" |
Definition at line 514 of file options/common.h.
| #define USAGE_MICROPHONE_INDEX_LINE USAGE_INDENT " --microphone-index INDEX " USAGE_INDENT "microphone device index (-1 for default) (default: -1)\n" |
Definition at line 586 of file options/common.h.
| #define USAGE_NO_AUDIO_MIXER_LINE USAGE_INDENT " --no-audio-mixer " USAGE_INDENT "disable audio mixer - send silence (debug mode only)\n" |
Definition at line 516 of file options/common.h.
| #define USAGE_NO_AUDIO_PLAYBACK_LINE |
Definition at line 579 of file options/common.h.
| #define USAGE_NO_COMPRESS_LINE USAGE_INDENT " --no-compress " USAGE_INDENT "disable frame compression (default: [unset])\n" |
Definition at line 621 of file options/common.h.
| #define USAGE_NO_ENCODE_AUDIO_LINE USAGE_INDENT " --no-encode-audio " USAGE_INDENT "disable Opus audio encoding\n" |
Definition at line 625 of file options/common.h.
| #define USAGE_NO_ENCRYPT_LINE USAGE_INDENT " --no-encrypt " USAGE_INDENT "disable encryption (default: [unset])\n" |
Definition at line 608 of file options/common.h.
| #define USAGE_PALETTE_CHARS_LINE |
Definition at line 557 of file options/common.h.
| #define USAGE_PALETTE_LINE |
Definition at line 554 of file options/common.h.
| #define USAGE_PASSWORD_LINE |
Definition at line 602 of file options/common.h.
| #define USAGE_PORT_CLIENT_LINE USAGE_INDENT "-p --port PORT " USAGE_INDENT "override port from address (default: 27224)\n" |
Definition at line 507 of file options/common.h.
| #define USAGE_PORT_LINE USAGE_INDENT "-p --port PORT " USAGE_INDENT "TCP port to listen on (default: %d)\n" |
Definition at line 505 of file options/common.h.
| #define USAGE_RECONNECT_LINE |
Definition at line 509 of file options/common.h.
| #define USAGE_RENDER_MODE_LINE |
Definition at line 551 of file options/common.h.
| #define USAGE_SERVER_KEY_LINE |
Definition at line 610 of file options/common.h.
| #define USAGE_SHOW_CAPABILITIES_LINE USAGE_INDENT " --show-capabilities " USAGE_INDENT "show detected terminal capabilities and exit\n" |
Definition at line 547 of file options/common.h.
| #define USAGE_SNAPSHOT_DELAY_LINE USAGE_INDENT "-D --snapshot-delay SECONDS " USAGE_INDENT "delay SECONDS before snapshot (default: %.1f)\n" |
Definition at line 567 of file options/common.h.
| #define USAGE_SNAPSHOT_LINE USAGE_INDENT "-S --snapshot " USAGE_INDENT "capture single frame and exit (default: [unset])\n" |
Definition at line 565 of file options/common.h.
| #define USAGE_SPEAKERS_INDEX_LINE USAGE_INDENT " --speakers-index INDEX " USAGE_INDENT "speakers device index (-1 for default) (default: -1)\n" |
Definition at line 588 of file options/common.h.
| #define USAGE_STRETCH_LINE |
Definition at line 560 of file options/common.h.
| #define USAGE_STRIP_ANSI_LINE |
Definition at line 569 of file options/common.h.
| #define USAGE_TEST_PATTERN_CLIENT_LINE |
Definition at line 533 of file options/common.h.
| #define USAGE_TEST_PATTERN_MIRROR_LINE USAGE_INDENT " --test-pattern " USAGE_INDENT "use test pattern instead of webcam (for testing)\n" |
Definition at line 536 of file options/common.h.
| #define USAGE_UTF8_LINE USAGE_INDENT " --utf8 " USAGE_INDENT "force enable UTF-8/Unicode support (default: [unset])\n" |
Definition at line 549 of file options/common.h.
| #define USAGE_VERSION_LINE USAGE_INDENT "-v --version " USAGE_INDENT "print version information\n" |
Definition at line 502 of file options/common.h.
| #define USAGE_WEBCAM_FLIP_LINE |
Definition at line 530 of file options/common.h.
| #define USAGE_WEBCAM_INDEX_LINE USAGE_INDENT "-c --webcam-index CAMERA " USAGE_INDENT "webcam device index (0-based) (default: 0)\n" |
Definition at line 526 of file options/common.h.
| #define USAGE_WIDTH_LINE USAGE_INDENT "-x --width WIDTH " USAGE_INDENT "render width (default: [auto-set])\n" |
Definition at line 520 of file options/common.h.
| asciichat_error_t detect_default_ssh_key | ( | char * | key_path, |
| size_t | path_size | ||
| ) |
Detect default SSH key path for the current user.
Checks if ~/.ssh/id_ed25519 exists and is a regular file. Only supports Ed25519 keys (modern, secure, fast).
| key_path | Buffer to store detected key path |
| path_size | Size of key_path buffer |
Example:
Definition at line 165 of file options/common.c.
References ASCIICHAT_OK, ERROR_CONFIG, ERROR_CRYPTO_KEY, expand_path(), log_debug, SAFE_FREE, SAFE_SNPRINTF, and SET_ERRNO.
| const char * find_similar_option | ( | const char * | unknown_opt, |
| const struct option * | options | ||
| ) |
Find a similar option name for typo suggestions.
Uses Levenshtein distance to find the most similar option name from the provided options array. Only suggests options within a reasonable edit distance.
| unknown_opt | The unknown/misspelled option name |
| options | Array of valid option structures (must be NULL-terminated) |
Example:
Definition at line 42 of file options/common.c.
References levenshtein(), and LEVENSHTEIN_SUGGESTION_THRESHOLD.
| 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.
Validates that an option has a non-empty argument and processes it. Returns NULL on error with appropriate error message printed.
Handles edge cases:
| opt_value | Argument value from getopt_long |
| buffer | Buffer for storing processed argument |
| buffer_size | Size of buffer |
| option_name | Name of the option (for error messages) |
| mode | Current mode (client/server/mirror) for error messages |
Example:
Definition at line 215 of file options/common.c.
References MODE_MIRROR, MODE_SERVER, and strip_equals_prefix().
Referenced by validate_required_argument().
| asciichat_error_t parse_color_mode_option | ( | const char * | value_str, |
| options_t * | opts | ||
| ) |
Parse –color-mode option and set opts->color_mode.
Validates color mode string and sets opts->color_mode field. Accepts: "auto", "none", "mono", "16", "16color", "256", "256color", "truecolor", "24bit"
| value_str | Color mode string from command line |
| opts | Options struct to update |
Definition at line 361 of file options/common.c.
References ASCIICHAT_OK, options_state::color_mode, COLOR_MODE_16_COLOR, COLOR_MODE_256_COLOR, COLOR_MODE_AUTO, COLOR_MODE_NONE, COLOR_MODE_TRUECOLOR, and ERROR_INVALID_PARAM.
| asciichat_error_t parse_height_option | ( | const char * | value_str, |
| options_t * | opts | ||
| ) |
Parse –height option and set opts->height.
Validates height value and sets opts->height and opts->auto_height fields.
| value_str | Height value from command line |
| opts | Options struct to update |
Definition at line 465 of file options/common.c.
References ASCIICHAT_OK, options_state::auto_height, ERROR_INVALID_PARAM, options_state::height, and validate_positive_int_opt().
| asciichat_error_t parse_log_level_option | ( | const char * | value_str, |
| options_t * | opts | ||
| ) |
Parse –log-level option and set opt_log_level.
Validates log level string and sets global opt_log_level variable. Accepts: "dev", "debug", "info", "warn", "error", "fatal" (case-insensitive)
| value_str | Log level string from command line |
Definition at line 513 of file options/common.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, options_state::log_level, and validate_opt_log_level().
| asciichat_error_t parse_palette_chars_option | ( | const char * | value_str, |
| options_t * | opts | ||
| ) |
Parse –palette-chars option and set opt_palette_custom.
Validates custom palette characters and sets global opt_palette_custom, opt_palette_custom_set, and opt_palette_type variables.
| value_str | Custom palette characters from command line |
Definition at line 430 of file options/common.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, options_state::palette_custom, PALETTE_CUSTOM, options_state::palette_custom_set, options_state::palette_type, and SAFE_STRNCPY.
| asciichat_error_t parse_palette_option | ( | const char * | value_str, |
| options_t * | opts | ||
| ) |
Parse –palette option and set opt_palette_type.
Validates palette type string and sets global opt_palette_type variable. Accepts: "standard", "blocks", "digital", "minimal", "cool", "custom"
| value_str | Palette type string from command line |
Definition at line 404 of file options/common.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, PALETTE_BLOCKS, PALETTE_COOL, PALETTE_CUSTOM, PALETTE_DIGITAL, PALETTE_MINIMAL, PALETTE_STANDARD, and options_state::palette_type.
| asciichat_error_t parse_render_mode_option | ( | const char * | value_str, |
| options_t * | opts | ||
| ) |
Parse –render-mode option and set opts->render_mode.
Validates render mode string and sets opts->render_mode field. Accepts: "foreground", "fg", "background", "bg", "half-block", "halfblock"
| value_str | Render mode string from command line |
| opts | Options struct to update |
Definition at line 384 of file options/common.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, options_state::render_mode, RENDER_MODE_BACKGROUND, RENDER_MODE_FOREGROUND, and RENDER_MODE_HALF_BLOCK.
| asciichat_error_t parse_snapshot_delay_option | ( | const char * | value_str, |
| options_t * | opts | ||
| ) |
Parse –snapshot-delay option and set opts->snapshot_delay.
Validates snapshot delay (non-negative float) and sets opts->snapshot_delay field.
| value_str | Snapshot delay in seconds from command line |
| opts | Options struct to update |
Definition at line 496 of file options/common.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, and options_state::snapshot_delay.
| asciichat_error_t parse_webcam_index_option | ( | const char * | value_str, |
| options_t * | opts | ||
| ) |
Parse –webcam-index option and set opts->webcam_index.
Validates webcam index and sets opts->webcam_index field.
| value_str | Webcam index from command line |
| opts | Options struct to update |
Definition at line 481 of file options/common.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, validate_webcam_index(), and options_state::webcam_index.
| asciichat_error_t parse_width_option | ( | const char * | value_str, |
| options_t * | opts | ||
| ) |
Parse –width option and set opts->width.
Validates width value and sets opts->width and opts->auto_width fields.
| value_str | Width value from command line |
| opts | Options struct to update |
Definition at line 449 of file options/common.c.
References ASCIICHAT_OK, options_state::auto_width, ERROR_INVALID_PARAM, validate_positive_int_opt(), and options_state::width.
| char * read_password_from_stdin | ( | const char * | prompt | ) |
Read password from stdin with prompt.
| prompt | Prompt message to display to user |
Prompts user for password input using prompt_password_simple() from util/password.h. Returns dynamically allocated string that must be freed by caller.
Definition at line 244 of file options/common.c.
References PASSWORD_MAX_LEN, prompt_password_simple(), SAFE_FREE, and SAFE_MALLOC.
| char * strip_equals_prefix | ( | const char * | opt_value, |
| char * | buffer, | ||
| size_t | buffer_size | ||
| ) |
Strip equals sign prefix from option argument.
Internal helper that handles GNU-style long options with = syntax (–option=value). Copies argument to buffer and returns pointer past the '=' if present.
| opt_value | Raw option value from getopt_long |
| buffer | Buffer to store processed value |
| buffer_size | Size of buffer |
Example:
Definition at line 195 of file options/common.c.
References SAFE_SNPRINTF.
Referenced by get_required_argument().
| int strtoint_safe | ( | const char * | str | ) |
Safely parse string to integer with validation.
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.
| void update_dimensions_for_full_height | ( | options_t * | opts | ) |
Update dimensions for full-height mode.
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.
| void update_dimensions_to_terminal_size | ( | options_t * | opts | ) |
Update dimensions to current 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.
| bool validate_fps_opt | ( | const char * | value_str, |
| int * | out_fps | ||
| ) |
Validate FPS value (1-144)
Internal option parsing helper that validates FPS is in reasonable range. Range chosen to support 1 FPS (slideshows) to 144 FPS (high refresh monitors).
| value_str | String to validate |
| out_fps | Output parameter for validated FPS |
Example:
Definition at line 127 of file options/common.c.
References strtoint_safe().
Validate port number (1-65535)
Internal option parsing helper that validates a port number is in valid range. Uses parse_port() for robust validation.
| value_str | String to validate |
| out_port | Output parameter for validated port |
Example:
Definition at line 112 of file options/common.c.
References ASCIICHAT_OK, and parse_port().
| bool validate_positive_int_opt | ( | const char * | value_str, |
| int * | out_value, | ||
| const char * | param_name | ||
| ) |
Validate a positive integer value.
Internal option parsing helper that validates a string represents a positive integer (> 0). Prints error message on failure.
| value_str | String to validate |
| out_value | Output parameter for validated integer |
| param_name | Parameter name for error messages |
Example:
Definition at line 96 of file options/common.c.
References strtoint_safe().
Referenced by parse_height_option(), and parse_width_option().
| 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.
Wrapper around get_required_argument() that also sets error code on failure. Used for options that must have an argument.
| optarg | Argument value from getopt_long |
| argbuf | Buffer for storing processed argument |
| argbuf_size | Size of argbuf |
| option_name | Name of the option (for error messages) |
| mode | Current mode (client/server/mirror) for error messages |
Example:
Definition at line 86 of file options/common.c.
References get_required_argument().
| bool validate_webcam_index | ( | const char * | value_str, |
| unsigned short int * | out_index | ||
| ) |
Validate webcam index using the common device index validator.
Validates webcam index is a non-negative integer. Unlike audio device indices, webcam indices do not support -1 (default).
| value_str | String to validate |
| out_index | Output parameter for validated index |
Example:
Definition at line 143 of file options/common.c.
References validate_opt_device_index().
Referenced by parse_webcam_index_option().