#include <perms.h>

                                                                //      1  !* Program name : SMULT
                                                                //      2  
                                                                //      3  !*   Title      :  VI.d    The IMP  SHORT  Facilities
                                                                //      4  !*   Version    :  II
                                                                //      5  !*   Date       :  24 August 1985
                                                                //      6  !*   Description:  Tests the Multiplication, Division, Exponentiation and
                                                                //      7  !*                 the REM function.
                                                                //      8  
                                                                //      9  %Begin
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //     10  
                                                                //     11     %string(255) param    { Used to get input from CLI}
_imp_string /*%string(255)*/ PARAM;
                                                                //     12  
                                                                //     13     %Short %Integer J 
short J;
                                                                //     14     %Short %Integer K 
short K;
                                                                //     15     %Short %Integer M
short M;
                                                                //     16     %Short %Integer P
short P;
                                                                //     17     %Short %Integer Q
short Q;
                                                                //     18  
                                                                //     19     %Constant %Short %Integer  CInt3 = 10
                                                                //     20     %Constant %Short %Integer  CInt4 = 3
                                                                //     21  
                                                                //     22  %owninteger failures=0
static int FAILURES = 0;
                                                                //     23  
                                                                //     24  %routine pass
void PASS( void )
{
                                                                //     25    printstring("Pass")
_imp_PRINTSTRING(_imp_str_literal("Pass"));
                                                                //     26    New Line
_imp_NEWLINE();
                                                                //     27  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block PASS at level 2
                                                                //     28  %routine fail
void FAIL( void )
{
                                                                //     29    printstring("FAIL")
_imp_PRINTSTRING(_imp_str_literal("FAIL"));
                                                                //     30    New Line
_imp_NEWLINE();
                                                                //     31    failures = failures+1
FAILURES = (((int)(FAILURES)) + (1));
                                                                //     32  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block FAIL at level 2
                                                                //     33  
                                                                //     34  
                                                                //     35        
                                                                //     36  
                                                                //     37     %Short %Integer %Function  F
short 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 open output(2, "journal") %and select output (2) %c
                                                                //     69     %else                                   open output(2, param)     %and select output (2)
                                                                //     70     
                                                                //     71  
                                                                //     72  
                                                                //     73  
                                                                //     74     New Lines(2)
_imp_NEWLINES(2);
                                                                //     75     Print String ("SHORT INTEGER Arithmetic Validation");   New Line
_imp_PRINTSTRING(_imp_str_literal("SHORT INTEGER Arithmetic Validation"));
_imp_NEWLINE();
                                                                //     76     Print String ("===================================");   New Lines (3)
_imp_PRINTSTRING(_imp_str_literal("==================================="));
_imp_NEWLINES(3);
                                                                //     77  
                                                                //     78  
                                                                //     79  
                                                                //     80     Print String ("Test the SHORT INTEGER Arithmetic Operators");  New Line
_imp_PRINTSTRING(_imp_str_literal("Test the SHORT INTEGER Arithmetic Operators"));
_imp_NEWLINE();
                                                                //     81     Print String ("-------------------------------------------");  New Line
_imp_PRINTSTRING(_imp_str_literal("-------------------------------------------"));
_imp_NEWLINE();
                                                                //     82  
                                                                //     83  
                                                                //     84  
                                                                //     85  
                                                                //     86     !*   Test the SHORT INTEGER MULTIPLICATION 
                                                                //     87            
                                                                //     88     !*  Test the ability to be assigned after a expression evaluation.
                                                                //     89     !*  In each of the following six tests, the destination variable
                                                                //     90     !*  is the same as one of the expression arguments. 
                                                                //     91  
                                                                //     92     New Lines (2)
_imp_NEWLINES(2);
                                                                //     93  
                                                                //     94     Print String ("Test SHORT INTEGER MULTIPLICATION.");   New Line
_imp_PRINTSTRING(_imp_str_literal("Test SHORT INTEGER MULTIPLICATION."));
_imp_NEWLINE();
                                                                //     95     Print String ("----------------------------------");   New Line
_imp_PRINTSTRING(_imp_str_literal("----------------------------------"));
_imp_NEWLINE();
                                                                //     96  
                                                                //     97  
                                                                //     98     J = 50
J = 50;
                                                                //     99     K = 10
K = 10;
                                                                //    100  
                                                                //    101     J = J * 10       { J = 500
J = (((int)(J)) * (10));
                                                                //    102     %If J = 500 %then pass %else fail
if (((J) != (500))) goto L_0008;
PASS();
goto L_0009;
L_0008:;
FAIL();
L_0009:;
                                                                //    103  
                                                                //    104     J = 10 * J       { J = 5000
J = ((10) * ((int)(J)));
                                                                //    105     %If J = 5000 %then pass %else fail
if (((J) != (5000))) goto L_000a;
PASS();
goto L_000b;
L_000a:;
FAIL();
L_000b:;
                                                                //    106  
                                                                //    107     J = 5
J = 5;
                                                                //    108  
                                                                //    109     J = J * CInt3    { J = 50
J = (((int)(J)) * (10));
                                                                //    110     %If J = 50 %then pass %else fail
if (((J) != (50))) goto L_000c;
PASS();
goto L_000d;
L_000c:;
FAIL();
L_000d:;
                                                                //    111  
                                                                //    112     J = CInt3 * J    { J = 500
J = ((10) * ((int)(J)));
                                                                //    113     %If J = 500 %then pass %else fail
if (((J) != (500))) goto L_000e;
PASS();
goto L_000f;
L_000e:;
FAIL();
L_000f:;
                                                                //    114  
                                                                //    115     J = J * K       { J = 5000
J = (((short)(J)) * (K));
                                                                //    116     %If J = 5000 %then pass %else fail
if (((J) != (5000))) goto L_0010;
PASS();
goto L_0011;
L_0010:;
FAIL();
L_0011:;
                                                                //    117  
                                                                //    118     
                                                                //    119     !*  Test that assignment after evaluation still works when the
                                                                //    120     !*  destination variable does not appear in the expression.
                                                                //    121  
                                                                //    122     J = 5
J = 5;
                                                                //    123  
                                                                //    124     M = J * K    
M = (((short)(J)) * (K));
                                                                //    125     %If M = 50 %then pass %else fail
if (((M) != (50))) goto L_0012;
PASS();
goto L_0013;
L_0012:;
FAIL();
L_0013:;
                                                                //    126  
                                                                //    127     
                                                                //    128     !*  Now test the values of the two main variables: J and K
                                                                //    129  
                                                                //    130     %If J = 5 %and K = 10 %then pass %else fail
if (((J) != (5))) goto L_0014;
if (((K) != (10))) goto L_0014;
PASS();
goto L_0015;
L_0014:;
FAIL();
L_0015:;
                                                                //    131  
                                                                //    132  
                                                                //    133  
                                                                //    134  
                                                                //    135  
                                                                //    136     !*    SHORT INTEGER EXPONENTIATION
                                                                //    137  
                                                                //    138     New Lines (2)
_imp_NEWLINES(2);
                                                                //    139  
                                                                //    140     Print String ("Test SHORT INTEGER EXPONENTIATION.");  New Line
_imp_PRINTSTRING(_imp_str_literal("Test SHORT INTEGER EXPONENTIATION."));
_imp_NEWLINE();
                                                                //    141     Print String ("----------------------------------");  New Line
_imp_PRINTSTRING(_imp_str_literal("----------------------------------"));
_imp_NEWLINE();
                                                                //    142  
                                                                //    143     K = 3
K = 3;
                                                                //    144     M = 5
M = 5;
                                                                //    145  
                                                                //    146     J = K ^^ 0
J = _imp_IEXP(K, 0);
                                                                //    147     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_0016;
PASS();
goto L_0017;
L_0016:;
FAIL();
L_0017:;
                                                                //    148  
                                                                //    149     J = K ^^ M
J = _imp_IEXP(K, M);
                                                                //    150     %If J = 243 %then pass %else fail
if (((J) != (243))) goto L_0018;
PASS();
goto L_0019;
L_0018:;
FAIL();
L_0019:;
                                                                //    151  
                                                                //    152     J = K ^^ CInt4
J = _imp_IEXP(K, 3);
                                                                //    153     %If J = 27 %then pass %else fail
if (((J) != (27))) goto L_001a;
PASS();
goto L_001b;
L_001a:;
FAIL();
L_001b:;
                                                                //    154  
                                                                //    155     J = 3 ^^ 0
J = _imp_IEXP(3, 0);
                                                                //    156     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_001c;
PASS();
goto L_001d;
L_001c:;
FAIL();
L_001d:;
                                                                //    157  
                                                                //    158     J = 3 ^^ M
J = _imp_IEXP(3, M);
                                                                //    159     %If J = 243 %then pass %else fail
if (((J) != (243))) goto L_001e;
PASS();
goto L_001f;
L_001e:;
FAIL();
L_001f:;
                                                                //    160  
                                                                //    161     J = 3 ^^ CInt4
J = _imp_IEXP(3, 3);
                                                                //    162     %If J = 27 %then pass %else fail
if (((J) != (27))) goto L_0020;
PASS();
goto L_0021;
L_0020:;
FAIL();
L_0021:;
                                                                //    163  
                                                                //    164     J = CInt4 ^^ 0
J = _imp_IEXP(3, 0);
                                                                //    165     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_0022;
PASS();
goto L_0023;
L_0022:;
FAIL();
L_0023:;
                                                                //    166  
                                                                //    167     J = CInt4 ^^ M
J = _imp_IEXP(3, M);
                                                                //    168     %If J = 243 %then pass %else fail
if (((J) != (243))) goto L_0024;
PASS();
goto L_0025;
L_0024:;
FAIL();
L_0025:;
                                                                //    169  
                                                                //    170     J = CInt3 ^^ CInt4
J = _imp_IEXP(10, 3);
                                                                //    171     %If J = 1000 %then pass %else fail
if (((J) != (1000))) goto L_0026;
PASS();
goto L_0027;
L_0026:;
FAIL();
L_0027:;
                                                                //    172     
                                                                //    173  
                                                                //    174     New Line
_imp_NEWLINE();
                                                                //    175     Print String ("Let:  J = 3  before every test with J as argument."); New Line
_imp_PRINTSTRING(_imp_str_literal("Let:  J = 3  before every test with J as argument."));
_imp_NEWLINE();
                                                                //    176     Print String ("---") ; New Line
_imp_PRINTSTRING(_imp_str_literal("---"));
_imp_NEWLINE();
                                                                //    177  
                                                                //    178     J = 3
J = 3;
                                                                //    179     J = J ^^ 0
J = _imp_IEXP(J, 0);
                                                                //    180     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_0028;
PASS();
goto L_0029;
L_0028:;
FAIL();
L_0029:;
                                                                //    181  
                                                                //    182     J = 3
J = 3;
                                                                //    183     J = J ^^ M
J = _imp_IEXP(J, M);
                                                                //    184     %If J = 243 %then pass %else fail
if (((J) != (243))) goto L_002a;
PASS();
goto L_002b;
L_002a:;
FAIL();
L_002b:;
                                                                //    185  
                                                                //    186     J = 3
J = 3;
                                                                //    187     J = J ^^ Cint4
J = _imp_IEXP(J, 3);
                                                                //    188     %If J = 27 %then pass %else fail
if (((J) != (27))) goto L_002c;
PASS();
goto L_002d;
L_002c:;
FAIL();
L_002d:;
                                                                //    189  
                                                                //    190     J = 3
J = 3;
                                                                //    191     J = J ^^ J
J = _imp_IEXP(J, J);
                                                                //    192     %If J = 27 %then pass %else fail
if (((J) != (27))) goto L_002e;
PASS();
goto L_002f;
L_002e:;
FAIL();
L_002f:;
                                                                //    193  
                                                                //    194     J = M ^^ M
J = _imp_IEXP(M, M);
                                                                //    195     %If J = 3125 %then pass %else fail
if (((J) != (3125))) goto L_0030;
PASS();
goto L_0031;
L_0030:;
FAIL();
L_0031:;
                                                                //    196  
                                                                //    197   
                                                                //    198   
                                                                //    199  
                                                                //    200     !*    SHORT INTEGER Division
                                                                //    201  
                                                                //    202     New Lines (2)
_imp_NEWLINES(2);
                                                                //    203  
                                                                //    204     Print String ("Test SHORT INTEGER Division.");  New Line
_imp_PRINTSTRING(_imp_str_literal("Test SHORT INTEGER Division."));
_imp_NEWLINE();
                                                                //    205     Print String ("----------------------------");  New Line
_imp_PRINTSTRING(_imp_str_literal("----------------------------"));
_imp_NEWLINE();
                                                                //    206  
                                                                //    207     K = 30
K = 30;
                                                                //    208     M = 5
M = 5;
                                                                //    209  
                                                                //    210     
                                                                //    211     J = K // M
J = (long)((long)((short)(K)) / (long)((short)(_Z(M))));
                                                                //    212     %If J = 6 %then pass %else fail
if (((J) != (6))) goto L_0032;
PASS();
goto L_0033;
L_0032:;
FAIL();
L_0033:;
                                                                //    213  
                                                                //    214     J = K // CInt4
J = (long)((long)((short)(K)) / (long)((int)(3)));
                                                                //    215     %If J = 10 %then pass %else fail
if (((J) != (10))) goto L_0034;
PASS();
goto L_0035;
L_0034:;
FAIL();
L_0035:;
                                                                //    216  
                                                                //    217     J = 30 // M
J = (long)((long)((int)(30)) / (long)((short)(_Z(M))));
                                                                //    218     %If J = 6 %then pass %else fail
if (((J) != (6))) goto L_0036;
PASS();
goto L_0037;
L_0036:;
FAIL();
L_0037:;
                                                                //    219  
                                                                //    220     J = 30 // CInt4
J = (long)((long)((int)(30)) / (long)((int)(3)));
                                                                //    221     %If J = 10 %then pass %else fail
if (((J) != (10))) goto L_0038;
PASS();
goto L_0039;
L_0038:;
FAIL();
L_0039:;
                                                                //    222  
                                                                //    223     J = CInt3 // M
J = (long)((long)((int)(10)) / (long)((short)(_Z(M))));
                                                                //    224     %If J = 2 %then pass %else fail
if (((J) != (2))) goto L_003a;
PASS();
goto L_003b;
L_003a:;
FAIL();
L_003b:;
                                                                //    225  
                                                                //    226     J = CInt3 // CInt4
J = (long)((long)((int)(10)) / (long)((int)(3)));
                                                                //    227     %If J = 3 %then pass %else fail
if (((J) != (3))) goto L_003c;
PASS();
goto L_003d;
L_003c:;
FAIL();
L_003d:;
                                                                //    228     
                                                                //    229     New Line
_imp_NEWLINE();
                                                                //    230     Print String ("Let:  J = 30  before every test with J as argument."); New Line
_imp_PRINTSTRING(_imp_str_literal("Let:  J = 30  before every test with J as argument."));
_imp_NEWLINE();
                                                                //    231     Print String ("---")
_imp_PRINTSTRING(_imp_str_literal("---"));
                                                                //    232     New Line
_imp_NEWLINE();
                                                                //    233  
                                                                //    234     J = 30
J = 30;
                                                                //    235     J = J // M
J = (long)((long)((short)(J)) / (long)((short)(_Z(M))));
                                                                //    236     %If J = 6 %then pass %else fail
if (((J) != (6))) goto L_003e;
PASS();
goto L_003f;
L_003e:;
FAIL();
L_003f:;
                                                                //    237  
                                                                //    238     J = 30
J = 30;
                                                                //    239     J = J // Cint4
J = (long)((long)((short)(J)) / (long)((int)(3)));
                                                                //    240     %If J = 10 %then pass %else fail
if (((J) != (10))) goto L_0040;
PASS();
goto L_0041;
L_0040:;
FAIL();
L_0041:;
                                                                //    241  
                                                                //    242     J = 30
J = 30;
                                                                //    243     J = J // J
J = (long)((long)((short)(J)) / (long)((short)(_Z(J))));
                                                                //    244     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_0042;
PASS();
goto L_0043;
L_0042:;
FAIL();
L_0043:;
                                                                //    245  
                                                                //    246     J = M // M
J = (long)((long)((short)(M)) / (long)((short)(_Z(M))));
                                                                //    247     %If J = 1 %then pass %else fail
if (((J) != (1))) goto L_0044;
PASS();
goto L_0045;
L_0044:;
FAIL();
L_0045:;
                                                                //    248  
                                                                //    249  
                                                                //    250  
                                                                //    251  
                                                                //    252     New Lines (2)
_imp_NEWLINES(2);
                                                                //    253  
                                                                //    254     Print String ("Test the Modulus Operator");  New Line
_imp_PRINTSTRING(_imp_str_literal("Test the Modulus Operator"));
_imp_NEWLINE();
                                                                //    255     Print String ("-------------------------");  New Line
_imp_PRINTSTRING(_imp_str_literal("-------------------------"));
_imp_NEWLINE();
                                                                //    256     
                                                                //    257     K = 0
K = 0;
                                                                //    258     M = -3
M = (-3);
                                                                //    259     P = 3
P = 3;
                                                                //    260  
                                                                //    261     J = |-3|
J = _imp_IMOD((-3));
                                                                //    262     Q = |3|
Q = _imp_IMOD(3);
                                                                //    263     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_0046;
PASS();
goto L_0047;
L_0046:;
FAIL();
L_0047:;
                                                                //    264     %if Q = 3 %then pass %else fail
if (((Q) != (3))) goto L_0048;
PASS();
goto L_0049;
L_0048:;
FAIL();
L_0049:;
                                                                //    265     
                                                                //    266     J = |CInt4|
J = _imp_IMOD(3);
                                                                //    267     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_004a;
PASS();
goto L_004b;
L_004a:;
FAIL();
L_004b:;
                                                                //    268  
                                                                //    269     J = |K|
J = _imp_IMOD(K);
                                                                //    270     %if J = 0 %then pass %else fail
if (((J) != (0))) goto L_004c;
PASS();
goto L_004d;
L_004c:;
FAIL();
L_004d:;
                                                                //    271  
                                                                //    272     J = |M|
J = _imp_IMOD(M);
                                                                //    273     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_004e;
PASS();
goto L_004f;
L_004e:;
FAIL();
L_004f:;
                                                                //    274  
                                                                //    275     J = |P|
J = _imp_IMOD(P);
                                                                //    276     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_0050;
PASS();
goto L_0051;
L_0050:;
FAIL();
L_0051:;
                                                                //    277  
                                                                //    278     P = |P|
P = _imp_IMOD(P);
                                                                //    279     %if P = 3 %then pass %else fail
if (((P) != (3))) goto L_0052;
PASS();
goto L_0053;
L_0052:;
FAIL();
L_0053:;
                                                                //    280  
                                                                //    281     J = |F|
J = _imp_IMOD(F());
                                                                //    282     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_0054;
PASS();
goto L_0055;
L_0054:;
FAIL();
L_0055:;
                                                                //    283  
                                                                //    284     J = |(|M|)|
J = _imp_MOD(_imp_IMOD(M));
                                                                //    285     %if J = 3 %then pass %else fail
if (((J) != (3))) goto L_0056;
PASS();
goto L_0057;
L_0056:;
FAIL();
L_0057:;
                                                                //    286  
                                                                //    287     J = |(-P) + K - (|F * M|)|
J = _imp_MOD(((((((-(P))) + (K)))) - (_imp_IMOD((((short)(F())) * (M))))));
                                                                //    288     %if J = 12 %then pass %else fail
if (((J) != (12))) goto L_0058;
PASS();
goto L_0059;
L_0058:;
FAIL();
L_0059:;
                                                                //    289  
                                                                //    290     
                                                                //    291  select output(1)
_imp_SELECTOUTPUT(1);
                                                                //    292  write(failures,1);  printstring(" failure(s)");  newline
_imp_WRITE(FAILURES, 1);
_imp_PRINTSTRING(_imp_str_literal(" failure(s)"));
_imp_NEWLINE();
                                                                //    293  
                                                                //    294  %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
