BuildInstaller is working
This commit is contained in:
@@ -12,30 +12,57 @@ using namespace std;
|
||||
#include "StdString.h"
|
||||
#include "InstallerFile.h"
|
||||
#include "Processor.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <stack>
|
||||
#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;
|
||||
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);
|
||||
|
||||
@@ -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<parts.size(); ++i)
|
||||
temp += parts[i];
|
||||
temp += ResolveVar(parts[i]);
|
||||
mVars[parts[1]] = temp;
|
||||
++nextLine;
|
||||
return;
|
||||
@@ -171,27 +188,12 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
|
||||
{
|
||||
if (parts.size() != 2)
|
||||
goto error;
|
||||
CString path = mCWD + ResolveVar(parts[1]);
|
||||
if (mkdir(path, 777))
|
||||
(*mError)("%s\n", strerror(errno));
|
||||
++nextLine;
|
||||
return;
|
||||
}
|
||||
|
||||
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());
|
||||
CString path = mCWD + "/" + ResolveVar(parts[1]);
|
||||
if (mkdir(path, 0777))
|
||||
{
|
||||
if (errno != EEXIST)
|
||||
(*mError)("%s\n", strerror(errno));
|
||||
}
|
||||
++nextLine;
|
||||
return;
|
||||
}
|
||||
@@ -214,6 +216,8 @@ void Processor::ProcessLine(const CString& line, unsigned& nextLine)
|
||||
if (parts.size() != 3)
|
||||
goto error;
|
||||
mVars[parts[1]] = (*mAsk)(parts[2]);
|
||||
++nextLine;
|
||||
return;
|
||||
}
|
||||
|
||||
error:
|
||||
|
||||
@@ -18,7 +18,8 @@ using namespace std;
|
||||
class Processor
|
||||
{
|
||||
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 void (*errorFunc)(const char *fmt, ...);
|
||||
typedef bool (*askFunc)(const CString& question);
|
||||
@@ -43,7 +44,7 @@ private:
|
||||
public:
|
||||
Processor(CString& path, handleFileFunc f, getPathFunc p, askFunc a, bool i)
|
||||
: 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 SetErrorFunc(errorFunc f) { mError = f; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user