From: Han-Wen Nienhuys Date: Thu, 19 May 2005 22:57:50 +0000 (+0000) Subject: * flower/file-path.cc (find): don't throw away file_name.dir, but X-Git-Tag: release/2.5.25~5 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=238d0dc299ccd27351991fa383c1af1de98b2084;p=lilypond.git * flower/file-path.cc (find): don't throw away file_name.dir, but append to it. Fixes \include with directories. * flower/include/file-path.hh (class File_path): don't derive from Array. * flower/include/file-name.hh (class File_name): remove to_str0() * lily/hara-kiri-engraver.cc (acknowledge_grob): split Hara_kiri_engraver in separate file. --- diff --git a/ChangeLog b/ChangeLog index b50334e23a..1576d999d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2005-05-20 Han-Wen Nienhuys + * flower/file-path.cc (find): don't throw away file_name.dir, but + append to it. Fixes \include with directories. + + * flower/include/file-path.hh (class File_path): don't derive from + Array. + + * flower/include/file-name.hh (class File_name): remove to_str0() + * lily/hara-kiri-engraver.cc (acknowledge_grob): split Hara_kiri_engraver in separate file. diff --git a/flower/file-name.cc b/flower/file-name.cc index 8d1a3fae8c..1763a546c0 100644 --- a/flower/file-name.cc +++ b/flower/file-name.cc @@ -75,11 +75,6 @@ File_name::to_string () const return s; } -char const * -File_name::to_str0 () const -{ - return to_string ().to_str0 (); -} File_name::File_name (String file_name) { diff --git a/flower/file-path.cc b/flower/file-path.cc index 32f174943a..783b1095ea 100644 --- a/flower/file-path.cc +++ b/flower/file-path.cc @@ -31,7 +31,7 @@ Array File_path::directories () const { - return *this; + return dirs_; } void @@ -41,7 +41,7 @@ File_path::parse_path (String p) while ((len = p.length ()) ) { int i = p.index (PATHSEP); - if (i <0) + if (i < 0) i = len; append (p.left_string (i)); p = p.right_string (len - i - 1); @@ -59,6 +59,7 @@ is_file (String file_name) if (!(sbuf.st_mode & __S_IFREG)) return false; #endif + #if !STAT_MACROS_BROKEN struct stat sbuf; if (stat (file_name.to_str0 (), &sbuf) != 0) @@ -67,12 +68,14 @@ is_file (String file_name) return !S_ISDIR (sbuf.st_mode); #endif + if (FILE *f = fopen (file_name.to_str0 (), "r")) { fclose (f); return true; } + return false; } @@ -120,29 +123,31 @@ File_path::find (String name) const File_name file_name (name); if (file_name.dir_[0] == DIRSEP && is_file (file_name.to_string ())) return file_name.to_string (); - - for (int i = 0, n = size (); i < n; i++) + + for (int i = 0; i < dirs_.size (); i++) { - File_name dir = elem (i); + File_name file_name (name); + File_name dir = dirs_[i]; file_name.root_ = dir.root_; dir.root_ = ""; - file_name.dir_ = dir.to_string (); + if (file_name.dir_.is_empty ()) + file_name.dir_ = dir.to_string (); + else if (!dir.to_string ().is_empty()) + file_name.dir_ += ::to_string (DIRSEP) + dir.to_string (); + if (is_file (file_name.to_string ())) return file_name.to_string (); } return ""; } -/** Find a file. - -Seach in the current dir (DUH! FIXME?), in the construction-arg -(what's that?, and in any other appended directory, in this order. +/* + Try to find -Search for NAME, or name without extension, or name with any of -EXTENSIONS, in that order. + file.EXT, -@return -The file name if found, or empty string if not found. */ + where EXT is from EXTENSIONS. +*/ String File_path::find (String name, char const *extensions[]) { @@ -161,6 +166,7 @@ File_path::find (String name, char const *extensions[]) if (!find (file_name.to_string ()).is_empty ()) break; } + /* Reshuffle extension */ file_name = File_name (file_name.to_string ()); } @@ -185,11 +191,23 @@ String File_path::to_string () const { String s; - for (int i = 0, n = size (); i < n; i++) + for (int i = 0; i < dirs_.size (); i++) { - s = s + elem (i); - if (i < n - 1) + s = s + dirs_[i]; + if (i < dirs_.size() - 1) s += ::to_string (PATHSEP); } return s; } + +void +File_path::append (String str) +{ + dirs_.push (str); +} + +void +File_path::prepend (String str) +{ + dirs_.insert (str, 0); +} diff --git a/flower/include/file-name.hh b/flower/include/file-name.hh index be2268ec85..fb3e3ff13a 100644 --- a/flower/include/file-name.hh +++ b/flower/include/file-name.hh @@ -23,7 +23,6 @@ public: File_name (String); String to_string () const; - char const *to_str0 () const; }; #endif /* FILE_NAME */ diff --git a/flower/include/file-path.hh b/flower/include/file-path.hh index 3c7cc26461..37a4b6c2b1 100644 --- a/flower/include/file-path.hh +++ b/flower/include/file-path.hh @@ -21,17 +21,18 @@ TODO: add a unix style PATH interface */ -class File_path : private Array +class File_path { + Array dirs_; public: Array directories () const; String find (String name) const; String find (String name, char const *extensions[]); String to_string () const; bool try_append (String str); - void append (String str) { Array::push (str); } + void append (String str); void parse_path (String); - void prepend (String str) { Array::insert (str, 0); } + void prepend (String str); }; #endif /* FILE_PATH */ diff --git a/lily/hara-kiri-engraver.cc b/lily/hara-kiri-engraver.cc index 5380c92a69..343bdb08c8 100644 --- a/lily/hara-kiri-engraver.cc +++ b/lily/hara-kiri-engraver.cc @@ -10,6 +10,7 @@ #include "axis-group-engraver.hh" #include "hara-kiri-group-spanner.hh" #include "rhythmic-head.hh" +#include "spanner.hh" class Hara_kiri_engraver : public Axis_group_engraver {