Example #1
0
 void _doStore(const std::string& name) {
     if (_loads.count(name))
         return;
     _stores.insert(name);
 }
Example #2
0
bool RecursiveParse(string& file_name, string& dir)
{
    static char buf[4096];

    file_name=Map["ScriptsDirectory"]+dir+file_name;
    FILE* f=fopen(file_name.c_str(),"r");
    if(!f)
    {
        printf("Couldn't open %s for reading.\n",file_name.c_str());
        return false;
    }
    while(fgets(buf,4096,f))
    {
        int pre=0;
        while(buf[pre] && isSpace(buf[pre])) pre++;
        if(!buf[pre] || buf[pre]!='#') continue;

        // buf[pre] == '#'
        int post = pre + 1;
        while(buf[post] && isSpace(buf[post])) post++;
        if(!buf[post]) continue;

        string line(buf);
        line.erase(pre, post - pre);

        StrVec vec;
        strsplit(line,vec);
        if(!vec[0].compare("define") && !IGNORING)
        {
            if(vec.size()<1) continue; // err
            string def=vec[1];
            int pos=def.find("@");
            if(pos>=0) def=def.substr(0,pos);
            Defines.insert(def);
            continue;
        }
        else if(!vec[0].compare("include") && !IGNORING)
        {
            if(vec.size()<1) continue; // err
            string incname=vec[1];
            if(incname[0]!='\"' || incname[incname.size()-1]!='\"') continue;
            incname=stolower(incname.substr(1,incname.size()-2));
            int idx=incname.find_last_of("/");
            string sdir = dir;
            if(idx!=-1)
            {
                sdir = dir + incname.substr(0,idx+1);
                incname = incname.substr(idx+1,incname.length()-idx-1);
            }

            if(!Headers.count(trimmedName(sdir+incname)))
            {
                Headers.insert(trimmedName(sdir+incname));
                printf("\tFound new header: '%s'\n",incname.c_str());
            }

            if(!RecursiveParse(incname, sdir))
                printf("Ignoring the include file %s.\n", incname.c_str());

            continue;
        }
        else if(!vec[0].compare("ifdef"))
        {
            if(vec.size()<1) continue; // err
            string def=vec[1];
            int pos=def.find("@");
            if(pos>=0) def=def.substr(0,pos);
            if(Defines.count(def)) IgnoreDepth++;
            Depth++;
            continue;
        }
        else if(!vec[0].compare("ifndef"))
        {
            if(vec.size()<1) continue; // err
            string def=vec[1];
            int pos=def.find("@");
            if(pos>=0) def=def.substr(0,pos);
            if(!Defines.count(def)) IgnoreDepth++;
            Depth++;
            continue;
        }
        else if(!vec[0].compare("endif"))
        {
            Depth--;
            if(Depth<0) Depth=0; // err
            if(Depth<IgnoreDepth) IgnoreDepth--;
        }
        else if(!vec[0].compare("undef") && !IGNORING)
        {
            if(vec.size()<1) continue; // err
            string def=vec[1];
            int pos=def.find("@");
            if(pos>=0) def=def.substr(0,pos);
            Defines.erase(def);
            continue;
        }
    }
    fclose(f);
    return true;
}