annotate dmd/Util.d @ 192:eb38fdcb3e62 default tip

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