dungeon_crawler
annotate prototype/src/datapath.cc @ 80:a373b36ffc17
better
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 27 Oct 2012 01:59:39 +0300 |
parents | 91180ee7b7d9 |
children |
rev | line source |
---|---|
nuclear@5 | 1 #include <stdio.h> |
nuclear@5 | 2 #include <vector> |
nuclear@5 | 3 #include <string> |
nuclear@5 | 4 #include "datapath.h" |
nuclear@5 | 5 |
nuclear@5 | 6 static std::vector<std::string> pathlist; |
nuclear@5 | 7 |
nuclear@5 | 8 void add_data_path(const char *path) |
nuclear@5 | 9 { |
nuclear@5 | 10 pathlist.push_back(path); |
nuclear@5 | 11 } |
nuclear@5 | 12 |
nuclear@63 | 13 std::string datafile_path(const char *fname) |
nuclear@5 | 14 { |
nuclear@63 | 15 std::string res; |
nuclear@16 | 16 if(!fname) { |
nuclear@63 | 17 return res; |
nuclear@16 | 18 } |
nuclear@16 | 19 |
nuclear@5 | 20 for(auto path : pathlist) { |
nuclear@5 | 21 res = path + "/" + std::string(fname); |
nuclear@5 | 22 FILE *fp = fopen(res.c_str(), "r"); |
nuclear@5 | 23 if(fp) { |
nuclear@5 | 24 fclose(fp); |
nuclear@63 | 25 return res; |
nuclear@5 | 26 } |
nuclear@5 | 27 } |
nuclear@63 | 28 return std::string(fname); |
nuclear@5 | 29 } |