add 1.11 features: more robust patsubst, fix other bugs

This commit is contained in:
David Rose 2002-06-04 23:28:58 +00:00
parent a8894d5815
commit b89e085397
7 changed files with 55 additions and 18 deletions

View File

@ -80,5 +80,5 @@
** Also be sure to change the version number **
** at the beginning of configure.in. **
**************** ****************/
#define VERSION "1.1"
#define VERSION "1.11"
/**************** UPDATE VERSION NUMBER HERE ****************/

View File

@ -5,7 +5,7 @@ dnl **************** UPDATE VERSION NUMBER HERE ****************
dnl ** Also be sure to change the version number **
dnl ** at the end of config_msvc.h. **
dnl **************** ****************
AM_INIT_AUTOMAKE(ppremake, 1.1)
AM_INIT_AUTOMAKE(ppremake, 1.11)
dnl **************** UPDATE VERSION NUMBER HERE ****************
AM_CONFIG_HEADER(config.h)

View File

@ -801,7 +801,11 @@ handle_endif_command() {
nest->pop(this);
if (nest->_block != _block_nesting) {
cerr << "If block not closed within scoping block.\n";
if (nest->_block != (BlockNesting *)NULL) {
cerr << "If block not closed within scoping block " << nest->_block->_name << ".\n";
} else {
cerr << "If block not closed within scoping block " << _block_nesting->_name << ".\n";
}
return false;
}
@ -1106,15 +1110,15 @@ handle_output_command() {
nest->push(this);
if (!_in_for) {
string filename = trim_blanks(_scope->expand_string(nest->_name));
Filename filename = trim_blanks(_scope->expand_string(nest->_name));
if (filename.empty()) {
cerr << "Attempt to output to empty filename\n";
return false;
}
if (filename[0] != '/') {
if (filename.is_local()) {
string prefix = _scope->expand_variable("DIRPREFIX");
filename = prefix + filename;
filename = Filename(prefix, filename);
}
nest->_params = filename;
@ -1157,7 +1161,7 @@ handle_end_command() {
nest->pop(this);
if (nest->_if != _if_nesting) {
cerr << "If block not closed within scoping block.\n";
cerr << "If block not closed within scoping block " << name << ".\n";
return false;
}
@ -1436,7 +1440,13 @@ handle_mkdir_command() {
vector<string>::const_iterator wi;
for (wi = words.begin(); wi != words.end(); ++wi) {
Filename dirname(*wi);
Filename filename(*wi, "file");
if (dirname.is_local()) {
string prefix = _scope->expand_variable("DIRPREFIX");
dirname = Filename(prefix, dirname);
}
Filename filename(dirname, "file");
if (!filename.make_dir()) {
if (!dirname.is_directory()) {
cerr << "Unable to create directory " << dirname << "\n";

View File

@ -498,6 +498,7 @@ read_depends_file(PPNamedScopes *named_scopes) {
}
named_scopes->set_current(_dirname);
current_output_directory = this;
PPCommandFile depends(_scope);
if (!depends.read_file(depends_filename)) {
cerr << "Error reading dependency definition file "

View File

@ -167,7 +167,21 @@ transform(const string &filename,
return _prefix;
} else {
string body = transform_from.extract_body(filename);
return _prefix + body + _suffix;
string result = _prefix + body;
// Now the suffix might contain more % characters. Replace all
// of them.
size_t p = 0;
size_t pct = _suffix.find(PATTERN_WILDCARD, p);
while (pct != string::npos) {
result += _suffix.substr(p, pct - p);
result += body;
p = pct + 1;
pct = _suffix.find(PATTERN_WILDCARD, p);
}
result += _suffix.substr(p);
return result;
}
}

View File

@ -104,7 +104,12 @@ read_source(const string &root) {
}
// Now cd to the source root and get the actual path.
string osdir = trydir.to_os_specific();
string osdir;
#ifdef HAVE_CYGWIN
osdir = trydir;
#else
osdir = trydir.to_os_specific();
#endif
if (chdir(osdir.c_str()) < 0) {
perror("chdir");
return false;

View File

@ -2023,7 +2023,7 @@ string PPScope::
expand_patsubst(const string &params, bool separate_words) {
// Split the string up into tokens based on the commas.
vector<string> tokens;
tokenize_params(params, tokens, true);
tokenize_params(params, tokens, false);
if (tokens.size() < 3) {
cerr << "patsubst requires at least three parameters.\n";
@ -2039,9 +2039,9 @@ expand_patsubst(const string &params, bool separate_words) {
// only if separate_words is true.
vector<string> words;
if (separate_words) {
tokenize_whitespace(tokens.back(), words);
tokenize_whitespace(expand_string(tokens.back()), words);
} else {
words.push_back(tokens.back());
words.push_back(expand_string(tokens.back()));
}
// Build up a vector of from/to patterns.
@ -2053,10 +2053,10 @@ expand_patsubst(const string &params, bool separate_words) {
size_t i;
for (i = 0; i < tokens.size() - 1; i += 2) {
// Each "from" pattern might be a collection of patterns separated
// by spaces.
// by spaces, and it is expanded immediately.
from.push_back(Patterns());
vector<string> froms;
tokenize_whitespace(tokens[i], froms);
tokenize_whitespace(expand_string(tokens[i]), froms);
vector<string>::const_iterator fi;
for (fi = froms.begin(); fi != froms.end(); ++fi) {
PPFilenamePattern pattern(*fi);
@ -2068,8 +2068,14 @@ expand_patsubst(const string &params, bool separate_words) {
from.back().push_back(pattern);
}
// However, the corresponding "to" pattern is just one pattern.
to.push_back(PPFilenamePattern(tokens[i + 1]));
// However, the corresponding "to" pattern is just one pattern,
// and it is expanded immediately only if it does not contain a
// wildcard character.
PPFilenamePattern to_pattern(tokens[i + 1]);
if (!to_pattern.has_wildcard()) {
to_pattern = PPFilenamePattern(expand_string(tokens[i + 1]));
}
to.push_back(to_pattern);
}
size_t num_patterns = from.size();
assert(num_patterns == to.size());
@ -2082,7 +2088,8 @@ expand_patsubst(const string &params, bool separate_words) {
for (pi = from[i].begin(); pi != from[i].end() && !matched; ++pi) {
if ((*pi).matches(*wi)) {
matched = true;
(*wi) = to[i].transform(*wi, (*pi));
string transformed = to[i].transform(*wi, (*pi));
(*wi) = expand_string(transformed);
}
}
}