#include <perms.h>

                                                                //      1  !* Program name : SADD
                                                                //      2  
                                                                //      3  !*   Title      :  V.d    The IMP  SHORT ADDITION  Facilities
                                                                //      4  !*   Version    :  II
                                                                //      5  !*   Date       :  24 August 1985
                                                                //      6  !*   Description:  Tests the short addition and subtraction (both
                                                                //      7  !*                 binary and unary) using various representations 
                                                                //      8  !*                 and combinations of argument.  The arithmetic
                                                                //      9  !*                 involves mostly binary operations.
                                                                //     10  
                                                                //     11  %Begin
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //     12  
                                                                //     13     %string(255) param    { Used to get input from CLI}
_imp_string /*%string(255)*/ PARAM;
                                                                //     14  
                                                                //     15     %Short %Integer J
short J;
                                                                //     16     %Short %Integer K
short K;
                                                                //     17     %Short %Integer M
short M;
                                                                //     18     %Short %Integer N
short N;
                                                                //     19  
                                                                //     20     %Constant %Short %Integer  CInt3 = 10
                                                                //     21     %Constant %Short %Integer  CInt4 = 3
                                                                //     22           
                                                                //     23           
                                                                //     24  %owninteger failures=0
static int FAILURES = 0;
                                                                //     25  
                                                                //     26  %routine pass
void PASS( void )
{
                                                                //     27    printstring("Pass")
_imp_PRINTSTRING(_imp_str_literal("Pass"));
                                                                //     28    New Line
_imp_NEWLINE();
                                                                //     29  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block PASS at level 2
                                                                //     30  %routine fail
void FAIL( void )
{
                                                                //     31    printstring("FAIL")
_imp_PRINTSTRING(_imp_str_literal("FAIL"));
                                                                //     32    New Line
_imp_NEWLINE();
                                                                //     33    failures = failures+1
FAILURES = (((int)(FAILURES)) + (1));
                                                                //     34  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block FAIL at level 2
                                                                //     35  
                                                                //     36  
                                                                //     37     %Integer %Function  F
int F( void )
{
                                                                //     38  
                                                                //     39       !*  An extremely simple short integer function that merely
                                                                //     40       !*  returns the number THREE.  Note that this function 
                                                                //     41       !*  does not presuppose parameter passing or expression
                                                                //     42       !*  evaluation within functions.  It merely tests the
                                                                //     43       !*  ability to encorporate functions within expressions. 
                                                                //     44                                                             
                                                                //     45       %Result = 3
/* Remove %on %event handler here if present for this block */
return 3;
                                                                //     46  
                                                                //     47      %End
} // End of block F at level 2
                                                                //     48  
                                                                //     49  
                                                                //     50  
                                                                //     51     ! Code to find out where the output is to be sent
                                                                //     52     ! -----------------------------------------------
                                                                //     53     ! Where the output goes to depends on the parameter after the
                                                                //     54     ! name used to run the program.
                                                                //     55     !                       Parameter   |   Result
                                                                //     56     !                       ------------|-------------
                                                                //     57     !                     No parameter  |  No output
                                                                //     58     !                          "s"      |  The screen
                                                                //     59     !                          "j"      |  "journal"
                                                                //     60     !                     anything else |  file name entered
                                                                //     61  
                                                                //     62     ! NOTE THAT THIS CODE USES STRING COMPARISONS, WHICH MAY NOT HAVE BEEN
                                                                //     63     ! TESTED YET. IF THE PROGRAM FAILS CHECK IT WAS NOT IN THIS PART.
                                                                //     64  
                                                                //     65     param=cliparam
PARAM = _imp_CLIPARAM();
                                                                //     66     %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:;
                                                                //     67     %else %if param="s" %or param="S" %then select output(1) %c
                                                                //     68     %else %if param="j" %or param="J" %then  %c
                                                                //     69        open output(2,"journal") %and select output (2) %c
                                                                //     70     %else open output(2,param) %and select output (2)
                                                                //     71     
                                                                //     72  
                                                                //     73  
                                                                //     74  
                                                                //     75     New Lines(2)
_imp_NEWLINES(2);
                                                                //     76     Print String ("SHORT INTEGER Arithmetic Validation");   New Line
_imp_PRINTSTRING(_imp_str_literal("SHORT INTEGER Arithmetic Validation"));
_imp_NEWLINE();
                                                                //     77     Print String ("===================================");   New Lines (3)
_imp_PRINTSTRING(_imp_str_literal("==================================="));
_imp_NEWLINES(3);
                                                                //     78  
                                                                //     79  
                                                                //     80  
                                                                //     81     !*  Test the SHORT INTEGER ADDITION 
                                                                //     82  
                                                                //     83     !*  Test the ability to be assigned after a expression evaluation.
                                                                //     84     !*  In each of the following six tests, the destination variable
                                                                //     85     !*  is the same as one of the expression arguments.
                                                                //     86  
                                                                //     87  
                                                                //     88     Print String ("Test SHORT INTEGER ADDITION.");  New Line
_imp_PRINTSTRING(_imp_str_literal("Test SHORT INTEGER ADDITION."));
_imp_NEWLINE();
                                                                //     89     Print String ("----------------------------");  New Line
_imp_PRINTSTRING(_imp_str_literal("----------------------------"));
_imp_NEWLINE();
                                                                //     90  
                                                                //     91     J = 50
J = 50;
                                                                //     92     K = 10
K = 10;
                                                                //     93  
                                                                //     94     J = J + 10       { J = 60
J = (((int)(J)) + (10));
                                                                //     95     %If J = 60 %then pass %else fail
if (((J) != (60))) goto L_0008;
PASS();
goto L_0009;
L_0008:;
FAIL();
L_0009:;
                                                                //     96  
                                                                //     97     J = 10 + J       { J = 70
J = ((10) + ((int)(J)));
                                                                //     98     %If J = 70 %then pass %else fail
if (((J) != (70))) goto L_000a;
PASS();
goto L_000b;
L_000a:;
FAIL();
L_000b:;
                                                                //     99  
                                                                //    100     J = J + CInt3    { J = 80
J = (((int)(J)) + (10));
                                                                //    101     %If J = 80 %then pass %else fail
if (((J) != (80))) goto L_000c;
PASS();
goto L_000d;
L_000c:;
FAIL();
L_000d:;
                                                                //    102  
                                                                //    103     J = CInt3 + J    { J = 90
J = ((10) + ((int)(J)));
                                                                //    104     %If J = 90 %then pass %else fail
if (((J) != (90))) goto L_000e;
PASS();
goto L_000f;
L_000e:;
FAIL();
L_000f:;
                                                                //    105  
                                                                //    106     J = J + K       { J = 100
J = (((short)(J)) + (K));
                                                                //    107     %If J = 100 %then pass %else fail
if (((J) != (100))) goto L_0010;
PASS();
goto L_0011;
L_0010:;
FAIL();
L_0011:;
                                                                //    108  
                                                                //    109     J = K + J        { J = 110
J = (((short)(K)) + (J));
                                                                //    110     %If J = 110 %then pass %else fail
if (((J) != (110))) goto L_0012;
PASS();
goto L_0013;
L_0012:;
FAIL();
L_0013:;
                                                                //    111  
                                                                //    112     
                                                                //    113     !*  Test that assignment after evaluation still works when the
                                                                //    114     !*  destination variable does not appear in the expression.
                                                                //    115  
                                                                //    116     M = J + K    
M = (((short)(J)) + (K));
                                                                //    117     %If M = 120 %then pass %else fail
if (((M) != (120))) goto L_0014;
PASS();
goto L_0015;
L_0014:;
FAIL();
L_0015:;
                                                                //    118  
                                                                //    119     
                                                                //    120     !*  Now test the values of the two main variables: J and K
                                                                //    121  
                                                                //    122     %If J = 110 %and K = 10 %then pass %else fail
if (((J) != (110))) goto L_0016;
if (((K) != (10))) goto L_0016;
PASS();
goto L_0017;
L_0016:;
FAIL();
L_0017:;
                                                                //    123  
                                                                //    124  
                                                                //    125  
                                                                //    126  
                                                                //    127  
                                                                //    128     !*  Test the SHORT INTEGER SUBTRACTION 
                                                                //    129  
                                                                //    130     !*  Test the ability to be assigned after a expression evaluation.
                                                                //    131     !*  In each of the following six tests, the destination variable
                                                                //    132     !*  is the same as one of the expression arguments.
                                                                //    133  
                                                                //    134     New Lines (2)
_imp_NEWLINES(2);
                                                                //    135  
                                                                //    136     Print String ("Test SHORT INTEGER SUBTRACTION.");   New Line
_imp_PRINTSTRING(_imp_str_literal("Test SHORT INTEGER SUBTRACTION."));
_imp_NEWLINE();
                                                                //    137     Print String ("-------------------------------");   New Line
_imp_PRINTSTRING(_imp_str_literal("-------------------------------"));
_imp_NEWLINE();
                                                                //    138  
                                                                //    139     J = 110
J = 110;
                                                                //    140     K = 10
K = 10;
                                                                //    141     
                                                                //    142     J = J - 10       { J = 100
J = (((int)(J)) - (10));
                                                                //    143     %If J = 100 %then pass %else fail
if (((J) != (100))) goto L_0018;
PASS();
goto L_0019;
L_0018:;
FAIL();
L_0019:;
                                                                //    144  
                                                                //    145     J = 10 - J       { J = -90
J = ((10) - ((int)(J)));
                                                                //    146     %If J = -90 %then pass %else fail
if (((J) != ((-90)))) goto L_001a;
PASS();
goto L_001b;
L_001a:;
FAIL();
L_001b:;
                                                                //    147  
                                                                //    148     J = J - CInt3    { J = -100
J = (((int)(J)) - (10));
                                                                //    149     %If J = -100 %then pass %else fail
if (((J) != ((-100)))) goto L_001c;
PASS();
goto L_001d;
L_001c:;
FAIL();
L_001d:;
                                                                //    150  
                                                                //    151     J = CInt3 - J    { J = 110
J = ((10) - ((int)(J)));
                                                                //    152     %If J = 110 %then pass %else fail
if (((J) != (110))) goto L_001e;
PASS();
goto L_001f;
L_001e:;
FAIL();
L_001f:;
                                                                //    153  
                                                                //    154     J = J - K       { J = 100
J = (((short)(J)) - (K));
                                                                //    155     %If J = 100 %then pass %else fail
if (((J) != (100))) goto L_0020;
PASS();
goto L_0021;
L_0020:;
FAIL();
L_0021:;
                                                                //    156  
                                                                //    157     J = K - J        { J = -90
J = (((short)(K)) - (J));
                                                                //    158     %If J = -90 %then pass %else fail
if (((J) != ((-90)))) goto L_0022;
PASS();
goto L_0023;
L_0022:;
FAIL();
L_0023:;
                                                                //    159  
                                                                //    160  
                                                                //    161     !*  Test that assignment after evaluation still works when the
                                                                //    162     !*  destination variable does not appear in the expression.
                                                                //    163  
                                                                //    164     M = J - K    
M = (((short)(J)) - (K));
                                                                //    165     %If M = -100 %then pass %else fail
if (((M) != ((-100)))) goto L_0024;
PASS();
goto L_0025;
L_0024:;
FAIL();
L_0025:;
                                                                //    166  
                                                                //    167  
                                                                //    168     !*  Now test the values of the two main variables: J and K
                                                                //    169  
                                                                //    170     %If J = -90 %and K = 10 %then pass %else fail
if (((J) != ((-90)))) goto L_0026;
if (((K) != (10))) goto L_0026;
PASS();
goto L_0027;
L_0026:;
FAIL();
L_0027:;
                                                                //    171  
                                                                //    172  
                                                                //    173  
                                                                //    174    
                                                                //    175  
                                                                //    176  
                                                                //    177     !*  Test the UNARY MINUS operation.
                                                                //    178  
                                                                //    179     New Lines (2)
_imp_NEWLINES(2);
                                                                //    180   
                                                                //    181     Print String ("Test the UNARY MINUS");   New Line
_imp_PRINTSTRING(_imp_str_literal("Test the UNARY MINUS"));
_imp_NEWLINE();
                                                                //    182     Print String ("--------------------");   New Lines (1)
_imp_PRINTSTRING(_imp_str_literal("--------------------"));
_imp_NEWLINES(1);
                                                                //    183  
                                                                //    184     
                                                                //    185     J = 50
J = 50;
                                                                //    186     K = 10
K = 10;
                                                                //    187  
                                                                //    188     N = -CInt4
N = (-3);
                                                                //    189     M = -J
M = (-(J));
                                                                //    190     K = -K
K = (-(K));
                                                                //    191     J = -(-(-M))
J = (-((-((-(M))))));
                                                                //    192  
                                                                //    193     %If N = -3 %then pass %else fail
if (((N) != ((-3)))) goto L_0028;
PASS();
goto L_0029;
L_0028:;
FAIL();
L_0029:;
                                                                //    194     %If M = -50 %then pass %else fail
if (((M) != ((-50)))) goto L_002a;
PASS();
goto L_002b;
L_002a:;
FAIL();
L_002b:;
                                                                //    195     %If K = -10 %then pass %else fail
if (((K) != ((-10)))) goto L_002c;
PASS();
goto L_002d;
L_002c:;
FAIL();
L_002d:;
                                                                //    196     %If J = 50 %then pass %else fail
if (((J) != (50))) goto L_002e;
PASS();
goto L_002f;
L_002e:;
FAIL();
L_002f:;
                                                                //    197  
                                                                //    198  
                                                                //    199  select output(1)
_imp_SELECTOUTPUT(1);
                                                                //    200  write(failures,1);  printstring(" failure(s)");  newline
_imp_WRITE(FAILURES, 1);
_imp_PRINTSTRING(_imp_str_literal(" failure(s)"));
_imp_NEWLINE();
                                                                //    201     
                                                                //    202     
                                                                //    203  %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
