libamxrt  0.4.2
Ambiorix Run Time Library
amxrt_args.c File Reference
#include <stdlib.h>
#include <string.h>
#include <yajl/yajl_gen.h>
#include <amxrt/amxrt.h>
#include <amxj/amxj_variant.h>
#include "amxrt_priv.h"

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

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)
 
void amxrt_cmd_line_add_default_options (void)
 
void amxrt_cmd_line_options_reset (void)
 Removes all default options. More...
 
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. More...
 
void amxrt_cmd_line_set_usage_doc (const char *usage)
 Set the overall usage documentation string. More...
 
int amxrt_cmd_line_parse (int argc, char *argv[], amxrt_arg_fn_t fn)
 Starts parsing the command line options. More...
 
void amxrt_cmd_line_parse_assignment (const char *option, bool force)
 Parses an command line option or an argument with an assignment. More...
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 56 of file amxrt_args.c.

Function Documentation

◆ amxrt_cmd_line_add_default_options()

void amxrt_cmd_line_add_default_options ( void  )

Definition at line 178 of file amxrt_args.c.

178  {
179  amxrt_cmd_line_add_option(0, 'h', "help", no_argument, "Print usage help and exit", NULL);
180  amxrt_cmd_line_add_option(0, 'H', "HELP", no_argument, "Print extended help and exit", NULL);
181  amxrt_cmd_line_add_option(0, 'B', "backend", required_argument, "Loads the shared object as bus backend", "so file");
182  amxrt_cmd_line_add_option(0, 'u', "uri", required_argument, "Adds an uri to the list of uris", "uri");
183  amxrt_cmd_line_add_option(0, 'A', "no-auto-detect", no_argument, "Do not auto detect unix domain sockets and back-ends", NULL);
184  amxrt_cmd_line_add_option(0, 'C', "no-connect", no_argument, "Do not auto connect the provided or detected uris", 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");
187  amxrt_cmd_line_add_option(0, 'o', "option", required_argument, "Adds a configuration option", "name=value");
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");
190  amxrt_cmd_line_add_option(0, 'D', "daemon", no_argument, "Daemonize the process", NULL);
191  amxrt_cmd_line_add_option(0, 'p', "priority", required_argument, "Sets the process nice level", "nice level");
192  amxrt_cmd_line_add_option(0, 'N', "no-pid-file", no_argument, "Disables the creation of a pid-file in /var/run", NULL);
193  amxrt_cmd_line_add_option(0, 'E', "eventing", no_argument, "Enables eventing during loading of ODL files", NULL);
194  amxrt_cmd_line_add_option(0, 'd', "dump", optional_argument, "Dumps configuration options or capabilities at start-up", "[caps|config]");
195  amxrt_cmd_line_add_option(0, 'l', "log", no_argument, "Write to syslog instead of stdout and stderr", NULL);
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");
197 }
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.
Definition: amxrt_args.c:206

◆ amxrt_cmd_line_default()

static int amxrt_cmd_line_default ( amxc_var_t *  config,
int  arg_id,
const char *  value 
)
static

Definition at line 73 of file amxrt_args.c.

75  {
76  int rv = 0;
77  switch(arg_id) {
78  case 'I':
79  amxc_var_add(cstring_t, GET_ARG(config, AMXRT_COPT_INCDIRS), value);
80  break;
81 
82  case 'L':
83  amxc_var_add(cstring_t, GET_ARG(config, AMXRT_COPT_LIBDIRS), value);
84  break;
85 
86  case 'B':
87  amxc_var_add(cstring_t, GET_ARG(config, AMXRT_COPT_BACKENDS), value);
88  break;
89 
90  case 'u':
91  amxc_var_add(cstring_t, GET_ARG(config, AMXRT_COPT_URIS), value);
92  break;
93 
94  case 'A':
95  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_AUTO_DETECT), false);
96  break;
97 
98  case 'C':
99  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_AUTO_CONNECT), false);
100  break;
101 
102  case 'D':
103  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DAEMON), true);
104  break;
105 
106  case 'E':
107  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_EVENT), true);
108  break;
109 
110  case 'd':
111  if((value == NULL) || (strcmp(value, "config") == 0)) {
112  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DUMP_CONFIG), true);
113  } else if(strcmp(value, "caps") == 0) {
114  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DUMP_CAPS), true);
115  }
116  break;
117 
118  case 'p':
119  amxc_var_set(int32_t, GET_ARG(config, AMXRT_COPT_PRIORITY), atoi(value));
120  break;
121 
122  case 'N':
123  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_PID_FILE), false);
124  break;
125 
126  case 'O':
127  amxc_var_add_key(cstring_t, config, AMXRT_COPT_ODL, value);
128  break;
129 
130  case 'l':
131  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_LOG), true);
132  break;
133 
134  case 'R':
135  amxc_var_add(cstring_t, GET_ARG(config, AMXRT_COPT_REQUIRES), value);
136  break;
137 
138  case 'o':
139  amxrt_cmd_line_parse_assignment(value, false);
140  break;
141 
142  case 'F':
143  amxrt_cmd_line_parse_assignment(value, true);
144  break;
145 
146 
147  case 'h': {
149  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DUMP_CONFIG), false);
150  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DUMP_CAPS), false);
151  rv = -1;
152  }
153  break;
154 
155  case 'H': {
157  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DUMP_CONFIG), false);
158  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DUMP_CAPS), false);
159  rv = -1;
160  }
161  break;
162 
163  default: {
164  amxrt_print_error("Argument not recognized - %d", arg_id);
166  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DUMP_CONFIG), false);
167  amxc_var_set(bool, GET_ARG(config, AMXRT_COPT_DUMP_CAPS), false);
168  rv = -1;
169  }
170  break;
171 
172  }
173 
174  return rv;
175 }
#define AMXRT_COPT_BACKENDS
Definition: amxrt.h:75
#define AMXRT_COPT_URIS
Definition: amxrt.h:73
#define AMXRT_COPT_PID_FILE
Definition: amxrt.h:84
#define AMXRT_COPT_ODL
Definition: amxrt.h:81
#define AMXRT_COPT_LIBDIRS
Definition: amxrt.h:79
#define AMXRT_COPT_DUMP_CONFIG
Definition: amxrt.h:91
#define AMXRT_COPT_PRIORITY
Definition: amxrt.h:83
#define AMXRT_COPT_DUMP_CAPS
Definition: amxrt.h:92
#define AMXRT_COPT_REQUIRES
Definition: amxrt.h:99
#define AMXRT_COPT_EVENT
Definition: amxrt.h:90
#define AMXRT_COPT_AUTO_DETECT
Definition: amxrt.h:76
#define AMXRT_COPT_LOG
Definition: amxrt.h:98
#define AMXRT_COPT_AUTO_CONNECT
Definition: amxrt.h:77
#define AMXRT_COPT_DAEMON
Definition: amxrt.h:82
#define AMXRT_COPT_INCDIRS
Definition: amxrt.h:78
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.
Definition: amxrt_args.c:296
void amxrt_print_usage(void)
Prints the usage information and all available options to stdout.
config
Definition: test.odl:54

◆ amxrt_cmd_line_free_option()

static void amxrt_cmd_line_free_option ( amxc_llist_it_t *  it)
static

Definition at line 68 of file amxrt_args.c.

68  {
69  amxrt_arg_t* option = amxc_container_of(it, amxrt_arg_t, it);
70  free(option);
71 }