#include "test.h"

int verbose = 0;

int is_verbose()
{
	return verbose;
}

void setverbose(int vrb)
{
	verbose = vrb;
}

FILE* ParseCmdLine(int argc, char* argv[])
{
	FILE* file;
	if (argc > 1)
	{
		if (file = fopen(argv[1], "r"))
		{
			printf("Taking input from file '%s'...\n", argv[1]);
			return file;
		}
		else
		{
			printf("Failed to open file '%s' for read access!\n", argv[1]);
			return 0;
		}
	}
	else
	{
		printf("Taking input from console. Type \"help\" to see a description of\n");
		printf("the input format.\n");
		return stdin;
	}
}	

int HasSelfLoops(matrix* Dm, matrix* Dp)
{
	int i, j;
	for (i = 0; i < NumberOfRows(*Dm); i++)
	{
		for (j = 0; j < NumberOfColumns(*Dm); j++)
		{
			if (GetMatrixEl(Dm, i, j) && GetMatrixEl(Dp, i, j))
			{
				return 1;
			}
		}
	}
	return 0;
}

void FillDmDp(int* Filled, matrix* D, matrix* Dm, matrix* Dp, MemoryManager* mem)
{
	/*If D has been filled...*/
	if (Filled[0])
	{
		/*We want to ignore any given Dm and Dp and instead fill Dm and Dp with
		matrices developed from D.*/
		if (Filled[1])
		{
			DeallocateMatrix(Dm);
		}
		else
		{
			ManageMatrix(mem, Dm);
		}
		if (Filled[2])
		{
			DeallocateMatrix(Dp);
		}
		else
		{
			ManageMatrix(mem, Dp);
		}
		AllocateMatrixType(2, Dm, NumberOfRows(*D), NumberOfColumns(*D));
		AllocateMatrixType(2, Dp, NumberOfRows(*D), NumberOfColumns(*D));
		d2dd(D, Dm, Dp);
		Filled[0] = 0;
		Filled[1] = 1;
		Filled[2] = 1;		
	}		
}

