/*            Interact.rexx                      */
/*                                               */
/* A program to demonstrate interactive tracing  */

options prompt "enter input ->"

/* We will use the following code to change the tracing    */
SIGNAL ON BREAK_F
/* Use this to eperiment. If you get stuck use the TS command from the  */
/* CLI, or Ctrl-C.                                                       */


/* We will use the following code to restart the read main loop */
SIGNAL ON BREAK_D

/* These are the definitions of the AREXX datatypes. We will use them in */
/* the 'analyse' function, for demonstration                             */
$a = 'alphanumeric' ; $b = 'binary'
$l = 'lowercase'    ; $m = 'mixed'
$n = 'numeric'      ; $s = 'symbol'
$u = 'upper'        ; $w = 'whole'

resume:
/* Our main input  - "000"   will cause an exit               */
/*      loop       - "$auto" will enter an automatic loop     */
/*                 - anything else will be processed          */

DO FOREVER
parse pull input
/* test if "000" was entered ('==' means exact equality. If we used '='  */
/*                             then 0 would also cause an exit )         */
IF input == "000" THEN LEAVE

/* test if "$auto" was entered. If so go to automatic loop.              */
IF input == "$auto"
   THEN DO FOREVER           /* this is the automatic loop    */
   SIGNAL ON BREAK_D         /* you can only break out of it  */
   rn = 1234.5               /* with a Ctrl-D.  The SIGNAL    */
   call analyse(rn)          /* instruction MUST be specified */
   END                       /* inside loops                  */

/* If it is neither of the above two, we process it   */
call analyse(input)

END  /* End of main loop - you can only break out with a Ctrl-F  */
     /* (to change the trace) or the usual Ctrl-C (halt)         */
     /* You can also get out by typing 000 at the prompt         */

EXIT 0  /* end of program */

break_d:
/* get out of automatic loop */
SIGNAL resume

break_f:
/* set the trace mode - program starts with trace off */
say "Enter a trace code (One of following :- A, C, E, I, L, N, R, S, ? or ! )"
pull code
trace value code
/* *******************************************************
 Here is a brief description of the tracing prefix codes that
 appear during traces: INTERMEDIATES will display them all

        CODE      Explanation
        >+>    Interactive line - enter command here!
        +++    Marks syntax error
        >C>    A compound name that has been expanded to this
        >F>    Function return
        >L>    Label
        >O>    Result of a two parameter operation
        >P>    Result of prefix operation
        >U>    Variable that has not been assigned a value
        >V>    Value of variable
        >>>    From expression or template
        >.>    Token placeholder

   ******************************************************** */

SIGNAL resume

analyse:
/* this function processes the string it is given.           */
/* it will tell us if the given strings are AREXX datatypes  */
parse arg testring
say "We are now analysing « " testring " ».  It is  "
IF datatype(testring,$a) THEN say "an" $a  "datatype"
IF datatype(testring,$b) THEN say "a" $b  "datatype"
IF datatype(testring,$l) THEN say "a" $l  "datatype"
IF datatype(testring,$m) THEN say "a" $m  "datatype"
IF datatype(testring,$n) THEN say "a" $n  "datatype"
IF datatype(testring,$s) THEN say "a" $s  "datatype"
IF datatype(testring,$u) THEN say "a" $u  "datatype"
IF datatype(testring,$w) THEN say "a" $w  "datatype"
RETURN