#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <algorithm>
#include "datamap.h"
-#ifdef WIN32
+#if defined(WIN32) || defined(__WIN32__)
#include <malloc.h>
#else
#include <alloca.h>
static char *clean_line(char *s);
+DataMap::DataMap()
+{
+ strip_paths = false;
+}
+
void DataMap::clear()
{
dmap.clear();
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;
{
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<std::string, std::string>::iterator it = cache.find(in);
if(it != cache.end()) {