From c8aeaa95523384adcfad8a3dd563cb61d6d0eca4 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 8 Oct 2001 14:09:06 +0000 Subject: [PATCH] finish merging of the bits of win32 port that have been sent to me git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2846 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/ChangeLog | 10 ++++++++++ src/support/filetools.C | 26 ++++++++++---------------- src/support/filetools.h | 6 +++--- src/support/os.h | 11 ++++++++--- src/support/os_os2.C | 14 ++++++++++++-- src/support/os_unix.C | 13 +++++++++---- src/support/os_win32.C | 26 ++++++++++++++++++++++---- 7 files changed, 74 insertions(+), 32 deletions(-) diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 0f0fb9edb5..1ae85c5232 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,13 @@ +2001-10-08 Jean-Marc Lasgouttes + + * filetools.C (AbsolutePath): Use os::is_absolute_path() (also in + several methods) + (findtexfile): oops! the change from last friday was wrong... + + * os_win32.C (is_absolute_path): + * os_unix.C (is_absolute_path): + * os_os2.C (is_absolute_path): new method + 2001-10-05 Jean-Marc Lasgouttes * filetools.C (findtexfile): apply os::internal_path to the result. diff --git a/src/support/filetools.C b/src/support/filetools.C index 3eef6694ea..95f60c3436 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -6,7 +6,7 @@ Parts Copyright 1985, 1990, 1993 Free Software Foundation, Inc. Parts Copyright 1996 Asger Alstrup - See also filetools.H. + See also filetools.h. lyx-filetool.C : tools functions for file/path handling this file is part of LyX, the High Level Word Processor @@ -557,7 +557,7 @@ string const OnlyPath(string const & Filename) string const MakeAbsPath(string const & RelPath, string const & BasePath) { // checks for already absolute path - if (AbsolutePath(RelPath)) + if (os::is_absolute_path(RelPath)) return RelPath; // Copies given paths @@ -567,7 +567,7 @@ string const MakeAbsPath(string const & RelPath, string const & BasePath) string TempBase; - if (AbsolutePath(BasePath)) + if (os::is_absolute_path(BasePath)) TempBase = BasePath; else TempBase = AddPath(lyx::getcwd(), BasePath); @@ -651,24 +651,21 @@ string const OnlyFilename(string const & fname) } -// Is a filename/path absolute? +/// Returns true is path is absolute bool AbsolutePath(string const & path) { -#ifndef __EMX__ - return (!path.empty() && path[0] == '/'); -#else - return (!path.empty() && isalpha(static_cast(path[0])) && path.length() > 1 && path[1] == ':'); -#endif + return os::is_absolute_path(path); } + // Create absolute path. If impossible, don't do anything // Supports ./ and ~/. Later we can add support for ~logname/. (Asger) string const ExpandPath(string const & path) { // checks for already absolute path string RTemp(ReplaceEnvironmentPath(path)); - if (AbsolutePath(RTemp)) + if (os::is_absolute_path(RTemp)) return RTemp; string Temp; @@ -698,7 +695,7 @@ string const NormalizePath(string const & path) string RTemp; string Temp; - if (AbsolutePath(path)) + if (os::is_absolute_path(path)) RTemp = path; else // Make implicit current directory explicit @@ -958,7 +955,7 @@ MakeDisplayPath (string const & path, unsigned int threshold) // If we backup from home or don't have a relative path, // this try is no good - if (prefixIs(relhome, "../") || AbsolutePath(relhome)) { + if (prefixIs(relhome, "../") || os::is_absolute_path(relhome)) { // relative path was no good, just use the original path relhome = path; l2 = l1; @@ -1076,11 +1073,8 @@ findtexfile(string const & fil, string const & /*format*/) lyxerr[Debug::LATEX] << "kpse status = " << c.first << "\n" << "kpse result = `" << strip(c.second, '\n') << "'" << endl; - string fullpath; if (c.first != -1) - fullpath = os::internal_path(strip(strip(c.second, - '\n'), - '\r')); + return os::internal_path(strip(strip(c.second, '\n'), '\r')); else return string(); } diff --git a/src/support/filetools.h b/src/support/filetools.h index 04d8b2deba..4c5bc161bc 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -116,9 +116,6 @@ string const MakeLatexName(string const & file); /// Put the name in quotes suitable for the current shell string const QuoteName(string const & file); -/// Is a filename/path absolute? -bool AbsolutePath(string const & path); - /// Add a filename to a path. Any path from filename is stripped first. string const AddName(string const & path, string const & fname); @@ -135,6 +132,9 @@ ChangeExtension(string const & oldname, string const & extension); /// Return the extension of the file (not including the .) string const GetExtension(string const & name); +/// Returns true is path is absolute +bool AbsolutePath(string const & path); + /// Create absolute path. If impossible, don't do anything string const ExpandPath(string const & path); diff --git a/src/support/os.h b/src/support/os.h index 3f947734eb..2d85f0ab12 100644 --- a/src/support/os.h +++ b/src/support/os.h @@ -41,14 +41,19 @@ public: static os::shell_type shell() {return _shell;}; // DBCS aware! - static string::size_type common_path(string const &p1, string const &p2); + static string::size_type common_path(string const &p1, + string const &p2); // no-op on UNIX, '\\'->'/' on OS/2 and Win32, ':'->'/' on MacOS, etc. static string slashify_path(string p); // converts a host OS path to unix style - static string external_path(string p); + static string external_path(string const &p); // converts a unix path to host OS style - static string internal_path(string p); + static string internal_path(string const &p); + // is path absolute? + static bool is_absolute_path(string const & p); + + // static void warn(string mesg); private: static string binpath_; diff --git a/src/support/os_os2.C b/src/support/os_os2.C index 358d487eb0..b61a5b9c55 100644 --- a/src/support/os_os2.C +++ b/src/support/os_os2.C @@ -155,10 +155,20 @@ string os::slashify_path(string p) { return p; } -string os::external_path(string p) { + +string os::external_path(string const &p) { return p; } -string os::internal_path(string p) { + +string os::internal_path(string const &p) { return p; } + + +bool os::is_absolute_path(string const & p) +{ + return (p.length() > 1 + && isalpha(static_cast(p[0])) + && p[1] == ':'); +} diff --git a/src/support/os_unix.C b/src/support/os_unix.C index 02da66050a..1cf91a34c5 100644 --- a/src/support/os_unix.C +++ b/src/support/os_unix.C @@ -23,7 +23,7 @@ void os::init(int * /*argc*/, char ** argv[]) /* :cp_(0), _shell(os::UNIX) */ { string tmp = *argv[0]; binname_ = OnlyFilename(tmp); tmp = ExpandPath(tmp); // This expands ./ and ~/ - if (!AbsolutePath(tmp)) { + if (!os::is_absolute_path(tmp)) { string binsearchpath = GetEnvPath("PATH"); // This will make "src/lyx" work always :-) binsearchpath += ";."; @@ -34,7 +34,7 @@ void os::init(int * /*argc*/, char ** argv[]) /* :cp_(0), _shell(os::UNIX) */ { // In case we are running in place and compiled with shared libraries if (suffixIs(tmp, "/.libs/")) - tmp.erase(tmp.length()-6, string::npos); + tmp.erase(tmp.length() - 6, string::npos); binpath_ = tmp; } @@ -64,10 +64,15 @@ string os::slashify_path(string p) { return p; } -string os::external_path(string p) { +string os::external_path(string const &p) { return p; } -string os::internal_path(string p) { +string os::internal_path(string const &p) { return p; } + +bool os::is_absolute_path(string const & p) +{ + return (!p.empty() && p[0] == '/'); +} diff --git a/src/support/os_win32.C b/src/support/os_win32.C index a248f04a97..9e3d113560 100644 --- a/src/support/os_win32.C +++ b/src/support/os_win32.C @@ -25,7 +25,7 @@ void os::init(int * argc, char ** argv[]) { binname_ = OnlyFilename(tmp); tmp = ExpandPath(tmp); // This expands ./ and ~/ - if (!AbsolutePath(tmp)) { + if (!is_absolute_path(tmp)) { string binsearchpath = GetEnvPath("PATH"); // This will make "src/lyx" work always :-) binsearchpath += ";."; @@ -68,9 +68,9 @@ string os::slashify_path(string p) { return subst(p, '\\', '/'); } -string os::external_path(string p) { +string os::external_path(string const & p) { string dos_path=p; - if (AbsolutePath(p)) { + if (is_absolute_path(p)) { char dp[255]; cygwin_conv_to_full_win32_path(p.c_str(), dp); dos_path=subst(dp,'\\','/'); @@ -82,11 +82,12 @@ string os::external_path(string p) { return dos_path; } + // (Claus H.) Parsing the latex log file in an Win32 environment all // files are mentioned in Win32/DOS syntax. Because LyX uses the dep file // entries to check if any file has been changed we must retranslate // the Win32/DOS pathnames into Cygwin pathnames. -string os::internal_path(string p) { +string os::internal_path(string const &p) { char pp[256]; cygwin_conv_to_posix_path(p.c_str(), pp); string const posix_path = MakeLatexName(pp); @@ -96,3 +97,20 @@ string os::internal_path(string p) { << posix_path << "]" << endl; return posix_path; } + +// (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used. +// Therefore an absolute path could be either a pathname starting +// with a slash (Unix) or a pathname starting with a drive letter +// followed by a colon. Because a colon is not valid in pathes in Unix +// and at another location in Win32 testing just for the existance +// of the colon in the 2nd position seems to be enough! +bool os::is_absolute_path(string const & p) +{ + if (p.empty()) + return false; + + bool isDosPath = (path.length() > 1 && path[1] == ':'); + bool isUnixPath = (path[0] == '/'); + + return isDosPath | isUnixPath; +}