Fixed the file path stuff. Don't show the bootstrap warning when .svn is present.
authordarco <darco@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Mon, 11 Apr 2005 23:47:01 +0000 (23:47 +0000)
committerdarco <darco@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Mon, 11 Apr 2005 23:47:01 +0000 (23:47 +0000)
git-svn-id: http://svn.voria.com/code@15 1f10aa63-cdf2-0310-b900-c93c546f37ac

ETL/trunk/ETL/_stringf.h
ETL/trunk/bootstrap
ETL/trunk/test/stringf.cpp

index 21a7190..61621ac 100644 (file)
@@ -197,7 +197,7 @@ inline bool
 is_absolute_path(const std::string &path)
 {
 #ifdef WIN32
-       if(path.size()>=3 && path[1]==':' && path[2]=='\\')
+       if(path.size()>=3 && path[1]==':' && (path[2]=='\\' || path[2]=='/'))
                return true;
        return false;
 #else
@@ -248,7 +248,7 @@ get_root_from_path(std::string path)
                        break;
                ret+=*iter;
        }
-       if(iter!=path.end())
+       //if(iter!=path.end())
                ret+=ETL_DIRECTORY_SEPERATOR;
        return ret;
 }
@@ -289,6 +289,7 @@ cleanup_path(std::string path)
                path=remove_root_from_path(path);
        }
        
+       // Remove any trailing directory seperators
        if(ret.size() && ret[ret.size()-1]==ETL_DIRECTORY_SEPERATOR)
        {
                ret.erase(ret.begin()+ret.size()-1);
@@ -323,6 +324,20 @@ relative_path(std::string curr_path,std::string dest_path)
                curr_path=absolute_path(curr_path);
        else
                curr_path=cleanup_path(curr_path);
+
+#ifdef WIN32
+       // If we are on windows and the dest path is on a different drive,
+       // then there is no way to make a relative path to it.
+       if(dest_path.size()>=3 && dest_path[1]==':' && dest_path[0]!=curr_path[0])
+       {
+               return dest_path;
+       }
+#endif
+
+       if(curr_path==dirname(dest_path))
+       {
+               return basename(dest_path);
+       }
        
        while(!dest_path.empty() && !curr_path.empty() && get_root_from_path(dest_path)==get_root_from_path(curr_path))
        {
index 533c02d..bba9c4a 100755 (executable)
@@ -54,7 +54,7 @@ output Prepairing build environment for $PACKAGE-$VERSION...
 
 # Look for the CVS directory. If we don't find it, we need to
 # ask the user if they know what they are doing.
-test -d CVS ||
+( test -d CVS || test -d .svn ) ||
 {
        echo "
 $BOOTSTRAP_NAME: warning: This shell script is intended for those
index 3a666a3..4312016 100644 (file)
@@ -109,7 +109,26 @@ int relative_path_test()
        if(relative_path(curr_path,dest_path)!=unix_to_local_path("../../share"))
                cerr<<"Bad relative path"<<endl,ret++;
 
+       cout<<endl;
+
+       curr_path=unix_to_local_path("/home/darco/projects/voria");
+       dest_path=unix_to_local_path("/home/darco/projects/voria/myfile.txt");
+       cout<<"curr_path="<<curr_path<<" dest_path="<<dest_path<<endl;
+       cout<<"relative_path="<<relative_path(curr_path,dest_path)<<endl;
+       if(relative_path(curr_path,dest_path)!=unix_to_local_path("myfile.txt"))
+               cerr<<"Bad relative path"<<endl,ret++;
        
+       cout<<endl;
+
+       curr_path=unix_to_local_path("/home/darco/projects/voria");
+       dest_path=unix_to_local_path("/home/darco/projects/voria/files/myfile.txt");
+       cout<<"curr_path="<<curr_path<<" dest_path="<<dest_path<<endl;
+       cout<<"relative_path="<<relative_path(curr_path,dest_path)<<endl;
+       if(relative_path(curr_path,dest_path)!=unix_to_local_path("files/myfile.txt"))
+               cerr<<"Bad relative path"<<endl,ret++;
+       
+       cout<<endl;
+
        curr_path=unix_to_local_path("/usr/local/../include/sys/../linux/linux.h");
        cout<<"dirty_path="<<curr_path<<endl;
        cout<<"clean_path="<<cleanup_path(curr_path)<<endl;