All pastes #968276 Raw Edit

Untitled

public text v1 · immutable
·published 2008-04-02 22:45 UTC
rendered paste body
void storeString(char* stringName,char* stringValue,unsigned short stringSize){
	unsigned short vatCounter;
	for(vatCounter=0;vatCounter<integerAmount;vatCounter++){
		if(strcmp((*(stringPointer+vatCounter)).name,stringName)==0){
			if(stringPointer[vatCounter].size!=stringSize){
				if(stringPointer[vatCounter].handle)HeapUnlock(stringPointer[vatCounter].handle);
				if((stringPointer[vatCounter].handle=HeapRealloc(stringPointer[vatCounter].handle,stringSize))==H_NULL)programError("Error reallocating memory");
				if(stringPointer[vatCounter].handle)HeapLock(stringPointer[vatCounter].handle);
				stringPointer[vatCounter].value=HeapDeref(stringPointer[vatCounter].handle);
				stringPointer[vatCounter].size=stringSize;
			}
			memcpy(stringPointer[vatCounter].value,stringValue,stringSize);
			return;
		}
	}
			// If the variable doesn't exist
	stringAmount++; 
	if(stringHandle)HeapUnlock(stringHandle);
	if((stringHandle=HeapRealloc(stringHandle,stringAmount*sizeof(string)))==H_NULL)programError("Error reallocating memory");
	if(stringHandle)HeapLock(stringHandle);
	else programError("Invalid handle");
	stringPointer=HeapDeref(stringHandle);
	// OK, fine, maybe I should increment stringAmount later, I don't care right now
	if(stringPointer[stringAmount-1].handle)HeapUnlock(stringPointer[vatCounter].handle);
	if((stringPointer[stringAmount-1].handle=HeapAlloc(stringSize))==H_NULL)programError("Error reallocating memory");
	if(stringPointer[stringAmount-1].handle)HeapLock(stringPointer[vatCounter].handle);
	stringPointer[stringAmount-1].value=HeapDeref(stringPointer[vatCounter].handle);
	memcpy(stringPointer[stringAmount-1].value,stringValue,stringSize);
	stringPointer[stringAmount-1].size=stringSize;
	memcpy(stringPointer[stringAmount-1].name,stringName,8);
}