#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include"var_dec.h"
#include"check_in.h"
#include"always.h"

main(void)
{
	int com;
	//printf("Enter the source file name..");
	//scanf("%s",source);
	//printf("Enter the destination file name ..");
	//scanf("%s",dest);

	if((fd=fopen("synter.v","w"))==NULL) {
		printf("Error opeaning source file");
		//exit();
	}
	if((fs=fopen("test.v","r"))==NULL) {
		printf("Error opeaning destination file");
		//exit();
	}

//while(strcmp(fgets(temp,sizeof(temp),fs),"endmodule")!=0)
   fprintf(fd,"`include\"genlib.h\"\n");
 while(feof(fs)==0)
{ fgets(temp,sizeof(temp),fs);
	 i=0;
	 com=strlen(temp);
	 temp[com-2]=' ';
	while(isspace(temp[i])==0)
	{
	temp1[i]=temp[i]; i++;
	}temp1[i]='\0';
	if(strcmp(temp1,"module")==0 || strcmp(temp1,"`include")==0)
	fputs(temp,fd);
	//fprintf(fd,"%s\n",temp);
	else if(strcmp(temp1,"input")==0 || strcmp(temp1,"output")==0 || strcmp(temp1,"reg")==0 || strcmp(temp1,"wire")==0)
	{check_inout(i); fputs(temp,fd);}

	else if(strcmp(temp1,"assign")==0)
	{variable1[0]='\0';variable2[0]='\0';final[0]='\0';outvar[0]='\0';and_or2(i);}
	else if(strcmp(temp1,"always")==0)
	{always();}



}
fprintf(fd,"\nendmodule\n");
	fclose(fd);

	fclose(fs);
	return(0);
}

