// FILE. . . . . /home/hak/hlt/src/hlt/osf/apps/v0/sources/OsfV0Main.java
// EDIT BY . . . Hassan Ait-Kaci
// ON MACHINE. . Hp-Dv7
// STARTED ON. . Fri Nov 02 18:15:16 2012

/**
 * This is the main entry file for running "<bf>OSF Version 0</bf>",
 * which defines a primitive OSF constraint language. (See <a
 * href="OsfV0.html">OsfV0.grm</a> for details.)
 *
 * <p>
 * 
 * @version     Last modified on Mon Nov 26 18:18:36 2012 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.v0;

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

import hlt.language.util.Error;

import hlt.osf.util.BitCode;

public class OsfV0Main
{
  final static void welcome ()
    {
      System.out.println();
      System.out.println("********************************************************");
      System.out.println("***                                                  ***");
      System.out.println("*** This is HLT's OSF Prototype Version 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 0 - Good Bye!          ***");
      System.out.println("********************************************************");
      System.out.println();
      System.exit(0);
    }

  final public static void main (String args[])
    {
      OsfV0Tokenizer tokenizer = new OsfV0Tokenizer();
      OsfV0Parser parser = new OsfV0Parser(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.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();
        }
    }
}
