MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / parse

Method parse

src/apputils/argparse.cpp:319–363  ·  view source on GitHub ↗

Top level command line parsing function called after all options have been parsed and created from the format strings. This function parses the command line (argc,argv) stored internally in the constructor. Each command line argument is parsed and checked to see if it matches an existing option. If there is no match, and error is reported and the function returns early. If there is a match, all

Source from the content-addressed store, hash-verified

317// function returns early. If there is a match, all the arguments for
318// that option are parsed and the associated variables are set.
319int
320ArgParse::parse (int xargc, const char **xargv)
321{
322 m_argc = xargc;
323 m_argv = xargv;
324
325 for (int i = 1; i < m_argc; i++) {
326 if (m_argv[i][0] == '-' &&
327 (isalpha (m_argv[i][1]) || m_argv[i][1] == '-')) { // flag
328 ArgOption *option = find_option (m_argv[i]);
329 if (option == NULL) {
330 error ("Invalid option \"%s\"", m_argv[i]);
331 return -1;
332 }
333
334 option->found_on_command_line();
335
336 if (option->is_flag()) {
337 option->set_parameter(0, NULL);
338 } else {
339 assert (option->is_regular());
340 for (int j = 0; j < option->parameter_count(); j++) {
341 if (j+i+1 >= m_argc) {
342 error ("Missing parameter %d from option "
343 "\"%s\"", j+1, option->name().c_str());
344 return -1;
345 }
346 option->set_parameter (j, m_argv[i+j+1]);
347 }
348 i += option->parameter_count();
349 }
350 } else {
351 // not an option nor an option parameter, glob onto global list
352 if (m_global)
353 m_global->invoke_callback (1, m_argv+i);
354 else {
355 error ("Argument \"%s\" does not have an associated "
356 "option", m_argv[i]);
357 return -1;
358 }
359 }
360 }
361
362 return 0;
363}
364
365
366

Callers 15

build_ctfFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
extract_docstringsFunction · 0.45

Calls 6

found_on_command_lineMethod · 0.80
is_flagMethod · 0.80
set_parameterMethod · 0.80
is_regularMethod · 0.80
parameter_countMethod · 0.80
invoke_callbackMethod · 0.45

Tested by 4

mainFunction · 0.36
UnitTestMainFunction · 0.36
mainFunction · 0.36
OCIO_ADD_TESTFunction · 0.36