]> git.lyx.org Git - lyx.git/blobdiff - src/support/filetools.C
remove !NEW_INSETS cruft
[lyx.git] / src / support / filetools.C
index f4480d3b6cf884554de56200626227f84a3f7e89..d284417e243acb55f47bf4af750bbbc69d922679 100644 (file)
@@ -32,7 +32,6 @@
 #include "lyx_gui_misc.h"
 #include "FileInfo.h"
 #include "support/path.h"        // I know it's OS/2 specific (SMiyata)
-#include "support/syscall.h"
 #include "gettext.h"
 #include "lyxlib.h"
 
@@ -60,13 +59,6 @@ using std::endl;
 using std::ifstream;
 using std::vector;
 
-#if 0
-using std::getenv;
-using std::isalpha;
-using std::isalnum;
-using std::popen;
-#endif
-
 extern string system_lyxdir;
 extern string build_lyxdir;
 extern string user_lyxdir;
@@ -75,13 +67,13 @@ extern string system_tempdir;
 
 bool IsLyXFilename(string const & filename)
 {
-       return contains(filename, ".lyx");
+       return suffixIs(filename, ".lyx");
 }
 
 
 bool IsSGMLFilename(string const & filename)
 {
-       return contains(filename, ".sgml");
+       return suffixIs(filename, ".sgml");
 }
 
 
@@ -151,8 +143,10 @@ int IsFileWriteable (string const & path)
 //      -1: error- couldn't find out
 int IsDirWriteable (string const & path)
 {
-        string const tmpfl(lyx::tempName(path)); //TmpFileName(path));
-
+        string const tmpfl(lyx::tempName(path, "lyxwritetest"));
+       // We must unlink the tmpfl.
+       lyx::unlink(tmpfl);
+       
        if (tmpfl.empty()) {
                WriteFSAlert(_("LyX Internal Error!"), 
                             _("Could not test if directory is writeable"));
@@ -380,7 +374,8 @@ bool PutEnvPath(string const & envstr)
 }
 
 
-static
+namespace {
+
 int DeleteAllFilesInDir (string const & path)
 {
        // I have decided that we will be using parts from the boost
@@ -433,7 +428,6 @@ int DeleteAllFilesInDir (string const & path)
 }
 
 
-static
 string const CreateTmpDir(string const & tempdir, string const & mask)
 {
        lyxerr[Debug::FILES]
@@ -447,7 +441,7 @@ string const CreateTmpDir(string const & tempdir, string const & mask)
        // safe because of the gap between unlink and mkdir. (Lgb)
        lyx::unlink(tmpfl.c_str());
        
-       if (tmpfl.empty() || lyx::mkdir(tmpfl, 0777)) {
+       if (tmpfl.empty() || lyx::mkdir(tmpfl, 0700)) {
                WriteFSAlert(_("Error! Couldn't create temporary directory:"),
                             tempdir);
                return string();
@@ -456,7 +450,6 @@ string const CreateTmpDir(string const & tempdir, string const & mask)
 }
 
 
-static
 int DestroyTmpDir(string const & tmpdir, bool Allfiles)
 {
 #ifdef __EMX__
@@ -469,7 +462,9 @@ int DestroyTmpDir(string const & tmpdir, bool Allfiles)
                return -1;
        }
        return 0; 
-} 
+}
+
+} // namespace anon
 
 
 string const CreateBufferTmpDir(string const & pathfor)
@@ -653,21 +648,6 @@ string const OnlyFilename(string const & fname)
 }
 
 
-// Strips filename from path
-string const BasePath(string const & fname)
-{
-       if (fname.empty())
-               return fname;
-
-       string::size_type j = fname.rfind('/');
-       if (j == string::npos) // no '/' in fname
-               return string();
-
-       // Strip to basename
-       return fname.substr(0,j + 1);
-}
-
-
 // Is a filename/path absolute?
 bool AbsolutePath(string const & path)
 {
@@ -940,12 +920,9 @@ string const AddPath(string const & path, string const & path_2)
                        buf += '/';
        }
 
-       if (!path2.empty()) {
-               string::size_type const p2start = path2.find_first_not_of('/');
-               string::size_type const p2end = path2.find_last_not_of('/');
-               string const tmp = path2.substr(p2start, p2end - p2start + 1);
-               buf += tmp + '/';
-       }
+       if (!path2.empty())
+               buf += frontStrip(strip(path2, '/'), '/') + '/';
+
        return buf;
 }
 
@@ -1053,8 +1030,10 @@ bool LyXReadLink(string const & File, string & Link)
 }
 
 
+namespace {
+
 typedef pair<int, string> cmdret;
-static
+
 cmdret const do_popen(string const & cmd)
 {
        // One question is if we should use popen or
@@ -1073,6 +1052,8 @@ cmdret const do_popen(string const & cmd)
        return make_pair(pret, ret);
 }
 
+} // namespace anon
+
 
 string const
 findtexfile(string const & fil, string const & /*format*/)