62 #include <yajl/yajl_gen.h>
64 #include <amxj/amxj_variant.h>
111 if((value == NULL) || (strcmp(value,
"config") == 0)) {
113 }
else if(strcmp(value,
"caps") == 0) {
183 amxrt_cmd_line_add_option(0,
'A',
"no-auto-detect", no_argument,
"Do not auto detect unix domain sockets and back-ends", NULL);
185 amxrt_cmd_line_add_option(0,
'I',
"include-dir", required_argument,
"Adds include directory for odl parser, multiple allowed",
"dir");
186 amxrt_cmd_line_add_option(0,
'L',
"import-dir", required_argument,
"Adds import directory for odl parser, multiple allowed",
"dir");
188 amxrt_cmd_line_add_option(0,
'F',
"forced-option", required_argument,
"Adds a configuration option, which can not be overwritten by odl files",
"name=value");
189 amxrt_cmd_line_add_option(0,
'O',
"ODL", required_argument,
"An ODL in string format, only one ODL string allowed",
"odl-string");
194 amxrt_cmd_line_add_option(0,
'd',
"dump", optional_argument,
"Dumps configuration options or capabilities at start-up",
"[caps|config]");
196 amxrt_cmd_line_add_option(0,
'R',
"requires", required_argument,
"Checks if datamodel objects are available or waits until they are available",
"root object");
212 when_null(option, exit);
214 option->
id =
id == 0 ? (int) short_option :
id;
232 rt->
usage_doc = usage == NULL ?
"[OPTIONS] <odl files>" : usage;
240 struct option* long_options = (
struct option*) calloc(nr_options + 1,
sizeof(
struct option));
241 amxc_string_t format;
246 if(long_options == NULL) {
252 amxc_string_init(&format, 0);
256 long_options[index].has_arg = option->
has_args;
257 long_options[index].val = option->
id;
258 if(option->
has_args == no_argument) {
259 amxc_string_appendf(&format,
"%c", option->
short_option);
260 }
else if(option->
has_args == optional_argument) {
261 amxc_string_appendf(&format,
"%c::", option->
short_option);
263 amxc_string_appendf(&format,
"%c:", option->
short_option);
270 c = getopt_long(argc, argv, amxc_string_get(&format, 0), long_options, &index);
286 when_failed_status(rv, exit, rv = -1);
291 amxc_string_clean(&format);
292 return rv == 0 ? optind : rv;
298 amxc_var_t*
config = NULL;
299 amxc_string_t str_option;
300 amxc_llist_t options;
301 amxc_string_t* name = NULL;
302 amxc_string_t* value = NULL;
303 amxc_var_t var_option;
305 amxc_var_init(&var_option);
306 amxc_llist_init(&options);
307 amxc_string_init(&str_option, 0);
309 amxc_string_set(&str_option, option);
310 amxc_string_split_to_llist(&str_option, &options,
'=');
311 when_true(amxc_llist_is_empty(&options), leave);
312 when_true(amxc_llist_size(&options) != 2, leave);
314 name = amxc_string_from_llist_it(amxc_llist_get_first(&options));
315 value = amxc_string_from_llist_it(amxc_llist_get_last(&options));
317 amxc_string_trim(name, NULL);
318 amxc_string_trim(value, NULL);
320 if(amxc_var_set(jstring_t, &var_option, amxc_string_get(value, 0)) != 0) {
321 amxc_var_set(cstring_t, &var_option, amxc_string_get(value, 0));
323 amxc_var_cast(&var_option, AMXC_VAR_ID_ANY);
327 amxc_var_set_path(
config, amxc_string_get(name, 0), &var_option,
328 AMXC_VAR_FLAG_AUTO_ADD | AMXC_VAR_FLAG_COPY);
331 amxc_string_clean(&str_option);
332 amxc_llist_clean(&options, amxc_string_list_it_free);
333 amxc_var_clean(&var_option);
#define AMXRT_COPT_BACKENDS
#define AMXRT_COPT_PID_FILE
#define AMXRT_COPT_LIBDIRS
int(* amxrt_arg_fn_t)(amxc_var_t *config, int arg_id, const char *value)
#define AMXRT_COPT_DUMP_CONFIG
#define AMXRT_COPT_PRIORITY
#define AMXRT_COPT_DUMP_CAPS
#define AMXRT_COPT_REQUIRES
#define AMXRT_COPT_AUTO_DETECT
#define AMXRT_COPT_AUTO_CONNECT
#define AMXRT_COPT_DAEMON
#define AMXRT_COPT_INCDIRS
void amxrt_cmd_line_add_default_options(void)
static void amxrt_cmd_line_free_option(amxc_llist_it_t *it)
static int amxrt_cmd_line_default(amxc_var_t *config, int arg_id, const char *value)
PRIVATE amxrt_t * amxrt_get(void)
PRIVATE void amxrt_print_error(const char *fmt,...)
PRIVATE void amxrt_print_help(void)
void amxrt_cmd_line_parse_assignment(const char *option, bool force)
Parses an command line option or an argument with an assignment.
int amxrt_cmd_line_add_option(int id, char short_option, const char *long_option, int has_args, const char *doc, const char *arg_doc)
Adds a command line option definition.
int amxrt_cmd_line_parse(int argc, char *argv[], amxrt_arg_fn_t fn)
Starts parsing the command line options.
void amxrt_cmd_line_set_usage_doc(const char *usage)
Set the overall usage documentation string.
void amxrt_cmd_line_options_reset(void)
Removes all default options.
void amxrt_print_usage(void)
Prints the usage information and all available options to stdout.
amxc_var_t * amxrt_get_config(void)
Gets the htable variant containing the configuration options.
amxc_llist_t cmd_line_args
amxc_var_t forced_options