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