/* Generated by Nim Compiler v0.10.2 */
/*   (c) 2014 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32
#include "nimbase.h"

#include <string.h>
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tlineinfo196539 tlineinfo196539;
typedef struct tlinkedlist129028 tlinkedlist129028;
typedef struct tlistentry129022 tlistentry129022;
typedef struct stringtableobj133012 stringtableobj133012;
typedef struct twin32finddata104019 twin32finddata104019;
typedef struct tfiletime103079 tfiletime103079;
typedef struct TNimObject TNimObject;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct keyvaluepairseq133010 keyvaluepairseq133010;
typedef struct keyvaluepair133008 keyvaluepair133008;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct  tlineinfo196539  {
NI16 Line;
NI16 Col;
NI32 Fileindex;
};
struct  tlinkedlist129028  {
tlistentry129022* Head;
tlistentry129022* Tail;
NI Counter;
};
struct  tfiletime103079  {
NI32 Dwlowdatetime;
NI32 Dwhighdatetime;
};
typedef NI16 TY104028[260];
typedef NI16 TY104032[14];
struct  twin32finddata104019  {
NI32 Dwfileattributes;
tfiletime103079 Ftcreationtime;
tfiletime103079 Ftlastaccesstime;
tfiletime103079 Ftlastwritetime;
NI32 Nfilesizehigh;
NI32 Nfilesizelow;
NI32 Dwreserved0;
NI32 Dwreserved1;
TY104028 Cfilename;
TY104032 Calternatefilename;
};
typedef N_STDCALL_PTR(NI32, TY104045) (NI hfindfile, twin32finddata104019* lpfindfiledata);
typedef N_STDCALL_PTR(void, TY104205) (NI hfindfile);
typedef N_NIMCALL_PTR(void, TY3089) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, TY3094) (void* p);
struct  TNimType  {
NI size;
NU8 kind;
NU8 flags;
TNimType* base;
TNimNode* node;
void* finalizer;
TY3089 marker;
TY3094 deepcopy;
};
struct  TNimObject  {
TNimType* m_type;
};
struct keyvaluepair133008 {
NimStringDesc* Field0;
NimStringDesc* Field1;
};
struct  stringtableobj133012  {
  TNimObject Sup;
NI Counter;
keyvaluepairseq133010* Data;
NU8 Mode;
};
struct  tlistentry129022  {
  TNimObject Sup;
tlistentry129022* Prev;
tlistentry129022* Next;
};
struct  TNimNode  {
NU8 kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
struct keyvaluepairseq133010 {
  TGenericSeq Sup;
  keyvaluepair133008 data[SEQ_DECL_SIZE];
};
N_NIMCALL(NIM_BOOL, contains_129224)(tlinkedlist129028 list, NimStringDesc* data);
N_NIMCALL(void, prependstr_129424)(tlinkedlist129028* list, NimStringDesc* data);
N_NIMCALL(void, addpathrec_206273)(NimStringDesc* dir, tlineinfo196539 info);
N_NIMCALL(stringtableobj133012*, nstnewStringTable)(NU8 mode);
N_NIMCALL(NI, findfirstfile_113416)(NimStringDesc* a, twin32finddata104019* b);
N_NIMCALL(NimStringDesc*, HEX2F_116499)(NimStringDesc* head, NimStringDesc* tail);
static N_INLINE(NIM_BOOL, skipfinddata_113436)(twin32finddata104019* f);
N_NIMCALL(NimStringDesc*, nosextractFilename)(NimStringDesc* path);
N_NIMCALL(NimStringDesc*, HEX24_79195)(NI16* s);
N_NIMCALL(void, addpackage_206148)(stringtableobj133012* packages, NimStringDesc* p);
N_NIMCALL(NI, versionsplitpos_206023)(NimStringDesc* s);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start_74628, NI last);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI first, NI last);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI start);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI first);
N_NIMCALL(NIM_BOOL, HEX3CHEX2E_206071)(NimStringDesc* a, NimStringDesc* b);
static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b);
N_NIMCALL(NI, npuParseInt)(NimStringDesc* s, NI* number, NI start);
N_NIMCALL(NimStringDesc*, nstGet)(stringtableobj133012* t, NimStringDesc* key);
N_NIMCALL(void, nstPut)(stringtableobj133012* t, NimStringDesc* key, NimStringDesc* val);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
N_NIMCALL(void, addnimblepath_206196)(NimStringDesc* p, tlineinfo196539 info);
N_NIMCALL(void, message_198976)(tlineinfo196539 info, NU16 msg, NimStringDesc* arg);
STRING_LITERAL(TMP1697, "*", 1);
STRING_LITERAL(TMP1698, "head", 4);
extern tlinkedlist129028 searchpaths_170122;
extern TY104045 Dl_104044;
extern TY104205 Dl_104204;
extern NI gverbosity_170127;
extern tlinkedlist129028 lazypaths_170123;

N_NIMCALL(void, addpath_206012)(NimStringDesc* path, tlineinfo196539 info) {
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = contains_129224(searchpaths_170122, path);
		if (!!(LOC3)) goto LA4;
		prependstr_129424((&searchpaths_170122), path);
	}
	LA4: ;
}

static N_INLINE(NIM_BOOL, skipfinddata_113436)(twin32finddata104019* f) {
	NIM_BOOL result;
	NIM_BOOL LOC1;
	NIM_BOOL LOC3;
	NIM_BOOL LOC5;
	result = 0;
	LOC1 = 0;
	LOC1 = (((NI) ((*f).Cfilename[(0)- 0])) == 46);
	if (!(LOC1)) goto LA2;
	LOC3 = 0;
	LOC3 = (((NI) ((*f).Cfilename[(1)- 0])) == 0);
	if (LOC3) goto LA4;
	LOC5 = 0;
	LOC5 = (((NI) ((*f).Cfilename[(1)- 0])) == 46);
	if (!(LOC5)) goto LA6;
	LOC5 = (((NI) ((*f).Cfilename[(2)- 0])) == 0);
	LA6: ;
	LOC3 = LOC5;
	LA4: ;
	LOC1 = LOC3;
	LA2: ;
	result = LOC1;
	return result;
}

N_NIMCALL(NI, versionsplitpos_206023)(NimStringDesc* s) {
	NI result;
	result = 0;
	result = (NI32)(s->Sup.len - 2);
	{
		while (1) {
			NIM_BOOL LOC3;
			LOC3 = 0;
			LOC3 = (1 < result);
			if (!(LOC3)) goto LA4;
			LOC3 = (((NU8)(s->data[result])) >= ((NU8)(48)) && ((NU8)(s->data[result])) <= ((NU8)(57)) || ((NU8)(s->data[result])) == ((NU8)(46)));
			LA4: ;
			if (!LOC3) goto LA2;
			result -= 1;
		} LA2: ;
	}
	{
		if (!!(((NU8)(s->data[result]) == (NU8)(45)))) goto LA7;
		result = s->Sup.len;
	}
	LA7: ;
	return result;
}

static N_INLINE(NIM_BOOL, eqStrings)(NimStringDesc* a, NimStringDesc* b) {
	NIM_BOOL result;
	NIM_BOOL LOC11;
	int LOC13;
	result = 0;
	{
		if (!(a == b)) goto LA3;
		result = NIM_TRUE;
		goto BeforeRet;
	}
	LA3: ;
	{
		NIM_BOOL LOC7;
		LOC7 = 0;
		LOC7 = (a == NIM_NIL);
		if (LOC7) goto LA8;
		LOC7 = (b == NIM_NIL);
		LA8: ;
		if (!LOC7) goto LA9;
		result = NIM_FALSE;
		goto BeforeRet;
	}
	LA9: ;
	LOC11 = 0;
	LOC11 = ((*a).Sup.len == (*b).Sup.len);
	if (!(LOC11)) goto LA12;
	LOC13 = 0;
	LOC13 = memcmp(((NCSTRING) ((*a).data)), ((NCSTRING) ((*b).data)), (NI32)((*a).Sup.len * 1));
	LOC11 = (LOC13 == ((NI32) 0));
	LA12: ;
	result = LOC11;
	goto BeforeRet;
	BeforeRet: ;
	return result;
}

N_NIMCALL(NIM_BOOL, HEX3CHEX2E_206071)(NimStringDesc* a, NimStringDesc* b) {
	NIM_BOOL result;
	NI i;
	NI j;
	NI vera;
	NI verb;
	result = 0;
	{
		if (!eqStrings(a, ((NimStringDesc*) &TMP1698))) goto LA3;
		result = NIM_FALSE;
		goto BeforeRet;
	}
	LA3: ;
	i = 0;
	j = 0;
	vera = 0;
	verb = 0;
	{
		while (1) {
			NI ii;
			NI jj;
			ii = npuParseInt(a, (&vera), i);
			jj = npuParseInt(b, (&verb), j);
			{
				NIM_BOOL LOC9;
				LOC9 = 0;
				LOC9 = (ii <= 0);
				if (LOC9) goto LA10;
				LOC9 = (jj <= 0);
				LA10: ;
				if (!LOC9) goto LA11;
				result = (0 < jj);
				goto BeforeRet;
			}
			LA11: ;
			{
				if (!(vera < verb)) goto LA15;
				result = NIM_TRUE;
				goto BeforeRet;
			}
			goto LA13;
			LA15: ;
			{
				if (!(verb < vera)) goto LA18;
				result = NIM_FALSE;
				goto BeforeRet;
			}
			goto LA13;
			LA18: ;
			LA13: ;
			i += ii;
			j += jj;
			{
				if (!((NU8)(a->data[i]) == (NU8)(46))) goto LA22;
				i += 1;
			}
			LA22: ;
			{
				if (!((NU8)(b->data[j]) == (NU8)(46))) goto LA26;
				j += 1;
			}
			LA26: ;
		}
	}
	BeforeRet: ;
	return result;
}

N_NIMCALL(void, addpackage_206148)(stringtableobj133012* packages, NimStringDesc* p) {
	NI x;
	NimStringDesc* name;
	x = versionsplitpos_206023(p);
	name = copyStrLast(p, 0, (NI32)(x - 1));
	{
		NimStringDesc* version;
		if (!(x < p->Sup.len)) goto LA3;
		version = copyStr(p, (NI32)(x + 1));
		{
			NimStringDesc* LOC7;
			NIM_BOOL LOC8;
			LOC7 = 0;
			LOC7 = nstGet(packages, name);
			LOC8 = 0;
			LOC8 = HEX3CHEX2E_206071(LOC7, version);
			if (!LOC8) goto LA9;
			nstPut(packages, name, version);
		}
		LA9: ;
	}
	goto LA1;
	LA3: ;
	{
		nstPut(packages, name, ((NimStringDesc*) &TMP1698));
	}
	LA1: ;
}

static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	memcpy(((NCSTRING) ((&(*dest).data[((*dest).Sup.len)- 0]))), ((NCSTRING) ((*src).data)), (NI32)((*src).Sup.len + 1));
	(*dest).Sup.len += (*src).Sup.len;
}

static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c) {
	(*dest).data[((*dest).Sup.len)- 0] = c;
	(*dest).data[((NI32)((*dest).Sup.len + 1))- 0] = 0;
	(*dest).Sup.len += 1;
}

N_NIMCALL(void, addnimblepath_206196)(NimStringDesc* p, tlineinfo196539 info) {
	{
		NIM_BOOL LOC3;
		LOC3 = 0;
		LOC3 = contains_129224(searchpaths_170122, p);
		if (!!(LOC3)) goto LA4;
		{
			if (!(1 <= gverbosity_170127)) goto LA8;
			message_198976(info, ((NU16) 271), p);
		}
		LA8: ;
		prependstr_129424((&lazypaths_170123), p);
	}
	LA4: ;
}

N_NIMCALL(void, addpathrec_206273)(NimStringDesc* dir, tlineinfo196539 info) {
	stringtableobj133012* packages;
	NI pos;
	packages = nstnewStringTable(((NU8) 2));
	pos = (NI32)(dir->Sup.len - 1);
	{
		if (!(((NU8)(dir->data[pos])) == ((NU8)(92)) || ((NU8)(dir->data[pos])) == ((NU8)(47)))) goto LA3;
		pos += 1;
	}
	LA3: ;
	{
		NU8 k_206305;
		NimStringDesc* p_206306;
		twin32finddata104019 f_206320;
		NI h_206322;
		NimStringDesc* LOC6;
		k_206305 = 0;
		p_206306 = 0;
		memset((void*)(&f_206320), 0, sizeof(f_206320));
		LOC6 = 0;
		LOC6 = HEX2F_116499(dir, ((NimStringDesc*) &TMP1697));
		h_206322 = findfirstfile_113416(LOC6, (&f_206320));
		{
			if (!!((h_206322 == -1))) goto LA9;
			{
				while (1) {
					NU8 k_206324;
					k_206324 = ((NU8) 0);
					{
						NIM_BOOL LOC15;
						NimStringDesc* LOC26;
						NimStringDesc* LOC27;
						LOC15 = 0;
						LOC15 = skipfinddata_113436((&f_206320));
						if (!!(LOC15)) goto LA16;
						{
							if (!!(((NI32)(f_206320.Dwfileattributes & ((NI32) 16)) == ((NI32) 0)))) goto LA20;
							k_206324 = ((NU8) 2);
						}
						LA20: ;
						{
							if (!!(((NI32)(f_206320.Dwfileattributes & ((NI32) 1024)) == ((NI32) 0)))) goto LA24;
							k_206324 = (k_206324 + 1);
						}
						LA24: ;
						k_206305 = k_206324;
						LOC26 = 0;
						LOC26 = HEX24_79195(((NI16*) ((&f_206320.Cfilename[(0)- 0]))));
						LOC27 = 0;
						LOC27 = nosextractFilename(LOC26);
						p_206306 = HEX2F_116499(dir, LOC27);
						{
							NIM_BOOL LOC30;
							LOC30 = 0;
							LOC30 = (k_206305 == ((NU8) 2));
							if (!(LOC30)) goto LA31;
							LOC30 = !(((NU8)(p_206306->data[pos]) == (NU8)(46)));
							LA31: ;
							if (!LOC30) goto LA32;
							addpackage_206148(packages, p_206306);
						}
						LA32: ;
					}
					LA16: ;
					{
						NI32 LOC36;
						LOC36 = 0;
						LOC36 = Dl_104044(h_206322, (&f_206320));
						if (!(LOC36 == ((NI32) 0))) goto LA37;
						goto LA11;
					}
					LA37: ;
				}
			} LA11: ;
			Dl_104204(h_206322);
		}
		LA9: ;
	}
	{
		NimStringDesc* p_206316;
		p_206316 = 0;
		{
			NimStringDesc* key_206331;
			NimStringDesc* val_206333;
			key_206331 = 0;
			val_206333 = 0;
			{
				NI h_206335;
				NI HEX3Atmp_206337;
				NI res_206339;
				h_206335 = 0;
				HEX3Atmp_206337 = 0;
				HEX3Atmp_206337 = ((*packages).Data->Sup.len-1);
				res_206339 = 0;
				{
					while (1) {
						if (!(res_206339 <= HEX3Atmp_206337)) goto LA43;
						h_206335 = res_206339;
						{
							NimStringDesc* res_206341;
							if (!!((*packages).Data->data[h_206335].Field0 == 0)) goto LA46;
							key_206331 = (*packages).Data->data[h_206335].Field0;
							val_206333 = (*packages).Data->data[h_206335].Field1;
							{
								if (!eqStrings(val_206333, ((NimStringDesc*) &TMP1698))) goto LA50;
								res_206341 = key_206331;
							}
							goto LA48;
							LA50: ;
							{
								NimStringDesc* LOC53;
								LOC53 = 0;
								LOC53 = rawNewString(key_206331->Sup.len + val_206333->Sup.len + 1);
appendString(LOC53, key_206331);
appendChar(LOC53, 45);
appendString(LOC53, val_206333);
								res_206341 = LOC53;
							}
							LA48: ;
							p_206316 = res_206341;
							addnimblepath_206196(p_206316, info);
						}
						LA46: ;
						res_206339 += 1;
					} LA43: ;
				}
			}
		}
	}
}

N_NIMCALL(void, nimblepath_206372)(NimStringDesc* path, tlineinfo196539 info) {
	addpathrec_206273(path, info);
	addnimblepath_206196(path, info);
}
NIM_EXTERNC N_NOINLINE(void, HEX00_nimblecmdInit)(void) {
}

NIM_EXTERNC N_NOINLINE(void, HEX00_nimblecmdDatInit)(void) {
}

