annotate dmd/Util.d @ 14:2cc604139636

Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
author Robert Clipsham <robert@octarineparrot.com>
date Sun, 04 Apr 2010 02:06:32 +0100
parents 7427ded8caf7
children 5c9b78899f5d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Library;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.File;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.String;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.FileName;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.PREC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import std.process : getenv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import std.c.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import std.stdio : writef, writefln, write;
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
16 version (Windows)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
17 {
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
18 import std.c.process : spawnl, spawnlp;
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
19 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import core.stdc.stdlib;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import core.stdc.ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import core.stdc.stdarg;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import core.stdc.stdio;
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
24 version (Bug4054) import core.memory;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 extern(C) int putenv(char*);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 //version = LOG;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
30 version (POSIX)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
31 {
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
32 import dmd.Gnuc;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 enum MAX_PATH = 256; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 version (Windows) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 import core.sys.windows.windows : GetModuleFileNameA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 string fromStringz(const(char)* s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 return s[0..strlen(s)].idup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 void warning(T...)(string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 void warning(T...)(Loc loc, string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 void error(T...)(Loc loc, string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 if (!global.gag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 string p = loc.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 if (p.length != 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 writef("%s: ", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 write("Error: ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 writefln(format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 //halt();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 global.errors++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 char* strupr(char* s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 char* t = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 while (*s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 *s = cast(char)toupper(*s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 s++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 char[] skipspace(char[] p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 foreach (i, c; p) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (!isspace(c)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 return p[i..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 char* skipspace(char* p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 while (isspace(*p))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 return p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 void inifile(string argv0, string inifile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 char *path; // need path for @P macro
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 string filename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 int k;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 int envsection = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 writef("inifile(argv0 = '%s', inifile = '%s')\n", argv0, inifile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 if (FileName.absolute(inifile)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 filename = inifile;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 /* Look for inifile in the following sequence of places:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 * o current directory
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 * o home directory
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 * o directory off of argv0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 * o /etc/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 if (FileName.exists(inifile)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 filename = inifile;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 filename = FileName.combine(getenv("HOME"), inifile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 if (!FileName.exists(filename)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 version (_WIN32) { // This fix by Tim Matthews
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 char resolved_name_b[MAX_PATH + 1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 auto resolved_name = resolved_name_b[].idup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 if (GetModuleFileNameA(null, resolved_name_b.ptr, MAX_PATH + 1) && FileName.exists(resolved_name))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 filename = FileName.replaceName(resolved_name, inifile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 if (FileName.exists(filename)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 goto Ldone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 filename = FileName.replaceName(argv0, inifile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 if (!FileName.exists(filename)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 version (XXX) { /// linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 version (XXX) { /// __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun&&__SVR4 // This fix by Thomas Kuehne
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 /* argv0 might be a symbolic link,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 * so try again looking past it to the real path
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 version (XXX) {/// #if __APPLE__ || __FreeBSD__ || __sun&&__SVR4
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 char resolved_name[PATH_MAX + 1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 char* real_argv0 = realpath(argv0, resolved_name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 char* real_argv0 = realpath(argv0, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 //printf("argv0 = %s, real_argv0 = %p\n", argv0, real_argv0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 if (real_argv0) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 filename = FileName.replaceName(real_argv0, inifile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 version (linux) {
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
158 ///free(real_argv0);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 if (FileName.exists(filename)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 goto Ldone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 static assert (false, "use of glibc non-standard extension realpath(char*, null)");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 if (true) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 // Search PATH for argv0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 const(char)* p = getenv("PATH");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 writef("\tPATH='%s'\n", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 Array paths = FileName.splitPath(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 filename = FileName.searchPath(paths, argv0, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 if (!filename) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 goto Letc; // argv0 not found on path
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 filename = FileName.replaceName(filename, inifile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 if (FileName.exists(filename)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 goto Ldone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 // Search /etc/ for inifile
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 Letc:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 filename = FileName.combine("/etc/", inifile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 Ldone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 path = cast(char*)toStringz(FileName.path(filename));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 writef("\tpath = '%s', filename = '%s'\n", fromStringz(path), filename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 scope File file = new File(filename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 if (file.read()) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 return; // error reading file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 // Parse into lines
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 int eof = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 for (i = 0; i < file.len && !eof; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 int linestart = i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 for (; i < file.len; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 switch (file.buffer[i])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 // Skip if it was preceded by '\r'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 if (i && file.buffer[i - 1] == '\r')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 goto Lskip;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 eof = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 // The line is file.buffer[linestart..i]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 char *line;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 int len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 char *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 char* pn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 line = cast(char*)&file.buffer[linestart];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 len = i - linestart;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 buf.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 // First, expand the macros.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 // Macros are bracketed by % characters.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 for (k = 0; k < len; k++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 if (line[k] == '%')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 int j;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 for (j = k + 1; j < len; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 if (line[j] == '%')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 if (j - k == 3 && memicmp(&line[k + 1], "@P", 2) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 // %@P% is special meaning the path to the .ini file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 p = path;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 if (!*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 p = cast(char*)".";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 int l = j - k;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 char tmp[10]; // big enough most of the time
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 if (l <= tmp.sizeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 p = tmp.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 else
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
279 {
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
280 version (Bug4054)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
281 p = cast(char*)GC.malloc(l);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
282 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 p = cast(char*)alloca(l);
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
284 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 l--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 memcpy(p, &line[k + 1], l);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 p[l] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 strupr(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 p = core.stdc.stdlib.getenv(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 if (!p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 p = cast(char*)"";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 buf.writestring(p[0..strlen(p)]); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 k = j;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 buf.writeByte(line[k]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 // Remove trailing spaces
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 while (buf.offset && isspace(buf.data[buf.offset - 1]))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 buf.offset--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 char[] pp = buf.getString();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 // The expanded line is in p.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 // Now parse it for meaning.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 pp = skipspace(pp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 if (pp.length != 0) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 switch (pp[0])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 case ';': // comment
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 case '[': // look for [Environment]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 pp = skipspace(pp[1..$]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 for (pn = pp.ptr; isalnum(*pn); pn++) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 if (pn - pp.ptr == 11 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 memicmp(pp.ptr, "Environment", 11) == 0 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 *skipspace(pn) == ']'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 envsection = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 envsection = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 if (envsection)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 pn = pp.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 // Convert name to upper case;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 // remove spaces bracketing =
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 auto p2 = pn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 for ( ; *p2; p2++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 { if (islower(*p2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 *p2 &= ~0x20;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 else if (isspace(*p))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 memmove(p2, p2 + 1, strlen(p2));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 else if (*p2 == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 p2++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 while (isspace(*p2))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 memmove(p2, p2 + 1, strlen(p2));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 //putenv(pn);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 putenv(cast(char*)toStringz(pp));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 writef("\tputenv('%s')\n", pn[0..strlen(pn)]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 //printf("getenv(\"TEST\") = '%s'\n",getenv("TEST"));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 Lskip:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 ///int response_expand(int *pargc, char ***pargv);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 void browse(const(char)* url)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 string[] getenv_setargv(string envvar, string[] args)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 char *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 string[] argv = args.dup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 int argc = args.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 int wildcard; // do wildcard expansion
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 int instring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 int slash;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 char c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 int j;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 string ienv = getenv(envvar);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 if (ienv is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 return args;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 char[] env = ienv.dup; // create our own writable copy
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 j = 1; // leave argv[0] alone
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 char* e = env.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 wildcard = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 switch (*e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 case ' ':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 case '\t':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 e++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 goto Ldone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 wildcard = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 argv ~= assumeUnique(e[0..strlen(e)]); // append
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 //argv.insert(j, env); // insert at position j
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 j++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 argc++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 p = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 slash = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 instring = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 c = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 char* ecopy = e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 c = *e++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 p -= (slash >> 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 if (slash & 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 goto Laddc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 instring ^= 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 slash = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 slash++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 *p++ = c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 case ' ':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 case '\t':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 if (instring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 goto Laddc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 *p = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 if (argv.length != 0) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 argv[$-1].length = p - argv[$-1].ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 //if (wildcard)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 //wildcardexpand(); // not implemented
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 if (c == 0) goto Ldone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 Laddc:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 slash = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 *p++ = c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 Ldone:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 return argv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 void error(T...)(string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 writefln(format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 exit(EXIT_FAILURE);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 void usage()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 writef("Digital Mars D Compiler %s\n%s %s\n", global.version_, global.copyright, global.written);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 writef(
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 "Documentation: http://www.digitalmars.com/d/2.0/index.html\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 "Usage:\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 " dmd files.d ... { -switch }\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 "\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 " files.d D source files\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 " @cmdfile read arguments from cmdfile\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 " -c do not link\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 " -cov do code coverage analysis\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 " -D generate documentation\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 " -Dddocdir write documentation file to docdir directory\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 " -Dffilename write documentation file to filename\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 " -d allow deprecated features\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 " -debug compile in debug code\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 " -debug=level compile in debug code <= level\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 " -debug=ident compile in debug code identified by ident\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 " -debuglib=name set symbolic debug library to name\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 " -defaultlib=name set default library to name\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 " -deps=filename write module dependencies to filename\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 " -g add symbolic debug info\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 " -gc add symbolic debug info, pretend to be C\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 " -H generate 'header' file\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 " -Hdhdrdir write 'header' file to hdrdir directory\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 " -Hffilename write 'header' file to filename\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 " --help print help\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 " -Ipath where to look for imports\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 " -ignore ignore unsupported pragmas\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 " -inline do function inlining\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 " -Jpath where to look for string imports\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 " -Llinkerflag pass linkerflag to link\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 " -lib generate library rather than object files\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 " -man open web browser on manual page\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 " -nofloat do not emit reference to floating point\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 " -O optimize\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 " -o- do not write object file\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 " -odobjdir write object & library files to directory objdir\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 " -offilename name output file to filename\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 " -op do not strip paths from source file\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 " -profile profile runtime performance of generated code\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 " -quiet suppress unnecessary messages\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 " -release compile release version\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 " -run srcfile args... run resulting program, passing args\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 " -safe safe memory model\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 " -unittest compile in unit tests\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 " -v verbose\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 " -version=level compile in version code >= level\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 " -version=ident compile in version code identified by ident\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 " -vtls list all variables going into thread local storage\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 " -w enable warnings\n"
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 void fatal()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 halt();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 exit(EXIT_FAILURE);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 void halt()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 void initPrecedence()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 precedence[TOK.TOKdotvar] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 precedence[TOK.TOKimport] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 precedence[TOK.TOKidentifier] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 precedence[TOK.TOKthis] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 precedence[TOK.TOKsuper] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 precedence[TOK.TOKint64] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 precedence[TOK.TOKfloat64] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 precedence[TOK.TOKnull] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 precedence[TOK.TOKstring] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 precedence[TOK.TOKarrayliteral] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 precedence[TOK.TOKtypeid] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 precedence[TOK.TOKis] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 precedence[TOK.TOKassert] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 precedence[TOK.TOKfunction] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 precedence[TOK.TOKvar] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 precedence[TOK.TOKdefault] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 // post
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 precedence[TOK.TOKdotti] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 precedence[TOK.TOKdot] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 // precedence[TOK.TOKarrow] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 precedence[TOK.TOKplusplus] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 precedence[TOK.TOKminusminus] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 precedence[TOK.TOKcall] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 precedence[TOK.TOKslice] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 precedence[TOK.TOKarray] = PREC.PREC_primary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 precedence[TOK.TOKaddress] = PREC.PREC_unary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 precedence[TOK.TOKstar] = PREC.PREC_unary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 precedence[TOK.TOKneg] = PREC.PREC_unary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 precedence[TOK.TOKuadd] = PREC.PREC_unary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 precedence[TOK.TOKnot] = PREC.PREC_unary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 precedence[TOK.TOKtobool] = PREC.PREC_add;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 precedence[TOK.TOKtilde] = PREC.PREC_unary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 precedence[TOK.TOKdelete] = PREC.PREC_unary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 precedence[TOK.TOKnew] = PREC.PREC_unary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 precedence[TOK.TOKcast] = PREC.PREC_unary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 precedence[TOK.TOKmul] = PREC.PREC_mul;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 precedence[TOK.TOKdiv] = PREC.PREC_mul;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 precedence[TOK.TOKmod] = PREC.PREC_mul;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 precedence[TOK.TOKadd] = PREC.PREC_add;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 precedence[TOK.TOKmin] = PREC.PREC_add;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 precedence[TOK.TOKcat] = PREC.PREC_add;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 precedence[TOK.TOKshl] = PREC.PREC_shift;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 precedence[TOK.TOKshr] = PREC.PREC_shift;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 precedence[TOK.TOKushr] = PREC.PREC_shift;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 precedence[TOK.TOKlt] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 precedence[TOK.TOKle] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 precedence[TOK.TOKgt] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 precedence[TOK.TOKge] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 precedence[TOK.TOKunord] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 precedence[TOK.TOKlg] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 precedence[TOK.TOKleg] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 precedence[TOK.TOKule] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 precedence[TOK.TOKul] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 precedence[TOK.TOKuge] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 precedence[TOK.TOKug] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 precedence[TOK.TOKue] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 precedence[TOK.TOKin] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 precedence[TOK.TOKequal] = PREC.PREC_equal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 precedence[TOK.TOKnotequal] = PREC.PREC_equal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 precedence[TOK.TOKidentity] = PREC.PREC_equal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 precedence[TOK.TOKnotidentity] = PREC.PREC_equal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 /* Note that we changed precedence, so that < and != have the same
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 * precedence. This change is in the parser, too.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 precedence[TOK.TOKequal] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 precedence[TOK.TOKnotequal] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 precedence[TOK.TOKidentity] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 precedence[TOK.TOKnotidentity] = PREC.PREC_rel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 precedence[TOK.TOKand] = PREC.PREC_and;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 precedence[TOK.TOKxor] = PREC.PREC_xor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 precedence[TOK.TOKor] = PREC.PREC_or;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 precedence[TOK.TOKandand] = PREC.PREC_andand;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 precedence[TOK.TOKoror] = PREC.PREC_oror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 precedence[TOK.TOKquestion] = PREC.PREC_cond;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 precedence[TOK.TOKassign] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 precedence[TOK.TOKconstruct] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 precedence[TOK.TOKblit] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 precedence[TOK.TOKaddass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 precedence[TOK.TOKminass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 precedence[TOK.TOKcatass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 precedence[TOK.TOKmulass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 precedence[TOK.TOKdivass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 precedence[TOK.TOKmodass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 precedence[TOK.TOKshlass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 precedence[TOK.TOKshrass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 precedence[TOK.TOKushrass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 precedence[TOK.TOKandass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 precedence[TOK.TOKorass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 precedence[TOK.TOKxorass] = PREC.PREC_assign;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 precedence[TOK.TOKcomma] = PREC.PREC_expr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 int runLINK()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 string p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 int status;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 scope OutBuffer cmdbuf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 global.params.libfiles.push(cast(void*)new String("user32"));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 global.params.libfiles.push(cast(void*)new String("kernel32"));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 for (i = 0; i < global.params.objfiles.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 if (i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 cmdbuf.writeByte('+');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 p = (cast(String)global.params.objfiles.data[i]).str;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 string ext = FileName.ext(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 if (ext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 // Write name sans extension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 writeFilename(cmdbuf, p[0..p.length - ext.length - 1]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 writeFilename(cmdbuf, p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 cmdbuf.writeByte(',');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 if (global.params.exefile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 writeFilename(cmdbuf, global.params.exefile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 /* Generate exe file name from first obj name.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 * No need to add it to cmdbuf because the linker will default to it.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 string n = (cast(String)global.params.objfiles.data[0]).str;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 n = FileName.name(n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 FileName fn = FileName.forceExt(n, "exe");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 global.params.exefile = fn.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 // Make sure path to exe file exists
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 string pp = FileName.path(global.params.exefile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 FileName.ensurePathExists(pp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 cmdbuf.writeByte(',');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 if (global.params.run)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 cmdbuf.writestring("nul");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 // if (mapfile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 // cmdbuf.writestring(output);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 cmdbuf.writeByte(',');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 for (i = 0; i < global.params.libfiles.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 if (i)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 cmdbuf.writeByte('+');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 writeFilename(cmdbuf, (cast(String)global.params.libfiles.data[i]).str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 if (global.params.deffile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 cmdbuf.writeByte(',');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 writeFilename(cmdbuf, global.params.deffile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 /* Eliminate unnecessary trailing commas */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 i = cmdbuf.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 if (!i || cmdbuf.data[i - 1] != ',')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 cmdbuf.offset--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 if (global.params.resfile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 cmdbuf.writestring("/RC:");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 writeFilename(cmdbuf, global.params.resfile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 if (mapfile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 cmdbuf.writestring("/m");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 if (debuginfo)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 cmdbuf.writestring("/li");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 if (codeview)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 cmdbuf.writestring("/co");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 if (codeview3)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 cmdbuf.writestring(":3");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 if (global.params.symdebug)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 cmdbuf.writestring("/co");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 cmdbuf.writestring("/noi");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 for (i = 0; i < global.params.linkswitches.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 cmdbuf.writestring((cast(String)global.params.linkswitches.data[i]).str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 cmdbuf.writeByte(';');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 p = cmdbuf.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 FileName lnkfilename = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 size_t plen = p.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 if (plen > 7000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 lnkfilename = FileName.forceExt(global.params.exefile, "lnk");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 scope File flnk = new File(lnkfilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 flnk.setbuffer(cast(void*)p.ptr, plen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 flnk.ref_ = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 if (flnk.write())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 error("error writing file %s", lnkfilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 if (lnkfilename.len() < plen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 p = std.string.format("@%s", lnkfilename.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 string linkcmd = getenv("LINKCMD");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 if (!linkcmd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 linkcmd = "link";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 status = executecmd(linkcmd, p, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 if (lnkfilename)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 remove(toStringz(lnkfilename.toChars()));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 ///delete lnkfilename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 return status;
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
796 } else version (POSIX) {/// linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
797 assert(false, "Unimplemented");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 /+
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 pid_t childpid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 int status;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 // Build argv[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 Array argv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 const char *cc = getenv("CC");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 if (!cc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 cc = "gcc";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 argv.push((void *)cc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 argv.insert(1, global.params.objfiles);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 // None of that a.out stuff. Use explicit exe file name, or
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 // generate one from name of first source file.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 argv.push((void *)"-o");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 if (global.params.exefile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 argv.push(global.params.exefile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 { // Generate exe file name from first obj name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 char *n = (char *)global.params.objfiles.data[0];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 char *e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 char *ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 n = FileName.name(n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 e = FileName.ext(n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 if (e)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 e--; // back up over '.'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 ex = (char *)mem.malloc(e - n + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 memcpy(ex, n, e - n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 ex[e - n] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 ex = (char *)"a.out"; // no extension, so give up
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 argv.push(ex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 global.params.exefile = ex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 // Make sure path to exe file exists
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 { char *p = FileName.path(global.params.exefile);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 FileName.ensurePathExists(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 mem.free(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 if (global.params.symdebug)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 argv.push((void *)"-g");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 if (global.params.isX86_64)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 argv.push((void *)"-m64");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 argv.push((void *)"-m32");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 if (0 && global.params.exefile)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 /* This switch enables what is known as 'smart linking'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 * in the Windows world, where unreferenced sections
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 * are removed from the executable. It eliminates unreferenced
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 * functions, essentially making a 'library' out of a module.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 * Although it is documented to work with ld version 2.13,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 * in practice it does not, but just seems to be ignored.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 * Thomas Kuehne has verified that it works with ld 2.16.1.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 * BUG: disabled because it causes exception handling to fail
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 argv.push((void *)"-Xlinker");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 argv.push((void *)"--gc-sections");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 for (i = 0; i < global.params.linkswitches.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 { char *p = (char *)global.params.linkswitches.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 if (!p || !p[0] || !(p[0] == '-' && p[1] == 'l'))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 // Don't need -Xlinker if switch starts with -l
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 argv.push((void *)"-Xlinker");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 argv.push((void *) p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 /* Add each library, prefixing it with "-l".
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 * The order of libraries passed is:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 * 1. any libraries passed with -L command line switch
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 * 2. libraries specified on the command line
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 * 3. libraries specified by pragma(lib), which were appended
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 * to global.params.libfiles.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 * 4. standard libraries.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 for (i = 0; i < global.params.libfiles.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 { char *p = (char *)global.params.libfiles.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 size_t plen = strlen(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 if (plen > 2 && p[plen - 2] == '.' && p[plen -1] == 'a')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 argv.push((void *)p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 char *s = (char *)mem.malloc(plen + 3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 s[0] = '-';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 s[1] = 'l';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 memcpy(s + 2, p, plen + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 argv.push((void *)s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 /* Standard libraries must go after user specified libraries
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 * passed with -l.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 const char *libname = (global.params.symdebug)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 ? global.params.debuglibname
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 : global.params.defaultlibname;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 char *buf = (char *)malloc(2 + strlen(libname) + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 strcpy(buf, "-l");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 strcpy(buf + 2, libname);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 argv.push((void *)buf); // turns into /usr/lib/libphobos2.a
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 // argv.push((void *)"-ldruntime");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 argv.push((void *)"-lpthread");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 argv.push((void *)"-lm");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 if (!global.params.quiet || global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 // Print it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 for (i = 0; i < argv.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 printf("%s ", (char *)argv.data[i]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 fflush(stdout);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 argv.push(null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 childpid = fork();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 if (childpid == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 execvp((char *)argv.data[0], (char **)argv.data);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 perror((char *)argv.data[0]); // failed to execute
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 return -1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 waitpid(childpid, &status, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 status=WEXITSTATUS(status);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 if (status)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 printf("--- errorlevel %d\n", status);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 return status;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 +/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 writef ("Linking is not yet supported for this version of DMD.\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 return -1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 int runProgram()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 void deleteExeFile()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 * Write filename to cmdbuf, quoting if necessary.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 void writeFilename(OutBuffer buf, string filename)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 auto len = filename.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 /* Loop and see if we need to quote
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 for (size_t i = 0; i < len; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 char c = filename[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 if (isalnum(c) || c == '_')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 /* Need to quote
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 buf.writeByte('"');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 buf.writestring(filename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 buf.writeByte('"');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 /* No quoting necessary
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 buf.writestring(filename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 /******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 * Execute a rule. Return the status.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 * cmd program to run
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 * args arguments to cmd, as a string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 * useenv if cmd knows about _CMDLINE environment variable
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 int executecmd(string cmd, string args, int useenv)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 int status;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 size_t len = args.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 if (!global.params.quiet || global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 printf("%s %s\n", cmd, args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 fflush(stdout);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 if (len > 255)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 char* q;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 static char[9] envname = "@_CMDLINE";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 envname[0] = '@';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 switch (useenv)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 case 0: goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 case 2: envname[0] = '%'; break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 default: break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 }
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
1016 version (Bug4054)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
1017 q = cast(char*) GC.malloc(envname.sizeof + len + 1);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
1018 else
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 q = cast(char*) alloca(envname.sizeof + len + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 sprintf(q, "%s=%s", envname.ptr + 1, args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 status = putenv(q);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 if (status == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 args = envname[].idup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 error("command line length of %d is too long",len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 status = executearg0(cmd, args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 if (status == -1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 auto cmdZ = toStringz(cmd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 auto argsZ = toStringz(args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 status = spawnlp(0, cmdZ, cmdZ, argsZ, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 // if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 // printf("\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 if (status)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 if (status == -1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 printf("Can't run '%s', check PATH\n", cmd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 printf("--- errorlevel %d\n", status);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 return status;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 * Attempt to find command to execute by first looking in the directory
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 * where DMD was run from.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 * -1 did not find command there
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 * !=-1 exit status from command
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 int executearg0(string cmd, string args)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 string file;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 string argv0 = global.params.argv0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 //printf("argv0='%s', cmd='%s', args='%s'\n",argv0,cmd,args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 // If cmd is fully qualified, we don't do this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 if (FileName.absolute(cmd))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 return -1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072 file = FileName.replaceName(argv0, cmd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 //printf("spawning '%s'\n",file);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 auto fileZ = toStringz(file);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 auto argsZ = toStringz(args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 return spawnl(0, fileZ, fileZ, argsZ, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 } else version (XXX) { ///#elif linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 /+
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 char *full;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 int cmdl = strlen(cmd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 full = (char*) mem.malloc(cmdl + strlen(args) + 2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 if (full == null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 strcpy(full, cmd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 full [cmdl] = ' ';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 strcpy(full + cmdl + 1, args);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 int result = system(full);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 mem.free(full);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 +/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 static assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 }
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 2
diff changeset
1101 }