* added C++-style comment and whitespace stripping at line ends. turn this off/on with #linestrip=0/1. default is on. note: this might break older scripts using // in the code somewhere.
* added #comments-start (#cs) and #comments-end (#ce) to make commenting out large code blocks possible
This commit is contained in:
parent
281962dad0
commit
cf7758074a
@ -258,6 +258,8 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
|
|||||||
std::string label, value, line, sn;
|
std::string label, value, line, sn;
|
||||||
std::fstream f;
|
std::fstream f;
|
||||||
bool load_debug=false,load_notify=false,cantload=false;
|
bool load_debug=false,load_notify=false,cantload=false;
|
||||||
|
bool line_strip = true; // true by default
|
||||||
|
bool commented = false;
|
||||||
char z;
|
char z;
|
||||||
unsigned int absline=0;
|
unsigned int absline=0;
|
||||||
DefScript *curScript = NULL;
|
DefScript *curScript = NULL;
|
||||||
@ -301,6 +303,44 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
|
|||||||
continue;
|
continue;
|
||||||
if(line.at(0)=='/' && line.at(1)=='/')
|
if(line.at(0)=='/' && line.at(1)=='/')
|
||||||
continue; // line is comment, proceed with next line
|
continue; // line is comment, proceed with next line
|
||||||
|
|
||||||
|
if(line_strip)
|
||||||
|
{
|
||||||
|
// strip comments at the end of the line
|
||||||
|
unsigned int cmpos = 0;
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
// note: this must also cover lines like: "out blah \// no-comment // comment"
|
||||||
|
cmpos = line.find("//",cmpos+1); // start searching at one position later then previous
|
||||||
|
if(cmpos != std::string::npos)
|
||||||
|
{
|
||||||
|
if(line[cmpos-1] == '\\')
|
||||||
|
continue;
|
||||||
|
line = line.substr(0,cmpos);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// strip spaces at the end of the line
|
||||||
|
while(line.at(line.length()-1) == ' ' || line.at(line.length()-1) == '\t')
|
||||||
|
{
|
||||||
|
line.erase(line.length()-1,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// need to check comments-end seperatedly
|
||||||
|
if(line=="#ce" || line=="#comments-end")
|
||||||
|
{
|
||||||
|
commented = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// commented lines will not be loaded nor have any #-tags evaluated (except the one above!)
|
||||||
|
if(commented)
|
||||||
|
continue;
|
||||||
|
|
||||||
if(line.at(0)=='#')
|
if(line.at(0)=='#')
|
||||||
{
|
{
|
||||||
line.erase(0,1); // remove #
|
line.erase(0,1); // remove #
|
||||||
@ -319,6 +359,10 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
|
|||||||
_DEFSC_DEBUG(printf("DefScript: now loading '%s'\n",sn.c_str()));
|
_DEFSC_DEBUG(printf("DefScript: now loading '%s'\n",sn.c_str()));
|
||||||
curScript=Script[sn];
|
curScript=Script[sn];
|
||||||
}
|
}
|
||||||
|
else if(label=="linestrip")
|
||||||
|
{
|
||||||
|
line_strip = isTrue(value);
|
||||||
|
}
|
||||||
else if(line=="debug")
|
else if(line=="debug")
|
||||||
{
|
{
|
||||||
if(curScript)
|
if(curScript)
|
||||||
@ -335,6 +379,10 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
|
|||||||
DeleteScript(SN_ONLOAD);
|
DeleteScript(SN_ONLOAD);
|
||||||
curScript=Script[sn];
|
curScript=Script[sn];
|
||||||
}
|
}
|
||||||
|
else if(line=="cs" || line=="comments-start")
|
||||||
|
{
|
||||||
|
commented = true;
|
||||||
|
}
|
||||||
else if(strncmp(line.c_str(),"tag",3)==0 || strncmp(line.c_str(),"mark",4)==0)
|
else if(strncmp(line.c_str(),"tag",3)==0 || strncmp(line.c_str(),"mark",4)==0)
|
||||||
{
|
{
|
||||||
curScript->AddLine("#" + line);
|
curScript->AddLine("#" + line);
|
||||||
@ -409,7 +457,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
|
|||||||
}
|
}
|
||||||
else if(line[bpos]=='\\')
|
else if(line[bpos]=='\\')
|
||||||
{
|
{
|
||||||
bpos++;
|
bpos++; // skip next char checking
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user