22 return SET_ERRNO(ERROR_INVALID_PARAM,
"Builder is NULL");
29 if (!entry->long_name) {
34 switch (entry->type) {
35 case OPTION_TYPE_STRING:
37 entry->default_value ? (
const char *)entry->default_value :
"", entry->help_text,
38 entry->group, entry->required, entry->env_var_name, entry->validate_fn);
42 if (entry->metadata.numeric_range.max != 0 ||
43 (entry->metadata.enum_values && entry->metadata.enum_values[0] != NULL)) {
45 entry->default_value ? *(
const int *)entry->default_value : 0,
46 entry->help_text, entry->group, entry->required, entry->env_var_name,
47 entry->validate_fn, &entry->metadata);
50 entry->default_value ? *(
const int *)entry->default_value : 0, entry->help_text,
51 entry->group, entry->required, entry->env_var_name, entry->validate_fn);
54 case OPTION_TYPE_BOOL:
56 entry->default_value ? *(
const bool *)entry->default_value :
false, entry->help_text,
57 entry->group, entry->required, entry->env_var_name);
59 case OPTION_TYPE_DOUBLE:
61 if (entry->metadata.numeric_range.max != 0) {
63 entry->default_value ? *(
const double *)entry->default_value : 0.0,
64 entry->help_text, entry->group, entry->required, entry->env_var_name,
65 entry->validate_fn, &entry->metadata);
68 entry->default_value ? *(
const double *)entry->default_value : 0.0, entry->help_text,
69 entry->group, entry->required, entry->env_var_name, entry->validate_fn);
72 case OPTION_TYPE_CALLBACK:
75 entry->default_value, entry->default_value_size, entry->parse_fn,
76 entry->help_text, entry->group, entry->required, entry->env_var_name,
77 entry->optional_arg, &entry->metadata);
79 case OPTION_TYPE_ACTION:
82 if (strcmp(entry->long_name,
"list-webcams") == 0) {
85 }
else if (strcmp(entry->long_name,
"list-microphones") == 0) {
87 entry->help_text, entry->group);
88 }
else if (strcmp(entry->long_name,
"list-speakers") == 0) {
91 }
else if (strcmp(entry->long_name,
"show-capabilities") == 0) {
93 entry->help_text, entry->group);
94 }
else if (strcmp(entry->long_name,
"check-update") == 0) {
97 }
else if (strcmp(entry->long_name,
"help") == 0 || strcmp(entry->long_name,
"version") == 0) {
109 if (entry->arg_placeholder) {
142 SET_ERRNO(ERROR_INVALID_PARAM,
"Long name is NULL");
151 if (strcmp(long_name,
"config") != 0) {
152 SET_ERRNO(ERROR_NOT_FOUND,
"Option not found: %s", long_name);
158 static option_descriptor_t desc;
159 desc.long_name = entry->long_name;
160 desc.short_name = entry->short_name;
161 desc.type = entry->type;
162 desc.offset = entry->offset;
163 desc.help_text = entry->help_text;
164 desc.group = entry->group;
165 desc.hide_from_mode_help =
false;
166 desc.hide_from_binary_help =
false;
167 desc.default_value = entry->default_value;
168 desc.required = entry->required;
169 desc.env_var_name = entry->env_var_name;
170 desc.validate = entry->validate_fn;
171 desc.parse_fn = entry->parse_fn;
172 desc.action_fn = NULL;
173 desc.owns_memory = entry->owns_memory;
174 desc.optional_arg = entry->optional_arg;
175 desc.mode_bitmask = entry->mode_bitmask;
181 if (short_name ==
'\0') {
182 SET_ERRNO(ERROR_INVALID_PARAM,
"Short name is empty");
190 SET_ERRNO(ERROR_NOT_FOUND,
"Option not found: -%c", short_name);
195 static option_descriptor_t desc;
196 desc.long_name = entry->long_name;
197 desc.short_name = entry->short_name;
198 desc.type = entry->type;
199 desc.offset = entry->offset;
200 desc.help_text = entry->help_text;
201 desc.group = entry->group;
202 desc.hide_from_mode_help =
false;
203 desc.hide_from_binary_help =
false;
204 desc.default_value = entry->default_value;
205 desc.required = entry->required;
206 desc.env_var_name = entry->env_var_name;
207 desc.validate = entry->validate_fn;
208 desc.parse_fn = entry->parse_fn;
209 desc.action_fn = NULL;
210 desc.owns_memory = entry->owns_memory;
211 desc.optional_arg = entry->optional_arg;
212 desc.mode_bitmask = entry->mode_bitmask;
219 SET_ERRNO(ERROR_INVALID_PARAM,
"Number of options is NULL");
226 option_mode_bitmask_t mode_bitmask = 0;
229 mode_bitmask = OPTION_MODE_SERVER;
232 mode_bitmask = OPTION_MODE_CLIENT;
235 mode_bitmask = OPTION_MODE_MIRROR;
237 case MODE_DISCOVERY_SERVICE:
238 mode_bitmask = OPTION_MODE_DISCOVERY_SVC;
241 mode_bitmask = OPTION_MODE_DISCOVERY;
244 SET_ERRNO(ERROR_INVALID_PARAM,
"Invalid mode: %d", mode);
263 option_descriptor_t *filtered = SAFE_MALLOC(count *
sizeof(option_descriptor_t), option_descriptor_t *);
265 SET_ERRNO(ERROR_INVALID_STATE,
"Failed to allocate filtered options array");
278 *num_options = count;
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)