X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=flower%2Ffile-name.cc;h=be5e6d047ddb6e013ffeacbb7ed86d2fab332423;hb=6aeffdda6fca2cb56f901d65ea1d5dbeb398443e;hp=c26562664a7f110186da76bc3ea75afd40961cca;hpb=da000980e554ce4c2a4095d68c1a2be6bc714f7f;p=lilypond.git diff --git a/flower/file-name.cc b/flower/file-name.cc index c26562664a..be5e6d047d 100644 --- a/flower/file-name.cc +++ b/flower/file-name.cc @@ -1,18 +1,21 @@ /* file-name.cc - implement File_name - + source file of the Flower Library - - (c) 1997--2004 Han-Wen Nienhuys - Jan Nieuwenhuizen + + (c) 1997--2005 Han-Wen Nienhuys + Jan Nieuwenhuizen */ -#include "config.h" -#include -#include -#include +#include "file-name.hh" + +#include +#include +using namespace std; + +#include "config.hh" -#if HAVE_SYS_STAT_H +#if HAVE_SYS_STAT_H #include #endif @@ -20,9 +23,6 @@ #include #endif -#include "file-name.hh" - -/* We don't have multiple roots, set this to '\0'? */ #ifndef ROOTSEP #define ROOTSEP ':' #endif @@ -39,15 +39,29 @@ static String dos_to_posix (String file_name) { - char buf[PATH_MAX]; + char buf[PATH_MAX] = ""; char *s = file_name.get_copy_str0 (); - /* urg, wtf? char const* argument gets modified! */ - cygwin_conv_to_posix_path (s, buf); + /* ugh: char const* argument gets modified. */ + int fail = cygwin_conv_to_posix_path (s, buf); delete s; - return buf; + if (!fail) + return buf; + return file_name; } #endif /* __CYGWIN__ */ +#ifdef __MINGW32__ +/** Use slash as directory separator. On Windows, they can pretty + much be exchanged. */ +static String +slashify (String file_name) +{ + file_name.substitute ('\\', '/'); + file_name.substitute ("//", "/"); + return file_name; +} +#endif /* __MINGW32__ */ + /* Join components to full file_name. */ String File_name::to_string () const @@ -56,27 +70,28 @@ File_name::to_string () const if (!root_.is_empty ()) s = root_ + ::to_string (ROOTSEP); if (!dir_.is_empty ()) - s += dir_ + ::to_string (DIRSEP); + { + s += dir_; + if (!base_.is_empty () || !ext_.is_empty ()) + s += ::to_string (DIRSEP); + } s += base_; if (!ext_.is_empty ()) s += ::to_string (EXTSEP) + ext_; return s; } -char const* -File_name::to_str0 () const -{ - return to_string ().to_str0 (); -} - File_name::File_name (String file_name) { #ifdef __CYGWIN__ - /* All system functions would work, even if we don't convert to - posix file_name, but we'd think that \foe\bar\baz.ly is in the cwd. - On by default. */ + /* All system functions would work, even if we do not convert to + posix file_name, but we would think that \foe\bar\baz.ly is in + the cwd. */ file_name = dos_to_posix (file_name); #endif +#ifdef __MINGW32__ + file_name = slashify (file_name); +#endif int i = file_name.index (ROOTSEP); if (i >= 0) @@ -101,3 +116,12 @@ File_name::File_name (String file_name) else base_ = file_name; } + +bool +File_name::is_absolute () const +{ + /* + Hmm. Is c:foo absolute? + */ + return (dir_.length () && dir_[0] == DIRSEP) || root_.length (); +}