From 9c74d33b82440e53e2da7a0b5a2531a4f3d80b4e Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 6 Apr 2006 14:44:52 +0000 Subject: [PATCH] Fix mess up of internal/external paths (from Enrico Forestieri) * src/frontends/qt2/QPrefs.C: (internal_path_list, external_path_list): Handle the PATH prefix style according to the user-prefs style. (QPrefs::apply, QPrefs::update_contents): fix inverted logic of rc.cygwin_path_fix * src/support/os.h: New declarations to deal with PATH lists. * src/support/os_cygwin.C: Major rewrite to account for path style problems. * src/support/os_unix.C: * src/support/os_win32.C: Stub functions for PATH lists. * src/support/environment.C: fix bug 2344: Wrong path_prefix handling in cygwin * src/support/filetools.C (ChangeExtension): fix for the path style to be written in .tex files (cygwin related). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_4_X@13570 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 8 +++ src/frontends/qt2/QPrefs.C | 18 ++++-- src/support/ChangeLog | 14 ++++ src/support/environment.C | 7 ++ src/support/filetools.C | 9 ++- src/support/os.h | 6 ++ src/support/os_cygwin.C | 124 +++++++++++++++++++++++++++++------- src/support/os_unix.C | 12 ++++ src/support/os_win32.C | 14 +++- status.14x | 8 ++- 10 files changed, 185 insertions(+), 35 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index c0559d0e14..f5c4ff6f18 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,11 @@ +2006-04-06 Jean-Marc Lasgouttes + + Fix mess up of internal/external paths (from Enrico Forestieri) + + * QPrefs.C (internal_path_list, external_path_list): Handle the + PATH prefix style according to the user-prefs style. + (apply, update_contents): fix inverted logic of rc.cygwin_path_fix + 2006-03-28 Jürgen Spitzmüller * QPrefsDialog.C (remove_format): Prevent deletion of file formats diff --git a/src/frontends/qt2/QPrefs.C b/src/frontends/qt2/QPrefs.C index 1a9038bc84..e6f97c8a85 100644 --- a/src/frontends/qt2/QPrefs.C +++ b/src/frontends/qt2/QPrefs.C @@ -148,6 +148,11 @@ string const internal_path(QString const & input) return lyx::support::os::internal_path(fromqstr(input)); } +string const internal_path_list(QString const & input) +{ + return lyx::support::os::internal_path_list(fromqstr(input)); +} + } @@ -199,7 +204,7 @@ void QPrefs::apply() #if defined(__CYGWIN__) || defined(__CYGWIN32__) QPrefCygwinPathModule * cygwinmod(dialog_->cygwinpathModule); - rc.cygwin_path_fix = cygwinmod->pathCB->isChecked(); + rc.cygwin_path_fix = !cygwinmod->pathCB->isChecked(); #endif QPrefLatexModule * latexmod(dialog_->latexModule); @@ -253,7 +258,7 @@ void QPrefs::apply() rc.template_path = internal_path(pathsmod->templateDirED->text()); rc.backupdir_path = internal_path(pathsmod->backupDirED->text()); rc.tempdir_path = internal_path(pathsmod->tempDirED->text()); - rc.path_prefix = fromqstr(pathsmod->pathPrefixED->text()); + rc.path_prefix = internal_path_list(pathsmod->pathPrefixED->text()); // FIXME: should be a checkbox only rc.lyxpipes = internal_path(pathsmod->lyxserverDirED->text()); @@ -467,6 +472,11 @@ QString const external_path(string const & input) return toqstr(lyx::support::os::external_path(input)); } +QString const external_path_list(string const & input) +{ + return toqstr(lyx::support::os::external_path_list(input)); +} + } @@ -536,7 +546,7 @@ void QPrefs::update_contents() #if defined(__CYGWIN__) || defined(__CYGWIN32__) QPrefCygwinPathModule * cygwinmod(dialog_->cygwinpathModule); - cygwinmod->pathCB->setChecked(rc.cygwin_path_fix); + cygwinmod->pathCB->setChecked(!rc.cygwin_path_fix); #endif QPrefLatexModule * latexmod(dialog_->latexModule); @@ -583,7 +593,7 @@ void QPrefs::update_contents() pathsmod->templateDirED->setText(external_path(rc.template_path)); pathsmod->backupDirED->setText(external_path(rc.backupdir_path)); pathsmod->tempDirED->setText(external_path(rc.tempdir_path)); - pathsmod->pathPrefixED->setText(toqstr(rc.path_prefix)); + pathsmod->pathPrefixED->setText(external_path_list(rc.path_prefix)); // FIXME: should be a checkbox only pathsmod->lyxserverDirED->setText(external_path(rc.lyxpipes)); diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 85da8e0a39..a8ac44af16 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,17 @@ +2006-04-06 Jean-Marc Lasgouttes + + Fix mess up of internal/external paths (from Enrico Forestieri) + + * os.h: New declarations to deal with PATH lists. + * os_cygwin.C: Major rewrite to account for path style + problems. + * os_unix.C: + * os_win32.C: Stub functions for PATH lists. + * environment.C: fix bug 2344: Wrong path_prefix handling + in cygwin + * filetools.C (ChangeExtension): fix for the path + style to be written in .tex files (cygwin related). + 2006-04-01 Michael Gerz * filename.C (mangledFilename): truncate filename to 100 characters diff --git a/src/support/environment.C b/src/support/environment.C index c1a5710978..616025cf2a 100644 --- a/src/support/environment.C +++ b/src/support/environment.C @@ -95,7 +95,14 @@ void setEnvPath(string const & name, vector const & env) for (; it != end; ++it) { if (it != begin) ss << separator; +#if defined(__CYGWIN__) || defined(__CYGWIN32__) + // 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); +#else ss << os::external_path(*it); +#endif } setEnv(name, ss.str()); } diff --git a/src/support/filetools.C b/src/support/filetools.C index 8c2ca46409..0aff392a1d 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -86,16 +86,19 @@ string const latex_path(string const & original_path, latex_path_extension extension, latex_path_dots dots) { - string path = subst(original_path, "\\", "/"); // On cygwin, we may need windows or posix style paths. - path = os::latex_path(path); + string path = os::latex_path(original_path); path = subst(path, "~", "\\string~"); if (path.find(' ') != string::npos) { // We can't use '"' because " is sometimes active (e.g. if // babel is loaded with the "german" option) if (extension == EXCLUDE_EXTENSION) { - string const base = ChangeExtension(path, string()); + // ChangeExtension calls os::internal_path internally + // so don't use it to remove the extension. string const ext = GetExtension(path); + string const base = ext.empty() ? + path : + path.substr(0, path.length() - ext.length() - 1); // ChangeExtension calls os::internal_path internally // so don't use it to re-add the extension. path = "\\string\"" + base + "\\string\"." + ext; diff --git a/src/support/os.h b/src/support/os.h index 85e97bfa85..4d6d54d231 100644 --- a/src/support/os.h +++ b/src/support/os.h @@ -47,6 +47,12 @@ std::string external_path(std::string const & p); /// Converts a host OS style path to unix style. std::string internal_path(std::string const & p); +/// Converts a unix style path list to host OS style. +std::string external_path_list(std::string const & p); + +/// Converts a host OS style path list to unix style. +std::string internal_path_list(std::string const & p); + /** * Converts a unix style path into a form suitable for inclusion in a LaTeX * document. diff --git a/src/support/os_cygwin.C b/src/support/os_cygwin.C index dce059d40b..e169f10e29 100644 --- a/src/support/os_cygwin.C +++ b/src/support/os_cygwin.C @@ -27,6 +27,8 @@ using std::endl; using std::string; +using lyx::support::contains; + namespace lyx { namespace support { @@ -66,39 +68,103 @@ namespace { bool cygwin_path_fix_ = 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 +// whether the path looks posix/pseudo-windows or not. + +bool is_posix_path(string const & p) +{ + return p.empty() || + (!contains(p, '\\') && (p.length() <= 1 || p[1] != ':')); +} + +// This is a test for a win32 style path with forward slashes (pseudo-windows). + +bool is_windows_path(string const & p) +{ + return p.empty() || + (!contains(p, '\\') && (p.length() <= 1 || p[1] == ':')); +} + + +enum PathStyle { + posix, + windows +}; + + +string convert_path(string const & p, PathStyle const & target) +{ + char path_buf[PATH_MAX]; + + if ((target == posix && is_posix_path(p)) || + (target == windows && is_windows_path(p))) + return p; + + path_buf[0] = '\0'; + + if (target == posix) + cygwin_conv_to_posix_path(p.c_str(), path_buf); + else + cygwin_conv_to_win32_path(p.c_str(), path_buf); + + return subst(path_buf[0] ? path_buf : p, '\\', '/'); +} + + +string convert_path_list(string const & p, PathStyle const & target) +{ + char const * const pc = p.c_str(); + PathStyle const actual = cygwin_posix_path_list_p(pc) ? posix : windows; + + if (target != actual) { + int const target_size = (target == posix) ? + cygwin_win32_to_posix_path_list_buf_size(pc) : + cygwin_posix_to_win32_path_list_buf_size(pc); + + char * ptr = new char[target_size]; + + if (ptr) { + if (target == posix) + cygwin_win32_to_posix_path_list(pc, ptr); + else + cygwin_posix_to_win32_path_list(pc, ptr); + + string path_list = subst(ptr, '\\', '/'); + delete ptr; + return path_list; + } + } + + return subst(p, '\\', '/'); +} + } // namespace anon string external_path(string const & p) { - string dos_path; - - // Translate from cygwin path syntax to dos path syntax - if (cygwin_path_fix_ && is_absolute_path(p)) { - char dp[PATH_MAX]; - cygwin_conv_to_full_win32_path(p.c_str(), dp); - dos_path = !dp ? "" : dp; - } - - else return p; - - //No backslashes in LaTeX files - dos_path = subst(dos_path,'\\','/'); - - lyxerr[Debug::LATEX] - << " [" - << p << "]->>[" - << dos_path << ']' << endl; - return dos_path; + return convert_path(p, cygwin_path_fix_ ? PathStyle(windows) + : PathStyle(posix)); } string internal_path(string const & p) { - char posix_path[PATH_MAX]; - posix_path[0] = '\0'; - cygwin_conv_to_posix_path(p.c_str(), posix_path); - return posix_path; + return convert_path(p, PathStyle(posix)); +} + + +string external_path_list(string const & p) +{ + return convert_path_list(p, cygwin_path_fix_ ? PathStyle(windows) + : PathStyle(posix)); +} + + +string internal_path_list(string const & p) +{ + return convert_path_list(p, PathStyle(posix)); } @@ -107,7 +173,17 @@ string latex_path(string const & p) // We may need a posix style path or a windows style path (depending // on cygwin_path_fix_), but we use always forward slashes, since it // gets written into a .tex file. - return external_path(p); + + if (cygwin_path_fix_ && is_absolute_path(p)) { + string dos_path = convert_path(p, PathStyle(windows)); + lyxerr[Debug::LATEX] + << " [" + << p << "]->>[" + << dos_path << ']' << endl; + return dos_path; + } + + return convert_path(p, PathStyle(posix)); } diff --git a/src/support/os_unix.C b/src/support/os_unix.C index d53b9345a5..0ffce418c9 100644 --- a/src/support/os_unix.C +++ b/src/support/os_unix.C @@ -63,6 +63,18 @@ string internal_path(string const & p) } +string external_path_list(string const & p) +{ + return p; +} + + +string internal_path_list(string const & p) +{ + return p; +} + + string latex_path(string const & p) { return p; diff --git a/src/support/os_win32.C b/src/support/os_win32.C index db823e5220..71d2ff5d56 100644 --- a/src/support/os_win32.C +++ b/src/support/os_win32.C @@ -216,9 +216,21 @@ string internal_path(string const & p) } +string external_path_list(string const & p) +{ + return subst(p, '/', '\\'); +} + + +string internal_path_list(string const & p) +{ + return subst(p, '\\', '/'); +} + + string latex_path(string const & p) { - return p; + return subst(p, '\\', '/'); } diff --git a/status.14x b/status.14x index d628903027..e9cfb3bd42 100644 --- a/status.14x +++ b/status.14x @@ -52,6 +52,8 @@ What's new - Fix crash when generating LaTeX dependencies on Cygwin. +- Fix wrong path_prefix handling in Cygwin builds (bug 2344) + - Set search path for included files correctly on Cygwin (bug 2409). - Better layout file conversion (bug 2355) @@ -62,6 +64,9 @@ What's new - Convert line endings for external copy/paste on OS X (bug 1955). +- Fix bookmarks and links to LaTeX errors which were broken after paragraph + deletion/insertion (bugs 2284 and 2242). + - Disable saving when document is unchanged (bug 2313). - Fix jurabib error with Spanish documents (bug 2365). @@ -122,6 +127,3 @@ What's new - Compilation fix (gtk frontend) for gcc 4.1. -- Fix bookmarks and links to LaTeX errors which were broken after paragraph - deletion/insertion (bugs 2284 and 2242). -