summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2001-02-27 20:41:21 (GMT)
committerBrad King <brad.king@kitware.com>2001-02-27 20:41:21 (GMT)
commit41d198ed40fcae8cbd2fae163af48d3c518c9628 (patch)
treef8b3f0cf49b88d67a6b21cb5114f5d823ad14ba2
parent5c74b6b90d0bfabc7f975b827f3f1eb46a92a930 (diff)
downloadCMake-41d198ed40fcae8cbd2fae163af48d3c518c9628.zip
CMake-41d198ed40fcae8cbd2fae163af48d3c518c9628.tar.gz
CMake-41d198ed40fcae8cbd2fae163af48d3c518c9628.tar.bz2
ENH/BUG: Improved function parsing to allow just about anything inside a double-quoted argument. Also fixed parsing of lines with both quoted and non-quoted arguments.
-rw-r--r--Source/cmSystemTools.cxx59
1 files changed, 43 insertions, 16 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index ffbf286..75bc616 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -198,10 +198,10 @@ bool cmSystemTools::ParseFunction(std::ifstream& fin,
if(fin.getline(inbuffer, BUFFER_SIZE ) )
{
cmRegularExpression blankLine("^$");
- cmRegularExpression comment("^#.*");
- cmRegularExpression oneLiner("[ \t]*([A-Za-z_0-9]*).*\\((.*)\\)");
- cmRegularExpression multiLine("[ \t]*([A-Za-z_0-9]*).*\\((.*)");
- cmRegularExpression lastLine("(.*)\\)");
+ cmRegularExpression comment("^#.*$");
+ cmRegularExpression oneLiner("^[ \t]*([A-Za-z_0-9]*)[ \t]*\\((.*)\\)[ \t]*$");
+ cmRegularExpression multiLine("^[ \t]*([A-Za-z_0-9]*)[ \t]*\\((.*)$");
+ cmRegularExpression lastLine("^(.*)\\)[ \t]*$");
// BEGIN VERBATIM JUNK SHOULD BE REMOVED
cmRegularExpression verbatim("BEGIN MAKE VERBATIM");
@@ -294,25 +294,52 @@ bool cmSystemTools::ParseFunction(std::ifstream& fin,
void cmSystemTools::GetArguments(std::string& line,
std::vector<std::string>& arguments)
{
- cmRegularExpression argument("[\t ]*([-/\\.\\\\{}\\$A-Za-z_0-9]+)[\t ]*");
- cmRegularExpression argumentWithSpaces("[\t ]*\"([-\\. /\\\\{}\\$A-Za-z_0-9]+)\"[\t ]*");
- std::string arg(" ");
- while(arg.length() )
+ // Match a normal argument (not quoted, no spaces).
+ cmRegularExpression normalArgument("[\t ]*([^\" \t]+)[\t ]*");
+ // Match a quoted argument (surrounded by double quotes, spaces allowed).
+ cmRegularExpression quotedArgument("[\t ]*(\"[^\"]*\")[\t ]*");
+
+ bool done = false;
+ while(!done)
{
- arg = "";
+ std::string arg;
long endpos;
+ bool foundQuoted = quotedArgument.find(line.c_str());
+ bool foundNormal = normalArgument.find(line.c_str());
- if (argumentWithSpaces.find(line.c_str()))
+ if(foundQuoted && foundNormal)
+ {
+ // Both matches were found. Take the earlier one.
+ if(normalArgument.start(1) < quotedArgument.start(1))
+ {
+ arg = normalArgument.match(1);
+ endpos = normalArgument.end(1);
+ }
+ else
+ {
+ arg = quotedArgument.match(1);
+ endpos = quotedArgument.end(1);
+ // Strip off the double quotes on the ends.
+ arg = arg.substr(1, arg.length()-2);
+ }
+ }
+ else if (foundQuoted)
+ {
+ arg = quotedArgument.match(1);
+ endpos = quotedArgument.end(1);
+ // Strip off the double quotes on the ends.
+ arg = arg.substr(1, arg.length()-2);
+ }
+ else if(foundNormal)
{
- arg = argumentWithSpaces.match(1);
- endpos = argumentWithSpaces.end(1);
+ arg = normalArgument.match(1);
+ endpos = normalArgument.end(1);
}
- else if(argument.find(line.c_str()))
+ else
{
- arg = argument.match(1);
- endpos = argument.end(1);
+ done = true;
}
- if(arg.length())
+ if(!done)
{
arguments.push_back(arg);
line = line.substr(endpos, line.length() - endpos);