comparison gen/configfile.cpp @ 1476:df0ffca8a636

There was another fix needed here for reading %%ldcbinarypath%%
author Kelly Wilson <wilsonk cpsc.ucalgary.ca>
date Thu, 04 Jun 2009 18:36:07 -0600
parents 1f29cbc36bf5
children 6023f65a3aee
comparison
equal deleted inserted replaced
1475:1f29cbc36bf5 1476:df0ffca8a636
26 ConfigFile::~ConfigFile() 26 ConfigFile::~ConfigFile()
27 { 27 {
28 delete cfg; 28 delete cfg;
29 } 29 }
30 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
42
31 bool ConfigFile::read(const char* argv0, void* mainAddr, const char* filename) 43 bool ConfigFile::read(const char* argv0, void* mainAddr, const char* filename)
32 { 44 {
33 45
46 #if _WIN32
47 std::string exeDirectoryName;
48 #endif
34 // try to find the config file 49 // try to find the config file
35 50
36 // 1) try the current working dir 51 // 1) try the current working dir
37 sys::Path p = sys::Path::GetCurrentDirectory(); 52 sys::Path p = sys::Path::GetCurrentDirectory();
38 p.appendComponent(filename); 53 p.appendComponent(filename);
54 p.appendComponent(filename); 69 p.appendComponent(filename);
55 70
56 if (!p.exists()) 71 if (!p.exists())
57 { 72 {
58 #if _WIN32 73 #if _WIN32
59 char buf[256]; 74 p = ConfigGetExePath(p);
60 GetModuleFileName(NULL, buf, 256); 75 exeDirectoryName = p.toString();
61 p = buf;
62 #else 76 #else
63 // 4) try next to the executable 77 // 4) try next to the executable
64 p = sys::Path::GetMainExecutable(argv0, mainAddr); 78 p = sys::Path::GetMainExecutable(argv0, mainAddr);
79 p.eraseComponent();
65 #endif 80 #endif
66 p.eraseComponent();
67 p.appendComponent(filename); 81 p.appendComponent(filename);
68 if (!p.exists()) 82 if (!p.exists())
69 { 83 {
70 // 5) fail load cfg, users still have the DFLAGS environment var 84 // 5) fail load cfg, users still have the DFLAGS environment var
71 std::cerr << "Error failed to locate the configuration file: " << filename << std::endl; 85 std::cerr << "Error failed to locate the configuration file: " << filename << std::endl;
95 109
96 // handle switches 110 // handle switches
97 if (root.exists("switches")) 111 if (root.exists("switches"))
98 { 112 {
99 std::string binpathkey = "%%ldcbinarypath%%"; 113 std::string binpathkey = "%%ldcbinarypath%%";
114
115 #if _WIN32
116 std::string binpath;
117 //This will happen if ldc.conf is found somewhere other than
118 //beside the ldc executable
119 if (exeDirectoryName == "")
120 {
121 sys::Path p;
122 p = ConfigGetExePath(p);
123 exeDirectoryName = p.toString();
124 }
125 binpath = exeDirectoryName;
126 #else
100 std::string binpath = sys::Path::GetMainExecutable(argv0, mainAddr).getDirname(); 127 std::string binpath = sys::Path::GetMainExecutable(argv0, mainAddr).getDirname();
128 #endif
129
101 130
102 libconfig::Setting& arr = cfg->lookup("default.switches"); 131 libconfig::Setting& arr = cfg->lookup("default.switches");
103 int len = arr.getLength(); 132 int len = arr.getLength();
104 for (int i=0; i<len; i++) 133 for (int i=0; i<len; i++)
105 { 134 {