package nxm.sys.intr;

import nxm.sys.lib.Intrinsic;

/**
  Handles trapping of errors in the macro language.

  @author Jeff Schoen

*/
public class Trap extends Intrinsic {

  /** default constructor */
  public Trap () {}

  public int process() {

    String type = MA.getS("TYPE");
    String label = MA.getS("LABEL");
    boolean quiet = MA.getState("QUIET");

    if (M.macro == null) {
      M.warning("No macro executing ...");
    }
    else if (type.startsWith("ERR") || type.equals("ON")) {
      M.macro.setTrapHandler(label,quiet);
    }
    else if (type.startsWith("WARN")) {
      M.macro.setTrapHandler(label,quiet);
    }
    else if (type.equals("OFF")) {
      M.macro.setTrapHandler("OFF",quiet);
    }
    else {
      M.info("Unsupported trap type="+type);
    }
    return (FINISH);
  }
}

