#include "keys.h"

cClusterKey::cClusterKey(void) {
	m_Key = kNone;
}

cClusterKey::cClusterKey(eKeys Key, const cString &Command) {
	m_Key = Key;
	m_Command = Command;
}

cClusterKey::~cClusterKey() {
}
	
bool cClusterKey::Parse(char *String) {
	char *p = strpbrk(String, " \t");
	if (p) {
		*p++ = 0;
		m_Key = cKey::FromString(String);
		if (m_Key != kNone) {
			p = skipspace(p);
			if (*p) {
				char *q;
				for (q = p; *q; ++q)
					if (*q == ';') *q = '\n';

				if (*--q != '\n')
					m_Command = p + cString('\n');
				else
					m_Command = p;

				return true;
			}
		}
	}
	return false;
}

const cString &cClusterKeys::Get(eKeys Key) const {
	static const cString NullString;

	if (Key != kNone) {
		for (cClusterKey *k = First(); k; k = Next(k)) {
			if (Key == k->Key())
				return k->Command();
		}
	}

	return NullString;
}
