MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ParseParameters

Method ParseParameters

src/common/args.cpp:177–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::string& error)
178{
179 LOCK(cs_args);
180 m_settings.command_line_options.clear();
181
182 for (int i = 1; i < argc; i++) {
183 std::string key(argv[i]);
184
185#ifdef __APPLE__
186 // At the first time when a user gets the "App downloaded from the
187 // internet" warning, and clicks the Open button, macOS passes
188 // a unique process serial number (PSN) as -psn_... command-line
189 // argument, which we filter out.
190 if (key.starts_with("-psn_")) continue;
191#endif
192
193 if (key == "-") break; //bitcoin-tx using stdin
194 std::optional<std::string> val;
195 size_t is_index = key.find('=');
196 if (is_index != std::string::npos) {
197 val = key.substr(is_index + 1);
198 key.erase(is_index);
199 }
200#ifdef WIN32
201 key = ToLower(key);
202 if (key[0] == '/')
203 key[0] = '-';
204#endif
205
206 if (key[0] != '-') {
207 if (!m_accept_any_command && m_command.empty()) {
208 // The first non-dash arg is a registered command
209 std::optional<unsigned int> flags = GetArgFlags_(key);
210 if (!flags || !(*flags & ArgsManager::COMMAND)) {
211 error = strprintf("Invalid command '%s'", argv[i]);
212 return false;
213 }
214 }
215 m_command.push_back(key);
216 while (++i < argc) {
217 // The remaining args are command args
218 m_command.emplace_back(argv[i]);
219 }
220 break;
221 }
222
223 // Transform --foo to -foo
224 if (key.length() > 1 && key[1] == '-')
225 key.erase(0, 1);
226
227 // Transform -foo to foo
228 key.erase(0, 1);
229 KeyInfo keyinfo = InterpretKey(key);
230 std::optional<unsigned int> flags = GetArgFlags_('-' + keyinfo.name);
231
232 // Unknown command line options and command line options with dot
233 // characters (which are returned from InterpretKey with nonempty
234 // section strings) are not valid.

Callers 15

UseMultiprocessFunction · 0.80
AppInitRawTxFunction · 0.80
AppInitRPCFunction · 0.80
AppInitUtilFunction · 0.80
ParseArgsFunction · 0.80
WalletAppInitFunction · 0.80
CheckValueMethod · 0.80
ParseMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
TestParseFunction · 0.80
BOOST_FIXTURE_TEST_CASEFunction · 0.80
ResetArgsFunction · 0.80

Calls 12

InterpretKeyFunction · 0.85
InterpretValueFunction · 0.85
FindKeyFunction · 0.85
findMethod · 0.80
ToLowerFunction · 0.50
clearMethod · 0.45
eraseMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45
emplace_backMethod · 0.45
writeMethod · 0.45
beginMethod · 0.45

Tested by 9

CheckValueMethod · 0.64
ParseMethod · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
TestParseFunction · 0.64
BOOST_FIXTURE_TEST_CASEFunction · 0.64
ResetArgsFunction · 0.64
BOOST_FIXTURE_TEST_CASEFunction · 0.64
SetOptsFromArgsFunction · 0.64
BasicTestingSetupMethod · 0.64