1 /* Generated by Nim Compiler v1.6.2 */
2 #define NIM_INTBITS 32
3
4 #include "nimbase.h"
5 #include <string.h>
6 #undef LANGUAGE_C
7 #undef MIPSEB
8 #undef MIPSEL
9 #undef PPC
10 #undef R3000
11 #undef R4000
12 #undef i386
13 #undef linux
14 #undef mips
15 #undef near
16 #undef far
17 #undef powerpc
18 #undef unix
19 #define nimfr_(x, y)
20 #define nimln_(x, y)
21 typedef struct NimStringDesc NimStringDesc;
22 typedef struct TGenericSeq TGenericSeq;
23 typedef struct tyObject_PathIter__tllF14xUpDWpqG9ci5sg9bMg tyObject_PathIter__tllF14xUpDWpqG9ci5sg9bMg;
24 typedef struct tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ;
25 struct TGenericSeq {
26 NI len;
27 NI reserved;
28 };
29 struct NimStringDesc {
30 TGenericSeq Sup;
31 NIM_CHAR data[SEQ_DECL_SIZE];
32 };
33 struct tyObject_PathIter__tllF14xUpDWpqG9ci5sg9bMg {
34 NI i;
35 NI prev;
36 NIM_BOOL notFirst;
37 };
38 struct tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ {
39 NI Field0;
40 NI Field1;
41 };
42 static N_INLINE(void, nimZeroMem)(void* p, NI size);
43 static N_INLINE(void, nimSetMem__systemZmemory_7)(void* a, int v, NI size);
44 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, hasNext__pureZpathnorm_6)(tyObject_PathIter__tllF14xUpDWpqG9ci5sg9bMg it, NimStringDesc* x);
45 N_LIB_PRIVATE N_NIMCALL(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, next__pureZpathnorm_10)(tyObject_PathIter__tllF14xUpDWpqG9ci5sg9bMg* it, NimStringDesc* x);
46 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isSlash__pureZpathnorm_63)(NimStringDesc* x, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds);
47 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, addChar)(NimStringDesc* s, NIM_CHAR c);
48 N_LIB_PRIVATE N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
49 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isDotDot__pureZpathnorm_59)(NimStringDesc* x, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds);
50 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, setLengthStr)(NimStringDesc* s, NI newLen);
51 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, substr__system_7743)(NimStringDesc* s, NI first, NI last);
52 static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
53 static N_INLINE(void, copyMem__system_1727)(void* dest, void* source, NI size);
54 static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size);
55 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, resizeString)(NimStringDesc* dest, NI addlen);
56 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isDot__pureZpathnorm_55)(NimStringDesc* x, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds);
57 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
58 N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
59 N_LIB_PRIVATE N_NIMCALL(void, addNormalizePath__pureZpathnorm_71)(NimStringDesc* x, NimStringDesc** result, NI* state, NIM_CHAR dirSep);
60 STRING_LITERAL(TM__DfU0iuayCGwHDN1Exp9cbKg_2, ".", 1);
N_INLINE(void,nimSetMem__systemZmemory_7)61 static N_INLINE(void, nimSetMem__systemZmemory_7)(void* a, int v, NI size) {
62 void* T1_;
63 T1_ = (void*)0;
64 T1_ = memset(a, v, ((size_t) (size)));
65 }
N_INLINE(void,nimZeroMem)66 static N_INLINE(void, nimZeroMem)(void* p, NI size) {
67 nimSetMem__systemZmemory_7(p, ((int) 0), size);
68 }
N_NIMCALL(NIM_BOOL,hasNext__pureZpathnorm_6)69 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, hasNext__pureZpathnorm_6)(tyObject_PathIter__tllF14xUpDWpqG9ci5sg9bMg it, NimStringDesc* x) {
70 NIM_BOOL result;
71 result = (NIM_BOOL)0;
72 result = (it.i < (x ? x->Sup.len : 0));
73 return result;
74 }
N_NIMCALL(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ,next__pureZpathnorm_10)75 N_LIB_PRIVATE N_NIMCALL(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, next__pureZpathnorm_10)(tyObject_PathIter__tllF14xUpDWpqG9ci5sg9bMg* it, NimStringDesc* x) {
76 tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ result;
77 nimZeroMem((void*)(&result), sizeof(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ));
78 (*it).prev = (*it).i;
79 {
80 NIM_BOOL T3_;
81 T3_ = (NIM_BOOL)0;
82 T3_ = !((*it).notFirst);
83 if (!(T3_)) goto LA4_;
84 T3_ = (((NU8)(x->data[(*it).i])) == ((NU8)(47)) || ((NU8)(x->data[(*it).i])) == ((NU8)(47)));
85 LA4_: ;
86 if (!T3_) goto LA5_;
87 (*it).i += ((NI) 1);
88 }
89 goto LA1_;
90 LA5_: ;
91 {
92 {
93 while (1) {
94 NIM_BOOL T10_;
95 T10_ = (NIM_BOOL)0;
96 T10_ = ((*it).i < (x ? x->Sup.len : 0));
97 if (!(T10_)) goto LA11_;
98 T10_ = !((((NU8)(x->data[(*it).i])) == ((NU8)(47)) || ((NU8)(x->data[(*it).i])) == ((NU8)(47))));
99 LA11_: ;
100 if (!T10_) goto LA9;
101 (*it).i += ((NI) 1);
102 } LA9: ;
103 }
104 }
105 LA1_: ;
106 {
107 NI colontmp_;
108 NI colontmp__2;
109 if (!((*it).prev < (*it).i)) goto LA14_;
110 colontmp_ = (*it).prev;
111 colontmp__2 = (NI)((*it).i - ((NI) 1));
112 result.Field0 = colontmp_;
113 result.Field1 = colontmp__2;
114 }
115 goto LA12_;
116 LA14_: ;
117 {
118 NIM_BOOL T17_;
119 T17_ = (NIM_BOOL)0;
120 T17_ = hasNext__pureZpathnorm_6((*it), x);
121 if (!T17_) goto LA18_;
122 result = next__pureZpathnorm_10(it, x);
123 }
124 goto LA12_;
125 LA18_: ;
126 LA12_: ;
127 {
128 while (1) {
129 NIM_BOOL T22_;
130 T22_ = (NIM_BOOL)0;
131 T22_ = ((*it).i < (x ? x->Sup.len : 0));
132 if (!(T22_)) goto LA23_;
133 T22_ = (((NU8)(x->data[(*it).i])) == ((NU8)(47)) || ((NU8)(x->data[(*it).i])) == ((NU8)(47)));
134 LA23_: ;
135 if (!T22_) goto LA21;
136 (*it).i += ((NI) 1);
137 } LA21: ;
138 }
139 (*it).notFirst = NIM_TRUE;
140 return result;
141 }
N_NIMCALL(NIM_BOOL,isSlash__pureZpathnorm_63)142 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isSlash__pureZpathnorm_63)(NimStringDesc* x, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds) {
143 NIM_BOOL result;
144 NIM_BOOL T1_;
145 result = (NIM_BOOL)0;
146 T1_ = (NIM_BOOL)0;
147 T1_ = (bounds.Field1 == bounds.Field0);
148 if (!(T1_)) goto LA2_;
149 T1_ = (((NU8)(x->data[bounds.Field0])) == ((NU8)(47)) || ((NU8)(x->data[bounds.Field0])) == ((NU8)(47)));
150 LA2_: ;
151 result = T1_;
152 return result;
153 }
N_NIMCALL(NIM_BOOL,isDotDot__pureZpathnorm_59)154 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isDotDot__pureZpathnorm_59)(NimStringDesc* x, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds) {
155 NIM_BOOL result;
156 NIM_BOOL T1_;
157 NIM_BOOL T2_;
158 result = (NIM_BOOL)0;
159 T1_ = (NIM_BOOL)0;
160 T2_ = (NIM_BOOL)0;
161 T2_ = (bounds.Field1 == (NI)(bounds.Field0 + ((NI) 1)));
162 if (!(T2_)) goto LA3_;
163 T2_ = ((NU8)(x->data[bounds.Field0]) == (NU8)(46));
164 LA3_: ;
165 T1_ = T2_;
166 if (!(T1_)) goto LA4_;
167 T1_ = ((NU8)(x->data[(NI)(bounds.Field0 + ((NI) 1))]) == (NU8)(46));
168 LA4_: ;
169 result = T1_;
170 return result;
171 }
N_INLINE(void,nimCopyMem)172 static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size) {
173 void* T1_;
174 T1_ = (void*)0;
175 T1_ = memcpy(dest, source, ((size_t) (size)));
176 }
N_INLINE(void,copyMem__system_1727)177 static N_INLINE(void, copyMem__system_1727)(void* dest, void* source, NI size) {
178 nimCopyMem(dest, source, size);
179 }
N_INLINE(void,appendString)180 static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
181 {
182 if (!!((src == ((NimStringDesc*) NIM_NIL)))) goto LA3_;
183 copyMem__system_1727(((void*) ((&(*dest).data[(*dest).Sup.len]))), ((void*) ((*src).data)), ((NI) ((NI)((*src).Sup.len + ((NI) 1)))));
184 (*dest).Sup.len += (*src).Sup.len;
185 }
186 LA3_: ;
187 }
N_NIMCALL(NIM_BOOL,isDot__pureZpathnorm_55)188 N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isDot__pureZpathnorm_55)(NimStringDesc* x, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds) {
189 NIM_BOOL result;
190 NIM_BOOL T1_;
191 result = (NIM_BOOL)0;
192 T1_ = (NIM_BOOL)0;
193 T1_ = (bounds.Field1 == bounds.Field0);
194 if (!(T1_)) goto LA2_;
195 T1_ = ((NU8)(x->data[bounds.Field0]) == (NU8)(46));
196 LA2_: ;
197 result = T1_;
198 return result;
199 }
N_NIMCALL(void,addNormalizePath__pureZpathnorm_71)200 N_LIB_PRIVATE N_NIMCALL(void, addNormalizePath__pureZpathnorm_71)(NimStringDesc* x, NimStringDesc** result, NI* state, NIM_CHAR dirSep) {
201 tyObject_PathIter__tllF14xUpDWpqG9ci5sg9bMg it;
202 nimZeroMem((void*)(&it), sizeof(tyObject_PathIter__tllF14xUpDWpqG9ci5sg9bMg));
203 it.notFirst = (((NI) 0) < (NI)((NI32)((*state)) >> (NU32)(((NI) 1))));
204 {
205 if (!it.notFirst) goto LA3_;
206 {
207 while (1) {
208 NIM_BOOL T7_;
209 T7_ = (NIM_BOOL)0;
210 T7_ = (it.i < (x ? x->Sup.len : 0));
211 if (!(T7_)) goto LA8_;
212 T7_ = (((NU8)(x->data[it.i])) == ((NU8)(47)) || ((NU8)(x->data[it.i])) == ((NU8)(47)));
213 LA8_: ;
214 if (!T7_) goto LA6;
215 it.i += ((NI) 1);
216 } LA6: ;
217 }
218 }
219 LA3_: ;
220 {
221 while (1) {
222 NIM_BOOL T11_;
223 tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ b;
224 T11_ = (NIM_BOOL)0;
225 T11_ = hasNext__pureZpathnorm_6(it, x);
226 if (!T11_) goto LA10;
227 b = next__pureZpathnorm_10((&it), x);
228 {
229 NIM_BOOL T14_;
230 T14_ = (NIM_BOOL)0;
231 T14_ = ((NI)((NI32)((*state)) >> (NU32)(((NI) 1))) == ((NI) 0));
232 if (!(T14_)) goto LA15_;
233 T14_ = isSlash__pureZpathnorm_63(x, b);
234 LA15_: ;
235 if (!T14_) goto LA16_;
236 {
237 NIM_BOOL T20_;
238 T20_ = (NIM_BOOL)0;
239 T20_ = (((*result) ? (*result)->Sup.len : 0) == ((NI) 0));
240 if (T20_) goto LA21_;
241 T20_ = !((((NU8)((*result)->data[(NI)(((*result) ? (*result)->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)) || ((NU8)((*result)->data[(NI)(((*result) ? (*result)->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47))));
242 LA21_: ;
243 if (!T20_) goto LA22_;
244 unsureAsgnRef((void**) (&(*result)), addChar((*result), dirSep));
245 }
246 LA22_: ;
247 (*state) = (NI)((*state) | ((NI) 1));
248 }
249 goto LA12_;
250 LA16_: ;
251 {
252 NIM_BOOL T25_;
253 T25_ = (NIM_BOOL)0;
254 T25_ = isDotDot__pureZpathnorm_59(x, b);
255 if (!T25_) goto LA26_;
256 {
257 NI d;
258 if (!(((NI) 1) <= (NI)((NI32)((*state)) >> (NU32)(((NI) 1))))) goto LA30_;
259 d = ((*result) ? (*result)->Sup.len : 0);
260 {
261 while (1) {
262 NIM_BOOL T34_;
263 T34_ = (NIM_BOOL)0;
264 T34_ = ((NI)((*state) & ((NI) 1)) < (NI)(d - ((NI) 1)));
265 if (!(T34_)) goto LA35_;
266 T34_ = !((((NU8)((*result)->data[(NI)(d - ((NI) 1))])) == ((NU8)(47)) || ((NU8)((*result)->data[(NI)(d - ((NI) 1))])) == ((NU8)(47))));
267 LA35_: ;
268 if (!T34_) goto LA33;
269 d -= ((NI) 1);
270 } LA33: ;
271 }
272 {
273 if (!(((NI) 0) < d)) goto LA38_;
274 unsureAsgnRef((void**) (&(*result)), setLengthStr((*result), ((NI) ((NI)(d - ((NI) 1))))));
275 (*state) -= ((NI) 2);
276 }
277 LA38_: ;
278 }
279 goto LA28_;
280 LA30_: ;
281 {
282 NimStringDesc* T47_;
283 {
284 NIM_BOOL T43_;
285 T43_ = (NIM_BOOL)0;
286 T43_ = (((NI) 0) < ((*result) ? (*result)->Sup.len : 0));
287 if (!(T43_)) goto LA44_;
288 T43_ = !((((NU8)((*result)->data[(NI)(((*result) ? (*result)->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)) || ((NU8)((*result)->data[(NI)(((*result) ? (*result)->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47))));
289 LA44_: ;
290 if (!T43_) goto LA45_;
291 unsureAsgnRef((void**) (&(*result)), addChar((*result), dirSep));
292 }
293 LA45_: ;
294 T47_ = NIM_NIL;
295 T47_ = substr__system_7743(x, b.Field0, b.Field1);
296 unsureAsgnRef((void**) (&(*result)), resizeString((*result), (T47_ ? T47_->Sup.len : 0) + 0));
297 appendString((*result), T47_);
298 }
299 LA28_: ;
300 }
301 goto LA12_;
302 LA26_: ;
303 {
304 NIM_BOOL T49_;
305 T49_ = (NIM_BOOL)0;
306 T49_ = isDot__pureZpathnorm_55(x, b);
307 if (!T49_) goto LA50_;
308 }
309 goto LA12_;
310 LA50_: ;
311 {
312 NimStringDesc* T61_;
313 if (!(b.Field0 <= b.Field1)) goto LA53_;
314 {
315 NIM_BOOL T57_;
316 T57_ = (NIM_BOOL)0;
317 T57_ = (((NI) 0) < ((*result) ? (*result)->Sup.len : 0));
318 if (!(T57_)) goto LA58_;
319 T57_ = !((((NU8)((*result)->data[(NI)(((*result) ? (*result)->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)) || ((NU8)((*result)->data[(NI)(((*result) ? (*result)->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47))));
320 LA58_: ;
321 if (!T57_) goto LA59_;
322 unsureAsgnRef((void**) (&(*result)), addChar((*result), dirSep));
323 }
324 LA59_: ;
325 T61_ = NIM_NIL;
326 T61_ = substr__system_7743(x, b.Field0, b.Field1);
327 unsureAsgnRef((void**) (&(*result)), resizeString((*result), (T61_ ? T61_->Sup.len : 0) + 0));
328 appendString((*result), T61_);
329 (*state) += ((NI) 2);
330 }
331 goto LA12_;
332 LA53_: ;
333 LA12_: ;
334 } LA10: ;
335 }
336 {
337 NIM_BOOL T64_;
338 T64_ = (NIM_BOOL)0;
339 T64_ = (((*result) ? (*result)->Sup.len : 0) == 0);
340 if (!(T64_)) goto LA65_;
341 T64_ = !(((x ? x->Sup.len : 0) == 0));
342 LA65_: ;
343 if (!T64_) goto LA66_;
344 unsureAsgnRef((void**) (&(*result)), copyString(((NimStringDesc*) &TM__DfU0iuayCGwHDN1Exp9cbKg_2)));
345 }
346 LA66_: ;
347 }
N_NIMCALL(NimStringDesc *,normalizePath__pureZpathnorm_127)348 N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, normalizePath__pureZpathnorm_127)(NimStringDesc* path, NIM_CHAR dirSep) {
349 NimStringDesc* result;
350 NI state;
351 result = NIM_NIL;
352 result = rawNewString(((NI) ((path ? path->Sup.len : 0))));
353 state = ((NI) 0);
354 addNormalizePath__pureZpathnorm_71(path, (&result), (&state), dirSep);
355 return result;
356 }
357