On Fri, Jan 12, 2007 at 05:55:20PM +0100, Georg Baum wrote:

> Enrico Forestieri wrote:
> 
> > as a parameter introducer. To tell you the truth, the cygwin version
> > of lyx that I make available for download is patched such that through
> > an env variable it is possible to use either posix or windows style
> > paths.
> 
> Making a binary created from patched sources available is very bad IMO.

Thanks for your opinion. So, you are saying that if I find that a patch
does something useful I should not share it with others.

> Either this patch is for your personal convenience, then you should not
> make the binary available, or it is useful in general, then the patch
> should be included in the official version.

I find this to be a somewhat hypocritical attitude, as I tried to have
accepted a similar patch but it was rejected. But maybe when you say
"useful in general" you mean that it must be useful for all platforms
an not for a particular one (which is not yours).

> I don't know if the README in the package talks about the patch and where to
> get it, but if it does not then you are even breaking the GPL.

Now you are going a bit above the lines (even for a Friday).
Please, find attached the patch in question. As you can see it does not
introduce changed behaviour or anything else. Perhaps I forgot to put it
on the wiki, and you could have suggested that I should do it, instead
of going through a hideous legalese. But I take it as a Friday statement.

-- 
Enrico
Index: src/frontends/qt2/qfont_loader.C
===================================================================
--- src/frontends/qt2/qfont_loader.C    (revision 15112)
+++ src/frontends/qt2/qfont_loader.C    (working copy)
@@ -102,7 +102,11 @@ void FontLoader::initFontPath()
        for (int i = 0 ; i < num_fonts_truetype ; ++i) {
                string const font_current = 
                        AddName(fonts_dir, win_fonts_truetype[i] + ".ttf");
+#if defined(__CYGWIN__) || defined(__CYGWIN32__)
+               AddFontResource(os::windows_path(font_current).c_str());
+#else
                AddFontResource(os::external_path(font_current).c_str());
+#endif
        }
 #endif
 }
@@ -115,7 +119,11 @@ FontLoader::~FontLoader() {
        for(int i = 0 ; i < num_fonts_truetype ; ++i) {
                string const font_current = 
                        AddName(fonts_dir, win_fonts_truetype[i] + ".ttf");
+#if defined(__CYGWIN__) || defined(__CYGWIN32__)
+               RemoveFontResource(os::windows_path(font_current).c_str());
+#else
                RemoveFontResource(os::external_path(font_current).c_str());
+#endif
        }
 #endif
 }
Index: src/frontends/qt2/FileDialog.C
===================================================================
--- src/frontends/qt2/FileDialog.C      (revision 15112)
+++ src/frontends/qt2/FileDialog.C      (working copy)
@@ -20,6 +20,7 @@
 #include "gettext.h"
 
 #include "support/filefilterlist.h"
+#include "support/os.h"
 
 /** when this is defined, the code will use
  * QFileDialog::getOpenFileName and friends to create filedialogs.
@@ -30,7 +31,7 @@
  *
  * Therefore there is a tradeoff in enabling or disabling this (JMarc)
  */
-#ifdef Q_WS_MACX
+#if defined(Q_WS_MACX) || defined(Q_CYGWIN_WIN)
 #define USE_NATIVE_FILEDIALOG 1
 #endif
 
@@ -42,6 +43,8 @@ using lyx::support::MakeAbsPath;
 
 using lyx::support::FileFilterList;
 
+using lyx::support::os::internal_path;
+
 using std::endl;
 using std::string;
 
@@ -80,11 +83,11 @@ FileDialog::Result const FileDialog::sav
 
 #ifdef USE_NATIVE_FILEDIALOG
        string const startsWith = MakeAbsPath(suggested, path);
-       result.second = fromqstr(
+       result.second = internal_path(fromqstr(
                QFileDialog::getSaveFileName(toqstr(startsWith),
                                             toqstr(filters.as_string()),
                                             qApp->focusWidget() ? 
qApp->focusWidget() : qApp->mainWidget(),
-                                            title_.c_str()));
+                                            title_.c_str())));
 #else
        LyXFileDialog dlg(path, filters, title_, private_->b1, private_->b2);
        dlg.setMode(QFileDialog::AnyFile);
@@ -96,7 +99,7 @@ FileDialog::Result const FileDialog::sav
        int res = dlg.exec();
        lyxerr[Debug::GUI] << "result " << res << endl;
        if (res == QDialog::Accepted)
-               result.second = fromqstr(dlg.selectedFile());
+               result.second = internal_path(fromqstr(dlg.selectedFile()));
        dlg.hide();
 #endif
        return result;
@@ -115,11 +118,11 @@ FileDialog::Result const FileDialog::ope
 
 #ifdef USE_NATIVE_FILEDIALOG
        string const startsWith = MakeAbsPath(suggested, path);
-       result.second = fromqstr(
+       result.second = internal_path(fromqstr(
                QFileDialog::getOpenFileName(toqstr(startsWith),
                                             toqstr(filters.as_string()),
                                             qApp->focusWidget() ? 
qApp->focusWidget() : qApp->mainWidget(),
-                                            title_.c_str()));
+                                            title_.c_str())));
 #else
        LyXFileDialog dlg(path, filters, title_, private_->b1, private_->b2);
 
@@ -130,7 +133,7 @@ FileDialog::Result const FileDialog::ope
        int res = dlg.exec();
        lyxerr[Debug::GUI] << "result " << res << endl;
        if (res == QDialog::Accepted)
-               result.second = fromqstr(dlg.selectedFile());
+               result.second = internal_path(fromqstr(dlg.selectedFile()));
        dlg.hide();
 #endif
        return result;
@@ -147,10 +150,10 @@ FileDialog::Result const FileDialog::ope
 
 #ifdef USE_NATIVE_FILEDIALOG
        string const startsWith = MakeAbsPath(suggested, path);
-       result.second = fromqstr(
+       result.second = internal_path(fromqstr(
                QFileDialog::getExistingDirectory(toqstr(startsWith),
                                                  qApp->focusWidget() ? 
qApp->focusWidget() : qApp->mainWidget(),
-                                                 title_.c_str()));
+                                                 title_.c_str())));
 #else
        FileFilterList const filter(_("Directories"));
 
@@ -165,7 +168,7 @@ FileDialog::Result const FileDialog::ope
        int res = dlg.exec();
        lyxerr[Debug::GUI] << "result " << res << endl;
        if (res == QDialog::Accepted)
-               result.second = fromqstr(dlg.selectedFile());
+               result.second = internal_path(fromqstr(dlg.selectedFile()));
        dlg.hide();
 #endif
        return result;
Index: src/support/os.h
===================================================================
--- src/support/os.h    (revision 15112)
+++ src/support/os.h    (working copy)
@@ -53,6 +53,14 @@ std::string external_path_list(std::stri
 /// Converts a host OS style path list to unix style.
 std::string internal_path_list(std::string const & p);
 
+#if defined(__CYGWIN__) || defined(__CYGWIN32__)
+/// Converts whatever path style to unix style.
+std::string posix_path(std::string const & p);
+
+/// Converts whatever path style to windows style.
+std::string windows_path(std::string const & p);
+#endif
+
 /**
  * Converts a unix style path into a form suitable for inclusion in a LaTeX
  * document.
Index: src/support/os_cygwin.C
===================================================================
--- src/support/os_cygwin.C     (revision 15112)
+++ src/support/os_cygwin.C     (working copy)
@@ -40,6 +40,7 @@ namespace os {
 namespace {
 
 bool windows_style_tex_paths_ = false;
+bool windows_style_lyx_paths_ = false;
 
 // In both is_posix_path() and is_windows_path() it is assumed that
 // a valid posix or pseudo-windows path is passed. They simply tell
@@ -132,25 +133,20 @@ void os::init(int, char *[])
 
                if (var == "TEMP")
                        temp_seen = true;
+
+               if (var == "LYX_WINPATHS" && (val == "true" || val == "yes"))
+                       windows_style_lyx_paths_ = true;
                
                if (GetEnvironmentVariable(var.c_str(), curval, 2) == 0
                                && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
                        /* Convert to Windows style where necessary */
                        if (var == "PATH" || var == "LD_LIBRARY_PATH") {
-                               string const winpathlist =
-                                   convert_path_list(val, PathStyle(windows));
-                               if (!winpathlist.empty()) {
-                                       SetEnvironmentVariable(var.c_str(),
-                                               winpathlist.c_str());
-                               }
+                               val = convert_path_list(val, 
PathStyle(windows));
                        } else if (var == "HOME" || var == "TMPDIR" ||
                                        var == "TMP" || var == "TEMP") {
-                               string const winpath =
-                                       convert_path(val, PathStyle(windows));
-                               SetEnvironmentVariable(var.c_str(), 
winpath.c_str());
-                       } else {
-                               SetEnvironmentVariable(var.c_str(), 
val.c_str());
+                               val = convert_path(val, PathStyle(windows));
                        }
+                       SetEnvironmentVariable(var.c_str(), val.c_str());
                }
        }
        if (!temp_seen) {
@@ -186,29 +182,36 @@ string::size_type common_path(string con
 }
 
 
-string external_path(string const & p)
+string windows_path(string const & p)
 {
-#ifdef X_DISPLAY_MISSING
        return convert_path(p, PathStyle(windows));
-#else
+}
+
+
+string posix_path(string const & p)
+{
        return convert_path(p, PathStyle(posix));
-#endif
 }
 
 
 string internal_path(string const & p)
 {
-       return convert_path(p, PathStyle(posix));
+       return convert_path(p, windows_style_lyx_paths_ ? PathStyle(windows)
+                                                      : PathStyle(posix));
+}
+
+
+string external_path(string const & p)
+{
+       return convert_path(p, windows_style_lyx_paths_ ? PathStyle(windows)
+                                                      : PathStyle(posix));
 }
 
 
 string external_path_list(string const & p)
 {
-#ifdef X_DISPLAY_MISSING
-       return convert_path_list(p, PathStyle(windows));
-#else
-       return convert_path_list(p, PathStyle(posix));
-#endif
+       return convert_path_list(p, windows_style_lyx_paths_ ?
+                                       PathStyle(windows) : PathStyle(posix));
 }
 
 
@@ -224,16 +227,18 @@ 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)) {
-               string dos_path = convert_path(p, PathStyle(windows));
-               lyxerr[Debug::LATEX]
-                       << "<Path correction for LaTeX> ["
-                       << p << "]->>["
-                       << dos_path << ']' << endl;
-               return dos_path;
+       if (is_absolute_path(p)) {
+               string const tex_path = convert_path(p, 
windows_style_tex_paths_ ?
+                                       PathStyle(windows) : PathStyle(posix));
+               if (tex_path != p) {
+                       lyxerr[Debug::LATEX]
+                               << "<Path correction for LaTeX> ["
+                               << p << "]->>["
+                               << tex_path << ']' << endl;
+                       return tex_path;
+               }
        }
-
-       return convert_path(p, PathStyle(posix));
+       return p;
 }
 
 
Index: src/support/environment.C
===================================================================
--- src/support/environment.C   (revision 15112)
+++ src/support/environment.C   (working copy)
@@ -99,7 +99,7 @@ void setEnvPath(string const & name, vec
                // On cygwin, os::external_path returns either posix or
                // pseudo-win style paths, but here we always need posix style.
                // This fixes bug 2344.
-               ss << os::internal_path(*it);
+               ss << os::posix_path(*it);
 #else
                ss << os::external_path(*it);
 #endif
Index: src/support/package.C.in
===================================================================
--- src/support/package.C.in    (revision 15112)
+++ src/support/package.C.in    (working copy)
@@ -171,20 +171,20 @@ namespace {
 // configuration-time.
 string const top_srcdir()
 {
-       static string const dir("%TOP_SRCDIR%");
+       static string const dir = os::internal_path("%TOP_SRCDIR%");
        return dir;
 }
 
 
 string const hardcoded_localedir()
 {
-       return string("%LOCALEDIR%");
+       return os::internal_path("%LOCALEDIR%");
 }
 
 
 string const hardcoded_system_support_dir()
 {
-       return string("%LYX_DIR%");
+       return os::internal_path("%LYX_DIR%");
 }
 
 
@@ -201,7 +201,7 @@ string const & with_version_suffix()
 
 string const & Package::top_srcdir() const
 {
-       static string const dir("%TOP_SRCDIR%");
+       static string const dir = os::internal_path("%TOP_SRCDIR%");
        return dir;
 }
 
@@ -361,7 +361,7 @@ string const get_temp_dir()
        GetTempPath(MAX_PATH, path);
        return os::internal_path(path);
 #else // Posix-like.
-       return "/tmp";
+       return os::internal_path("/tmp");
 #endif
 }
 
Index: src/messages.C
===================================================================
--- src/messages.C      (revision 15112)
+++ src/messages.C      (working copy)
@@ -14,6 +14,9 @@
 #include "support/filetools.h"
 #include "support/environment.h"
 #include "support/package.h"
+#ifdef __CYGWIN__
+#include "support/os.h"
+#endif
 
 #include <boost/current_function.hpp>
 #include <boost/regex.hpp>
@@ -24,6 +27,10 @@ using lyx::support::package;
 using lyx::support::getEnv;
 using lyx::support::setEnv;
 
+#ifdef __CYGWIN__
+using lyx::support::os::posix_path;
+#endif
+
 using std::string;
 
 
@@ -142,7 +149,12 @@ public:
 
                setlocale(LC_CTYPE, lang_.c_str());
                errno = 0;
+#ifdef __CYGWIN__
+               string const locale_dir = posix_path(package().locale_dir());
+               char const * c = bindtextdomain(PACKAGE, locale_dir.c_str());
+#else
                char const * c = bindtextdomain(PACKAGE, 
package().locale_dir().c_str());
+#endif
                int e = errno;
                if (e) {
                        lyxerr[Debug::DEBUG]

Reply via email to