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_ */
int * seen_records
A table containing for each mutex the last seen option record.
Definition: fg_argparser.h:93
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
int * mutex
Null-terminated array of mutex IDs (greater zero) this option belongs to.
Definition: fg_argparser.h:59
char * opt_string
Observed opt string (maybe the long or the short version).
Definition: fg_argparser.h:65
Option without argument (flag).
Definition: fg_argparser.h:37
int num_options
Number of known options.
Definition: fg_argparser.h:81
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
int num_mutex
The number of defined mutex.
Definition: fg_argparser.h:87
Defines a valid command line option.
Definition: fg_argparser.h:45
int tag
User tag for distinction of options.
Definition: fg_argparser.h:53
ap_Has_arg
Specifies whether a command line option needs an argument.
Definition: fg_argparser.h:35
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
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
void ap_free_mutex_state(struct ap_Mutex_state *const ms)
Free a mutex context.
Definition: fg_argparser.c:583
enum ap_Has_arg has_arg
Argument specifier.
Definition: fg_argparser.h:51
const char * ap_error(const struct arg_parser *const ap)
Get the string containing errors encountered during parsing.
Definition: fg_argparser.c:458
char * error
Contains errors encountered during parsing.
Definition: fg_argparser.h:79
void ap_reset_mutex(struct ap_Mutex_state *const ms)
Reset a mutex context.
Definition: fg_argparser.c:578
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
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
int error_size
Real size of the error string.
Definition: fg_argparser.h:85
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
Holds a parsed command line option and its argument.
Definition: fg_argparser.h:63
int data_size
Number of parsed records.
Definition: fg_argparser.h:83
int code
Short option letter or code (code != 0).
Definition: fg_argparser.h:47
void ap_free(struct arg_parser *const ap)
Free internal state of arg-parser.
Definition: fg_argparser.c:448
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
Optional Argument.
Definition: fg_argparser.h:41
char * argument
Argument string (may be empty).
Definition: fg_argparser.h:67
Argument required.
Definition: fg_argparser.h:39
Contains the state of all mutex.
Definition: fg_argparser.h:91
Internal state of the argument parser.
Definition: fg_argparser.h:73
struct ap_Option * options
Array containing user-defined options.
Definition: fg_argparser.h:75
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
char * name
Long option name (maybe null).
Definition: fg_argparser.h:49
int option_index
Index of the option for internal use (e.g.
Definition: fg_argparser.h:69
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
int num_mutex
The number of defined mutex.
Definition: fg_argparser.h:95
struct ap_Record * data
Container for parsed cmdline options.
Definition: fg_argparser.h:77
int ap_arguments(const struct arg_parser *const ap)
Number of arguments parsed (may be different from argc).
Definition: fg_argparser.c:463