1 22 23 29 30 package org.netbeans.lib.terminalemulator; 31 32 public class InterpANSI extends InterpDumb { 33 34 protected static class InterpTypeANSI extends InterpTypeDumb { 35 protected final State st_esc = new State("esc"); protected final State st_esc_lb = new State("esc_lb"); 38 protected final Actor act_reset_number = new ACT_RESET_NUMBER(); 39 protected final Actor act_remember_digit = new ACT_REMEMBER_DIGIT(); 40 41 protected InterpTypeANSI() { 42 st_base.setAction((char) 27, st_esc, new ACT_TO_ESC()); 43 44 st_esc.setRegular(st_esc, act_regular); 45 st_esc.setAction('7', st_base, new ACT_SC()); 46 st_esc.setAction('8', st_base, new ACT_RC()); 47 st_esc.setAction('c', st_base, new ACT_FULL_RESET()); 48 st_esc.setAction('[', st_esc_lb, act_reset_number); 49 50 51 st_esc_lb.setRegular(st_esc_lb, act_regular); 52 for (char c = '0'; c <= '9'; c++) 53 st_esc_lb.setAction(c, st_esc_lb, act_remember_digit); 54 st_esc_lb.setAction(';', st_esc_lb, new ACT_PUSH_NUMBER()); 55 st_esc_lb.setAction('A', st_base, new ACT_UP()); 56 st_esc_lb.setAction('B', st_base, new ACT_DO()); 57 st_esc_lb.setAction('C', st_base, new ACT_ND()); 58 st_esc_lb.setAction('D', st_base, new ACT_BC()); 59 st_esc_lb.setAction('H', st_base, new ACT_HO()); 60 st_esc_lb.setAction('i', st_base, new ACT_PRINT()); 61 st_esc_lb.setAction('J', st_base, new ACT_J()); 62 st_esc_lb.setAction('K', st_base, new ACT_K()); 63 st_esc_lb.setAction('L', st_base, new ACT_AL()); 64 st_esc_lb.setAction('M', st_base, new ACT_DL()); 65 st_esc_lb.setAction('m', st_base, new ACT_ATTR()); 66 st_esc_lb.setAction('n', st_base, new ACT_DSR()); 67 st_esc_lb.setAction('P', st_base, new ACT_DC()); 68 st_esc_lb.setAction('h', st_base, new ACT_SM()); 69 st_esc_lb.setAction('l', st_base, new ACT_RM()); 70 st_esc_lb.setAction('r', st_base, new ACT_MARGIN()); 71 st_esc_lb.setAction('t', st_base, new ACT_GLYPH()); 72 st_esc_lb.setAction('@', st_base, new ACT_IC()); 73 } 74 75 protected static final class ACT_TO_ESC implements Actor { 76 public String action(AbstractInterp ai, char c) { 77 InterpDumb i = (InterpDumb) ai; 78 i.ctl_sequence = ""; return null; 80 } 81 } 82 83 protected static final class ACT_SC implements Actor { 84 public String action(AbstractInterp ai, char c) { 85 ai.ops.op_sc(); 86 return null; 87 } 88 } 89 protected static final class ACT_RC implements Actor { 90 public String action(AbstractInterp ai, char c) { 91 ai.ops.op_rc(); 92 return null; 93 } 94 } 95 protected static final class ACT_FULL_RESET implements Actor { 96 public String action(AbstractInterp ai, char c) { 97 ai.ops.op_full_reset(); 98 return null; 99 } 100 } 101 102 protected static class ACT_RESET_NUMBER implements Actor { 103 public String action(AbstractInterp ai, char c) { 104 ai.resetNumber(); 105 return null; 106 } 107 }; 108 109 protected static class ACT_REMEMBER_DIGIT implements Actor { 110 public String action(AbstractInterp ai, char c) { 111 ai.remember_digit(c); 112 return null; 113 } 114 }; 115 116 protected static final class ACT_PUSH_NUMBER implements Actor { 117 public String action(AbstractInterp ai, char c) { 118 if (!ai.pushNumber()) 119 return "ACT PUSH_NUMBER"; return null; 121 } 122 } 123 protected static final class ACT_UP implements Actor { 124 public String action(AbstractInterp ai, char c) { 125 if (ai.noNumber()) 126 ai.ops.op_up(1); 127 else 128 ai.ops.op_up(ai.numberAt(0)); 129 return null; 130 } 131 } 132 protected static final class ACT_DO implements Actor { 133 public String action(AbstractInterp ai, char c) { 134 if (ai.noNumber()) 135 ai.ops.op_do(1); 136 else 137 ai.ops.op_do(ai.numberAt(0)); 138 return null; 139 } 140 } 141 protected static final class ACT_ND implements Actor { 142 public String action(AbstractInterp ai, char c) { 143 if (ai.noNumber()) 144 ai.ops.op_nd(1); 145 else 146 ai.ops.op_nd(ai.numberAt(0)); 147 return null; 148 } 149 } 150 protected static final class ACT_BC implements Actor { 151 public String action(AbstractInterp ai, char c) { 152 if (ai.noNumber()) 153 ai.ops.op_bc(1); 154 else 155 ai.ops.op_bc(ai.numberAt(0)); 156 return null; 157 } 158 } 159 protected static final class ACT_MARGIN implements Actor { 160 public String action(AbstractInterp ai, char c) { 161 if (ai.noNumber()) 162 ai.ops.op_margin(0, 0); 163 else 164 ai.ops.op_margin(ai.numberAt(0), ai.numberAt(1)); 165 return null; 166 } 167 } 168 protected static final class ACT_DC implements Actor { 169 public String action(AbstractInterp ai, char c) { 170 if (ai.noNumber()) 171 ai.ops.op_dc(1); 172 else 173 ai.ops.op_dc(ai.numberAt(0)); 174 return null; 175 } 176 } 177 178 protected static final class ACT_SM implements Actor { 179 public String action(AbstractInterp ai, char c) { 180 if (ai.noNumber()) 181 ai.ops.op_set_mode(1); 182 else 183 ai.ops.op_set_mode(ai.numberAt(0)); 184 return null; 185 } 186 } 187 188 protected static final class ACT_RM implements Actor { 189 public String action(AbstractInterp ai, char c) { 190 if (ai.noNumber()) 191 ai.ops.op_reset_mode(1); 192 else 193 ai.ops.op_reset_mode(ai.numberAt(0)); 194 return null; 195 } 196 } 197 198 protected static final class ACT_IC implements Actor { 199 public String action(AbstractInterp ai, char c) { 200 if (ai.noNumber()) 201 ai.ops.op_ic(1); 202 else 203 ai.ops.op_ic(ai.numberAt(0)); 204 return null; 205 } 206 } 207 protected static final class ACT_DL implements Actor { 208 public String action(AbstractInterp ai, char c) { 209 if (ai.noNumber()) { 210 ai.ops.op_dl(1); 211 } else { 212 ai.ops.op_dl(ai.numberAt(0)); 213 } 214 return null; 215 } 216 } 217 protected static final class ACT_HO implements Actor { 218 public String action(AbstractInterp ai, char c) { 219 if (ai.noNumber()) { 220 ai.ops.op_ho(); 221 } else { 222 ai.ops.op_cm(ai.numberAt(0), ai.numberAt(1)); } 224 return null; 225 } 226 } 227 protected static final class ACT_PRINT implements Actor { 228 public String action(AbstractInterp ai, char c) { 229 if (ai.noNumber()) { 231 } else { 233 switch (ai.numberAt(0)) { 234 case 1: case 4: case 5: break; 238 case 10: 239 ai.ops.op_time(true); 240 break; 241 case 11: 242 ai.ops.op_time(false); 243 break; 244 } 245 } 246 return null; 247 } 248 } 249 protected static final class ACT_J implements Actor { 250 public String action(AbstractInterp ai, char c) { 251 if (ai.noNumber()) { 252 ai.ops.op_cd(); 253 } else { 254 int count = ai.numberAt(0); 255 if (count == 1) { 256 return "ACT J: count of 1 not supported"; } else if (count == 2) { 258 ai.ops.op_cl(); 259 } 260 } 261 return null; 262 } 263 } 264 protected static final class ACT_K implements Actor { 265 public String action(AbstractInterp ai, char c) { 266 if (ai.noNumber()) { 267 ai.ops.op_ce(); 268 } else { 269 int count = ai.numberAt(0); 270 if (count == 1) { 271 return "ACT K: count of 1 not supported"; } else if (count == 2) { 273 return "ACT K: count of 2 not supported"; } 275 } 276 return null; 277 } 278 } 279 protected static final class ACT_AL implements Actor { 280 public String action(AbstractInterp ai, char c) { 281 if (ai.noNumber()) { 282 ai.ops.op_al(1); 283 } else { 284 ai.ops.op_al(ai.numberAt(0)); 285 } 286 return null; 287 } 288 } 289 290 protected static final class ACT_ATTR implements Actor { 291 public String action(AbstractInterp ai, char c) { 292 if (ai.noNumber()) { 294 ai.ops.op_attr(0); } else { 296 for (int n = 0; n <= ai.nNumbers(); n++) 297 ai.ops.op_attr(ai.numberAt(n)); 298 } 299 return null; 300 } 301 } 302 303 protected static final class ACT_DSR implements Actor { 304 public String action(AbstractInterp ai, char c) { 306 if (ai.noNumber()) { 307 ai.ops.op_status_report(5); } else { 309 ai.ops.op_status_report(ai.numberAt(0)); 310 } 311 return null; 312 } 313 } 314 315 protected static final class ACT_GLYPH implements Actor { 316 public String action(AbstractInterp ai, char c) { 317 if (ai.noNumber()) { 318 return "ACT GLYPH: missing number"; } else { 320 int p1 = ai.numberAt(0); 321 int p2 = ai.numberAt(1); 322 int p3 = ai.numberAt(2); 323 if (p1 == 22) { 324 ai.ops.op_glyph(p2, p3); 325 } else { 326 return "ACT GLYPH: op othger than 22 not supported"; } 328 } 329 return null; 330 } 331 } 332 } 333 334 private InterpTypeANSI type; 335 336 public static final InterpTypeANSI type_singleton = new InterpTypeANSI(); 337 338 public InterpANSI(Ops ops) { 339 super(ops, type_singleton); 340 this.type = type_singleton; 341 setup(); 342 } 343 344 protected InterpANSI(Ops ops, InterpTypeANSI type) { 345 super(ops, type); 346 this.type = type; 347 setup(); 348 } 349 350 public String name() { 351 return "ansi"; } 353 354 public void reset() { 355 super.reset(); 356 } 357 358 private void setup() { 359 state = type.st_base; 360 } 361 } 362 | Popular Tags |