int main(int argc, char** argv){ int c; bool has_edit_option = false; bool has_pattern_file_option = false; bool silent = false; int count_option_num = 0;//count number of arguments int max_error = 0;//maximum edit distance allowed string pat_file; vector<string> patterns; vector<string> textfiles; while (1){ static struct option long_options[] = { {"silent", no_argument, 0, 's'}, {"help", no_argument, 0, 'h'}, {"edit", required_argument, 0, 'e'}, {"pattern", required_argument, 0, 'p'}, {0, 0, 0, 0} }; int option_index = 0; c = getopt_long (argc, argv, "she:p:",long_options, &option_index); if (c == -1)//end break; switch (c){ case 'e': has_edit_option = true; max_error = atoi(optarg); count_option_num += 2; break; case 'p': has_pattern_file_option = true; pat_file = optarg; count_option_num += 2; break; case 's': silent = true; break; case 'h': case '?': default: help(); break; } } if(!has_pattern_file_option){//read pattern from command line arg count_option_num++; string pat(argv[count_option_num]); patterns.push_back(pat); }else{//read patterns from file ifstream infile(pat_file); if (!infile.good()){ cout << "Arquivo de padrão << " << pat_file << " >> não existe" << endl; } string pat; while (infile >> pat){ patterns.push_back(pat); } } if(argc - 1 <= count_option_num){ cout << "Insira 1 ou mais arquivos de texto" << endl; } for (int i = count_option_num+1; i < argc; i++){ string str = argv[i]; vector<string> files = getTextFiles(str); for(string &file : files){ textfiles.push_back(file); } } if(!has_edit_option || max_error == 0){//exact search if(patterns.size() == 1){//kmp string pat = patterns[0]; for(string &txt : textfiles){ run_kmp(txt, pat, silent); } }else if(patterns.size() > 1){//aho for(string &txt : textfiles){ run_aho(txt, patterns, silent); } }else{ //error } }else if(has_edit_option){//approximate search for(string &txt : textfiles){ for(string &pat : patterns){ if(pat.length() < 64){ run_wu_manber(txt, pat, max_error, silent); }else{ run_sellers(txt, pat, max_error, silent); } } } } return 0; }
void gkTextManager::parseScripts(const gkString& group) { gkResourceManager::ResourceIterator iter = getResourceIterator(); while (iter.hasMoreElements()) { gkTextFile* tf = static_cast<gkTextFile*>(iter.getNext().second); if (!group.empty() && tf->getGroupName() != group) continue; const gkString& buf = tf->getText(); const int type = tf->getType(); #ifdef OGREKIT_COMPILE_OGRE_SCRIPTS try { if (type == TT_MATERIAL) { Ogre::DataStreamPtr memStream( OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size())); Ogre::MaterialManager::getSingleton().parseScript(memStream, group); } else if (type == TT_PARTICLE) { Ogre::DataStreamPtr memStream( OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size())); Ogre::ParticleSystemManager::getSingleton().parseScript(memStream, group); } else if (type == TT_FONT) { // Note: font must be an external file (.ttf anyway (texture fonts are not tested) ) Ogre::DataStreamPtr memStream( OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size())); Ogre::FontManager::getSingleton().parseScript(memStream, group); } else if (type == TT_COMPOSIT) { Ogre::DataStreamPtr memStream( OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size())); Ogre::CompositorManager::getSingleton().parseScript(memStream, group); } } catch (Ogre::Exception& e) { gkLogMessage("TextManager: " << e.getDescription()); continue; } if (type == TT_BFONT) { utMemoryStream stream; stream.open(buf.c_str(), buf.size(), utStream::SM_READ); gkFontManager::getSingleton().parseScript(&stream); } #endif #ifdef OGREKIT_USE_LUA if (type == TT_LUA) gkLuaManager::getSingleton().createFromText(gkResourceName(tf->getResourceName().getName(), group), buf); #endif } #ifdef OGREKIT_COMPILE_OGRE_SCRIPTS // Overlays are a dependant script. (.material .font) try { TextArray overlays; getTextFiles(overlays, TT_OVERLAY); TextArray::Iterator it = overlays.iterator(); while (it.hasMoreElements()) { gkTextFile* tf = (gkTextFile*)it.getNext(); const gkString& buf = tf->getText(); const int type = tf->getType(); Ogre::DataStreamPtr memStream( OGRE_NEW Ogre::MemoryDataStream((void*)buf.c_str(), buf.size())); Ogre::OverlayManager::getSingleton().parseScript(memStream, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); } } catch (Ogre::Exception& e) { gkLogMessage("TextManager: " << e.getDescription()); } #endif }