From 5d44043a65106ff411abeaaaa80c732a47284024 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 17 Dec 2016 03:26:39 +0200 Subject: [PATCH] added strip_path in metascene --- src/datamap.cc | 24 ++++++++++++++++++------ src/datamap.h | 4 ++++ src/metascene.cc | 7 ++++++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/datamap.cc b/src/datamap.cc index 1f3befe..e448923 100644 --- a/src/datamap.cc +++ b/src/datamap.cc @@ -11,6 +11,11 @@ static char *clean_line(char *s); +DataMap::DataMap() +{ + strip_paths = false; +} + void DataMap::clear() { dmap.clear(); @@ -22,6 +27,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 +101,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()) { diff --git a/src/datamap.h b/src/datamap.h index 137fdca..674ab7c 100644 --- a/src/datamap.h +++ b/src/datamap.h @@ -9,11 +9,15 @@ class DataMap { std::vector> dmap; mutable std::map cache; std::string root; + bool strip_paths; public: + DataMap(); + void clear(); void set_path(const char *path); + void set_strip(bool s); bool load_map(const char *fname); void map(const char *match, const char *path); diff --git a/src/metascene.cc b/src/metascene.cc index 53474f7..6059664 100644 --- a/src/metascene.cc +++ b/src/metascene.cc @@ -118,10 +118,15 @@ static bool proc_scenefile(MetaScene *mscn, struct ts_node *node) // datapath struct ts_attr *adpath = attr_inscope(node, "datapath"); if(adpath && adpath->val.type == TS_STRING) { - info_log("adding data path: %s\n", adpath->val.str); mscn->datamap.set_path(adpath->val.str); } + // strip path + struct ts_attr *aspath = attr_inscope(node, "strip_path"); + if(aspath && aspath->val.type == TS_NUMBER) { + mscn->datamap.set_strip(aspath->val.inum); + } + // walkmesh struct ts_attr *awmesh = attr_inscope(node, "walkmesh"); if(awmesh && awmesh->val.type == TS_STRING) { -- 1.7.10.4