annotate gen/configfile.cpp @ 1484:7d3b47852a7a

Print the path to the configuration file being used if `-v` is passed.
author Frits van Bommel <fvbommel wxs.nl>
date Sun, 07 Jun 2009 17:20:55 +0200
parents 6023f65a3aee
children a048f31bf9f6
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
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
43 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
44 {
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
45
1476
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
46 #if _WIN32
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
47 std::string exeDirectoryName;
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
48 #endif
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
49 // try to find the config file
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
50
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
51 // 1) try the current working dir
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
52 sys::Path p = sys::Path::GetCurrentDirectory();
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
53 p.appendComponent(filename);
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
54
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
55 if (!p.exists())
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
56 {
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
57 // 2) try the user home dir
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
58 p = sys::Path::GetUserHomeDirectory();
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
59 p.appendComponent(filename);
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
60
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
61 if (!p.exists())
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
62 {
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
63 // 3) try the install-prefix/etc
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
64 p = sys::Path(LDC_INSTALL_PREFIX);
1114
454f0c8acc4b Hopefully fix #232
Frits van Bommel <fvbommel wxs.nl>
parents: 1103
diff changeset
65 #if !_WIN32
454f0c8acc4b Hopefully fix #232
Frits van Bommel <fvbommel wxs.nl>
parents: 1103
diff changeset
66 // Does Window need something similar?
454f0c8acc4b Hopefully fix #232
Frits van Bommel <fvbommel wxs.nl>
parents: 1103
diff changeset
67 p.appendComponent("etc");
454f0c8acc4b Hopefully fix #232
Frits van Bommel <fvbommel wxs.nl>
parents: 1103
diff changeset
68 #endif
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
69 p.appendComponent(filename);
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
70
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
71 if (!p.exists())
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
72 {
1473
8309ebaa23d5 Fix for finding ldc.conf file with mingw
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1340
diff changeset
73 #if _WIN32
1477
6023f65a3aee Fix indentation, removing tabs.
Frits van Bommel <fvbommel wxs.nl>
parents: 1476
diff changeset
74 p = ConfigGetExePath(p);
6023f65a3aee Fix indentation, removing tabs.
Frits van Bommel <fvbommel wxs.nl>
parents: 1476
diff changeset
75 exeDirectoryName = p.toString();
6023f65a3aee Fix indentation, removing tabs.
Frits van Bommel <fvbommel wxs.nl>
parents: 1476
diff changeset
76 #else
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
77 // 4) try next to the executable
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
78 p = sys::Path::GetMainExecutable(argv0, mainAddr);
1476
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
79 p.eraseComponent();
1473
8309ebaa23d5 Fix for finding ldc.conf file with mingw
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1340
diff changeset
80 #endif
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
81 p.appendComponent(filename);
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
82 if (!p.exists())
1473
8309ebaa23d5 Fix for finding ldc.conf file with mingw
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1340
diff changeset
83 {
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
84 // 5) fail load cfg, users still have the DFLAGS environment var
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
85 std::cerr << "Error failed to locate the configuration file: " << filename << std::endl;
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
86 return false;
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
87 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
88 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
89 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
90 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
91
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
92 // 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
93 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
94
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
95 try
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
96 {
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
97 // read the cfg
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
98 cfg->readFile(p.c_str());
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 // 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
101 if (!cfg->exists("default"))
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 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
104 return false;
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 libconfig::Setting& root = cfg->lookup("default");
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
107 if (!root.isGroup())
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 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
110 return false;
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
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
113 // handle switches
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
114 if (root.exists("switches"))
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
115 {
1340
206329112670 Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents: 1339
diff changeset
116 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
117
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
118 #if _WIN32
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
119 std::string binpath;
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
120 //This will happen if ldc.conf is found somewhere other than
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
121 //beside the ldc executable
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
122 if (exeDirectoryName == "")
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
123 {
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
124 sys::Path p;
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
125 p = ConfigGetExePath(p);
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
126 exeDirectoryName = p.toString();
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 binpath = exeDirectoryName;
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
129 #else
1340
206329112670 Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents: 1339
diff changeset
130 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
131 #endif
df0ffca8a636 There was another fix needed here for reading %%ldcbinarypath%%
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1475
diff changeset
132
1340
206329112670 Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents: 1339
diff changeset
133
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
134 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
135 int len = arr.getLength();
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
136 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
137 {
1337
b6e819244062 In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents: 1114
diff changeset
138 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
139
b6e819244062 In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents: 1114
diff changeset
140 // 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
141 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
142 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
143 v.replace(p, binpathkey.size(), binpath);
1340
206329112670 Fix the ldcbinarypath config file rewriting.
Christian Kamm <kamm incasoftware de>
parents: 1339
diff changeset
144
1337
b6e819244062 In config file: replace %%ldcbinarypath%% with the path to the ldc executable.
Christian Kamm <kamm incasoftware de>
parents: 1114
diff changeset
145 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
146 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
147 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
148
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(libconfig::FileIOException& fioe)
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 << "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
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 catch(libconfig::ParseException& pe)
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
156 {
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
157 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
158 << "(" << pe.getLine() << "): " << pe.getError() << std::endl;
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
159 return false;
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
160 }
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
161 catch(...)
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 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
164 return false;
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
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
diff changeset
167 return true;
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