// FILE. . . . . /home/hak/hlt/src/hlt/osfv2/apps/v2/sources/OsfV2Main.java
// EDIT BY . . . Hassan Ait-Kaci
// ON MACHINE. . Hak-Laptop
// STARTED ON. . Tue Jan 21 08:19:15 2014

/**
 * This is the main entry file for running "<bf>OSF Version 1</bf>",
 * which defines a primitive OSF constraint language. (See <a
 * href="OsfV2.html">OsfV2.grm</a> for details.)
 *
 * <p>
 * 
 * @version     Last modified on Mon Feb 17 08:21:21 2014 by hak
 * @author      <a href="mailto:hak@acm.org">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; <a href="http://www.hassan-ait-kaci.net/">by the author</a>
 */

package hlt.osf.v2;

import java.io.File;
import java.io.IOException;

import hlt.language.util.Error;

import hlt.osf.util.BitCode;

public class OsfV2Main
{
  final static void welcome ()
    {
      System.out.println();
      System.out.println("**********************************************************");
      System.out.println("***                                                    ***");
      System.out.println("*** This is HLT's OSF Prototype Version 2.0 - Welcome! ***");
      System.out.println("***                                                    ***");
      System.out.println("**********************************************************");
      System.out.println();
      System.out.println("*** Interactive mode: type '%help.' for known pragmas.");
      System.out.println();
    }

  final static void exit ()
    {
      System.out.println();
      System.out.println();
      System.out.println("**********************************************************");
      System.out.println("*** Exiting HLT's OSF Version 2.0 - Good Bye!          ***");
      System.out.println("**********************************************************");
      System.out.println();
      System.exit(0);
    }

  final public static void main (String args[])
    {
      OsfV2Tokenizer tokenizer = new OsfV2Tokenizer();
      OsfV2Parser parser = new OsfV2Parser(tokenizer);

      welcome();

      BitCode.setOnChar('+');
      BitCode.setOffChar('-');

      try
        {
          for (int i=0; i<args.length; i++)
            {
              parser.displayLine("*** Loading file: "+args[i]);
              parser.parse(args[i]);
            }
          tokenizer.setInteractive();
	  parser.setTreeType("XML");
          parser.parse();
        }
      catch (IOException e)
        {
          parser.errorManager().reportError(new Error().setLabel("IO Error: ")
					    .setMsg(e.getMessage()+" aborting")
					    .setSee("..."));
        }
      catch (Throwable e)
        {
          parser.errorManager().reportError(new Error().setLabel("Fatal Error: ")
                                            .setMsg("aborting")
                                            .setSee("..."));
          e.printStackTrace();
        }
      finally
        {
          exit();
        }
    }
}
