X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fdatamap.cc;h=dcbae788b0cc2fe3d7b0ea6f8b0154a701ceab86;hp=1f3befeada97e3107352251666091250b2f489e0;hb=80c04e7a9aa6d42f769dd4fa70c2c3113440cbce;hpb=c38b9bd9f3b1f4efdb0de5a2aabc3bddf76b6aec diff --git a/src/datamap.cc b/src/datamap.cc index 1f3befe..dcbae78 100644 --- a/src/datamap.cc +++ b/src/datamap.cc @@ -1,9 +1,10 @@ #include #include #include +#include #include "datamap.h" -#ifdef WIN32 +#if defined(WIN32) || defined(__WIN32__) #include #else #include @@ -11,6 +12,11 @@ static char *clean_line(char *s); +DataMap::DataMap() +{ + strip_paths = false; +} + void DataMap::clear() { dmap.clear(); @@ -22,6 +28,11 @@ void DataMap::set_path(const char *path) root = std::string(path); } +void DataMap::set_strip(bool s) +{ + strip_paths = s; +} + bool DataMap::load_map(const char *fname) { std::string path = root.empty() ? fname : root + std::string("/") + fname; @@ -91,15 +102,17 @@ int DataMap::lookup(const char *in, char *buf, int bsz) const { std::string res; - char *inbuf = (char*)alloca(strlen(in) + 1); - strcpy(inbuf, in); - if(!(in = clean_line(inbuf))) { - if(buf && bsz > 0) { - buf[0] = 0; + if(strip_paths) { + const char *ptr = strrchr(in, '/'); + if(ptr) { + in = ptr + 1; } - return 0; } + char *inbuf = (char*)alloca(strlen(in) + 1); + strcpy(inbuf, in); + in = clean_line(inbuf); + // first check the cache std::map::iterator it = cache.find(in); if(it != cache.end()) {