![]() |
The ROme OpTimistic Simulator
3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
|
Command line option parser. More...
#include <core/arg_parse.h>
#include <mm/mm.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
Go to the source code of this file.
Macros | |
#define | SCREEN_LENGTH 80 |
Expected length of the terminal expressed in monospace characters width. | |
#define | HELP_INDENT 6 |
Number of spaces to indent the --help entries. | |
#define | HELP_OPT_LEN_MIN 20 |
Minimum indentation of the documentation strings in the --help entries. | |
#define | HELP_OPT_LEN_MAX 26 |
Maximum indentation of the documentation strings in the --help entries. | |
#define | HELP_SPACES_MIN 3 |
Minimum spaces between the option and its documentation in the --help text. | |
#define | USAGE_INDENT 11 |
Number of spaces to indent the --usage text. | |
Enumerations | |
enum | internal_opt_key { AP_HELP = AP_KEY_FINI + 1, AP_USAGE, AP_VERSION } |
The keys used in the internal struct ap_option to handle base options. More... | |
Functions | |
static int | cmp_opts (const void *a, const void *b) |
Compares two ap_option structs alphabetically. More... | |
static int | cmp_sects (const void *a, const void *b) |
Compares two ap_section structs (used to reorder sections alphabetically) More... | |
static void | print_indented_string (const char *str, int curr_i, int indent) |
Prints a string in the terminal indenting it and wrapping it. More... | |
static void | print_help_option (const char *name, const char *arg, const char *doc) |
Prints the help text for a single option. More... | |
static void | print_help (void) |
Prints the help text for the whole argument parsing context. | |
static int | print_usage_option (const char *name, const char *arg, int curr_i) |
Prints the help text for a single option. More... | |
static void | print_usage (void) |
Prints the usage text for the whole argument parsing context. | |
static void | internal_opt_parse (int key, const char *arg) |
The parsing function for the internal options (–help, –usage, –version) More... | |
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 struct is also injected. | |
static void | undo_setup_settings (void) |
Undos the injection of the internal ap_section struct. | |
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. More... | |
static int | process_option (const char *o_name, const char *arg) |
Parses a single option by calling the appropriate parser or throwing an error. More... | |
void | arg_parse_run (struct ap_settings *ap_s, char **argv) |
Parses the command line options. More... | |
const char * | arg_parse_program_name (void) |
Gets the program name. More... | |
void | arg_parse_error (const char *fmt,...) |
Prints a parsing related error message and exits with a bad exit code. More... | |
Variables | |
static const char * | ap_pname |
The program name extracted from the command line. | |
static const struct ap_settings * | ap_settings |
The currently parsed struct ap_settings. | |
static struct ap_option | ap_internal_opts [] |
The internal struct ap_option used to handle base options. More... | |
Command line option parser.
A command line option parser mimicking a subset of GNU argp features.
Definition in file arg_parse.c.
enum internal_opt_key |
The keys used in the internal struct ap_option to handle base options.
Enumerator | |
---|---|
AP_HELP | Identifies the --help option. |
AP_USAGE | Identifies the --usage option. |
AP_VERSION | Identifies the --version option. |
Definition at line 39 of file arg_parse.c.
void arg_parse_error | ( | const char * | fmt, |
... | |||
) |
Prints a parsing related error message and exits with a bad exit code.
fmt | the printf-style format string |
... | the arguments required to fill in the format string |
Definition at line 432 of file arg_parse.c.
const char* arg_parse_program_name | ( | void | ) |
Gets the program name.
Definition at line 422 of file arg_parse.c.
void arg_parse_run | ( | struct ap_settings * | ap_s, |
char ** | argv | ||
) |
Parses the command line options.
ap_s | the parsing settings (see struct ap_settings for more info) |
argv | the NULL terminated array of C strings from the command line |
Definition at line 382 of file arg_parse.c.
|
static |
Compares two ap_option structs alphabetically.
Definition at line 63 of file arg_parse.c.
|
static |
Compares two ap_section structs (used to reorder sections alphabetically)
a | the first ap_section to compare |
b | the second ap_section to compare |
Definition at line 76 of file arg_parse.c.
|
static |
The parsing function for the internal options (–help, –usage, –version)
key | the currently parsed key |
arg | the currently parsed argument |
Definition at line 233 of file arg_parse.c.
|
static |
Parses a single option by calling the appropriate parser or throwing an error.
s | the section of the option currently parsed |
o | the option currently parsed |
arg | the argument associated with the option (can be NULL) |
arg_explicit | a flag indicating if the argument has been supplied explicitly (with an option formatted as –option=value) |
Definition at line 306 of file arg_parse.c.
|
static |
Prints the help text for a single option.
name | the name of the option |
arg | the documentation for the argument (if present, else NULL) |
doc | the documentation for the option (if present, else NULL) |
Definition at line 131 of file arg_parse.c.
|
static |
Prints a string in the terminal indenting it and wrapping it.
str | the string to print |
curr_i | the number of characters already present in the current line of the terminal |
indent | the desired indentation level for the string express in number of spaces |
Definition at line 95 of file arg_parse.c.
|
static |
Prints the help text for a single option.
name | the name of the option |
arg | the documentation for the argument (if present, else NULL) |
curr_i | the number of characters already present in the current line of the terminal |
Definition at line 188 of file arg_parse.c.
|
static |
Parses a single option by calling the appropriate parser or throwing an error.
o_name | the option currently parsed |
arg | the argument associated with the option (can be NULL) |
Definition at line 334 of file arg_parse.c.
|
static |
The internal struct ap_option used to handle base options.
Definition at line 49 of file arg_parse.c.