BuildInstaller is working

This commit is contained in:
Steve Checkoway
2003-09-10 02:42:49 +00:00
parent c7e13b3cd4
commit 0a54033e39
3 changed files with 96 additions and 64 deletions
@@ -12,30 +12,57 @@ using namespace std;
#include "StdString.h" #include "StdString.h"
#include "InstallerFile.h" #include "InstallerFile.h"
#include "Processor.h" #include "Processor.h"
#include <unistd.h>
#include <sys/param.h>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <stack> #include <stack>
#include <map> #include <map>
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; static bool archiveMade = false;
CString command; CString command;
if (archiveMade) if (archiveMade)
command = "tar rfP '"; command = "tar rfPC '";
else else
{ {
archiveMade = true; archiveMade = true;
command = "tar cfP '"; command = "tar cfPC '";
} }
command += archivePath + "' '" + file + "'"; command += archivePath + "' '" + dir +"' '" + file + "'";
system(command); system(command);
printf("%s\n", file.c_str()); 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) void PrintUsage(int err)
{ {
printf("usage: BuildInstaller config [dir]\n\n" printf("usage: BuildInstaller config [dir]\n\n"
@@ -94,7 +121,7 @@ int main(int argc, char *argv[])
CString archivePath = outDir + "/archive.tar"; CString archivePath = outDir + "/archive.tar";
Processor p(archivePath, HandleFile, NULL, NULL, false); Processor p(archivePath, HandleFile, GetPath, NULL, false);
while (nextLine < config.GetNumLines()) while (nextLine < config.GetNumLines())
p.ProcessLine(config.GetLine(nextLine), nextLine); p.ProcessLine(config.GetLine(nextLine), nextLine);
+61 -57
View File
@@ -46,22 +46,11 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
{ {
CStringArray parts; CStringArray parts;
split(line, ":", parts); split(line, ":", parts);
if (!mInstalling)
{
if (parts[0] == "FILE")
{
if (parts.size() != 3)
goto error;
(*mHandleFile)(parts[1], mPath, true);
}
++nextLine;
return;
}
if (parts[0] == "LABEL") if (parts[0] == "LABEL")
{ {
printf("%u: %s\n", nextLine, line.c_str());
if (parts.size() != 2) if (parts.size() != 2)
goto error; goto error;
if (mDoGoto && parts[1] == mLabel) if (mDoGoto && parts[1] == mLabel)
@@ -79,6 +68,54 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
return; 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[0] == "GOTO")
{ {
if (parts.size() != 2) if (parts.size() != 2)
@@ -96,8 +133,8 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
mDoGoto = true; mDoGoto = true;
mReturnStack.push(++nextLine); mReturnStack.push(++nextLine);
return; return;
} }
if (parts[0] == "IF") if (parts[0] == "IF")
{ {
if (parts.size() != 4) if (parts.size() != 4)
@@ -123,17 +160,6 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
return; 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 (parts[0] == "RETURN")
{ {
if (mReturnStack.empty()) if (mReturnStack.empty())
@@ -146,22 +172,13 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
return; 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[0] == "SETVAR")
{ {
if (parts.size() < 3) if (parts.size() < 3)
goto error; goto error;
CString temp = ""; CString temp = "";
for (unsigned i=2; i<parts.size(); ++i) for (unsigned i=2; i<parts.size(); ++i)
temp += parts[i]; temp += ResolveVar(parts[i]);
mVars[parts[1]] = temp; mVars[parts[1]] = temp;
++nextLine; ++nextLine;
return; return;
@@ -171,27 +188,12 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
{ {
if (parts.size() != 2) if (parts.size() != 2)
goto error; goto error;
CString path = mCWD + ResolveVar(parts[1]); CString path = mCWD + "/" + ResolveVar(parts[1]);
if (mkdir(path, 777)) if (mkdir(path, 0777))
(*mError)("%s\n", strerror(errno)); {
++nextLine; if (errno != EEXIST)
return; (*mError)("%s\n", strerror(errno));
} }
if (parts[0] == "CD")
{
if (parts.size() != 2)
goto error;
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());
++nextLine; ++nextLine;
return; return;
} }
@@ -214,6 +216,8 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
if (parts.size() != 3) if (parts.size() != 3)
goto error; goto error;
mVars[parts[1]] = (*mAsk)(parts[2]); mVars[parts[1]] = (*mAsk)(parts[2]);
++nextLine;
return;
} }
error: error:
+3 -2
View File
@@ -18,7 +18,8 @@ using namespace std;
class Processor class Processor
{ {
private: private:
typedef void (*handleFileFunc)(const CString& file, const CString& archivePath, bool overwrite); typedef void (*handleFileFunc)(const CString& file, const CString& dir, const CString& archivePath,
bool overwrite);
typedef const CString (*getPathFunc)(const CString& ID); typedef const CString (*getPathFunc)(const CString& ID);
typedef void (*errorFunc)(const char *fmt, ...); typedef void (*errorFunc)(const char *fmt, ...);
typedef bool (*askFunc)(const CString& question); typedef bool (*askFunc)(const CString& question);
@@ -43,7 +44,7 @@ private:
public: public:
Processor(CString& path, handleFileFunc f, getPathFunc p, askFunc a, bool i) Processor(CString& path, handleFileFunc f, getPathFunc p, askFunc a, bool i)
: mDoGoto(false), mPath(path), mCWD("."), mHandleFile(f), mGetPath(p), mAsk(a), : mDoGoto(false), mPath(path), mCWD("."), mHandleFile(f), mGetPath(p), mAsk(a),
mError(Processor::DefaultError), mInstalling(i) { } mError(Processor::DefaultError), mInstalling(i) { mConditionals["INSTALLING"] = i; }
void ProcessLine(const CString& line, unsigned& nextLine); void ProcessLine(const CString& line, unsigned& nextLine);
void SetErrorFunc(errorFunc f) { mError = f; } void SetErrorFunc(errorFunc f) { mError = f; }
}; };