]> git.lyx.org Git - lyx.git/blobdiff - src/support/os_cygwin.cpp
add onoff support for "inset-modify changetype xxx" in include inset
[lyx.git] / src / support / os_cygwin.cpp
index d8d052fe97c46b6ddd7acd984437c301469c8279..8ffaef55e4cd69ae9e62b9fa17f0a0d9f0008a20 100644 (file)
@@ -6,6 +6,7 @@
  * \author Ruurd A. Reitsma
  * \author Claus Hentschel
  * \author Angus Leeming
+ * \author Enrico Forestieri
  *
  * Full author contact details are available in file CREDITS.
  *
 #include <config.h>
 
 #include "support/os.h"
-#include "support/lstrings.h"
 
-#include "debug.h"
+#include "support/FileName.h"
+#include "support/lstrings.h"
+#include "support/debug.h"
 
 #include <windows.h>
 #include <io.h>
 #include <windef.h>
 #include <shellapi.h>
 #include <shlwapi.h>
+#include <limits.h>
+#include <stdlib.h>
 
 #include <sys/cygwin.h>
 
-using std::endl;
-using std::string;
-
-using lyx::support::contains;
-
-#ifdef X_DISPLAY_MISSING
-#include "support/filetools.h"
-#include "support/Package.h"
-#include "support/Path.h"
-using lyx::support::addName;
-using lyx::support::addPath;
-using lyx::support::package;
-
-// API definition for manually calling font functions on Windows 2000 and later
-typedef int (WINAPI *FONTAPI)(LPCSTR, DWORD, PVOID);
-#define FR_PRIVATE     0x10
-
-// Names of TrueType fonts to load
-string const win_fonts_truetype[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
-       "eufm10", "msam10", "msbm10", "wasy10", "esint10"};
-const int num_fonts_truetype = sizeof(win_fonts_truetype) / sizeof(*win_fonts_truetype);
-#endif
-
+using namespace std;
 
 namespace lyx {
 namespace support {
@@ -143,23 +125,12 @@ string convert_path_list(string const & p, PathStyle const & target)
 
 } // namespace anon
 
-void os::init(int, char *[])
+void init(int, char *[])
 {
        // Make sure that the TEMP variable is set
        // and sync the Windows environment.
 
-       char **envp = environ;
-       string var;
-       bool temp_seen = false;
-
-       while (envp && *envp && !temp_seen) {
-               split(*envp++, var, '=');
-               if (var == "TEMP")
-                       temp_seen = true;
-       }
-       if (!temp_seen)
-               ::setenv("TEMP", "/tmp", true);
-
+       setenv("TEMP", "/tmp", false);
        cygwin_internal(CW_SYNC_WINENV);
 }
 
@@ -170,6 +141,12 @@ string current_root()
 }
 
 
+bool isFilesystemCaseSensitive()
+{
+       return false;
+}
+
+
 docstring::size_type common_path(docstring const & p1, docstring const & p2)
 {
        docstring::size_type i = 0;
@@ -190,6 +167,38 @@ docstring::size_type common_path(docstring const & p1, docstring const & p2)
 }
 
 
+bool path_prefix_is(string const & path, string const & pre)
+{
+       return path_prefix_is(const_cast<string &>(path), pre, CASE_UNCHANGED);
+}
+
+
+bool path_prefix_is(string & path, string const & pre, path_case how)
+{
+       docstring const p1 = from_utf8(path);
+       docstring const p2 = from_utf8(pre);
+       docstring::size_type const p1_len = p1.length();
+       docstring::size_type const p2_len = p2.length();
+       docstring::size_type common_len = common_path(p1, p2);
+
+       if (p2[p2_len - 1] == '/' && p1_len != p2_len)
+               ++common_len;
+
+       if (common_len != p2_len)
+               return false;
+
+       if (how == CASE_ADJUSTED && !prefixIs(path, pre)) {
+               if (p1_len < common_len)
+                       path = to_utf8(p2.substr(0, p1_len));
+               else
+                       path = to_utf8(p2 + p1.substr(common_len,
+                                                       p1_len - common_len));
+       }
+
+       return true;
+}
+
+
 string external_path(string const & p)
 {
        return convert_path(p, PathStyle(posix));
@@ -220,12 +229,10 @@ string latex_path(string const & p)
        // on windows_style_tex_paths_), but we use always forward slashes,
        // since it gets written into a .tex file.
 
-       if (windows_style_tex_paths_ && is_absolute_path(p)) {
+       if (windows_style_tex_paths_ && FileName::isAbsolute(p)) {
                string dos_path = convert_path(p, PathStyle(windows));
-               LYXERR(Debug::LATEX)
-                       << "<Path correction for LaTeX> ["
-                       << p << "]->>["
-                       << dos_path << ']' << endl;
+               LYXERR(Debug::LATEX, "<Path correction for LaTeX> ["
+                       << p << "]->>[" << dos_path << ']');
                return dos_path;
        }
 
@@ -233,15 +240,20 @@ string latex_path(string const & p)
 }
 
 
-bool is_absolute_path(string const & p)
+bool is_valid_strftime(string const & p)
 {
-       if (p.empty())
-               return false;
-
-       bool isDosPath = (p.length() > 1 && p[1] == ':');
-       bool isUnixPath = (p[0] == '/');
-
-       return isDosPath || isUnixPath;
+       string::size_type pos = p.find_first_of('%');
+       while (pos != string::npos) {
+               if (pos + 1 == string::npos)
+                       break;
+               if (!containsOnly(p.substr(pos + 1, 1),
+                       "aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyYzZ%+"))
+                       return false;
+               if (pos + 2 == string::npos)
+                     break;
+               pos = p.find_first_of('%', pos + 2);
+       }
+       return true;
 }
 
 
@@ -260,6 +272,12 @@ string const & nulldev()
 }
 
 
+bool is_terminal(io_channel channel)
+{
+       return isatty(channel);
+}
+
+
 shell_type shell()
 {
        return UNIX;
@@ -287,18 +305,16 @@ bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
 
        DWORD bufSize = MAX_PATH + 100;
        TCHAR buf[MAX_PATH + 100];
-       // reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc
-       //                 /platform/shell/reference/shlwapi/registry/assocquerystring.asp
+       // reference: http://msdn.microsoft.com/en-us/library/bb773471.aspx
        char const * action = (mode == VIEW) ? "open" : "edit";
-       return S_OK == AssocQueryString(0, ASSOCSTR_EXECUTABLE,
-               full_ext.c_str(), action, buf, &bufSize);
+       return S_OK == AssocQueryString(ASSOCF_INIT_IGNOREUNKNOWN,
+               ASSOCSTR_EXECUTABLE, full_ext.c_str(), action, buf, &bufSize);
 }
 
 
 bool autoOpenFile(string const & filename, auto_open_mode const mode)
 {
-       // reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc
-       //                 /platform/shell/reference/functions/shellexecute.asp
+       // reference: http://msdn.microsoft.com/en-us/library/bb762153.aspx
        string const win_path = to_local8bit(from_utf8(convert_path(filename, PathStyle(windows))));
        char const * action = (mode == VIEW) ? "open" : "edit";
        return reinterpret_cast<int>(ShellExecute(NULL, action,
@@ -306,56 +322,11 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode)
 }
 
 
-void addFontResources()
+string real_path(string const & path)
 {
-#ifdef X_DISPLAY_MISSING
-       // Windows only: Add BaKoMa TrueType font resources
-       string const fonts_dir = addPath(package().system_support().absFilename(), "fonts");
-
-       HMODULE hDLL = LoadLibrary("gdi32");
-       FONTAPI pAddFontResourceEx =
-               (FONTAPI) GetProcAddress(hDLL, "AddFontResourceExA");
-
-       for (int i = 0 ; i < num_fonts_truetype ; ++i) {
-               string const font_current = to_local8bit(from_utf8(convert_path(
-                       addName(fonts_dir, win_fonts_truetype[i] + ".ttf"),
-                       PathStyle(windows))));
-               if (pAddFontResourceEx) {
-                       // Windows 2000 and later: Use AddFontResourceEx
-                       pAddFontResourceEx(font_current.c_str(), FR_PRIVATE, 0);
-               } else {
-                       // Older Windows versions: Use AddFontResource
-                       AddFontResource(font_current.c_str());
-               }
-       }
-       FreeLibrary(hDLL);
-#endif
-}
-
-
-void restoreFontResources()
-{
-#ifdef X_DISPLAY_MISSING
-       // Windows only: Remove BaKoMa TrueType font resources
-       string const fonts_dir = addPath(package().system_support().absFilename(), "fonts");
-
-       HMODULE hDLL = LoadLibrary("gdi32");
-       FONTAPI pRemoveFontResourceEx = (FONTAPI) GetProcAddress(hDLL, "RemoveFontResourceExA");
-
-       for(int i = 0 ; i < num_fonts_truetype ; ++i) {
-               string const font_current = to_local8bit(from_utf8(convert_path(
-                       addName(fonts_dir, win_fonts_truetype[i] + ".ttf"),
-                       PathStyle(windows))));
-               if (pRemoveFontResourceEx) {
-                       // Windows 2000 and later: Use RemoveFontResourceEx
-                       pRemoveFontResourceEx(font_current.c_str(), FR_PRIVATE, 0);
-               } else {
-                       // Older Windows versions: Use RemoveFontResource
-                       RemoveFontResource(font_current.c_str());
-               }
-       }
-       FreeLibrary(hDLL);
-#endif
+       char rpath[PATH_MAX + 1];
+       char * result = realpath(path.c_str(), rpath);
+       return FileName::fromFilesystemEncoding(result ? rpath : path).absFilename();
 }
 
 } // namespace os