Mercurial > projects > ldc
comparison gen/configfile.cpp @ 1536:49ae9728bea4
Check for ldc.conf next to the ldc binary before home and etc.
The new search order is
* current working directory
* next to executable
* user home directory
* prefix/etc
* prefix/etc/ldc
* /etc
* /etc/ldc
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Mon, 13 Jul 2009 22:24:12 +0200 |
parents | 7120a74e9ae2 |
children | ee6b20e7aedb |
comparison
equal
deleted
inserted
replaced
1535:61f12f4651b5 | 1536:49ae9728bea4 |
---|---|
24 } | 24 } |
25 | 25 |
26 | 26 |
27 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) |
28 { | 28 { |
29 // 1) try the current working dir | 29 // try the current working dir |
30 p = sys::Path::GetCurrentDirectory(); | 30 p = sys::Path::GetCurrentDirectory(); |
31 p.appendComponent(filename); | 31 p.appendComponent(filename); |
32 if (p.exists()) | 32 if (p.exists()) |
33 return true; | 33 return true; |
34 | 34 |
35 // 2) try the user home dir | 35 // try next to the executable |
36 p = sys::Path::GetMainExecutable(argv0, mainAddr); | |
37 p.eraseComponent(); | |
38 p.appendComponent(filename); | |
39 if (p.exists()) | |
40 return true; | |
41 | |
42 // try the user home dir | |
36 p = sys::Path::GetUserHomeDirectory(); | 43 p = sys::Path::GetUserHomeDirectory(); |
37 p.appendComponent(filename); | 44 p.appendComponent(filename); |
38 if (p.exists()) | 45 if (p.exists()) |
39 return true; | 46 return true; |
40 | 47 |
41 // 3) try the install-prefix/etc | 48 // try the install-prefix/etc |
42 p = sys::Path(LDC_INSTALL_PREFIX); | 49 p = sys::Path(LDC_INSTALL_PREFIX); |
43 #if !_WIN32 | 50 #if !_WIN32 |
44 // Does Windows need something similar? | 51 // Does Windows need something similar? |
45 p.appendComponent("etc"); | 52 p.appendComponent("etc"); |
46 #endif | 53 #endif |
49 return true; | 56 return true; |
50 | 57 |
51 #if !_WIN32 | 58 #if !_WIN32 |
52 // Does Windows need something similar to these? | 59 // Does Windows need something similar to these? |
53 | 60 |
54 // 4) try the install-prefix/etc/ldc | 61 // try the install-prefix/etc/ldc |
55 p = sys::Path(LDC_INSTALL_PREFIX); | 62 p = sys::Path(LDC_INSTALL_PREFIX); |
56 p.appendComponent("etc"); | 63 p.appendComponent("etc"); |
57 p.appendComponent("ldc"); | 64 p.appendComponent("ldc"); |
58 p.appendComponent(filename); | 65 p.appendComponent(filename); |
59 if (p.exists()) | 66 if (p.exists()) |
60 return true; | 67 return true; |
61 | 68 |
62 // 5) try /etc (absolute path) | 69 // try /etc (absolute path) |
63 p = sys::Path("/etc"); | 70 p = sys::Path("/etc"); |
64 p.appendComponent(filename); | 71 p.appendComponent(filename); |
65 if (p.exists()) | 72 if (p.exists()) |
66 return true; | 73 return true; |
67 | 74 |
68 // 6) try /etc/ldc (absolute path) | 75 // try /etc/ldc (absolute path) |
69 p = sys::Path("/etc/ldc"); | 76 p = sys::Path("/etc/ldc"); |
70 p.appendComponent(filename); | 77 p.appendComponent(filename); |
71 if (p.exists()) | 78 if (p.exists()) |
72 return true; | 79 return true; |
73 #endif | 80 #endif |
74 | 81 |
75 // 7) try next to the executable | |
76 p = sys::Path::GetMainExecutable(argv0, mainAddr); | |
77 p.eraseComponent(); | |
78 p.appendComponent(filename); | |
79 if (p.exists()) | |
80 return true; | |
81 | |
82 return false; | 82 return false; |
83 } | 83 } |
84 | 84 |
85 bool ConfigFile::read(const char* argv0, void* mainAddr, const char* filename) | 85 bool ConfigFile::read(const char* argv0, void* mainAddr, const char* filename) |
86 { | 86 { |