Changed: Minor changes

This commit is contained in:
kervala 2016-01-18 21:31:23 +01:00
parent eb30647103
commit 58d7c95b05

View file

@ -51,35 +51,35 @@ int main(int argc, char *argv[])
printf("%s <world_edit_class> <primitive_file> [-test]", argv[0]); printf("%s <world_edit_class> <primitive_file> [-test]", argv[0]);
return -1; return -1;
} }
string sourceDocName; string sourceDocName;
if (!test) if (!test)
sourceDocName = argv[2]; sourceDocName = argv[2];
else else
sourceDocName = "test_compilateur.primitive"; sourceDocName = "test_compilateur.primitive";
// remove the path // remove the path
sourceDocName = CFile::getFilename(sourceDocName); sourceDocName = CFile::getFilename(sourceDocName);
// init ligo // init ligo
NLLIGO::CLigoConfig LigoConfig; NLLIGO::CLigoConfig LigoConfig;
CPrimitiveContext::instance().CurrentLigoConfig = &LigoConfig; CPrimitiveContext::instance().CurrentLigoConfig = &LigoConfig;
nlinfo("Reading ligo configuration file..."); nlinfo("Reading ligo configuration file...");
if (!LigoConfig.readPrimitiveClass (argv[1], false)) if (!LigoConfig.readPrimitiveClass (argv[1], false))
{ {
nlwarning("Can't read '%s' !", argv[1]); nlwarning("Can't read '%s' !", argv[1]);
return -1; return -1;
} }
NLLIGO::Register(); NLLIGO::Register();
nlinfo("Reading primitive file..."); nlinfo("Reading primitive file...");
CPrimitives primDoc; CPrimitives primDoc;
CPrimitiveContext::instance().CurrentPrimitive = &primDoc; CPrimitiveContext::instance().CurrentPrimitive = &primDoc;
loadXmlPrimitiveFile(primDoc, sourceDocName, LigoConfig); loadXmlPrimitiveFile(primDoc, sourceDocName, LigoConfig);
CMissionCompiler mc; CMissionCompiler mc;
if (test) if (test)
@ -99,7 +99,7 @@ int main(int argc, char *argv[])
script = script.replace(NL.c_str(), "\n"); script = script.replace(NL.c_str(), "\n");
const char *tmp = ::getenv("TEMP"); const char *tmp = ::getenv("TEMP");
FILE *fp = ::fopen((string(tmp)+"/compiled_mission.script").c_str(), "w"); FILE *fp = ::fopen((string(tmp)+"/compiled_mission.script").c_str(), "w");
::fwrite(script.data(), script.size(), 1, fp); ::fwrite(script.data(), script.size(), 1, fp);
::fclose(fp); ::fclose(fp);
@ -119,7 +119,7 @@ int main(int argc, char *argv[])
} }
return 0; return 0;
} }
nlinfo("Compiling missions..."); nlinfo("Compiling missions...");
try try
{ {
@ -166,14 +166,14 @@ int main(int argc, char *argv[])
TPrimitiveSet scripts; TPrimitiveSet scripts;
CPrimitiveSet<TPrimitiveClassPredicate> filter; CPrimitiveSet<TPrimitiveClassPredicate> filter;
filter.buildSet(primDoc->RootNode, TPrimitiveClassPredicate("mission"), scripts); filter.buildSet(primDoc->RootNode, TPrimitiveClassPredicate("mission"), scripts);
// for each script, check if it was generated, and if so, check the name // for each script, check if it was generated, and if so, check the name
// of the source primitive file. // of the source primitive file.
for (uint i=0; i<scripts.size(); ++i) for (uint i=0; i<scripts.size(); ++i)
{ {
vector<string> *script; vector<string> *script;
if (scripts[i]->getPropertyByName("script", script) && !script->empty()) if (scripts[i]->getPropertyByName("script", script) && !script->empty())
{ {
// Format should be : #compiled from <source_primitive_name> // Format should be : #compiled from <source_primitive_name>
if (script->front().find("compiled from")) if (script->front().find("compiled from"))
{ {
@ -208,14 +208,14 @@ int main(int argc, char *argv[])
if (bots.empty()) if (bots.empty())
{ {
nlwarning("Can't find bot '%s' in primitive '%s' !", nlwarning("Can't find bot '%s' in primitive '%s' !",
mission.getGiverName().c_str(), mission.getGiverName().c_str(),
fileName.c_str()); fileName.c_str());
throw EParseException(NULL, "Can't find giver in primitive"); throw EParseException(NULL, "Can't find giver in primitive");
} }
else if (bots.size() > 1) else if (bots.size() > 1)
{ {
nlwarning("Found more than one bot named '%s' in primitive '%s' !", nlwarning("Found more than one bot named '%s' in primitive '%s' !",
mission.getGiverName().c_str(), mission.getGiverName().c_str(),
fileName.c_str()); fileName.c_str());
throw EParseException(NULL, "More than one bot with giver name in primitive"); throw EParseException(NULL, "More than one bot with giver name in primitive");