/*
** SellaNMS
** $Id: flatfile.cxx,v 1.5 2005/05/21 23:10:28 sella Exp $
** Copyright (c) 2001-2005 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

static char rcsid[] = "$Id: flatfile.cxx,v 1.5 2005/05/21 23:10:28 sella Exp $";

#include "flatfile.h"
#include "common/confignode.h"
#include "configuration_parser.h"
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <regex.h>
#include <stl/slist>
#include <stl/string>

Flatfile::Flatfile() {
	this->config = new ConfigNode();
}

Flatfile::~Flatfile() {
	SAFE_DELETE(this->config);
}

RESULT Flatfile::read(string source) {
	RESULT result;

	ConfigNode 				new_conf;
	ConfigurationParser 	config_parser;

	slist<string> 			errors;
	string					error;

	assert(this->config != NULL);

	result = config_parser.loadConfiguration(errors, new_conf, source);
	if (result == SUCCESS) {
		this->config->clear();
		(*this->config) = new_conf;
	} else {
#ifdef DEEP_ERROR
		for (slist<string>::iterator it = errors.begin(); it != errors.end(); ++it) {
			LMSG("ERROR: %s", it->c_str());
		}
#else
		for (slist<string>::iterator it = errors.begin(); it != errors.end(); ++it) {
			error = *it;
		}
		LMSG("ERROR: %s", error.c_str());
#endif
	}
	return result;
}

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim600: fdm=marker
** vim: noet ts=3 sw=3
*/
