#include <perms.h>

                                                                //      1  !* Program Name : ARRNAME
                                                                //      2  
                                                                //      3  !*   Title      :  XVIII  Integer Array Name Procedure Parameter Testing
                                                                //      4  !*   Version    :  II
                                                                //      5  !*   Date       :  24 August 1985
                                                                //      6  !*   Description:  Checks that functions containg %integer %array %name     
                                                                //      7  !*                 as parameters returns the correct values.               
                                                                //      8  
                                                                //      9  
                                                                //     10  %begin
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //     11  
                                                                //     12  %string(255) param    { Used to get input from CLI}
_imp_string /*%string(255)*/ PARAM;
                                                                //     13  
                                                                //     14  %owninteger failures=0
static int FAILURES = 0;
                                                                //     15  
                                                                //     16  %ownintegerarray aa(1:10) = 1,2,3,4,5,6,7,8,9,10
static int AA[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,  };
                                                                //     17  
                                                                //     18  ! Three routines to chack the that the array is passed correctly
                                                                //     19  %integerfn sigma(%integerarrayname a{(1:10)})
int SIGMA( int /*arrayname*/*A )
{
                                                                //     20  %integer i,j=0
int I;
int J;
J = 0;
                                                                //     21    j = j+a(i) %for i = 1,1,10
I = 0;
if ((((10)-(1)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 1, 1, 10");
L_0002:;
if (I == 10) goto L_0003;
I += 1;
J = (((int)(J)) + (A[I]));
goto L_0002;
L_0003:;
                                                                //     22    %result = j
/* Remove %on %event handler here if present for this block */
return J;
                                                                //     23  %end
} // End of block SIGMA at level 2
                                                                //     24  
                                                                //     25  %integerfn sigma2(%integerarrayname a{(1:10)})
int SIGMA2( int /*arrayname*/*A )
{
                                                                //     26  %integer i,j=0
int I;
int J;
J = 0;
                                                                //     27    j = j+j+a(i) %for i = 1,1,10
I = 0;
if ((((10)-(1)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 1, 1, 10");
L_0005:;
if (I == 10) goto L_0006;
I += 1;
J = (((int)((((int)(J)) + (J)))) + (A[I]));
goto L_0005;
L_0006:;
                                                                //     28    %result = j
/* Remove %on %event handler here if present for this block */
return J;
                                                                //     29  %end
} // End of block SIGMA2 at level 2
                                                                //     30  
                                                                //     31  %integerfn sigma3(%integerarrayname a{(1:10)})
int SIGMA3( int /*arrayname*/*A )
{
                                                                //     32  %integer i,j=0
int I;
int J;
J = 0;
                                                                //     33    j = j+j+j+a(i) %for i = 1,1,10
I = 0;
if ((((10)-(1)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 1, 1, 10");
L_0008:;
if (I == 10) goto L_0009;
I += 1;
J = (((int)((((int)((((int)(J)) + (J)))) + (J)))) + (A[I]));
goto L_0008;
L_0009:;
                                                                //     34    %result = j
/* Remove %on %event handler here if present for this block */
return J;
                                                                //     35  %end
} // End of block SIGMA3 at level 2
                                                                //     36  
                                                                //     37  ! Check that the values in the array can be changed
                                                                //     38  %integerfn change(%integerarrayname a{(1:10)})
int CHANGE( int /*arrayname*/*A )
{
                                                                //     39  %integer i,j=0
int I;
int J;
J = 0;
                                                                //     40    a(i)=a(i)*2 %for i =1,1,10
I = 0;
if ((((10)-(1)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 1, 1, 10");
L_000b:;
if (I == 10) goto L_000c;
I += 1;
A[I] = (((int)(A[I])) * (2));
goto L_000b;
L_000c:;
                                                                //     41    j=j+a(i) %for i= 3,1,9
I = 2;
if ((((9)-(3)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 3, 1, 9");
L_000e:;
if (I == 9) goto L_000f;
I += 1;
J = (((int)(J)) + (A[I]));
goto L_000e;
L_000f:;
                                                                //     42    %result = j
/* Remove %on %event handler here if present for this block */
return J;
                                                                //     43  %end
} // End of block CHANGE at level 2
                                                                //     44  
                                                                //     45  ! Check that the array is still changed when the
                                                                //     46  ! previous function has finished.
                                                                //     47  %integerfn Check(%integerarrayname a{(1:10)})
int CHECK( int /*arrayname*/*A )
{
                                                                //     48  %integer i,j=0
int I;
int J;
J = 0;
                                                                //     49     %for i=1,1,10 %cycle
I = 0;
if ((((10)-(1)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 1, 1, 10");
L_0011:;
if (I == 10) goto L_0012;
I += 1;
                                                                //     50       j=j+1 %if a(i)=i*2
if (((A[I]) != ((((int)(I)) * (2))))) goto L_0014;
J = (((int)(J)) + (1));
L_0014:;
                                                                //     51     %repeat
goto L_0011;
L_0012:;
                                                                //     52     %result = j
/* Remove %on %event handler here if present for this block */
return J;
                                                                //     53  %end
} // End of block CHECK at level 2
                                                                //     54  
                                                                //     55  ! routine that checks whether the above functions return the correct values
                                                                //     56  !!%routine do(%integerfn f(%integerarrayname x{(1:10)}),
                                                                //     57  !!            %integer res)
                                                                //     58  
                                                                //     59  %integer i, res
int I;
int RES;
                                                                //     60  
                                                                //     61    %routine pass
void PASS( void )
{
                                                                //     62      printstring(" Pass")
_imp_PRINTSTRING(_imp_str_literal(" Pass"));
                                                                //     63      New Line
_imp_NEWLINE();
                                                                //     64    %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block PASS at level 2
                                                                //     65    %routine fail
void FAIL( void )
{
                                                                //     66      printstring(" FAIL :")
_imp_PRINTSTRING(_imp_str_literal(" FAIL :"));
                                                                //     67      printstring(" Was expecting");write(res,1)
_imp_PRINTSTRING(_imp_str_literal(" Was expecting"));
_imp_WRITE(RES, 1);
                                                                //     68      printstring(" and got");write(i,1)
_imp_PRINTSTRING(_imp_str_literal(" and got"));
_imp_WRITE(I, 1);
                                                                //     69      New Line
_imp_NEWLINE();
                                                                //     70      failures = failures+1
FAILURES = (((int)(FAILURES)) + (1));
                                                                //     71    %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block FAIL at level 2
                                                                //     72  
                                                                //     73  !!  i = f(aa)
                                                                //     74  !!  %if i = res %then pass %else fail
                                                                //     75  !!%end
                                                                //     76  
                                                                //     77     ! Code to find out where the output is to be sent
                                                                //     78     ! -----------------------------------------------
                                                                //     79     ! Where the output goes to depends on the parameter after the
                                                                //     80     ! name used to run the program.
                                                                //     81     !                       Parameter   |   Result
                                                                //     82     !                       ------------|-------------
                                                                //     83     !                     No parameter  |  No output
                                                                //     84     !                          "s"      |  The screen
                                                                //     85     !                          "j"      |  "journal"
                                                                //     86     !                     anything else |  file name entered
                                                                //     87  
                                                                //     88     ! NOTE THAT THIS CODE USES STRING COMPARISONS, WHICH MAY NOT HAVE BEEN
                                                                //     89     ! TESTED YET. IF THE PROGRAM FAILS CHECK IT WAS NOT IN THIS PART.
                                                                //     90  
                                                                //     91     param=cliparam
PARAM = _imp_CLIPARAM();
                                                                //     92     %if param = "" %then select output (2) %c
if ((_imp_strcmp(PARAM, _imp_str_literal("")) != 0)) goto L_0015;
_imp_SELECTOUTPUT(2);
goto L_0016;
L_0015:;
if ((_imp_strcmp(PARAM, _imp_str_literal("s")) == 0)) goto L_0017;
if ((_imp_strcmp(PARAM, _imp_str_literal("S")) != 0)) goto L_0018;
L_0017:;
_imp_SELECTOUTPUT(1);
goto L_0016;
L_0018:;
if ((_imp_strcmp(PARAM, _imp_str_literal("j")) == 0)) goto L_0019;
if ((_imp_strcmp(PARAM, _imp_str_literal("J")) != 0)) goto L_001a;
L_0019:;
_imp_OPENOUTPUT(2, _imp_str_literal("journal"));
_imp_SELECTOUTPUT(2);
goto L_0016;
L_001a:;
_imp_OPENOUTPUT(2, PARAM);
_imp_SELECTOUTPUT(2);
L_0016:;
                                                                //     93     %else %if param="s" %or param="S" %then select output(1) %c
                                                                //     94     %else %if param="j" %or param="J" %then  %c
                                                                //     95        open output(2,"journal") %and select output (2) %c
                                                                //     96     %else open output(2,param) %and select output (2)
                                                                //     97     
                                                                //     98  
                                                                //     99    New Line
_imp_NEWLINE();
                                                                //    100    Print string ("Integer array names as parameters"); New Line
_imp_PRINTSTRING(_imp_str_literal("Integer array names as parameters"));
_imp_NEWLINE();
                                                                //    101    Print string ("---------------------------------"); New Line
_imp_PRINTSTRING(_imp_str_literal("---------------------------------"));
_imp_NEWLINE();
                                                                //    102  
                                                                //    103    !do(sigma,55)
                                                                //    104    i = sigma(aa); res = 55
I = SIGMA(/*is_array_name3*/ &((AA-1)[0]));
RES = 55;
                                                                //    105    %if i = res %then pass %else fail
if (((I) != (RES))) goto L_001b;
PASS();
goto L_001c;
L_001b:;
FAIL();
L_001c:;
                                                                //    106  
                                                                //    107    !do(sigma2,2036)
                                                                //    108    i = sigma2(aa); res = 2036
I = SIGMA2(/*is_array_name3*/ &((AA-1)[0]));
RES = 2036;
                                                                //    109    %if i = res %then pass %else fail
if (((I) != (RES))) goto L_001d;
PASS();
goto L_001e;
L_001d:;
FAIL();
L_001e:;
                                                                //    110  
                                                                //    111    !do(sigma3,44281)
                                                                //    112    i = sigma3(aa); res = 44281
I = SIGMA3(/*is_array_name3*/ &((AA-1)[0]));
RES = 44281;
                                                                //    113    %if i = res %then pass %else fail
if (((I) != (RES))) goto L_001f;
PASS();
goto L_0020;
L_001f:;
FAIL();
L_0020:;
                                                                //    114  
                                                                //    115    !do(change,84)
                                                                //    116    i = change(aa); res = 84
I = CHANGE(/*is_array_name3*/ &((AA-1)[0]));
RES = 84;
                                                                //    117    %if i = res %then pass %else fail
if (((I) != (RES))) goto L_0021;
PASS();
goto L_0022;
L_0021:;
FAIL();
L_0022:;
                                                                //    118  
                                                                //    119    !do(check,10)
                                                                //    120    i = check(aa); res = 10
I = CHECK(/*is_array_name3*/ &((AA-1)[0]));
RES = 10;
                                                                //    121    %if i = res %then pass %else fail
if (((I) != (RES))) goto L_0023;
PASS();
goto L_0024;
L_0023:;
FAIL();
L_0024:;
                                                                //    122  
                                                                //    123  
                                                                //    124  
                                                                //    125  select output(1)
_imp_SELECTOUTPUT(1);
                                                                //    126  write(failures,1);  printstring(" failure(s)");  newline
_imp_WRITE(FAILURES, 1);
_imp_PRINTSTRING(_imp_str_literal(" failure(s)"));
_imp_NEWLINE();
                                                                //    127     
                                                                //    128  %endofprogram
/* Remove %on %event handler here if present for this block */
return 0;
} // End of block _imp_main at level 1
// End of file
