aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-01-03 22:59:17 +0100
committerdec05eba <dec05eba@protonmail.com>2018-01-03 22:59:22 +0100
commite862bb76a2f4c9c293fe2638c7fb034de2af709c (patch)
tree01e8b246da70c6c7308364570899c5296c2404ad /src
parent8dd3fbf6211de0e2f274af47c6fe5a73334f0bb0 (diff)
Add custom define option
Diffstat (limited to 'src')
-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);