!ACSL - JR

!Takoma Park MS

!David Tolnay

 

DIM commands$(0)

DO

   INPUT PROMPT "Command: ": command$

   LET command$ = ucase$(command$)

   LET numcom = 0

   LET lastslash = 1

   MAT REDIM commands$(0)

   FOR slash = 1 TO len(command$)

      IF command$[slash:slash] = "/" THEN

         LET numcom = numcom + 1

         MAT REDIM commands$(numcom)

         LET commands$(numcom) = command$[lastslash:slash - 1]

         LET lastslash = slash + 1

      END IF

   NEXT slash

   LET string$ = command$[lastslash:len(command$)]

   LET error = 0

   FOR exec = 1 TO numcom

      WHEN ERROR IN

         LET amount = val(commands$(exec)[4:len(commands$(exec))])

      USE

         LET arguments$ = commands$(exec)[4:len(commands$(exec))]

         IF len(arguments$) <> 4 OR POS("0123456789",arguments$[1:1]) = 0 OR POS("0123456789",arguments$[2:2]) = 0 OR POS("0123456789",arguments$[3:3]) = 0 OR arguments$[4:4] <> "R" AND arguments$[4:4] <> "L" THEN

            PRINT "Error: Invalid command."

            LET error = 1

            EXIT FOR

         ELSE

            LET s = val(arguments$[1:1])

            LET l = val(arguments$[2:2])

            LET x = val(arguments$[3:3])

            LET d$ = arguments$[4:4]

         END IF

      END WHEN

      IF commands$(exec)[1:3] = "LS-" THEN

         CALL ls(amount,string$)

      ELSE IF commands$(exec)[1:3] = "RS-" THEN

         CALL rs(amount,string$)

      ELSE IF commands$(exec)[1:3] = "LC-" THEN

         CALL lc(amount,string$)

      ELSE IF commands$(exec)[1:3] = "RC-" THEN

         CALL rc(amount,string$)

      ELSE IF commands$(exec)[1:3] = "MC-" THEN

         CALL mc(s,l,x,d$,string$)

      ELSE

         PRINT "Error: Invalid command."

         LET error = 1

         EXIT FOR

      END IF

   NEXT exec

   IF error = 0 THEN

      PRINT string$

   END IF

   PRINT

   DO

      INPUT PROMPT "Another command? (y/n) ": again$

      LET again$ = lcase$(again$[1:1])

      IF again$ <> "y" AND again$ <> "n" THEN

         PRINT "Invalid."

      END IF

   LOOP UNTIL again$ = "y" OR again$ = "n"

   PRINT

LOOP UNTIL again$ = "n"

END

 

SUB ls(amount,string$)

   FOR add = 1 TO amount

      LET string$ = string$ & "#"

   NEXT add

   LET string$ = string$[amount + 1:len(string$)]

END SUB

 

SUB rs(amount,string$)

   FOR add = 1 TO amount

      LET string$ = "#" & string$

   NEXT add

   LET string$ = string$[1:len(string$) - amount]

END SUB

 

SUB lc(amount,string$)

   FOR circ = 1 TO amount

      LET string$ = string$[2:len(string$)] & string$[1:1]

   NEXT circ

END SUB

 

SUB rc(amount,string$)

   FOR circ = 1 TO amount

      LET string$ = string$[len(string$):len(string$)] & string$[1:len(string$) - 1]

   NEXT circ

END SUB

 

SUB mc(s,l,x,d$,string$)

   LET use$ = string$[s:s + l - 1]

   IF d$ = "R" THEN

      CALL rc(x,use$)

   ELSE

      CALL lc(x,use$)

   END IF

   LET string$ = string$[1:s - 1] & use$ & string$[s + l:len(string$)]

END SUB