Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Build/Cmake/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"architecture": "x64",
"binaryDir": "${sourceDir}/build/vs2022-x64",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/vcpkg/scripts/buildsystems/vcpkg.cmake",
"CMAKE_TOOLCHAIN_FILE": "$penv{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"VCPKG_MANIFEST_DIR": "${sourceDir}"
}
},
Expand Down
42 changes: 31 additions & 11 deletions IccXML/IccLibXML/IccMpeXml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2652,14 +2652,40 @@ bool CIccMpeXmlCalculator::ParseImport(xmlNode *pNode, std::string importPath, s
return true;
}

// macros can be call{a} or #a, and both could be used in the same expression!
static
const char *FindNextMacro(const char *macroText)
{
const char *ptr = strstr(macroText, "call{");
const char *ptrHash = strchr(macroText, '#');

// if only one is found, choose that one
// if both are found, choose the first one in the string
if (ptrHash && (!ptr || ptrHash < ptr))
ptr = ptrHash;

return ptr;
}

bool CIccMpeXmlCalculator::ValidMacroCalls(const char *szMacroText, std::string macroStack, std::string &parseStr) const
{
const char *ptr;
for (ptr = strstr(szMacroText, "call{"); ptr; ptr = strstr(ptr, "call{")) {
CIccFuncTokenizer parse(ptr, true);
parse.GetNext();

std::string name = parse.GetReference();
for (ptr = FindNextMacro(szMacroText); ptr; ptr = FindNextMacro(ptr)) {
bool isHash = false;
if (ptr[0] == '#') {
isHash = true;
ptr++;
}
CIccFuncTokenizer parse(ptr, true); // tokenizer doesn't seem to recoginze # syntax
parse.GetNext();

std::string name;
if (isHash)
name = parse.GetName();
else
name = parse.GetReference();

MacroMap::const_iterator m = m_macroMap.find(name);
if (m == m_macroMap.end()) {
parseStr += "Call to undefined macro '" + name + "'\n";
Expand All @@ -2684,7 +2710,7 @@ bool CIccMpeXmlCalculator::ValidateMacroCalls(std::string &parseStr) const
MacroMap::const_iterator m;

for (m = m_macroMap.begin(); m != m_macroMap.end(); m++) {
if (!ValidMacroCalls(m->second.c_str(), "*", parseStr)) {
if (!ValidMacroCalls(m->second.c_str(), std::string("*") + m->first + "*", parseStr)) {
return false;
}
}
Expand Down Expand Up @@ -2721,12 +2747,6 @@ bool CIccMpeXmlCalculator::Flatten(std::string &flatStr, std::string macroName,

MacroMap::iterator m = m_macroMap.find(name.c_str());
if (m != m_macroMap.end()) {
if (name == macroName) {
// there is a self/circular reference in the macro, error out before we recurse infinitely
parseStr += "Self reference in macro '" + macroName + "'\n";
return false;
}

icUInt16Number nLocalsSize = 0;
TempDeclVarMap::iterator locals = m_macroLocalMap.find(macroName);
if (locals != m_macroLocalMap.end()) {
Expand Down
Loading