From d24e58ca5b51877dff138fad2383470707b51a0d Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 22 Jan 2006 21:54:58 +0000 Subject: [PATCH] * flower/file-path.cc: * flower/include/file-path.hh: Use std::string [interface]. Update callers. * flower/std-string.cc: * flower/include/std-string.hh: New file. --- ChangeLog | 6 ++++- flower/file-path.cc | 52 ++++++++++++++++++------------------ flower/include/file-path.hh | 24 ++++++++--------- flower/include/std-string.hh | 2 +- lily/includable-lexer.cc | 2 +- lily/lily-parser-scheme.cc | 8 +++--- lily/relocate.cc | 2 +- lily/score-engraver.cc | 2 +- 8 files changed, 51 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index b6ca2e623f..05d3dacfbe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2006-01-22 Jan Nieuwenhuizen + * flower/file-path.cc: + * flower/include/file-path.hh: Use std::string [interface]. + Update callers. + * flower/direction.cc: * flower/axis.cc: Unused. Remove. @@ -9,7 +13,7 @@ * flower/include/std-string.hh: New file. * flower/file-name.cc[STD_STRING]: - * flower/include/file-name.hh[STD_STRING]: Use it. + * flower/include/file-name.hh[STD_STRING]: Use it. Update callers. 2006-01-22 Han-Wen Nienhuys diff --git a/flower/file-path.cc b/flower/file-path.cc index d6e0e04403..e1c387a5ae 100644 --- a/flower/file-path.cc +++ b/flower/file-path.cc @@ -29,32 +29,32 @@ using namespace std; #define PATHSEP ':' #endif -Array +Array File_path::directories () const { return dirs_; } void -File_path::parse_path (String p) +File_path::parse_path (Std_string p) { int len; while ((len = p.length ())) { - int i = p.index (PATHSEP); + int i = p.find (PATHSEP); if (i < 0) i = len; - append (p.left_string (i)); - p = p.right_string (len - i - 1); + append (String (p, 0, i)); + p = String (p, i + 1); } } bool -is_file (String file_name) +is_file (Std_string file_name) { #if 0 /* Check if directory. TODO: encapsulate for autoconf */ struct stat sbuf; - if (stat (file_name.to_str0 (), &sbuf) != 0) + if (stat (file_name.c_str (), &sbuf) != 0) return false; if (! (sbuf.st_mode & __S_IFREG)) @@ -63,13 +63,13 @@ is_file (String file_name) #if !STAT_MACROS_BROKEN struct stat sbuf; - if (stat (file_name.to_str0 (), &sbuf) != 0) + if (stat (file_name.c_str (), &sbuf) != 0) return false; return !S_ISDIR (sbuf.st_mode); #endif - if (FILE *f = fopen (file_name.to_str0 (), "r")) + if (FILE *f = fopen (file_name.c_str (), "r")) { fclose (f); return true; @@ -79,17 +79,17 @@ is_file (String file_name) } bool -is_dir (String file_name) +is_dir (Std_string file_name) { #if !STAT_MACROS_BROKEN struct stat sbuf; - if (stat (file_name.to_str0 (), &sbuf) != 0) + if (stat (file_name.c_str (), &sbuf) != 0) return false; return S_ISDIR (sbuf.st_mode); #endif - if (FILE *f = fopen (file_name.to_str0 (), "r")) + if (FILE *f = fopen (file_name.c_str (), "r")) { fclose (f); return true; @@ -106,14 +106,14 @@ directory, in this order. @return The file name if found, or empty string if not found. */ -String -File_path::find (String name) const +Std_string +File_path::find (Std_string name) const { if (!name.length () || (name == "-")) return name; #ifdef __MINGW32__ - if (name.index ('\\') >= 0) + if (name.find ('\\') >= 0) programming_error ("file name not normalized: " + name); #endif /* __MINGW32__ */ @@ -146,22 +146,22 @@ File_path::find (String name) const where EXT is from EXTENSIONS. */ -String -File_path::find (String name, char const *extensions[]) +Std_string +File_path::find (Std_string name, char const *extensions[]) { - if (name.is_empty () || name == "-") + if (name.empty () || name == "-") return name; File_name file_name (name); - String orig_ext = file_name.ext_; + Std_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]; - String found = find (file_name.to_string ()); - if (!found.is_empty ()) + Std_string found = find (file_name.to_string ()); + if (!found.empty ()) return found; } @@ -170,7 +170,7 @@ File_path::find (String name, char const *extensions[]) /** Append a directory, return false if failed. */ bool -File_path::try_append (String s) +File_path::try_append (Std_string s) { if (s == "") s = "."; @@ -182,10 +182,10 @@ File_path::try_append (String s) return false; } -String +Std_string File_path::to_string () const { - String s; + Std_string s; for (int i = 0; i < dirs_.size (); i++) { s = s + dirs_[i]; @@ -196,13 +196,13 @@ File_path::to_string () const } void -File_path::append (String str) +File_path::append (Std_string str) { dirs_.push (str); } void -File_path::prepend (String str) +File_path::prepend (Std_string str) { dirs_.insert (str, 0); } diff --git a/flower/include/file-path.hh b/flower/include/file-path.hh index e63c5eb7fd..2399700232 100644 --- a/flower/include/file-path.hh +++ b/flower/include/file-path.hh @@ -10,7 +10,7 @@ #define FILE_PATH_HH #include "array.hh" -#include "string.hh" +#include "std-string.hh" /** search in directories for a file. @@ -23,19 +23,19 @@ class File_path { - Array dirs_; + 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); - void parse_path (String); - void prepend (String str); + Array directories () const; + Std_string find (Std_string name) const; + Std_string find (Std_string name, char const *extensions[]); + Std_string to_string () const; + bool try_append (Std_string str); + void append (Std_string str); + void parse_path (Std_string); + void prepend (Std_string str); }; -bool is_file (String file_name); -bool is_dir (String file_name); +bool is_file (Std_string file_name); +bool is_dir (Std_string file_name); #endif /* FILE_PATH */ diff --git a/flower/include/std-string.hh b/flower/include/std-string.hh index d2b2ffd1a3..129cf4dfc7 100644 --- a/flower/include/std-string.hh +++ b/flower/include/std-string.hh @@ -18,7 +18,7 @@ #else #include -#warning Using std::string +// #warning Using std::string namespace std { diff --git a/lily/includable-lexer.cc b/lily/includable-lexer.cc index 243938bc02..a8edb0f16d 100644 --- a/lily/includable-lexer.cc +++ b/lily/includable-lexer.cc @@ -58,7 +58,7 @@ Includable_lexer::new_input (String name, Sources *sources) String msg = _f ("can't find file: `%s'", name); msg += "\n"; msg += _f ("(search path: `%s')", - sources->path_->to_string ().to_str0 ()); + sources->path_->to_string ().c_str ()); LexerError (msg.to_str0 ()); return; } diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index 689b694641..f7eac0e9f1 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -90,19 +90,19 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", String out_file = out_file_name.to_string (); - if (init.length () && global_path.find (init).is_empty ()) + if (init.length () && global_path.find (init).empty ()) { warning (_f ("can't find init file: `%s'", init)); warning (_f ("(search path: `%s')", - global_path.to_string ().to_str0 ())); + global_path.to_string ().c_str ())); exit (2); } - if ((file_name != "-") && global_path.find (file_name).is_empty ()) + if ((file_name != "-") && global_path.find (file_name).empty ()) { warning (_f ("can't find file: `%s'", file_name)); scm_throw (ly_symbol2scm ("ly-file-failed"), - scm_list_1 (scm_makfrom0str (file_name.to_str0 ()))); + scm_list_1 (scm_makfrom0str (file_name.c_str ()))); } else { diff --git a/lily/relocate.cc b/lily/relocate.cc index 1c6c422ad1..fec75ee470 100644 --- a/lily/relocate.cc +++ b/lily/relocate.cc @@ -211,7 +211,7 @@ setup_paths (char const *argv0_ptr) if (be_verbose_global) warning (_f ("Relocation: from PATH=%s\nargv0=%s", - path.to_string ().get_str0 (), argv0_ptr)); + path.to_string ().c_str (), argv0_ptr)); #ifndef __MINGW32__ argv0_abs = path.find (argv0_filename.to_string ()); diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc index 37fbced6c2..e45a99676c 100644 --- a/lily/score-engraver.cc +++ b/lily/score-engraver.cc @@ -66,7 +66,7 @@ Score_engraver::initialize () + "\n" + _ ("Music font has not been installed properly.") + "\n" - + _f ("Search path `%s'", global_path.to_string ().to_str0 ()) + + _f ("Search path `%s'", global_path.to_string ().c_str ()) + "\n" + _ ("Aborting")); } -- 2.39.5