From 2dbaada733947bf4ac7c104f56b6090ee04a425d Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 15 Apr 2006 07:12:33 +0000 Subject: [PATCH] * lily/lily-parser-scheme.cc: Use them to fix --output=DIR/BASE pdf conversion behaviour. * flower/file-name.cc (dir_name) (get_working_directory): Move from relocate.cc. * lily/relocate.cc (setup_paths): Remove rogue stat calls. * lily/relocate.cc: Encapsulate sys/stat.h in HAVE_STAT_H. --- ChangeLog | 13 +++++++++++++ THANKS | 1 + flower/file-name.cc | 23 +++++++++++++++++++++++ flower/include/file-name.hh | 3 +++ lily/include/relocate.hh | 2 -- lily/lily-parser-scheme.cc | 21 +++++++++++---------- lily/relocate.cc | 30 ++---------------------------- 7 files changed, 53 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe4f2669d8..ae9e904f4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2006-04-15 Jan Nieuwenhuizen + + * lily/lily-parser-scheme.cc: Use them to fix --output=DIR/BASE + pdf conversion behaviour. + + * flower/file-name.cc (dir_name) + (get_working_directory): Move from relocate.cc. + + * lily/relocate.cc (setup_paths): Remove rogue stat calls. + + * lily/relocate.cc: Encapsulate sys/stat.h in + HAVE_STAT_H. + 2006-04-14 Graham Percival * Documentation/user/ various: small updates from Cameron diff --git a/THANKS b/THANKS index d3911ef02f..790a69688c 100644 --- a/THANKS +++ b/THANKS @@ -41,6 +41,7 @@ David Rogers J. Leung Harald Wellmann Orm Finnendahl +Rick Hansen Stephen Carter Werner Lemberg diff --git a/flower/file-name.cc b/flower/file-name.cc index 41b3f96f3e..66b1aaa114 100644 --- a/flower/file-name.cc +++ b/flower/file-name.cc @@ -11,6 +11,8 @@ #include #include +#include + using namespace std; #include "config.hh" @@ -63,6 +65,27 @@ slashify (string file_name) return file_name; } +string +dir_name (string const file_name) +{ + string s = file_name; + s = slashify (s); + ssize n = s.length (); + if (n && s[n - 1] == '/') + s[n - 1] = 0; + s = s.substr (0, s.rfind ('/')); + return s; +} + +string +get_working_directory () +{ + char cwd[PATH_MAX]; + getcwd (cwd, PATH_MAX); + + return string (cwd); +} + /* Join components to full file_name. */ string File_name::to_string () const diff --git a/flower/include/file-name.hh b/flower/include/file-name.hh index 5fcadc2ce3..edfa72c23f 100644 --- a/flower/include/file-name.hh +++ b/flower/include/file-name.hh @@ -12,6 +12,9 @@ #include "std-vector.hh" #include "std-string.hh" +std::string dir_name (std::string const file_name); +std::string get_working_directory (); + class File_name { public: diff --git a/lily/include/relocate.hh b/lily/include/relocate.hh index 18188e01b5..77929598e4 100644 --- a/lily/include/relocate.hh +++ b/lily/include/relocate.hh @@ -10,8 +10,6 @@ #ifndef RELOCATE_HH #define RELOCATE_HH - - #include "std-string.hh" int sane_putenv (char const *key, string value, bool overwrite); diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index 7603487665..1657438212 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -65,20 +65,21 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", if (!output_name_global.empty ()) { /* Interpret --output=DIR to mean --output=DIR/BASE. */ + string dir; if (is_dir (output_name_global)) { - char cwd[PATH_MAX]; - getcwd (cwd, PATH_MAX); - - if (output_name_global != cwd) - { - global_path.prepend (cwd); - message (_f ("Changing working directory to `%s'", - output_name_global.c_str ())); - chdir (output_name_global.c_str ()); - } + dir = output_name_global; output_name_global = ""; } + else + dir = dir_name (output_name_global); + if (dir != "" && dir != "." && dir != get_working_directory ()) + { + global_path.prepend (get_working_directory ()); + message (_f ("Changing working directory to `%s'", + dir.c_str ())); + chdir (dir.c_str ()); + } else out_file_name = File_name (output_name_global); } diff --git a/lily/relocate.cc b/lily/relocate.cc index aaf8bb4eca..6bfbc8ae57 100644 --- a/lily/relocate.cc +++ b/lily/relocate.cc @@ -11,9 +11,6 @@ #include "config.hh" -#include -#include - #if HAVE_GETTEXT #include #endif @@ -81,18 +78,6 @@ prepend_env_path (char const *key, string value) return -1; } -string -dir_name (string const file_name) -{ - string s = file_name; - replace_all (s, '\\', '/'); - ssize n = s.length (); - if (n && s[n - 1] == '/') - s[n - 1] = 0; - s = s.substr (0, s.rfind ('/')); - return s; -} - #ifdef __MINGW32__ #include #endif @@ -175,15 +160,6 @@ framework_relocation (string prefix) prepend_env_path ("PATH", bindir); } -string -get_working_directory () -{ - char cwd[PATH_MAX]; - getcwd (cwd, PATH_MAX); - - return string (cwd); -} - void setup_paths (char const *argv0_ptr) { @@ -274,14 +250,12 @@ setup_paths (char const *argv0_ptr) */ - struct stat statbuf; string build_prefix_current = prefix_directory + "/share/lilypond/" "current"; string build_prefix_version = prefix_directory + "/share/lilypond/" TOPLEVEL_VERSION; - if (stat (build_prefix_version.c_str (), &statbuf) == 0) + if (is_dir (build_prefix_version.c_str ())) prefix_directory = build_prefix_version; - else if (stat (build_prefix_current.c_str (), &statbuf) == 0) + else if (is_dir (build_prefix_current.c_str ())) prefix_directory = build_prefix_current; - /* Adding mf/out make lilypond unchanged source directory, when setting LILYPONDPREFIX to lilypond-x.y.z */ -- 2.39.2