#include "table.c"

#define MAX 32

int main ( int argc, char *argv[] )
{
	int i;
	char which_request[MAX];
	char tout_name[MAX], tin_name[MAX], tleft_name[MAX], tright_name[MAX];
	char end_line[MAX];
	TABLE *tout, *tin, *tleft, *tright;

	printf ( "This program implements iterative procedures for the basic \n" );
	printf ( "relational opertations (RESTRICT, PROJECT, UNION and JOIN \n"  );
	printf ( "in a way that keeps track of tuple reads and writes. \n"	   );

	if ( argc < 3 )
		{
			printf ( "Your options are: \n" );
			printf ( "R tout tin <cond> NULL \n" );
			printf ( "J tout tleft tright <cols> NULL \n" );
			printf ( "P tout tin <cols> NULL \n" );
			printf ( "M tout tin <cols> NULL \n" );
			printf ( "Q tout tin NULL \n" );
			printf ( "U tout tin NULL \n" );
			printf ( "where R, J, P, M, Q, U request RESTRICT, JOIN, PROJECT \n " );
			printf ( "PROJECTM, UNIQUE and UNION. tout, tin, tleft and tright \n " );
			printf ( "are names of relations. cond is a sequence of values and \n " );
			printf ( "cols is either a sequence of Booleans or a sequence of \n" );
			printf ( "attribute numbers. \n" );
		}
	else
		{
			strcpy ( which_request, argv[1] );
		}

	if (which_request[0] == 'R')
		{
				strcpy ( tout_name, argv[2] );
				strcpy ( tin_name, argv[3] );
				topen (tout_name, "r" );
				topen (tin_name, "r" );
				printf ( "I made it to R.\n" );
		}
	else if (which_request[0] == 'J')
		{
				strcpy ( tout_name, argv[2] );
				strcpy ( tleft_name, argv[3] );
				strcpy ( tright_name, argv[4] );
				topen (tout_name, "r" );
				topen (tin_name, "r" );
				printf ( "I made it to J.\n" );
		}
	else if (which_request[0] == 'P')
		{
				strcpy ( tout_name, argv[2] );
				strcpy ( tin_name, argv[3] );
				strcpy ( end_line, argv[i] );
				topen (tout_name, "r" );
				topen (tin_name, "r" );
				printf ( "I made it to P.\n" );
		}
	else if (which_request[0] == 'M')
		{
				strcpy ( tout_name, argv[2] );
				strcpy ( tin_name, argv[3] );
				topen (tout_name, "r" );
				topen (tin_name, "r" );
				printf ( "I made it to M.\n" );
		}
	else if (which_request[0] == 'Q')
		{
				strcpy ( tout_name, argv[2] );
				strcpy ( tin_name, argv[3] );
				topen (tout_name, "r" );
				topen (tin_name, "r" );
				printf ( "I made it to Q.\n" );		
		}
	else if (which_request[0] == 'U')
		{
				strcpy ( tout_name, argv[2] );
				strcpy ( tin_name, argv[3] );
				topen (tout_name, "r" );
				topen (tin_name, "r" );
				printf ( "I made it to U.\n" );
		}
	
	printf ( "Good-Bye\n" );
	exit ( 0 );
}

