Mercurial > projects > ldc
annotate 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 |
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 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
14 namespace sys = llvm::sys; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
15 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
16 ConfigFile::ConfigFile() |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
17 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
18 cfg = new libconfig::Config; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
19 } |
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 delete cfg; |
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 |
1476
df0ffca8a636
There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents:
1475
diff
changeset
|
26 |
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
|
27 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
|
28 { |
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
|
29 // 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 |
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
|
35 // 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 |
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
|
41 // 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
|
42 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
|
43 #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
|
44 // 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
|
45 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
|
46 #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
|
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 |
1490
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
51 #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
|
52 // 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
|
53 |
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
|
54 // 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 |
1490
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
62 // 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
68 // 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 #endif |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
74 |
cd4478b47b10
Look for configuration file in `/etc` and `/etc/ldc` too (absolute paths)
Frits van Bommel <fvbommel wxs.nl>
parents:
1489
diff
changeset
|
75 // 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 |
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
|
82 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
|
83 } |
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
|
84 |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
85 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
|
86 { |
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
|
87 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
|
88 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
|
89 { |
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
|
90 // 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
|
91 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
|
92 return false; |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
93 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
94 |
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
|
95 // 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
|
96 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
|
97 |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
98 try |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
99 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
100 // read the cfg |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
101 cfg->readFile(p.c_str()); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
102 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
103 // 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
|
104 if (!cfg->exists("default")) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
105 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
106 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
|
107 return false; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
108 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
109 libconfig::Setting& root = cfg->lookup("default"); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
110 if (!root.isGroup()) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
111 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
112 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
|
113 return false; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
114 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
115 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
116 // handle switches |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
117 if (root.exists("switches")) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
118 { |
1340
206329112670
Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents:
1339
diff
changeset
|
119 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
|
120 |
1340
206329112670
Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents:
1339
diff
changeset
|
121 std::string binpath = sys::Path::GetMainExecutable(argv0, mainAddr).getDirname(); |
206329112670
Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents:
1339
diff
changeset
|
122 |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
123 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
|
124 int len = arr.getLength(); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
125 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
|
126 { |
1337
b6e819244062
In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents:
1114
diff
changeset
|
127 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
|
128 |
b6e819244062
In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents:
1114
diff
changeset
|
129 // 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
|
130 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
|
131 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
|
132 v.replace(p, binpathkey.size(), binpath); |
1340
206329112670
Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents:
1339
diff
changeset
|
133 |
1337
b6e819244062
In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents:
1114
diff
changeset
|
134 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
|
135 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
136 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
137 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
138 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
139 catch(libconfig::FileIOException& fioe) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
140 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
141 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
|
142 return false; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
143 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
144 catch(libconfig::ParseException& pe) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
145 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
146 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
|
147 << "(" << pe.getLine() << "): " << pe.getError() << std::endl; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
148 return false; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
149 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
150 catch(...) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
151 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
152 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
|
153 return false; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
154 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
155 |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
156 return true; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
157 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff
changeset
|
158 |