Am Montag, 3. April 2006 10:15 schrieb Enrico Forestieri: > On Sun, Apr 02, 2006 at 10:20:35PM +0200, Georg Baum wrote: > > > Am Sonntag, 2. April 2006 17:57 schrieb Enrico Forestieri: > > > enum path_target { > > > DEFAULT, > > > LATEX > > > } > > > > > > std::string internal_path(std::string const & p, > > > path_target target = DEFAULT); > > > > May I ask you why you need it? Is that for conversion of paths that come > > from latex? > > No, it is for conversion of paths going to .tex files. See below > the reason I need it.
This enum is dangerous IMO, because it makes the semantics of internal_path() unclear. I therefore got rid of it by not using ChangeExtension() in latex_path(). Even better would be to remove the call of internal_path() in ChangeExtension, but seeing how often ChangeExtension is used I did not dare to do that. > Index: src/support/os_win32.C > =================================================================== > --- src/support/os_win32.C (revision 13547) > +++ src/support/os_win32.C (working copy) > @@ -210,15 +210,27 @@ string const get_long_path(string const > } // namespace anon > > > -string internal_path(string const & p) > +string internal_path(string const & p, path_target) > { > return subst(get_long_path(p), "\\", "/"); > } > > > -string latex_path(string const & p) > +string external_path_list(string const & p) > +{ > + return p; > +} I changed this > + > + > +string internal_path_list(string const & p) > { > return p; > +} and this too, so that the path lists are converted. I know that these are currently not used on win_32, but you never know what happens in the future. > Index: src/support/environment.C > =================================================================== > --- src/support/environment.C (revision 13547) > +++ src/support/environment.C (working copy) > @@ -95,7 +95,11 @@ void setEnvPath(string const & name, vec > for (; it != end; ++it) { > if (it != begin) > ss << separator; > +#if defined(__CYGWIN__) || defined(__CYGWIN32__) > + ss << os::internal_path(*it); > +#else > ss << os::external_path(*it); > +#endif Please add a comment why this is necessary. Attached is my modified version of the patch (without changelogs). Please test whether it still works. Georg
Index: src/frontends/qt2/QPrefs.C =================================================================== --- src/frontends/qt2/QPrefs.C (Revision 13548) +++ src/frontends/qt2/QPrefs.C (Arbeitskopie) @@ -148,6 +148,11 @@ string const internal_path(QString const 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)); +} + } @@ -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 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)); +} + } @@ -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)); Index: src/support/os_unix.C =================================================================== --- src/support/os_unix.C (Revision 13548) +++ src/support/os_unix.C (Arbeitskopie) @@ -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; Index: src/support/os.h =================================================================== --- src/support/os.h (Revision 13548) +++ src/support/os.h (Arbeitskopie) @@ -47,6 +47,12 @@ std::string external_path(std::string co /// 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. Index: src/support/filetools.C =================================================================== --- src/support/filetools.C (Revision 13548) +++ src/support/filetools.C (Arbeitskopie) @@ -86,16 +86,19 @@ string const latex_path(string const & o 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()); + // removeExtension 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; Index: src/support/os_win32.C =================================================================== --- src/support/os_win32.C (Revision 13548) +++ src/support/os_win32.C (Arbeitskopie) @@ -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, '\\', '/'); } Index: src/support/os_cygwin.C =================================================================== --- src/support/os_cygwin.C (Revision 13548) +++ src/support/os_cygwin.C (Arbeitskopie) @@ -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; -} // namespace anon +// In both is_posix_path() and is_windows_path() it is assumed that +// a valid posix or windows path is passed. They simply tell whether +// the path looks posix/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. -string external_path(string const & p) +bool is_windows_path(string const & p) { - string dos_path; + return p.empty() || + (!contains(p, '\\') && (p.length() < 1 || p[1] == ':')); +} - // 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; + +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; + } } - else return p; + return subst(p, '\\', '/'); +} + +} // namespace anon - //No backslashes in LaTeX files - dos_path = subst(dos_path,'\\','/'); - lyxerr[Debug::LATEX] - << "<Cygwin path correction> [" - << p << "]->>[" - << dos_path << ']' << endl; - return dos_path; +string external_path(string const & p) +{ + 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] + << "<Cygwin path correction> [" + << p << "]->>[" + << dos_path << ']' << endl; + return dos_path; + } + + return convert_path(p, PathStyle(posix)); } Index: src/support/environment.C =================================================================== --- src/support/environment.C (Revision 13548) +++ src/support/environment.C (Arbeitskopie) @@ -95,7 +95,11 @@ void setEnvPath(string const & name, vec for (; it != end; ++it) { if (it != begin) ss << separator; +#if defined(__CYGWIN__) || defined(__CYGWIN32__) + ss << os::internal_path(*it); +#else ss << os::external_path(*it); +#endif } setEnv(name, ss.str()); }