On Tuesday, March 12, 2024 4:31:07 PM EDT David "Judah's Shadow" Blue wrote: > After grepping around in the BibleTime source code, I settled on using their > solution of using module category and/or features showing the module is a > devotional. I'm doing the following assignment > > category = tempMod->getConfigEntry("Category"); > > If category is a std::string I get a segfault. If category is a const char* > it works. Is there some reason the return value of getConfigEntry isn't > compatible with std::string in this instance? Or have I found a magic/more > magic switch?
Based on other weirdness I get from this function, I want to say it's a magic/ more magic switch. That said, I would really like to declare category as a std::string instead of a const char* so I can do a straight literal comparison instead of mucking around with strncmp (which at the moment is also crashing). For devotionals, maps, and image based modules I can fall back to getConfig.has("Feature",feature). But I don't have such a fallback for "Cult / Unorthodox / Questionable Material" category works, which is what I'm currently trying to filter out. I've included my function as it stands currently using const char* and strncmp. std::list<std::string> Library::getModuleList(std::string moduleType) { std::string module = ""; sword::ModMap::iterator libraryIterator; std::list<std::string> moduleList; std::string selectedType; std::string modType; std::string bible = sword::SWMgr::MODTYPE_BIBLES; std::string comentary = sword::SWMgr::MODTYPE_COMMENTARIES; std::string devo = sword::SWMgr::MODTYPE_DAILYDEVOS; std::string book = sword::SWMgr::MODTYPE_GENBOOKS; std::string dict = sword::SWMgr::MODTYPE_LEXDICTS; const char *category; sword::SWModule *tempMod; if(moduleType == "bible") { selectedType = bible; } else if(moduleType == "commentary") { selectedType = comentary; } else if(moduleType == "devotion") { selectedType = devo; } else if(moduleType == "book") { selectedType = book; } else if(moduleType == "dictionary") { selectedType = dict; } else { //We should never get here but you never know. module = "Invalid type"; moduleList.push_back(module); return moduleList; } for(libraryIterator = this->swordLibrary->Modules.begin(); libraryIterator != this->swordLibrary->Modules.end(); libraryIterator++) { tempMod = libraryIterator->second; category = tempMod->getConfigEntry("Category"); //Devotions will never match on straight type, so check category or //features and set the module type to devotion, otherwise accept the //type from the module. if(strncmp("Devotional",category,11) == 0 || tempMod->getConfig().has("Feature","DailyDevotion")) { modType = devo; } //Modules with images aren't supported since this is a text only //application so set the type to something selectedType will never //match against else if(strncmp(category, "Maps",4) == 0 || strncmp(category,"Images",6) == 0 || tempMod->getConfig().has("Feature", "Images")) { modType = "Unsupported"; } else if(strncmp(category, "Cults / Unorthodox / Questionable Material" ,42)) { modType = "cultish"; } else { modType = tempMod->getType(); } if(modType == selectedType) { module = "For "; module += tempMod->getDescription(); module += " select "; module += tempMod->getName(); moduleList.push_front(module); module = ""; } } return moduleList; } _______________________________________________ sword-devel mailing list: sword-devel@crosswire.org http://crosswire.org/mailman/listinfo/sword-devel Instructions to unsubscribe/change your settings at above page