Bladeren bron

use relative paths for includes

Patrick Brosi 5 jaren geleden
bovenliggende
commit
54da0925a2
2 gewijzigde bestanden met toevoegingen van 11 en 1 verwijderingen
  1. 10 1
      ConfigFileParser.cpp
  2. 1 0
      ConfigFileParser.h

+ 10 - 1
ConfigFileParser.cpp

@@ -75,7 +75,7 @@ void ConfigFileParser::parse(const std::string& path) {
75 75
         if (c == '\n') {
76 76
           throw ParseExc(l, pos, ">", "<newline>", path);
77 77
         } else if (c == '>') {
78
-          parse(tmp);
78
+          parse(relPath(tmp, path));
79 79
           tmp.clear();
80 80
           s = NONE;
81 81
         } else {
@@ -353,3 +353,12 @@ void ConfigFileParser::updateVals(size_t sec, const KeyVals& kvs) {
353 353
     _kvs[sec][kv.first] = kv.second;
354 354
   }
355 355
 }
356
+
357
+// _____________________________________________________________________________
358
+std::string ConfigFileParser::relPath(const std::string& file,
359
+                                      std::string curF) const {
360
+  // pass absolute paths through unchanged
361
+  if (file.size() && file[0] == '/') return file;
362
+  curF.erase(std::find(curF.rbegin(), curF.rend(), '/').base(), curF.end());
363
+  return curF + "/" + file;
364
+}

+ 1 - 0
ConfigFileParser.h

@@ -99,5 +99,6 @@ class ConfigFileParser {
99 99
   bool toBool(std::string str) const;
100 100
 
101 101
   void updateVals(size_t sec, const KeyVals& kvs);
102
+  std::string relPath(const std::string& file, std::string curFile) const;
102 103
 };
103 104
 }