Browse Source

use relative paths for includes

Patrick Brosi 5 years ago
parent
commit
54da0925a2
2 changed files with 11 additions and 1 deletions
  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
         if (c == '\n') {
75
         if (c == '\n') {
76
           throw ParseExc(l, pos, ">", "<newline>", path);
76
           throw ParseExc(l, pos, ">", "<newline>", path);
77
         } else if (c == '>') {
77
         } else if (c == '>') {
78
-          parse(tmp);
78
+          parse(relPath(tmp, path));
79
           tmp.clear();
79
           tmp.clear();
80
           s = NONE;
80
           s = NONE;
81
         } else {
81
         } else {
@@ -353,3 +353,12 @@ void ConfigFileParser::updateVals(size_t sec, const KeyVals& kvs) {
353
     _kvs[sec][kv.first] = kv.second;
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
   bool toBool(std::string str) const;
99
   bool toBool(std::string str) const;
100
 
100
 
101
   void updateVals(size_t sec, const KeyVals& kvs);
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
 }