|
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.
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 * | 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 * | 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 * | 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. | |
| void | usage (FILE *desc, asciichat_mode_t mode) |
| Print usage information for client, server, or mirror mode. | |
Common utilities and helpers for option parsing.
Shared helper functions, validators, and global variables used by all option parsing modules (client.c, server.c, mirror.c).
Definition in file options/common.c.
| 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().
| 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().
| ASCIICHAT_API bool auto_height = true |
Definition at line 263 of file options/common.c.
| ASCIICHAT_API bool auto_width = true |
Definition at line 263 of file options/common.c.
| ASCIICHAT_API char opt_address[OPTIONS_BUFF_SIZE] = "localhost" |
Definition at line 268 of file options/common.c.
| ASCIICHAT_API char opt_address6[OPTIONS_BUFF_SIZE] = "" |
Definition at line 268 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_audio_analysis_enabled = 0 |
Definition at line 298 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_audio_enabled = 0 |
Definition at line 295 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_audio_no_playback = 0 |
Definition at line 299 of file options/common.c.
| ASCIICHAT_API char opt_client_keys[OPTIONS_BUFF_SIZE] = "" |
Definition at line 338 of file options/common.c.
| ASCIICHAT_API terminal_color_mode_t opt_color_mode = COLOR_MODE_AUTO |
Definition at line 290 of file options/common.c.
| ASCIICHAT_API int opt_compression_level = 1 |
Definition at line 275 of file options/common.c.
| ASCIICHAT_API bool opt_encode_audio = true |
Definition at line 277 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_encrypt_enabled = 0 |
Definition at line 330 of file options/common.c.
| ASCIICHAT_API char opt_encrypt_key[OPTIONS_BUFF_SIZE] = "" |
Definition at line 331 of file options/common.c.
| ASCIICHAT_API char opt_encrypt_keyfile[OPTIONS_BUFF_SIZE] = "" |
Definition at line 333 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_force_utf8 = 0 |
Definition at line 293 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_height = OPT_HEIGHT_DEFAULT |
Definition at line 262 of file options/common.c.
| ASCIICHAT_API char opt_log_file[OPTIONS_BUFF_SIZE] = "" |
Definition at line 320 of file options/common.c.
| ASCIICHAT_API log_level_t opt_log_level = LOG_DEBUG |
Definition at line 326 of file options/common.c.
| ASCIICHAT_API int opt_max_clients = 10 |
Definition at line 272 of file options/common.c.
| ASCIICHAT_API int opt_microphone_index = -1 |
Definition at line 296 of file options/common.c.
| ASCIICHAT_API bool opt_no_audio_mixer = false |
Definition at line 287 of file options/common.c.
| ASCIICHAT_API bool opt_no_compress = false |
Definition at line 276 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_no_encrypt = 0 |
Definition at line 336 of file options/common.c.
| ASCIICHAT_API char opt_palette_custom[256] = "" |
Definition at line 342 of file options/common.c.
| ASCIICHAT_API bool opt_palette_custom_set = false |
Definition at line 343 of file options/common.c.
| ASCIICHAT_API palette_type_t opt_palette_type = PALETTE_STANDARD |
Definition at line 341 of file options/common.c.
| ASCIICHAT_API char opt_password[OPTIONS_BUFF_SIZE] = "" |
Definition at line 332 of file options/common.c.
| ASCIICHAT_API char opt_port[OPTIONS_BUFF_SIZE] = "27224" |
Definition at line 269 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_quiet = 0 |
Definition at line 305 of file options/common.c.
| ASCIICHAT_API int opt_reconnect_attempts = -1 |
Definition at line 280 of file options/common.c.
| ASCIICHAT_API render_mode_t opt_render_mode = RENDER_MODE_FOREGROUND |
Definition at line 291 of file options/common.c.
| ASCIICHAT_API char opt_server_key[OPTIONS_BUFF_SIZE] = "" |
Definition at line 337 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_show_capabilities = 0 |
Definition at line 292 of file options/common.c.
| ASCIICHAT_API float opt_snapshot_delay = SNAPSHOT_DELAY_DEFAULT |
Definition at line 314 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_snapshot_mode = 0 |
Definition at line 311 of file options/common.c.
| ASCIICHAT_API int opt_speakers_index = -1 |
Definition at line 297 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_stretch = 0 |
Definition at line 302 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_strip_ansi = 0 |
Definition at line 317 of file options/common.c.
| ASCIICHAT_API bool opt_test_pattern = false |
Definition at line 286 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_verbose_level = 0 |
Definition at line 308 of file options/common.c.
| ASCIICHAT_API bool opt_webcam_flip = true |
Definition at line 284 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_webcam_index = 0 |
Definition at line 282 of file options/common.c.
| ASCIICHAT_API unsigned short int opt_width = OPT_WIDTH_DEFAULT |
Definition at line 262 of file options/common.c.
Definition at line 266 of file options/common.c.