1 22 23 package org.netbeans.lib.terminalemulator; 24 25 import java.util.Stack ; 26 27 31 public class InterpDumb extends AbstractInterp { 32 33 protected static class InterpTypeDumb { 34 public final State st_base = new State("base"); 36 protected final Actor act_nop = new ACT_NOP(); 37 protected final Actor act_pause = new ACT_PAUSE(); 38 protected final Actor act_err = new ACT_ERR(); 39 protected final Actor act_regular = new ACT_REGULAR(); 40 protected final Actor act_cr = new ACT_CR(); 41 protected final Actor act_lf = new ACT_LF(); 42 protected final Actor act_bs = new ACT_BS(); 43 protected final Actor act_tab = new ACT_TAB(); 44 protected final Actor act_beL = new ACT_BEL(); 45 46 protected InterpTypeDumb() { 47 st_base.setRegular(st_base, act_regular); 48 49 for (char c = 0; c < 128; c++) 50 st_base.setAction(c, st_base, act_regular); 51 52 st_base.setAction((char) 0, st_base, act_pause); 53 st_base.setAction('\r', st_base, act_cr); 54 st_base.setAction('\n', st_base, act_lf); 55 st_base.setAction('\b', st_base, act_bs); 56 st_base.setAction('\t', st_base, act_tab); 57 st_base.setAction((char) 7, st_base, act_beL); 58 } 59 60 protected static final class ACT_NOP implements Actor { 61 public String action(AbstractInterp ai, char c) { 62 return null; 63 } 64 }; 65 66 protected static final class ACT_PAUSE implements Actor { 67 public String action(AbstractInterp ai, char c) { 68 ai.ops.op_pause(); 69 return null; 70 } 71 }; 72 73 protected static final class ACT_ERR implements Actor { 74 public String action(AbstractInterp ai, char c) { 75 return "ACT ERROR"; } 77 }; 78 79 protected static final class ACT_REGULAR implements Actor { 80 public String action(AbstractInterp ai, char c) { 81 ai.ops.op_char(c); 82 return null; 83 } 84 }; 85 86 87 protected static final class ACT_CR implements Actor { 88 public String action(AbstractInterp ai, char c) { 89 ai.ops.op_carriage_return(); 90 return null; 91 } 92 }; 93 94 protected static final class ACT_LF implements Actor { 95 public String action(AbstractInterp ai, char c) { 96 ai.ops.op_line_feed(); 97 return null; 98 } 99 }; 100 101 102 protected static final class ACT_BS implements Actor { 103 public String action(AbstractInterp ai, char c) { 104 ai.ops.op_back_space(); 105 return null; 106 } 107 }; 108 109 protected static final class ACT_TAB implements Actor { 110 public String action(AbstractInterp ai, char c) { 111 ai.ops.op_tab(); 112 return null; 113 } 114 }; 115 116 protected static final class ACT_BEL implements Actor { 117 public String action(AbstractInterp ai, char c) { 118 ai.ops.op_bel(); 119 return null; 120 } 121 } 122 } 123 124 127 private Stack stack = new Stack (); 128 129 protected void push_state(State s) { 130 stack.push(s); 131 } 132 133 protected State pop_state() { 134 return (State) stack.pop(); 135 } 136 137 protected void pop_all_states() { 138 while(!stack.empty()) 139 stack.pop(); 140 } 141 142 143 protected String ctl_sequence = null; 144 145 private InterpTypeDumb type; 146 147 public static final InterpTypeDumb type_singleton = new InterpTypeDumb(); 148 149 public InterpDumb(Ops ops) { 150 super(ops); 151 this.type = type_singleton; 152 setup(); 153 ctl_sequence = null; 154 } 155 156 protected InterpDumb(Ops ops, InterpTypeDumb type) { 157 super(ops); 158 this.type = type; 159 setup(); 160 ctl_sequence = null; 161 } 162 163 public String name() { 164 return "dumb"; } 166 167 public void reset() { 168 super.reset(); 169 pop_all_states(); 170 state = type.st_base; 171 ctl_sequence = null; 172 } 173 174 private void setup() { 175 state = type.st_base; 176 } 177 178 179 private void reset_state_bad() { 180 194 reset(); 195 } 196 197 public void processChar(char c) { 198 199 if (ctl_sequence != null) 201 ctl_sequence += c; 202 203 try { 204 State.Action a = state.getAction(c); 205 215 String err_str = a.actor.action(this, c); 216 if (err_str != null) { 217 220 reset_state_bad(); 221 return; 222 } 223 224 if (a.new_state != null) 225 state = a.new_state; 226 else 227 ; 229 } finally { 230 if (state == type.st_base) 231 ctl_sequence = null; 232 } 233 } 234 235 238 239 } 240 | Popular Tags |