package nxm.sys.intr;

import nxm.sys.inc.LimitedFutureSupport;
import nxm.sys.lib.Intrinsic;
import nxm.sys.lib.Shell;
import nxm.sys.lib.Time;

/** Causes the system to beep.

    @author Mike King
 */
@LimitedFutureSupport("This macro command does not work in RHEL 6")
public class Beep extends Intrinsic {

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

  public int process() {
    String func = MA.getU("FUNC");

    if (func.equals("ON")) {
      M.verify |= Verify.BEEP;
//      MR.put("ENV.VERIFY",Parser.mask2s(Verify.verifyList,M.verify));
    }
    else if (func.equals("OFF")) {
      M.verify &= ~Verify.BEEP;
//      MR.put("ENV.VERIFY",Parser.mask2s(Verify.verifyList,M.verify));
    }
    else {
      int times = MA.getL("FUNC");
      double delay = MA.getD("DELAY");
      for (int i=0; i<times;) {
        Shell.beep();
        if (++i<times) Time.sleep(delay);
      }
    }

    return FINISH;
  }
}
