Flowgrind
Advanced TCP traffic generator
fg_argparser.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2014 Felix Rietig <felix.rietig@rwth-aachen.de>
8  * Copyright (C) 2006-2013 Antonio Diaz Diaz <antonio@gnu.org>
9  *
10  * This file is part of Flowgrind. It is based on the POSIX/GNU
11  * command line argument parser 'arg_parser' origninally written by
12  * Antonio Diaz Diaz.
13  *
14  * Flowgrind is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * Flowgrind is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with Flowgrind. If not, see <http://www.gnu.org/licenses/>.
26  *
27  */
28 
29 #ifndef _ARG_PARSER_H_
30 #define _ARG_PARSER_H_
31 
32 #include <stdbool.h>
33 
35 enum ap_Has_arg {
37  ap_no = 0,
42 };
43 
45 struct ap_Option {
47  int code;
49  char *name;
53  int tag;
59  int *mutex;
60 };
61 
63 struct ap_Record {
65  char *opt_string;
67  char *argument;
70 };
71 
73 struct arg_parser {
75  struct ap_Option *options;
77  struct ap_Record *data;
79  char *error;
83  int data_size;
87  int num_mutex;
88 };
89 
95  int num_mutex;
96 };
97 
111 bool ap_init(struct arg_parser *const ap,
112  const int argc, const char *const argv[],
113  const struct ap_Option options[], const char in_order);
114 
120 void ap_free(struct arg_parser *const ap);
121 
129 const char *ap_error(const struct arg_parser *const ap);
130 
137 int ap_arguments(const struct arg_parser *const ap);
138 
147 int ap_code(const struct arg_parser *const ap, const int i);
148 
157 const char *ap_argument(const struct arg_parser *const ap, const int i);
158 
166 const struct ap_Option *ap_option(const struct arg_parser *const ap, const int i);
167 
175 const char *ap_opt_string(const struct arg_parser *const ap, const int i);
176 
185 bool ap_is_used(const struct arg_parser *const ap, int code);
186 
199 bool ap_init_mutex_state(const struct arg_parser *const ap,
200  struct ap_Mutex_state *const ms);
201 
214 bool ap_check_mutex(const struct arg_parser *const ap,
215  const struct ap_Mutex_state *const ms,
216  const int i, int *conflict);
217 
226 bool ap_set_mutex(const struct arg_parser *const ap,
227  struct ap_Mutex_state *const ms, const int i);
228 
240 bool ap_set_check_mutex(const struct arg_parser *const ap,
241  struct ap_Mutex_state *const ms,
242  const int i, int *conflict);
243 
249 void ap_reset_mutex(struct ap_Mutex_state *const ms);
250 
256 void ap_free_mutex_state(struct ap_Mutex_state *const ms);
257 
258 #endif /* _ARG_PARSER_H_ */
arg_parser::error_size
int error_size
Real size of the error string.
Definition: fg_argparser.h:85
ap_Mutex_state::seen_records
int * seen_records
A table containing for each mutex the last seen option record.
Definition: fg_argparser.h:93
arg_parser
Internal state of the argument parser.
Definition: fg_argparser.h:73
ap_Has_arg
ap_Has_arg
Specifies whether a command line option needs an argument.
Definition: fg_argparser.h:35
ap_no
@ ap_no
Option without argument (flag).
Definition: fg_argparser.h:37
ap_Option::mutex
int * mutex
Null-terminated array of mutex IDs (greater zero) this option belongs to.
Definition: fg_argparser.h:59
ap_option
const struct ap_Option * ap_option(const struct arg_parser *const ap, const int i)
Get the user-defined option for a given record position.
Definition: fg_argparser.c:494
arg_parser::num_mutex
int num_mutex
The number of defined mutex.
Definition: fg_argparser.h:87
ap_set_check_mutex
bool ap_set_check_mutex(const struct arg_parser *const ap, struct ap_Mutex_state *const ms, const int i, int *conflict)
Check a new option record for mutex and register it at the same time.
Definition: fg_argparser.c:569
ap_Option::has_arg
enum ap_Has_arg has_arg
Argument specifier.
Definition: fg_argparser.h:51
ap_init
bool ap_init(struct arg_parser *const ap, const int argc, const char *const argv[], const struct ap_Option options[], const char in_order)
Initialize the arg-parser given command line and user-defined options.
Definition: fg_argparser.c:374
ap_code
int ap_code(const struct arg_parser *const ap, const int i)
Returns the code of a parsed option with given index.
Definition: fg_argparser.c:468
arg_parser::data
struct ap_Record * data
Container for parsed cmdline options.
Definition: fg_argparser.h:77
ap_yes
@ ap_yes
Argument required.
Definition: fg_argparser.h:39
ap_Mutex_state
Contains the state of all mutex.
Definition: fg_argparser.h:91
ap_Option::code
int code
Short option letter or code (code != 0).
Definition: fg_argparser.h:47
arg_parser::data_size
int data_size
Number of parsed records.
Definition: fg_argparser.h:83
ap_reset_mutex
void ap_reset_mutex(struct ap_Mutex_state *const ms)
Reset a mutex context.
Definition: fg_argparser.c:578
ap_Option::tag
int tag
User tag for distinction of options.
Definition: fg_argparser.h:53
arg_parser::num_options
int num_options
Number of known options.
Definition: fg_argparser.h:81
ap_is_used
bool ap_is_used(const struct arg_parser *const ap, int code)
Returns true if the option specified by code was given at least once.
Definition: fg_argparser.c:503
ap_free_mutex_state
void ap_free_mutex_state(struct ap_Mutex_state *const ms)
Free a mutex context.
Definition: fg_argparser.c:583
ap_error
const char * ap_error(const struct arg_parser *const ap)
Get the string containing errors encountered during parsing.
Definition: fg_argparser.c:458
ap_Record::argument
char * argument
Argument string (may be empty).
Definition: fg_argparser.h:67
ap_opt_string
const char * ap_opt_string(const struct arg_parser *const ap, const int i)
Get the real command line option string (may be the short or long version).
Definition: fg_argparser.c:486
ap_Option
Defines a valid command line option.
Definition: fg_argparser.h:45
arg_parser::error
char * error
Contains errors encountered during parsing.
Definition: fg_argparser.h:79
ap_Option::name
char * name
Long option name (maybe null).
Definition: fg_argparser.h:49
ap_init_mutex_state
bool ap_init_mutex_state(const struct arg_parser *const ap, struct ap_Mutex_state *const ms)
Initialize a new mutex state table.
Definition: fg_argparser.c:516
ap_argument
const char * ap_argument(const struct arg_parser *const ap, const int i)
Returns the argument of a parsed option.
Definition: fg_argparser.c:478
ap_free
void ap_free(struct arg_parser *const ap)
Free internal state of arg-parser.
Definition: fg_argparser.c:448
ap_Record::option_index
int option_index
Index of the option for internal use (e.g.
Definition: fg_argparser.h:69
ap_maybe
@ ap_maybe
Optional Argument.
Definition: fg_argparser.h:41
ap_Mutex_state::num_mutex
int num_mutex
The number of defined mutex.
Definition: fg_argparser.h:95
ap_set_mutex
bool ap_set_mutex(const struct arg_parser *const ap, struct ap_Mutex_state *const ms, const int i)
Register an option record in a mutex context.
Definition: fg_argparser.c:553
arg_parser::options
struct ap_Option * options
Array containing user-defined options.
Definition: fg_argparser.h:75
ap_check_mutex
bool ap_check_mutex(const struct arg_parser *const ap, const struct ap_Mutex_state *const ms, const int i, int *conflict)
Check a new option record for mutex.
Definition: fg_argparser.c:527
ap_Record::opt_string
char * opt_string
Observed opt string (maybe the long or the short version).
Definition: fg_argparser.h:65
ap_Record
Holds a parsed command line option and its argument.
Definition: fg_argparser.h:63
ap_arguments
int ap_arguments(const struct arg_parser *const ap)
Number of arguments parsed (may be different from argc).
Definition: fg_argparser.c:463