#include "environment.h"
#include <stdlib.h>
#include <string.h>

// --- cBurnEnvVar ------------------------------------------------------------

cBurnVariable::cBurnVariable(const char *Name, const char *Value):
		mName(Name),
		mValue(Value != NULL ? Value : "")
{
}

// --- cBurnEnvironment -------------------------------------------------------

cBurnEnvironment::cBurnEnvironment(void)
{
}
	
cBurnEnvironment &cBurnEnvironment::operator=(const cBurnEnvironment &Object)
{
	for (cBurnVariable *var = Object.First(); var != NULL; 
		 var = Object.Next(var)) {
		cBurnVariable *newVar = new cBurnVariable(var->Name(), var->Value());
		Add(newVar);
	}
	return *this;
}

void cBurnEnvironment::Set(void)
{
	for (cBurnVariable *var = First(); var != NULL; var = Next(var))
		setenv(var->Name(), var->Value(), 1);
}

void cBurnEnvironment::Put(const char *Name, const char *Value)
{
	for (cBurnVariable *var = First(); var != NULL; var = Next(var)) {
		if (strcmp(var->Name(), Name) == 0) {
			Del(var);
			break;
		}
	}
	Add(new cBurnVariable(Name, Value));
}
