source: trunk/src/org/expeditee/actions/Simple.java@ 97

Last change on this file since 97 was 97, checked in by ra33, 16 years ago

Lots of changes!!

File size: 84.2 KB
Line 
1package org.expeditee.actions;
2
3import java.awt.Color;
4import java.awt.Point;
5import java.awt.event.InputEvent;
6import java.io.BufferedReader;
7import java.io.InputStreamReader;
8import java.util.ArrayList;
9import java.util.Collection;
10import java.util.HashMap;
11import java.util.LinkedList;
12import java.util.List;
13import java.util.Map;
14import java.util.Random;
15
16import org.expeditee.agents.DefaultAgent;
17import org.expeditee.agents.DisplayTree;
18import org.expeditee.agents.WriteTree;
19import org.expeditee.gui.AttributeUtils;
20import org.expeditee.gui.DisplayIO;
21import org.expeditee.gui.Frame;
22import org.expeditee.gui.FrameGraphics;
23import org.expeditee.gui.FrameIO;
24import org.expeditee.gui.FrameKeyboardActions;
25import org.expeditee.gui.FrameMouseActions;
26import org.expeditee.gui.FrameUtils;
27import org.expeditee.io.Conversion;
28import org.expeditee.items.Dot;
29import org.expeditee.items.Item;
30import org.expeditee.items.ItemUtils;
31import org.expeditee.items.Line;
32import org.expeditee.items.Text;
33import org.expeditee.items.Item.SelectedMode;
34import org.expeditee.simple.AboveMaxParametreCountException;
35import org.expeditee.simple.BelowMinParametreCountException;
36import org.expeditee.simple.Context;
37import org.expeditee.simple.IncorrectParametreCountException;
38import org.expeditee.simple.IncorrectTypeException;
39import org.expeditee.simple.Pointers;
40import org.expeditee.simple.Primitives;
41import org.expeditee.simple.SBoolean;
42import org.expeditee.simple.SCharacter;
43import org.expeditee.simple.SInteger;
44import org.expeditee.simple.SPointer;
45import org.expeditee.simple.SPrimitive;
46import org.expeditee.simple.SReal;
47import org.expeditee.simple.SString;
48import org.expeditee.simple.SVariable;
49import org.expeditee.simple.UnitTestFailedException;
50import org.expeditee.stats.AgentStats;
51import org.expeditee.stats.SessionStats;
52
53public class Simple implements Runnable {
54
55 private static final String DEFAULT_STRING = "$s.";
56
57 private static final String DEFAULT_BOOLEAN = "$b.";
58
59 private static final String DEFAULT_CHAR = "$c.";
60
61 private static final String DEFAULT_INTEGER = "$i.";
62
63 private static final String DEFAULT_REAL = "$r.";
64
65 private static final String DEFAULT_ITEM = "$ip.";
66
67 private static final String DEFAULT_FRAME = "$fp.";
68
69 private static final String DEFAULT_ASSOCIATION = "$ap.";
70
71 private static final String EXIT_TEXT = "exitall";
72
73 private static enum Status {
74 Exit, OK, Break, Continue, Return, TrueIf, FalseIf;
75 };
76
77 private static final String BREAK2_TEXT = "exitrepeat";
78
79 private static final String BREAK_TEXT = "break";
80
81 private static final String CONTINUE2_TEXT = "nextrepeat";
82
83 private static final String CONTINUE_TEXT = "continue";
84
85 private static final String RETURN_TEXT = "return";
86
87 private static final String LOOP_TEXT = "repeat";
88
89 private static final String TOKEN_SEPARATOR = " +";
90
91 public static final String RUN_FRAME_ACTION = "runframe";
92
93 public static final String DEBUG_FRAME_ACTION = "debugframe";
94
95 /**
96 * Keeps track of how many simple programs are running. Used to check if
97 * simple should read in keyboard input. Or if the keyboard input should be
98 * handled normally by Expeditee.
99 */
100 private static int _programsRunning = 0;
101
102 /**
103 * This flag is set to true if Simple should hijack keyboard input from
104 * Expeditee
105 */
106 private static boolean _consumeKeyboardInput = false;
107
108 public static void ProgramFinished() {
109 _programsRunning--;
110 _stop = false;
111 }
112
113 private static LinkedList<Character> _KeyStrokes = new LinkedList<Character>();
114
115 private static boolean _stop;
116
117 private static boolean _step;
118
119 private static int _stepPause = -1;
120
121 private static Color _stepColor;
122
123 private static boolean _nextStatement;
124
125 public static void KeyStroke(char c) {
126 _KeyStrokes.add(c);
127 }
128
129 public static boolean isProgramRunning() {
130 return _programsRunning > 0;
131 }
132
133 public static boolean consumeKeyboardInput() {
134 return _consumeKeyboardInput && _programsRunning > 0;
135 }
136
137 public static void NewSimpleTest() {
138 Frame newSimpleTest = FrameIO.CreateFrame(DisplayIO.getCurrentFrame()
139 .getFramesetName(), "Test", null);
140 List<String> actions = new ArrayList<String>();
141 actions.add(RUN_FRAME_ACTION);
142 newSimpleTest.getTitleItem().setActions(actions);
143 FrameUtils.DisplayFrame(newSimpleTest, true);
144 FrameGraphics.DisplayMessage("New test created");
145 }
146
147 public static void NextTest() {
148 Frame next = DisplayIO.getCurrentFrame();
149 do {
150 next = FrameIO.LoadNext(next);
151 } while (next != null && next.isTestFrame());
152 FrameUtils.DisplayFrame(next, true);
153 }
154
155 public static void PreviousTest() {
156 Frame prev = DisplayIO.getCurrentFrame();
157 do {
158 prev = FrameIO.LoadPrevious(prev);
159 } while (prev != null && prev.isTestFrame());
160
161 FrameUtils.DisplayFrame(prev, true);
162 }
163
164 public static void LastTest() {
165 Frame next = FrameIO.LoadLast();
166 Frame lastTest = null;
167 do {
168 // check if its a test frame
169 if (next != null && next.isTestFrame()) {
170 lastTest = next;
171 break;
172 }
173
174 next = FrameIO.LoadPrevious(next);
175 } while (next != null);
176
177 FrameUtils.DisplayFrame(lastTest, true);
178 }
179
180 public static void RunSimpleTests(String frameset) {
181 RunSimpleTests(frameset, false, true);
182 }
183
184 public static void RunSimpleTestsVerbose(String frameset) {
185 RunSimpleTests(frameset, true, true);
186 }
187
188 private String _frameset;
189
190 private boolean _verbose;
191
192 public Simple(String frameset, boolean verbose) {
193 _frameset = frameset;
194 _verbose = verbose;
195 }
196
197 public void run() {
198 runSuite();
199 }
200
201 public boolean runSuite() {
202 int testsPassed = 0;
203 int testsFailed = 0;
204
205 FrameIO.SaveFrame(DisplayIO.getCurrentFrame(), false);
206 FrameGraphics.DisplayMessage("Starting test suite: " + _frameset,
207 Color.CYAN);
208
209 // Get the next number in the inf file for the _frameset
210 int lastFrameNo = FrameIO.getLastNumber(_frameset);
211
212 // Loop through all the valid frames in the _frameset
213 for (int i = 1; i <= lastFrameNo; i++) {
214 String nextFrameName = _frameset + i;
215 Frame nextFrame = FrameIO.LoadFrame(nextFrameName);
216 if (nextFrame == null)
217 continue;
218 Item frameTitle = nextFrame.getTitleItem();
219 if (frameTitle == null)
220 continue;
221 // Run the frames with the RunFrame action on the title
222 Item title = frameTitle.copy();
223 List<String> actions = title.getAction();
224 if (actions == null || title.isAnnotation())
225 continue;
226 if (actions.get(0).toLowerCase().equals("runframe")) {
227 boolean passed = true;
228 String errorMessage = null;
229 try {
230 title.setLink(nextFrameName);
231 // TODO add the ability to run a setup frame
232 // which sets up variables to be used in all
233 // tests
234 AgentStats.reset();
235 _KeyStrokes.clear();
236 _programsRunning++;
237 RunFrameAndReportError(title, new Context());
238 _programsRunning--;
239 // if the throws exception annotation is on the frame then
240 // it passes only if an exception is thrown
241 if (title.getParentOrCurrentFrame().hasAnnotation(
242 "ThrowsException")) {
243 errorMessage = "Expected exception " + title.toString();
244 passed = false;
245 }
246 } catch (Exception e) {
247 _programsRunning--;
248 if (!title.getParentOrCurrentFrame().hasAnnotation(
249 "ThrowsException")) {
250 errorMessage = e.getMessage();
251 passed = false;
252 }
253 }
254 if (passed) {
255 if (_verbose)
256 FrameGraphics.DisplayMessage("Test passed: "
257 + title.toString(), Item.GREEN);
258 testsPassed++;
259 } else {
260 testsFailed++;
261 // Print out the reason for failed tests
262 FrameGraphics.LinkedErrorMessage(errorMessage);
263 if (Simple._stop) {
264 Simple._stop = false;
265 return false;
266 }
267 }
268 }
269 }
270 // The statement below assumes there are no other programs running at
271 // the same time
272 assert (_programsRunning == 0);
273 // Report the number of test passed and failed
274 FrameGraphics.DisplayMessage("Total tests: "
275 + (testsPassed + testsFailed), Color.CYAN);
276 if (testsPassed > 0)
277 FrameGraphics.DisplayMessage("Passed: " + testsPassed, Item.GREEN);
278 if (testsFailed > 0)
279 FrameGraphics.DisplayMessage("Failed: " + testsFailed, Color.RED);
280 // Remove items from the cursor...
281 Frame.FreeItems.clear();
282
283 return testsFailed == 0;
284 }
285
286 /**
287 * Runs a suite of tests stored in a given frameset.
288 *
289 * @param frameset
290 * @param verbose
291 * @param newThread
292 * false if tests should be run on the current frame
293 */
294 public static void RunSimpleTests(String frameset, boolean verbose,
295 boolean newThread) {
296 _stop = false;
297 Simple testSuite = new Simple(frameset, verbose);
298 if (newThread) {
299 Thread t = new Thread(testSuite);
300 t.setPriority(Thread.MIN_PRIORITY);
301 t.start();
302 } else {
303 assert (testSuite.runSuite());
304 }
305
306 }
307
308 private static void RunFrame(Item current, boolean acceptKeyboardInput,
309 boolean step, int pause, Color color) {
310 try {
311 DisplayIO.addToBack(current.getParent());
312
313 _stepColor = color == null ? Color.green : color;
314 _stepColor = new Color(_stepColor.getRed(), _stepColor.getGreen(),
315 _stepColor.getBlue(), 50);
316 _stepPause = pause;
317 _step = step;
318 _consumeKeyboardInput = acceptKeyboardInput;
319 FrameIO.SaveFrame(DisplayIO.getCurrentFrame(), true);
320
321 // an item without a link signals to run the current frame
322 if (current.getLink() == null) {
323 current = current.copy();
324 current.setLink(DisplayIO.getCurrentFrame().getName());
325 }
326
327 _KeyStrokes.clear();
328
329 Thread t = new Thread(current);
330 t.setPriority(Thread.MIN_PRIORITY);
331 t.start();
332 } catch (Exception e) {
333 }
334 }
335
336 public static void RunFrame(Item current, boolean acceptKeyboardInput) {
337 RunFrame(current, acceptKeyboardInput, false, 0, null);
338 }
339
340 public static void RunFrame(Item current) {
341 RunFrame(current, false);
342 }
343
344 /**
345 * At present programs which accept keyboard input can not be debugged.
346 *
347 * @param current
348 * @param pause
349 */
350 public static void DebugFrame(Item current, double pause, Color color) {
351 RunFrame(current, false, true, (int) (pause * 1000 + 0.5), color);
352 }
353
354 /**
355 * At present programs which accept keyboard input can not be debugged.
356 *
357 * @param current
358 * @param pause
359 * the time to pause between
360 */
361 public static void DebugFrame(Item current, double pause) {
362 DebugFrame(current, pause, null);
363 }
364
365 public static void DebugFrame(Item current) {
366 DebugFrame(current, -1.0, null);
367 }
368
369 private static void FlagError(Item item) {
370 FrameUtils.DisplayFrame(item.getParent().getName(), true);
371 item.setSelectedMode(SelectedMode.Normal);
372 item.setSelectionColor(Color.CYAN);
373 FrameIO.SaveFrame(item.getParent());
374 }
375
376 /**
377 * Runs a simple code begining on a frame linked to by the specified item
378 * parametre.
379 *
380 * @param current
381 * the item that is linked to the frame to be run.
382 */
383 public static Status RunFrameAndReportError(Item current, Context context)
384 throws Exception {
385 // the item must link to a frame
386 if (current.getLink() == null) {
387 throw new Exception("Could not run unlinked item: "
388 + current.toString());
389 }
390
391 Frame child = FrameIO.LoadFrame(current.getAbsoluteLink());
392
393 if (_step) {
394 if (child != DisplayIO.getCurrentFrame()) {
395 DisplayIO.setCurrentFrame(child);
396 }
397 DisplayIO.addToBack(child);
398 }
399
400 AgentStats.FrameExecuted();
401
402 // if the frame could not be loaded
403 if (child == null) {
404 throw new Exception("Could not load item link: "
405 + current.toString());
406 }
407
408 // loop through non-title, non-name, text items
409 List<Text> body = child.getBodyTextItems(false);
410
411 // if no item was found
412 if (body.size() == 0)
413 throw new Exception("No code to be executed: " + current.toString());
414
415 Status lastItemStatus = Status.OK;
416 for (Text item : body) {
417 AgentStats.ItemExecuted();
418 try {
419 Color oldColor = item.getBackgroundColor();
420 if (_step) {
421 if (item.getLink() != null) {
422 pause(item);
423 item.setSelectedMode(Item.SelectedMode.Normal,
424 _stepColor);
425 } else {
426 item.setBackgroundColor(_stepColor);
427 }
428 FrameGraphics.Repaint();
429 }
430 lastItemStatus = RunItem(item, context, lastItemStatus);
431 if (_step) {
432 if (item.getLink() == null) {
433 item.setBackgroundColor(oldColor);
434 pause(item);
435 } else {
436 item.setSelectedMode(Item.SelectedMode.None);
437 }
438 }
439
440 if (lastItemStatus != Status.OK) {
441 if (lastItemStatus != Status.TrueIf
442 && lastItemStatus != Status.FalseIf) {
443 if (_step) {
444 DisplayIO.removeFromBack();
445 }
446 return lastItemStatus;
447 }
448 }
449 } catch (ArrayIndexOutOfBoundsException e) {
450 FlagError(item);
451 throw new Exception("Too few parametres: " + item.toString());
452 } catch (NullPointerException e) {
453 FlagError(item);
454 throw new Exception("Null pointer exception: "
455 + item.toString());
456 } catch (RuntimeException e) {
457 FlagError(item);
458 throw new Exception(e.getMessage() + " " + item.toString());
459 } catch (Exception e) {
460 throw new Exception(e.getMessage());
461 }
462 }
463
464 if (_step) {
465 DisplayIO.removeFromBack();
466 DisplayIO.setCurrentFrame(current.getParent());
467 }
468
469 return Status.OK;
470 }
471
472 /**
473 * @param item
474 * @param oldColor
475 * @throws Exception
476 * @throws InterruptedException
477 */
478 private static void pause(Text item) throws Exception, InterruptedException {
479 if (!_step)
480 return;
481
482 Color oldColor = item.getBackgroundColor();
483 item.setBackgroundColor(_stepColor);
484 item.setSelectedMode(Item.SelectedMode.None);
485
486 // Make sure we are on the frame with this item
487 Frame parent = item.getParentOrCurrentFrame();
488 if (!parent.equals(DisplayIO.getCurrentFrame())) {
489 DisplayIO.setCurrentFrame(parent);
490 }
491
492 FrameGraphics.Repaint();
493
494 int timeRemaining;
495 if (_stepPause < 0)
496 timeRemaining = Integer.MAX_VALUE;
497 else
498 timeRemaining = _stepPause;
499
500 while (timeRemaining > 0 && !_nextStatement) {
501 if (_stop) {
502 item.setBackgroundColor(oldColor);
503 item.setSelectedMode(SelectedMode.Normal, _stepColor);
504 throw new Exception("Program terminated");
505 }
506 Thread.sleep(DefaultAgent.TIMER_RESOLUTION);
507 timeRemaining -= DefaultAgent.TIMER_RESOLUTION;
508 }
509 _nextStatement = false;
510 // Turn off the highlighting
511 item.setBackgroundColor(oldColor);
512 }
513
514 private static void pause(double time) throws Exception {
515 for (int i = 0; i < time * 10; i++) {
516 if (_stop) {
517 throw new Exception("Program terminated");
518 }
519 Thread.yield();
520 Thread.sleep(100);
521 }
522 }
523
524 /**
525 * This method should be modified to parse strings correctly
526 *
527 * @param statement
528 * @return
529 */
530 private static String[] parseStatement(Text code) throws Exception {
531 String statement = code.getText().trim();
532 ArrayList<String> tokens = new ArrayList<String>();
533
534 // At the moment annotation items are ignored by the interpreter
535 // // Check special annotation tags for programs
536 // if (statement.length() > 0 && statement.charAt(0) == '@') {
537 // statement = statement.toLowerCase();
538 // // Flags the next unit test as being required to throw an exception
539 // if (statement.equals("@throwsexception")) {
540 // code.getParentOrCurrentFrame().setThrowsException(true);
541 // }
542 // return null;
543 // }
544
545 for (int i = 0; i < statement.length(); i++) {
546 char c = statement.charAt(i);
547 // ignore spaces
548 if (c != ' ') {
549 int startOfToken = i;
550 if (c == '\"') {
551 int endOfToken = statement.length() - 1;
552 // find the end of the string literal
553 while (statement.charAt(endOfToken) != '\"')
554 endOfToken--;
555 if (endOfToken > startOfToken) {
556 tokens.add(statement.substring(startOfToken,
557 endOfToken + 1));
558 } else {
559 throw new RuntimeException("Expected matching \" ");
560 }
561 break;
562 } else if (c == '#' || c == '/') {
563 break;
564 } else {
565 // read in a normal token
566 while (++i < statement.length()
567 && statement.charAt(i) != ' ')
568 ;
569 tokens.add(statement.substring(startOfToken, i)
570 .toLowerCase());
571 }
572 }
573 }
574
575 String[] a = new String[tokens.size()];
576 a = tokens.toArray(a);
577 code.setProcessedText(a);
578 return a;
579 }
580
581 /**
582 * Runs a SIMPLE procedure statement.
583 *
584 * @param tokens
585 * the parsed Call statement.
586 * @param code
587 * the expeditee item containing the procedure call and the link
588 * to the frame with the procedure code.
589 * @param context
590 * the current context from which the procedure call is being
591 * made.
592 * @throws Exception
593 * when errors occur in running the procedure.
594 */
595 private static Status Call(String[] tokens, Item code, Context context)
596 throws Exception {
597 // Check that the call statement is linked
598 if (code.getLink() == null)
599 throw new Exception("Unlinked call statement: " + code.toString());
600
601 Frame procedure = FrameIO.LoadFrame(code.getAbsoluteLink());
602
603 // Add call to the start of the title if it doesnt exist
604 // This makes the call and signature tokens counts match
605 String procedureTitle = procedure.getTitleItem().getFirstLine();
606 if (!procedureTitle.toLowerCase().startsWith("call "))
607 procedureTitle = "call " + procedureTitle;
608
609 // Check that the calling statement matches the procedure
610 // signature
611 String[] procedureSignature = procedureTitle.split(TOKEN_SEPARATOR);
612
613 // Check for the right amount of parametres
614 if (procedureSignature.length < tokens.length)
615 throw new Exception("Call statement has too many parametres: "
616 + code.toString());
617 else if (procedureSignature.length > tokens.length)
618 throw new Exception("Call statement has too few parametres: "
619 + code.toString());
620 // else if (procedureSignature[1].equals(tokens[1]))
621 // throw new Exception("Call statement and procedure name dont match: "
622 // + code.toString());
623
624 // create the new context for the sub procedure
625 Context newContext = new Context();
626 // Check that the types/prefixes match
627 for (int i = 2; i < tokens.length; i++) {
628 // TODO allow for auto casting of primitives
629 if (tokens[i].substring(1, 2).equals(
630 procedureSignature[i].substring(1, 2))) {
631 // Add the variables to the new context
632 if (Primitives.isPrimitive(tokens[i])) {
633 try {
634 // try and get the value for the variable
635 SPrimitive p = context.getPrimitives().getVariable(
636 tokens[i]);
637 newContext.getPrimitives()
638 .add(procedureSignature[i], p);
639 } catch (Exception e) {
640 // If an exception occurs the variable doesnt
641 // exist in the current context
642 // So the variable must be added to both context
643 context.getPrimitives().add(tokens[i], new SString(""));
644 newContext.getPrimitives().add(procedureSignature[i],
645 new SString(""));
646 }
647 } else if (Pointers.isPointer(tokens[i])) {
648 try {
649 // try and get the value for the variable
650 SPointer p = context.getPointers().getVariable(
651 tokens[i]);
652 newContext.getPointers().add(procedureSignature[i], p);
653 } catch (Exception e) {
654 // If an exception occurs the variable doesnt
655 // exist in the current context
656 // So the variable must be added to both context
657 context.getPointers().setObject(tokens[i], null);
658 newContext.getPointers().setObject(
659 procedureSignature[i], null);
660 }
661 } else
662 throw new Exception("Unrecognised variable type: "
663 + tokens[i] + " in " + code.toString());
664 } else
665 throw new IncorrectTypeException(procedureSignature[i], i);
666 }
667
668 // Follow the link and Run the code for the procedure
669 Status result = RunFrameAndReportError(code, newContext);
670 // If a return statement ends the procedure then we accept this as
671 // normal execution
672 switch (result) {
673 case Return:
674 result = Status.OK;
675 break;
676 case Break:
677 throw new Exception(BREAK_TEXT + " statement without matching "
678 + LOOP_TEXT + " in " + code.toString());
679 case Continue:
680 throw new Exception("");
681 }
682
683 // Now copy the values from the procedure context into the
684 // current context
685 for (int i = 2; i < tokens.length; i++) {
686 try {
687 if (Primitives.isPrimitive(tokens[i])) {
688 // try and get the value for the variable
689 SVariable p = context.getPrimitives()
690 .getVariable(tokens[i]);
691 SVariable newP = newContext.getPrimitives().getVariable(
692 procedureSignature[i]);
693 p.setValue(newP);
694 } else {
695 // try and get the value for the variable
696 SVariable p = context.getPointers().getVariable(tokens[i]);
697 SVariable newP = newContext.getPointers().getVariable(
698 procedureSignature[i]);
699 p.setValue(newP);
700 }
701 } catch (Exception e) {
702 assert (false);
703 }
704 }
705
706 return result;
707 }
708
709 /**
710 * Runs a text item on a frame as a SIMPLE statement. The statement is
711 * parsed and if it is a recognised SIMPLE keyword or procedure the code is
712 * executed.
713 *
714 * @param code
715 * the item containing the code to be executed.
716 * @param context
717 * @return
718 * @throws Exception
719 */
720 private static Status RunItem(Text code, Context context,
721 Status lastItemStatus) throws Exception {
722 if (_stop) {
723 throw new Exception("Program terminated");
724 }
725
726 String[] tokens = code.getProcessedText();
727
728 if (tokens == null) {
729 tokens = parseStatement(code);
730 }
731
732 // Annotation items are ignored after parsing running options
733 if (tokens == null) {
734 return Status.OK;
735 // Comments without links are ignored
736 } else if (tokens.length == 0) {
737 if (code.getLink() == null)
738 return Status.OK;
739 else
740 return RunFrameAndReportError(code, context);
741 }
742
743 // At present only set statements can have literals so they
744 // are the only statements that we have to worry about string
745 // literals
746 if (tokens[0].equals("call") && tokens.length >= 2) {
747 return Call(tokens, code, context);
748 // Check if the user wants to display a message
749 // Check for set statements
750 } else if (tokens[0].startsWith("set")) {
751 if (tokens[0].equals("set")) {
752 try {
753 // Check if we are setting variable to variable
754 if (tokens[2].startsWith(SVariable.prefix)
755 && tokens.length == 3) {
756 context.getPrimitives().set(tokens[1], tokens[2]);
757 }
758 // Otherwise we are setting a variable with a literal
759 else {
760 // check for strings enclosed in quotes
761 if (tokens[2].startsWith("\"")) {
762 context.getPrimitives().setValue(
763 tokens[1],
764 new SString(tokens[2].substring(1,
765 tokens[2].length() - 1)));
766 // set a literal
767 } else if (tokens.length == 3) {
768 context.getPrimitives().setValue(tokens[1],
769 tokens[2]);
770 }
771 }
772 } catch (Exception e) {
773 throw new RuntimeException(e.getMessage());
774 }
775 } else if (tokens[0].equals("setassociation")) {
776 assertExactParametreCount(tokens, 3);
777
778 Map map = (Map) context.getPointers().getVariable(tokens[1])
779 .getValue();
780 String attribute = context.getPrimitives().getStringValue(
781 tokens[2]);
782 String value = context.getPrimitives()
783 .getStringValue(tokens[3]);
784 map.put(attribute, value);
785 } else if (tokens[0].equals("setframevalue")) {
786 assertMinParametreCount(tokens, 3);
787 assertVariableType(tokens[1], 1, SPointer.framePrefix);
788
789 // Get the attribute to be searched for on the target frame
790 Frame targetFrame = (Frame) context.getPointers().getVariable(
791 tokens[1]).getValue();
792 String targetAttribute = context.getPrimitives()
793 .getStringValue(tokens[2]).toLowerCase()
794 + ":";
795 String value = context.getPrimitives()
796 .getStringValue(tokens[3]);
797 Boolean found = false;
798 Text attributeItem = null;
799 Item valueItem = null;
800 // Begin the search
801 for (Text text : targetFrame.getBodyTextItems(true)) {
802 String s = text.getText().toLowerCase();
803
804 if (s.startsWith(targetAttribute)) {
805 attributeItem = text;
806 AttributeUtils.replaceValue(attributeItem, value);
807 found = true;
808 break;
809 }
810 }
811 // Keep looking for a matching value nearby if we found an
812 // attribute without the value in the same item
813 if (!found && attributeItem != null) {
814 Point endPoint = attributeItem.getEndParagraphPosition();
815
816 for (Text text : targetFrame.getBodyTextItems(true)) {
817 Point startPoint = text.getPosition();
818 if (Math.abs(startPoint.y - endPoint.y) < 10
819 && Math.abs(startPoint.x - endPoint.x) < 20) {
820 found = true;
821 valueItem = text;
822 text.setText(value);
823 break;
824 }
825 }
826 }
827
828 // Set the values of the output parametres
829 if (tokens.length > 4) {
830 context.getPrimitives().setValue(tokens[4],
831 new SBoolean(found));
832 if (tokens.length > 5) {
833 context.getPointers().setObject(tokens[5],
834 attributeItem);
835 if (tokens.length > 6) {
836 context.getPointers().setObject(tokens[6],
837 valueItem);
838 }
839 }
840 }
841 } else if (tokens[0].startsWith("setitem")) {
842 if (tokens[0].equals("setitemposition")) {
843 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
844 // assertPrimitiveType(tokens[2], 2);
845 // assertPrimitiveType(tokens[3], 3);
846 Item item = (Item) context.getPointers().getVariable(
847 tokens[1]).getValue();
848 item.setPosition(context.getPrimitives().getVariable(
849 tokens[2]).integerValue().intValue(), context
850 .getPrimitives().getVariable(tokens[3])
851 .integerValue().intValue());
852 } else if (tokens[0].equals("setitemthickness")) {
853 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
854 // assertPrimitiveType(tokens[2], 2);
855 Item item = (Item) context.getPointers().getVariable(
856 tokens[1]).getValue();
857 item.setThickness(context.getPrimitives().getVariable(
858 tokens[2]).integerValue().intValue());
859 } else if (tokens[0].equals("setitemwidth")) {
860 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
861 // assertPrimitiveType(tokens[2], 2);
862 Item item = (Item) context.getPointers().getVariable(
863 tokens[1]).getValue();
864 item.setWidth(context.getPrimitives()
865 .getVariable(tokens[2]).integerValue().intValue());
866 } else if (tokens[0].equals("setitemsize")) {
867 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
868 // assertPrimitiveType(tokens[2], 2);
869 Item item = (Item) context.getPointers().getVariable(
870 tokens[1]).getValue();
871 item.setSize(context.getPrimitives().getVariable(tokens[2])
872 .integerValue().intValue());
873 } else if (tokens[0].equals("setitemlink")) {
874 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
875 // assertPrimitiveType(tokens[2], 2);
876 Item item = (Item) context.getPointers().getVariable(
877 tokens[1]).getValue();
878 item.setLink(context.getPrimitives().getVariable(tokens[2])
879 .stringValue());
880 } else if (tokens[0].equals("setitemdata")) {
881 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
882 // assertPrimitiveType(tokens[2], 2);
883 Item item = (Item) context.getPointers().getVariable(
884 tokens[1]).getValue();
885 item.setData(context.getPrimitives().getVariable(tokens[2])
886 .stringValue());
887 } else if (tokens[0].equals("setitemaction")) {
888 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
889 // assertPrimitiveType(tokens[2], 2);
890 Item item = (Item) context.getPointers().getVariable(
891 tokens[1]).getValue();
892 item.setAction(context.getPrimitives().getVariable(
893 tokens[2]).stringValue());
894 } else if (tokens[0].equals("setitemfillcolor")) {
895 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
896 // assertPrimitiveType(tokens[2], 2);
897 Item item = (Item) context.getPointers().getVariable(
898 tokens[1]).getValue();
899 String stringColor = context.getPrimitives().getVariable(
900 tokens[2]).stringValue();
901 item.setBackgroundColor((Color) Conversion.Convert(
902 Color.class, stringColor));
903 } else if (tokens[0].equals("setitemcolor")) {
904 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
905 // assertPrimitiveType(tokens[2], 2);
906 Item item = (Item) context.getPointers().getVariable(
907 tokens[1]).getValue();
908 String stringColor = context.getPrimitives().getVariable(
909 tokens[2]).stringValue();
910 item.setColor((Color) Conversion.Convert(Color.class,
911 stringColor));
912 } else if (tokens[0].equals("setitemtext")) {
913 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
914 // assertPrimitiveType(tokens[2], 2);
915 String newText = context.getPrimitives().getVariable(
916 tokens[2]).stringValue();
917 Text textItem = (Text) context.getPointers().getVariable(
918 tokens[1]).getValue();
919 textItem.setText(newText);
920 } else
921 throw new Exception("Unsupported setItem command: "
922 + code.toString());
923 } else if (tokens[0].equals("setstrchar")) {
924 assertExactParametreCount(tokens, 3);
925 StringBuffer s = new StringBuffer(context.getPrimitives()
926 .getStringValue(tokens[1]));
927 int pos = (int) context.getPrimitives().getIntegerValue(
928 tokens[2]);
929 char newChar = context.getPrimitives().getCharacterValue(
930 tokens[3]);
931 while (pos > s.length()) {
932 s.append(newChar);
933 }
934 s.setCharAt(pos - 1, newChar);
935
936 context.getPrimitives().setValue(tokens[1],
937 new SString(s.toString()));
938 } else if (tokens[0].equals("setcharinitem")) {
939 assertExactParametreCount(tokens, 4);
940 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
941
942 int row = (int) context.getPrimitives().getIntegerValue(
943 tokens[3]) - 1;
944 int col = (int) context.getPrimitives().getIntegerValue(
945 tokens[4]) - 1;
946 char newChar = context.getPrimitives().getCharacterValue(
947 tokens[2]);
948 Text item = (Text) context.getPointers().getVariable(tokens[1])
949 .getValue();
950 List<String> itemText = item.getTextList();
951
952 while (row >= itemText.size()) {
953 StringBuffer sb = new StringBuffer();
954 for (int i = 0; i <= col; i++)
955 sb.append(newChar);
956 itemText.add(sb.toString());
957 }
958 StringBuffer sb = new StringBuffer(itemText.get(row));
959 while (sb.length() <= col)
960 sb.append(newChar);
961 sb.setCharAt(col, newChar);
962
963 // set the modified string
964 itemText.set(row, sb.toString());
965 item.setTextList(itemText);
966 }
967 } else if (tokens[0].startsWith("assert")) {
968 if (tokens[0].equals("asserttrue")) {
969 assertExactParametreCount(tokens, 1);
970 if (!context.getPrimitives().getBooleanValue(tokens[1]))
971 throw new UnitTestFailedException("true", "false");
972 } else if (tokens[0].equals("assertfalse")) {
973 assertExactParametreCount(tokens, 1);
974 if (context.getPrimitives().getBooleanValue(tokens[1]))
975 throw new UnitTestFailedException("false", "true");
976 } else if (tokens[0].equals("assertfail")) {
977 assertExactParametreCount(tokens, 0);
978 throw new UnitTestFailedException("pass", "fail");
979 } else if (tokens[0].equals("assertnull")) {
980 assertExactParametreCount(tokens, 1);
981 Object value = context.getPrimitives().getVariable(tokens[1])
982 .getValue();
983 if (value != null)
984 throw new UnitTestFailedException("null", value.toString());
985 } else if (tokens[0].equals("assertnotnull")) {
986 assertExactParametreCount(tokens, 1);
987 Object value = context.getPrimitives().getVariable(tokens[1])
988 .getValue();
989 if (value == null)
990 throw new UnitTestFailedException("not null", "null");
991 } else if (tokens[0].equals("assertdefined")) {
992 assertExactParametreCount(tokens, 1);
993 if (!context.isDefined(tokens[1]))
994 throw new UnitTestFailedException("defined", "not defined");
995 } else if (tokens[0].equals("assertnotdefined")) {
996 assertExactParametreCount(tokens, 1);
997 if (context.isDefined(tokens[1]))
998 throw new UnitTestFailedException("defined", "not defined");
999 } else if (tokens[0].equals("assertequals")) {
1000 assertExactParametreCount(tokens, 2);
1001 if (!context.getPrimitives().equalValues(tokens[1], tokens[2]))
1002 throw new UnitTestFailedException(context.getPrimitives()
1003 .getStringValue(tokens[1]), context.getPrimitives()
1004 .getStringValue(tokens[2]));
1005 } else if (tokens[0].equals("assertdefined")) {
1006 assertExactParametreCount(tokens, 1);
1007 if (!context.isDefined(tokens[1])) {
1008 throw new UnitTestFailedException(tokens[1] + " exists",
1009 "not defined");
1010 }
1011 }
1012 } else if (tokens[0].startsWith("goto")) {
1013 String frameNameVar = DEFAULT_STRING;
1014 if (tokens.length > 1) {
1015 assertExactParametreCount(tokens, 1);
1016 frameNameVar = tokens[1];
1017 }
1018 String frameName = context.getPrimitives().getStringValue(
1019 frameNameVar);
1020 NavigationActions.Goto(frameName);
1021 } else if (tokens[0].startsWith("get")) {
1022 if (tokens[0].startsWith("getframe")) {
1023 if (tokens[0].equals("getframevalue")) {
1024 assertMinParametreCount(tokens, 3);
1025 assertVariableType(tokens[1], 1, SPointer.framePrefix);
1026
1027 // Get the attribute to be searched for on the target frame
1028 Frame targetFrame = (Frame) context.getPointers()
1029 .getVariable(tokens[1]).getValue();
1030 String targetAttribute = context.getPrimitives()
1031 .getStringValue(tokens[2]).toLowerCase()
1032 + ":";
1033 Boolean found = false;
1034 String value = "";
1035 Text attributeItem = null;
1036 Item valueItem = null;
1037 // Begin the search
1038 for (Text text : targetFrame.getBodyTextItems(true)) {
1039 String s = text.getText().toLowerCase();
1040 if (s.startsWith(targetAttribute)) {
1041 attributeItem = text;
1042 value = AttributeUtils.getValue(s);
1043 if (value.length() > 0) {
1044 found = true;
1045 }
1046 break;
1047 }
1048 }
1049 // Keep looking for a matching value nearby if we found an
1050 // attribute without the value in the same item
1051 if (!found && attributeItem != null) {
1052 Point endPoint = attributeItem
1053 .getEndParagraphPosition();
1054
1055 for (Text text : targetFrame.getBodyTextItems(true)) {
1056 Point startPoint = text.getPosition();
1057 if (Math.abs(startPoint.y - endPoint.y) < 10
1058 && Math.abs(startPoint.x - endPoint.x) < 20) {
1059 found = true;
1060 valueItem = text;
1061 value = text.getText();
1062 break;
1063 }
1064 }
1065 }
1066
1067 // Set the values of the output parametres
1068 context.getPrimitives().setValue(tokens[3],
1069 new SString(value));
1070 if (tokens.length > 4) {
1071 context.getPrimitives().setValue(tokens[4],
1072 new SBoolean(found));
1073 if (tokens.length > 5) {
1074 context.getPointers().setObject(tokens[5],
1075 attributeItem);
1076 if (tokens.length > 6) {
1077 context.getPointers().setObject(tokens[6],
1078 valueItem);
1079 }
1080 }
1081 }
1082 } else if (tokens[0].startsWith("getframename")) {
1083 String frameNameVar = DEFAULT_STRING;
1084 String frameVar = DEFAULT_FRAME;
1085
1086 if (tokens.length > 1) {
1087 assertExactParametreCount(tokens, 2);
1088 assertVariableType(tokens[1], 1, SPointer.framePrefix);
1089 frameNameVar = tokens[2];
1090 frameVar = tokens[1];
1091 }
1092 Frame frame = (Frame) context.getPointers().getVariable(
1093 frameVar).getValue();
1094 context.getPrimitives().setValue(frameNameVar,
1095 frame.getName());
1096 } else if (tokens[0].startsWith("getframefilepath")) {
1097 assertExactParametreCount(tokens, 2);
1098 String frameName = context.getPrimitives().getStringValue(
1099 tokens[1]);
1100 String path = FrameIO.LoadFrame(frameName).path;
1101 String filePath = FrameIO.getFrameFullPathName(path,
1102 frameName);
1103 context.getPrimitives().setValue(tokens[2], filePath);
1104 } else if (tokens[0].equals("getframelog")) {
1105 assertExactParametreCount(tokens, 1);
1106 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1107
1108 String log = SessionStats.getFrameEventList();
1109 Text t;
1110
1111 t = (Text) context.getPointers().getVariable(tokens[1])
1112 .getValue();
1113 t.setText(log);
1114 }
1115 } else if (tokens[0].equals("getassociation")) {
1116 assertMinParametreCount(tokens, 3);
1117 Map map = (Map) context.getPointers().getVariable(tokens[1])
1118 .getValue();
1119 String attribute = context.getPrimitives().getStringValue(
1120 tokens[2]);
1121 String newValue = map.get(attribute).toString();
1122 context.getPrimitives().setValue(tokens[3], newValue);
1123 } else if (tokens[0].startsWith("getcurrent")) {
1124 if (tokens[0].equals("getcurrentframe")) {
1125 assertMinParametreCount(tokens, 1);
1126 assertVariableType(tokens[1], 1, SPointer.framePrefix);
1127
1128 Frame currentFrame = DisplayIO.getCurrentFrame();
1129 context.getPointers().setObject(tokens[1], currentFrame);
1130
1131 // check if the user is also after the frameName
1132 if (tokens.length > 2) {
1133 context.getPrimitives().setValue(tokens[2],
1134 new SString(currentFrame.getName()));
1135 }
1136 }
1137 } else if (tokens[0].startsWith("getitem")) {
1138 if (tokens[0].equals("getitemposition")) {
1139 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1140 // assertPrimitiveType(tokens[2], 2);
1141 // assertPrimitiveType(tokens[3], 3);
1142 Point pos = ((Item) context.getPointers().getVariable(
1143 tokens[1]).getValue()).getPosition();
1144 Integer x = pos.x;
1145 Integer y = pos.y;
1146 context.getPrimitives()
1147 .setValue(tokens[2], new SInteger(x));
1148 context.getPrimitives()
1149 .setValue(tokens[3], new SInteger(y));
1150 } else if (tokens[0].equals("getitemthickness")) {
1151 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1152 // assertPrimitiveType(tokens[2], 2);
1153 Float thickness = ((Item) context.getPointers()
1154 .getVariable(tokens[1]).getValue()).getThickness();
1155 context.getPrimitives().setValue(tokens[2],
1156 new SReal(thickness));
1157 } else if (tokens[0].equals("getitemwidth")) {
1158 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1159 // assertPrimitiveType(tokens[2], 2);
1160 Integer width = ((Item) context.getPointers().getVariable(
1161 tokens[1]).getValue()).getWidth();
1162 context.getPrimitives().setValue(tokens[2],
1163 new SInteger(width));
1164 } else if (tokens[0].equals("getitemsize")) {
1165 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1166 // assertPrimitiveType(tokens[2], 2);
1167 Integer size = ((Item) context.getPointers().getVariable(
1168 tokens[1]).getValue()).getSize();
1169 context.getPrimitives().setValue(tokens[2],
1170 new SInteger(size));
1171 } else if (tokens[0].equals("getitemlink")) {
1172 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1173 // assertPrimitiveType(tokens[2], 2);
1174 String link = ((Item) context.getPointers().getVariable(
1175 tokens[1]).getValue()).getLink();
1176 context.getPrimitives().setValue(tokens[2],
1177 new SString(link));
1178 } else if (tokens[0].equals("getitemdata")) {
1179 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1180 Collection<String> dataList = ((Item) context.getPointers()
1181 .getVariable(tokens[1]).getValue()).getData();
1182 String data = "";
1183 if (dataList.size() > 0)
1184 data = dataList.iterator().next();
1185 context.getPrimitives().setValue(tokens[2],
1186 new SString(data));
1187 } else if (tokens[0].equals("getitemaction")) {
1188 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1189 Collection<String> dataList = ((Item) context.getPointers()
1190 .getVariable(tokens[1]).getValue()).getAction();
1191 String action = "";
1192 if (dataList.size() > 0)
1193 action = dataList.iterator().next();
1194 context.getPrimitives().setValue(tokens[2],
1195 new SString(action));
1196 } else if (tokens[0].equals("getitemfillcolor")) {
1197 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1198 // assertPrimitiveType(tokens[2], 2);
1199 Color itemColor = ((Item) context.getPointers()
1200 .getVariable(tokens[1]).getValue())
1201 .getPaintBackgroundColor();
1202 String color = itemColor.getRed() + " "
1203 + itemColor.getGreen() + " " + itemColor.getBlue();
1204 context.getPrimitives().setValue(tokens[2],
1205 new SString(color));
1206 } else if (tokens[0].equals("getitemcolor")) {
1207 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1208 // assertPrimitiveType(tokens[2], 2);
1209 Color itemColor = ((Item) context.getPointers()
1210 .getVariable(tokens[1]).getValue()).getPaintColor();
1211 String color = itemColor.getRed() + " "
1212 + itemColor.getGreen() + " " + itemColor.getBlue();
1213 context.getPrimitives().setValue(tokens[2],
1214 new SString(color));
1215 } else if (tokens[0].equals("getitemtext")) {
1216 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1217 Item item = ((Item) context.getPointers().getVariable(
1218 tokens[1]).getValue());
1219 context.getPrimitives().setValue(
1220 tokens[2],
1221 new SString((item instanceof Text) ? ((Text) item)
1222 .getText() : ""));
1223 } else
1224 throw new Exception("Unsupported getItem command: "
1225 + code.toString());
1226 } else if (tokens[0].equals("getstrchar")) {
1227 assertExactParametreCount(tokens, 3);
1228 String s = context.getPrimitives().getStringValue(tokens[1]);
1229 int pos = (int) context.getPrimitives().getIntegerValue(
1230 tokens[2]);
1231
1232 context.getPrimitives().setValue(tokens[3],
1233 new SCharacter(s.charAt(pos - 1)));
1234 } else if (tokens[0].equals("getstrlength")) {
1235 assertExactParametreCount(tokens, 2);
1236 String s = context.getPrimitives().getStringValue(tokens[1]);
1237
1238 context.getPrimitives().setValue(tokens[2],
1239 new SInteger(s.length()));
1240 } else if (tokens[0].equals("getelapsedtime")) {
1241 assertExactParametreCount(tokens, 1);
1242 context.getPrimitives().setValue(tokens[1],
1243 new SInteger(AgentStats.getMilliSecondsElapsed()));
1244 } else if (tokens[0].equals("getlastnumberinframeset")) {
1245 String framesetNameVar = DEFAULT_STRING;
1246 String countVar = DEFAULT_INTEGER;
1247 if (tokens.length > 1) {
1248 assertMinParametreCount(tokens, 2);
1249 framesetNameVar = tokens[1];
1250 countVar = tokens[2];
1251 }
1252 String frameset = context.getPrimitives().getStringValue(
1253 framesetNameVar);
1254 long count = FrameIO.getLastNumber(frameset);
1255 context.getPrimitives().setValue(countVar, new SInteger(count));
1256 } else if (tokens[0].equals("getlistofframesets")) {
1257 String stringVar = DEFAULT_ITEM;
1258 if (tokens.length > 1) {
1259 assertMinParametreCount(tokens, 1);
1260 stringVar = tokens[1];
1261 }
1262 context.getPrimitives().setValue(stringVar,
1263 FrameIO.getFramesetList());
1264 } else if (tokens[0].equals("getsessionstats")) {
1265 assertExactParametreCount(tokens, 1);
1266 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1267
1268 String stats = SessionStats.getCurrentStats();
1269 Text t = (Text) context.getPointers().getVariable(tokens[1])
1270 .getValue();
1271 t.setText(stats);
1272 } else if (tokens[0].equals("getrandominteger")) {
1273 assertExactParametreCount(tokens, 3);
1274 int lowerBound = (int) context.getPrimitives().getIntegerValue(
1275 tokens[1]);
1276 int upperBound = (int) context.getPrimitives().getIntegerValue(
1277 tokens[2]);
1278 Random random = new Random();
1279 long result = Math.abs(random.nextInt())
1280 % (upperBound - lowerBound) + lowerBound;
1281 context.getPrimitives().setValue(tokens[3],
1282 new SInteger(result));
1283 } else if (tokens[0].equals("getrandomreal")) {
1284 assertExactParametreCount(tokens, 3);
1285 double lowerBound = context.getPrimitives().getDoubleValue(
1286 tokens[1]);
1287 double upperBound = context.getPrimitives().getDoubleValue(
1288 tokens[2]);
1289 Random random = new Random();
1290 double result = random.nextDouble() * (upperBound - lowerBound)
1291 + lowerBound;
1292 context.getPrimitives().setValue(tokens[3], new SReal(result));
1293 } else if (tokens[0].equals("getrandomtextitem")) {
1294 assertExactParametreCount(tokens, 2);
1295 assertVariableType(tokens[1], 1, SPointer.framePrefix);
1296 assertVariableType(tokens[2], 2, SPointer.itemPrefix);
1297 List<Text> items = ((Frame) context.getPointers().getVariable(
1298 tokens[1]).getValue()).getBodyTextItems(false);
1299 Random random = new Random();
1300 int itemIndex = random.nextInt(items.size());
1301 context.getPointers()
1302 .setObject(tokens[2], items.get(itemIndex));
1303 }
1304 } else if (tokens[0].equals("or")) {
1305 for (int i = 1; i < tokens.length - 1; i++) {
1306 if (Primitives.isPrimitive(tokens[i])) {
1307 if (context.getPrimitives().getBooleanValue(tokens[i])) {
1308 context.getPrimitives().setValue(
1309 tokens[tokens.length - 1], new SBoolean(true));
1310 return Status.OK;
1311 }
1312 }
1313 }
1314 context.getPrimitives().setValue(tokens[tokens.length - 1],
1315 new SBoolean(false));
1316 } else if (tokens[0].equals("and")) {
1317 for (int i = 1; i < tokens.length - 1; i++) {
1318 if (Primitives.isPrimitive(tokens[i])) {
1319 if (!context.getPrimitives().getBooleanValue(tokens[i])) {
1320 context.getPrimitives().setValue(
1321 tokens[tokens.length - 1], new SBoolean(false));
1322 return Status.OK;
1323 }
1324 }
1325 }
1326 context.getPrimitives().setValue(tokens[tokens.length - 1],
1327 new SBoolean(true));
1328 } else if (tokens[0].equals("messagelnitem")
1329 || tokens[0].equals("messagelineitem")) {
1330 String itemVar = DEFAULT_ITEM;
1331
1332 if (tokens.length > 1) {
1333 assertExactParametreCount(tokens, 1);
1334 itemVar = tokens[1];
1335 assertVariableType(itemVar, 1, SPointer.itemPrefix);
1336 }
1337 Item message = (Item) context.getPointers().getVariable(itemVar)
1338 .getValue();
1339 try {
1340 FrameGraphics.DisplayMessage(((Text) message).copy());
1341 } catch (NullPointerException e) {
1342 FrameGraphics.DisplayMessage("null");
1343 } catch (ClassCastException e) {
1344 // Just ignore not text items!
1345 FrameGraphics.DisplayMessage(message.toString());
1346 } catch (Exception e) {
1347 // Just ignore other errors
1348 }
1349 } else if (tokens[0].equals("messageln")
1350 || tokens[0].equals("messageline")
1351 || tokens[0].equals("messagelnnospaces")
1352 || tokens[0].equals("messagelinenospaces")
1353 || tokens[0].equals("errorln") || tokens[0].equals("errorline")) {
1354 String message = getMessage(tokens, context, code.toString(),
1355 tokens[0].endsWith("nospaces") ? "" : " ", 1);
1356
1357 if (tokens[0].equals("errorln") || tokens[0].equals("errorline"))
1358 FrameGraphics.ErrorMessage(message);
1359 else
1360 FrameGraphics.DisplayMessageAlways(message);
1361 } else if (tokens[0].equals("typeatrate")) {
1362 assertMinParametreCount(tokens, 1);
1363 double delay = context.getPrimitives().getDoubleValue(tokens[1]);
1364 String s = getMessage(tokens, context, code.toString(), " ", 2);
1365 for (int i = 0; i < s.length(); i++) {
1366 FrameKeyboardActions.processChar(s.charAt(i), false);
1367 Thread.sleep((int) (delay * 1000));
1368 }
1369 } else if (tokens[0].equals("type") || tokens[0].equals("typenospaces")) {
1370
1371 String s = getMessage(tokens, context, code.toString(), tokens[0]
1372 .equals("type") ? " " : "", 1);
1373 for (int i = 0; i < s.length(); i++) {
1374 FrameKeyboardActions.processChar(s.charAt(i), false);
1375 Thread.sleep(25);
1376 }
1377 } else if (tokens[0].equals("runstring")) {
1378 String codeText = getMessage(tokens, context, code.toString(), " ",
1379 1);
1380 Text dynamicCode = new Text(1, codeText);
1381 RunItem(dynamicCode, context, Status.OK);
1382 } else if (tokens[0].equals("runoscommand")) {
1383 String command = getMessage(tokens, context, code.toString(), " ",
1384 1);
1385 Runtime.getRuntime().exec(command);
1386 } else if (tokens[0].equals("executeoscommand")) {
1387 String command = getMessage(tokens, context, code.toString(), " ",
1388 1);
1389 try {
1390 Process p = Runtime.getRuntime().exec(command);
1391 FrameGraphics.DisplayMessage(command, Color.darkGray);
1392
1393 BufferedReader stdInput = new BufferedReader(
1394 new InputStreamReader(p.getInputStream()));
1395 BufferedReader stdError = new BufferedReader(
1396 new InputStreamReader(p.getErrorStream()));
1397 String message = "";
1398 while ((message = stdInput.readLine()) != null) {
1399 FrameGraphics.DisplayMessage(message);
1400 }
1401 while ((message = stdError.readLine()) != null) {
1402 FrameGraphics.ErrorMessage(message);
1403 }
1404 } catch (Exception e) {
1405 throw new RuntimeException(e.getMessage());
1406 }
1407 } else if (tokens[0].startsWith("else")) {
1408 // if the if statement was false then run the else statement
1409 if (lastItemStatus == Status.FalseIf) {
1410 // check if it is a one line if statment
1411 if (tokens.length > 1) {
1412 // put together the one line statement
1413 StringBuilder statement = new StringBuilder();
1414 for (int i = 1; i < tokens.length; i++)
1415 statement.append(tokens[i]).append(' ');
1416 // create a copy of the code item to run
1417 Text copiedCode = code.copy();
1418 copiedCode.setText(statement.toString());
1419 return RunItem(copiedCode, context, Status.OK);
1420 } else {
1421 return RunFrameAndReportError(code, context);
1422 }
1423 } else if (lastItemStatus == Status.TrueIf) {
1424 return Status.OK;
1425 }
1426 throw new RuntimeException("Else without matching If statement");
1427 } else if (tokens[0].startsWith("if")) {
1428 Boolean result = null;
1429 int parametres = 1;
1430 String variable = DEFAULT_ITEM;
1431 String ifStatement = tokens[0];
1432 // Set the default variable
1433 if (tokens.length == 1) {
1434 if (ifStatement.equals("if") || ifStatement.equals("ifnot"))
1435 variable = DEFAULT_STRING;
1436 else if (ifStatement.equals("ifzero")
1437 || ifStatement.equals("ifnotzero"))
1438 variable = DEFAULT_INTEGER;
1439 } else {
1440 variable = tokens[1];
1441 }
1442
1443 if (ifStatement.equals("if")) {
1444 result = context.getPrimitives().getBooleanValue(variable);
1445 } else if (ifStatement.equals("ifnot")) {
1446 result = !context.getPrimitives().getBooleanValue(variable);
1447 } else if (ifStatement.equals("ifdefined")) {
1448 result = context.isDefined(tokens[1]);
1449 } else if (ifStatement.equals("ifnotdef")) {
1450 result = !context.isDefined(tokens[1]);
1451 } else if (ifStatement.equals("ifzero")) {
1452 result = context.getPrimitives().getIntegerValue(variable) == 0;
1453 } else if (ifStatement.equals("ifnotzero")) {
1454 result = context.getPrimitives().getIntegerValue(variable) != 0;
1455 } else if (tokens[0].equals("ifeq")) {
1456 result = context.equalValues(tokens[1], tokens[2]);
1457 parametres = 2;
1458 } else if (tokens[0].equals("ifeqnocase")) {
1459 result = context.getPrimitives().equalValuesNoCase(tokens[1],
1460 tokens[2]);
1461 parametres = 2;
1462 } else if (tokens[0].equals("ifnoteqnocase")) {
1463 result = !context.getPrimitives().equalValuesNoCase(tokens[1],
1464 tokens[2]);
1465 parametres = 2;
1466 } else if (tokens[0].equals("ifnoteq")) {
1467 result = !context.equalValues(tokens[1], tokens[2]);
1468 parametres = 2;
1469 } else if (tokens[0].equals("ifless")) {
1470 result = context.getPrimitives().compareValues(tokens[1],
1471 tokens[2]) < 0;
1472 parametres = 2;
1473 } else if (tokens[0].equals("ifgtr")) {
1474 result = context.getPrimitives().compareValues(tokens[1],
1475 tokens[2]) > 0;
1476 parametres = 2;
1477 } else if (tokens[0].equals("ifgeq")) {
1478 result = context.getPrimitives().compareValues(tokens[1],
1479 tokens[2]) >= 0;
1480 parametres = 2;
1481 } else if (tokens[0].equals("ifleq")) {
1482 result = context.getPrimitives().compareValues(tokens[1],
1483 tokens[2]) <= 0;
1484 parametres = 2;
1485 } else if (tokens[0].equals("ifexistingframe")) {
1486 result = FrameIO.canAccessFrame(context.getPrimitives()
1487 .getStringValue(tokens[1]));
1488 } else if (tokens[0].equals("ifexistingframeset")) {
1489 String framesetName = context.getPrimitives().getStringValue(
1490 tokens[1]);
1491 result = FrameIO.canAccessFrameset(framesetName);
1492 } else {
1493 // assertVariableType(variable, 1, SPointer.itemPrefix);
1494 if (ifStatement.equals("ifannotation")) {
1495 result = ((Item) context.getPointers()
1496 .getVariable(variable).getValue()).isAnnotation();
1497 } else if (ifStatement.equals("iflinked")) {
1498 result = ((Item) context.getPointers()
1499 .getVariable(variable).getValue()).getLink() != null;
1500 } else if (ifStatement.equals("ifactioned")) {
1501 result = ((Item) context.getPointers()
1502 .getVariable(variable).getValue()).getAction() != null;
1503 } else if (ifStatement.equals("ifnotactioned")) {
1504 result = ((Item) context.getPointers()
1505 .getVariable(variable).getValue()).getAction() == null;
1506 } else if (ifStatement.equals("ifbodytext")) {
1507 Item i = (Item) context.getPointers().getVariable(variable)
1508 .getValue();
1509 result = i instanceof Text && !i.isFrameName()
1510 && !i.isFrameTitle();
1511 } else if (ifStatement.equals("ifnotannotation")) {
1512 result = !((Item) context.getPointers().getVariable(
1513 variable).getValue()).isAnnotation();
1514 } else if (ifStatement.equals("ifnotlinked")) {
1515 result = ((Item) context.getPointers()
1516 .getVariable(variable).getValue()).getLink() == null;
1517 } else if (ifStatement.equals("ifnotbodytext")) {
1518 Item i = (Item) context.getPointers().getVariable(variable)
1519 .getValue();
1520 result = !(i instanceof Text) || i.isFrameName()
1521 || i.isFrameTitle();
1522 }
1523 }
1524
1525 if (result == null)
1526 throw new RuntimeException("Invalid If statement");
1527 // Now check if we need to run the code
1528 else if (result) {
1529 Status status;
1530 // check if it is a one line if statment
1531 if (tokens.length > parametres + 1) {
1532 // put together the one line statement
1533 StringBuilder statement = new StringBuilder();
1534 for (int i = parametres + 1; i < tokens.length; i++)
1535 statement.append(tokens[i]).append(' ');
1536 // create a copy of the code item to run
1537 Text copiedCode = code.copy();
1538 copiedCode.setText(statement.toString());
1539 status = RunItem(copiedCode, context, Status.OK);
1540 } else {
1541 status = RunFrameAndReportError(code, context);
1542 }
1543 if (status == Status.OK) {
1544 return Status.TrueIf;
1545 } else {
1546 return status;
1547 }
1548 }
1549 return Status.FalseIf;
1550 } // Look for variable length methods
1551 else if (tokens[0].equals("attachitemtocursor")) {
1552 String itemVar = DEFAULT_ITEM;
1553
1554 if (tokens.length > 1) {
1555 assertExactParametreCount(tokens, 1);
1556 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1557 itemVar = tokens[1];
1558 }
1559 Item item = (Item) context.getPointers().getVariable(itemVar)
1560 .getValue();
1561 item
1562 .setPosition(FrameMouseActions.MouseX,
1563 FrameMouseActions.MouseY);
1564 FrameMouseActions.pickup(item);
1565 } else if (tokens[0].equals("attachstrtocursor")) {
1566 String stringVar = DEFAULT_STRING;
1567
1568 if (tokens.length > 1) {
1569 assertExactParametreCount(tokens, 1);
1570 stringVar = tokens[1];
1571 }
1572 String s = context.getPrimitives().getStringValue(stringVar);
1573 Frame frame = DisplayIO.getCurrentFrame();
1574 Item item = frame.createNewText(s);
1575 item
1576 .setPosition(FrameMouseActions.MouseX,
1577 FrameMouseActions.MouseY);
1578 FrameMouseActions.pickup(item);
1579 } else if (tokens[0].equals("additemtoframe")) {
1580 String itemVar = DEFAULT_ITEM;
1581 String frameVar = DEFAULT_FRAME;
1582
1583 if (tokens.length > 1) {
1584 assertExactParametreCount(tokens, 2);
1585 assertVariableType(tokens[1], 1, SPointer.framePrefix);
1586 assertVariableType(tokens[2], 2, SPointer.itemPrefix);
1587 itemVar = tokens[2];
1588 frameVar = tokens[1];
1589 }
1590 Frame frame = (Frame) context.getPointers().getVariable(frameVar)
1591 .getValue();
1592 Item item = (Item) context.getPointers().getVariable(itemVar)
1593 .getValue();
1594 frame.addItem(item);
1595 } else if (tokens[0].equals("connectdots")) {
1596 assertMinParametreCount(tokens, 2);
1597 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1598 assertVariableType(tokens[2], 2, SPointer.itemPrefix);
1599 Item dot1 = null;
1600 Item dot2 = null;
1601 try {
1602 dot1 = (Item) context.getPointers().getVariable(tokens[1])
1603 .getValue();
1604 } catch (Exception e) {
1605 throw new IncorrectTypeException("Dot", 1);
1606 }
1607 try {
1608 dot2 = (Item) context.getPointers().getVariable(tokens[2])
1609 .getValue();
1610 } catch (Exception e) {
1611 throw new IncorrectTypeException("Dot", 2);
1612 }
1613 Frame frame = dot1.getParent();
1614 frame.addItem(new Line(dot1, dot2, frame.getNextItemID()));
1615 } else if (tokens[0].equals("createitem")
1616 || tokens[0].equals("createtext")) {
1617 assertMinParametreCount(tokens, 4);
1618 assertVariableType(tokens[1], 1, SPointer.framePrefix);
1619 assertVariableType(tokens[4], 4, SPointer.itemPrefix);
1620 Frame frame = (Frame) context.getPointers().getVariable(tokens[1])
1621 .getValue();
1622 Item newItem;
1623 int x = (int) context.getPrimitives().getIntegerValue(tokens[2]);
1624 int y = (int) context.getPrimitives().getIntegerValue(tokens[3]);
1625 // check for the option text and action for the new item
1626 if (tokens.length > 5) {
1627 String newText = context.getPrimitives().getStringValue(
1628 tokens[5]);
1629 String newAction = null;
1630 if (tokens.length > 6) {
1631 newAction = context.getPrimitives().getStringValue(
1632 tokens[6]);
1633 }
1634 newItem = frame.addText(x, y, newText, newAction);
1635 } else {
1636 if (tokens[0].equals("createtext")) {
1637 newItem = frame.createNewText();
1638 newItem.setPosition(x, y);
1639 } else {
1640 // create a point if the optional params are not provided
1641 newItem = frame.addDot(x, y);
1642 }
1643 }
1644 context.getPointers().setObject(tokens[4], newItem);
1645 } else if (tokens[0].equals("deleteitem")) {
1646 assertMinParametreCount(tokens, 1);
1647 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1648 Item item = (Item) context.getPointers().getVariable(tokens[1])
1649 .getValue();
1650 item.delete();
1651 } else if (tokens[0].equals("deleteframe")) {
1652 assertMinParametreCount(tokens, 1);
1653 assertVariableType(tokens[1], 1, SPointer.framePrefix);
1654 Frame frame = (Frame) context.getPointers().getVariable(tokens[1])
1655 .getValue();
1656 String errorMessage = "Error deleting " + frame.getName();
1657 boolean success = false;
1658 try {
1659 success = FrameIO.DeleteFrame(frame);
1660 if (!success)
1661 FrameGraphics.WarningMessage(errorMessage);
1662 } catch (Exception e) {
1663 // If an exception is thrown then success is false
1664 FrameGraphics
1665 .WarningMessage(errorMessage
1666 + (e.getMessage() != null ? ". "
1667 + e.getMessage() : ""));
1668 }
1669 if (tokens.length > 2) {
1670 context.getPrimitives().setValue(tokens[2],
1671 new SBoolean(success));
1672 }
1673 } else if (tokens[0].equals("deleteframeset")) {
1674 assertMinParametreCount(tokens, 1);
1675 String framesetName = context.getPrimitives().getStringValue(
1676 tokens[1]);
1677 boolean success = FrameIO.DeleteFrameset(framesetName);
1678 if (!success)
1679 FrameGraphics.WarningMessage("Error deleting " + framesetName);
1680 if (tokens.length > 2) {
1681 context.getPrimitives().setValue(tokens[2],
1682 new SBoolean(success));
1683 }
1684 } else if (tokens[0].equals("copyitem")) {
1685 assertMinParametreCount(tokens, 2);
1686 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1687 assertVariableType(tokens[2], 2, SPointer.itemPrefix);
1688 Item item = (Item) context.getPointers().getVariable(tokens[1])
1689 .getValue();
1690 Item copy = item.copy();
1691 context.getPointers().setObject(tokens[2], copy);
1692 } else if (tokens[0].equals("copyframeset")) {
1693 assertMinParametreCount(tokens, 2);
1694 String framesetToCopy = context.getPrimitives().getStringValue(
1695 tokens[1]);
1696 String copiedFrameset = context.getPrimitives().getStringValue(
1697 tokens[2]);
1698 boolean success = FrameIO.CopyFrameset(framesetToCopy,
1699 copiedFrameset);
1700 if (!success)
1701 FrameGraphics.WarningMessage("Error copying " + framesetToCopy);
1702 if (tokens.length > 3) {
1703 context.getPrimitives().setValue(tokens[3],
1704 new SBoolean(success));
1705 }
1706 } else if (tokens[0].equals("copyframe")) {
1707 assertMinParametreCount(tokens, 2);
1708 assertVariableType(tokens[1], 1, SPointer.framePrefix);
1709 assertVariableType(tokens[2], 2, SPointer.framePrefix);
1710 Frame frameToCopy = (Frame) context.getPointers().getVariable(
1711 tokens[1]).getValue();
1712 FrameIO.SuspendCache();
1713 Frame freshCopy = FrameIO.LoadFrame(frameToCopy.getName());
1714 // Change the frameset if one was provided
1715 if (tokens.length > 3) {
1716 String destinationFrameset = context.getPrimitives()
1717 .getStringValue(tokens[3]);
1718 freshCopy.setFrameset(destinationFrameset);
1719 }// Otherwise add it to the end of this frameset
1720 freshCopy.setFrameNumber(FrameIO.getLastNumber(freshCopy
1721 .getFramesetName()) + 1);
1722 context.getPointers().setObject(tokens[2], freshCopy);
1723 String fileContents = FrameIO.ForceSaveFrame(freshCopy);
1724 boolean success = fileContents != null;
1725 if (!success)
1726 FrameGraphics.WarningMessage("Error copying " + frameToCopy.getName());
1727 FrameIO.ResumeCache();
1728 if (tokens.length > 4) {
1729 context.getPrimitives().setValue(tokens[4],
1730 new SBoolean(success));
1731 }
1732 } else if (tokens[0].equals("createframe")) {
1733
1734 String framesetName = DEFAULT_STRING;
1735 String frameVar = DEFAULT_FRAME;
1736
1737 if (tokens.length > 1) {
1738 assertMinParametreCount(tokens, 2);
1739 assertVariableType(tokens[2], 2, SPointer.framePrefix);
1740 framesetName = tokens[1];
1741 frameVar = tokens[2];
1742 }
1743
1744 if (tokens.length > 3) {
1745 context.createFrame(framesetName, frameVar, tokens[3]);
1746 } else
1747 context.createFrame(framesetName, frameVar, null);
1748 } else if (tokens[0].equals("closeframe")) {
1749 String frameVar = DEFAULT_FRAME;
1750
1751 if (tokens.length > 1) {
1752 assertVariableType(tokens[1], 1, SPointer.framePrefix);
1753 frameVar = tokens[1];
1754 }
1755
1756 if (tokens.length > 2) {
1757 // assertPrimitiveType(tokens[3], 3);
1758 context.closeFrame(frameVar, tokens[3]);
1759 } else
1760 context.closeFrame(frameVar, null);
1761 } else if (tokens[0].equals("readframe")
1762 || tokens[0].equals("openframe")) {
1763
1764 String frameName = DEFAULT_STRING;
1765 String frameVar = DEFAULT_FRAME;
1766
1767 if (tokens.length > 1) {
1768 assertMinParametreCount(tokens, 2);
1769 assertVariableType(tokens[2], 2, SPointer.framePrefix);
1770 frameName = tokens[1];
1771 frameVar = tokens[2];
1772 // assertPrimitiveType(frameName, 1);
1773 }
1774
1775 if (tokens.length > 3) {
1776 // assertPrimitiveType(tokens[3], 3);
1777 context.readFrame(frameName, frameVar, tokens[3]);
1778 } else
1779 context.readFrame(frameName, frameVar, null);
1780 } else if (tokens[0].equals("readkbdcond")) {
1781
1782 String nextCharVarName = DEFAULT_CHAR;
1783 String wasCharVarName = DEFAULT_BOOLEAN;
1784
1785 if (tokens.length > 1) {
1786 assertMinParametreCount(tokens, 2);
1787 assertVariableType(tokens[2], 2, SPointer.framePrefix);
1788 nextCharVarName = tokens[1];
1789 wasCharVarName = tokens[2];
1790 }
1791
1792 Character nextChar = _KeyStrokes.poll();
1793 boolean hasChar = nextChar != null;
1794 context.getPrimitives().setValue(wasCharVarName,
1795 new SBoolean(hasChar));
1796 if (hasChar)
1797 context.getPrimitives().setValue(nextCharVarName,
1798 new SCharacter(nextChar));
1799 } else if (tokens[0].equals("createassociation")) {
1800
1801 String associationVar = DEFAULT_ASSOCIATION;
1802
1803 if (tokens.length > 0) {
1804 assertVariableType(tokens[1], 2, SPointer.associationPrefix);
1805 associationVar = tokens[1];
1806 }
1807 Map<String, String> newMap = new HashMap<String, String>();
1808 context.getPointers().setObject(associationVar, newMap);
1809 } else if (tokens[0].equals("deleteassociation")) {
1810
1811 String associationVar = DEFAULT_ASSOCIATION;
1812
1813 if (tokens.length > 0) {
1814 assertVariableType(tokens[1], 2, SPointer.associationPrefix);
1815 associationVar = tokens[1];
1816 }
1817 context.getPointers().delete(associationVar);
1818 } else if (tokens[0].equals("openreadfile")) {
1819 assertVariableType(tokens[1], 1, SString.prefix);
1820 assertVariableType(tokens[2], 2, SPointer.filePrefix);
1821
1822 if (tokens.length > 3) {
1823 assertVariableType(tokens[3], 3, SBoolean.prefix);
1824 context.openReadFile(tokens[1], tokens[2], tokens[3]);
1825 } else
1826 context.openReadFile(tokens[1], tokens[2]);
1827 } else if (tokens[0].equals("readlinefile")
1828 || tokens[0].equals("readlnfile")) {
1829 assertVariableType(tokens[1], 1, SPointer.filePrefix);
1830
1831 if (tokens.length > 3) {
1832 assertVariableType(tokens[3], 3, SBoolean.prefix);
1833 context.readLineFile(tokens[1], tokens[2], tokens[3]);
1834 } else
1835 context.readLineFile(tokens[1], tokens[2]);
1836 } else if (tokens[0].equals("readitemfile")) {
1837 assertVariableType(tokens[1], 1, SPointer.filePrefix);
1838 assertVariableType(tokens[2], 1, SPointer.itemPrefix);
1839
1840 if (tokens.length > 3) {
1841 assertVariableType(tokens[3], 3, SBoolean.prefix);
1842 context.readItemFile(tokens[1], tokens[2], tokens[3]);
1843 } else
1844 context.readItemFile(tokens[1], tokens[2]);
1845 } else if (tokens[0].equals("openwritefile")) {
1846 assertVariableType(tokens[1], 1, SString.prefix);
1847 assertVariableType(tokens[2], 2, SPointer.filePrefix);
1848
1849 if (tokens.length > 3) {
1850 assertVariableType(tokens[3], 3, SBoolean.prefix);
1851 context.openWriteFile(tokens[1], tokens[2], tokens[3]);
1852 } else
1853 context.openWriteFile(tokens[1], tokens[2]);
1854 } else if (tokens[0].equals("writefile")
1855 || tokens[0].equals("writelinefile")
1856 || tokens[0].equals("writelnfile")) {
1857 assertVariableType(tokens[1], 1, SPointer.filePrefix);
1858
1859 StringBuilder textToWrite = new StringBuilder();
1860 if (tokens.length == 1) {
1861 textToWrite.append(context.getPrimitives().getVariable(
1862 DEFAULT_STRING).stringValue()
1863 + " ");
1864 } else {
1865 for (int i = 2; i < tokens.length; i++) {
1866 if (Primitives.isPrimitive(tokens[i])) {
1867 textToWrite.append(context.getPrimitives().getVariable(
1868 tokens[i]).stringValue());
1869 } else
1870 throw new Exception("Illegal parametre: " + tokens[i]
1871 + " in " + code.toString());
1872 }
1873 }
1874
1875 if (!tokens[0].equals("writefile"))
1876 textToWrite.append('\n');
1877 context.writeFile(tokens[1], textToWrite.toString());
1878 } else if (tokens[0].equals("displayframeset")) {
1879 assertMinParametreCount(tokens, 1);
1880 String framesetName = context.getPrimitives().getStringValue(
1881 tokens[1]);
1882 int lastFrameNo = FrameIO.getLastNumber(framesetName);
1883 int firstFrameNo = 0;
1884 double pause = 0.0;
1885 // get the first and last frames to display if they were proided
1886 if (tokens.length > 2) {
1887 firstFrameNo = (int) context.getPrimitives().getIntegerValue(
1888 tokens[2]);
1889 if (tokens.length > 3) {
1890 lastFrameNo = (int) context.getPrimitives()
1891 .getIntegerValue(tokens[3]);
1892 if (tokens.length > 4) {
1893 pause = context.getPrimitives().getDoubleValue(
1894 tokens[4]);
1895 }
1896 }
1897 }
1898 Runtime runtime = Runtime.getRuntime();
1899 // Display the frames
1900 for (int i = firstFrameNo; i <= lastFrameNo; i++) {
1901 Frame frame = FrameIO.LoadFrame(framesetName + i);
1902 if (frame != null) {
1903 double thisFramesPause = pause;
1904 // check for change in delay for this frame only
1905 Item pauseItem = ItemUtils.FindTag(frame.getItems(),
1906 "@DisplayFramePause:");
1907 if (pauseItem != null) {
1908 try {
1909 // attempt to read in the delay value
1910 thisFramesPause = Double.parseDouble(ItemUtils
1911 .StripTag(
1912 ((Text) pauseItem).getFirstLine(),
1913 "@DisplayFramePause"));
1914 } catch (NumberFormatException nfe) {
1915 }
1916 }
1917 DisplayIO.setCurrentFrame(frame);
1918 pause(thisFramesPause);
1919
1920 long freeMemory = runtime.freeMemory();
1921 if (freeMemory < DisplayTree.GARBAGE_COLLECTION_THRESHOLD) {
1922 runtime.gc();
1923 FrameGraphics
1924 .DisplayMessage("Force Garbage Collection!");
1925 }
1926 }
1927 }
1928 } else if (tokens[0].equals("createframeset")) {
1929 String framesetName = DEFAULT_STRING;
1930 String successVar = null;
1931 if (tokens.length > 1) {
1932 framesetName = tokens[1];
1933 if (tokens.length > 2)
1934 successVar = tokens[2];
1935 }
1936 context.createFrameset(framesetName, successVar);
1937 } else if (tokens[0].equals("writetree")) {
1938 assertMinParametreCount(tokens, 3);
1939 assertVariableType(tokens[1], 1, SPointer.framePrefix);
1940 Frame source = (Frame) context.getPointers().getVariable(tokens[1])
1941 .getValue();
1942 String format = context.getPrimitives().getStringValue(tokens[2]);
1943 String fileName = context.getPrimitives().getStringValue(tokens[3]);
1944 WriteTree wt = new WriteTree(format, fileName);
1945 if (wt.initialise(source)) {
1946 wt.setStartFrame(source);
1947 wt.run();
1948 }
1949 } else if (tokens[0].equals("concatstr")) {
1950 assertMinParametreCount(tokens, 3);
1951 String resultVar = tokens[tokens.length - 1];
1952
1953 StringBuilder sb = new StringBuilder();
1954 // loop through all the strings concatenating them
1955 for (int i = 1; i < tokens.length - 1; i++) {
1956 // assertPrimitiveType(tokens[i], i);
1957 sb.append(context.getPrimitives().getStringValue(tokens[i]));
1958 }
1959 context.getPrimitives().setValue(resultVar,
1960 new SString(sb.toString()));
1961 } else if (tokens[0].equals("convstrlower")) {
1962 assertExactParametreCount(tokens, 1);
1963 // assertPrimitiveType(tokens[1], 1);
1964 context.getPrimitives().setValue(
1965 tokens[1],
1966 new SString(context.getPrimitives().getStringValue(
1967 tokens[1]).toLowerCase()));
1968 } else if (tokens[0].equals("convstrupper")) {
1969 assertExactParametreCount(tokens, 1);
1970 // assertPrimitiveType(tokens[1], 1);
1971 context.getPrimitives().setValue(
1972 tokens[1],
1973 new SString(context.getPrimitives().getStringValue(
1974 tokens[1]).toUpperCase()));
1975 } else if (tokens[0].equals("countcharsinstr")) {
1976 assertExactParametreCount(tokens, 3);
1977 String s = context.getPrimitives().getStringValue(tokens[1]);
1978 String pattern = context.getPrimitives().getStringValue(tokens[2]);
1979 int count = countCharsInString(s, pattern);
1980 context.getPrimitives().setValue(tokens[3], new SInteger(count));
1981 } else if (tokens[0].equals("countcharsinitem")) {
1982 assertExactParametreCount(tokens, 3);
1983 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
1984 Item item = (Item) context.getPointers().getVariable(tokens[1])
1985 .getValue();
1986 String pattern = context.getPrimitives().getStringValue(tokens[2]);
1987 int count = 0;
1988 if (item instanceof Text)
1989 count = countCharsInString(((Text) item).getText(), pattern);
1990 context.getPrimitives().setValue(tokens[3], new SInteger(count));
1991 } else if (tokens[0].equals("parseframename")) {
1992 assertExactParametreCount(tokens, 4);
1993 String frameName = context.getPrimitives()
1994 .getStringValue(tokens[1]);
1995 String frameSet = "";
1996 int frameNo = -1;
1997 boolean success = true;
1998 try {
1999 frameSet = Conversion.getFramesetName(frameName, false);
2000 frameNo = Conversion.getFrameNumber(frameName);
2001 } catch (Exception e) {
2002 success = false;
2003 FrameGraphics.WarningMessage("Error parsing " + frameName);
2004 }
2005 // assertPrimitiveType(tokens[2], 2);
2006 context.getPrimitives().setValue(tokens[2], new SBoolean(success));
2007
2008 // assertPrimitiveType(tokens[3], 3);
2009 context.getPrimitives().setValue(tokens[3], new SString(frameSet));
2010
2011 // assertPrimitiveType(tokens[4], 4);
2012 context.getPrimitives().setValue(tokens[4], new SInteger(frameNo));
2013 } else if (tokens[0].equals("parsestr")) {
2014 assertMinParametreCount(tokens, 2);
2015 // assertPrimitiveType(tokens[1], 1);
2016 // assertPrimitiveType(tokens[2], 2);
2017
2018 String s = context.getPrimitives().getStringValue(tokens[1]);
2019
2020 String separator = context.getPrimitives()
2021 .getStringValue(tokens[2]);
2022
2023 String[] split = s.split(separator, tokens.length - 4);
2024
2025 if (tokens.length > 3) {
2026 // assertPrimitiveType(tokens[3], 3);
2027 int count = split.length;
2028 // if the string is not blank and its got a remainder then
2029 // decrease the count by 1 to account for the remainder
2030 if (split.length != 0 && split.length > tokens.length - 5)
2031 count--;
2032
2033 context.getPrimitives()
2034 .setValue(tokens[3], new SInteger(count));
2035
2036 if (tokens.length > 4) {
2037 // Set the remainder string
2038 // assertPrimitiveType(tokens[4], 4);
2039 if (split.length < tokens.length - 4)
2040 context.getPrimitives().setValue(tokens[4],
2041 new SString());
2042 else
2043 context.getPrimitives().setValue(tokens[4],
2044 new SString(split[split.length - 1]));
2045
2046 // Set the strings for each of the vars
2047 if (tokens.length > 5) {
2048 for (int i = 5; i < tokens.length; i++) {
2049 // assertPrimitiveType(tokens[i], i);
2050 if (split.length < i - 4)
2051 context.getPrimitives().setValue(tokens[i],
2052 new SString());
2053 else
2054 context.getPrimitives().setValue(tokens[i],
2055 new SString(split[i - 5]));
2056 }
2057 }
2058 }
2059 }
2060 } else if (tokens[0].equals("stripstr")) {
2061 assertExactParametreCount(tokens, 2);
2062 String s = context.getPrimitives().getStringValue(tokens[1]);
2063 String charsToStrip = context.getPrimitives().getStringValue(
2064 tokens[2]);
2065 for (int i = 0; i < charsToStrip.length(); i++)
2066 s = s.replaceAll(charsToStrip.substring(i, i + 1), "");
2067 context.getPrimitives().setValue(tokens[1], new SString(s));
2068 } else if (tokens[0].equals("subststr")) {
2069 assertExactParametreCount(tokens, 3);
2070 String oldString = context.getPrimitives()
2071 .getStringValue(tokens[2]);
2072 String newString = context.getPrimitives()
2073 .getStringValue(tokens[3]);
2074 String result = context.getPrimitives().getStringValue(tokens[1]);
2075 result = result.replaceAll(oldString, newString);
2076 context.getPrimitives().setValue(tokens[1], new SString(result));
2077 } else if (tokens[0].equals("substr")) {
2078 assertExactParametreCount(tokens, 4);
2079 int startPos = (int) context.getPrimitives().getIntegerValue(
2080 tokens[2]) - 1;
2081 int length = (int) context.getPrimitives().getIntegerValue(
2082 tokens[3]);
2083 String s = context.getPrimitives().getStringValue(tokens[1]);
2084 String result;
2085 if (startPos + length < s.length())
2086 result = s.substring(startPos, startPos + length);
2087 else
2088 result = s.substring(startPos);
2089 context.getPrimitives().setValue(tokens[4], new SString(result));
2090 } else if (tokens[0].equals("pause")) {
2091 String lengthVar = DEFAULT_REAL;
2092
2093 if (tokens.length > 1) {
2094 assertExactParametreCount(tokens, 1);
2095 lengthVar = tokens[1];
2096 }
2097
2098 pause(context.getPrimitives().getDoubleValue(lengthVar));
2099 } else if (tokens[0].equals("glidecursorto")) {
2100 assertMinParametreCount(tokens, 2);
2101 int finalX = (int) context.getPrimitives().getIntegerValue(
2102 tokens[1]);
2103 int finalY = (int) context.getPrimitives().getIntegerValue(
2104 tokens[2]);
2105 int milliseconds = 1000;
2106 if (tokens.length > 3)
2107 milliseconds = (int) (context.getPrimitives().getDoubleValue(
2108 tokens[3]) * 1000);
2109
2110 int initialX = DisplayIO.getMouseX();
2111 int initialY = DisplayIO.getMouseY();
2112
2113 final int timeInterval = 40;
2114
2115 int deltaX = (int) (finalX - initialX);
2116 int deltaY = (int) (finalY - initialY);
2117
2118 int intervals = milliseconds / timeInterval;
2119 for (double i = 0; i < intervals; i++) {
2120 int newX = initialX + (int) (deltaX * i / intervals);
2121 int newY = initialY + (int) (deltaY * i / intervals);
2122 Thread.yield();
2123 Thread.sleep(timeInterval);
2124 DisplayIO.setCursorPosition(newX, newY);
2125 // DisplayIO.repaint();
2126 }
2127 // Thread.yield();
2128 Thread.sleep(milliseconds % timeInterval);
2129 DisplayIO.setCursorPosition(finalX, finalY);
2130 } else if (tokens[0].equals("glideitemto")) {
2131 assertMinParametreCount(tokens, 3);
2132 assertVariableType(tokens[1], 1, SPointer.itemPrefix);
2133 Item item = (Item) context.getPointers().getVariable(tokens[1])
2134 .getValue();
2135 int finalX = (int) context.getPrimitives().getIntegerValue(
2136 tokens[2]);
2137 int finalY = (int) context.getPrimitives().getIntegerValue(
2138 tokens[3]);
2139
2140 // DisplayIO.setCursorPosition(item.getX(), item.getY());
2141 // FrameMouseActions.pickup(item);
2142
2143 int milliseconds = 1000;
2144 if (tokens.length > 4)
2145 milliseconds = (int) (context.getPrimitives().getDoubleValue(
2146 tokens[4]) * 1000);
2147
2148 int initialX = item.getX();
2149 int initialY = item.getY();
2150 // int initialX = DisplayIO.getMouseX();
2151 // int initialY = DisplayIO.getMouseY();
2152
2153 final int timeInterval = 40;
2154
2155 int deltaX = (int) (finalX - initialX);
2156 int deltaY = (int) (finalY - initialY);
2157
2158 int intervals = milliseconds / timeInterval;
2159 for (double i = 0; i < intervals; i++) {
2160 int newX = initialX + (int) (deltaX * i / intervals);
2161 int newY = initialY + (int) (deltaY * i / intervals);
2162 Thread.yield();
2163 Thread.sleep(timeInterval);
2164 // DisplayIO.setCursorPosition(newX, newY);
2165
2166 item.setPosition(newX, newY);
2167 FrameGraphics.Repaint();
2168 }
2169 // Thread.yield();
2170 Thread.sleep(milliseconds % timeInterval);
2171 item.setPosition(finalX, finalY);
2172 // DisplayIO.setCursorPosition(finalX, finalY);
2173 FrameMouseActions.anchor(item);
2174 Frame.FreeItems.clear();
2175 FrameGraphics.Repaint();
2176 // FrameMouseActions.updateCursor();
2177 }
2178 // Now look for fixed parametre statements
2179 else if (tokens[0].equals(EXIT_TEXT)) {
2180 return Status.Exit;
2181 } else if (tokens[0].equals(LOOP_TEXT)) {
2182 Status status = Status.OK;
2183 // Keep looping until break or exit occurs
2184 while (status == Status.OK || status == Status.Continue) {
2185 status = RunFrameAndReportError(code, context);
2186 pause(code);
2187 }
2188 if (status == Status.Continue || status == Status.Break)
2189 status = Status.OK;
2190 return status;
2191 } else if (tokens[0].equals(CONTINUE_TEXT)
2192 || tokens[0].equals(CONTINUE2_TEXT)) {
2193 return Status.Continue;
2194 } else if (tokens[0].equals(BREAK_TEXT)
2195 || tokens[0].equals(BREAK2_TEXT)) {
2196 return Status.Break;
2197 } else if (tokens[0].equals(RETURN_TEXT)) {
2198 return Status.Return;
2199 } else if (tokens[0].equals("pressleftbutton")) {
2200 assertExactParametreCount(tokens, 0);
2201 DisplayIO.pressMouse(InputEvent.BUTTON1_MASK);
2202 } else if (tokens[0].equals("pressmiddlebutton")) {
2203 assertExactParametreCount(tokens, 0);
2204 DisplayIO.pressMouse(InputEvent.BUTTON2_MASK);
2205 } else if (tokens[0].equals("pressrightbutton")) {
2206 assertExactParametreCount(tokens, 0);
2207 DisplayIO.pressMouse(InputEvent.BUTTON3_MASK);
2208 } else if (tokens[0].equals("releaseleftbutton")) {
2209 assertExactParametreCount(tokens, 0);
2210 DisplayIO.releaseMouse(InputEvent.BUTTON1_MASK);
2211 } else if (tokens[0].equals("releasemiddlebutton")) {
2212 assertExactParametreCount(tokens, 0);
2213 DisplayIO.releaseMouse(InputEvent.BUTTON2_MASK);
2214 } else if (tokens[0].equals("releaserightbutton")) {
2215 assertExactParametreCount(tokens, 0);
2216 DisplayIO.releaseMouse(InputEvent.BUTTON3_MASK);
2217 } else if (tokens[0].equals("clickleftbutton")) {
2218 assertExactParametreCount(tokens, 0);
2219 DisplayIO.clickMouse(InputEvent.BUTTON1_MASK);
2220 } else if (tokens[0].equals("clickmiddlebutton")) {
2221 assertExactParametreCount(tokens, 0);
2222 DisplayIO.clickMouse(InputEvent.BUTTON2_MASK);
2223 } else if (tokens[0].equals("clickrightbutton")) {
2224 assertExactParametreCount(tokens, 0);
2225 DisplayIO.clickMouse(InputEvent.BUTTON3_MASK);
2226 } else if (tokens[0].equals("repaint")) {
2227 assertExactParametreCount(tokens, 0);
2228 FrameGraphics.Repaint();
2229 } else if (tokens[0].equals("add")) {
2230 assertMaxParametreCount(tokens, 3);
2231 switch (tokens.length) {
2232 case 1:
2233 context.getPrimitives().add(DEFAULT_INTEGER);
2234 break;
2235 case 2:
2236 context.getPrimitives().add(tokens[1]);
2237 break;
2238 case 3:
2239 context.getPrimitives().add(tokens[2], tokens[1]);
2240 break;
2241 case 4:
2242 context.getPrimitives().add(tokens[1], tokens[2], tokens[3]);
2243 break;
2244 default:
2245 assert (false);
2246 }
2247 } else if (tokens[0].equals("subtract")) {
2248 assertMaxParametreCount(tokens, 3);
2249 switch (tokens.length) {
2250 case 1:
2251 context.getPrimitives().subtract(DEFAULT_INTEGER);
2252 break;
2253 case 2:
2254 context.getPrimitives().subtract(tokens[1]);
2255 break;
2256 case 3:
2257 context.getPrimitives().subtract(tokens[2], tokens[1]);
2258 break;
2259 case 4:
2260 context.getPrimitives().subtract(tokens[1], tokens[2],
2261 tokens[3]);
2262 break;
2263 default:
2264 assert (false);
2265 }
2266 } else if (tokens[0].equals("multiply")) {
2267 assertMinParametreCount(tokens, 2);
2268 assertMaxParametreCount(tokens, 3);
2269 switch (tokens.length) {
2270 case 3:
2271 context.getPrimitives().multiply(tokens[2], tokens[1]);
2272 break;
2273 case 4:
2274 context.getPrimitives().multiply(tokens[1], tokens[2],
2275 tokens[3]);
2276 break;
2277 default:
2278 assert (false);
2279 }
2280 } else if (tokens[0].equals("divide")) {
2281 assertMinParametreCount(tokens, 2);
2282 assertMaxParametreCount(tokens, 3);
2283 switch (tokens.length) {
2284 case 3:
2285 context.getPrimitives().divide(tokens[2], tokens[1]);
2286 break;
2287 case 4:
2288 context.getPrimitives().divide(tokens[1], tokens[2], tokens[3]);
2289 break;
2290 default:
2291 assert (false);
2292 }
2293 } else if (tokens[0].equals("modulo")) {
2294 assertExactParametreCount(tokens, 3);
2295 context.getPrimitives().modulo(tokens[1], tokens[2], tokens[3]);
2296 } else if (tokens[0].equals("power")) {
2297 assertExactParametreCount(tokens, 3);
2298 context.getPrimitives().power(tokens[1], tokens[2], tokens[3]);
2299 } else if (tokens[0].equals("not")) {
2300 assertExactParametreCount(tokens, 2);
2301 context.getPrimitives().not(tokens[1], tokens[2]);
2302 } else if (tokens[0].equals("exp")) {
2303 assertExactParametreCount(tokens, 2);
2304 context.getPrimitives().exp(tokens[1], tokens[2]);
2305 } else if (tokens[0].equals("log")) {
2306 assertExactParametreCount(tokens, 2);
2307 context.getPrimitives().log(tokens[2], tokens[2]);
2308 } else if (tokens[0].equals("log10")) {
2309 assertExactParametreCount(tokens, 2);
2310 context.getPrimitives().log10(tokens[1], tokens[2]);
2311 } else if (tokens[0].equals("sqrt")) {
2312 assertExactParametreCount(tokens, 2);
2313 context.getPrimitives().sqrt(tokens[1], tokens[2]);
2314 } else if (tokens[0].equals("closewritefile")) {
2315 assertVariableType(tokens[1], 1, SPointer.filePrefix);
2316 context.closeWriteFile(tokens[1]);
2317 } else if (tokens[0].equals("closereadfile")) {
2318 assertVariableType(tokens[1], 1, SPointer.filePrefix);
2319 context.closeReadFile(tokens[1]);
2320 } else if (tokens[0].startsWith("foreach")) {
2321 if (tokens[0].equals("foreachassociation")) {
2322 assertExactParametreCount(tokens, 3);
2323 assertVariableType(tokens[1], 1, SPointer.associationPrefix);
2324 Map<String, String> map = (Map<String, String>) context
2325 .getPointers().getVariable(tokens[1]).getValue();
2326 for (Map.Entry entry : map.entrySet()) {
2327 String value = entry.getValue().toString();
2328 String key = entry.getKey().toString();
2329 context.getPrimitives().setValue(tokens[2], key);
2330 context.getPrimitives().setValue(tokens[3], value);
2331 Status status = RunFrameAndReportError(code, context);
2332 pause(code);
2333 // check if we need to exit this loop because of
2334 // statements in the code that was run
2335 if (status == Status.Exit || status == Status.Return)
2336 return status;
2337 else if (status == Status.Break)
2338 break;
2339 }
2340 } else {
2341 Class itemType = Object.class;
2342 String type = tokens[0].substring("foreach".length());
2343 // Check the type of foreach loop
2344 // and set the item type to iterate over
2345 if (type.equals("dot")) {
2346 itemType = Dot.class;
2347 } else if (type.equals("text")) {
2348 itemType = Text.class;
2349 } else if (type.equals("line")) {
2350 itemType = Line.class;
2351 } else if (type.equals("item") || type.equals("")) {
2352 itemType = Object.class;
2353 } else {
2354 throw new RuntimeException("Invalid ForEach loop type");
2355 }
2356
2357 assertVariableType(tokens[2], 2, SPointer.itemPrefix);
2358 assertVariableType(tokens[1], 1, SPointer.framePrefix);
2359 Frame currFrame = (Frame) context.getPointers().getVariable(
2360 tokens[1]).getValue();
2361 // Create the ip variable
2362 Item frameTitle = currFrame.getTitleItem();
2363
2364 for (Item i : currFrame.getItems()) {
2365 if (i == frameTitle)
2366 continue;
2367 if (!(itemType.isInstance(i)))
2368 continue;
2369
2370 context.getPointers().setObject(tokens[2], i);
2371 Status status = RunFrameAndReportError(code, context);
2372 pause(code);
2373 // check if we need to exit this loop because of
2374 // statements in the code that was run
2375 if (status == Status.Exit || status == Status.Return)
2376 return status;
2377 else if (status == Status.Break)
2378 return Status.OK;
2379 }
2380 }
2381 } else if (tokens[0].equals("movecursorto")) {
2382 assertExactParametreCount(tokens, 2);
2383 int x = (int) context.getPrimitives().getIntegerValue(tokens[1]);
2384 int y = (int) context.getPrimitives().getIntegerValue(tokens[2]);
2385 DisplayIO.setCursorPosition(x, y);
2386 } else {
2387 throw new RuntimeException("Unknown statement");
2388 }
2389 return Status.OK;
2390 }
2391
2392 public static int countCharsInString(String s, String pattern) {
2393 String newString = s;
2394 int count = -1;
2395 do {
2396 count++;
2397 s = newString;
2398 newString = s.replaceFirst(pattern, "");
2399 } while (s.length() != newString.length());
2400
2401 return count;
2402 }
2403
2404 public static void assertVariableType(String varName, int no, String type)
2405 throws Exception {
2406 if (!varName.startsWith(type))
2407 throw new IncorrectTypeException(type, no);
2408 }
2409
2410 /*
2411 * public static void assertPrimitiveType(String varName, int no) throws
2412 * Exception { if (!Primitives.isPrimitive(varName)) throw new
2413 * IncorrectTypeException("primitive", no); }
2414 */
2415
2416 public static void assertMinParametreCount(String[] tokens,
2417 int minParametres) throws Exception {
2418 if (tokens.length - 1 < minParametres)
2419 throw new BelowMinParametreCountException(minParametres);
2420 }
2421
2422 public static void assertExactParametreCount(String[] tokens,
2423 int parametreCount) throws Exception {
2424 if (tokens.length - 1 != parametreCount)
2425 throw new IncorrectParametreCountException(parametreCount);
2426 }
2427
2428 public static void assertMaxParametreCount(String[] tokens,
2429 int parametreCount) throws Exception {
2430 if (tokens.length - 1 > parametreCount)
2431 throw new AboveMaxParametreCountException(parametreCount);
2432 }
2433
2434 private static String getMessage(String[] tokens, Context context,
2435 String code, String separator, int firstStringIndex)
2436 throws Exception {
2437 StringBuilder message = new StringBuilder();
2438 if (tokens.length == firstStringIndex) {
2439 message.append(context.getPrimitives().getVariable(DEFAULT_STRING)
2440 .stringValue());
2441 } else {
2442 for (int i = firstStringIndex; i < tokens.length; i++) {
2443 if (Primitives.isPrimitive(tokens[i])) {
2444 message.append(context.getPrimitives().getVariable(
2445 tokens[i]).stringValue()
2446 + separator);
2447 } else
2448 throw new Exception("Illegal parametre: [" + tokens[i]
2449 + "] in line " + code);
2450 }
2451 }
2452 return message.toString();
2453 }
2454
2455 public static void stop() {
2456 _stop = true;
2457 }
2458
2459 public static void nextStatement() {
2460 _nextStatement = true;
2461 }
2462
2463 public static void ProgramStarted() {
2464 _programsRunning++;
2465 AgentStats.reset();
2466 FrameGraphics.DisplayMessage("Running SimpleProgram...", Color.BLUE);
2467 }
2468}
Note: See TracBrowser for help on using the repository browser.