From e862bb76a2f4c9c293fe2638c7fb034de2af709c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 3 Jan 2018 22:59:17 +0100 Subject: Add custom define option --- src/Conf.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/Conf.cpp') 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 &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); -- cgit v1.2.3