match_path should work the same with or without -pr

This commit is contained in:
David Rose 2003-04-11 19:14:27 +00:00
parent 6e686caf8c
commit dcc8130031
2 changed files with 81 additions and 48 deletions

View File

@ -18,6 +18,7 @@
#include "pathReplace.h"
#include "config_util.h"
#include "indent.h"
////////////////////////////////////////////////////////////////////
// Function: PathReplace::Constructor
@ -53,20 +54,6 @@ match_path(const Filename &orig_filename,
Filename match;
bool got_match = false;
if (_entries.empty()) {
// If we have no entries, still look up the file on the search
// path (unless _path_store is PS_keep).
if (_path_store != PS_keep) {
Filename new_filename = orig_filename;
if (new_filename.resolve_filename(_path) ||
new_filename.resolve_filename(additional_path) ||
new_filename.resolve_filename(get_model_path())) {
// Found it!
return new_filename;
}
}
} else {
Entries::const_iterator ei;
for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
const Entry &entry = (*ei);
@ -105,7 +92,6 @@ match_path(const Filename &orig_filename,
// The prefix matched, but it didn't exist. Keep looking.
}
}
}
// The file couldn't be found anywhere. Did we at least get any
// prefix match?
@ -113,6 +99,18 @@ match_path(const Filename &orig_filename,
return match;
}
// Well, we still haven't found it; look it up on the search path as
// is.
if (_path_store != PS_keep) {
Filename new_filename = orig_filename;
if (new_filename.resolve_filename(_path) ||
new_filename.resolve_filename(additional_path) ||
new_filename.resolve_filename(get_model_path())) {
// Found it!
return new_filename;
}
}
// Nope, couldn't find anything. Just return the original filename.
return orig_filename;
}
@ -161,6 +159,39 @@ store_path(const Filename &orig_filename) {
return filename;
}
////////////////////////////////////////////////////////////////////
// Function: PathReplace::write
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void PathReplace::
write(ostream &out, int indent_level) const {
Entries::const_iterator ei;
for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
indent(out, indent_level)
<< "-pr " << (*ei)._orig_prefix << "="
<< (*ei)._replacement_prefix << "\n";
}
int num_directories = _path.get_num_directories();
for (int i = 0; i < num_directories; i++) {
indent(out, indent_level)
<< "-pp " << _path.get_directory(i) << "\n";
}
indent(out, indent_level)
<< "-ps " << _path_store << "\n";
// The path directory is only relevant if _path_store is rel or rel_abs.
switch (_path_store) {
case PS_relative:
case PS_rel_abs:
indent(out, indent_level)
<< "-pd " << _path_directory << "\n";
default:
break;
}
}
////////////////////////////////////////////////////////////////////
// Function: PathReplace::Entry::Constructor
// Access: Public

View File

@ -61,6 +61,8 @@ public:
INLINE Filename convert_path(const Filename &orig_filename,
const DSearchPath &additional_path = DSearchPath());
void write(ostream &out, int indent_level = 0) const;
public:
// This is used (along with _entries) to support match_path().
DSearchPath _path;