package EDU.neu.ccs.demeter.tools.apstudio.graphedit;
import java.awt.*;
import java.io.*;
import java.util.*;
import EDU.neu.ccs.demeter.*;
import EDU.neu.ccs.demeter.common.tg.*;


import EDU.neu.ccs.demeter.*;
class Main extends UniversalVisitor {
  public Main() {
    super();
  }

		/**
		A command line interface to test out all the non-gui part of ApStudio
		The input is a class dictionary file(cd) and a text file containing
		a strategy expression.
		The ouput is the propagation graph corresponding to the input strategy.
		The non-gui parts of ApStudio are -
		cd-to-gcd , gcd-to-cd , placement , subgraph , propagation-graph 
		*/
	public static void main(String args[]) throws Exception
	{
		
		BufferedReader din = new BufferedReader(new InputStreamReader(System.in));
		System.out.print("\nEnter the name of the input Apstudio file - ");
		System.out.flush();
		String strfilename = din.readLine();
		FileInputStream fi=new FileInputStream(strfilename);			

		Program prog = Program.parse(fi);

		try{
		UGraph graph = prog.print_edges();	
									//print_edges() converts cd to gcd
		
		System.out.print("\nEnter the name of the strategy  file - ");
		System.out.flush();
		strfilename = din.readLine();
		FileInputStream fi2=new FileInputStream(strfilename);			
		
		StrategyGraph sg = StrategyGraph.parse(fi2);
		
		sg.toGraph(sg.getFirst());	//needed to initialise strategy properly
		//System.out.println("did sg.toGraph");
		
		
		
		graph.computeSubgraph(sg);	//compute the subgraph
		//System.out.println("graph- \n"+ graph.GetGraphString());
		
		//propagation graph - 
		UGraph gnew = graph.parse(graph.GetMarkedGraphString());
									//GetMarkedGraphString returns only the 
									//marked portion of the gcd

		System.out.println(gnew.getCdString());		
									//getCdString() does gcd to cd conversion
		
		//System.out.println("Done");
		}
		catch(ParameterisationException e)
		{
			System.out.println("Cannot handle parameterized classes in class dictionary");
		}
	}
	  void universal_trv0_bef(UniversalVisitor _v_) {
    super.universal_trv0_bef(_v_);
  }
  void universal_trv0_aft(UniversalVisitor _v_) {
    super.universal_trv0_aft(_v_);
  }
  void universal_trv0(UniversalVisitor _v_) {
    universal_trv0_bef(_v_);
    super.universal_trv0(_v_);
    universal_trv0_aft(_v_);
  }
}

