@@ -11,6 +11,8 @@ Author: Daniel Kroening
11
11
12
12
#include " armcc_cmdline.h"
13
13
14
+ #include < util/optional.h>
15
+
14
16
#include < cstring>
15
17
#include < iostream>
16
18
@@ -265,18 +267,17 @@ static const char *options_with_arg[]=
265
267
nullptr
266
268
};
267
269
268
- bool prefix_in_list (const char *option, const char **list, std::string &prefix )
270
+ optionalt<std::string> prefix_in_list (const char *option, const char **list)
269
271
{
270
272
for (std::size_t i = 0 ; list[i] != nullptr ; i++)
271
273
{
272
274
if (strncmp (option, list[i], strlen (list[i])) == 0 )
273
275
{
274
- prefix = std::string (list[i]);
275
- return true ;
276
+ return {list[i]};
276
277
}
277
278
}
278
279
279
- return false ;
280
+ return {} ;
280
281
}
281
282
282
283
bool armcc_cmdlinet::parse (int argc, const char **argv)
@@ -291,35 +292,34 @@ bool armcc_cmdlinet::parse(int argc, const char **argv)
291
292
}
292
293
293
294
// it starts with - and it isn't "-"
294
-
295
- std::string prefix;
295
+ optionalt<std::string> prefix;
296
296
297
297
if (in_list (argv[i], options_no_arg))
298
298
{
299
299
// options that don't have any arguments
300
300
set (argv[i]);
301
301
}
302
- else if (prefix_in_list (argv[i], options_with_arg, prefix ))
302
+ else if ((prefix = prefix_in_list (argv[i], options_with_arg) ))
303
303
{
304
304
// options that have a separated _or_ concatenated argument
305
- if (strlen (argv[i])> prefix. size ()) // concatenated?
306
- set (prefix, std::string (argv[i], prefix. size (), std::string::npos));
305
+ if (strlen (argv[i]) > prefix-> size ()) // Concatenated.
306
+ set (* prefix, std::string (argv[i], prefix-> size (), std::string::npos));
307
307
else
308
308
{
309
309
// Separated.
310
310
if (i!=argc-1 ) // Guard against end of command line.
311
311
{
312
- set (prefix, argv[i+ 1 ]);
312
+ set (* prefix, argv[i + 1 ]);
313
313
i++;
314
314
}
315
315
else
316
- set (prefix, " " );
316
+ set (* prefix, " " );
317
317
}
318
318
}
319
- else if (prefix_in_list (argv[i], options_with_prefix, prefix ))
319
+ else if ((prefix = prefix_in_list (argv[i], options_with_prefix) ))
320
320
{
321
321
// options that have a concatenated argument
322
- set (prefix, std::string (argv[i], prefix. size (), std::string::npos));
322
+ set (* prefix, std::string (argv[i], prefix-> size (), std::string::npos));
323
323
}
324
324
else
325
325
{ // unrecognized option
0 commit comments