import java.util.*;

public class MovementRoutine
{
    public MovementRoutine (String fullCommand, Vector<MovementFunction> functions, boolean debug)
    {
        _fullCommand = fullCommand;
        _functions = functions;
        _debug = debug;
    }

    public String getMainRoutine ()
    {
        /*
         * We know that Function A (1) is first in the sequence, followed by
         * B (2) and then C (3) is last but we don't know the order they follow
         * after the first.
         */

        String str = FunctionRoutine.ROUTINE_A;
        int index = _functions.elementAt(FunctionRoutine.ROUTINE_A_INDEX).getLength();

        System.out.println("index "+index);
        System.out.println("fullCommand "+_fullCommand.length());

        while (index < _fullCommand.length())
        {
            System.out.println("Searching for "+_functions.elementAt(FunctionRoutine.ROUTINE_A_INDEX).getCommand());

            if (_fullCommand.startsWith(_functions.elementAt(FunctionRoutine.ROUTINE_A_INDEX).getCommand(), index))
            {
                str += ","+FunctionRoutine.ROUTINE_A;

                index += _functions.elementAt(FunctionRoutine.ROUTINE_A_INDEX).getLength();
            }
            else
            {
                System.out.println("Searching for "+_functions.elementAt(FunctionRoutine.ROUTINE_B_INDEX).getCommand());

                if (_fullCommand.startsWith(_functions.elementAt(FunctionRoutine.ROUTINE_B_INDEX).getCommand(), index))
                {
                    str += str += ","+FunctionRoutine.ROUTINE_B;

                    index += _functions.elementAt(FunctionRoutine.ROUTINE_B_INDEX).getLength();
                }
                else
                {
                    System.out.println("Searching for "+_functions.elementAt(FunctionRoutine.ROUTINE_C_INDEX).getCommand());

                    if (_fullCommand.startsWith(_functions.elementAt(FunctionRoutine.ROUTINE_C_INDEX).getCommand(), index))
                    {
                        str += str += ","+FunctionRoutine.ROUTINE_C;

                        index += _functions.elementAt(FunctionRoutine.ROUTINE_C_INDEX).getLength();
                    }
                    else
                    {
                        System.out.println("Error, no functions found in commannd string "+_fullCommand);

                        System.exit(0);
                    }
                }
            }
        }

        return str;
    }

    private String _fullCommand;
    private Vector<MovementFunction> _functions;
    private boolean _debug;
}
@@ -548,16 +548,57 @@
 TINE_A;%0A
+        String searchStr = _fullCommand;%0A
         
@@ -836,32 +836,81 @@
 th())%0A        %7B%0A
+            System.out.println(%22index %22+index);%0A%0A
             Syst
@@ -1023,32 +1023,93 @@
         
-if (_fullCommand
+System.out.println(%22search string is %22+searchStr);%0A%0A            if (searchStr
 .startsW
@@ -1170,39 +1170,32 @@
 EX).getCommand()
-, index
 ))%0A            %7B
@@ -1250,16 +1250,67 @@
 INE_A;%0A%0A
+                System.out.println(%22Found %22+str);%0A%0A
         
@@ -1384,32 +1384,151 @@
 EX).getLength();
+%0A%0A                searchStr = searchStr.substring(_functions.elementAt(FunctionRoutine.ROUTINE_A_INDEX).getLength()+1);
 %0A            %7D%0A 
@@ -1695,36 +1695,33 @@
         if (
-_fullCommand
+searchStr
 .startsWith(
@@ -1778,39 +1778,32 @@
 EX).getCommand()
-, index
 ))%0A             
@@ -1825,39 +1825,32 @@
           str +=
- str +=
  %22,%22+FunctionRou
@@ -1866,16 +1866,71 @@
 INE_B;%0A%0A
+                    System.out.println(%22Found %22+str);%0A%0A
         
@@ -2008,32 +2008,155 @@
 EX).getLength();
+%0A%0A                    searchStr = searchStr.substring(_functions.elementAt(FunctionRoutine.ROUTINE_B_INDEX).getLength()+1);
 %0A               
@@ -2347,28 +2347,25 @@
     if (
-_fullCommand
+searchStr
 .startsW
@@ -2405,33 +2405,33 @@
 Routine.ROUTINE_
-C
+B
 _INDEX).getComma
@@ -2438,15 +2438,8 @@
 nd()
-, index
 ))%0A 
@@ -2489,23 +2489,16 @@
   str +=
- str +=
  %22,%22+Fun
@@ -2522,16 +2522,75 @@
 INE_C;%0A%0A
+                        System.out.println(%22Found %22+str);%0A%0A
         
@@ -2680,16 +2680,143 @@
 ength();
+%0A%0A                        searchStr = searchStr.substring(_functions.elementAt(FunctionRoutine.ROUTINE_C_INDEX).getLength()+1);
 %0A       

Update MovementRoutine.java