From 0a54033e39c1236e580afa4a05eb2cefa42591b7 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Wed, 10 Sep 2003 02:42:49 +0000 Subject: [PATCH] BuildInstaller is working --- .../PBProject/Installer/BuildInstaller.cpp | 37 +++++- stepmania/PBProject/Installer/Processor.cpp | 118 +++++++++--------- stepmania/PBProject/Installer/Processor.h | 5 +- 3 files changed, 96 insertions(+), 64 deletions(-) diff --git a/stepmania/PBProject/Installer/BuildInstaller.cpp b/stepmania/PBProject/Installer/BuildInstaller.cpp index 90884884b7..fd90dd52c8 100644 --- a/stepmania/PBProject/Installer/BuildInstaller.cpp +++ b/stepmania/PBProject/Installer/BuildInstaller.cpp @@ -12,30 +12,57 @@ using namespace std; #include "StdString.h" #include "InstallerFile.h" #include "Processor.h" +#include +#include #include #include #include #include -void HandleFile(const CString& file, const CString& archivePath, bool overwrite) +void HandleFile(const CString& file, const CString& dir, const CString& archivePath, bool overwrite) { static bool archiveMade = false; CString command; if (archiveMade) - command = "tar rfP '"; + command = "tar rfPC '"; else { archiveMade = true; - command = "tar cfP '"; + command = "tar cfPC '"; } - command += archivePath + "' '" + file + "'"; + command += archivePath + "' '" + dir +"' '" + file + "'"; system(command); printf("%s\n", file.c_str()); } +const CString GetPath(const CString& ID) +{ + if (ID == "install path") + { + char cwd[MAXPATHLEN]; + char path[MAXPATHLEN]; + char *ptr; + + getwd(cwd); + printf("Enter a path (relative or absolute) to the install files\n" + "The current working directory is: %s\n" + "> ", cwd); + ptr = gets(path); + ASSERT(ptr); + while (*ptr != '\000' && (*ptr == ' ' || *ptr == '\t')) + ++ptr; + if (*ptr == '/') + return ptr; + return CString(cwd) + "/" + CString(ptr); + } + + fprintf(stderr, "Unknown path command, return `.'\n"); + return "."; +} + void PrintUsage(int err) { printf("usage: BuildInstaller config [dir]\n\n" @@ -94,7 +121,7 @@ int main(int argc, char *argv[]) CString archivePath = outDir + "/archive.tar"; - Processor p(archivePath, HandleFile, NULL, NULL, false); + Processor p(archivePath, HandleFile, GetPath, NULL, false); while (nextLine < config.GetNumLines()) p.ProcessLine(config.GetLine(nextLine), nextLine); diff --git a/stepmania/PBProject/Installer/Processor.cpp b/stepmania/PBProject/Installer/Processor.cpp index c7c5e3afab..4ee8f0c0f3 100644 --- a/stepmania/PBProject/Installer/Processor.cpp +++ b/stepmania/PBProject/Installer/Processor.cpp @@ -46,22 +46,11 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine) { CStringArray parts; - split(line, ":", parts); - - if (!mInstalling) - { - if (parts[0] == "FILE") - { - if (parts.size() != 3) - goto error; - (*mHandleFile)(parts[1], mPath, true); - } - ++nextLine; - return; - } + split(line, ":", parts); if (parts[0] == "LABEL") { + printf("%u: %s\n", nextLine, line.c_str()); if (parts.size() != 2) goto error; if (mDoGoto && parts[1] == mLabel) @@ -79,6 +68,54 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine) return; } + printf("%u: %s\n", nextLine, line.c_str()); + + if (parts[0] == "FILE") + { + if (parts.size() != 3) + goto error; + bool overwrite = ResolveConditional(parts[2]); + (*mHandleFile)(parts[1], mCWD, mPath, overwrite); + + ++nextLine; + return; + } + + if (parts[0] == "GETPATH") + { + if (parts.size() != 3) + goto error; + mVars[parts[2]] = (*mGetPath)(parts[1]); + ++nextLine; + return; + } + + if (parts[0] == "CD") + { + if (parts.size() != 3) + goto error; + ++nextLine; + if (!ResolveConditional(parts[2])) + return; + CString path = ResolveVar(parts[1]); + if (path[0] == '/') + mCWD = path; + else + mCWD += "/" + path; + struct stat st; + if (stat(mCWD, &st)) + (*mError)("%s\n", strerror(errno)); + if (!(st.st_mode & S_IFDIR)) + (*mError)("%s is not a directory.\n", mCWD.c_str()); + return; + } + + if (!mInstalling) + { + ++nextLine; + return; + } + if (parts[0] == "GOTO") { if (parts.size() != 2) @@ -96,8 +133,8 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine) mDoGoto = true; mReturnStack.push(++nextLine); return; - } - + } + if (parts[0] == "IF") { if (parts.size() != 4) @@ -123,17 +160,6 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine) return; } - if (parts[0] == "FILE") - { - if (parts.size() != 3) - goto error; - bool overwrite = ResolveConditional(parts[2]); - (*mHandleFile)(parts[1], mPath, overwrite); - - ++nextLine; - return; - } - if (parts[0] == "RETURN") { if (mReturnStack.empty()) @@ -146,22 +172,13 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine) return; } - if (parts[0] == "GETPATH") - { - if (parts.size() != 3) - goto error; - mVars[parts[2]] = (*mGetPath)(parts[1]); - ++nextLine; - return; - } - if (parts[0] == "SETVAR") { if (parts.size() < 3) goto error; CString temp = ""; for (unsigned i=2; i