#include "inword.h"
#include "binfile.h"

void InputWord::ctor()
{
	file = new BinaryInputFile(GetFileName(),this,GetFormatIn(),
		GetInitialSkip());
	if (file->is_open()) FileName_1 = file->name();
}

void InputWord::dtor()
{
	delete file ;
}

ErrCode InputWord::kernel(int32 k)
{
	if (node_state >= EndOfData) return node_state ;
	if (!file->is_open()) {
		file->open(1);
		if (!file->is_open()) return node_state = FatalError ;
		FileName_1 = file->name();
	}
	for (int32 i = 0 ; i < k ; i++)
		for (int32 b = 0 ; b < GetBlockSize(); b++)
			for (int e = 0; e < GetElementSize(); e++) {
				BinMachWord bin_in ;
				MachWord in ;
				if (GetIntegerOut()) bin_in = file->read_integer();
				else in = file->read();
				if (file->file_state() >= EndOfData)
					return node_state=file->file_state() ;
				if (GetIntegerOut()) WriteInteger(bin_in);
				else WriteWord(in);
			}
	return OK ;
}


