From 64eed6d825dfb94a4bf235da62e8d1f3e02e0208 Mon Sep 17 00:00:00 2001 From: Robert Keser Date: Mon, 17 Apr 2017 15:27:50 +0200 Subject: [PATCH] Bugfix: Reading files on Windows (recognizing relative or absoulte path) Author: Vanja Skuric --- src/OSspecific/MSWindows/printStack.C | 16 +++++++++++----- src/OSspecific/POSIX/printStack.C | 16 +++++++++++----- .../functionEntries/includeEntry/includeEntry.C | 2 +- src/foam/global/argList/argList.C | 7 +++++-- .../chemkinReader/chemkinReader.C | 10 ++++++++-- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/OSspecific/MSWindows/printStack.C b/src/OSspecific/MSWindows/printStack.C index 6ff3799e2..6120bb0a0 100644 --- a/src/OSspecific/MSWindows/printStack.C +++ b/src/OSspecific/MSWindows/printStack.C @@ -126,7 +126,7 @@ void printSourceFileAndLine myAddress = nStream.str(); } - if (filename[0] == '/') + if (filename[0] == '/' || filename[1] == ':') { string line = pOpen ( @@ -266,7 +266,10 @@ void getSymbolForRaw const word& address ) { - if (filename.size() && filename[0] == '/') + if + ( + filename.size() && (filename[0] == '/' || filename[1] == ':') + ) { string fcnt = pOpen ( @@ -316,7 +319,10 @@ void error::printStack(Ostream& os) string::size_type space = line.rfind(' ') + 1; fileName libPath = line.substr(space, line.size()-space); - if (libPath.size() && libPath[0] == '/') + if + ( + libPath.size() && (libPath[0] == '/' || libPath[1] == ':') + ) { string offsetString(line.substr(0, line.find('-'))); IStringStream offsetStr(offsetString); @@ -359,10 +365,10 @@ void error::printStack(Ostream& os) programFile = msg.substr(0, min(spacePos, bracketPos)); // not an absolute path - if (programFile[0] != '/') + if (programFile[0] != '/' && programFile[1] != ':') { string tmp = pOpen("which " + programFile); - if (tmp[0] == '/' || tmp[0] == '~') + if (tmp[0] == '/' || tmp[1] == ':' || tmp[0] == '~') { programFile = tmp; } diff --git a/src/OSspecific/POSIX/printStack.C b/src/OSspecific/POSIX/printStack.C index ccbcc159e..c22b88f1b 100644 --- a/src/OSspecific/POSIX/printStack.C +++ b/src/OSspecific/POSIX/printStack.C @@ -130,7 +130,7 @@ void printSourceFileAndLine } #ifndef darwin - if (filename[0] == '/') + if (filename[0] == '/' || filename[1] == ':') #else if (1) #endif @@ -175,7 +175,10 @@ void getSymbolForRaw const word& address ) { - if (filename.size() && filename[0] == '/') + if + ( + filename.size() && (filename[0] == '/' || filename[1] == ':') + ) { string fcnt = pOpen ( @@ -224,7 +227,10 @@ void error::printStack(Ostream& os) string::size_type space = line.rfind(' ') + 1; fileName libPath = line.substr(space, line.size()-space); - if (libPath.size() && libPath[0] == '/') + if + ( + libPath.size() && (libPath[0] == '/' || libPath[1] == ':') + ) { string offsetString(line.substr(0, line.find('-'))); IStringStream offsetStr(offsetString); @@ -268,10 +274,10 @@ void error::printStack(Ostream& os) programFile = msg.substr(0, min(spacePos, bracketPos)); // not an absolute path - if (programFile[0] != '/') + if (programFile[0] != '/' && programFile[1] != ':') { string tmp = pOpen("which " + programFile); - if (tmp[0] == '/' || tmp[0] == '~') + if (tmp[0] == '/' || tmp[1] == ':' || tmp[0] == '~') { programFile = tmp; } diff --git a/src/foam/db/dictionary/functionEntries/includeEntry/includeEntry.C b/src/foam/db/dictionary/functionEntries/includeEntry/includeEntry.C index 5da286a8b..8e69c125f 100644 --- a/src/foam/db/dictionary/functionEntries/includeEntry/includeEntry.C +++ b/src/foam/db/dictionary/functionEntries/includeEntry/includeEntry.C @@ -77,7 +77,7 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName fileName fName(is); fName.expand(); - if (fName.size() && fName[0] != '/') + if (fName.size() && fName[0] != '/' && fName[1] != ':') { fName = fileName(is.name()).path()/fName; } diff --git a/src/foam/global/argList/argList.C b/src/foam/global/argList/argList.C index 151f53c63..4b17f67cc 100644 --- a/src/foam/global/argList/argList.C +++ b/src/foam/global/argList/argList.C @@ -159,7 +159,10 @@ void Foam::argList::getRootCase() casePath = cwd(); options_.erase("case"); } - else if (casePath[0] != '/' && casePath.name() == "..") + else if + ( + casePath[0] != '/' && casePath[1] != ':' && casePath.name() == ".." + ) { // avoid relative cases ending in '..' - makes for very ugly names casePath = cwd()/casePath; @@ -177,7 +180,7 @@ void Foam::argList::getRootCase() case_ = globalCase_; // Set the case and case-name as an environment variable - if (rootPath_[0] == '/') + if (rootPath_[0] == '/' || rootPath_[1] == ':') { // Absolute path - use as-is setEnv("FOAM_CASE", rootPath_/globalCase_, true); diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C index 9e9b3a425..0ca39f3d6 100644 --- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C +++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C @@ -884,12 +884,18 @@ Foam::chemkinReader::chemkinReader(const dictionary& thermoDict) fileName relPath = thermoDict.name().path(); if (relPath.size()) { - if (chemkinFile.size() && chemkinFile[0] != '/') + if + ( + chemkinFile.size() && chemkinFile[0] != '/' && chemkinFile[1] != ':' + ) { chemkinFile = relPath/chemkinFile; } - if (thermoFile.size() && thermoFile[0] != '/') + if + ( + thermoFile.size() && thermoFile[0] != '/' && thermoFile[1] != ':' + ) { thermoFile = relPath/thermoFile; }