void MInput::flush(void) { // keys map<string, int>::iterator mit (m_keys.begin()), mend(m_keys.end()); for(; mit!=mend; mit++) { if(mit->second == 1) mit->second = 2; else if(mit->second == 3) mit->second = 0; } // axis unsigned int a, aSize = m_axisToFlush.size(); for(a=0; a<aSize; a++) (*m_axisToFlush[a]) = 0; // touches map<int, TouchData>::iterator t_it(m_touches.begin()), t_end(m_touches.end()); for(; t_it!=t_end; t_it++) { TouchData* data = &(t_it->second); data->phase = M_TOUCH_NONE; data->touchPoint = MVector2(0.0f); } }
void DesktopConfigDbBackend::init() { m_manager->reset(); m_currentOid = 1; //KSimpleConfig config( m_fileName ); // DEPRECATED KDE3 -> KDE4 by Percy KConfig config( m_fileName ); QStringList groups = config.groupList(); QStringList::ConstIterator it( groups.begin() ); QStringList::ConstIterator end( groups.end() ); QMap<QString,QString> map; for ( ; it != end; ++it ) { map = config.entryMap( *it ); ObjectRef<Object> obj; if ( map.contains( "oid" ) ) obj = Classes::classInfo( *it )->create( stringToOid( map["oid"] ), m_manager, true ); else obj = Classes::classInfo( *it )->create( m_manager ); assert( obj ); if ( m_currentOid < obj->oid() ) m_currentOid = obj->oid(); //QMapConstIterator<QString,QString> mit( map.begin() ); // DEPRECATED Qt3 -> Qt4 by Percy //QMapConstIterator<QString,QString> mend( map.end() ); // DEPRECATED Qt3 -> Qt4 by Percy QMap<QString, QString>::const_iterator mit( map.begin() ); QMap<QString, QString>::const_iterator mend( map.end() ); for ( ; mit != mend; ++mit ) { if ( mit.key() != "oid" ) //obj->setProperty( mit.key(), mit.data() ); // DEPRECATED Qt3 -> Qt4 by Percy obj->setProperty( mit.key().toAscii(), QVariant(mit.value()) ); } } }
void File::addEntity(Entity* entity) { map<string, Entity*>* entities; if (entity != NULL) { entities = entity->getEntities(); if ( entities != NULL) { map<std::string,Entity*>::const_iterator mit (entities->begin()), mend(entities->end()); for(; mit!=mend; ++mit) { if (mit->second->getIP() != NULL) { deploysOn.push_back(mit->second); mit->second->addDeploymentState(0, this, OFFLINE); } if (mit->second->getEntities() != NULL) addEntity(mit->second); } } else { deploysOn.push_back(entity); entity->addDeploymentState(0, this, OFFLINE); } } }
std::string LLCoros::getNameByID(const void* self_id) const { // Walk the existing coroutines, looking for one from which the 'self_id' // passed to us comes. for (CoroMap::const_iterator mi(mCoros.begin()), mend(mCoros.end()); mi != mend; ++mi) { namespace coro_private = boost::coroutines::detail; if (static_cast<void*>(coro_private::coroutine_accessor::get_impl(const_cast<coro&>(*mi->second)).get()) == self_id) { return mi->first; } } return ""; }
void LLFloaterRegListener::getBuildMap(const LLSD& event) const { LLSD reply; // Build an LLSD map that mirrors sBuildMap. Since we have no good way to // represent a C++ callable in LLSD, the only part of BuildData we can // store is the filename. For each LLSD map entry, it would be more // extensible to store a nested LLSD map containing a single key "file" -- // but we don't bother, simply storing the string filename instead. for (LLFloaterReg::build_map_t::const_iterator mi(LLFloaterReg::sBuildMap.begin()), mend(LLFloaterReg::sBuildMap.end()); mi != mend; ++mi) { reply[mi->first] = mi->second.mFile; } // Send the reply to the LLEventPump named in event["reply"]. sendReply(reply, event); }
void Similarity::computeSimilarity() { std::cout << "Computing similarity scores." << std::endl; for (unsigned int i = 0; i < ptrOOD->getSize(); i++) { std::map<std::string, int> tmpTF; for (unsigned int j = 0; j < ptrVecWords->size(); j++) { tmpTF[ptrVecWords->operator[](j)] = 0; } std::vector<std::string> lWords; std::string line = ptrOOD->getLine(i); boost::split(lWords, line, boost::is_any_of(" ")); for (unsigned int j = 0; j < lWords.size(); j++) { std::map<std::string, int>::const_iterator mit(tmpTF.find(lWords[j])), mend(tmpTF.end()); if(mit != mend) tmpTF[lWords[j]] = tmpTF[lWords[j]] + 1; } float sumAiBi = 0.0; float sumAiSQ = 0.0; float sumBiSQ = 0.0; for (unsigned int j = 0; j < ptrVecWords->size(); j++) { float oodTfIdf = (float)tmpTF[ptrVecWords->operator[](j)] * (float)ptrOodVecIdf->operator[](j); float idTfIdf = ptrIdVecTfIdf->operator[](j); sumAiBi = sumAiBi + (idTfIdf * oodTfIdf); sumAiSQ = sumAiSQ + (idTfIdf * idTfIdf); sumBiSQ = sumBiSQ + (oodTfIdf * oodTfIdf); } float sim = sumAiBi / (sqrt(sumAiSQ) * sqrt(sumBiSQ)); /** @bug Sometimes sim = NaN, so we need to protect against that */ if (sim != sim) sim = 0.0; ptrOodSimilarity->operator[](i) = sim; } std::cout << "Done computing similarity scores." << std::endl; }
User* UserSet::add(User* user) { for (mutable_iterator it = mbegin(); it != mend(); ++it) { User* current = *it; if (current->getName().getDB() == user->getName().getDB()) { // There can be only one user per database. *it = user; return current; } } if (_usersEnd == _users.end()) { _users.push_back(user); _usersEnd = _users.end(); } else { *_usersEnd = user; ++_usersEnd; } return NULL; }
// ###################################################################### void Logger::start1() { DetectionParameters dp = DetectionParametersSingleton::instance()->itsParameters; // initialize the XML if requested to save event set to XML if (itsSaveOutput.getVal()) { Image< PixRGB<byte> > tmpimg; MbariImage< PixRGB<byte> > mstart(itsInputFrameSource.getVal()); MbariImage< PixRGB<byte> > mend(itsInputFrameSource.getVal()); // get the dimensions, starting and ending timecodes from the frames nub::ref<FrameIstream> rep = itsIfs->getFrameSource(); rep->setFrameNumber(itsFrameRange.getFirst()); tmpimg = rep->readRGB(); mstart.updateData(tmpimg, itsFrameRange.getFirst()); rep->setFrameNumber(itsFrameRange.getLast()); tmpimg = rep->readRGB(); mend.updateData(tmpimg, itsFrameRange.getLast()); // create the XML document with header information createXMLDocument(Version::versionString(), itsFrameRange, mstart.getMetaData().getTC(), mend.getMetaData().getTC(), dp); // reset the frame number back since we will be streaming this soon rep->setFrameNumber((itsFrameRange.getFirst())); } //MbariVisualEvent::VisualEventSet eventSet; // are we loading the event structure from a file? if (itsLoadEventsName.getVal().length() > 0) { //loadVisualEventSet(eventSet); // TODO: test preloading of events; hasn't been used in a while but // potentially useful for future so will leave it here } }
void MALContext::deleteBuffer(unsigned int * bufferId) { M_PROFILE_SCOPE(MALContext::deleteBuffer); if(*bufferId > 0) { // unlink sources map<unsigned int, unsigned int>::iterator mit (m_sources.begin()), mend(m_sources.end()); for(;mit!=mend;++mit) { if(mit->second == (*bufferId)) { stopSource(mit->first); setSourceBufferId(mit->first, 0); } } // delete buffer alDeleteBuffers(1, bufferId); } }
bool LLCoros::cleanup(const LLSD&) { // Walk the mCoros map, checking and removing completed coroutines. for (CoroMap::iterator mi(mCoros.begin()), mend(mCoros.end()); mi != mend; ) { // Has this coroutine exited (normal return, exception, exit() call) // since last tick? if (mi->second->exited()) { LL_INFOS("LLCoros") << "LLCoros: cleaning up coroutine " << mi->first << LL_ENDL; // The erase() call will invalidate its passed iterator value -- // so increment mi FIRST -- but pass its original value to // erase(). This is what postincrement is all about. mCoros.erase(mi++); } else { // Still live, just skip this entry as if incrementing at the top // of the loop as usual. ++mi; } } return false; }
/********************************************************************** * Function basic_alg_menu(); * * Parameter: * * * This function prompts user to choose a basic algorithm to execute * such as Boyer-Moore. The utilities menu is also available from * this menu. * **********************************************************************/ void basic_alg_menu() { int i, status, num_lines, alpha_size, num_patterns; char ch; STRING *text, *pattern, **patterns; alpha_size = 0; while (1) { num_lines = 22; printf("\n** Basic Search Algorithm Menu **\n\n"); printf("1) Naive Algorithm\n"); printf("2) Boyer-Moore Variations\n"); printf(" a) Bad character rule\n"); printf(" b) Extended bad character rule\n"); printf(" c) Good suffix & bad character rules\n"); printf(" d) Good suffix & extended bad character rules\n"); printf("3) Knuth-Morris-Pratt (original preprocessing)\n"); printf(" a) using sp values\n"); printf(" b) using sp' values\n"); printf("4) Aho-Corasick Set Matching\n"); printf("5) Boyer-Moore Set Matching\n"); printf(" a) Bad character rule only\n"); printf(" b) Good suffix rule using keyword and suffix trees\n"); printf(" c) Good suffix rule using suffix tree only\n"); printf(" d) using original Boyer-Moore (1c) on each pattern\n"); printf("*) String Utilites\n"); printf("0) Exit\n"); printf("\nEnter Selection: "); while ((choice = my_getline(stdin, &ch_len)) == NULL) ; switch (choice[0]) { case '0': return; case '1': if (!(pattern = get_string("pattern")) || !(text = get_string("text"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe pattern:\n"); terse_print_string(pattern); mprintf("\nThe text:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, pattern, NULL, 0); if (status != -1) { mprintf ("Executing naive search algorithm...\n\n"); strmat_naive_match(pattern, text, stats_flag); unmap_sequences(text, pattern, NULL, 0); } mend(num_lines); putchar('\n'); break; case '2': ch = choice[1]; if (toupper(ch) != 'A' && toupper(ch) != 'B' && toupper(ch) != 'C' && toupper(ch) != 'D') { printf("\nYou must specify the Boyer-Moore variation" " (as in '2a' or '2c').\n"); continue; } if (!(pattern = get_string("pattern")) || !(text = get_string("text"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe pattern:\n"); terse_print_string(pattern); mprintf("\nThe text:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, pattern, NULL, 0); if (status != -1) { mprintf("Executing Boyer-Moore algorithm...\n\n"); switch (toupper(ch)) { case 'A': strmat_bmbad_match(pattern, text, stats_flag); break; case 'B': strmat_bmext_match(pattern, text, stats_flag); break; case 'C': strmat_bmgood_match(pattern, text, stats_flag); break; case 'D': strmat_bmextgood_match(pattern, text, stats_flag); break; } unmap_sequences(text, pattern, NULL, 0); } mend(num_lines); putchar('\n'); break; case '3': ch = choice[1]; if (toupper(ch) != 'A' && toupper(ch) != 'B') { printf("\nYou must specify the KMP variation (as in '3a' or '3b').\n"); continue; } if (!(pattern = get_string("pattern")) || !(text = get_string("text"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe pattern:\n"); terse_print_string(pattern); mprintf("\nThe text:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, pattern, NULL, 0); if (status != -1) { if (toupper(ch) == 'A') { mprintf ("Executing KMP with sp values...\n\n"); strmat_kmp_sp_orig_match(pattern, text, stats_flag); } else { mprintf ("Executing KMP with sp' values...\n\n"); strmat_kmp_spprime_orig_match(pattern, text, stats_flag); } unmap_sequences(text, pattern, NULL, 0); } mend(num_lines); putchar('\n'); break; case '4': if (!(patterns = get_string_ary("list of patterns", &num_patterns))) continue; if (!(text = get_string("text"))) { free(patterns); continue; } mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe patterns:\n"); for (i=0; i < num_patterns; i++) { mprintf("%2d)", i + 1); terse_print_string(patterns[i]); } mprintf("\nThe text:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, NULL, patterns, num_patterns); if (status != -1) { mprintf("Executing Aho-Corasick algorithm...\n\n"); strmat_ac_match(patterns, num_patterns, text, stats_flag); unmap_sequences(text, NULL, patterns, num_patterns); } mend(num_lines); putchar('\n'); free(patterns); break; case '5': ch = toupper(choice[1]); if (ch != 'A' && ch != 'B' && ch != 'C' && ch != 'D') { printf("\nYou must specify the set Boyer-Moore variation" " (as in '5a' or '5c').\n"); continue; } if (!(patterns = get_string_ary("list of patterns", &num_patterns))) continue; if (!(text = get_string("text"))) { free(patterns); continue; } mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe patterns:\n"); for (i=0; i < num_patterns; i++) { mprintf("%2d)", i + 1); terse_print_string(patterns[i]); } mprintf("\nThe text:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, NULL, patterns, num_patterns); if (status != -1) { mprintf("Executing Boyer-Moore set matching algorithm...\n\n"); switch (toupper(ch)) { case 'A': strmat_bmset_badonly_match(patterns, num_patterns, text, stats_flag); break; case 'B': strmat_bmset_2trees_match(patterns, num_patterns, text, stats_flag); break; case 'C': strmat_bmset_1tree_match(patterns, num_patterns, text, stats_flag); break; case 'D': strmat_bmset_naive_match(patterns, num_patterns, text, stats_flag); break; } unmap_sequences(text, NULL, patterns, num_patterns); } mend(num_lines); putchar('\n'); free(patterns); break; case '*': util_menu(); break; default: printf("\nThat is not a choice.\n"); } } }
void llsdutil_object::test<9>() { set_test_name("llsd_matches"); // for this test, construct a map of all possible LLSD types LLSD map; map.insert("empty", LLSD()); map.insert("Boolean", LLSD::Boolean()); map.insert("Integer", LLSD::Integer(0)); map.insert("Real", LLSD::Real(0.0)); map.insert("String", LLSD::String("bah")); map.insert("NumString", LLSD::String("1")); map.insert("UUID", LLSD::UUID()); map.insert("Date", LLSD::Date()); map.insert("URI", LLSD::URI()); map.insert("Binary", LLSD::Binary()); map.insert("Map", LLSD().with("foo", LLSD())); // Only an empty array can be constructed on the fly LLSD array; array.append(LLSD()); map.insert("Array", array); // These iterators are declared outside our various for loops to avoid // fatal MSVC warning: "I used to be broken, but I'm all better now!" LLSD::map_const_iterator mi, mend(map.endMap()); /*-------------------------- llsd_matches --------------------------*/ // empty prototype matches anything for (mi = map.beginMap(); mi != mend; ++mi) { ensure_equals(std::string("empty matches ") + mi->first, llsd_matches(LLSD(), mi->second), ""); } LLSD proto_array, data_array; for (int i = 0; i < 3; ++i) { proto_array.append(LLSD()); data_array.append(LLSD()); } // prototype array matches only array for (mi = map.beginMap(); mi != mend; ++mi) { ensure(std::string("array doesn't match ") + mi->first, ! llsd_matches(proto_array, mi->second).empty()); } // data array must be at least as long as prototype array proto_array.append(LLSD()); ensure_equals("data array too short", llsd_matches(proto_array, data_array), "Array size 4 required instead of Array size 3"); data_array.append(LLSD()); ensure_equals("data array just right", llsd_matches(proto_array, data_array), ""); data_array.append(LLSD()); ensure_equals("data array longer", llsd_matches(proto_array, data_array), ""); // array element matching data_array[0] = LLSD::String(); ensure_equals("undefined prototype array entry", llsd_matches(proto_array, data_array), ""); proto_array[0] = LLSD::Binary(); ensure_equals("scalar prototype array entry", llsd_matches(proto_array, data_array), "[0]: Binary required instead of String"); data_array[0] = LLSD::Binary(); ensure_equals("matching prototype array entry", llsd_matches(proto_array, data_array), ""); // build a coupla maps LLSD proto_map, data_map; data_map["got"] = LLSD(); data_map["found"] = LLSD(); for (LLSD::map_const_iterator dmi(data_map.beginMap()), dmend(data_map.endMap()); dmi != dmend; ++dmi) { proto_map[dmi->first] = dmi->second; } proto_map["foo"] = LLSD(); proto_map["bar"] = LLSD(); // prototype map matches only map for (mi = map.beginMap(); mi != mend; ++mi) { ensure(std::string("map doesn't match ") + mi->first, ! llsd_matches(proto_map, mi->second).empty()); } // data map must contain all keys in prototype map std::string error(llsd_matches(proto_map, data_map)); ensure_contains("missing keys", error, "missing keys"); ensure_contains("missing foo", error, "foo"); ensure_contains("missing bar", error, "bar"); ensure_does_not_contain("found found", error, "found"); ensure_does_not_contain("got got", error, "got"); data_map["bar"] = LLSD(); error = llsd_matches(proto_map, data_map); ensure_contains("missing foo", error, "foo"); ensure_does_not_contain("got bar", error, "bar"); data_map["foo"] = LLSD(); ensure_equals("data map just right", llsd_matches(proto_map, data_map), ""); data_map["extra"] = LLSD(); ensure_equals("data map with extra", llsd_matches(proto_map, data_map), ""); // map element matching data_map["foo"] = LLSD::String(); ensure_equals("undefined prototype map entry", llsd_matches(proto_map, data_map), ""); proto_map["foo"] = LLSD::Binary(); ensure_equals("scalar prototype map entry", llsd_matches(proto_map, data_map), "['foo']: Binary required instead of String"); data_map["foo"] = LLSD::Binary(); ensure_equals("matching prototype map entry", llsd_matches(proto_map, data_map), ""); // String { static const char* matches[] = { "String", "NumString", "Boolean", "Integer", "Real", "UUID", "Date", "URI" }; test_matches("String", map, boost::begin(matches), boost::end(matches)); } // Boolean, Integer, Real static const char* numerics[] = { "Boolean", "Integer", "Real" }; for (const char **ni = boost::begin(numerics), **nend = boost::end(numerics); ni != nend; ++ni) { static const char* matches[] = { "Boolean", "Integer", "Real", "String", "NumString" }; test_matches(*ni, map, boost::begin(matches), boost::end(matches)); } // UUID { static const char* matches[] = { "UUID", "String", "NumString" }; test_matches("UUID", map, boost::begin(matches), boost::end(matches)); } // Date { static const char* matches[] = { "Date", "String", "NumString" }; test_matches("Date", map, boost::begin(matches), boost::end(matches)); } // URI { static const char* matches[] = { "URI", "String", "NumString" }; test_matches("URI", map, boost::begin(matches), boost::end(matches)); } // Binary { static const char* matches[] = { "Binary" }; test_matches("Binary", map, boost::begin(matches), boost::end(matches)); } /*-------------------------- llsd_equals ---------------------------*/ // Cross-product of each LLSD type with every other for (LLSD::map_const_iterator lmi(map.beginMap()), lmend(map.endMap()); lmi != lmend; ++lmi) { for (LLSD::map_const_iterator rmi(map.beginMap()), rmend(map.endMap()); rmi != rmend; ++rmi) { // Name this test based on the map keys naming the types of // interest, e.g "String::Integer". // We expect the values (xmi->second) to be equal if and only // if the type names (xmi->first) are equal. ensure(STRINGIZE(lmi->first << "::" << rmi->first), bool(lmi->first == rmi->first) == bool(llsd_equals(lmi->second, rmi->second))); } } // Array cases LLSD rarray; rarray.append(1.0); rarray.append(2); rarray.append("3"); LLSD larray(rarray); ensure("llsd_equals(equal arrays)", llsd_equals(larray, rarray)); rarray[2] = "4"; ensure("llsd_equals(different [2])", ! llsd_equals(larray, rarray)); rarray = larray; rarray.append(LLSD::Date()); ensure("llsd_equals(longer right array)", ! llsd_equals(larray, rarray)); rarray = larray; rarray.erase(2); ensure("llsd_equals(shorter right array)", ! llsd_equals(larray, rarray)); // Map cases LLSD rmap; rmap["San Francisco"] = 65; rmap["Phoenix"] = 92; rmap["Boston"] = 77; LLSD lmap(rmap); ensure("llsd_equals(equal maps)", llsd_equals(lmap, rmap)); rmap["Boston"] = 80; ensure("llsd_equals(different [\"Boston\"])", ! llsd_equals(lmap, rmap)); rmap = lmap; rmap["Atlanta"] = 95; ensure("llsd_equals(superset right map)", ! llsd_equals(lmap, rmap)); rmap = lmap; lmap["Seattle"] = 72; ensure("llsd_equals(superset left map)", ! llsd_equals(lmap, rmap)); }
// Mesh bin export bool exportMeshBin(const char * filename, MMesh * mesh) { int version = 2; char rep[256]; bool state; // create file MFile * file = M_fopen(filename, "wb"); if(! file) { printf("Error : can't create file %s\n", filename); return false; } // get file directory getRepertory(rep, filename); // header M_fwrite(M_MESH_HEADER, sizeof(char), 8, file); // version M_fwrite(&version, sizeof(int), 1, file); // Animation { // anim refs MArmatureAnimRef * armatureAnimRef = mesh->getArmatureAnimRef(); MTexturesAnimRef * texturesAnimRef = mesh->getTexturesAnimRef(); MMaterialsAnimRef * materialsAnimRef = mesh->getMaterialsAnimRef(); // armature anim ref writeDataRef(file, armatureAnimRef, rep); // textures anim ref writeDataRef(file, texturesAnimRef, rep); // materials anim ref writeDataRef(file, materialsAnimRef, rep); // anims ranges unsigned int animsRangesNumber = mesh->getAnimsRangesNumber(); MAnimRange * animsRanges = mesh->getAnimsRanges(); M_fwrite(&animsRangesNumber, sizeof(int), 1, file); if(animsRangesNumber > 0) M_fwrite(animsRanges, sizeof(MAnimRange), animsRangesNumber, file); } // Textures { unsigned int t, texturesNumber = mesh->getTexturesNumber(); M_fwrite(&texturesNumber, sizeof(int), 1, file); for(t=0; t<texturesNumber; t++) { MTexture * texture = mesh->getTexture(t); MTextureRef * textureRef = texture->getTextureRef(); M_TEX_GEN_MODES genMode = texture->getGenMode(); M_WRAP_MODES UWrapMode = texture->getUWrapMode(); M_WRAP_MODES VWrapMode = texture->getVWrapMode(); MVector2 texTranslate = texture->getTexTranslate(); MVector2 texScale = texture->getTexScale(); float texRotate = texture->getTexRotate(); // texture ref writeDataRef(file, textureRef, rep); if(textureRef) { bool mipmap = textureRef->isMipmapEnabled(); M_fwrite(&mipmap, sizeof(bool), 1, file); } // data M_fwrite(&genMode, sizeof(M_TEX_GEN_MODES), 1, file); M_fwrite(&UWrapMode, sizeof(M_WRAP_MODES), 1, file); M_fwrite(&VWrapMode, sizeof(M_WRAP_MODES), 1, file); M_fwrite(&texTranslate, sizeof(MVector2), 1, file); M_fwrite(&texScale, sizeof(MVector2), 1, file); M_fwrite(&texRotate, sizeof(float), 1, file); } } // Materials { unsigned int m, materialsNumber = mesh->getMaterialsNumber(); M_fwrite(&materialsNumber, sizeof(int), 1, file); for(m=0; m<materialsNumber; m++) { MMaterial * material = mesh->getMaterial(m); int type = material->getType(); float opacity = material->getOpacity(); float shininess = material->getShininess(); float customValue = material->getCustomValue(); M_BLENDING_MODES blendMode = material->getBlendMode(); MVector3 emit = material->getEmit(); MVector3 diffuse = material->getDiffuse(); MVector3 specular = material->getSpecular(); MVector3 customColor = material->getCustomColor(); MFXRef * FXRef = material->getFXRef(); MFXRef * ZFXRef = material->getZFXRef(); // FX ref state = FXRef != NULL; M_fwrite(&state, sizeof(bool), 1, file); if(FXRef) { MShaderRef * vertShadRef = FXRef->getVertexShaderRef(); MShaderRef * pixShadRef = FXRef->getPixelShaderRef(); writeDataRef(file, vertShadRef, rep); writeDataRef(file, pixShadRef, rep); } // Z FX ref state = ZFXRef != NULL; M_fwrite(&state, sizeof(bool), 1, file); if(ZFXRef) { MShaderRef * vertShadRef = ZFXRef->getVertexShaderRef(); MShaderRef * pixShadRef = ZFXRef->getPixelShaderRef(); writeDataRef(file, vertShadRef, rep); writeDataRef(file, pixShadRef, rep); } // data M_fwrite(&type, sizeof(int), 1, file); M_fwrite(&opacity, sizeof(float), 1, file); M_fwrite(&shininess, sizeof(float), 1, file); M_fwrite(&customValue, sizeof(float), 1, file); M_fwrite(&blendMode, sizeof(M_BLENDING_MODES), 1, file); M_fwrite(&emit, sizeof(MVector3), 1, file); M_fwrite(&diffuse, sizeof(MVector3), 1, file); M_fwrite(&specular, sizeof(MVector3), 1, file); M_fwrite(&customColor, sizeof(MVector3), 1, file); // textures pass unsigned int t, texturesPassNumber = material->getTexturesPassNumber(); M_fwrite(&texturesPassNumber, sizeof(int), 1, file); for(t=0; t<texturesPassNumber; t++) { MTexturePass * texturePass = material->getTexturePass(t); MTexture * texture = texturePass->getTexture(); unsigned int mapChannel = texturePass->getMapChannel(); M_TEX_COMBINE_MODES combineMode = texturePass->getCombineMode(); // texture id int textureId = getTextureId(mesh, texture); M_fwrite(&textureId, sizeof(int), 1, file); // data M_fwrite(&mapChannel, sizeof(int), 1, file); M_fwrite(&combineMode, sizeof(M_TEX_COMBINE_MODES), 1, file); } } } // Bones { MArmature * armature = mesh->getArmature(); state = armature != NULL; M_fwrite(&state, sizeof(bool), 1, file); if(armature) { unsigned int b, bonesNumber = armature->getBonesNumber(); M_fwrite(&bonesNumber, sizeof(int), 1, file); for(b=0; b<bonesNumber; b++) { MOBone * bone = armature->getBone(b); MObject3d * parent = bone->getParent(); MVector3 position = bone->getPosition(); MVector3 scale = bone->getScale(); MQuaternion rotation = bone->getRotation(); // name writeString(file, bone->getName()); // parent id int parentId = -1; if(parent) { unsigned int id; if(armature->getBoneId(parent->getName(), &id)) parentId = (int)id; } M_fwrite(&parentId, sizeof(int), 1, file); // position / rotation / scale M_fwrite(&position, sizeof(MVector3), 1, file); M_fwrite(&rotation, sizeof(MQuaternion), 1, file); M_fwrite(&scale, sizeof(MVector3), 1, file); } } } // BoundingBox { MBox3d * box = mesh->getBoundingBox(); M_fwrite(box, sizeof(MBox3d), 1, file); } // SubMeshs { unsigned int s, subMeshsNumber = mesh->getSubMeshsNumber(); MSubMesh * subMeshs = mesh->getSubMeshs(); M_fwrite(&subMeshsNumber, sizeof(int), 1, file); for(s=0; s<subMeshsNumber; s++) { MSubMesh * subMesh = &(subMeshs[s]); unsigned int indicesSize = subMesh->getIndicesSize(); unsigned int verticesSize = subMesh->getVerticesSize(); unsigned int normalsSize = subMesh->getNormalsSize(); unsigned int tangentsSize = subMesh->getTangentsSize(); unsigned int texCoordsSize = subMesh->getTexCoordsSize(); unsigned int colorsSize = subMesh->getColorsSize(); M_TYPES indicesType = subMesh->getIndicesType(); void * indices = subMesh->getIndices(); MColor * colors = subMesh->getColors(); MVector3 * vertices = subMesh->getVertices(); MVector3 * normals = subMesh->getNormals(); MVector3 * tangents = subMesh->getTangents(); MVector2 * texCoords = subMesh->getTexCoords(); MBox3d * box = subMesh->getBoundingBox(); MSkinData * skin = subMesh->getSkinData(); map<unsigned int, unsigned int> * mapChannelOffsets = subMesh->getMapChannelOffsets(); // BoundingBox M_fwrite(box, sizeof(MBox3d), 1, file); // indices M_fwrite(&indicesSize, sizeof(int), 1, file); if(indicesSize > 0) { // indice type M_fwrite(&indicesType, sizeof(M_TYPES), 1, file); switch(indicesType) { case M_USHORT: M_fwrite(indices, sizeof(short), indicesSize, file); break; case M_UINT: M_fwrite(indices, sizeof(int), indicesSize, file); break; } } // vertices M_fwrite(&verticesSize, sizeof(int), 1, file); if(verticesSize > 0) M_fwrite(vertices, sizeof(MVector3), verticesSize, file); // normals M_fwrite(&normalsSize, sizeof(int), 1, file); if(normalsSize > 0) M_fwrite(normals, sizeof(MVector3), normalsSize, file); // tangents M_fwrite(&tangentsSize, sizeof(int), 1, file); if(tangentsSize > 0) M_fwrite(tangents, sizeof(MVector3), tangentsSize, file); // texCoords M_fwrite(&texCoordsSize, sizeof(int), 1, file); if(texCoordsSize > 0) M_fwrite(texCoords, sizeof(MVector2), texCoordsSize, file); // colors M_fwrite(&colorsSize, sizeof(int), 1, file); if(colorsSize > 0) M_fwrite(colors, sizeof(MColor), colorsSize, file); // mapChannels { unsigned int size = mapChannelOffsets->size(); M_fwrite(&size, sizeof(int), 1, file); map<unsigned int, unsigned int>::iterator mit (mapChannelOffsets->begin()), mend(mapChannelOffsets->end()); for(;mit!=mend;++mit) { M_fwrite(&mit->first, sizeof(int), 1, file); M_fwrite(&mit->second, sizeof(int), 1, file); } } // Skins state = skin != NULL; M_fwrite(&state, sizeof(bool), 1, file); if(skin) { // skin point unsigned int p, pointsNumber = skin->getPointsNumber(); M_fwrite(&pointsNumber, sizeof(int), 1, file); for(p=0; p<pointsNumber; p++) { MSkinPoint * skinPoint = skin->getPoint(p); unsigned int vertexId = skinPoint->getVertexId(); unsigned int bonesNumber = skinPoint->getBonesNumber(); unsigned short * bonesIds = skinPoint->getBonesIds(); float * bonesWeights = skinPoint->getBonesWeights(); // data M_fwrite(&vertexId, sizeof(int), 1, file); M_fwrite(&bonesNumber, sizeof(int), 1, file); if(bonesNumber > 0) { M_fwrite(bonesIds, sizeof(short), bonesNumber, file); M_fwrite(bonesWeights, sizeof(float), bonesNumber, file); } } } // Displays unsigned int d, displaysNumber = subMesh->getDisplaysNumber(); M_fwrite(&displaysNumber, sizeof(int), 1, file); for(d=0; d<displaysNumber; d++) { MDisplay * display = subMesh->getDisplay(d); M_PRIMITIVE_TYPES primitiveType = display->getPrimitiveType(); unsigned int begin = display->getBegin(); unsigned int size = display->getSize(); MMaterial * material = display->getMaterial(); M_CULL_MODES cullMode = display->getCullMode(); int materialId = getMaterialId(mesh, material); // data M_fwrite(&primitiveType, sizeof(M_PRIMITIVE_TYPES), 1, file); M_fwrite(&begin, sizeof(int), 1, file); M_fwrite(&size, sizeof(int), 1, file); M_fwrite(&materialId, sizeof(int), 1, file); M_fwrite(&cullMode, sizeof(M_CULL_MODES), 1, file); } } } M_fclose(file); return true; }
/********************************************************************** * Function suf_tree_menu() * * Parameter: * * * This function prompts user to choose an algorithm to create * a suffix tree and use it. * The utilities menu is also available from this menu. * **********************************************************************/ void suf_tree_menu() { int i, status, num_lines, num_strings; char ch; STRING *pattern, **strings, *text; while (1) { num_lines = 18; printf("\n** Suffix Tree Menu **\n\n"); printf("1) Build a suffix tree using Ukkonen's algorithm\n"); printf("2) Build a suffix tree using Weiner's algorithm\n"); printf("3) Exact matching using a suffix tree for the text\n"); printf("4) Walk around a suffix tree\n"); printf("5) Compute the LCA values for a suffix tree\n"); printf(" a) using the naive LCA algorithm\n"); printf(" b) using the constant time LCA algorithm\n"); printf("6) Compute Lempel-Ziv decomposition\n"); printf(" a) original version (f-factorization)\n"); printf(" b) nonoverlapping blocks (as in the book)\n"); printf("8) Set suffix tree build policy (current: "); switch(stree_build_policy) { case LINKED_LIST: printf("linked list)\n"); break; case SORTED_LIST: printf("sorted list)\n"); break; case LIST_THEN_ARRAY: printf("list then array, threshold %d)\n", stree_build_threshold); break; case COMPLETE_ARRAY: printf("complete array)\n"); break; } printf("9) Suffix tree print toggle (current: %s)\n", (stree_print_flag == ON ? "on" : "off")); printf("*) String Utilites\n"); printf("0) Exit\n"); printf("\nEnter Selection: "); while ((choice = my_getline(stdin, &ch_len)) == NULL) ; switch (choice[0]) { case '0': return; case '1': strings = get_string_ary("list of sequences", &num_strings); if (strings == NULL) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe sequences:\n"); for (i=0; i < num_strings; i++) { mprintf("%2d)", i + 1); terse_print_string(strings[i]); } mputc('\n'); status = map_sequences(NULL, NULL, strings, num_strings); if (status != -1) { mprintf("Executing Ukkonen's Algorithm...\n\n"); strmat_ukkonen_build(strings, num_strings, stree_build_policy, stree_build_threshold, stats_flag, stree_print_flag); unmap_sequences(NULL, NULL, strings, num_strings); } mend(num_lines); putchar('\n'); free(strings); break; case '2': strings = get_string_ary("list of sequences", &num_strings); if (strings == NULL) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe sequences:\n"); for (i=0; i < num_strings; i++) { mprintf("%2d)", i + 1); terse_print_string(strings[i]); } mputc('\n'); status = map_sequences(NULL, NULL, strings, num_strings); if (status != -1) { mprintf("Executing Weiner's Algorithm...\n\n"); strmat_weiner_build(strings, num_strings, stree_build_policy, stree_build_threshold, stats_flag, stree_print_flag); unmap_sequences(NULL, NULL, strings, num_strings); } mend(num_lines); putchar('\n'); free(strings); break; case '3': if (!(pattern = get_string("pattern")) || !(strings = get_string_ary("list of sequences", &num_strings))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe pattern:\n"); terse_print_string(pattern); mprintf("\nThe texts:\n"); for (i=0; i < num_strings; i++) { mprintf("%2d)", i + 1); terse_print_string(strings[i]); } mputc('\n'); status = map_sequences(NULL, pattern, strings, num_strings); if (status != -1) { mprintf("Executing exact matching with a suffix tree...\n\n"); strmat_stree_match(pattern, strings, num_strings, stree_build_policy, stree_build_threshold, stats_flag); unmap_sequences(NULL, pattern, strings, num_strings); } mend(num_lines); putchar('\n'); free(strings); break; case '4': strings = get_string_ary("list of sequences", &num_strings); if (strings == NULL) continue; status = map_sequences(NULL, NULL, strings, num_strings); if (status != -1) { strmat_stree_walkaround(strings, num_strings, stree_build_policy, stree_build_threshold); unmap_sequences(NULL, NULL, strings, num_strings); } putchar('\n'); free(strings); break; case '5': ch = toupper(choice[1]); if (ch != 'A' && ch != 'B') { printf("\nYou must specify which type of LCA algorithm to use " "(as in '3a' or '3b').\n"); continue; } strings = get_string_ary("list of sequences", &num_strings); if (strings == NULL) continue; status = map_sequences(NULL, NULL, strings, num_strings); if (status != -1) { if (ch == 'A') strmat_stree_naive_lca(strings, num_strings, stree_build_policy, stree_build_threshold, stats_flag); else strmat_stree_lca(strings, num_strings, stree_build_policy, stree_build_threshold, stats_flag); unmap_sequences(NULL, NULL, strings, num_strings); } putchar('\n'); free(strings); break; case '6': ch = toupper(choice[1]); if (ch!='A' && ch!='B') { printf("\nYou must specify which type of decomposition to compute " "(as in '6a' or '6b').\n"); continue; } if (!(text = get_string("string"))) continue; mstart(stdin, fpout, OK, OK, 0, NULL); mprintf("\nThe string:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, NULL, NULL, 0); if(status != -1) { strmat_stree_lempel_ziv(text, stree_build_policy, stree_build_threshold, stats_flag,ch); unmap_sequences(text, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '8': choice = "0"; while (choice[0] != '1' && choice[0] != '2' && choice[0] != '3' && choice[0] != '4') { printf("\n** Suffix Tree Build Policies **\n"); printf("\n(1 - linked list, 2 - sorted list, 3 - linked list/array," " 4 - complete array)\n"); printf("Enter Build Policy [%d]: ", (stree_build_policy == LINKED_LIST ? 1 : (stree_build_policy == SORTED_LIST ? 2 : (stree_build_policy == LIST_THEN_ARRAY ? 3 : 4)))); if ((choice = my_getline(stdin, &ch_len)) == NULL || choice[0] == '\0') break; switch (choice[0]) { case '1': stree_build_policy = LINKED_LIST; break; case '2': stree_build_policy = SORTED_LIST; break; case '3': stree_build_policy = LIST_THEN_ARRAY; break; case '4': stree_build_policy = COMPLETE_ARRAY; break; default: printf("\nThat is not a choice.\n"); } } if (stree_build_policy == LIST_THEN_ARRAY) { printf("\nEnter Build Threshold [%d]: ", stree_build_threshold); if ((choice = my_getline(stdin, &ch_len)) != NULL) sscanf(choice, "%d", &stree_build_threshold); } putchar('\n'); break; case '9': if (stree_print_flag == ON) stree_print_flag = OFF; else stree_print_flag = ON; break; case '*': util_menu(); break; default: printf("\nThat is not a choice.\n"); } } }
/********************************************************************** * Function z_alg_menu(); * * Parameter: * * * This function prompts user to create and utilize the Z values * for a string. The utilities menu is also available from this menu. * **********************************************************************/ void z_alg_menu() { int status, num_lines; char ch; STRING *text, *pattern; while (1) { num_lines = 12; printf("\n** Z-value Algorithm Menu **\n\n"); printf("1) Build Z values for a sequence\n"); printf("2) Exact matching using Z values\n"); printf("3) Knuth-Morris-Pratt (Z-values preprocessing)\n"); printf(" a) using sp values\n"); printf(" b) using sp' values\n"); printf("*) String Utilites\n"); printf("0) Exit\n"); printf("\nEnter Selection: "); while ((choice = my_getline(stdin, &ch_len)) == NULL) ; switch (choice[0]) { case '0': return; case '1': if (!(text = get_string("text"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mputs("The string:\n"); terse_print_string(text); status = map_sequences(text, NULL, NULL, 0); if (status != -1) { mputs("Building Z values...\n\n"); strmat_z_build(text, stats_flag); unmap_sequences(text, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '2': if (!(pattern = get_string("pattern")) || !(text = get_string("text"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mputs("\nThe pattern:\n"); terse_print_string(pattern); mputs("\nThe text:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, pattern, NULL, 0); if (status != -1) { mputs("Executing exact matching with Z values algorithm...\n\n"); strmat_z_match(pattern, text, stats_flag); unmap_sequences(text, pattern, NULL, 0); } mend(num_lines); putchar('\n'); break; case '3': ch = choice[1]; if (toupper(ch) != 'A' && toupper(ch) != 'B') { printf("\nYou must specify the KMP variation (as in '3a' or '3b').\n"); continue; } if (!(pattern = get_string("pattern")) || !(text = get_string("text"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe pattern:\n"); terse_print_string(pattern); mprintf("\nThe text:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, pattern, NULL, 0); if (status != -1) { if (toupper(ch) == 'A') { mprintf ("Executing KMP with sp values...\n\n"); strmat_kmp_sp_z_match(pattern, text, stats_flag); } else { mprintf ("Executing KMP with sp' values...\n\n"); strmat_kmp_spprime_z_match(pattern, text, stats_flag); } unmap_sequences(text, pattern, NULL, 0); } mend(num_lines); putchar('\n'); break; case '*': util_menu(); break; default: printf("\nThat is not a choice.\n"); } } }
bool exportFontBin(const char * filename, MFont * font) { if(! font) return false; MEngine * engine = MEngine::getInstance(); MRenderingContext * render = engine->getRenderingContext(); // read image MImage image; render->bindTexture(font->getTextureId()); render->getTexImage(0, &image); unsigned int width = image.getWidth(); unsigned int height = image.getHeight(); if(width == 0 && height == 0) { printf("Error : unable to create image font for %s\n", filename); return false; } // create file FILE * file = fopen(filename, "wb"); if(! file) { printf("Error : can't create file %s\n", filename); return false; } // bin fwrite(M_FONT_HEADER, sizeof(char), 8, file); // version int version = 1; fwrite(&version, sizeof(int), 1, file); // font size unsigned int fontSize = font->getFontSize(); fwrite(&fontSize, sizeof(int), 1, file); // write image { fwrite(&width, sizeof(int), 1, file); fwrite(&height, sizeof(int), 1, file); unsigned char color[4]; unsigned int x, y; for(y=0; y<height; y++) { for(x=0; x<width; x++) { image.readPixel(x, y, color); fwrite(&color[3], sizeof(char), 1, file); } } } // write characters infos { map <unsigned int, MCharacter> * characters = font->getCharacters(); // size unsigned int size = font->getCharactersNumber(); fwrite(&size, sizeof(int), 1, file); // characters map <unsigned int, MCharacter>::iterator mit (characters->begin()), mend(characters->end()); for(;mit!=mend;++mit) { unsigned int charCode = mit->first; MCharacter * character = &mit->second; MVector2 pos = character->getPos(); MVector2 offset = character->getOffset(); MVector2 scale = character->getScale(); float xadvance = character->getXAdvance(); fwrite(&charCode, sizeof(int), 1, file); fwrite(&pos, sizeof(float), 2, file); fwrite(&offset, sizeof(float), 2, file); fwrite(&scale, sizeof(float), 2, file); fwrite(&xadvance, sizeof(float), 1, file); } } fclose(file); return true; }
/********************************************************************** * Function suf_ary_menu() * * Parameter: * * * This function prompts user to choose an algorithm to create * a suffix array and use it. * The utilities menu is also available from this menu. * **********************************************************************/ void suf_ary_menu() { int status, num_lines; STRING *spt, *pattern, *text; while (1) { num_lines = 13; printf("\n** Suffix Array Menu **\n\n"); printf("1) Build suffix array using quick sort\n"); printf("2) Build suffix array (Zerkle's version)\n"); printf("3) Build suffix array from a suffix tree\n"); printf("4) Exact matching using suffix array and naive algorithm\n"); printf("5) Exact matching using suffix array and mlr accelerant\n"); printf("6) Exact matching using suffix array and lcp super-accelerant\n"); printf("*) String Utilites\n"); printf("0) Exit\n"); printf("\nEnter Selection: "); while ((choice = my_getline(stdin, &ch_len)) == NULL) ; switch (choice[0]) { case '0': return; case '1': if (!(spt = get_string("sequence"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe sequence:\n"); terse_print_string(spt); mputc('\n'); status = map_sequences(spt, NULL, NULL, 0); if (status != -1) { mprintf("Building suffix array using qsort...\n\n"); strmat_sary_qsort(spt, stats_flag); unmap_sequences(spt, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '2': if (!(spt = get_string("sequence"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe sequence:\n"); terse_print_string(spt); mputc('\n'); status = map_sequences(spt, NULL, NULL, 0); if (status != -1) { mprintf("Executing Zerkle's algorithm...\n\n"); strmat_sary_zerkle(spt, stats_flag); unmap_sequences(spt, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '3': if (!(spt = get_string("sequence"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe sequence:\n"); terse_print_string(spt); mputc('\n'); status = map_sequences(spt, NULL, NULL, 0); if (status != -1) { mprintf("Building suffix array from suffix tree...\n\n"); strmat_sary_stree(spt, stats_flag); unmap_sequences(spt, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '4': if (!(pattern = get_string("pattern")) || !(text = get_string("text"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe pattern:\n"); terse_print_string(pattern); mprintf("\nThe text:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, pattern, NULL, 0); if (status != -1) { mprintf("Executing exact matching using suffix array...\n\n"); strmat_sary_match_naive(pattern, text, stats_flag); unmap_sequences(text, pattern, NULL, 0); } mend(num_lines); putchar('\n'); break; case '5': if (!(pattern = get_string("pattern")) || !(text = get_string("text"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe pattern:\n"); terse_print_string(pattern); mprintf("\nThe text:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, pattern, NULL, 0); if (status != -1) { mprintf("Executing exact matching using suffix array...\n\n"); strmat_sary_match_mlr(pattern, text, stats_flag); unmap_sequences(text, pattern, NULL, 0); } mend(num_lines); putchar('\n'); break; case '6': if (!(pattern = get_string("pattern")) || !(text = get_string("text"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe pattern:\n"); terse_print_string(pattern); mprintf("\nThe text:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, pattern, NULL, 0); if (status != -1) { mprintf("Executing exact matching using suffix array...\n\n"); strmat_sary_match_lcp(pattern, text, stats_flag); unmap_sequences(text, pattern, NULL, 0); } mend(num_lines); putchar('\n'); break; case '*': util_menu(); break; default: printf("\nThat is not a choice.\n"); } } }
/********************************************************************** * Function repeats_menu() * * Parameter: * * * This function prompts user to choose an algorithm to compute * repeats and similar things. * The utilities menu is also available from this menu. * **********************************************************************/ void repeats_menu() { static int smax_percent = 0; static int smax_minlen = 0; int status, num_lines; char ch; STRING *text; while (1) { num_lines = 20; printf("\n** Repeats Menu **\n\n"); printf("1) Find primitive tandem repeats (Crochemore's algorithm)\n"); printf("2) Find supermaximals and near supermaximals of a string\n"); printf("3) Find nonoverlapping maximals of a string" " (Crochemore variant)\n"); printf("4) Find nonoverlapping maximals of a string" " (big path algorithm)\n"); printf("5) Find tandem repeats/tandem arrays using the suffix tree\n"); printf("6) Find vocabulary of tandem repeats (and more) using\n"); printf(" a) Ziv-Lempel decomposition\n"); printf(" b) nonoverlapping blocks decomposition (as in the book)\n"); printf("7) Find occurrences in linear time (without suffix tree) using\n"); printf(" a) Ziv-Lempel decomposition\n"); printf(" b) nonoverlapping blocks decomposition (as in the book)\n"); printf("*) String Utilites\n"); printf("0) Exit\n"); printf("\nEnter Selection: "); while ((choice = my_getline(stdin, &ch_len)) == NULL) ; switch (choice[0]) { case '0': return; case '1': if (!(text = get_string("string"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe string:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, NULL, NULL, 0); if (status != -1) { strmat_repeats_primitives(text, stats_flag); unmap_sequences(text, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '2': if (!(text = get_string("text"))) continue; smax_percent = get_bounded("Percent Supermaximal", 0, 100, smax_percent); printf("\n"); if (smax_percent == -1) continue; smax_minlen = get_bounded("Supermax. Minimum Length", 0, text->length, smax_minlen); printf("\n"); if (smax_minlen == -1) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe text:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, NULL, NULL, 0); if (status != -1) { mprintf("Finding the supermaximals...\n\n"); strmat_repeats_supermax(text, smax_percent, smax_minlen); unmap_sequences(text, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '3': if (!(text = get_string("string"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe string:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, NULL, NULL, 0); if (status != -1) { strmat_repeats_nonoverlapping(text, stats_flag); unmap_sequences(text, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '4': if (!(text = get_string("string"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe string:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, NULL, NULL, 0); if (status != -1) { strmat_repeats_bigpath(text, stree_build_policy, stree_build_threshold, stats_flag); unmap_sequences(text, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '5': if (!(text = get_string("string"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe string:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, NULL, NULL, 0); if (status != -1) { strmat_repeats_tandem(text, stree_build_policy, stree_build_threshold, stats_flag); unmap_sequences(text, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '6': ch = toupper(choice[1]); if (ch!='A' && ch!='B') { printf("\nYou must specify which type of decomposition to use" "(as in '6a' or '6b').\n"); continue; } if (!(text = get_string("string"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe string:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, NULL, NULL, 0); if (status != -1) { strmat_repeats_vocabulary(text, stree_build_policy, stree_build_threshold, stats_flag,ch); unmap_sequences(text, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '7': ch = toupper(choice[1]); if (ch!='A' && ch!='B') { printf("\nYou must specify which type of decomposition to use" "(as in '7a' or '7b').\n"); continue; } if (!(text = get_string("string"))) continue; mstart(stdin, fpout, OK, OK, 5, NULL); mprintf("\nThe string:\n"); terse_print_string(text); mputc('\n'); status = map_sequences(text, NULL, NULL, 0); if (status != -1) { strmat_repeats_linear_occs(text, stree_build_policy, stree_build_threshold, stats_flag,ch); unmap_sequences(text, NULL, NULL, 0); } mend(num_lines); putchar('\n'); break; case '*': util_menu(); break; default: printf("\nThat is not a choice.\n"); } } }