|
ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
|
Implementation of options builder API. More...
Go to the source code of this file.
Macros | |
| #define | asprintf platform_asprintf |
Functions | |
| const char * | get_option_help_placeholder_str (const option_descriptor_t *desc) |
| Get help placeholder string for an option type. | |
| int | format_option_default_value_str (const option_descriptor_t *desc, char *buf, size_t bufsize) |
| Format option default value as a string. | |
| bool | option_applies_to_mode (const option_descriptor_t *desc, asciichat_mode_t mode, bool for_binary_help) |
| Check if an option applies to a specific mode using bitmask. | |
| void | ensure_descriptor_capacity (options_builder_t *builder) |
| Grow descriptor array if needed. | |
| void | ensure_dependency_capacity (options_builder_t *builder) |
| Grow dependency array if needed. | |
| void | ensure_positional_arg_capacity (options_builder_t *builder) |
| Grow positional arg array if needed. | |
| const option_descriptor_t * | find_option (const options_config_t *config, const char *long_name) |
| Find option descriptor by long name. | |
| bool | is_option_set (const options_config_t *config, const void *options_struct, const char *option_name) |
| Check if an option is set (has non-default value) | |
| options_builder_t * | options_builder_create (size_t struct_size) |
| options_builder_t * | options_builder_from_preset (const options_config_t *preset) |
| void | options_builder_destroy (options_builder_t *builder) |
| options_config_t * | options_builder_build (options_builder_t *builder) |
| void | options_config_destroy (options_config_t *config) |
| void | options_builder_add_bool (options_builder_t *builder, const char *long_name, char short_name, size_t offset, bool default_value, const char *help_text, const char *group, bool required, const char *env_var_name) |
| void | options_builder_add_int (options_builder_t *builder, const char *long_name, char short_name, size_t offset, int default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *, char **)) |
| void | options_builder_add_int_with_metadata (options_builder_t *builder, const char *long_name, char short_name, size_t offset, int default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *options_struct, char **error_msg), const option_metadata_t *metadata) |
| void | options_builder_add_string (options_builder_t *builder, const char *long_name, char short_name, size_t offset, const char *default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *, char **)) |
| void | options_builder_add_double (options_builder_t *builder, const char *long_name, char short_name, size_t offset, double default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *, char **)) |
| void | options_builder_add_double_with_metadata (options_builder_t *builder, const char *long_name, char short_name, size_t offset, double default_value, const char *help_text, const char *group, bool required, const char *env_var_name, bool(*validate)(const void *, char **), const option_metadata_t *metadata) |
| void | options_builder_add_callback (options_builder_t *builder, const char *long_name, char short_name, size_t offset, const void *default_value, size_t value_size, bool(*parse_fn)(const char *, void *, char **), const char *help_text, const char *group, bool required, const char *env_var_name) |
| void | options_builder_add_callback_optional (options_builder_t *builder, const char *long_name, char short_name, size_t offset, const void *default_value, size_t value_size, bool(*parse_fn)(const char *, void *, char **), const char *help_text, const char *group, bool required, const char *env_var_name, bool optional_arg) |
| Add callback option with optional argument support. | |
| void | options_builder_add_callback_with_metadata (options_builder_t *builder, const char *long_name, char short_name, size_t offset, const void *default_value, size_t value_size, bool(*parse_fn)(const char *, void *, char **), const char *help_text, const char *group, bool required, const char *env_var_name, bool optional_arg, const option_metadata_t *metadata) |
| void | options_builder_add_action (options_builder_t *builder, const char *long_name, char short_name, void(*action_fn)(void), const char *help_text, const char *group) |
| void | options_builder_add_descriptor (options_builder_t *builder, const option_descriptor_t *descriptor) |
| void | options_builder_set_mode_bitmask (options_builder_t *builder, option_mode_bitmask_t mode_bitmask) |
| void | options_builder_set_arg_placeholder (options_builder_t *builder, const char *arg_placeholder) |
| void | options_builder_set_enum_values (options_builder_t *builder, const char *option_name, const char **values, const char **descriptions) |
| void | options_builder_set_numeric_range (options_builder_t *builder, const char *option_name, int min, int max, int step) |
| void | options_builder_set_examples (options_builder_t *builder, const char *option_name, const char **examples) |
| void | options_builder_set_input_type (options_builder_t *builder, const char *option_name, option_input_type_t input_type) |
| void | options_builder_mark_as_list (options_builder_t *builder, const char *option_name) |
| void | options_builder_set_default_value_display (options_builder_t *builder, const char *option_name, const char *default_value) |
| void | options_builder_add_dependency_requires (options_builder_t *builder, const char *option_name, const char *depends_on, const char *error_message) |
| void | options_builder_add_dependency_conflicts (options_builder_t *builder, const char *option_name, const char *conflicts_with, const char *error_message) |
| void | options_builder_add_dependency_implies (options_builder_t *builder, const char *option_name, const char *implies, const char *error_message) |
| void | options_builder_add_dependency (options_builder_t *builder, const option_dependency_t *dependency) |
| void | options_builder_mark_binary_only (options_builder_t *builder, const char *option_name) |
| void | options_builder_add_positional (options_builder_t *builder, const char *name, const char *help_text, bool required, const char *section_heading, const char **examples, size_t num_examples, option_mode_bitmask_t mode_bitmask, int(*parse_fn)(const char *arg, void *config, char **remaining, int num_remaining, char **error_msg)) |
| void | options_builder_add_usage (options_builder_t *builder, const char *mode, const char *positional, bool show_options, const char *description) |
| void | options_builder_add_example (options_builder_t *builder, uint32_t mode_bitmask, const char *args, const char *description, bool owns_args) |
| void | options_builder_add_example_utility (options_builder_t *builder, uint32_t mode_bitmask, const char *args, const char *description, bool is_utility_command) |
| Add an example with utility command support. | |
| void | options_builder_add_mode (options_builder_t *builder, const char *name, const char *description) |
| void | options_builder_add_custom_section (options_builder_t *builder, const char *heading, const char *content, option_mode_bitmask_t mode_bitmask) |
| asciichat_error_t | options_config_parse_positional (const options_config_t *config, int remaining_argc, char **remaining_argv, void *options_struct) |
| asciichat_error_t | options_config_set_defaults (const options_config_t *config, void *options_struct) |
| const option_descriptor_t * | find_option_descriptor (const options_config_t *config, const char *opt_name) |
| Find option descriptor by short or long name. | |
| asciichat_error_t | options_config_parse (const options_config_t *config, int argc, char **argv, void *options_struct, option_mode_bitmask_t detected_mode, int *remaining_argc, char ***remaining_argv) |
| asciichat_error_t | options_config_validate (const options_config_t *config, const void *options_struct, char **error_message) |
Implementation of options builder API.
Definition in file builder.c.
| #define asprintf platform_asprintf |
| void ensure_dependency_capacity | ( | options_builder_t * | builder | ) |
Grow dependency array if needed.
Definition at line 203 of file builder.c.
Referenced by options_builder_add_dependency(), options_builder_add_dependency_conflicts(), options_builder_add_dependency_implies(), and options_builder_add_dependency_requires().
| void ensure_descriptor_capacity | ( | options_builder_t * | builder | ) |
Grow descriptor array if needed.
Definition at line 186 of file builder.c.
Referenced by options_builder_add_action(), options_builder_add_bool(), options_builder_add_callback(), options_builder_add_callback_optional(), options_builder_add_callback_with_metadata(), options_builder_add_descriptor(), options_builder_add_double(), options_builder_add_double_with_metadata(), options_builder_add_int(), options_builder_add_int_with_metadata(), and options_builder_add_string().
| void ensure_positional_arg_capacity | ( | options_builder_t * | builder | ) |
Grow positional arg array if needed.
Definition at line 220 of file builder.c.
Referenced by options_builder_add_positional().
| const option_descriptor_t * find_option | ( | const options_config_t * | config, |
| const char * | long_name | ||
| ) |
Find option descriptor by long name.
Definition at line 317 of file builder.c.
Referenced by is_option_set().
| const option_descriptor_t * find_option_descriptor | ( | const options_config_t * | config, |
| const char * | opt_name | ||
| ) |
Find option descriptor by short or long name.
Definition at line 1453 of file builder.c.
| int format_option_default_value_str | ( | const option_descriptor_t * | desc, |
| char * | buf, | ||
| size_t | bufsize | ||
| ) |
Format option default value as a string.
| desc | Option descriptor |
| buf | Output buffer |
| bufsize | Size of buffer |
Definition at line 56 of file builder.c.
References options_format_default_value(), and safe_snprintf().
Referenced by options_config_print_options_sections_with_width(), and options_config_print_usage().
| const char * get_option_help_placeholder_str | ( | const option_descriptor_t * | desc | ) |
Get help placeholder string for an option type.
| desc | Option descriptor |
Definition at line 38 of file builder.c.
References options_get_type_placeholder().
Referenced by options_config_print_options_sections_with_width(), and options_config_print_usage().
| bool is_option_set | ( | const options_config_t * | config, |
| const void * | options_struct, | ||
| const char * | option_name | ||
| ) |
Check if an option is set (has non-default value)
Definition at line 329 of file builder.c.
References find_option(), and g_builder_handlers.
Referenced by options_config_validate().
| bool option_applies_to_mode | ( | const option_descriptor_t * | desc, |
| asciichat_mode_t | mode, | ||
| bool | for_binary_help | ||
| ) |
Check if an option applies to a specific mode using bitmask.
| desc | Option descriptor |
| mode | Mode to check (use invalid value like -1 for binary help) |
| for_binary_help | If true, show binary options; if false, hide them |
Definition at line 150 of file builder.c.
Referenced by options_config_print_options_sections_with_width(), and options_config_print_usage().
| void options_builder_add_action | ( | options_builder_t * | builder, |
| const char * | long_name, | ||
| char | short_name, | ||
| void(*)(void) | action_fn, | ||
| const char * | help_text, | ||
| const char * | group | ||
| ) |
Definition at line 919 of file builder.c.
References ensure_descriptor_capacity().
Referenced by options_registry_add_all_to_builder().
| void options_builder_add_bool | ( | options_builder_t * | builder, |
| const char * | long_name, | ||
| char | short_name, | ||
| size_t | offset, | ||
| bool | default_value, | ||
| const char * | help_text, | ||
| const char * | group, | ||
| bool | required, | ||
| const char * | env_var_name | ||
| ) |
Definition at line 627 of file builder.c.
References ensure_descriptor_capacity().
Referenced by options_registry_add_all_to_builder().
| void options_builder_add_callback | ( | options_builder_t * | builder, |
| const char * | long_name, | ||
| char | short_name, | ||
| size_t | offset, | ||
| const void * | default_value, | ||
| size_t | value_size, | ||
| bool(*)(const char *, void *, char **) | parse_fn, | ||
| const char * | help_text, | ||
| const char * | group, | ||
| bool | required, | ||
| const char * | env_var_name | ||
| ) |
Definition at line 825 of file builder.c.
References ensure_descriptor_capacity().
| void options_builder_add_callback_optional | ( | options_builder_t * | builder, |
| const char * | long_name, | ||
| char | short_name, | ||
| size_t | offset, | ||
| const void * | default_value, | ||
| size_t | value_size, | ||
| bool(*)(const char *, void *, char **) | parse_fn, | ||
| const char * | help_text, | ||
| const char * | group, | ||
| bool | required, | ||
| const char * | env_var_name, | ||
| bool | optional_arg | ||
| ) |
Add callback option with optional argument support.
| builder | Builder to add to |
| long_name | Long option name |
| short_name | Short option char (or '\0') |
| offset | offsetof(struct, field) |
| default_value | Pointer to default value (or NULL) |
| value_size | sizeof(field_type) |
| parse_fn | Custom parser function |
| help_text | Help description |
| group | Group name for help |
| required | If true, option must be provided |
| env_var_name | Environment variable fallback (or NULL) |
| optional_arg | If true, argument is optional (parser receives NULL if not provided) |
Definition at line 866 of file builder.c.
References ensure_descriptor_capacity().
| void options_builder_add_callback_with_metadata | ( | options_builder_t * | builder, |
| const char * | long_name, | ||
| char | short_name, | ||
| size_t | offset, | ||
| const void * | default_value, | ||
| size_t | value_size, | ||
| bool(*)(const char *, void *, char **) | parse_fn, | ||
| const char * | help_text, | ||
| const char * | group, | ||
| bool | required, | ||
| const char * | env_var_name, | ||
| bool | optional_arg, | ||
| const option_metadata_t * | metadata | ||
| ) |
Definition at line 892 of file builder.c.
References ensure_descriptor_capacity().
Referenced by options_registry_add_all_to_builder().
| void options_builder_add_custom_section | ( | options_builder_t * | builder, |
| const char * | heading, | ||
| const char * | content, | ||
| option_mode_bitmask_t | mode_bitmask | ||
| ) |
Definition at line 1295 of file builder.c.
Referenced by options_preset_unified().
| void options_builder_add_dependency | ( | options_builder_t * | builder, |
| const option_dependency_t * | dependency | ||
| ) |
Definition at line 1140 of file builder.c.
References ensure_dependency_capacity().
Referenced by options_builder_from_preset().
| void options_builder_add_dependency_conflicts | ( | options_builder_t * | builder, |
| const char * | option_name, | ||
| const char * | conflicts_with, | ||
| const char * | error_message | ||
| ) |
Definition at line 1118 of file builder.c.
References ensure_dependency_capacity().
Referenced by options_preset_unified().
| void options_builder_add_dependency_implies | ( | options_builder_t * | builder, |
| const char * | option_name, | ||
| const char * | implies, | ||
| const char * | error_message | ||
| ) |
Definition at line 1130 of file builder.c.
References ensure_dependency_capacity().
| void options_builder_add_dependency_requires | ( | options_builder_t * | builder, |
| const char * | option_name, | ||
| const char * | depends_on, | ||
| const char * | error_message | ||
| ) |
Definition at line 1106 of file builder.c.
References ensure_dependency_capacity().
Referenced by options_preset_unified().
| void options_builder_add_descriptor | ( | options_builder_t * | builder, |
| const option_descriptor_t * | descriptor | ||
| ) |
Definition at line 949 of file builder.c.
References ensure_descriptor_capacity().
Referenced by options_builder_from_preset().
| void options_builder_add_double | ( | options_builder_t * | builder, |
| const char * | long_name, | ||
| char | short_name, | ||
| size_t | offset, | ||
| double | default_value, | ||
| const char * | help_text, | ||
| const char * | group, | ||
| bool | required, | ||
| const char * | env_var_name, | ||
| bool(*)(const void *, char **) | validate | ||
| ) |
Definition at line 757 of file builder.c.
References ensure_descriptor_capacity().
Referenced by options_registry_add_all_to_builder().
| void options_builder_add_double_with_metadata | ( | options_builder_t * | builder, |
| const char * | long_name, | ||
| char | short_name, | ||
| size_t | offset, | ||
| double | default_value, | ||
| const char * | help_text, | ||
| const char * | group, | ||
| bool | required, | ||
| const char * | env_var_name, | ||
| bool(*)(const void *, char **) | validate, | ||
| const option_metadata_t * | metadata | ||
| ) |
Definition at line 790 of file builder.c.
References ensure_descriptor_capacity().
Referenced by options_registry_add_all_to_builder().
| void options_builder_add_example | ( | options_builder_t * | builder, |
| uint32_t | mode_bitmask, | ||
| const char * | args, | ||
| const char * | description, | ||
| bool | owns_args | ||
| ) |
Definition at line 1231 of file builder.c.
References args, and platform_strdup().
Referenced by options_preset_unified().
| void options_builder_add_example_utility | ( | options_builder_t * | builder, |
| uint32_t | mode_bitmask, | ||
| const char * | args, | ||
| const char * | description, | ||
| bool | is_utility_command | ||
| ) |
Add an example with utility command support.
Allows marking utility commands (like pbpaste, grep, etc.) that shouldn't be prepended with program name in help output.
Definition at line 1265 of file builder.c.
References args.
Referenced by options_preset_unified().
| void options_builder_add_int | ( | options_builder_t * | builder, |
| const char * | long_name, | ||
| char | short_name, | ||
| size_t | offset, | ||
| int | default_value, | ||
| const char * | help_text, | ||
| const char * | group, | ||
| bool | required, | ||
| const char * | env_var_name, | ||
| bool(*)(const void *, char **) | validate | ||
| ) |
Definition at line 651 of file builder.c.
References ensure_descriptor_capacity().
Referenced by options_registry_add_all_to_builder().
| void options_builder_add_int_with_metadata | ( | options_builder_t * | builder, |
| const char * | long_name, | ||
| char | short_name, | ||
| size_t | offset, | ||
| int | default_value, | ||
| const char * | help_text, | ||
| const char * | group, | ||
| bool | required, | ||
| const char * | env_var_name, | ||
| bool(*)(const void *options_struct, char **error_msg) | validate, | ||
| const option_metadata_t * | metadata | ||
| ) |
Definition at line 684 of file builder.c.
References ensure_descriptor_capacity().
Referenced by options_registry_add_all_to_builder().
| void options_builder_add_mode | ( | options_builder_t * | builder, |
| const char * | name, | ||
| const char * | description | ||
| ) |
Definition at line 1284 of file builder.c.
Referenced by options_preset_unified().
| void options_builder_add_positional | ( | options_builder_t * | builder, |
| const char * | name, | ||
| const char * | help_text, | ||
| bool | required, | ||
| const char * | section_heading, | ||
| const char ** | examples, | ||
| size_t | num_examples, | ||
| option_mode_bitmask_t | mode_bitmask, | ||
| int(*)(const char *arg, void *config, char **remaining, int num_remaining, char **error_msg) | parse_fn | ||
| ) |
Definition at line 1168 of file builder.c.
References ensure_positional_arg_capacity().
Referenced by options_builder_from_preset(), and options_preset_unified().
| void options_builder_add_string | ( | options_builder_t * | builder, |
| const char * | long_name, | ||
| char | short_name, | ||
| size_t | offset, | ||
| const char * | default_value, | ||
| const char * | help_text, | ||
| const char * | group, | ||
| bool | required, | ||
| const char * | env_var_name, | ||
| bool(*)(const void *, char **) | validate | ||
| ) |
Definition at line 720 of file builder.c.
References ensure_descriptor_capacity().
Referenced by options_registry_add_all_to_builder().
| void options_builder_add_usage | ( | options_builder_t * | builder, |
| const char * | mode, | ||
| const char * | positional, | ||
| bool | show_options, | ||
| const char * | description | ||
| ) |
Definition at line 1218 of file builder.c.
References usage().
Referenced by options_preset_unified().
| options_config_t * options_builder_build | ( | options_builder_t * | builder | ) |
Definition at line 452 of file builder.c.
Referenced by options_builder_generate_manpage_template(), and options_preset_unified().
| options_builder_t * options_builder_create | ( | size_t | struct_size | ) |
Definition at line 351 of file builder.c.
Referenced by options_builder_from_preset(), and options_preset_unified().
| void options_builder_destroy | ( | options_builder_t * | builder | ) |
Definition at line 437 of file builder.c.
Referenced by options_preset_unified().
| options_builder_t * options_builder_from_preset | ( | const options_config_t * | preset | ) |
Definition at line 402 of file builder.c.
References options_builder_add_dependency(), options_builder_add_descriptor(), options_builder_add_positional(), and options_builder_create().
| void options_builder_mark_as_list | ( | options_builder_t * | builder, |
| const char * | option_name | ||
| ) |
Definition at line 1069 of file builder.c.
| void options_builder_mark_binary_only | ( | options_builder_t * | builder, |
| const char * | option_name | ||
| ) |
Definition at line 1148 of file builder.c.
| void options_builder_set_arg_placeholder | ( | options_builder_t * | builder, |
| const char * | arg_placeholder | ||
| ) |
Definition at line 968 of file builder.c.
Referenced by options_registry_add_all_to_builder().
| void options_builder_set_default_value_display | ( | options_builder_t * | builder, |
| const char * | option_name, | ||
| const char * | default_value | ||
| ) |
Definition at line 1085 of file builder.c.
| void options_builder_set_enum_values | ( | options_builder_t * | builder, |
| const char * | option_name, | ||
| const char ** | values, | ||
| const char ** | descriptions | ||
| ) |
Definition at line 998 of file builder.c.
| void options_builder_set_examples | ( | options_builder_t * | builder, |
| const char * | option_name, | ||
| const char ** | examples | ||
| ) |
Definition at line 1035 of file builder.c.
| void options_builder_set_input_type | ( | options_builder_t * | builder, |
| const char * | option_name, | ||
| option_input_type_t | input_type | ||
| ) |
Definition at line 1052 of file builder.c.
| void options_builder_set_mode_bitmask | ( | options_builder_t * | builder, |
| option_mode_bitmask_t | mode_bitmask | ||
| ) |
Definition at line 960 of file builder.c.
Referenced by options_registry_add_all_to_builder().
| void options_builder_set_numeric_range | ( | options_builder_t * | builder, |
| const char * | option_name, | ||
| int | min, | ||
| int | max, | ||
| int | step | ||
| ) |
Definition at line 1016 of file builder.c.
| void options_config_destroy | ( | options_config_t * | config | ) |
Definition at line 601 of file builder.c.
Referenced by options_init(), and usage().
| asciichat_error_t options_config_parse | ( | const options_config_t * | config, |
| int | argc, | ||
| char ** | argv, | ||
| void * | options_struct, | ||
| option_mode_bitmask_t | detected_mode, | ||
| int * | remaining_argc, | ||
| char *** | remaining_argv | ||
| ) |
Definition at line 1750 of file builder.c.
Referenced by options_init().
| asciichat_error_t options_config_parse_positional | ( | const options_config_t * | config, |
| int | remaining_argc, | ||
| char ** | remaining_argv, | ||
| void * | options_struct | ||
| ) |
Definition at line 1307 of file builder.c.
| asciichat_error_t options_config_set_defaults | ( | const options_config_t * | config, |
| void * | options_struct | ||
| ) |
Definition at line 1376 of file builder.c.
References g_builder_handlers.
Referenced by options_init().
| asciichat_error_t options_config_validate | ( | const options_config_t * | config, |
| const void * | options_struct, | ||
| char ** | error_message | ||
| ) |
Definition at line 1775 of file builder.c.
References asprintf, g_builder_handlers, is_option_set(), is_set, and platform_strdup().
Referenced by validate_options_and_report().