#include "test.h"

int main(int argc, char* argv[])
{
	char iDesc[] = "arrayi V, matrix M, string chr, int option, string ShowOffset";
	char *result;
	char ShowOffset[128] = "";
	int* vector = 0;
	int vLength = 0, option = 0;
	char chr[128] = "";
	int *iFill;
	matrix M;
	
	FILE* file;
	
	if (! (file = ParseCmdLine(argc, argv)))
	{	
		return 0;
	}
	
	MemoryManager mem = CreateMemoryManager(3, 1, 0, 0);
	
	while (ParseStructure(file, iDesc, &iFill, &mem, &vector, &vLength, &M, chr, &option, ShowOffset))
	{
		if (iFill[0]) iFill[1] = 0;
		DisplayStructure(iDesc, iFill, vector, vLength, &M, chr, option, ShowOffset);
		if (iFill[4])
		{
			if (strcmp(ShowOffset, "on") && strcmp(ShowOffset, "off"))
			{
				printf("Warning: Invalid ShowOffset option: '%s'.\n", ShowOffset);
				printf("Ignoring. Default is ShowOffset = off.\n");
				ShowOffset[0] = '\0';
			}
		}		
		if (iFill[0])
		{
			result = avpr(vector, vLength, DISPLAY_INTS | (strcmp(ShowOffset, "on") ? 0 : DISPLAY_OFFSET), chr, option);
		}
		else if (iFill[1])
		{
			result = avpr(&M, 0, DISPLAY_MATRIX | (strcmp(ShowOffset, "on") ? 0 : DISPLAY_OFFSET), chr, option);
		}
		else
		{
			result = " No vector or matrix provided!";
		}
		
		printf("Result:\n%s\n", result);
		
		FreeMemory(&mem);
		mem = CreateMemoryManager(3, 0, 0, 0);
		
		vector = 0;
		vLength = 0;
		option = 0;
		chr[0] = '\0';
		ShowOffset[0] = '\0';
		printf("-------------------------------------------------------------------------------\n");
	}
	FreeMemory(&mem);
	return 1;
}
		