13
13
#define CONFIG_LOGGER "config"
14
14
15
15
static logger_id_t logger_id ;
16
+ // FIXME: We need further improvements without depending on temporary variables
17
+ static int tmp_argc ;
16
18
17
19
int get_conf_key (char const * const key ) {
18
20
for (int i = 0 ; i < cli_cmd_num ; ++ i ) {
@@ -24,6 +26,19 @@ int get_conf_key(char const* const key) {
24
26
return 0 ;
25
27
}
26
28
29
+ static void remove_nonvalue_dash (int argc , char * * argv ) {
30
+ for (int i = 1 ; i < argc ; i ++ ) {
31
+ if ((strlen (argv [i ]) == 2 ) && (!strncmp (argv [i ], "--" , 2 ))) {
32
+ argc -- ;
33
+ if (argc == (i + 1 )) {
34
+ break ;
35
+ }
36
+ memmove (argv + i , argv + (i + 1 ), (argc - i ) * sizeof (char * ));
37
+ }
38
+ }
39
+ tmp_argc = argc ;
40
+ }
41
+
27
42
struct option * cli_build_options () {
28
43
struct option * long_options = (struct option * )malloc (cli_cmd_num * sizeof (struct option ));
29
44
for (int i = 0 ; i < cli_cmd_num ; ++ i ) {
@@ -190,6 +205,9 @@ status_t ta_core_file_init(ta_core_t* const core, int argc, char** argv) {
190
205
goto done ;
191
206
}
192
207
208
+ // remove `--` from argv
209
+ remove_nonvalue_dash (argc , argv );
210
+
193
211
// Loop through the CLI arguments for first time to find the configuration file path
194
212
while ((key = getopt_long (argc , argv , "hv" , long_options , NULL )) != -1 ) {
195
213
switch (key ) {
@@ -277,7 +295,10 @@ status_t ta_core_cli_init(ta_core_t* const core, int argc, char** argv) {
277
295
status_t ret = SC_OK ;
278
296
struct option * long_options = cli_build_options ();
279
297
280
- while ((key = getopt_long (argc , argv , "hv" , long_options , NULL )) != -1 ) {
298
+ // remove `--` from argv
299
+ remove_nonvalue_dash (tmp_argc , argv );
300
+
301
+ while ((key = getopt_long (tmp_argc , argv , "hv" , long_options , NULL )) != -1 ) {
281
302
switch (key ) {
282
303
case ':' :
283
304
ret = SC_CONF_MISSING_ARGUMENT ;
0 commit comments