ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
help_api.c File Reference

Public API for retrieving option help text. More...

Go to the source code of this file.

Functions

const char * options_get_help_text (asciichat_mode_t mode, const char *option_name)
 Get help text for an option in a specific mode.
 

Detailed Description

Public API for retrieving option help text.

Provides the options_get_help_text() function for external code (especially web clients) to retrieve help text for CLI options.

Author
Zachary Fogg me@zf.nosp@m.o.gg
Date
February 2026

Definition in file help_api.c.

Function Documentation

◆ options_get_help_text()

const char * options_get_help_text ( asciichat_mode_t  mode,
const char *  option_name 
)

Get help text for an option in a specific mode.

Parameters
modeThe mode context (MODE_SERVER, MODE_CLIENT, MODE_MIRROR, etc.)
option_nameThe long name of the option (e.g., "color-mode", "fps")
Returns
Help text string, or NULL if option doesn't apply to this mode

Searches the options registry for the given option name and checks if it applies to the requested mode. If it does, returns the help text. If the option doesn't exist or doesn't apply to the mode, returns NULL.

Definition at line 27 of file help_api.c.

27 {
28 if (!option_name || !option_name[0]) {
29 return NULL;
30 }
31
32 // Get the registry (initializes size if needed)
34
35 // Search through all registered options
36 for (size_t i = 0; i < g_registry_size; i++) {
37 const registry_entry_t *entry = &g_options_registry[i];
38
39 // Skip empty entries or entries without a long name
40 if (!entry->long_name || !entry->long_name[0]) {
41 continue;
42 }
43
44 // Check if this is the option we're looking for
45 if (strcmp(entry->long_name, option_name) != 0) {
46 continue;
47 }
48
49 // Check if this option applies to the requested mode
50 // Convert mode to bitmask for comparison
51 // Validate mode is in valid range (0-4) to avoid undefined behavior in bit shift
52 if (mode < 0 || mode >= MODE_INVALID) {
53 continue; // Skip invalid mode
54 }
55 uint32_t mode_bitmask = (1 << mode) | OPTION_MODE_BINARY;
56
57 if ((entry->mode_bitmask & mode_bitmask) == 0) {
58 // Option doesn't apply to this mode
59 return NULL;
60 }
61
62 // Return the help text (or empty string if not set)
63 return entry->help_text ? entry->help_text : "";
64 }
65
66 // Option not found
67 return NULL;
68}
void registry_init_size(void)
Initialize registry size and metadata.
Definition core.c:108
registry_entry_t g_options_registry[2048]
Definition registry.c:35
size_t g_registry_size
Definition registry.c:37

References g_options_registry, g_registry_size, and registry_init_size().

Referenced by get_help_text().