Mercurial > projects > ldc
annotate gen/configfile.cpp @ 1526:54b3c1394d62
Merged dmdfe 2.031.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 07 Jul 2009 02:26:11 +0100 |
parents | cd4478b47b10 |
children | 7120a74e9ae2 |
rev | line source |
---|---|
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
1 #include <iostream> |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
2 #include <string> |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
3 #include <cassert> |
1340
206329112670
Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents:
1339
diff
changeset
|
4 #include <cstring> |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
5 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
6 #include "llvm/System/Path.h" |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
7 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
8 #include "libconfig.h++" |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
9 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
10 #include "gen/configfile.h" |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
11 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
12 #include "mars.h" |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
13 |
1473
8309ebaa23d5
Fix for finding ldc.conf file with mingw
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1340
diff
changeset
|
14 #if _WIN32 |
8309ebaa23d5
Fix for finding ldc.conf file with mingw
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1340
diff
changeset
|
15 #include <windows.h> |
8309ebaa23d5
Fix for finding ldc.conf file with mingw
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1340
diff
changeset
|
16 #undef GetCurrentDirectory |
8309ebaa23d5
Fix for finding ldc.conf file with mingw
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1340
diff
changeset
|
17 #endif |
8309ebaa23d5
Fix for finding ldc.conf file with mingw
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1340
diff
changeset
|
18 |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
19 namespace sys = llvm::sys; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
20 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
21 ConfigFile::ConfigFile() |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
22 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
23 cfg = new libconfig::Config; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
24 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
25 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
26 ConfigFile::~ConfigFile() |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
27 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
28 delete cfg; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
29 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
30 |
1476
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
31 #if _WIN32 |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
32 sys::Path ConfigGetExePath(sys::Path p) |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
33 { |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
34 char buf[MAX_PATH]; |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
35 GetModuleFileName(NULL, buf, MAX_PATH); |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
36 p = buf; |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
37 p.eraseComponent(); |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
38 return p; |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
39 } |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
40 #endif |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
41 |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
42 |
1489
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
43 bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const char* filename) |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
44 { |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
45 // 1) try the current working dir |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
46 p = sys::Path::GetCurrentDirectory(); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
47 p.appendComponent(filename); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
48 if (p.exists()) |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
49 return true; |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
50 |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
51 // 2) try the user home dir |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
52 p = sys::Path::GetUserHomeDirectory(); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
53 p.appendComponent(filename); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
54 if (p.exists()) |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
55 return true; |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
56 |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
57 // 3) try the install-prefix/etc |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
58 p = sys::Path(LDC_INSTALL_PREFIX); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
59 #if !_WIN32 |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
60 // Does Windows need something similar? |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
61 p.appendComponent("etc"); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
62 #endif |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
63 p.appendComponent(filename); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
64 if (p.exists()) |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
65 return true; |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
66 |
1490
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
67 #if !_WIN32 |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
68 // Does Windows need something similar to these? |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
69 |
1489
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
70 // 4) try the install-prefix/etc/ldc |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
71 p = sys::Path(LDC_INSTALL_PREFIX); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
72 p.appendComponent("etc"); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
73 p.appendComponent("ldc"); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
74 p.appendComponent(filename); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
75 if (p.exists()) |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
76 return true; |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
77 |
1490
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
78 // 5) try /etc (absolute path) |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
79 p = sys::Path("/etc"); |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
80 p.appendComponent(filename); |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
81 if (p.exists()) |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
82 return true; |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
83 |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
84 // 6) try /etc/ldc (absolute path) |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
85 p = sys::Path("/etc/ldc"); |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
86 p.appendComponent(filename); |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
87 if (p.exists()) |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
88 return true; |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
89 #endif |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
90 |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
91 // 7) try next to the executable |
1489
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
92 #if _WIN32 |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
93 p = ConfigGetExePath(p); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
94 #else |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
95 p = sys::Path::GetMainExecutable(argv0, mainAddr); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
96 p.eraseComponent(); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
97 #endif |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
98 p.appendComponent(filename); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
99 if (p.exists()) |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
100 return true; |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
101 |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
102 return false; |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
103 } |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
104 |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
105 bool ConfigFile::read(const char* argv0, void* mainAddr, const char* filename) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
106 { |
1489
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
107 sys::Path p; |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
108 if (!locate(p, argv0, mainAddr, filename)) |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
109 { |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
110 // failed to find cfg, users still have the DFLAGS environment var |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
111 std::cerr << "Error failed to locate the configuration file: " << filename << std::endl; |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
112 return false; |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
113 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
114 |
1484
7d3b47852a7a
Print the path to the configuration file being used if `-v` is passed.
Frits van Bommel <fvbommel wxs.nl>
parents:
1477
diff
changeset
|
115 // save config file path for -v output |
7d3b47852a7a
Print the path to the configuration file being used if `-v` is passed.
Frits van Bommel <fvbommel wxs.nl>
parents:
1477
diff
changeset
|
116 pathstr = p.toString(); |
7d3b47852a7a
Print the path to the configuration file being used if `-v` is passed.
Frits van Bommel <fvbommel wxs.nl>
parents:
1477
diff
changeset
|
117 |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
118 try |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
119 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
120 // read the cfg |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
121 cfg->readFile(p.c_str()); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
122 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
123 // make sure there's a default group |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
124 if (!cfg->exists("default")) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
125 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
126 std::cerr << "no default settings in configuration file" << std::endl; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
127 return false; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
128 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
129 libconfig::Setting& root = cfg->lookup("default"); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
130 if (!root.isGroup()) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
131 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
132 std::cerr << "default is not a group" << std::endl; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
133 return false; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
134 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
135 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
136 // handle switches |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
137 if (root.exists("switches")) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
138 { |
1340
206329112670
Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents:
1339
diff
changeset
|
139 std::string binpathkey = "%%ldcbinarypath%%"; |
1476
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
140 |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
141 #if _WIN32 |
1489
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
142 sys::Path p; |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
143 p = ConfigGetExePath(p); |
a048f31bf9f6
Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
Christian Kamm <kamm incasoftware de>
parents:
1484
diff
changeset
|
144 std::string binpath = p.toString(); |
1476
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
145 #else |
1340
206329112670
Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents:
1339
diff
changeset
|
146 std::string binpath = sys::Path::GetMainExecutable(argv0, mainAddr).getDirname(); |
1476
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
147 #endif |
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
148 |
1340
206329112670
Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents:
1339
diff
changeset
|
149 |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
150 libconfig::Setting& arr = cfg->lookup("default.switches"); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
151 int len = arr.getLength(); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
152 for (int i=0; i<len; i++) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
153 { |
1337
b6e819244062
In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents:
1114
diff
changeset
|
154 std::string v = arr[i]; |
b6e819244062
In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents:
1114
diff
changeset
|
155 |
b6e819244062
In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents:
1114
diff
changeset
|
156 // replace binpathkey with binpath |
b6e819244062
In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents:
1114
diff
changeset
|
157 size_t p; |
b6e819244062
In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents:
1114
diff
changeset
|
158 while (std::string::npos != (p = v.find(binpathkey))) |
b6e819244062
In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents:
1114
diff
changeset
|
159 v.replace(p, binpathkey.size(), binpath); |
1340
206329112670
Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents:
1339
diff
changeset
|
160 |
1337
b6e819244062
In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents:
1114
diff
changeset
|
161 switches.push_back(strdup(v.c_str())); |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
162 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
163 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
164 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
165 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
166 catch(libconfig::FileIOException& fioe) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
167 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
168 std::cerr << "Error reading configuration file: " << filename << std::endl; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
169 return false; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
170 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
171 catch(libconfig::ParseException& pe) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
172 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
173 std::cerr << "Error parsing configuration file: " << filename |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
174 << "(" << pe.getLine() << "): " << pe.getError() << std::endl; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
175 return false; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
176 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
177 catch(...) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
178 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
179 std::cerr << "Unknown exception caught!" << std::endl; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
180 return false; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
181 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
182 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
183 return true; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
184 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
185 |