summaryrefslogtreecommitdiff
path: root/cpp/src/IcePatch2/Calc.cpp
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2005-01-27 21:22:48 +0000
committerMarc Laukien <marc@zeroc.com>2005-01-27 21:22:48 +0000
commit1decea8e7dcbf1c7836d27401d63229c49191556 (patch)
treed4bd9e931ea34841bc194b711f77f9cec4a499b3 /cpp/src/IcePatch2/Calc.cpp
parentbug fix for thread per connection (diff)
downloadice-1decea8e7dcbf1c7836d27401d63229c49191556.tar.bz2
ice-1decea8e7dcbf1c7836d27401d63229c49191556.tar.xz
ice-1decea8e7dcbf1c7836d27401d63229c49191556.zip
icepatch2 changes
Diffstat (limited to 'cpp/src/IcePatch2/Calc.cpp')
-rw-r--r--cpp/src/IcePatch2/Calc.cpp78
1 files changed, 58 insertions, 20 deletions
diff --git a/cpp/src/IcePatch2/Calc.cpp b/cpp/src/IcePatch2/Calc.cpp
index 29b7199ee1e..358794c146d 100644
--- a/cpp/src/IcePatch2/Calc.cpp
+++ b/cpp/src/IcePatch2/Calc.cpp
@@ -174,36 +174,68 @@ main(int argc, char* argv[])
usage(argv[0]);
return EXIT_FAILURE;
}
+ dataDir = simplify(args[0]);
+
+ for(vector<string>::size_type i = 1; i < args.size(); ++i)
+ {
+ fileSeq.push_back(simplify(args[i]));
+ }
try
{
- //
- // Make working directory the data directory *before* calling normalize() for
- // for the first time (because normalize caches the current working directory).
- //
- if(chdir(args[0].c_str()) != 0)
+ StringSeq::iterator p;
+ string absDataDir = dataDir;
+
+#ifdef _WIN32
+ char cwd[_MAX_PATH];
+ if(_getcwd(cwd, _MAX_PATH) == NULL)
{
- string msg = "cannot change working directory to `" + args[0] + "': " + lastError();
- throw msg;
+ throw "cannot get the current directory:\n" + lastError();
}
- dataDir = normalize(".");
- string dataDirWithSlash = dataDir + "/";
-
- for(vector<string>::size_type i = 1; i < args.size(); ++i)
+
+ if(absDataDir[0] != '/' && !(absDataDir.size() > 1 && isalpha(absDataDir[0]) && absDataDir[1] == ':'))
+ {
+ absDataDir = string(cwd) + '/' + absDataDir;
+ }
+
+ for(p = fileSeq.begin(); p != fileSeq.end(); ++p)
+ {
+ if((*p)[0] != '/' && !(p->size() > 1 && isalpha((*p)[0]) && (*p)[1] == ':'))
+ {
+ *p = string(cwd) + '/' + *p;
+ }
+ }
+#else
+ char cwd[PATH_MAX];
+ if(getcwd(cwd, PATH_MAX) == NULL)
{
- fileSeq.push_back(normalize(args[i]));
+ throw "cannot get the current directory:\n" + lastError();
}
+
+ if(absDataDir[0] != '/')
+ {
+ absDataDir = string(cwd) + '/' + absDataDir;
+ }
+
+ for(p = fileSeq.begin(); p != fileSeq.end(); ++p)
+ {
+ if((*p)[0] != '/')
+ {
+ *p = string(cwd) + '/' + *p;
+ }
+ }
+#endif
- StringSeq::iterator p;
+ string absDataDirWithSlash = absDataDir + '/';
+
for(p = fileSeq.begin(); p != fileSeq.end(); ++p)
{
- if(p->compare(0, dataDirWithSlash.size(), dataDirWithSlash) != 0)
+ if(p->compare(0, absDataDirWithSlash.size(), absDataDirWithSlash) != 0)
{
throw "`" + *p + "' is not a path in `" + dataDir + "'";
}
- p->erase(0, dataDirWithSlash.size());
- *p = "./" + *p;
+ p->erase(0, absDataDirWithSlash.size());
}
FileInfoSeq infoSeq;
@@ -211,18 +243,24 @@ main(int argc, char* argv[])
if(fileSeq.empty())
{
CalcCB calcCB;
- getFileInfoSeq(".", compress, verbose ? &calcCB : 0, infoSeq);
+ if(!getFileInfoSeq(absDataDir, compress, verbose ? &calcCB : 0, infoSeq))
+ {
+ return EXIT_FAILURE;
+ }
}
else
{
- loadFileInfoSeq(".", infoSeq);
+ loadFileInfoSeq(absDataDir, infoSeq);
for(p = fileSeq.begin(); p != fileSeq.end(); ++p)
{
FileInfoSeq partialInfoSeq;
CalcCB calcCB;
- getFileInfoSeq(*p, compress, verbose ? &calcCB : 0, partialInfoSeq);
+ if(!getFileInfoSeqSubDir(absDataDir, *p, compress, verbose ? &calcCB : 0, partialInfoSeq))
+ {
+ return EXIT_FAILURE;
+ }
FileInfoSeq newInfoSeq;
newInfoSeq.reserve(infoSeq.size());
@@ -274,7 +312,7 @@ main(int argc, char* argv[])
}
}
- saveFileInfoSeq(dataDir, infoSeq);
+ saveFileInfoSeq(absDataDir, infoSeq);
}
catch(const string& ex)
{