Task

Create a function that returns the maximum value in a provided set of values,

where the number of values may not be known until run-time.




include c:\cxpl\codes;                  \include 'code' declarations
 
def  Tab=$09, LF=$0A, CR=$0D, EOF=$1A;
 
int  CpuReg, Hand;
char CmdTail($80);
int  I, Max, C;
 
[\Copy file name on command line, which is in the Program Segment Prefix (PSP)
\ ES=CpuReg(11), to the CmdTail array, which is in our Data Segment = CpuReg(12)
CpuReg:= GetReg;                        \point to copy of CPU registers
Blit(CpuReg(11), $81, CpuReg(12), CmdTail, $7F);
Hand:= FOpen(CmdTail, 0);               \open file for input and get its handle
FSet(Hand, ^I);                         \assign handle to device 3
OpenI(3);                               \initialize file for input
 
Max:= 0;                                \scan file for longest line
repeat  I:= 0;
        repeat  C:= ChIn(3);
                case C of
                  CR, LF, EOF:  [];     \don't count these characters
                  Tab:  [I:= I+8 & ~7]  \(every 8th column)
                other   I:= I+1;        \count all other characters
        until   C=LF or C=EOF;
        if I > Max then Max:= I;
until   C = EOF;
Text(0, "Longest line = ");  IntOut(0, Max);  CrLf(0);
]