annotate dmd/FileName.d @ 175:94b6033c07f3

get rid of globals malloc -> GC.malloc
author korDen
date Sun, 10 Oct 2010 03:48:06 +0400
parents af724d3510d7
children e3afd1303184
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.FileName;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.String;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.File;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
9 import core.memory;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
10
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
11 import core.stdc.stdlib : malloc, alloca;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import core.stdc.string : memcpy, strlen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import core.stdc.ctype : isspace;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14
34
544b922227c7 update to work with dmd 2.048
korDen
parents: 16
diff changeset
15 import std.exception : assumeUnique;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import std.string : cmp, icmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import std.file : mkdirRecurse;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
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: 5
diff changeset
19 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: 5
diff changeset
20 {
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: 5
diff changeset
21 import core.sys.windows.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: 5
diff changeset
22 }
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: 5
diff changeset
23
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: 5
diff changeset
24 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: 5
diff changeset
25 {
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: 5
diff changeset
26 import core.stdc.stdlib;
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: 5
diff changeset
27 import core.sys.posix.sys.stat;
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: 5
diff changeset
28 import std.conv;
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: 5
diff changeset
29 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 class FileName : String
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 this(string str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 super(str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 this(string path, string name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 super(combine(path, name));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 45
diff changeset
43 override hash_t hashCode()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
45 version (Windows)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
46 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 // We need a different hashCode because it must be case-insensitive
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 size_t len = str.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 hash_t hash = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 ubyte* s = cast(ubyte*)str.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 for (;;)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 switch (len)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 return hash;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 case 1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 hash *= 37;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 hash += *(cast(ubyte*)s) | 0x20;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 return hash;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 case 2:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 hash *= 37;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 hash += *(cast(ushort*)s) | 0x2020;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 return hash;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 case 3:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 hash *= 37;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 hash += (*cast(ushort*)s) << 8 +
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 ((cast(ubyte*)s)[2]) | 0x202020;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 hash *= 37;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 hash += (*cast(int*)s) | 0x20202020;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 s += 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 len -= 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 // darwin HFS is case insensitive, though...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 return super.hashCode();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 45
diff changeset
89 override bool opEquals(Object obj)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 return opCmp(obj) == 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
45
ccbc1e0bb3f0 StringExp.equals implemented
korDen
parents: 34
diff changeset
94 static bool equals(string name1, string name2)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 return compare(name1, name2) == 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 45
diff changeset
99 override int opCmp(Object obj)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 return compare(str, (cast(FileName)obj).str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 static int compare(string name1, string name2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 version (_WIN32) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 return icmp(name1, name2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 return cmp(name1, name2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
81
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
113 static pure bool absolute(const(char)[] name)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 {
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
115 version (Windows)
81
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
116 {
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
117 return (name[0] == '\\') ||
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
118 (name[0] == '/') ||
102
3ddadd0c4534 wrong name.length check fixed (greetings to Trass3r!)
korDen
parents: 101
diff changeset
119 ((name.length > 1) && (name[1] == ':'));
81
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
120 }
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
121 else version (POSIX)
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
122 {
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
123 return (name[0] == '/');
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
124 }
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
125 else
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
126 {
722df8e7509c * fixed win32_lib
Trass3r
parents: 72
diff changeset
127 static assert(false);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 /********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 * Return filename extension (read-only).
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 * Points past '.' of extension.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 * If there isn't one, return NULL.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 static string ext(string str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 foreach_reverse (i, c; str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 case '.':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 return str[i+1..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 }
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
148 version (Windows)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
149 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 case ':':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 } default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
159
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 string ext()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 return ext(str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
167
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 /********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 * Return filename with extension removed.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 static string removeExt(string str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 string e = ext(str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 if (e !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 size_t len = (e.ptr - str.ptr - 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 return str[0..len];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 return str;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
183
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 /********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 * Return filename name excluding path (read-only).
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 static string name(string str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 foreach_reverse(i, c; str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 {
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
194 version (Posix)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
195 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 return str[i+1..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 }
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
199 version (Windows)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
200 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 return str[i+1..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 case ':':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 /* The ':' is a drive letter only if it is the second
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 * character or the last character,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 * otherwise it is an ADS (Alternate Data Stream) separator.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 * Consider ADS separators as part of the file name.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 if (i == 1 || i == str.length - 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 return str[i+1..$];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 return str;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 string name()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 return name(str);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
225
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 * Return path portion of str.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 * Path will does not include trailing path separator.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 static string path(string str)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 auto n = name(str).ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 if (n > str.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 auto p = n - 1;
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
238 version (Posix)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
239 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 if (*p == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 n--;
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
242 } else version (Windows)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
243 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 if (*p == '\\' || *p == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 n--;
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
246 } else
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
247 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 static assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 size_t pathlen = n - str.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 return str[0..pathlen];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
255
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 * Replace filename portion of path.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 */
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
259
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 static string replaceName(string path, string name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 if (absolute(name))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 return name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 string n = FileName.name(path);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 if (n is path)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 return name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 size_t pathlen = n.ptr - path.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 size_t namelen = name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
272 char* f = cast(char*)GC.malloc(pathlen + 1 + namelen + 1);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 memcpy(f, path.ptr, pathlen);
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
274 version (Posix)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
275 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 if (path[pathlen - 1] != '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 f[pathlen] = '/';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 pathlen++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 }
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
281 }
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
282 else version (Windows)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
283 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 if (path[pathlen - 1] != '\\' &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 path[pathlen - 1] != '/' &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 path[pathlen - 1] != ':')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 f[pathlen] = '\\';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 pathlen++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 }
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
291 }
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
292 else
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
293 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 static assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 memcpy(f + pathlen, name.ptr, namelen + 1);
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
297
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 return assumeUnique(f[0..pathlen+namelen]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 static string combine(string path, string name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 size_t pathlen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 size_t namelen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 if (path.length == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 return name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 pathlen = path.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 namelen = name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
312 char* f = cast(char*)GC.malloc(pathlen + 1 + namelen + 1);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 memcpy(f, path.ptr, pathlen);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
316 version (Posix) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 if (path[pathlen - 1] != '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 f[pathlen] = '/';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 pathlen++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 }
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
322 }
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
323 else version (Windows)
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
324 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
325 if (path[pathlen - 1] != '\\' &&
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 path[pathlen - 1] != '/' &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 path[pathlen - 1] != ':')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 f[pathlen] = '\\';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 pathlen++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 }
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
332 }
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
333 else
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
334 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 static assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 memcpy(f + pathlen, name.ptr, namelen + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 return assumeUnique(f[0..pathlen+namelen]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
341
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 static string[] splitPath(const(char)[] spath)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 char c = 0; // unnecessary initializer is for VC /W4
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 scope OutBuffer buf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 string[] array;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
348
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 if (spath !is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 const(char)* p = spath.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 int len = spath.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 char instring = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 while (len > 0 && isspace(*p)) { // skip leading whitespace
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 --len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
361
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 buf.reserve(len + 1); // guess size of path
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 for (; len; p++, len--)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 instring ^= 1; // toggle inside/outside of string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 version (MACINTOSH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 case ',':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 }
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
375 version (Windows) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 case ';':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 }
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
378 version (Posix) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 case ':':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 break; // note that ; cannot appear as part
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 // of a path, quotes won't protect it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 case 0x1A: // ^Z means end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 //case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 continue; // ignore carriage returns
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 case '~':
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: 5
diff changeset
394 buf.writestring(to!string(getenv("HOME")));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 version (disabled) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 case ' ':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 case '\t': // tabs in filenames?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 if (!instring) // if not in string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 break; // treat as end of path
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 buf.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 if (buf.offset) // if path is not empty
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 //buf.writeByte(0); // to asciiz
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 array ~= buf.extractString();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 } while (len > 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
417
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 return array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
420
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 static FileName defaultExt(string name, string ext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 string e = FileName.ext(name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 if (e !is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 // if already has an extension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 return new FileName(name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 size_t len = name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 size_t extlen = ext.length;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
431 char* s = cast(char*)GC.malloc(len + 1 + extlen + 1);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 memcpy(s, name.ptr, len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 s[len] = '.';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 memcpy(s + len + 1, ext.ptr, extlen + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 return new FileName(assumeUnique(s[0..len+1+extlen]));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 static FileName forceExt(string name, string ext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 string e = FileName.ext(name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 if (e !is null) // if already has an extension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 size_t len = e.ptr - name.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 size_t extlen = ext.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446
175
94b6033c07f3 get rid of globals
korDen
parents: 174
diff changeset
447 char* s = cast(char*)GC.malloc(len + extlen + 1); /// !
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 memcpy(s, name.ptr, len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 memcpy(s + len, ext.ptr, extlen + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 return new FileName(assumeUnique(s[0..len+extlen]));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 return defaultExt(name, ext); // doesn't have one
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
455
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 /******************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 * Return true if extensions match.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 */
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
459
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 bool equalsExt(string ext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 string e = FileName.ext();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 if (e.length == 0 && ext.length == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 if (e.length == 0 || ext.length == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 version (POSIX) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 return cmp(e,ext) == 0;
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
471 } else version (Windows) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 return icmp(e,ext) == 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 static assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
477
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 * Copy file from this to to.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 void CopyTo(FileName to)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 scope File file = new File(this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
486 version (Win32) {
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
487 file.touchtime = GC.malloc(WIN32_FIND_DATA.sizeof); // keep same file time
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
488 } else version (Posix) {
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: 5
diff changeset
489 file.touchtime = GC.malloc(stat_t.sizeof); // keep same file time
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 static assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 file.readv();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 file.name = to;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 file.writev();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
497
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 /*************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 * Search Path for file.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 * Input:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 * cwd if true, search current directory before searching path
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 static string searchPath(Array path, string name, bool cwd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 if (absolute(name)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 return exists(name) ? name : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
509
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 if (cwd) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 if (exists(name)) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 return name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
515
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 if (path !is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 foreach (i; 0..path.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 String p = cast(String)path.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 string n = combine(p.str, name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 if (exists(n))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 return n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
526
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 }
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
529
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
530 static string searchPath(string[] path, string name, bool cwd)
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
531 {
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
532 if (absolute(name)) {
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
533 return exists(name) ? name : null;
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
534 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
535
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
536 if (cwd) {
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
537 if (exists(name)) {
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
538 return name;
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
539 }
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
540 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
541
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
542 if (path !is null) {
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
543 foreach (i, p; path)
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
544 {
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
545 string n = combine(p, name);
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
546
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
547 if (exists(n))
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
548 return n;
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
549 }
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
550 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
551
16
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
552 return null;
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
553 }
5c9b78899f5d Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents: 14
diff changeset
554
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 static int exists(string name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 {
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
557 version (Posix) {
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: 5
diff changeset
558 stat_t st;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559
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: 5
diff changeset
560 if (stat(toStringz(name), &st) < 0)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 if (S_ISDIR(st.st_mode))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 return 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 return 1;
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 102
diff changeset
565 } else version (Win32) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 HANDLE h = CreateFileA(toStringz(name), GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, HANDLE.init); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 if (h == INVALID_HANDLE_VALUE) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
570
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 CloseHandle(h);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 DWORD dw = GetFileAttributesA(name.ptr); /// CARE!
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 if (dw == -1L) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 } else if (dw & FILE_ATTRIBUTE_DIRECTORY) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 return 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 static assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 136
diff changeset
586
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 static void ensurePathExists(string path)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 {
136
9d194c848e3a fixed a few null reference bugs, thx sagitario
Trass3r
parents: 114
diff changeset
589 if (path.length == 0)
9d194c848e3a fixed a few null reference bugs, thx sagitario
Trass3r
parents: 114
diff changeset
590 return;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 try {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 mkdirRecurse(path);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 } catch {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 }
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: 5
diff changeset
596 }