double CIXml::getFloatProperty(xmlNodePtr node, const char *property, float defaultValue) { CSString s; bool b; b=getPropertyString(s,node,property); if (b==false) return defaultValue; return s.strip().atof(); }
int CIXml::getIntProperty(xmlNodePtr node, const char *property, int defaultValue) { CSString s; bool b; b=getPropertyString(s,node,property); if (b==false) return defaultValue; s=s.strip(); sint val=s.atoi(); if (val==0 && s!="0") { nlwarning("bad integer value: %s",s.c_str()); return defaultValue; } return val; }
static void checkShutdownRequest() { // a little system to prevent us from eating too much CPU on systems that have a cstly 'fileExists()' static uint32 count=0; if ((++count)<10) return; count=0; // if there's no ctrl file to be found then giveup if (!NLMISC::CFile::fileExists(ShutdownRequestFileName)) return; // if a shutdown ctrl file exists then read it's contents (if the file doesn't exist this returns an empty string) CSString fileContents; fileContents.readFromFile(ShutdownRequestFileName.c_str()); // see if the file exists if (!fileContents.empty()) { NLMISC::CFile::deleteFile(ShutdownRequestFileName); fileContents= fileContents.strip().splitToOneOfSeparators(" \t\n\r\x1a"); // get rid of any unwanted junk surrounding the file contents nlinfo("Treating shutdown request from ctrl file %s: %s",ShutdownRequestFileName.c_str(),("#.State="+fileContents).c_str()); NLMISC::ICommand::execute("getViewAES #.State="+fileContents, *NLMISC::InfoLog); } }
static CSString cleanQuotes(CSString src) { src= src.strip().unquoteIfQuoted(); return (needsQuotes(src))? src.quote(): src; }
//void executeScriptBuf(char *txt) void executeScriptBuf(const string &text) { CSString buf = text; CVectorSString lines; vector<string> tmpLines; NLMISC::explode(std::string(buf.c_str()), std::string("\n"), tmpLines, true); lines.resize(tmpLines.size()); for (uint i=0; i<tmpLines.size();i++) { lines[i]= tmpLines[i]; } for (uint i=0; i<lines.size(); ++i) { CSString line = lines[i]; line = line.strip(); if (line.empty() || line.find("//") == 0) { // comment or empty line, skip continue; } CSString command = line.strtok(" \t"); line = line.strip(); if (command == "DFNPATH") { //CPath::getPathContent(args,true,false,true,files); CPath::addSearchPath(line, true, false); // for the dfn files } else if (command == "PATH") { files.clear(); CPath::getPathContent(line, true,false,true,files); CPath::addSearchPath(line, true, false); // for the dfn files } else if (command == "OUTPUT") { setOutputFile(line); } else if (command == "FIELD") { addField(line); } else if (command == "SOURCE") { addSource(line); } else if (command == "SCANFILES") { scanFiles(line); } else if (command == "SCRIPT") { executeScriptFile(line); } else { fprintf(stderr,"Unknown command: '%s' '%s'\n", command.c_str(), line.c_str()); } } }
void buildFileVector(std::vector<std::string> &filenames, const std::string &filespec) { uint i,j; // split up the filespec into chains CSString filters = filespec; filters.strip(); std::vector<std::string> in, out; while (!filters.empty()) { CSString filter = filters.strtok(" \t"); if (filter.empty()) continue; switch (filter[0]) { case '+': in.push_back(filter.leftCrop(1)); break; break; case '-': out.push_back(filter.leftCrop(1)); break; break; default: fprintf(stderr,"Error in '%s' : filter must start with '+' or '-'\n", filter.c_str()); getchar(); exit(1); } } /* for (i=0;i<filespec.size();) { for (j=i;j<filespec.size() && filespec[j]!=' ' && filespec[j]!='\t';j++) {} switch(filespec[i]) { case '+': in.push_back(filespec.substr(i+1,j-i-1)); break; case '-': out.push_back(filespec.substr(i+1,j-i-1)); break; default: fprintf(stderr,"Filter must start with '+' or '-'\n",&(filespec[i])); getchar(); exit(1); } i=j; while (i<filespec.size() && (filespec[i]==' ' || filespec[i]=='\t')) i++; // skip white space } */ // use the filespec as a filter while we build the sheet file vector for (i=0;i<files.size();i++) { bool ok=true; // make sure the filename includes all of the include strings for (j=0;j<in.size() && ok;j++) { if (!testWildCard(CFile::getFilename(files[i]), in[j])) { ok=false; } } // make sure the filename includes none of the exclude strings for (j=0;j<out.size() && ok;j++) { if (testWildCard(CFile::getFilename(files[i]), out[j])) { ok=false; } } // if the filename matched all of the above criteria then add it to the list if (ok) { printf("Added: %s\n",CFile::getFilename(files[i]).c_str()); filenames.push_back(files[i]); } } printf("Found: %zu matching files (from %zu)\n",filenames.size(),files.size()); }