MCPcopy Create free account
hub / github.com/OSGeo/gdal / EarlySetConfigOptions

Function EarlySetConfigOptions

apps/commonutils.cpp:57–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55/* -------------------------------------------------------------------- */
56
57void EarlySetConfigOptions(int argc, char **argv)
58{
59 // Must process some config options before GDALAllRegister() or
60 // OGRRegisterAll(), but we can't call GDALGeneralCmdLineProcessor() or
61 // OGRGeneralCmdLineProcessor(), because it needs the drivers to be
62 // registered for the --format or --formats options.
63
64 // Start with --debug, so that "my_command --config UNKNOWN_CONFIG_OPTION --debug on"
65 // detects and warns about a unknown config option.
66 for (int i = 1; i < argc; i++)
67 {
68 if (EQUAL(argv[i], "--config") && i + 1 < argc)
69 {
70 const char *pszArg = argv[i + 1];
71 if (strchr(pszArg, '=') != nullptr)
72 {
73 char *pszKey = nullptr;
74 const char *pszValue = CPLParseNameValue(pszArg, &pszKey);
75 if (pszKey && EQUAL(pszKey, "CPL_DEBUG") && pszValue)
76 {
77 CPLSetConfigOption(pszKey, pszValue);
78 }
79 CPLFree(pszKey);
80 ++i;
81 }
82 else
83 {
84 if (i + 2 >= argc)
85 {
86 CPLError(CE_Failure, CPLE_AppDefined,
87 "--config option given without a key and value "
88 "argument.");
89 return;
90 }
91
92 if (EQUAL(argv[i + 1], "CPL_DEBUG"))
93 {
94 CPLSetConfigOption(argv[i + 1], argv[i + 2]);
95 }
96
97 i += 2;
98 }
99 }
100 else if (EQUAL(argv[i], "--debug") && i + 1 < argc)
101 {
102 CPLSetConfigOption("CPL_DEBUG", argv[i + 1]);
103 i += 1;
104 }
105 }
106 for (int i = 1; i < argc; i++)
107 {
108 if (EQUAL(argv[i], "--config") && i + 1 < argc)
109 {
110 const char *pszArg = argv[i + 1];
111 if (strchr(pszArg, '=') != nullptr)
112 {
113 char *pszKey = nullptr;
114 const char *pszValue = CPLParseNameValue(pszArg, &pszKey);

Callers 15

MAIN_STARTFunction · 0.85
MAIN_STARTFunction · 0.85
MAIN_STARTFunction · 0.85
MAIN_STARTFunction · 0.85
MAIN_STARTFunction · 0.85
MAIN_STARTFunction · 0.85
gdalinfo_bin.cppFile · 0.85
MAIN_STARTFunction · 0.85
MAIN_STARTFunction · 0.85
MAIN_STARTFunction · 0.85
MAIN_STARTFunction · 0.85
ogrinfo_bin.cppFile · 0.85

Calls 3

CPLParseNameValueFunction · 0.85
CPLErrorFunction · 0.85
EQUALFunction · 0.50

Tested by 1

MAIN_STARTFunction · 0.68