//------------------------------------------------- // load a driver name and offset into an // indexed array //------------------------------------------------- void datfile_manager::load_driver_text(FILE *fp, game_driver const *drv, std::string &buffer, drvindex const &idx, std::string const &tag) { std::string s(core_filename_extract_base(drv->source_file)); auto index = idx.find(s); // if driver not found, return if (index == idx.end()) return; buffer.append("\n--- DRIVER INFO ---\n").append("Driver: ").append(s).append("\n\n"); auto s_offset = index->second; std::fseek(fp, s_offset, SEEK_SET); char rbuf[64 * 1024]; std::string readbuf; while (std::fgets(rbuf, 64 * 1024, fp) != nullptr) { readbuf = chartrimcarriage(rbuf); // end entry when a end tag is encountered if (readbuf == TAG_END) break; // continue if a specific tag is encountered if (readbuf == tag) continue; // add this string to the buffer buffer.append(readbuf).append("\n"); } }
//------------------------------------------------- // load a game name and offset into an // indexed array (mameinfo) //------------------------------------------------- int datfile_manager::index_mame_mess_info(fileptr &&fp, dataindex &index, drvindex &index_drv, int &drvcount) { size_t foundtag; auto t_mame = TAG_MAMEINFO_R.size(); auto t_mess = TAG_MESSINFO_R.size(); auto t_ginit = TAG_GAMEINIT_R.size(); auto t_info = TAG_INFO.size(); char rbuf[64 * 1024]; std::string readbuf, xid, name; while (std::fgets(rbuf, 64 * 1024, fp.get()) != nullptr) { readbuf = chartrimcarriage(rbuf); if (m_mame_rev.empty() && readbuf.compare(0, t_mame, TAG_MAMEINFO_R) == 0) { auto found = readbuf.find(" ", t_mame + 1); m_mame_rev = readbuf.substr(t_mame + 1, found - t_mame); } else if (m_mess_rev.empty() && (foundtag = readbuf.find(TAG_MESSINFO_R)) != std::string::npos) { auto found = readbuf.find(" ", foundtag + t_mess + 1); m_mess_rev = readbuf.substr(foundtag + t_mess + 1, found - t_mess - foundtag); } else if (m_ginit_rev.empty() && readbuf.compare(0, t_ginit, TAG_GAMEINIT_R) == 0) { auto found = readbuf.find(" ", t_ginit + 1); m_ginit_rev = readbuf.substr(t_ginit + 1, found - t_ginit); } else if (readbuf.compare(0, t_info, TAG_INFO) == 0) { // TAG_INFO std::fgets(rbuf, 64 * 1024, fp.get()); xid = chartrimcarriage(rbuf); name = readbuf.substr(t_info + 1); if (xid == TAG_MAME) { // validate driver auto game_index = driver_list::find(name.c_str()); if (game_index != -1) index.emplace(&driver_list::driver(game_index), std::ftell(fp.get())); } else if (xid == TAG_DRIVER) { index_drv.emplace(name, std::ftell(fp.get())); drvcount++; } } } return index.size(); }
//------------------------------------------------- // create the menu index //------------------------------------------------- void datfile_manager::index_menuidx(const game_driver *drv, dataindex &idx, drvindex &index) { dataindex::iterator itemsiter = idx.find(drv); if (itemsiter == idx.end()) { int cloneof = driver_list::non_bios_clone(*drv); if (cloneof == -1) return; else { const game_driver *c_drv = &driver_list::driver(cloneof); itemsiter = idx.find(c_drv); if (itemsiter == idx.end()) return; } } // seek to correct point in datafile long s_offset = (*itemsiter).second; fseek(fp, s_offset, SEEK_SET); size_t tinfo = TAG_INFO.size(); char rbuf[64 * 1024]; std::string readbuf; while (fgets(rbuf, 64 * 1024, fp) != nullptr) { readbuf = chartrimcarriage(rbuf); if (!core_strnicmp(TAG_INFO.c_str(), readbuf.c_str(), tinfo)) break; // TAG_COMMAND identifies the driver if (readbuf == TAG_COMMAND) { fgets(rbuf, 64 * 1024, fp); chartrimcarriage(rbuf); index.emplace(rbuf, ftell(fp)); } } }
//------------------------------------------------- // create the menu index //------------------------------------------------- void datfile_manager::index_menuidx(fileptr &&fp, const game_driver *drv, dataindex const &idx, drvindex &index) { auto itemsiter = idx.find(drv); if (itemsiter == idx.end()) { auto const cloneof = driver_list::non_bios_clone(*drv); if (cloneof == -1) return; auto const c_drv = &driver_list::driver(cloneof); if ((itemsiter = idx.find(c_drv)) == idx.end()) return; } // seek to correct point in datafile auto const s_offset = itemsiter->second; std::fseek(fp.get(), s_offset, SEEK_SET); auto const tinfo = TAG_INFO.size(); char rbuf[64 * 1024]; std::string readbuf; while (std::fgets(rbuf, 64 * 1024, fp.get()) != nullptr) { readbuf = chartrimcarriage(rbuf); if (!core_strnicmp(TAG_INFO.c_str(), readbuf.c_str(), tinfo)) break; // TAG_COMMAND identifies the driver if (readbuf == TAG_COMMAND) { std::fgets(rbuf, 64 * 1024, fp.get()); chartrimcarriage(rbuf); index.emplace(rbuf, std::ftell(fp.get())); } } }