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