On Fri, Mar 24, 2006 at 02:04:53PM +0100, Georg Baum wrote: > No, it does not need posix style paths: It simply cannot cope with > backslashes for obvious reasons. AFAIK miktex can handle paths like > "C:/temp/test.tex". Not a big difference, but not exactly posix either.
This path style is called mixed style in the cygwin documentation. The test performed by the configure script about use_cygwin_path_fix is exactly based on that. It consists in creating a latex file containing something like "\input{C:/temp/test.tex}", launching latex on the file, and then looking for an error. The cygwin tetex gives an error, indeed, whereas miktex does not. > If everything works: Fine, but from reading the code I suspect that there > might be problems when calling external programs or handling paths to the > filedialog. Of course we should not fix anything when we are not sure where > the problem lies. As I said, cygwin can cope with both win and posix style paths, so a problem is unlikely to occur but not impossible (see bug 2344). However, I am getting more and more convinced that the way the "Use Cygwin-style paths" checkbox is currently used is wrong. The configure script already takes care of appropriately setting the use_cygwin_path_fix switch, and the fact that such setting can be subverted through that checkbox, can only be harmful to the casual user which has not clear what its implications are. I don't know if the idea of who introduced such checkbox was to let the user decide what kind of path style LyX would use/show in its GUI, but I think that its purpose should be exactly this one. Therefore it should be made orthogonal to the use_cygwin_path_fix switch. Building upon your clever intuition about the need of an os::latex_path function, I devised the attached patch and I am currently testing it. Until now everything works and the behavior seems more consistent to me. Essentially, my idea is that when "Use Cygwin-style paths" is unchecked, LyX/Cygwin should look and feel as a native windows application and the files it produces should be completely interoperable with the native LyX/Win version, as I think this is a good thing. I still have to reach that goal. For the moment only the paths in preferences are converted to the desired format. Anyway, I am posting the patch as it is now, in order to get some feedback. -- Enrico
Index: src/lyxfunc.C =================================================================== --- src/lyxfunc.C (revision 13496) +++ src/lyxfunc.C (working copy) @@ -1977,6 +1977,11 @@ void actOnUpdatedPrefs(LyXRC const & lyx namespace os = lyx::support::os; os::cygwin_path_fix(lyxrc_new.cygwin_path_fix); } + case LyXRC::RC_CYGWIN_STYLE_PATHS: + if (lyxrc_orig.cygwin_style_paths != lyxrc_new.cygwin_style_paths) { + namespace os = lyx::support::os; + os::cygwin_style_paths(lyxrc_new.cygwin_style_paths); + } case LyXRC::RC_DATE_INSERT_FORMAT: case LyXRC::RC_DEFAULT_LANGUAGE: case LyXRC::RC_DEFAULT_PAPERSIZE: Index: src/frontends/qt2/QPrefs.C =================================================================== --- src/frontends/qt2/QPrefs.C (revision 13496) +++ src/frontends/qt2/QPrefs.C (working copy) @@ -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)); +} + } @@ -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_style_paths = 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 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_style_paths); #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)); Index: src/frontends/xforms/FormPreferences.C =================================================================== --- src/frontends/xforms/FormPreferences.C (revision 13496) +++ src/frontends/xforms/FormPreferences.C (working copy) @@ -2074,7 +2074,7 @@ void FormPreferences::OutputsMisc::apply rc.auto_reset_options = fl_get_button(dialog_->check_autoreset_classopt); #if defined(__CYGWIN__) || defined(__CYGWIN32__) - rc.cygwin_path_fix = fl_get_button(dialog_->check_cygwin_path); + rc.cygwin_style_paths = fl_get_button(dialog_->check_cygwin_path); #endif } @@ -2141,11 +2141,8 @@ FormPreferences::OutputsMisc::feedback(F return LyXRC::getDescription(LyXRC::RC_AUTORESET_OPTIONS); #if defined(__CYGWIN__) || defined(__CYGWIN32__) if (ob == dialog_->check_cygwin_path) - return _("Select if LyX should output Cygwin-style paths " - "rather than Windows-style paths. Useful if you're " - "using the Cygwin teTeX rather than a native Windows " - "MikTeX. Note, however, that you'll need to write " - "shell script wrappers for all your converters."); + return _("Select if LyX should use/show Cygwin-style paths " + "rather than Windows-style paths in the GUI."); #endif return string(); } @@ -2172,7 +2169,7 @@ void FormPreferences::OutputsMisc::updat fl_set_button(dialog_->check_autoreset_classopt, rc.auto_reset_options); #if defined(__CYGWIN__) || defined(__CYGWIN32__) - fl_set_button(dialog_->check_cygwin_path, rc.cygwin_path_fix); + fl_set_button(dialog_->check_cygwin_path, rc.cygwin_style_paths); #endif } Index: src/support/os_unix.C =================================================================== --- src/support/os_unix.C (revision 13496) +++ src/support/os_unix.C (working copy) @@ -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; @@ -101,6 +113,10 @@ char path_separator() void cygwin_path_fix(bool) +{} + + +void cygwin_style_paths(bool) {} } // namespace os Index: src/support/os.h =================================================================== --- src/support/os.h (revision 13496) +++ src/support/os.h (working copy) @@ -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. @@ -68,11 +74,17 @@ char const * popen_read_mode(); */ char path_separator(); -/** If @c use_cygwin_paths is true, LyX will output cygwin style paths - * rather than native Win32 ones. Obviously, this option is used only - * under Cygwin. +/** If @c fix_cygwin_paths is true, LyX will output cygwin style paths + * rather than native Win32 ones in latex files. Obviously, this option + * is used only under Cygwin. + */ +void cygwin_path_fix(bool fix_cygwin_paths); + +/** If @c use_cygwin_paths is true, LyX will use/show cygwin style paths + * rather than native Win32 ones in the GUI. Obviously, this option + * is used only under Cygwin. */ -void cygwin_path_fix(bool use_cygwin_paths); +void cygwin_style_paths(bool use_cygwin_paths); } // namespace os } // namespace support Index: src/support/os_win32.C =================================================================== --- src/support/os_win32.C (revision 13496) +++ src/support/os_win32.C (working copy) @@ -216,6 +216,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; @@ -268,6 +280,10 @@ char path_separator() void cygwin_path_fix(bool) +{} + + +void cygwin_style_paths(bool) {} Index: src/support/os_cygwin.C =================================================================== --- src/support/os_cygwin.C (revision 13496) +++ src/support/os_cygwin.C (working copy) @@ -65,30 +65,20 @@ string::size_type common_path(string con namespace { bool cygwin_path_fix_ = false; +bool cygwin_style_paths_ = false; } // namespace anon string external_path(string const & p) { - string dos_path; + if (cygwin_style_paths_) + return internal_path(p); // 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] - << "<Cygwin path correction> [" - << p << "]->>[" - << dos_path << ']' << endl; + char dos_path[PATH_MAX]; + dos_path[0] = '\0'; + cygwin_conv_to_win32_path(p.c_str(), dos_path); return dos_path; } @@ -102,12 +92,75 @@ string internal_path(string const & p) } +string external_path_list(string const & p) +{ + if (cygwin_style_paths_) + return internal_path_list(p); + + char const * const pc = p.c_str(); + + // Check whether path list is in posix style before + // trying to translate it to windows style + if (cygwin_posix_path_list_p(pc)) { + char * ptr = + new char[cygwin_posix_to_win32_path_list_buf_size(pc)]; + if (ptr) { + cygwin_posix_to_win32_path_list(pc, ptr); + string dos_path_list = ptr; + delete ptr; + return dos_path_list; + } + } + + return p; +} + + +string internal_path_list(string const & p) +{ + char const * const pc = p.c_str(); + + // Check whether path list is in windows style before + // trying to translate it to posix style + if (!cygwin_posix_path_list_p(pc)) { + char * ptr = + new char[cygwin_win32_to_posix_path_list_buf_size(pc)]; + if (ptr) { + cygwin_win32_to_posix_path_list(pc, ptr); + string posix_path_list = ptr; + delete ptr; + return posix_path_list; + } + } + + return p; +} + + 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); + + 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] + << "<Cygwin path correction> [" + << p << "]->>[" + << dos_path << ']' << endl; + return dos_path; } @@ -150,9 +203,15 @@ char path_separator() } -void cygwin_path_fix(bool use_cygwin_paths) +void cygwin_path_fix(bool fix_cygwin_paths) +{ + cygwin_path_fix_ = fix_cygwin_paths; +} + + +void cygwin_style_paths(bool use_cygwin_paths) { - cygwin_path_fix_ = use_cygwin_paths; + cygwin_style_paths_ = use_cygwin_paths; } } // namespace os Index: src/support/environment.C =================================================================== --- src/support/environment.C (revision 13496) +++ 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 } setEnv(name, ss.str()); } Index: src/lyxrc.C =================================================================== --- src/lyxrc.C (revision 13496) +++ src/lyxrc.C (working copy) @@ -81,6 +81,7 @@ keyword_item lyxrcTags[] = { { "\\custom_export_command", LyXRC::RC_CUSTOM_EXPORT_COMMAND }, { "\\custom_export_format", LyXRC::RC_CUSTOM_EXPORT_FORMAT }, { "\\cygwin_path_fix_needed", LyXRC::RC_CYGWIN_PATH_FIX }, + { "\\cygwin_style_paths_wanted", LyXRC::RC_CYGWIN_STYLE_PATHS }, { "\\date_insert_format", LyXRC::RC_DATE_INSERT_FORMAT }, { "\\default_language", LyXRC::RC_DEFAULT_LANGUAGE }, { "\\default_papersize", LyXRC::RC_DEFAULT_PAPERSIZE }, @@ -272,6 +273,7 @@ void LyXRC::setDefaults() { default_language = "english"; show_banner = true; cygwin_path_fix = false; + cygwin_style_paths = false; tex_allows_spaces = false; date_insert_format = "%A, %e %B %Y"; cursor_follows_scrollbar = false; @@ -395,6 +397,12 @@ int LyXRC::read(LyXLex & lexrc) } break; + case RC_CYGWIN_STYLE_PATHS: + if (lexrc.next()) { + cygwin_style_paths = lexrc.getBool(); + } + break; + case RC_TEX_ALLOWS_SPACES: if (lexrc.next()) { tex_allows_spaces = lexrc.getBool(); @@ -1343,6 +1351,12 @@ void LyXRC::write(ostream & os, bool ign os << "\\cygwin_path_fix_needed " << convert<string>(cygwin_path_fix) << '\n'; } + case RC_CYGWIN_STYLE_PATHS: + if (ignore_system_lyxrc || + cygwin_style_paths != system_lyxrc.cygwin_style_paths) { + os << "\\cygwin_style_paths_wanted " + << convert<string>(cygwin_style_paths) << '\n'; + } case RC_TEX_ALLOWS_SPACES: if (tex_allows_spaces != system_lyxrc.tex_allows_spaces) { os << "\\tex_allows_spaces " @@ -2138,6 +2152,9 @@ string const LyXRC::getDescription(LyXRC break; case RC_CYGWIN_PATH_FIX: + break; + + case RC_CYGWIN_STYLE_PATHS: break; case RC_DATE_INSERT_FORMAT: Index: src/lyxrc.h =================================================================== --- src/lyxrc.h (revision 13496) +++ src/lyxrc.h (working copy) @@ -52,6 +52,7 @@ public: RC_CUSTOM_EXPORT_COMMAND, RC_CUSTOM_EXPORT_FORMAT, RC_CYGWIN_PATH_FIX, + RC_CYGWIN_STYLE_PATHS, RC_DATE_INSERT_FORMAT, RC_DEFAULT_LANGUAGE, RC_DEFAULT_PAPERSIZE, @@ -376,8 +377,10 @@ public: std::string user_name; /// user email std::string user_email; - /// + /// True if the TeX engine should use mixed windows/unix style paths bool cygwin_path_fix; + /// True if LyX should use/show posix style paths in the GUI + bool cygwin_style_paths; /// True if the TeX engine can handle file names containing spaces bool tex_allows_spaces; /** Prepend paths to the PATH environment variable. Index: src/lyx_main.C =================================================================== --- src/lyx_main.C (revision 13496) +++ src/lyx_main.C (working copy) @@ -475,6 +475,7 @@ void LyX::init(bool gui) lyxrc.print(); os::cygwin_path_fix(lyxrc.cygwin_path_fix); + os::cygwin_style_paths(lyxrc.cygwin_style_paths); if (!lyxrc.path_prefix.empty()) prependEnvPath("PATH", lyxrc.path_prefix);