package nxm.sys.intr;

import nxm.sys.lib.Intrinsic;
import nxm.sys.lib.Midas;
import nxm.sys.lib.Shell;

/**
  Handles starting a macro.

  @author Jeff Schoen

  @see Endmacro
*/
public class Startmacro extends Intrinsic {

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

  public int process() {
    if (M.macro == null) {
      M.error("No macro executing ...");
    } else if (M.macro.level != 0) {
      M.error("Macro not at root level - structural error ...");
    }

    Midas pM = M.macro.getParentContext();

    if (pM!=null && pM.macro!=null && pM.macro.args!=null) {
      pM.macro.args.propagateSwitchesTo (M.macro.args);
    }

    M.msglog = MA.getS("/MSGLOG",null);

    // auto start pipe modes
    if (MA.getState("/PIPE")) Shell.runCommand(M,"PIPE,ON");
    if (MA.getState("/XPIPE")) Shell.runCommand(M,"XPIPE,ON");

    return (FINISH);
  }
}

