ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
help_api.c
Go to the documentation of this file.
1
13#include <ascii-chat/options/options.h>
14#include <ascii-chat/options/registry/core.h>
15#include <string.h>
16
27const char *options_get_help_text(asciichat_mode_t mode, const char *option_name) {
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
const char * options_get_help_text(asciichat_mode_t mode, const char *option_name)
Get help text for an option in a specific mode.
Definition help_api.c:27
registry_entry_t g_options_registry[2048]
Definition registry.c:35
size_t g_registry_size
Definition registry.c:37