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

Function LoadPythonDriver

gcore/gdalpythondriverloader.cpp:1813–1896  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1811/************************************************************************/
1812
1813static void LoadPythonDriver(const char *pszFilename)
1814{
1815 char **papszLines = CSLLoad2(pszFilename, 1000, 1000, nullptr);
1816 if (papszLines == nullptr)
1817 {
1818 return;
1819 }
1820 CPLString osPluginName;
1821 char **papszMD = nullptr;
1822 bool bAPIOK = false;
1823 constexpr int CURRENT_API_VERSION = 1;
1824 for (int i = 0; papszLines[i] != nullptr; i++)
1825 {
1826 const char *pszLine = papszLines[i];
1827 if (!STARTS_WITH_CI(pszLine, "# gdal: DRIVER_"))
1828 continue;
1829 pszLine += strlen("# gdal: DRIVER_");
1830
1831 const char *pszEqual = strchr(pszLine, '=');
1832 if (pszEqual == nullptr)
1833 continue;
1834
1835 CPLString osKey(pszLine);
1836 osKey.resize(pszEqual - pszLine);
1837 osKey.Trim();
1838
1839 CPLString osValue(pszEqual + 1);
1840 osValue.Trim();
1841
1842 char chQuote = 0;
1843 if (!osValue.empty() && (osValue[0] == '"' || osValue[0] == '\''))
1844 {
1845 chQuote = osValue[0];
1846 osValue = osValue.substr(1);
1847 }
1848 if (!osValue.empty() && osValue[osValue.size() - 1] == chQuote)
1849 osValue.resize(osValue.size() - 1);
1850 if (EQUAL(osKey, "NAME"))
1851 {
1852 osPluginName = std::move(osValue);
1853 }
1854 else if (EQUAL(osKey, "SUPPORTED_API_VERSION"))
1855 {
1856 const CPLStringList aosTokens(
1857 CSLTokenizeString2(osValue, "[, ]", 0));
1858 for (int j = 0; j < aosTokens.size(); ++j)
1859 {
1860 if (atoi(aosTokens[j]) == CURRENT_API_VERSION)
1861 {
1862 bAPIOK = true;
1863 break;
1864 }
1865 }
1866 }
1867 else
1868 {
1869 papszMD = CSLSetNameValue(papszMD, osKey.c_str(), osValue);
1870 }

Callers 1

AutoLoadPythonDriversMethod · 0.85

Calls 13

CSLLoad2Function · 0.85
moveFunction · 0.85
CSLTokenizeString2Function · 0.85
CSLSetNameValueFunction · 0.85
CPLErrorFunction · 0.85
CPLDebugFunction · 0.85
GetGDALDriverManagerFunction · 0.85
EQUALFunction · 0.50
resizeMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected