|
| 1 | +/* |
| 2 | + * ExecShellWaitInstruction.java |
| 3 | + */ |
| 4 | + |
| 5 | +package nsl.instruction; |
| 6 | + |
| 7 | +import java.io.IOException; |
| 8 | +import java.util.ArrayList; |
| 9 | +import java.util.EnumSet; |
| 10 | +import nsl.*; |
| 11 | +import nsl.expression.*; |
| 12 | + |
| 13 | +/** |
| 14 | + * @author Jan |
| 15 | + */ |
| 16 | +public class ExecShellWaitInstruction extends AssembleExpression |
| 17 | +{ |
| 18 | + public static final String name = "ExecShellWait"; |
| 19 | + private final Expression action; |
| 20 | + private final Expression command; |
| 21 | + private final Expression parameters; |
| 22 | + private final Expression show; |
| 23 | + |
| 24 | + /** |
| 25 | + * Class constructor. |
| 26 | + * @param returns the number of values to return |
| 27 | + */ |
| 28 | + public ExecShellWaitInstruction(int returns) |
| 29 | + { |
| 30 | + if (!SectionInfo.in() && !FunctionInfo.in()) |
| 31 | + throw new NslContextException(EnumSet.of(NslContext.Section, NslContext.Function), name); |
| 32 | + if (returns > 1) |
| 33 | + throw new NslReturnValueException(name, 0, 1); |
| 34 | + |
| 35 | + ArrayList<Expression> paramsList = Expression.matchList(); |
| 36 | + int paramsCount = paramsList.size(); |
| 37 | + if (paramsCount < 2 || paramsCount > 4) |
| 38 | + throw new NslArgumentException(name, 2, 4); |
| 39 | + |
| 40 | + this.action = paramsList.get(0); |
| 41 | + |
| 42 | + this.command = paramsList.get(1); |
| 43 | + |
| 44 | + if (paramsCount > 2) |
| 45 | + { |
| 46 | + this.parameters = paramsList.get(2); |
| 47 | + |
| 48 | + if (paramsCount > 3) |
| 49 | + this.show = paramsList.get(3); |
| 50 | + else |
| 51 | + this.show = null; |
| 52 | + } |
| 53 | + else |
| 54 | + { |
| 55 | + this.parameters = null; |
| 56 | + this.show = null; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Assembles the source code. |
| 62 | + */ |
| 63 | + @Override |
| 64 | + public void assemble() throws IOException |
| 65 | + { |
| 66 | + Expression varOrAction = AssembleExpression.getRegisterOrExpression(this.action); |
| 67 | + Expression varOrCommand = AssembleExpression.getRegisterOrExpression(this.command); |
| 68 | + if (this.parameters != null) |
| 69 | + { |
| 70 | + AssembleExpression.assembleIfRequired(this.parameters); |
| 71 | + if (this.show != null) |
| 72 | + { |
| 73 | + AssembleExpression.assembleIfRequired(this.show); |
| 74 | + ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand + " " + this.parameters + " " + this.show); |
| 75 | + } |
| 76 | + else |
| 77 | + { |
| 78 | + ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand + " " + this.parameters); |
| 79 | + } |
| 80 | + } |
| 81 | + else |
| 82 | + { |
| 83 | + ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand); |
| 84 | + } |
| 85 | + varOrAction.setInUse(false); |
| 86 | + varOrCommand.setInUse(false); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Assembles the source code. |
| 91 | + * @param var the variable to assign the value to |
| 92 | + */ |
| 93 | + @Override |
| 94 | + public void assemble(Register var) throws IOException |
| 95 | + { |
| 96 | + Expression varOrAction = AssembleExpression.getRegisterOrExpression(this.action); |
| 97 | + Expression varOrCommand = AssembleExpression.getRegisterOrExpression(this.command); |
| 98 | + if (this.parameters != null) |
| 99 | + { |
| 100 | + AssembleExpression.assembleIfRequired(this.parameters); |
| 101 | + if (this.show != null) |
| 102 | + { |
| 103 | + AssembleExpression.assembleIfRequired(this.show); |
| 104 | + ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand + " " + this.parameters + " " + this.show + " " + var); |
| 105 | + } |
| 106 | + else |
| 107 | + { |
| 108 | + ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand + " " + this.parameters + " " + var); |
| 109 | + } |
| 110 | + } |
| 111 | + else |
| 112 | + { |
| 113 | + ScriptParser.writeLine(name + " " + varOrAction + " " + varOrCommand + " " + var); |
| 114 | + } |
| 115 | + varOrAction.setInUse(false); |
| 116 | + varOrCommand.setInUse(false); |
| 117 | + } |
| 118 | +} |
0 commit comments