//#define _NoTasm
#include <quick.h>
#include "globals.h"
#include "variable.h"

Set::Set(word s)
{
dword vs=s+1;
Size=s;
ArraySize=(vs>>4)+1;
Array=new word[ArraySize];
for (word i=0;i<ArraySize;i++)
	Array[i]=0;
};

cdecl Set::~Set()
{
delete Array;
ArraySize=0;
}

word Set::operator [](word i)
{
if (i>Size) return 0;
return Array[i>>4]&(1<<(i&15));
};

void Set::operator +=(word o)
{
Array[o>>4]|=(1<<(o&15));
};

void Set::operator -=(word o)
{
Array[o>>4]&=~(1<<(o&15));
}

void Set::operator +=(Set& o)
{
word m;
if (ArraySize>=o.ArraySize) m=o.ArraySize;
	else m=ArraySize;
for (word i=0;i<m;i++)
	Array[i]|=o.Array[i];
}

void Set::operator -=(Set& o)
{
word m;
if (ArraySize>=o.ArraySize) m=o.ArraySize;
	else m=ArraySize;
for (word i=0;i<m;i++)
	Array[i]&=!o.Array[i];
}


cdecl string::~string(){};

string::string()
{for(int i=0;i<258;i++)
	str[i]=0;
};

string::string(char *s)
{for(int i=0;(s[i]!=0)&(i<256);i++)
	str[i+1]=s[i];
str[i+1]=0;
str[0]=i;
};

/*void string::operator=(char *s) volatile
{for(int i=0;(s[i]!=0)&(i<256);i++)
	str[i+1]=s[i];
str[i+1]=0;
str[0]=i;
};*/



string::string(char s)
{str[1]=s;
str[2]=0;
str[0]=1;
};

word string::operator==(string& s) const volatile
{
if (str[0]!=s.str[0]) return 0;
for(word i=1;i<=str[0];i++)
	if (str[i]!=s.str[i]) return 0;
return 1;
}

word string::operator==(char* s) const volatile
{
for(word i=1;(i<=str[0])&(s[i-1]!='\0');i++)
	if (str[i]!=s[i-1]) return 0;
if ((i<=str[0])||(s[i-1]!='\0')||(str[i]!=s[i-1]))
//if ((i>str[0])&&(s[i-1]!='\0'))
	return 0;
return 1;
}

string::string(string& s)
{
for(int i=0;i<=s.str[0];i++)
	str[i]=s.str[i];
str[i]=0;
};

/*void string::operator=(string& s) volatile
{
for(int i=0;i<=s.str[0];i++)
	str[i]=s.str[i];
str[i]=0;
//return *this;
};  */

string::string(string* s)
{for(int i=0;i<=s->str[0];i++)
	str[i+1]=s->str[i];
str[i]=0;
};

string string::operator +(char s) const volatile
{
char t[257];
word a=str[0];
if (a>255) a=255;
for(word i=1;i<=a;i++)
	t[i-1]=str[i];
t[i-1]=s;
t[i]=0;
return (string)t;
};

string string::operator +(char *s) const volatile
{
word a;
char t[257];

a=str[0];
for(word i=1;i<=a;i++)
	t[i-1]=str[i];
for(a=0;(i<256)&(s[a]!=0);(i+=1,a+=1))
	t[i-1]=s[a];
t[i-1]=0;
return t;
};

string string::operator +(string& st) const volatile
{
word a;
char t[257];
char *s=st.str+1;
a=str[0];
for(word i=1;i<=a;i++)
	t[i-1]=str[i];
for(a=0;(i<256)&(s[a]!=0);(i+=1,a+=1))
	t[i-1]=s[a];
t[i-1]=0;
return t;
};

char * string::operator +=(char s) volatile
{
if (str[0]<255) {
    str[++str[0]]=s;
    str[str[0]+1]=0;
	};
return (char *)str+1;
};

char * string::operator +=(char *s) volatile
{
word a=0,i=str[0]+1;

for(a=0;(i<256)&(s[a]!=0);i++,a++)
	str[i]=s[a];
str[i]=0;
str[0]=i-1;
return (char *)str+1;
};

char * string::operator +=(string& st) volatile
{
word a=0,i=str[0]+1;
char *s=st.str+1;
for(a=0;(i<256)&(s[a]!=0);i++,a++)
	str[i]=s[a];
str[i]=0;
str[0]=i-1;
return (char *)str+1;
};

string operator +(char c,string& s)
{
char t[257];
word a=s.str[0];
if (a>255) a=255;
t[0]=c;
for(word i=1;i<=a;i++)
	t[i]=s.str[i];
t[i]=0;
return t;
}

string operator +(char *s,string st)
{
char t[257];
for(word a=0;(a<256)&(s[a]!=0);a++)
	t[a]=s[a];
for(word i=1;(a<256)&(i<=st.str[0]);i++,a++)
	t[a]=st.str[i];
t[a]=0;
return t;
};

word operator!=(char* s,string& st)
{return !(st==s);}

word operator==(char* s,string& st)
{
for(word i=1;(i<=st.str[0])&(s[i-1]!='\0');i++)
	if (st.str[i]!=s[i-1]) return 0;
return 1;
}

