aboutsummaryrefslogtreecommitdiff
path: root/src/Conf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Conf.cpp')
-rw-r--r--src/Conf.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Conf.cpp b/src/Conf.cpp
index 0bbbf7b..75fdd02 100644
--- a/src/Conf.cpp
+++ b/src/Conf.cpp
@@ -398,6 +398,24 @@ namespace sibs
}
}
+ bool isValidCIdentifier(const StringView &identifier)
+ {
+ if(identifier.size == 0)
+ return false;
+
+ char c = identifier.data[0];
+ if(isalpha(c) || c == '_')
+ {
+ for(int i = 1; i < identifier.size; ++i)
+ {
+ c = identifier.data[i];
+ if(!isalnum(c) && c != '_')
+ return false;
+ }
+ }
+ return true;
+ }
+
bool directoryToIgnore(const FileString &dir, const vector<string> &ignoreDirList)
{
string dirUtf8 = toUtf8(dir);
@@ -689,6 +707,22 @@ namespace sibs
else
throw ParserException("Expected field under dependencies to be a single value, was a list");
}
+ else if(currentObject.equals("define"))
+ {
+ if(value.isSingle())
+ {
+ if(!isValidCIdentifier(name))
+ {
+ string errMsg = "Definition \"";
+ errMsg.append(name.data, name.size);
+ errMsg += "\" is not in a valid format. The first character have to match [a-zA-Z_] and the next characters have to match [a-zA-Z0-9_]";
+ throw ParserException(errMsg);
+ }
+ defines[string(name.data, name.size)] = string(value.asSingle().data, value.asSingle().size);
+ }
+ else
+ throw ParserException("Expected field under define to be a single value, was a list");
+ }
else if(currentObject.equals("cmake"))
{
parseCmake(name, value, cmakeDirGlobal, cmakeArgsGlobal);