# # patch "ChangeLog" # from [f22fc5208fad5ae7788c81b9c90654420b53df2e] # to [204f139360eb7a130c7c43d2c9823d079d16b885] # # patch "paths.cc" # from [0b241b1c009cc5577bf347e150b698f0eafbbb98] # to [9b7c66bbcc5a4da1ebcff29799abd5e7028a967c] # ======================================================================== --- ChangeLog f22fc5208fad5ae7788c81b9c90654420b53df2e +++ ChangeLog 204f139360eb7a130c7c43d2c9823d079d16b885 @@ -1,5 +1,9 @@ 2005-08-25 Nathaniel Smith + * paths.cc: Many fixes. Now compiles. + +2005-08-25 Nathaniel Smith + * paths.cc (system_path): Implement. 2005-08-24 Nathaniel Smith ======================================================================== --- paths.cc 0b241b1c009cc5577bf347e150b698f0eafbbb98 +++ paths.cc 9b7c66bbcc5a4da1ebcff29799abd5e7028a967c @@ -13,6 +13,8 @@ #include "paths.hh" #include "platform.hh" #include "sanity.hh" +#include "interner.hh" +#include "transforms.hh" // some structure to ensure we aren't doing anything broken when resolving // filenames. the idea is to make sure @@ -27,23 +29,21 @@ I(!used); value = val; } - T const & get() const + T const & get() { I(initialized); used = true; return value; } + T const & get_but_unused() + { + I(initialized); + return value; + } T value; bool initialized, used; - access_tracker() : initialized(false), used(false); + access_tracker() : initialized(false), used(false) {}; }; -// need this so we can log our values -// logging does not count as using... -template ostream & -operator <<(ostream & o, access_tracker const & a) -{ - o << a.value; -} // paths to use in interpreting paths from various sources, // conceptually: @@ -66,7 +66,7 @@ initial_abs_path.set(system_path(get_current_working_dir()), false); // We still use boost::fs, so let's continue to initialize it properly. fs::initial_path(); - L(F("initial abs path is: %s") % initial_abs_path); + L(F("initial abs path is: %s") % initial_abs_path.get_but_unused()); } /////////////////////////////////////////////////////////////////////////// @@ -133,6 +133,7 @@ return false; start = stop + 1; } + return true; } static inline bool @@ -143,12 +144,12 @@ file_path::file_path(file_path::source_type type, std::string const & path) { - switch (source_type) + switch (type) { - internal: + case internal: data = path; break; - external: + case external: fs::path tmp(initial_rel_path.get().as_internal()); tmp /= fs::path(path, fs::native); tmp = tmp.normalize(); @@ -190,17 +191,18 @@ // - ["", "bar"] file_path::file_path(std::vector const & pieces) { - std::vector::const_iterator i = names.begin(); - I(i != names.end()); - if (names.size() > 1) + std::vector::const_iterator i = pieces.begin(); + I(i != pieces.end()); + if (pieces.size() > 1) I(!null_name(*i)); - data = pc_interner.lookup(*i); - for (++i; i != names.end(); ++i) + std::string tmp = pc_interner.lookup(*i); + for (++i; i != pieces.end(); ++i) { I(!null_name(*i)); - data += "/"; - data += pc_interner.lookup(*i); + tmp += "/"; + tmp += pc_interner.lookup(*i); } + data = tmp; } // @@ -216,20 +218,21 @@ // get a single-element vector containing the null component. with the old // code, in this one case, you would have gotten an empty vector. void -file_path::split(std::vector & pieces) +file_path::split(std::vector & pieces) const { pieces.clear(); std::string::size_type start, stop; start = 0; + std::string const & s = data(); while (1) { - stop = p_str.find('/', start); - if (stop < 0 || stop > p_str.length()) + stop = s.find('/', start); + if (stop < 0 || stop > s.length()) { - pieces.push_back(pc_interner.intern(p_str.substr(start))); + pieces.push_back(pc_interner.intern(s.substr(start))); break; } - components.push_back(pc_interner.intern(p_str.substr(start, stop - start))); + pieces.push_back(pc_interner.intern(s.substr(start, stop - start))); start = stop + 1; } } @@ -323,14 +326,24 @@ data = (working_root.get() / other.as_internal()).as_internal(); } -system_path::system_path(std::string const & path) +static inline std::string const_system_path(std::string const & path) { if (is_absolute(path)) - data = path; + return path; else - data = (initial_abs_path.get() / other.as_internal()).as_internal(); + return (initial_abs_path.get() / path).as_internal(); } +system_path::system_path(std::string const & path) +{ + data = const_system_path(path); +} + +system_path::system_path(utf8 const & path) +{ + data = const_system_path(path()); +} + /////////////////////////////////////////////////////////////////////////// // working copy (and path roots) handling /////////////////////////////////////////////////////////////////////////// @@ -386,10 +399,10 @@ working_root.set(current.native_file_string(), true); initial_rel_path.set(file_path_internal(removed.string()), true); - L(F("working root is '%s'") % working_root); - L(F("initial relative path is '%s'") % initial_rel_path); + L(F("working root is '%s'") % working_root.get_but_unused()); + L(F("initial relative path is '%s'") % initial_rel_path.get_but_unused()); - change_current_working_dir(working_root); + change_current_working_dir(working_root.get_but_unused()); return true; }