summaryrefslogtreecommitdiff
path: root/cpp/src/IcePatch2/Calc.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2005-01-11 03:59:42 +0000
committerMichi Henning <michi@zeroc.com>2005-01-11 03:59:42 +0000
commitbfdd46fc78552716f25900de5b75a6aff79c6d7c (patch)
treeb0078934828f0c08be6d5f2bf12757e1010f5ed1 /cpp/src/IcePatch2/Calc.cpp
parentCommented out the delete[] args calls again -- I couldn't reproduce a (diff)
downloadice-bfdd46fc78552716f25900de5b75a6aff79c6d7c.tar.bz2
ice-bfdd46fc78552716f25900de5b75a6aff79c6d7c.tar.xz
ice-bfdd46fc78552716f25900de5b75a6aff79c6d7c.zip
Minor refactoring of IcePatch2.
Diffstat (limited to 'cpp/src/IcePatch2/Calc.cpp')
-rw-r--r--cpp/src/IcePatch2/Calc.cpp71
1 files changed, 19 insertions, 52 deletions
diff --git a/cpp/src/IcePatch2/Calc.cpp b/cpp/src/IcePatch2/Calc.cpp
index 1621c63f196..5d8f7aeefce 100644
--- a/cpp/src/IcePatch2/Calc.cpp
+++ b/cpp/src/IcePatch2/Calc.cpp
@@ -174,68 +174,35 @@ main(int argc, char* argv[])
usage(argv[0]);
return EXIT_FAILURE;
}
- dataDir = normalize(args[0]);
-
- for(vector<string>::size_type i = 1; i < args.size(); ++i)
- {
- fileSeq.push_back(normalize(args[i]));
- }
try
{
- StringSeq::iterator p;
- string absDataDir = dataDir;
-
-#ifdef _WIN32
- char cwd[_MAX_PATH];
- if(_getcwd(cwd, _MAX_PATH) == NULL)
+ //
+ // 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)
{
- throw "cannot get the current directory:\n" + lastError();
+ string msg = "cannot change working directory to `" + args[0] + "': " + lastError();
+ throw msg;
}
-
- 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)
- {
- throw "cannot get the current directory:\n" + lastError();
- }
-
- if(absDataDir[0] != '/')
- {
- absDataDir = string(cwd) + '/' + absDataDir;
- }
-
- for(p = fileSeq.begin(); p != fileSeq.end(); ++p)
+ dataDir = normalize(".");
+ string dataDirWithSlash = dataDir + "/";
+
+ for(vector<string>::size_type i = 1; i < args.size(); ++i)
{
- if((*p)[0] != '/')
- {
- *p = string(cwd) + '/' + *p;
- }
+ fileSeq.push_back(normalize(args[i]));
}
-#endif
- string absDataDirWithSlash = absDataDir + '/';
-
+ StringSeq::iterator p;
for(p = fileSeq.begin(); p != fileSeq.end(); ++p)
{
- if(p->compare(0, absDataDirWithSlash.size(), absDataDirWithSlash) != 0)
+ if(p->compare(0, dataDirWithSlash.size(), dataDirWithSlash) != 0)
{
throw "`" + *p + "' is not a path in `" + dataDir + "'";
}
- p->erase(0, absDataDirWithSlash.size());
+ p->erase(0, dataDirWithSlash.size());
}
FileInfoSeq infoSeq;
@@ -243,21 +210,21 @@ main(int argc, char* argv[])
if(fileSeq.empty())
{
CalcCB calcCB;
- if(!getFileInfoSeq(absDataDir, compress, verbose ? &calcCB : 0, infoSeq))
+ if(!getFileInfoSeq(".", compress, verbose ? &calcCB : 0, infoSeq))
{
return EXIT_FAILURE;
}
}
else
{
- loadFileInfoSeq(absDataDir, infoSeq);
+ loadFileInfoSeq(".", infoSeq);
for(p = fileSeq.begin(); p != fileSeq.end(); ++p)
{
FileInfoSeq partialInfoSeq;
CalcCB calcCB;
- if(!getFileInfoSeqSubDir(absDataDir, *p, compress, verbose ? &calcCB : 0, partialInfoSeq))
+ if(!getFileInfoSeq(*p, compress, verbose ? &calcCB : 0, partialInfoSeq))
{
return EXIT_FAILURE;
}
@@ -312,7 +279,7 @@ main(int argc, char* argv[])
}
}
- saveFileInfoSeq(absDataDir, infoSeq);
+ saveFileInfoSeq(dataDir, infoSeq);
}
catch(const string& ex)
{