#include <perms.h>

                                                                //      1  !* Program Name : IF
                                                                //      2  
                                                                //      3  !*   Title      :  IX   The Imp  Conditional Statements
                                                                //      4  !*   Version    :  II
                                                                //      5  !*   Date       :  24 August 1985
                                                                //      6  !*   Description:  Tests the %IF and %UNLESS Statements.
                                                                //      7  
                                                                //      8  %Begin
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //      9  
                                                                //     10      %string(255) param    { Used to get input from CLI}
_imp_string /*%string(255)*/ PARAM;
                                                                //     11  
                                                                //     12      %Integer  J
int J;
                                                                //     13      %Integer  K
int K;
                                                                //     14      %Integer  M
int M;
                                                                //     15      %Integer  Acc
int ACC;
                                                                //     16  
                                                                //     17  %owninteger failures=0
static int FAILURES = 0;
                                                                //     18  
                                                                //     19  %routine pass
void PASS( void )
{
                                                                //     20    printstring("Pass")
_imp_PRINTSTRING(_imp_str_literal("Pass"));
                                                                //     21    New Line
_imp_NEWLINE();
                                                                //     22  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block PASS at level 2
                                                                //     23  %routine fail
void FAIL( void )
{
                                                                //     24    printstring("FAIL")
_imp_PRINTSTRING(_imp_str_literal("FAIL"));
                                                                //     25    New Line
_imp_NEWLINE();
                                                                //     26    failures = failures+1
FAILURES = (((int)(FAILURES)) + (1));
                                                                //     27  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block FAIL at level 2
                                                                //     28  
                                                                //     29  
                                                                //     30  
                                                                //     31     ! Code to find out where the output is to be sent
                                                                //     32     ! -----------------------------------------------
                                                                //     33     ! Where the output goes to depends on the parameter after the
                                                                //     34     ! name used to run the program.
                                                                //     35     !                       Parameter   |   Result
                                                                //     36     !                       ------------|-------------
                                                                //     37     !                     No parameter  |  No output
                                                                //     38     !                          "s"      |  The screen
                                                                //     39     !                          "j"      |  "journal"
                                                                //     40     !                     anything else |  file name entered
                                                                //     41  
                                                                //     42     ! NOTE THAT THIS CODE USES STRING COMPARISONS, WHICH MAY NOT HAVE BEEN
                                                                //     43     ! TESTED YET. IF THE PROGRAM FAILS CHECK IT WAS NOT IN THIS PART.
                                                                //     44  
                                                                //     45     param=cliparam
PARAM = _imp_CLIPARAM();
                                                                //     46     %if param = "" %then select output (2) %c
if ((_imp_strcmp(PARAM, _imp_str_literal("")) != 0)) goto L_0002;
_imp_SELECTOUTPUT(2);
goto L_0003;
L_0002:;
if ((_imp_strcmp(PARAM, _imp_str_literal("s")) == 0)) goto L_0004;
if ((_imp_strcmp(PARAM, _imp_str_literal("S")) != 0)) goto L_0005;
L_0004:;
_imp_SELECTOUTPUT(1);
goto L_0003;
L_0005:;
if ((_imp_strcmp(PARAM, _imp_str_literal("j")) == 0)) goto L_0006;
if ((_imp_strcmp(PARAM, _imp_str_literal("J")) != 0)) goto L_0007;
L_0006:;
_imp_OPENOUTPUT(2, _imp_str_literal("journal"));
_imp_SELECTOUTPUT(2);
goto L_0003;
L_0007:;
_imp_OPENOUTPUT(2, PARAM);
_imp_SELECTOUTPUT(2);
L_0003:;
                                                                //     47     %else %if param="s" %or param="S" %then select output(1) %c
                                                                //     48     %else %if param="j" %or param="J" %then  %c
                                                                //     49        open output(2,"journal") %and select output (2) %c
                                                                //     50     %else open output(2,param) %and select output (2)
                                                                //     51     
                                                                //     52  
                                                                //     53  
                                                                //     54     New Lines(2)
_imp_NEWLINES(2);
                                                                //     55     Print String ("Conditional Statements");   New Line
_imp_PRINTSTRING(_imp_str_literal("Conditional Statements"));
_imp_NEWLINE();
                                                                //     56     Print String ("======================");   New Lines (3)
_imp_PRINTSTRING(_imp_str_literal("======================"));
_imp_NEWLINES(3);
                                                                //     57  
                                                                //     58  
                                                                //     59  
                                                                //     60  
                                                                //     61      Print String ("Test the Full %IF Conditional");   New Line
_imp_PRINTSTRING(_imp_str_literal("Test the Full %IF Conditional"));
_imp_NEWLINE();
                                                                //     62      Print String ("-----------------------------");   New Line
_imp_PRINTSTRING(_imp_str_literal("-----------------------------"));
_imp_NEWLINE();
                                                                //     63  
                                                                //     64      
                                                                //     65      M = 0
M = 0;
                                                                //     66      Acc = 0
ACC = 0;
                                                                //     67      %For J = 1, 1, 10 %cycle
J = 0;
if ((((10)-(1)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle J = 1, 1, 10");
L_0008:;
if (J == 10) goto L_0009;
J += 1;
                                                                //     68         %If J = 1 %then %Start
if (((J) != (1))) goto L_000b;
                                                                //     69            Acc = Acc + 1
ACC = (((int)(ACC)) + (1));
                                                                //     70            K = 1
K = 1;
                                                                //     71         %Finish %else %If J = 2 %then %Start
goto L_000c;
L_000b:;
if (((J) != (2))) goto L_000d;
                                                                //     72            Acc = Acc + 2
ACC = (((int)(ACC)) + (2));
                                                                //     73            K = 2
K = 2;
                                                                //     74         %Finish %else %If J = 3 %then %Start
goto L_000c;
L_000d:;
if (((J) != (3))) goto L_000e;
                                                                //     75            Acc = Acc + 3
ACC = (((int)(ACC)) + (3));
                                                                //     76            K = 3
K = 3;
                                                                //     77         %Finish %else %If J = 4 %then %Start
goto L_000c;
L_000e:;
if (((J) != (4))) goto L_000f;
                                                                //     78            Acc = Acc + 4
ACC = (((int)(ACC)) + (4));
                                                                //     79            K = 4
K = 4;
                                                                //     80         %Finish %else %If J = 5 %then %Start
goto L_000c;
L_000f:;
if (((J) != (5))) goto L_0010;
                                                                //     81            Acc = Acc + 5
ACC = (((int)(ACC)) + (5));
                                                                //     82            K = 5
K = 5;
                                                                //     83         %Finish %else %If J = 6 %then %Start
goto L_000c;
L_0010:;
if (((J) != (6))) goto L_0011;
                                                                //     84            Acc = Acc + 6
ACC = (((int)(ACC)) + (6));
                                                                //     85            K = 6
K = 6;
                                                                //     86         %Finish %else %If J = 7 %then %Start
goto L_000c;
L_0011:;
if (((J) != (7))) goto L_0012;
                                                                //     87            Acc = Acc + 7
ACC = (((int)(ACC)) + (7));
                                                                //     88            K = 7
K = 7;
                                                                //     89         %Finish %else %If J = 8 %then %Start
goto L_000c;
L_0012:;
if (((J) != (8))) goto L_0013;
                                                                //     90            Acc = Acc + 8
ACC = (((int)(ACC)) + (8));
                                                                //     91            K = 8
K = 8;
                                                                //     92         %Finish %else %If J = 9 %then %Start
goto L_000c;
L_0013:;
if (((J) != (9))) goto L_0014;
                                                                //     93            Acc = Acc + 9
ACC = (((int)(ACC)) + (9));
                                                                //     94            K = 9
K = 9;
                                                                //     95         %Finish %else %Start
goto L_000c;
L_0014:;
                                                                //     96            Acc = Acc + 10
ACC = (((int)(ACC)) + (10));
                                                                //     97            K = 10
K = 10;
                                                                //     98         %Finish 
L_000c:;
                                                                //     99         %Unless K = J %then M = M + 1
if (((K) == (J))) goto L_0015;
M = (((int)(M)) + (1));
L_0015:;
                                                                //    100      %Repeat
goto L_0008;
L_0009:;
                                                                //    101  
                                                                //    102      %Unless M = 0 %and Acc = 45 %then pass %else fail
if (((M) != (0))) goto L_000a;
if (((ACC) == (45))) goto L_0016;
L_000a:;
PASS();
goto L_0017;
L_0016:;
FAIL();
L_0017:;
                                                                //    103  !   Long-winded conditional.
                                                                //    104  
                                                                //    105  
                                                                //    106      Acc = 0
ACC = 0;
                                                                //    107      %Unless Acc = 0 %then %Start
if (((ACC) == (0))) goto L_0018;
                                                                //    108          M = 1
M = 1;
                                                                //    109      %Finish %else %Start
goto L_0019;
L_0018:;
                                                                //    110          M = 2
M = 2;
                                                                //    111      %Finish
L_0019:;
                                                                //    112  
                                                                //    113      %If M = 2 %then pass %else fail
if (((M) != (2))) goto L_001a;
PASS();
goto L_001b;
L_001a:;
FAIL();
L_001b:;
                                                                //    114  !   The long %UNLESS variant with TRUE condition.
                                                                //    115  
                                                                //    116  
                                                                //    117  
                                                                //    118      Acc = 1
ACC = 1;
                                                                //    119      %Unless Acc = 0 %then %Start
if (((ACC) == (0))) goto L_001c;
                                                                //    120          M = 1
M = 1;
                                                                //    121      %Finish %else %Start
goto L_001d;
L_001c:;
                                                                //    122          M = 2
M = 2;
                                                                //    123      %Finish
L_001d:;
                                                                //    124  
                                                                //    125      %If M = 1 %then pass %else fail
if (((M) != (1))) goto L_001e;
PASS();
goto L_001f;
L_001e:;
FAIL();
L_001f:;
                                                                //    126  !   The long %UNLESS variant with FALSE condition.
                                                                //    127  
                                                                //    128    
                                                                //    129  
                                                                //    130  
                                                                //    131  
                                                                //    132  
                                                                //    133      !*  Test the shortend variants of %IF and %UNLESS
                                                                //    134  
                                                                //    135      Acc = 0
ACC = 0;
                                                                //    136      M   = 0
M = 0;
                                                                //    137      Acc = 1 %if Acc = 0
if (((ACC) != (0))) goto L_0020;
ACC = 1;
L_0020:;
                                                                //    138      M   = 1 %if M = 1
if (((M) != (1))) goto L_0021;
M = 1;
L_0021:;
                                                                //    139  
                                                                //    140      %If M = 0 %and Acc = 1 %then pass %else fail
if (((M) != (0))) goto L_0022;
if (((ACC) != (1))) goto L_0022;
PASS();
goto L_0023;
L_0022:;
FAIL();
L_0023:;
                                                                //    141  
                                                                //    142  
                                                                //    143      Acc = 0
ACC = 0;
                                                                //    144      M   = 0
M = 0;
                                                                //    145      Acc = 1 %unless Acc = 0
if (((ACC) == (0))) goto L_0024;
ACC = 1;
L_0024:;
                                                                //    146      M   = 2 %unless M   = 1
if (((M) == (1))) goto L_0025;
M = 2;
L_0025:;
                                                                //    147  
                                                                //    148      %If M = 2 %and Acc = 0 %then pass %else fail
if (((M) != (2))) goto L_0026;
if (((ACC) != (0))) goto L_0026;
PASS();
goto L_0027;
L_0026:;
FAIL();
L_0027:;
                                                                //    149  
                                                                //    150  
                                                                //    151  
                                                                //    152  select output(1)
_imp_SELECTOUTPUT(1);
                                                                //    153  write(failures,1);  printstring(" failure(s)");  newline
_imp_WRITE(FAILURES, 1);
_imp_PRINTSTRING(_imp_str_literal(" failure(s)"));
_imp_NEWLINE();
                                                                //    154  
                                                                //    155  %End %of %Program
/* Remove %on %event handler here if present for this block */
return 0;
} // End of block _imp_main at level 1
// End of file
