/**
 * The husk of the Setup class for Approach 1. 
 *
 * @author Rikhei Harris
 * @author Andrew Kaiser
 * @author Jonathan Wellons
 * @version 1.2 of April 2001
 */

import java.io.*;
import SimpleInput;
import SimpleOutput;

public class Setup1 {
    
    public static String readline (FileReader reader) throws IOException {
        String line = "";
        int c;
        
        while ((c = reader.read()) != -1) {
            if (c == '\n')
                return line;
            else
                line += (char)c;
        }
        return "EOF";
    } // readline
    
    public static String[] getTestInfo(String str) {
        String[] tia = new String[4];
        int c; 
        int i;
        
        for (i = 0; i < 5; i++) {
            c = str.indexOf(' ');
            tia[i] = str.substring(0, c);
            str = str.substring(c+1);
        }
        return tia;
    } // getTestInfo
    
    
    public static void main(String[] args) {
        
        SimpleInput in = new SimpleInput();
        SimpleOutput out = new SimpleOutput();
    
        // Find out if the user wants a graphical or terminal interface.
        
        out.println("Please type /'term/' if you would like to use a terminal");
        out.println("interface or /'gui/' if you would like to use a graphical");
        out.println(" interface: ");
        String iface = in.readString();
        while (iface != "gui" && iface != "term") {
            out.println("That is not a recognized command. Please try again.");
            iface = in.readString();
        }
        SchemeTesterInterface1 intface = null;
        if (iface == "gui") {
            intface = new GUI1();
        }
        else {
            intface = new Terminal1();
        }
        
        String[] data = intface.getData();
        String labNumber = data[0];
        String codeLocation = data[1];
        String specialTestCases = data[2];

        try {
        
        File inputFile = new File("testinfo.txt");
        FileReader reader = new FileReader(inputFile);
        
        String text;
        
        // Read an entire line in at a time, and tell see whether it begins
        // with the lab number..   
        
        do {
            text = readline (reader);
        }
        while (!(text.startsWith(labNumber)));
        

        String[] blah = getTestInfo(text);
        labNumber = blah[0];
        String fileNameForRegTests = blah[1];
        String AuthorityProgramLocation = blah[2];
        String co = blah[3];
        Integer cor = new Integer(co);
        int correctness = cor.intValue();
        
        } catch (Exception e) {}


        // Somehow we need to figure out how to get the filename and 
        // the labnumber from that goddamned method. And we should get the 
        // level of correctness or some junk. 
       
        ComparisonChecker1 cc = new ComparisonChecker1();
        RunSchemeTest1 rstA = new RunSchemeTest1(codeLocation,60,1000,'A',cc);
        RunSchemeTest1 rstU = new RunSchemeTest1(codeLocation,60,1000,'U',cc);
        OutputFormatter1 of = new OutputFormatter1(intface,correctness);
        InstructorNotifier1 ins = new InstructorNotifier1();
        TestGenerator1 tcg = new TestGenerator1();
        
        
        // Now we have to 
        tcg.getCases(fileNameForRegTests, specialTestCases);
        
    } // main
} // Setup1
