annotate gen/configfile.cpp @ 1489:a048f31bf9f6

Move locating the configuration file into a separate function. Also look in PREFIX/etc/ldc. Fixes #322.
author Christian Kamm <kamm incasoftware de>
date Mon, 08 Jun 2009 19:48:20 +0200
parents 7d3b47852a7a
children cd4478b47b10
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
67 // 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
68 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
69 #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
70 // 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
71 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
72 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
73 #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
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
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 // 5) try next to the executable
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 _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
80 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
81 #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
82 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
83 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
84 #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
85 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
86 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
87 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
88
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 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
90 }
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
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
92 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
93 {
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
94 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
95 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
96 {
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 // 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
98 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
99 return false;
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
100 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
101
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
102 // 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
103 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
104
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
105 try
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
106 {
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
107 // read the cfg
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
108 cfg->readFile(p.c_str());
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
109
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
110 // 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
111 if (!cfg->exists("default"))
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
112 {
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
113 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
114 return false;
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 libconfig::Setting& root = cfg->lookup("default");
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
117 if (!root.isGroup())
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
118 {
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
119 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
120 return false;
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
121 }
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 // handle switches
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
124 if (root.exists("switches"))
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
125 {
1340
206329112670 Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents: 1339
diff changeset
126 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
127
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
128 #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
129 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
130 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
131 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
132 #else
1340
206329112670 Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents: 1339
diff changeset
133 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
134 #endif
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
135
1340
206329112670 Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents: 1339
diff changeset
136
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
137 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
138 int len = arr.getLength();
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
139 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
140 {
1337
b6e819244062 In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents: 1114
diff changeset
141 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
142
b6e819244062 In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents: 1114
diff changeset
143 // 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
144 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
145 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
146 v.replace(p, binpathkey.size(), binpath);
1340
206329112670 Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents: 1339
diff changeset
147
1337
b6e819244062 In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents: 1114
diff changeset
148 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
149 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
150 }
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 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
153 catch(libconfig::FileIOException& fioe)
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 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
156 return false;
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 catch(libconfig::ParseException& pe)
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
159 {
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
160 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
161 << "(" << pe.getLine() << "): " << pe.getError() << std::endl;
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
162 return false;
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 catch(...)
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 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
167 return false;
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
168 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
169
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
170 return true;
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
171 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
172