From c94534b769aa949562716619d8c3e3fcb937c755 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 9 Nov 2000 00:54:56 +0000 Subject: [PATCH] *** empty log message *** --- ppremake/configure.in | 2 +- ppremake/ppDirectory.cxx | 2 ++ ppremake/ppScope.cxx | 77 ++++++++++++++++++++++++++++++++-------- ppremake/ppScope.h | 3 +- 4 files changed, 67 insertions(+), 17 deletions(-) diff --git a/ppremake/configure.in b/ppremake/configure.in index 53b9b263bf..2b5855aefa 100644 --- a/ppremake/configure.in +++ b/ppremake/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(ppremake.cxx) -AM_INIT_AUTOMAKE(ppremake, 0.54) +AM_INIT_AUTOMAKE(ppremake, 0.57) AM_CONFIG_HEADER(config.h) AC_PREFIX_DEFAULT(/usr/local/panda) diff --git a/ppremake/ppDirectory.cxx b/ppremake/ppDirectory.cxx index 620a9d0085..41919a397a 100644 --- a/ppremake/ppDirectory.cxx +++ b/ppremake/ppDirectory.cxx @@ -411,6 +411,7 @@ r_scan(const string &prefix) { PPDirectory *subtree = new PPDirectory(filename, this); if (!subtree->r_scan(next_prefix)) { + closedir(root); return false; } } @@ -419,6 +420,7 @@ r_scan(const string &prefix) { d = readdir(root); } + closedir(root); return true; } diff --git a/ppremake/ppScope.cxx b/ppremake/ppScope.cxx index 115265c54d..fe27f0ff48 100644 --- a/ppremake/ppScope.cxx +++ b/ppremake/ppScope.cxx @@ -854,9 +854,13 @@ r_expand_variable(const string &str, size_t &vp, } else if (funcname == "firstword") { return expand_firstword(params); } else if (funcname == "patsubst") { - return expand_patsubst(params); + return expand_patsubst(params, true); + } else if (funcname == "patsubstw") { + return expand_patsubst(params, false); } else if (funcname == "subst") { return expand_subst(params); + } else if (funcname == "wordsubst") { + return expand_wordsubst(params); } else if (funcname == "filter") { return expand_filter(params); } else if (funcname == "filter_out" || funcname == "filter-out") { @@ -1849,7 +1853,7 @@ expand_firstword(const string ¶ms) const { // Description: Expands the "patsubst" function variable. //////////////////////////////////////////////////////////////////// string PPScope:: -expand_patsubst(const string ¶ms) const { +expand_patsubst(const string ¶ms, bool separate_words) const { // Split the string up into tokens based on the commas. vector tokens; tokenize_params(params, tokens, true); @@ -1864,9 +1868,14 @@ expand_patsubst(const string ¶ms) const { return string(); } - // Split the last parameter into tokens based on the spaces. + // Split the last parameter into tokens based on the spaces--but + // only if separate_words is true. vector words; - tokenize_whitespace(tokens.back(), words); + if (separate_words) { + tokenize_whitespace(tokens.back(), words); + } else { + words.push_back(tokens.back()); + } // Build up a vector of from/to patterns. typedef vector Patterns; @@ -1984,7 +1993,7 @@ expand_filter_out(const string ¶ms) const { tokenize_params(params, tokens, true); if (tokens.size() != 2) { - cerr << "filter requires two parameters.\n"; + cerr << "filter-out requires two parameters.\n"; return string(); } @@ -2049,20 +2058,58 @@ expand_subst(const string ¶ms) const { return string(); } + // Now substitute each of the substitute strings out for the + // replacement strings. + string str = tokens.back(); + for (size_t i = 0; i < tokens.size() - 1; i += 2) { + string new_str; + const string &subst = tokens[i]; + const string &repl = tokens[i + 1]; + size_t q = 0; + size_t p = str.find(subst, q); + while (p != string::npos) { + new_str += str.substr(q, p - q) + repl; + q = p + subst.length(); + p = str.find(subst, q); + } + str = new_str + str.substr(q); + } + return str; +} + +//////////////////////////////////////////////////////////////////// +// Function: PPScope::expand_wordsubst +// Access: Private +// Description: Expands the "wordsubst" function variable. This is +// like "subst" except it only replaces whole words. +//////////////////////////////////////////////////////////////////// +string PPScope:: +expand_wordsubst(const string ¶ms) const { + // Split the string up into tokens based on the commas. + vector tokens; + tokenize_params(params, tokens, true); + + if (tokens.size() < 3) { + cerr << "subst requires at least three parameters.\n"; + return string(); + } + + if ((tokens.size() % 2) != 1) { + cerr << "subst requires an odd number of parameters.\n"; + return string(); + } + // Split the last parameter into tokens based on the spaces. vector words; tokenize_whitespace(tokens.back(), words); - vector::iterator wi; - for (wi = words.begin(); wi != words.end(); ++wi) { - string &word = (*wi); - - // Check for the given word in the subst/replace strings. - bool found = false; - for (size_t i = 0; i < tokens.size() - 1 && !found; i += 2) { - if (tokens[i] == word) { - found = true; - word = tokens[i + 1]; + for (size_t i = 0; i < tokens.size() - 1; i += 2) { + const string &subst = tokens[i]; + const string &repl = tokens[i + 1]; + vector::iterator wi; + for (wi = words.begin(); wi != words.end(); ++wi) { + if ((*wi) == subst) { + (*wi) = repl; } } } diff --git a/ppremake/ppScope.h b/ppremake/ppScope.h index 03c4048603..06c5524196 100644 --- a/ppremake/ppScope.h +++ b/ppremake/ppScope.h @@ -102,9 +102,10 @@ private: string expand_wordlist(const string ¶ms) const; string expand_words(const string ¶ms) const; string expand_firstword(const string ¶ms) const; - string expand_patsubst(const string ¶ms) const; + string expand_patsubst(const string ¶ms, bool separate_words) const; string expand_filter(const string ¶ms) const; string expand_filter_out(const string ¶ms) const; + string expand_wordsubst(const string ¶ms) const; string expand_subst(const string ¶ms) const; string expand_sort(const string ¶ms) const; string expand_unique(const string ¶ms) const;