mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
match_path should work the same with or without -pr
This commit is contained in:
parent
6e686caf8c
commit
dcc8130031
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "pathReplace.h"
|
#include "pathReplace.h"
|
||||||
#include "config_util.h"
|
#include "config_util.h"
|
||||||
|
#include "indent.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: PathReplace::Constructor
|
// Function: PathReplace::Constructor
|
||||||
@ -53,57 +54,42 @@ match_path(const Filename &orig_filename,
|
|||||||
Filename match;
|
Filename match;
|
||||||
bool got_match = false;
|
bool got_match = false;
|
||||||
|
|
||||||
if (_entries.empty()) {
|
Entries::const_iterator ei;
|
||||||
// If we have no entries, still look up the file on the search
|
for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
|
||||||
// path (unless _path_store is PS_keep).
|
const Entry &entry = (*ei);
|
||||||
if (_path_store != PS_keep) {
|
Filename new_filename;
|
||||||
Filename new_filename = orig_filename;
|
if (entry.try_match(orig_filename, new_filename)) {
|
||||||
if (new_filename.resolve_filename(_path) ||
|
// The prefix matches. Save the resulting filename for
|
||||||
new_filename.resolve_filename(additional_path) ||
|
// posterity.
|
||||||
new_filename.resolve_filename(get_model_path())) {
|
got_match = true;
|
||||||
// Found it!
|
match = new_filename;
|
||||||
return new_filename;
|
|
||||||
}
|
if (new_filename.is_fully_qualified()) {
|
||||||
}
|
// If the resulting filename is fully qualified, it's a match
|
||||||
|
// if and only if it exists.
|
||||||
} else {
|
if (new_filename.exists()) {
|
||||||
Entries::const_iterator ei;
|
return new_filename;
|
||||||
for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
|
|
||||||
const Entry &entry = (*ei);
|
|
||||||
Filename new_filename;
|
|
||||||
if (entry.try_match(orig_filename, new_filename)) {
|
|
||||||
// The prefix matches. Save the resulting filename for
|
|
||||||
// posterity.
|
|
||||||
got_match = true;
|
|
||||||
match = new_filename;
|
|
||||||
|
|
||||||
if (new_filename.is_fully_qualified()) {
|
|
||||||
// If the resulting filename is fully qualified, it's a match
|
|
||||||
// if and only if it exists.
|
|
||||||
if (new_filename.exists()) {
|
|
||||||
return new_filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Otherwise, if it's a relative filename, attempt to look it
|
|
||||||
// up on the search path.
|
|
||||||
if (new_filename.resolve_filename(_path) ||
|
|
||||||
new_filename.resolve_filename(additional_path) ||
|
|
||||||
new_filename.resolve_filename(get_model_path())) {
|
|
||||||
// Found it!
|
|
||||||
if (_path_store == PS_keep) {
|
|
||||||
// If we asked to "keep" the pathname, we return the
|
|
||||||
// matched path, but not the found path.
|
|
||||||
return match;
|
|
||||||
} else {
|
|
||||||
// Otherwise, we return the actual, found path.
|
|
||||||
return new_filename;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The prefix matched, but it didn't exist. Keep looking.
|
} else {
|
||||||
|
// Otherwise, if it's a relative filename, attempt to look it
|
||||||
|
// up on the search path.
|
||||||
|
if (new_filename.resolve_filename(_path) ||
|
||||||
|
new_filename.resolve_filename(additional_path) ||
|
||||||
|
new_filename.resolve_filename(get_model_path())) {
|
||||||
|
// Found it!
|
||||||
|
if (_path_store == PS_keep) {
|
||||||
|
// If we asked to "keep" the pathname, we return the
|
||||||
|
// matched path, but not the found path.
|
||||||
|
return match;
|
||||||
|
} else {
|
||||||
|
// Otherwise, we return the actual, found path.
|
||||||
|
return new_filename;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The prefix matched, but it didn't exist. Keep looking.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +99,18 @@ match_path(const Filename &orig_filename,
|
|||||||
return match;
|
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.
|
// Nope, couldn't find anything. Just return the original filename.
|
||||||
return orig_filename;
|
return orig_filename;
|
||||||
}
|
}
|
||||||
@ -161,6 +159,39 @@ store_path(const Filename &orig_filename) {
|
|||||||
return 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
|
// Function: PathReplace::Entry::Constructor
|
||||||
// Access: Public
|
// Access: Public
|
||||||
|
@ -61,6 +61,8 @@ public:
|
|||||||
INLINE Filename convert_path(const Filename &orig_filename,
|
INLINE Filename convert_path(const Filename &orig_filename,
|
||||||
const DSearchPath &additional_path = DSearchPath());
|
const DSearchPath &additional_path = DSearchPath());
|
||||||
|
|
||||||
|
void write(ostream &out, int indent_level = 0) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// This is used (along with _entries) to support match_path().
|
// This is used (along with _entries) to support match_path().
|
||||||
DSearchPath _path;
|
DSearchPath _path;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user