Mercurial > projects > ldc
comparison gen/configfile.cpp @ 1340:206329112670
Fix the ldcbinarypath config file rewriting.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 10 May 2009 18:14:36 +0200 |
parents | 2e98ddd72fa7 |
children | 8309ebaa23d5 |
comparison
equal
deleted
inserted
replaced
1339:2e98ddd72fa7 | 1340:206329112670 |
---|---|
1 #include <iostream> | 1 #include <iostream> |
2 #include <string> | 2 #include <string> |
3 #include <cassert> | 3 #include <cassert> |
4 #include <string.h> | 4 #include <cstring> |
5 | 5 |
6 #include "llvm/System/Path.h" | 6 #include "llvm/System/Path.h" |
7 | 7 |
8 #include "libconfig.h++" | 8 #include "libconfig.h++" |
9 | 9 |
83 } | 83 } |
84 | 84 |
85 // handle switches | 85 // handle switches |
86 if (root.exists("switches")) | 86 if (root.exists("switches")) |
87 { | 87 { |
88 std::string binpathkey = "%%ldcbinarypath%%"; | |
89 std::string binpath = sys::Path::GetMainExecutable(argv0, mainAddr).getDirname(); | |
90 | |
88 libconfig::Setting& arr = cfg->lookup("default.switches"); | 91 libconfig::Setting& arr = cfg->lookup("default.switches"); |
89 int len = arr.getLength(); | 92 int len = arr.getLength(); |
90 for (int i=0; i<len; i++) | 93 for (int i=0; i<len; i++) |
91 { | 94 { |
92 std::string v = arr[i]; | 95 std::string v = arr[i]; |
93 | 96 |
94 // replace binpathkey with binpath | 97 // replace binpathkey with binpath |
95 std::string binpathkey = "%%ldcbinarypath%%"; | |
96 sys::Path binpathgetter = sys::Path::GetMainExecutable(argv0, mainAddr); | |
97 binpathgetter.eraseComponent(); | |
98 std::string binpath = binpathgetter.toString(); | |
99 size_t p; | 98 size_t p; |
100 while (std::string::npos != (p = v.find(binpathkey))) | 99 while (std::string::npos != (p = v.find(binpathkey))) |
101 v.replace(p, binpathkey.size(), binpath); | 100 v.replace(p, binpathkey.size(), binpath); |
101 | |
102 switches.push_back(strdup(v.c_str())); | 102 switches.push_back(strdup(v.c_str())); |
103 } | 103 } |
104 } | 104 } |
105 | 105 |
106 } | 106 } |