// "[-]NNN.NNNNNNN" // Bien plus rapide que passer par atof(). Sur rhone-alpes.osm GCC 4.5.0 -O2 : // atof = 75s fixedlatlon = 67s int OSMData::fixedlatlon (const char *str) { bool const negative = (*str == '-'); int lsb = 10000000; int val = 0; char c; if (negative) ++str; // Partie entiere while (((c = *str++) != '\0') && (c != '.')) { checkSyntax ((c >= '0') && (c <= '9')); val = val*10 + (int) (c - '0'); } // Partie fractionnaire // + Un peu plus rapide a executer que de traiter les deux dans la meme boucle // (mais plus long a coder) ... on gagne 0.5s sur rhones-alpes.osm (66s) if (c == '.') { while (((c = *str++) != '\0')) { checkSyntax ((c >= '0') && (c <= '9')); val = val*10 + (int) (c - '0'); lsb /= 10; } } val *= lsb; return (negative) ? -val : val; }
void CustomEdit::recordClicked(void) { if (!checkSyntax()) return; RecordingRule *record = new RecordingRule(); MythUIButtonListItem* item = m_ruleList->GetItemCurrent(); CustomRuleInfo rule = qVariantValue<CustomRuleInfo>(item->GetData()); int cur_recid = rule.recordid.toInt(); if (cur_recid > 0) { record->ModifyPowerSearchByID(cur_recid, m_titleEdit->GetText(), evaluate(m_descriptionEdit->GetText()), m_subtitleEdit->GetText()); } else { record->LoadBySearch(kPowerSearch, m_titleEdit->GetText(), evaluate(m_descriptionEdit->GetText()), m_subtitleEdit->GetText(), m_pginfo->GetTitle().isEmpty() ? NULL : m_pginfo); } MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); ScheduleEditor *schededit = new ScheduleEditor(mainStack, record); if (schededit->Create()) { mainStack->AddScreen(schededit); connect(schededit, SIGNAL(ruleSaved(int)), SLOT(scheduleCreated(int))); } else delete schededit; }
void CustomPriority::testClicked(void) { if (!checkSyntax()) return; testSchedule(); }
void CustomPriority::installClicked(void) { if (!checkSyntax()) return; MythUIButtonListItem *item = m_prioritySpin->GetItemCurrent(); if (!item) return; MSqlQuery query(MSqlQuery::InitCon()); query.prepare("DELETE FROM powerpriority WHERE priorityname = :NAME;"); query.bindValue(":NAME", m_titleEdit->GetText()); if (!query.exec()) MythDB::DBError("Install power search delete", query); query.prepare("INSERT INTO powerpriority " "(priorityname, recpriority, selectclause) " "VALUES(:NAME,:VALUE,:CLAUSE);"); query.bindValue(":NAME", m_titleEdit->GetText()); query.bindValue(":VALUE", item->GetText()); query.bindValue(":CLAUSE", m_descriptionEdit->GetText()); if (!query.exec()) MythDB::DBError("Install power search insert", query); else ScheduledRecording::ReschedulePlace("InstallCustomPriority"); Close(); }
void InspectorRuntimeAgent::parse(ErrorString&, const String& expression, Inspector::Protocol::Runtime::SyntaxErrorType* result, Inspector::Protocol::OptOutput<String>* message, RefPtr<Inspector::Protocol::Runtime::ErrorRange>& range) { JSLockHolder lock(m_vm); ParserError error; checkSyntax(m_vm, JSC::makeSource(expression), error); switch (error.syntaxErrorType()) { case ParserError::SyntaxErrorNone: *result = Inspector::Protocol::Runtime::SyntaxErrorType::None; break; case ParserError::SyntaxErrorIrrecoverable: *result = Inspector::Protocol::Runtime::SyntaxErrorType::Irrecoverable; break; case ParserError::SyntaxErrorUnterminatedLiteral: *result = Inspector::Protocol::Runtime::SyntaxErrorType::UnterminatedLiteral; break; case ParserError::SyntaxErrorRecoverable: *result = Inspector::Protocol::Runtime::SyntaxErrorType::Recoverable; break; } if (error.syntaxErrorType() != ParserError::SyntaxErrorNone) { *message = error.message(); range = buildErrorRangeObject(error.token().m_location); } }
void InspectorRuntimeAgent::parse(ErrorString*, const String& expression, Inspector::TypeBuilder::Runtime::SyntaxErrorType::Enum* result, Inspector::TypeBuilder::OptOutput<String>* message, RefPtr<Inspector::TypeBuilder::Runtime::ErrorRange>& range) { VM* vm = JSDOMWindowBase::commonVM(); JSLockHolder lock(vm); ParserError error; checkSyntax(*vm, JSC::makeSource(expression), error); switch (error.m_syntaxErrorType) { case ParserError::SyntaxErrorNone: *result = Inspector::TypeBuilder::Runtime::SyntaxErrorType::None; break; case ParserError::SyntaxErrorIrrecoverable: *result = Inspector::TypeBuilder::Runtime::SyntaxErrorType::Irrecoverable; break; case ParserError::SyntaxErrorUnterminatedLiteral: *result = Inspector::TypeBuilder::Runtime::SyntaxErrorType::UnterminatedLiteral; break; case ParserError::SyntaxErrorRecoverable: *result = Inspector::TypeBuilder::Runtime::SyntaxErrorType::Recoverable; break; } if (error.m_syntaxErrorType != ParserError::SyntaxErrorNone) { *message = error.m_message; range = buildErrorRangeObject(error.m_token.m_location); } }
int main() { checkSyntax(); checkReadability(); return 0; }
static inline enum eltType eltvalue (const XML_Char *str) { if (sameEltName(str, "node")) return eltNode; if (sameEltName(str, "way")) return eltWay; if (sameEltName(str, "relation")) return eltRelation; checkSyntax(false); throw "syntaxError"; // on ne peut pas laisser faire }
void OSMData::endElementHandler (const XML_Char *name) { switch (name[0]) { case 'n' : // XML "node/" element (or "nd/") if (name[1] == 'o') { checkSyntax (!strcmp (name, "node")); endNode (); } break; case 'w' : // XML "way/" element checkSyntax (!strcmp (name, "way")); endWay (); break; } }
int main(int ac, char**av) { if (ac == 2) { std::string s = removeSpaces(av[1]); if (checkSyntax(s.c_str())) find_parenthesis(s); else std::cout << "syntax error" << std::endl; } else std::cout << "argument error" << std::endl; return 0; }
int vmMarkov::nextLine(QStringList &cmds) { int count = cmds.count(); for ( int i = 0; i < count; i++ ) { QString s = cmds[i]; if ( s == "" ) continue; if ( ! checkSyntax(s) ) return -1; if ( memory.indexOf( deleteSymb( s.mid(0, s.indexOf(QString("->"))), 'E' ) ) >= 0 ) return i; } return -1; }
void CustomPriority::deleteClicked(void) { if (!checkSyntax()) return; MSqlQuery query(MSqlQuery::InitCon()); query.prepare("DELETE FROM powerpriority " "WHERE priorityname=:NAME;"); query.bindValue(":NAME", m_titleEdit->GetText()); if (!query.exec()) MythDB::DBError("Delete power search query", query); else ScheduledRecording::ReschedulePlace("DeleteCustomPriority"); Close(); }
void CustomEdit::testClicked(void) { if (!checkSyntax()) { return; } MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); ProgLister *pl = new ProgLister(mainStack, plSQLSearch, evaluate(m_descriptionEdit->GetText()), m_subtitleEdit->GetText()); if (pl->Create()) { mainStack->AddScreen(pl); } else delete pl; }
bool vmMarkov::executeCmd(QString cmd) { if ( ! checkSyntax(cmd) ) return false; if ( cmd == "" ) return true; int index = cmd.indexOf("->"); if ( index < 0 ) return false; QString s1 = deleteSymb( cmd.mid( 0, index ), 'E' ); QString s2 = deleteSymb( cmd.mid( index + 2, cmd.size() - index - 2 ), 'E' ); QString lastMemory = memory; bool last = false; if ( s2[0] == '.' ) { last = true; s2.remove(0, 1); } index = memory.indexOf(s1); if ( index < 0 ) return false; memory.remove(index, s1.size()); memory.insert(index, s2); if ( last ) stop(); #ifndef WITHOUT_INFINITE_LOOP_CHECK else if ( memory == lastMemory ) { stop(); //! @todo в покроковий режим dwrite(QString().fromUtf8("Помічено зациклення, виконання припинено")); } #endif return true; }
int main(int argc, char *argv[]){ if(argc==2) { int correctSyntax=checkSyntax(argv[1]); if(correctSyntax){ printf("Sintaxe correcta\n"); char *user,*password,*host,*urlpath,*ip; int ret,sock1fd,pasvPort,sock2fd; user=ALLOCSTRING; password=ALLOCSTRING; host=ALLOCSTRING; urlpath=ALLOCSTRING; ip=ALLOCSTRING; ret = parseParams(argv[1],user,password,host,urlpath); getIP(host,ip); sock1fd=createSocket(ip,FTPPORT); if(ret == 0) loginUserPass(sock1fd,user,password); else if(ret == 1) loginUser(sock1fd,user); else if(ret == 2) loginUserPass(sock1fd,"anonymous","foo"); pasvPort = enterPassiveMode(sock1fd); sock2fd = createSocket(ip,pasvPort); download(sock1fd,sock2fd,urlpath); close(sock1fd); close(sock2fd); } else printf("Sintaxe errada!\n"); } else return -1; return 0; }
void OBJObject::parse(std::string& filename) { std::ifstream infile(filename); std::string line; std::vector<std::string> tokens; std::string token; int lineNum = 0; std::cout << "Starting parse..." << std::endl; //While all your lines are belong to us while (std::getline(infile, line)) { //Progress //Split a line into tokens by delimiting it on spaces //"Er Mah Gerd" becomes ["Er", "Mah", "Gerd"] tokens.clear(); tokens = split(line, ' ', tokens); if (tokens.size() <= 0) { continue; } /*if (++lineNum % 10000 == 0) { std::cout << "At line " << lineNum << std::endl; std::cout << tokens.at(0) << std::endl; }*/ //If first token is a v then it gots to be a vertex if(tokens.at(0).compare("v") == 0) { //Parse the vertex line float x = std::stof(tokens.at(1)); float y = std::stof(tokens.at(2)); float z = std::stof(tokens.at(3)); /* if (tokens.size() > 4) { float r = std::stof(tokens.at(4)); float g = std::stof(tokens.at(5)); float b = std::stof(tokens.at(6)); colors->push_back(new Vector3(r, g, b)); } */ vertices->push_back(new Vector3(x, y, z)); if (first) { this->minX = this->maxX = x; this->minY = this->maxY = y; this->minZ = this->maxZ = z; first = false; } else { if (minX > x) minX = x; if (minY > y) minY = y; if (minZ > z) minZ = z; if (maxX < x) maxX = x; if (maxY < y) maxY = y; if (maxZ < z) maxZ = z; } } else if(tokens.at(0).compare("vn") == 0) { //Parse the normal line float x = std::stof(tokens.at(1)); float y = std::stof(tokens.at(2)); float z = std::stof(tokens.at(3)); normals->push_back(new Vector3(x, y, z)); } else if(tokens.at(0).compare("f") == 0) { Face* face = new Face; std::string currString; //Parse the face line for (int i = 1; i < 4; i++) { currString = tokens.at(i); face->vertexIndices[i - 1] = std::stoi(currString.substr(0, currString.find('/', 0))) - 1; face->normalIndices[i - 1] = std::stoi(currString.substr(currString.find('/', 0) + 2, std::string::npos)) - 1; } faces->push_back(face); } else if(tokens.at(0).compare("How does I are C++?!?!!") == 0) { //Parse as appropriate //There are more line types than just the above listed //See the Wavefront Object format specification for details } } std::cout << "Done parsing." << std::endl; std::cout << "There are " << (*vertices).size() << " vertices and " << (*faces).size() << " faces and " << (*normals).size() << " normals." << std::endl; std::cout << checkSyntax("butt"); }
//------------------------------------------------------------------------------------------------- void LuaWorker::doSyntaxCheck(const IFile *pFile) { if (pFile!=NULL) emit checkSyntax(pFile); }
Completion Interpreter::checkSyntax(const UString& sourceURL, int startingLineNumber, const UString& code) { return checkSyntax(sourceURL, startingLineNumber, code.data(), code.size()); }
void OSMData::startElementHandler (const XML_Char *name, const XML_Char **atts) { // Les differents element XML d'un OSM sont : // osm, bounds, node, way, relation, nd, member, tag // On peut donc, presque, se contenter de tester le 1er chr ce qui va mieux // qu'un strcmp // Mesure sur rhone-alpes.osm (2.4G) GCC 4.5.0 MinGW en "-O2 -DNDEBUG -g" : // strcmp = 80.0s, switch = 78.7s + newND fixe = 78.1s switch (name[0]) { case 'o' : // XML "osm" element : ignored { checkSyntax (!strcmp (name, "osm")); } break; case 'b' : // XML "bounds" element { checkSyntax (!strcmp (name, "bounds")); m_filebound.min.lat = fixedlatlon (value (atts, "minlat")); m_filebound.max.lat = fixedlatlon (value (atts, "maxlat")); m_filebound.min.lon = fixedlatlon (value (atts, "minlon")); m_filebound.max.lon = fixedlatlon (value (atts, "maxlon")); } break; case 'n' : // XML "node" or "nd" element { if (name[1] == 'o') { checkSyntax (!strcmp (name, "node")); newNode (atts); } else { checkSyntax (!strcmp (name, "nd")); #if 1 // Pas la peine de chercher, "ref" est toujours atts[0] ? checkSyntax (! strcmp (atts[0], "ref")); newND (idvalue(atts[1])); #else newND (idvalue(value(atts, "ref"))); #endif } } break; case 'w' : // XML "way" element { checkSyntax (!strcmp (name, "way")); newWay (atts); } break; case 'r' : // XML "relation" element { checkSyntax (!strcmp (name, "relation")); newRelation (atts); } break; case 'm' : // XML "member" element { checkSyntax (!strcmp (name, "member")); newMember (idvalue(value(atts, "ref")), eltvalue(value(atts, "type")), value(atts, "role")); } break; case 't' : // XML "tag" element { checkSyntax (!strcmp (name, "tag")); // Pas la peine de chercher, c'est toujours 0="k" et 2="v" ... ? addTag (value(atts, "k"), value(atts, "v")); } break; } }
// My main function int main(int argc, char *argv[]) { int syntaxCheck=0,status=0; char *inputString=NULL; size_t len = 512; char **arg_temp=NULL; char **arg=NULL; char *path=NULL, *pathname=NULL,*cdpath=NULL; int size,i=0,arg_count=0; char *strparse=NULL; char **temp_arg=NULL; int numberArg=0; char *strwithBackground=NULL; char *bck=NULL,*strptr=NULL; int bckFlag=0; inputString = (char *) malloc (512); memset(inputString,'\0',len); while(1) { bckFlag=0; if(argc ==2) { printf("%s:",argv[1]); } else if(argc==1) printf("myshell:"); fflush(stdout); getline(&inputString, &len, stdin); if(feof(stdin) != 0) { exit(0); } size=strlen(inputString); inputString[size-1]='\0'; arg = (char **)malloc(10 * sizeof(char *)); memset(arg,0,10 * sizeof(char *)); syntaxCheck=checkSyntax(inputString); if(syntaxCheck==1) { printf("Syntax Error\n"); continue; } arg_temp=&inputString; arg[i] = strsep(arg_temp, ";"); while(arg[i] != NULL) { bckFlag=0; strparse = Strcpy(arg[i]); strparse=truncateEndSpaces(strparse); if(strcmp(strparse, "exit") == 0) exit(0); if(strstr(strparse, "cd")) { pathname=strstr(strparse, "cd"); while(*pathname!=' ') { pathname=pathname+1; } if(*pathname==' ') { while(*pathname==' ') { pathname=pathname+1; } } cdpath=(char *)malloc(strlen(strparse)); memset(cdpath,'\0',strlen(strparse)); path=cdpath; while(*pathname!='\0') { *path++=*pathname++; } *path='\0'; if(chdir(cdpath)==-1) { perror("Change Directory Failed"); } i++; arg[i] = strsep(arg_temp, ";"); continue; } strptr=strparse; strwithBackground=(char *)malloc(sizeof(char)*200); memset(strwithBackground,'\0',sizeof(char)*200); bck=strwithBackground; if(strstr(strparse,"&")) { bckFlag=1; while(*strptr!='&') { *bck++=*strptr++; } *bck='\0'; strwithBackground=truncateEndSpaces(strwithBackground); memset(strparse,'\0',strlen(strwithBackground)+1); strparse = Strcpy(strwithBackground); } arg_count++; temp_arg=parseString(strparse,&numberArg); setStructure(temp_arg,numberArg); runCommand(bckFlag); i++; arg[i] = strsep(arg_temp, ";"); } wait4(-1,&status,WNOHANG,NULL); } return 0; }