]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/file-name.cc
Merge with master
[lilypond.git] / flower / file-name.cc
index 41b3f96f3e1adda4e2e9de79068dfe955b443e7e..e5736e06b0834ed6c26e15e01f32d25d91682067 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the Flower Library
 
-  (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
   Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
@@ -11,6 +11,8 @@
 
 #include <cstdio>
 #include <cerrno>
+#include <unistd.h>
+
 using namespace std;
 
 #include "config.hh"
@@ -40,7 +42,7 @@ static string
 dos_to_posix (string file_name)
 {
   char buf[PATH_MAX] = "";
-  char s[PATH_MAX];
+  char s[PATH_MAX] = {0};
   file_name.copy (s, PATH_MAX - 1);
   /* ugh: char const* argument gets modified.  */
   int fail = cygwin_conv_to_posix_path (s, buf);
@@ -63,25 +65,73 @@ 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;
+  if (s.rfind ('/') != NPOS)
+    s = s.substr (0, s.rfind ('/'));
+  else
+    s = "";
+  
+  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
+File_name::dir_part () const
 {
   string s;
   if (!root_.empty ())
     s = root_ + ::to_string (ROOTSEP);
+
   if (!dir_.empty ())
     {
       s += dir_;
-      if (!base_.empty () || !ext_.empty ())
-       s += ::to_string (DIRSEP);
     }
-  s += base_;
+
+  return s;
+}
+
+
+string
+File_name::file_part () const
+{
+  string s;
+  s = base_;
   if (!ext_.empty ())
     s += ::to_string (EXTSEP) + ext_;
   return s;
 }
 
+string
+File_name::to_string () const
+{
+  string d = dir_part ();
+  string f = file_part ();
+
+  if (!f.empty ()
+      && !dir_.empty())
+    {
+      d += ::to_string (DIRSEP);
+    }
+
+  return d + f;
+}
+
 File_name::File_name (string file_name)
 {
 #ifdef __CYGWIN__