summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2004-12-29 04:01:59 +0000
committerMichi Henning <michi@zeroc.com>2004-12-29 04:01:59 +0000
commit704217528abde49e61021531c4d91ca7525aa093 (patch)
tree3c9a275591511ffaa5f05b7c70836c0926a93ca9 /cpp
parentFixed bug in checkedCast template. (diff)
downloadice-704217528abde49e61021531c4d91ca7525aa093.tar.bz2
ice-704217528abde49e61021531c4d91ca7525aa093.tar.xz
ice-704217528abde49e61021531c4d91ca7525aa093.zip
Backed out previous check-in of IcePatch2 files -- they were checked in by
mistake.
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/IcePatch2/Util.h2
-rw-r--r--cpp/src/IcePatch2/Client.cpp2
-rw-r--r--cpp/src/IcePatch2/Server.cpp29
-rw-r--r--cpp/src/IcePatch2/Util.cpp122
4 files changed, 59 insertions, 96 deletions
diff --git a/cpp/include/IcePatch2/Util.h b/cpp/include/IcePatch2/Util.h
index 7d9f5500a93..4041838cf69 100644
--- a/cpp/include/IcePatch2/Util.h
+++ b/cpp/include/IcePatch2/Util.h
@@ -21,8 +21,6 @@ ICE_PATCH2_API std::string lastError();
ICE_PATCH2_API std::string bytesToString(const Ice::ByteSeq&);
ICE_PATCH2_API Ice::ByteSeq stringToBytes(const std::string&);
-ICE_PATCH2_API bool isDir(const std::string&);
-
ICE_PATCH2_API std::string normalize(const std::string&);
ICE_PATCH2_API std::string getSuffix(const std::string&);
diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp
index c7018787e20..8c9581061f2 100644
--- a/cpp/src/IcePatch2/Client.cpp
+++ b/cpp/src/IcePatch2/Client.cpp
@@ -303,7 +303,7 @@ Client::usage(const string& appName)
"-v, --version Display the Ice version.\n"
"-t, --thorough Recalculate all checksums.";
- cerr << "Usage: " << appName << " [options] DIR" << endl;
+ cerr << "Usage: " << appName << " [options] [DIR]" << endl;
cerr << options << endl;
}
diff --git a/cpp/src/IcePatch2/Server.cpp b/cpp/src/IcePatch2/Server.cpp
index 013f66c0c11..7f30e1169d5 100644
--- a/cpp/src/IcePatch2/Server.cpp
+++ b/cpp/src/IcePatch2/Server.cpp
@@ -16,9 +16,6 @@
# include <direct.h>
#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-
using namespace std;
using namespace Ice;
using namespace IcePatch2;
@@ -125,16 +122,28 @@ IcePatch2::PatcherService::start(int argc, char* argv[])
}
}
- if(!isDir(dataDir))
- {
- throw "`" + dataDir + "' is not a directory";
- }
-
FileInfoSeq infoSeq;
try
{
- dataDir = normalize(dataDir);
+#ifdef _WIN32
+ if(dataDir[0] != '/' && !(dataDir.size() > 1 && isalpha(dataDir[0]) && dataDir[1] == ':'))
+ {
+ char cwd[_MAX_PATH];
+ if(_getcwd(cwd, _MAX_PATH) == NULL)
+#else
+ if(dataDir[0] != '/')
+ {
+ char cwd[PATH_MAX];
+ if(getcwd(cwd, PATH_MAX) == NULL)
+#endif
+ {
+ throw "cannot get the current directory:\n" + lastError();
+ }
+
+ dataDir = string(cwd) + '/' + dataDir;
+ }
+
loadFileInfoSeq(dataDir, infoSeq);
}
catch(const string& ex)
@@ -234,7 +243,7 @@ IcePatch2::PatcherService::usage(const string& appName)
"--nochdir Do not change the current working directory."
);
#endif
- cerr << "Usage: " << appName << " [options] DIR" << endl;
+ cerr << "Usage: " << appName << " [options] [DIR]" << endl;
cerr << options << endl;
}
diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp
index 5f2f92b5e14..0bf6c71106c 100644
--- a/cpp/src/IcePatch2/Util.cpp
+++ b/cpp/src/IcePatch2/Util.cpp
@@ -210,56 +210,10 @@ IcePatch2::stringToBytes(const string& str)
return bytes;
}
-bool
-IcePatch2::isDir(const string& path)
-{
- struct stat buf;
- if(stat(path.c_str(), &buf) == -1)
- {
- throw "cannot stat `" + path + "':\n" + lastError();
- }
- return S_ISDIR(buf.st_mode);
-}
-
string
IcePatch2::normalize(const string& path)
{
- assert(!path.empty());
-
- static IceUtil::StaticMutex mutex = ICE_STATIC_MUTEX_INITIALIZER;
-
-#ifdef _WIN32
- static char cwd[_MAX_PATH];
-#else
- static char cwd[PATH_MAX];
-#endif
-
- {
- IceUtil::StaticMutex::Lock sync(mutex);
-
- if(*cwd == '\0')
- {
-#ifdef _WIN32
- if(_getcwd(cwd, _MAX_PATH) == NULL)
-#else
- if(getcwd(cwd, PATH_MAX) == NULL)
-#endif
- {
- throw "cannot get the current directory:\n" + lastError();
- }
- }
- }
-
- string result;
-#ifdef _WIN32
- if(path[0] != '/' && path[0] != '\\' && !(path.size() > 1 && isalpha(path[0]) && path[1] == ':'))
-#else
- if(path[0] != '/')
-#endif
- {
- result = cwd + '/';
- }
- result += path;
+ string result = path;
string::size_type pos;
@@ -282,41 +236,23 @@ IcePatch2::normalize(const string& path)
pos = 0;
while((pos = result.find("/./", pos)) != string::npos)
{
- result.erase(pos, 2); // Remove redundant current directory components.
+ result.erase(pos, 2);
}
- if(result.size() > 1 && result[result.size() - 1] == '/')
- {
- result.erase(result.size() - 1, 1);
- }
-
- while(result.size() > 2 && result.substr(0, 2) == "./")
- {
- result.erase(0, 2);
- }
-
-
-
if(result.substr(0, 2) == "./")
{
result.erase(0, 2);
}
- if(result == "/.")
- {
- return "/";
- }
-
- while(result.size() > 2 && result.substr(result.size() - 2, 2) == "/.")
+ if(result.size() >= 2 && result.substr(result.size() - 2, 2) == "/.")
{
result.erase(result.size() - 2, 2);
}
- if(result.size() > 1 && result[result.size() - 1] == '/')
+ if(result.size() >= 1 && result[result.size() - 1] == '/')
{
result.erase(result.size() - 1);
}
- cerr << "normalize: returning " << result << endl;
return result;
}
@@ -325,20 +261,32 @@ string
IcePatch2::getSuffix(const string& pa)
{
const string path = normalize(pa);
- string::size_type slashPos = path.rfind('/');
- slashPos = slashPos == string::npos ? 0 : slashPos + 1;
- string::size_type dotPos = path.find('.', slashPos);
- return dotPos == string::npos ? string() : path.substr(dotPos + 1);
+
+ string::size_type pos = path.rfind('.');
+ if(pos == string::npos)
+ {
+ return string();
+ }
+ else
+ {
+ return path.substr(pos + 1);
+ }
}
string
IcePatch2::getWithoutSuffix(const string& pa)
{
const string path = normalize(pa);
- string::size_type slashPos = path.rfind('/');
- slashPos = slashPos == string::npos ? 0 : slashPos + 1;
- string::size_type dotPos = path.rfind('.', slashPos);
- return dotPos == string::npos ? path : path.substr(0, dotPos);
+
+ string::size_type pos = path.rfind('.');
+ if(pos == string::npos)
+ {
+ return path;
+ }
+ else
+ {
+ return path.substr(0, pos);
+ }
}
bool
@@ -354,24 +302,32 @@ string
IcePatch2::getBasename(const string& pa)
{
const string path = normalize(pa);
- if(path == "/")
+
+ string::size_type pos = path.rfind('/');
+ if(pos == string::npos)
{
return path;
}
- string::size_type slashPos = path.rfind('/');
- return slashPos == string::npos ? path : path.substr(slashPos + 1);
+ else
+ {
+ return path.substr(pos + 1);
+ }
}
string
IcePatch2::getDirname(const string& pa)
{
const string path = normalize(pa);
- if(path == "/")
+
+ string::size_type pos = path.rfind('/');
+ if(pos == string::npos)
{
- return path;
+ return string();
+ }
+ else
+ {
+ return path.substr(0, pos);
}
- string::size_type slashPos = path.rfind('/');
- return slashPos == string::npos ? string() : path.substr(0, slashPos);
}
void