X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Frelocate.cc;h=214e488f46339739400b6333a092e8ae42b4a9f2;hb=94dc81b1820c38ffb09ff47227d76b59cc6dd69c;hp=aac4ada90ad85c03bdf1a789533d893875646af0;hpb=712fe7b7888d891773ec5a3a78f15c357c3eae9b;p=lilypond.git diff --git a/lily/relocate.cc b/lily/relocate.cc index aac4ada90a..214e488f46 100644 --- a/lily/relocate.cc +++ b/lily/relocate.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 2005 Han-Wen Nienhuys + (c) 2005--2006 Han-Wen Nienhuys */ @@ -20,20 +20,23 @@ #include "file-name.hh" #include "file-path.hh" +#include "international.hh" #include "lily-guile.hh" #include "lily-version.hh" #include "main.hh" #include "version.hh" #include "warn.hh" +#define FRAMEWORKDIR ".." + int -sane_putenv (char const *key, String value, bool overwrite) +sane_putenv (char const *key, string value, bool overwrite) { if (overwrite || !getenv (key)) { - String combine = String (key) + "=" + value; - char *s = strdup (combine.to_str0 ()); + string combine = string (key) + "=" + value; + char *s = strdup (combine.c_str ()); return putenv (s); } @@ -41,7 +44,7 @@ sane_putenv (char const *key, String value, bool overwrite) } static int -set_env_file (char const *key, String value, bool overwrite = false) +set_env_file (char const *key, string value, bool overwrite = false) { if (is_file (value)) return sane_putenv (key, value, overwrite); @@ -51,7 +54,7 @@ set_env_file (char const *key, String value, bool overwrite = false) } static int -set_env_dir (char const *key, String value) +set_env_dir (char const *key, string value) { if (is_dir (value)) return sane_putenv (key, value, false); @@ -61,32 +64,32 @@ set_env_dir (char const *key, String value) } static int -prepend_env_path (char const *key, String value) +prepend_env_path (char const *key, string value) { if (is_dir (value)) { if (be_verbose_global) - progress_indication (_f ("%s=%s\n", key, value.to_str0 ())); + progress_indication (_f ("%s=%s\n", key, value.c_str ())); if (char const *cur = getenv (key)) value += to_string (PATHSEP) + cur; - return sane_putenv (key, value.to_str0 (), true); + return sane_putenv (key, value.c_str (), true); } else if (be_verbose_global) warning (_f ("no such directory: %s for %s", value, key)); return -1; } -String -dir_name (String const file_name) +string +dir_name (string const file_name) { - String s = file_name; - s.substitute ('\\', '/'); - int n = s.length (); + string s = file_name; + replace_all (s, '\\', '/'); + ssize n = s.length (); if (n && s[n - 1] == '/') s[n - 1] = 0; - s = s.left_string (s.index_last ('/')); + s = s.substr (0, s.rfind ('/')); return s; } @@ -95,39 +98,41 @@ dir_name (String const file_name) #endif void -prefix_relocation (String prefix) +prefix_relocation (string prefix) { if (be_verbose_global) warning (_f ("Relocation: compile prefix=%s, new prefix=%s", prefix_directory, - prefix.to_str0 ())); + prefix.c_str ())); - String bindir = prefix + "/bin"; - String datadir = prefix + "/share"; - String localedir = datadir + "/locale"; - String lilypond_datadir = datadir + "/lilypond/" TOPLEVEL_VERSION; + string bindir = prefix + "/bin"; + string datadir = prefix + "/share"; + string localedir = datadir + "/locale"; + string lilypond_datadir = datadir + "/lilypond/"; - if (is_dir (lilypond_datadir)) - prefix_directory = lilypond_datadir; + if (is_dir (lilypond_datadir + "/" + TOPLEVEL_VERSION)) + prefix_directory = lilypond_datadir + "/" + TOPLEVEL_VERSION; + else if (is_dir (lilypond_datadir + "/current")) + prefix_directory = lilypond_datadir + "/current"; #if HAVE_GETTEXT if (is_dir (localedir)) - bindtextdomain ("lilypond", localedir.to_str0 ()); + bindtextdomain ("lilypond", localedir.c_str ()); #endif prepend_env_path ("PATH", bindir); } void -framework_relocation (String prefix) +framework_relocation (string prefix) { if (be_verbose_global) warning (_f ("Relocation: framework_prefix=%s", prefix)); - String bindir = prefix + "/bin"; - String datadir = prefix + "/share"; - String libdir = prefix + "/lib"; - String sysconfdir = prefix + "/etc"; + string bindir = prefix + "/bin"; + string datadir = prefix + "/share"; + string libdir = prefix + "/lib"; + string sysconfdir = prefix + "/etc"; /* need otherwise dynamic .so's aren't found. */ prepend_env_path ("DYLD_LIBRARY_PATH", libdir); @@ -141,10 +146,20 @@ framework_relocation (String prefix) prepend_env_path ("GS_FONTPATH", font_dir); #endif - /* FIXME: *cough* 8.15 *cough* */ - prepend_env_path ("GS_FONTPATH", datadir + "/ghostscript/8.15/fonts"); - prepend_env_path ("GS_LIB", datadir + "/ghostscript/8.15/Resource"); - prepend_env_path ("GS_LIB", datadir + "/ghostscript/8.15/lib"); + string gs_version = +#ifdef GHOSTSCRIPT_VERSION + GHOSTSCRIPT_VERSION +#else + "ghostscript-version-undefined" +#endif + ; + + if (char const *cur = getenv ("LILYPOND_GS_VERSION")) + gs_version = cur; + + prepend_env_path ("GS_FONTPATH", datadir + "/ghostscript/" + gs_version + "/fonts"); + prepend_env_path ("GS_LIB", datadir + "/ghostscript/" + gs_version + "/Resource"); + prepend_env_path ("GS_LIB", datadir + "/ghostscript/" + gs_version + "/lib"); prepend_env_path ("GS_FONTPATH", datadir + "/gs/fonts"); prepend_env_path ("GS_LIB", datadir + "/gs/Resource"); @@ -160,13 +175,13 @@ framework_relocation (String prefix) prepend_env_path ("PATH", bindir); } -String +string get_working_directory () { char cwd[PATH_MAX]; getcwd (cwd, PATH_MAX); - return String (cwd); + return string (cwd); } void @@ -178,18 +193,18 @@ setup_paths (char const *argv0_ptr) if (relocate_binary && getenv ("LILYPOND_RELOCATE_PREFIX")) { - String prefix = getenv ("LILYPOND_RELOCATE_PREFIX"); + string prefix = getenv ("LILYPOND_RELOCATE_PREFIX"); #ifdef __MINGW32__ /* Normalize file name. */ - prefix = File_name (prefix).to_string ().get_copy_str0 (); + prefix = File_name (prefix).to_string (); #endif /* __MINGW32__ */ prefix_relocation (prefix); - String bindir = prefix + "/bin"; - framework_relocation (bindir + "/" FRAMEWORKDIR); + string bindir = prefix + "/bin"; + framework_relocation (bindir); } else if (relocate_binary) { - String argv0_abs; + string argv0_abs; if (argv0_filename.is_absolute ()) { argv0_abs = argv0_filename.to_string (); @@ -199,7 +214,7 @@ setup_paths (char const *argv0_ptr) else if (argv0_filename.dir_.length ()) { argv0_abs = get_working_directory () - + "/" + String (argv0_filename.to_string ()); + + "/" + string (argv0_filename.to_string ()); if (be_verbose_global) warning (_f ("Relocation: from cwd: argv0=%s", argv0_ptr)); } @@ -211,7 +226,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 ()); @@ -220,27 +235,29 @@ setup_paths (char const *argv0_ptr) argv0_abs = path.find (argv0_filename.to_string (), ext); #endif /* __MINGW32__ */ - if (argv0_abs.is_empty ()) + if (argv0_abs.empty ()) programming_error ("can't find absolute argv0."); } - String bindir = dir_name (argv0_abs); - String argv0_prefix = dir_name (bindir); - String compile_prefix = dir_name (dir_name (dir_name (prefix_directory))); + string bindir = dir_name (argv0_abs); + string argv0_prefix = dir_name (bindir); + string compile_prefix = dir_name (dir_name (dir_name (prefix_directory))); if (argv0_prefix != compile_prefix) prefix_relocation (argv0_prefix); - if (argv0_prefix != compile_prefix || String (FRAMEWORKDIR) != "..") - framework_relocation (bindir + "/" FRAMEWORKDIR); + if (argv0_prefix != compile_prefix || string (FRAMEWORKDIR) != "..") + framework_relocation (bindir + "/" + FRAMEWORKDIR); } /* FIXME: use LILYPOND_DATADIR. */ if (char const *env = getenv ("LILYPONDPREFIX")) { + #ifdef __MINGW32__ /* Normalize file name. */ - env = File_name (env).to_string ().get_copy_str0 (); -#endif + prefix_directory = File_name (env).to_string (); +#else prefix_directory = env; +#endif } global_path.append (""); @@ -258,9 +275,12 @@ setup_paths (char const *argv0_ptr) */ struct stat statbuf; - String build_prefix = prefix_directory + "/share/lilypond/" TOPLEVEL_VERSION; - if (stat (build_prefix.to_str0 (), &statbuf) == 0) - prefix_directory = build_prefix; + 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) + prefix_directory = build_prefix_version; + else if (stat (build_prefix_current.c_str (), &statbuf) == 0) + prefix_directory = build_prefix_current; /* Adding mf/out make lilypond unchanged source directory, when setting @@ -268,18 +288,18 @@ setup_paths (char const *argv0_ptr) char *suffixes[] = {"ly", "ps", "scm", 0 }; - Array dirs; + vector dirs; for (char **s = suffixes; *s; s++) { - String path = prefix_directory + to_string ('/') + String (*s); - dirs.push (path); + string path = prefix_directory + to_string ('/') + string (*s); + dirs.push_back (path); } - dirs.push (prefix_directory + "/fonts/otf/"); - dirs.push (prefix_directory + "/fonts/type1/"); - dirs.push (prefix_directory + "/fonts/svg/"); + dirs.push_back (prefix_directory + "/fonts/otf/"); + dirs.push_back (prefix_directory + "/fonts/type1/"); + dirs.push_back (prefix_directory + "/fonts/svg/"); - for (int i = 0; i < dirs.size (); i++) + for (vsize i = 0; i < dirs.size (); i++) global_path.prepend (dirs[i]); }