MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / parse

Method parse

src/base/program_options.cpp:58–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58void ProgramOptions::parse(int argc, const char* argv[])
59{
60 for (int i=1; i<argc; ++i) {
61 string arg(argv[i]);
62
63 // n = number of dashes ('-') at the beginning of the argument.
64 size_t n = 0;
65 for (; arg[n] == '-'; ++n)
66 ;
67 size_t len = arg.size()-n;
68
69 // Ignore process serial number argument (-psn...) when the app is run from command line
70#if __APPLE__
71 if (arg.size() >= 4 && arg.substr(0, 4) == "-psn")
72 continue;
73#endif
74
75 if ((n > 0) && (len > 0)) {
76 // Use mnemonics
77 if (n == 1) {
78 char usedBy = 0;
79
80 for (size_t j=1; j<arg.size(); ++j) {
81 OptionList::iterator it =
82 find_if(m_options.begin(), m_options.end(), same_mnemonic(arg[j]));
83
84 if (it == m_options.end()) {
85 stringstream msg;
86 msg << "Invalid option '-" << arg[j] << "'";
87 throw InvalidProgramOption(msg.str());
88 }
89
90 Option* option = *it;
91 std::string optionValue;
92
93 if (option->doesRequireValue()) {
94 if (usedBy != 0) {
95 stringstream msg;
96 msg << "You cannot use '-" << option->mnemonic()
97 << "' and '-" << usedBy << "' "
98 << "together, both options need one extra argument";
99 throw InvalidProgramOptionsCombination(msg.str());
100 }
101
102 if (i+1 >= argc) {
103 stringstream msg;
104 msg << "Option '-" << option->mnemonic()
105 << "' needs one extra argument";
106 throw ProgramOptionNeedsValue(msg.str());
107 }
108
109 // Set the value specified for this argument
110 optionValue = argv[++i];
111 usedBy = option->mnemonic();
112 }
113
114 m_values.push_back(Value(option, optionValue));
115 }

Callers 10

getJSONFunction · 0.80
postJSONFunction · 0.80
pingFunction · 0.80
AIFunction · 0.80
ai.jsFile · 0.80
TESTFunction · 0.80
runFunction · 0.80
AppOptionsMethod · 0.80
cfgwriteFunction · 0.80
thread_initFunction · 0.80

Calls 12

same_mnemonicClass · 0.85
same_nameClass · 0.85
doesRequireValueMethod · 0.80
mnemonicMethod · 0.80
ValueClass · 0.70
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
strMethod · 0.45

Tested by 1

TESTFunction · 0.64