File: %40m..%40slib%40spure%40spathnorm.nim.c

package info (click to toggle)
nim 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,911,644 kB
  • sloc: sh: 24,603; ansic: 1,761; python: 1,492; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (389 lines) | stat: -rw-r--r-- 12,751 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/* Generated by Nim Compiler v2.2.0 */
#define NIM_INTBITS 64

#include "nimbase.h"
#include <string.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
typedef struct tyObject_PathIter__eeeI18iIyWiZq6ovtjB4jA tyObject_PathIter__eeeI18iIyWiZq6ovtjB4jA;
typedef struct tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ;
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
struct tyObject_PathIter__eeeI18iIyWiZq6ovtjB4jA {
	NI i;
	NI prev;
	NIM_BOOL notFirst;
};
struct tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ {
	NI Field0;
	NI Field1;
};
static N_INLINE(void, nimZeroMem)(void* p_p0, NI size_p1);
static N_INLINE(void, nimSetMem__systemZmemory_u7)(void* a_p0, int v_p1, NI size_p2);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, hasNext__pureZpathnorm_u6)(tyObject_PathIter__eeeI18iIyWiZq6ovtjB4jA it_p0, NimStringV2 x_p1);
N_LIB_PRIVATE N_NIMCALL(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, next__pureZpathnorm_u10)(tyObject_PathIter__eeeI18iIyWiZq6ovtjB4jA* it_p0, NimStringV2 x_p1);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isSlash__pureZpathnorm_u78)(NimStringV2 x_p0, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds_p1);
static N_INLINE(void, nimAddCharV1)(NimStringV2* s_p0, NIM_CHAR c_p1);
N_LIB_PRIVATE N_NIMCALL(void, prepareAdd)(NimStringV2* s_p0, NI addLen_p1);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isDotDot__pureZpathnorm_u74)(NimStringV2 x_p0, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds_p1);
N_LIB_PRIVATE N_NIMCALL(void, setLengthStrV2)(NimStringV2* s_p0, NI newLen_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, substr__system_u8405)(NimStringV2 s_p0, NI first_p1, NI last_p2);
static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1);
static N_INLINE(void, copyMem__system_u1713)(void* dest_p0, void* source_p1, NI size_p2);
static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2);
N_LIB_PRIVATE N_NIMCALL(void, eqdestroy___system_u2597)(NimStringV2 dest_p0);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isDot__pureZpathnorm_u70)(NimStringV2 x_p0, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds_p1);
N_LIB_PRIVATE N_NIMCALL(void, eqsink___system_u2606)(NimStringV2* dest_p0, NimStringV2 src_p1);
N_NIMCALL(NimStringV2, rawNewString)(NI cap_p0);
N_LIB_PRIVATE N_NIMCALL(void, addNormalizePath__pureZpathnorm_u86)(NimStringV2 x_p0, NimStringV2* result_p1, NI* state_p2, NIM_CHAR dirSep_p3);
static const struct {
  NI cap; NIM_CHAR data[1+1];
} TM__DfU0iuayCGwHDN1Exp9cbKg_2 = { 1 | NIM_STRLIT_FLAG, "." };
static const NimStringV2 TM__DfU0iuayCGwHDN1Exp9cbKg_3 = {1, (NimStrPayload*)&TM__DfU0iuayCGwHDN1Exp9cbKg_2};
extern NIM_BOOL nimInErrorMode__system_u4311;
static N_INLINE(void, nimSetMem__systemZmemory_u7)(void* a_p0, int v_p1, NI size_p2) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memset(a_p0, v_p1, ((size_t) (size_p2)));
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4311);
	return result;
}
static N_INLINE(void, nimZeroMem)(void* p_p0, NI size_p1) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimSetMem__systemZmemory_u7(p_p0, ((int)0), size_p1);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, hasNext__pureZpathnorm_u6)(tyObject_PathIter__eeeI18iIyWiZq6ovtjB4jA it_p0, NimStringV2 x_p1) {
	NIM_BOOL result;
	result = (it_p0.i < x_p1.len);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ, next__pureZpathnorm_u10)(tyObject_PathIter__eeeI18iIyWiZq6ovtjB4jA* it_p0, NimStringV2 x_p1) {
	tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimZeroMem((void*)(&result), sizeof(tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ));
	(*it_p0).prev = (*it_p0).i;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = !((*it_p0).notFirst);
		if (!(T3_)) goto LA4_;
		T3_ = (((NU8)(x_p1.p->data[(*it_p0).i])) == ((NU8)(47)) || ((NU8)(x_p1.p->data[(*it_p0).i])) == ((NU8)(47)));
LA4_: ;
		if (!T3_) goto LA5_;
		(*it_p0).i += ((NI)1);
	}
	goto LA1_;
LA5_: ;
	{
		{
			while (1) {
				NIM_BOOL T10_;
				T10_ = (NIM_BOOL)0;
				T10_ = ((*it_p0).i < x_p1.len);
				if (!(T10_)) goto LA11_;
				T10_ = !((((NU8)(x_p1.p->data[(*it_p0).i])) == ((NU8)(47)) || ((NU8)(x_p1.p->data[(*it_p0).i])) == ((NU8)(47))));
LA11_: ;
				if (!T10_) goto LA9;
				(*it_p0).i += ((NI)1);
			} LA9: ;
		}
	}
LA1_: ;
	{
		NI colontmp_;
		NI colontmp__2;
		if (!((*it_p0).prev < (*it_p0).i)) goto LA14_;
		colontmp_ = (*it_p0).prev;
		colontmp__2 = (NI)((*it_p0).i - ((NI)1));
		result.Field0 = colontmp_;
		result.Field1 = colontmp__2;
	}
	goto LA12_;
LA14_: ;
	{
		NIM_BOOL T17_;
		T17_ = (NIM_BOOL)0;
		T17_ = hasNext__pureZpathnorm_u6((*it_p0), x_p1);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!T17_) goto LA18_;
		result = next__pureZpathnorm_u10(it_p0, x_p1);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA12_;
LA18_: ;
LA12_: ;
	{
		while (1) {
			NIM_BOOL T22_;
			T22_ = (NIM_BOOL)0;
			T22_ = ((*it_p0).i < x_p1.len);
			if (!(T22_)) goto LA23_;
			T22_ = (((NU8)(x_p1.p->data[(*it_p0).i])) == ((NU8)(47)) || ((NU8)(x_p1.p->data[(*it_p0).i])) == ((NU8)(47)));
LA23_: ;
			if (!T22_) goto LA21;
			(*it_p0).i += ((NI)1);
		} LA21: ;
	}
	(*it_p0).notFirst = NIM_TRUE;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isSlash__pureZpathnorm_u78)(NimStringV2 x_p0, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds_p1) {
	NIM_BOOL result;
	NIM_BOOL T1_;
	T1_ = (NIM_BOOL)0;
	T1_ = (bounds_p1.Field1 == bounds_p1.Field0);
	if (!(T1_)) goto LA2_;
	T1_ = (((NU8)(x_p0.p->data[bounds_p1.Field0])) == ((NU8)(47)) || ((NU8)(x_p0.p->data[bounds_p1.Field0])) == ((NU8)(47)));
LA2_: ;
	result = T1_;
	return result;
}
static N_INLINE(void, nimAddCharV1)(NimStringV2* s_p0, NIM_CHAR c_p1) {
	prepareAdd(s_p0, ((NI)1));
	(*(*s_p0).p).data[(*s_p0).len] = c_p1;
	(*s_p0).len += ((NI)1);
	(*(*s_p0).p).data[(*s_p0).len] = 0;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isDotDot__pureZpathnorm_u74)(NimStringV2 x_p0, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds_p1) {
	NIM_BOOL result;
	NIM_BOOL T1_;
	NIM_BOOL T2_;
	T1_ = (NIM_BOOL)0;
	T2_ = (NIM_BOOL)0;
	T2_ = (bounds_p1.Field1 == (NI)(bounds_p1.Field0 + ((NI)1)));
	if (!(T2_)) goto LA3_;
	T2_ = ((NU8)(x_p0.p->data[bounds_p1.Field0]) == (NU8)(46));
LA3_: ;
	T1_ = T2_;
	if (!(T1_)) goto LA4_;
	T1_ = ((NU8)(x_p0.p->data[(NI)(bounds_p1.Field0 + ((NI)1))]) == (NU8)(46));
LA4_: ;
	result = T1_;
	return result;
}
static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest_p0, source_p1, ((size_t) (size_p2)));
}
static N_INLINE(void, copyMem__system_u1713)(void* dest_p0, void* source_p1, NI size_p2) {
	nimCopyMem(dest_p0, source_p1, size_p2);
}
static N_INLINE(void, appendString)(NimStringV2* dest_p0, NimStringV2 src_p1) {
	{
		if (!(((NI)0) < src_p1.len)) goto LA3_;
		copyMem__system_u1713(((void*) ((&(*(*dest_p0).p).data[(*dest_p0).len]))), ((void*) ((&(*src_p1.p).data[((NI)0)]))), ((NI)(src_p1.len + ((NI)1))));
		(*dest_p0).len += src_p1.len;
	}
LA3_: ;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isDot__pureZpathnorm_u70)(NimStringV2 x_p0, tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ bounds_p1) {
	NIM_BOOL result;
	NIM_BOOL T1_;
	T1_ = (NIM_BOOL)0;
	T1_ = (bounds_p1.Field1 == bounds_p1.Field0);
	if (!(T1_)) goto LA2_;
	T1_ = ((NU8)(x_p0.p->data[bounds_p1.Field0]) == (NU8)(46));
LA2_: ;
	result = T1_;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, addNormalizePath__pureZpathnorm_u86)(NimStringV2 x_p0, NimStringV2* result_p1, NI* state_p2, NIM_CHAR dirSep_p3) {
	tyObject_PathIter__eeeI18iIyWiZq6ovtjB4jA it;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimZeroMem((void*)(&it), sizeof(tyObject_PathIter__eeeI18iIyWiZq6ovtjB4jA));
	it.notFirst = (((NI)0) < (NI)((NI64)((*state_p2)) >> (NU64)(((NI)1))));
	{
		if (!it.notFirst) goto LA3_;
		{
			while (1) {
				NIM_BOOL T7_;
				T7_ = (NIM_BOOL)0;
				T7_ = (it.i < x_p0.len);
				if (!(T7_)) goto LA8_;
				T7_ = (((NU8)(x_p0.p->data[it.i])) == ((NU8)(47)) || ((NU8)(x_p0.p->data[it.i])) == ((NU8)(47)));
LA8_: ;
				if (!T7_) goto LA6;
				it.i += ((NI)1);
			} LA6: ;
		}
	}
LA3_: ;
	{
		while (1) {
			NIM_BOOL T11_;
			tyTuple__1v9bKyksXWMsm0vNwmZ4EuQ b;
			T11_ = (NIM_BOOL)0;
			T11_ = hasNext__pureZpathnorm_u6(it, x_p0);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			if (!T11_) goto LA10;
			b = next__pureZpathnorm_u10((&it), x_p0);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			{
				NIM_BOOL T14_;
				T14_ = (NIM_BOOL)0;
				T14_ = ((NI)((NI64)((*state_p2)) >> (NU64)(((NI)1))) == ((NI)0));
				if (!(T14_)) goto LA15_;
				T14_ = isSlash__pureZpathnorm_u78(x_p0, b);
				if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
LA15_: ;
				if (!T14_) goto LA16_;
				{
					NIM_BOOL T20_;
					T20_ = (NIM_BOOL)0;
					T20_ = ((*result_p1).len == ((NI)0));
					if (T20_) goto LA21_;
					T20_ = !((((NU8)((*result_p1).p->data[(NI)((*result_p1).len - ((NI)1))])) == ((NU8)(47)) || ((NU8)((*result_p1).p->data[(NI)((*result_p1).len - ((NI)1))])) == ((NU8)(47))));
LA21_: ;
					if (!T20_) goto LA22_;
					nimAddCharV1((&(*result_p1)), dirSep_p3);
				}
LA22_: ;
				(*state_p2) = (NI)((*state_p2) | ((NI)1));
			}
			goto LA12_;
LA16_: ;
			{
				NIM_BOOL T25_;
				T25_ = (NIM_BOOL)0;
				T25_ = isDotDot__pureZpathnorm_u74(x_p0, b);
				if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
				if (!T25_) goto LA26_;
				{
					NI d;
					if (!(((NI)1) <= (NI)((NI64)((*state_p2)) >> (NU64)(((NI)1))))) goto LA30_;
					d = (*result_p1).len;
					{
						while (1) {
							NIM_BOOL T34_;
							T34_ = (NIM_BOOL)0;
							T34_ = ((NI)((*state_p2) & ((NI)1)) < (NI)(d - ((NI)1)));
							if (!(T34_)) goto LA35_;
							T34_ = !((((NU8)((*result_p1).p->data[(NI)(d - ((NI)1))])) == ((NU8)(47)) || ((NU8)((*result_p1).p->data[(NI)(d - ((NI)1))])) == ((NU8)(47))));
LA35_: ;
							if (!T34_) goto LA33;
							d -= ((NI)1);
						} LA33: ;
					}
					{
						if (!(((NI)0) < d)) goto LA38_;
						setLengthStrV2((&(*result_p1)), ((NI)(d - ((NI)1))));
						(*state_p2) -= ((NI)2);
					}
LA38_: ;
				}
				goto LA28_;
LA30_: ;
				{
					NimStringV2 colontmpD_;
					colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
					{
						NIM_BOOL T43_;
						T43_ = (NIM_BOOL)0;
						T43_ = (((NI)0) < (*result_p1).len);
						if (!(T43_)) goto LA44_;
						T43_ = !((((NU8)((*result_p1).p->data[(NI)((*result_p1).len - ((NI)1))])) == ((NU8)(47)) || ((NU8)((*result_p1).p->data[(NI)((*result_p1).len - ((NI)1))])) == ((NU8)(47))));
LA44_: ;
						if (!T43_) goto LA45_;
						nimAddCharV1((&(*result_p1)), dirSep_p3);
					}
LA45_: ;
					colontmpD_ = substr__system_u8405(x_p0, b.Field0, b.Field1);
					prepareAdd((&(*result_p1)), colontmpD_.len + 0);
appendString((&(*result_p1)), colontmpD_);
					eqdestroy___system_u2597(colontmpD_);
				}
LA28_: ;
			}
			goto LA12_;
LA26_: ;
			{
				NIM_BOOL T48_;
				T48_ = (NIM_BOOL)0;
				T48_ = isDot__pureZpathnorm_u70(x_p0, b);
				if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
				if (!T48_) goto LA49_;
			}
			goto LA12_;
LA49_: ;
			{
				NimStringV2 colontmpD__2;
				if (!(b.Field0 <= b.Field1)) goto LA52_;
				colontmpD__2.len = 0; colontmpD__2.p = NIM_NIL;
				{
					NIM_BOOL T56_;
					T56_ = (NIM_BOOL)0;
					T56_ = (((NI)0) < (*result_p1).len);
					if (!(T56_)) goto LA57_;
					T56_ = !((((NU8)((*result_p1).p->data[(NI)((*result_p1).len - ((NI)1))])) == ((NU8)(47)) || ((NU8)((*result_p1).p->data[(NI)((*result_p1).len - ((NI)1))])) == ((NU8)(47))));
LA57_: ;
					if (!T56_) goto LA58_;
					nimAddCharV1((&(*result_p1)), dirSep_p3);
				}
LA58_: ;
				colontmpD__2 = substr__system_u8405(x_p0, b.Field0, b.Field1);
				prepareAdd((&(*result_p1)), colontmpD__2.len + 0);
appendString((&(*result_p1)), colontmpD__2);
				(*state_p2) += ((NI)2);
				eqdestroy___system_u2597(colontmpD__2);
			}
			goto LA12_;
LA52_: ;
LA12_: ;
		} LA10: ;
	}
	{
		NIM_BOOL T62_;
		T62_ = (NIM_BOOL)0;
		T62_ = ((*result_p1).len == 0);
		if (!(T62_)) goto LA63_;
		T62_ = !((x_p0.len == 0));
LA63_: ;
		if (!T62_) goto LA64_;
		eqsink___system_u2606((&(*result_p1)), TM__DfU0iuayCGwHDN1Exp9cbKg_3);
	}
LA64_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, normalizePath__pureZpathnorm_u146)(NimStringV2 path_p0, NIM_CHAR dirSep_p1) {
	NimStringV2 result;
	NI state;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result.len = 0; result.p = NIM_NIL;
	result = rawNewString((path_p0.len));
	state = ((NI)0);
	addNormalizePath__pureZpathnorm_u86(path_p0, (&result), (&state), dirSep_p1);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}