]> git.lyx.org Git - lyx.git/blobdiff - src/support/filetools.C
lyxserver cleanup patch + andre's small patches
[lyx.git] / src / support / filetools.C
index 3eef6694eac377d02f048edf86439627f3df1827..e21eb0da48ea38efb9e676111929fdc332b3beb2 100644 (file)
@@ -6,7 +6,7 @@
         Parts Copyright 1985, 1990, 1993 Free Software Foundation, Inc.
        Parts Copyright 1996 Asger Alstrup
        
-       See also filetools.H.
+       See also filetools.h.
 
        lyx-filetool.C : tools functions for file/path handling
        this file is part of LyX, the High Level Word Processor
@@ -292,7 +292,22 @@ string const
 i18nLibFileSearch(string const & dir, string const & name, 
                  string const & ext)
 {
-       string const lang = token(string(GetEnv("LANG")), '_', 0);
+       // this comment is from intl/dcigettext.c. We try to mimick this
+       // behaviour here.  
+       /* The highest priority value is the `LANGUAGE' environment
+           variable. But we don't use the value if the currently
+           selected locale is the C locale. This is a GNU extension. */
+
+       string const lc_all = GetEnv("LC_ALL");
+       string lang = GetEnv("LANGUAGE");
+       if (lang.empty() || lc_all == "C") {
+               lang = lc_all;
+               if (lang.empty()) {
+                       lang = GetEnv("LANG");
+               }
+       }
+       
+       lang = token(lang, '_', 0);
        
        if (lang.empty() || lang == "C")
                return LibFileSearch(dir, name, ext);
@@ -557,7 +572,7 @@ string const OnlyPath(string const & Filename)
 string const MakeAbsPath(string const & RelPath, string const & BasePath)
 {
        // checks for already absolute path
-       if (AbsolutePath(RelPath))
+       if (os::is_absolute_path(RelPath))
                return RelPath;
 
        // Copies given paths
@@ -567,7 +582,7 @@ string const MakeAbsPath(string const & RelPath, string const & BasePath)
 
        string TempBase;
 
-       if (AbsolutePath(BasePath))
+       if (os::is_absolute_path(BasePath))
                TempBase = BasePath;
        else
                TempBase = AddPath(lyx::getcwd(), BasePath);
@@ -651,24 +666,21 @@ string const OnlyFilename(string const & fname)
 }
 
 
-// Is a filename/path absolute?
+/// Returns true is path is absolute
 bool AbsolutePath(string const & path)
 {
-#ifndef __EMX__
-       return (!path.empty() && path[0] == '/');
-#else
-       return (!path.empty() && isalpha(static_cast<unsigned char>(path[0])) && path.length() > 1 && path[1] == ':');
-#endif
+       return os::is_absolute_path(path);
 }
 
 
+
 // Create absolute path. If impossible, don't do anything
 // Supports ./ and ~/. Later we can add support for ~logname/. (Asger)
 string const ExpandPath(string const & path)
 {
        // checks for already absolute path
        string RTemp(ReplaceEnvironmentPath(path));
-       if (AbsolutePath(RTemp))
+       if (os::is_absolute_path(RTemp))
                return RTemp;
 
        string Temp;
@@ -698,7 +710,7 @@ string const NormalizePath(string const & path)
        string RTemp;
        string Temp;
 
-       if (AbsolutePath(path))
+       if (os::is_absolute_path(path))
                RTemp = path;
        else
                // Make implicit current directory explicit
@@ -958,7 +970,7 @@ MakeDisplayPath (string const & path, unsigned int threshold)
 
        // If we backup from home or don't have a relative path,
        // this try is no good
-       if (prefixIs(relhome, "../") || AbsolutePath(relhome)) {
+       if (prefixIs(relhome, "../") || os::is_absolute_path(relhome)) {
                // relative path was no good, just use the original path
                relhome = path;
                l2 = l1;
@@ -1076,11 +1088,8 @@ findtexfile(string const & fil, string const & /*format*/)
         lyxerr[Debug::LATEX] << "kpse status = " << c.first << "\n"
                             << "kpse result = `" << strip(c.second, '\n') 
                             << "'" << endl;
-       string fullpath;
        if (c.first != -1) 
-               fullpath = os::internal_path(strip(strip(c.second,
-                                                        '\n'),
-                                                  '\r'));
+               return os::internal_path(strip(strip(c.second, '\n'), '\r'));
        else
                return string();
 }