@@ -27,25 +27,21 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
27
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
28
*/
29
29
30
+ #include "args.h"
31
+
30
32
#include <assert.h>
31
- #include <string.h>
32
33
#include <stdlib.h>
33
-
34
+ #include <string.h>
34
35
#include <yara.h>
35
36
36
- #include "args.h"
37
-
38
- #define args_is_long_arg (arg ) \
39
- (arg[0] == '-' && arg[1] == '-' && arg[2] != '\0')
37
+ #define args_is_long_arg (arg ) (arg[0] == '-' && arg[1] == '-' && arg[2] != '\0')
40
38
41
39
42
- #define args_is_short_arg (arg ) \
43
- (arg[0] == '-' && arg[1] != '-' && arg[1] != '\0')
40
+ #define args_is_short_arg (arg ) \
41
+ (arg[0] == '-' && arg[1] != '-' && arg[1] != '\0')
44
42
45
43
46
- args_option_t * args_get_short_option (
47
- args_option_t * options ,
48
- const char opt )
44
+ args_option_t * args_get_short_option (args_option_t * options , const char opt )
49
45
{
50
46
while (options -> type != ARGS_OPT_END )
51
47
{
@@ -59,11 +55,9 @@ args_option_t* args_get_short_option(
59
55
}
60
56
61
57
62
- args_option_t * args_get_long_option (
63
- args_option_t * options ,
64
- const char * arg )
58
+ args_option_t * args_get_long_option (args_option_t * options , const char * arg )
65
59
{
66
- arg += 2 ; // skip starting --
60
+ arg += 2 ; // skip starting --
67
61
68
62
while (options -> type != ARGS_OPT_END )
69
63
{
@@ -90,52 +84,52 @@ args_error_type_t args_parse_option(
90
84
const char * opt_arg ,
91
85
int * opt_arg_was_used )
92
86
{
93
- char * endptr = NULL ;
87
+ char * endptr = NULL ;
94
88
95
89
if (opt_arg_was_used != NULL )
96
- * opt_arg_was_used = 0 ;
90
+ * opt_arg_was_used = 0 ;
97
91
98
92
if (opt -> count == opt -> max_count )
99
93
return ARGS_ERROR_TOO_MANY ;
100
94
101
95
switch (opt -> type )
102
96
{
103
- case ARGS_OPT_BOOLEAN :
104
- * (bool * ) opt -> value = !(* (bool * ) opt -> value );
105
- break ;
97
+ case ARGS_OPT_BOOLEAN :
98
+ * (bool * ) opt -> value = !(* (bool * ) opt -> value );
99
+ break ;
106
100
107
- case ARGS_OPT_INTEGER :
101
+ case ARGS_OPT_INTEGER :
108
102
109
- if (opt_arg == NULL )
110
- return ARGS_ERROR_REQUIRED_INTEGER_ARG ;
103
+ if (opt_arg == NULL )
104
+ return ARGS_ERROR_REQUIRED_INTEGER_ARG ;
111
105
112
- * (int * ) opt -> value = strtol (opt_arg , & endptr , 0 );
106
+ * (int * ) opt -> value = strtol (opt_arg , & endptr , 0 );
113
107
114
- if (* endptr != '\0' )
115
- return ARGS_ERROR_REQUIRED_INTEGER_ARG ;
108
+ if (* endptr != '\0' )
109
+ return ARGS_ERROR_REQUIRED_INTEGER_ARG ;
116
110
117
- if (opt_arg_was_used != NULL )
118
- * opt_arg_was_used = 1 ;
111
+ if (opt_arg_was_used != NULL )
112
+ * opt_arg_was_used = 1 ;
119
113
120
- break ;
114
+ break ;
121
115
122
- case ARGS_OPT_STRING :
116
+ case ARGS_OPT_STRING :
123
117
124
- if (opt_arg == NULL )
125
- return ARGS_ERROR_REQUIRED_STRING_ARG ;
118
+ if (opt_arg == NULL )
119
+ return ARGS_ERROR_REQUIRED_STRING_ARG ;
126
120
127
- if (opt -> max_count > 1 )
128
- ((const char * * )opt -> value )[opt -> count ] = opt_arg ;
129
- else
130
- * (const char * * ) opt -> value = opt_arg ;
121
+ if (opt -> max_count > 1 )
122
+ ((const char * * ) opt -> value )[opt -> count ] = opt_arg ;
123
+ else
124
+ * (const char * * ) opt -> value = opt_arg ;
131
125
132
- if (opt_arg_was_used != NULL )
133
- * opt_arg_was_used = 1 ;
126
+ if (opt_arg_was_used != NULL )
127
+ * opt_arg_was_used = 1 ;
134
128
135
- break ;
129
+ break ;
136
130
137
- default :
138
- assert (0 );
131
+ default :
132
+ assert (0 );
139
133
}
140
134
141
135
opt -> count ++ ;
@@ -144,37 +138,32 @@ args_error_type_t args_parse_option(
144
138
}
145
139
146
140
147
- void args_print_error (
148
- args_error_type_t error ,
149
- const char * option )
141
+ void args_print_error (args_error_type_t error , const char * option )
150
142
{
151
- switch (error )
143
+ switch (error )
152
144
{
153
- case ARGS_ERROR_UNKNOWN_OPT :
154
- fprintf (stderr , "unknown option `%s`\n" , option );
155
- break ;
156
- case ARGS_ERROR_TOO_MANY :
157
- fprintf (stderr , "too many `%s` options\n" , option );
158
- break ;
159
- case ARGS_ERROR_REQUIRED_INTEGER_ARG :
160
- fprintf (stderr , "option `%s` requires an integer argument\n" , option );
161
- break ;
162
- case ARGS_ERROR_REQUIRED_STRING_ARG :
163
- fprintf (stderr , "option `%s` requires a string argument\n" , option );
164
- break ;
165
- case ARGS_ERROR_UNEXPECTED_ARG :
166
- fprintf (stderr , "option `%s` doesn't expect an argument\n" , option );
167
- break ;
168
- default :
169
- return ;
145
+ case ARGS_ERROR_UNKNOWN_OPT :
146
+ fprintf (stderr , "unknown option `%s`\n" , option );
147
+ break ;
148
+ case ARGS_ERROR_TOO_MANY :
149
+ fprintf (stderr , "too many `%s` options\n" , option );
150
+ break ;
151
+ case ARGS_ERROR_REQUIRED_INTEGER_ARG :
152
+ fprintf (stderr , "option `%s` requires an integer argument\n" , option );
153
+ break ;
154
+ case ARGS_ERROR_REQUIRED_STRING_ARG :
155
+ fprintf (stderr , "option `%s` requires a string argument\n" , option );
156
+ break ;
157
+ case ARGS_ERROR_UNEXPECTED_ARG :
158
+ fprintf (stderr , "option `%s` doesn't expect an argument\n" , option );
159
+ break ;
160
+ default :
161
+ return ;
170
162
}
171
163
}
172
164
173
165
174
- int args_parse (
175
- args_option_t * options ,
176
- int argc ,
177
- const char * * argv )
166
+ int args_parse (args_option_t * options , int argc , const char * * argv )
178
167
{
179
168
args_error_type_t error = ARGS_ERROR_OK ;
180
169
@@ -257,9 +246,7 @@ int args_parse(
257
246
}
258
247
259
248
260
- void args_print_usage (
261
- args_option_t * options ,
262
- int help_alignment )
249
+ void args_print_usage (args_option_t * options , int help_alignment )
263
250
{
264
251
char buffer [128 ];
265
252
@@ -278,8 +265,7 @@ void args_print_usage(
278
265
if (options -> long_name != NULL )
279
266
len += sprintf (buffer + len , "--%s" , options -> long_name );
280
267
281
- if (options -> type == ARGS_OPT_STRING ||
282
- options -> type == ARGS_OPT_INTEGER )
268
+ if (options -> type == ARGS_OPT_STRING || options -> type == ARGS_OPT_INTEGER )
283
269
{
284
270
len += sprintf (
285
271
buffer + len ,
0 commit comments