 |
The ROme OpTimistic Simulator
3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
|
Go to the documentation of this file.
21 #define SCREEN_LENGTH 80
24 #define HELP_OPT_LEN_MIN 20
26 #define HELP_OPT_LEN_MAX 26
28 #define HELP_SPACES_MIN 3
30 #define USAGE_INDENT 11
50 {
"help",
AP_HELP, NULL,
"Give this help list"},
51 {
"usage",
AP_USAGE, NULL,
"Give a short usage message"},
52 {
"version",
AP_VERSION, NULL,
"Print program version"},
63 static int cmp_opts (
const void *a,
const void *b)
66 return strcmp(oa->
name, ob->name);
80 if (oa->
header == NULL || ob->header == NULL) {
81 return (ob->header == NULL) - (oa->
header == NULL);
84 return strcmp(oa->
header, ob->header);
100 while (*p && !isspace(*p)) ++p;
104 printf(
"\n%*c", indent,
' ');
107 printf(
"%.*s", l, str);
110 while(*p && isspace(*p)) {
112 printf(
"\n%*c", indent,
' ');
134 name, arg ?
"=" :
"", arg ? arg :
"");
138 printf(
"\n%*c", l,
' ');
169 printf(
" %s\n", s->
header);
173 }
while ((++o)->
name);
190 int l = snprintf(NULL, 0,
" [--%s%s%s]",
name,
210 int curr_i = printf(
"Usage: %s",
ap_pname);
259 size_t sects_cnt = 0;
261 while (s[sects_cnt].
opts) {
266 while (o[opts_cnt].
name) {
278 s[sects_cnt].
header = NULL;
307 const char *arg,
bool arg_explicit)
312 if (arg && !o->
arg) {
315 "option '--%s' does not require an argument", o->
name);
316 else if (arg[0] !=
'-')
324 return arg != NULL && !arg_explicit;
346 while(o_name[i] && o->
name[i] == o_name[i])
349 if (o_name[i] == o->
name[i])
365 if (!max_s || (o_name[max_s] && o_name[max_s] !=
'='))
371 if (o_name[max_s] ==
'=')
372 return parse_option(cand_s, cand_o, &o_name[max_s + 1],
true);
398 const char *str = *argv;
438 vfprintf(stderr, fmt, args);
442 "\nTry `%s --help' or `%s --usage' for more information.\n",
const char * header
The header printed before this section in the --help text.
@ AP_VERSION
Identifies the --version option.
static int print_usage_option(const char *name, const char *arg, int curr_i)
Prints the help text for a single option.
static const char * ap_pname
The program name extracted from the command line.
const char * arg
The argument name for this option, shown in the --usage text.
const char * prog_doc
A description of the program.
@ AP_HELP
Identifies the --help option.
@ AP_USAGE
Identifies the --usage option.
A single parsable command line option.
static int process_option(const char *o_name, const char *arg)
Parses a single option by calling the appropriate parser or throwing an error.
static int cmp_opts(const void *a, const void *b)
Compares two ap_option structs alphabetically.
@ AP_KEY_INIT
Signals the start of the parsing process.
const char * doc
The documentation of this option, shown in the --help text.
A set of options organized and parsed together.
internal_opt_key
The keys used in the internal struct ap_option to handle base options.
static void sort_and_setup_settings(void)
Sets up the ap_section structs and their ap_option structs by sorting them. The internal ap_section s...
int key
The key passed to the parsing function when encountering this option.
@ AP_KEY_FINI
Signals the end of the parsing process.
A complete command line option parsing setup.
static void print_help(void)
Prints the help text for the whole argument parsing context.
void arg_parse_run(struct ap_settings *ap_s, char **argv)
Parses the command line options.
#define SCREEN_LENGTH
Expected length of the terminal expressed in monospace characters width.
static void undo_setup_settings(void)
Undos the injection of the internal ap_section struct.
static void print_help_option(const char *name, const char *arg, const char *doc)
Prints the help text for a single option.
static int parse_option(struct ap_section *s, struct ap_option *o, const char *arg, bool arg_explicit)
Parses a single option by calling the appropriate parser or throwing an error.
const char * prog_version
A description of the program version.
static struct ap_option ap_internal_opts[]
The internal struct ap_option used to handle base options.
#define HELP_OPT_LEN_MAX
Maximum indentation of the documentation strings in the --help entries.
static void print_usage(void)
Prints the usage text for the whole argument parsing context.
#define HELP_OPT_LEN_MIN
Minimum indentation of the documentation strings in the --help entries.
static void print_indented_string(const char *str, int curr_i, int indent)
Prints a string in the terminal indenting it and wrapping it.
#define HELP_SPACES_MIN
Minimum spaces between the option and its documentation in the --help text.
Command line option parser.
const char * name
The long option name.
const char * prog_report
The email address of the maintainer.
#define USAGE_INDENT
Number of spaces to indent the --usage text.
static const struct ap_settings * ap_settings
The currently parsed struct ap_settings.
static int cmp_sects(const void *a, const void *b)
Compares two ap_section structs (used to reorder sections alphabetically)
const char * arg_parse_program_name(void)
Gets the program name.
void arg_parse_error(const char *fmt,...)
Prints a parsing related error message and exits with a bad exit code.
struct ap_section * sects
The array of supported sections, terminated by a zeroed element.
struct ap_option * opts
The array of recognized options, terminated by a zeroed element.
static void internal_opt_parse(int key, const char *arg)
The parsing function for the internal options (–help, –usage, –version)
#define HELP_INDENT
Number of spaces to indent the --help entries.
Memory Manager main header.
void(* parser)(int key, const char *arg)
The parsing function.