X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Ffile-path.cc;h=0177d40c9f70c3ff7f5b993b0ef3b79f084adfe8;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=ea963ca355b876787e700a0fd925f3229bcdc63a;hpb=9f4d4a1ce5dc0fad4ed27c9cc1e357cae090b1b1;p=lilypond.git diff --git a/flower/file-path.cc b/flower/file-path.cc index ea963ca355..0177d40c9f 100644 --- a/flower/file-path.cc +++ b/flower/file-path.cc @@ -3,17 +3,14 @@ source file of the Flower Library - (c) 1997--2006 Han-Wen Nienhuys + (c) 1997--2008 Han-Wen Nienhuys Jan Nieuwenhuizen */ #include "file-path.hh" -#include "std-string.hh" - #include #include -using namespace std; #include "config.hh" #if HAVE_SYS_STAT_H @@ -31,44 +28,22 @@ using namespace std; #define PATHSEP ':' #endif -std::vector +vector File_path::directories () const { return dirs_; } -/* - TODO: use split_string. - - */ - #include void -File_path::parse_path (std::string p) +File_path::parse_path (string p) { - ssize len; - while ((len = p.length ())) - { - ssize i = p.find (PATHSEP); - if (i == NPOS) - i = len; - append (p.substr (0, i)); - p = p.substr (std::min (len, i + 1)); - } + concat (dirs_, string_split (p, PATHSEP)); } bool -is_file (std::string file_name) +is_file (string file_name) { -#if 0 /* Check if directory. TODO: encapsulate for autoconf */ - struct stat sbuf; - if (stat (file_name.c_str (), &sbuf) != 0) - return false; - - if (! (sbuf.st_mode & __S_IFREG)) - return false; -#endif - #if !STAT_MACROS_BROKEN struct stat sbuf; if (stat (file_name.c_str (), &sbuf) != 0) @@ -87,8 +62,13 @@ is_file (std::string file_name) } bool -is_dir (std::string file_name) +is_dir (string file_name) { + /* + canonicalize; in particular, trailing slashes should disappear. + */ + file_name = File_name (file_name).to_string (); + #if !STAT_MACROS_BROKEN struct stat sbuf; if (stat (file_name.c_str (), &sbuf) != 0) @@ -114,8 +94,8 @@ directory, in this order. @return The file name if found, or empty string if not found. */ -std::string -File_path::find (std::string name) const +string +File_path::find (string name) const { if (!name.length () || (name == "-")) return name; @@ -133,14 +113,14 @@ File_path::find (std::string name) const for (vsize i = 0; i < dirs_.size (); i++) { File_name file_name (name); - File_name dir = (std::string) dirs_[i]; + File_name dir = (string) dirs_[i]; file_name.root_ = dir.root_; dir.root_ = ""; if (file_name.dir_.empty ()) file_name.dir_ = dir.to_string (); else if (!dir.to_string ().empty ()) file_name.dir_ = dir.to_string () - + std::to_string (DIRSEP) + file_name.dir_; + + ::to_string (DIRSEP) + file_name.dir_; if (is_file (file_name.to_string ())) return file_name.to_string (); } @@ -154,21 +134,21 @@ File_path::find (std::string name) const where EXT is from EXTENSIONS. */ -std::string -File_path::find (std::string name, char const *extensions[]) +string +File_path::find (string name, char const *extensions[]) { if (name.empty () || name == "-") return name; File_name file_name (name); - std::string orig_ext = file_name.ext_; + string orig_ext = file_name.ext_; for (int i = 0; extensions[i]; i++) { file_name.ext_ = orig_ext; if (*extensions[i] && !file_name.ext_.empty ()) file_name.ext_ += "."; file_name.ext_ += extensions[i]; - std::string found = find (file_name.to_string ()); + string found = find (file_name.to_string ()); if (!found.empty ()) return found; } @@ -178,7 +158,7 @@ File_path::find (std::string name, char const *extensions[]) /** Append a directory, return false if failed. */ bool -File_path::try_append (std::string s) +File_path::try_append (string s) { if (s == "") s = "."; @@ -190,27 +170,27 @@ File_path::try_append (std::string s) return false; } -std::string +string File_path::to_string () const { - std::string s; + string s; for (vsize i = 0; i < dirs_.size (); i++) { s = s + dirs_[i]; if (i < dirs_.size () - 1) - s += std::to_string (PATHSEP); + s += ::to_string (PATHSEP); } return s; } void -File_path::append (std::string str) +File_path::append (string str) { dirs_.push_back (str); } void -File_path::prepend (std::string str) +File_path::prepend (string str) { dirs_.insert (dirs_.begin (), str); }