comparison gen/configfile.cpp @ 1531:7120a74e9ae2

Remove duplicated code This was implemented for windows in llvm r73379
author Benjamin Kramer <benny.kra@gmail.com>
date Sat, 11 Jul 2009 13:58:23 +0200
parents cd4478b47b10
children 49ae9728bea4
comparison
equal deleted inserted replaced
1530:05c235309d6f 1531:7120a74e9ae2
9 9
10 #include "gen/configfile.h" 10 #include "gen/configfile.h"
11 11
12 #include "mars.h" 12 #include "mars.h"
13 13
14 #if _WIN32
15 #include <windows.h>
16 #undef GetCurrentDirectory
17 #endif
18
19 namespace sys = llvm::sys; 14 namespace sys = llvm::sys;
20 15
21 ConfigFile::ConfigFile() 16 ConfigFile::ConfigFile()
22 { 17 {
23 cfg = new libconfig::Config; 18 cfg = new libconfig::Config;
25 20
26 ConfigFile::~ConfigFile() 21 ConfigFile::~ConfigFile()
27 { 22 {
28 delete cfg; 23 delete cfg;
29 } 24 }
30
31 #if _WIN32
32 sys::Path ConfigGetExePath(sys::Path p)
33 {
34 char buf[MAX_PATH];
35 GetModuleFileName(NULL, buf, MAX_PATH);
36 p = buf;
37 p.eraseComponent();
38 return p;
39 }
40 #endif
41 25
42 26
43 bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const char* filename) 27 bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const char* filename)
44 { 28 {
45 // 1) try the current working dir 29 // 1) try the current working dir
87 if (p.exists()) 71 if (p.exists())
88 return true; 72 return true;
89 #endif 73 #endif
90 74
91 // 7) try next to the executable 75 // 7) try next to the executable
92 #if _WIN32
93 p = ConfigGetExePath(p);
94 #else
95 p = sys::Path::GetMainExecutable(argv0, mainAddr); 76 p = sys::Path::GetMainExecutable(argv0, mainAddr);
96 p.eraseComponent(); 77 p.eraseComponent();
97 #endif
98 p.appendComponent(filename); 78 p.appendComponent(filename);
99 if (p.exists()) 79 if (p.exists())
100 return true; 80 return true;
101 81
102 return false; 82 return false;
136 // handle switches 116 // handle switches
137 if (root.exists("switches")) 117 if (root.exists("switches"))
138 { 118 {
139 std::string binpathkey = "%%ldcbinarypath%%"; 119 std::string binpathkey = "%%ldcbinarypath%%";
140 120
141 #if _WIN32
142 sys::Path p;
143 p = ConfigGetExePath(p);
144 std::string binpath = p.toString();
145 #else
146 std::string binpath = sys::Path::GetMainExecutable(argv0, mainAddr).getDirname(); 121 std::string binpath = sys::Path::GetMainExecutable(argv0, mainAddr).getDirname();
147 #endif
148
149 122
150 libconfig::Setting& arr = cfg->lookup("default.switches"); 123 libconfig::Setting& arr = cfg->lookup("default.switches");
151 int len = arr.getLength(); 124 int len = arr.getLength();
152 for (int i=0; i<len; i++) 125 for (int i=0; i<len; i++)
153 { 126 {