Category : Modula II Source Code
Archive   : HISTRPT.ZIP
Filename : MCSTOCK.MOD

 
Output of file : MCSTOCK.MOD contained in archive : HISTRPT.ZIP
IMPLEMENTATION MODULE MCSTOCK;
(*
FROM FIO IMPORT Open,Close,Create,File,EOF,RdBin,WrBin,Seek,Size;
FROM IO IMPORT WrLn,WrStr,WrCard,WrLngCard;
FROM Str IMPORT Compare;
FROM Window IMPORT Clear,GotoXY;

CONST
delrecord = 0FFH;
VAR
SN : File;
SNX : StockIndex;
STOCK : StockType;
SFILE : File;

PROCEDURE SSearch(Strng:Str16):LONGCARD;

LABEL QUIT;
VAR
result,
filesize,
buffsize,
recs,
lrec,
start,
endr,
peek : LONGCARD;
cresult : INTEGER;
nread : CARDINAL;
out : BOOLEAN;

BEGIN

out := FALSE;
buffsize := SIZE(SNX);
filesize := Size(SN);
recs := filesize DIV buffsize;
lrec := filesize - buffsize;
start := 0;
endr := recs;
peek := endr DIV 2;

Seek(SN,start);
nread := RdBin(SN,SNX,VAL(CARDINAL,buffsize));
cresult := Compare(Strng,SNX.item);
IF cresult = 0 THEN
result := SNX.recnum;
GOTO QUIT;
END;
Seek(SN,endr);
nread := RdBin(SN,SNX,VAL(CARDINAL,buffsize));
cresult := Compare(Strng,SNX.item);
IF cresult = 0 THEN
result := SNX.recnum;
GOTO QUIT;
END;
REPEAT
IF start + 1 # endr THEN
Seek(SN,peek*buffsize);
nread := RdBin(SN,SNX,VAL(CARDINAL,buffsize));
cresult := Compare(Strng,SNX.item);
CASE cresult OF
1 : start := peek;
peek := ((endr-start) DIV 2) + start|
0 : result := SNX.recnum;
out := TRUE|
-1 : endr := peek;
peek := ((endr-start) DIV 2) + start|
END;
ELSE
result := MAX(LONGCARD);
out := TRUE;
END;
UNTIL out;
QUIT:

RETURN result;

END SSearch;
*)
PROCEDURE TSearch(Strng:Str16):LONGCARD;

LABEL QUIT;
VAR
result,
filesize,
buffsize,
recs,
lrec,
start,
endr,
peek : LONGCARD;
cresult : INTEGER;
nread : CARDINAL;
out : BOOLEAN;

BEGIN
out := FALSE;
buffsize := SIZE(SNX);
filesize := Size(SN);
recs := filesize DIV buffsize;
lrec := filesize - buffsize;
start := 0;
endr := recs;
peek := endr DIV 2;

Seek(SN,start);
nread := RdBin(SN,SNX,VAL(CARDINAL,buffsize));
cresult := Compare(Strng,SNX.item);
IF cresult = 0 THEN
result := peek;
GOTO QUIT;
END;
Seek(SN,endr);
nread := RdBin(SN,SNX,VAL(CARDINAL,buffsize));
cresult := Compare(Strng,SNX.item);
IF cresult = 0 THEN
result := peek;
GOTO QUIT;
END;
REPEAT
IF start + 1 # endr THEN
Seek(SN,peek*buffsize);
nread := RdBin(SN,SNX,VAL(CARDINAL,buffsize));
cresult := Compare(Strng,SNX.item);
CASE cresult OF
1 : start := peek;
peek := ((endr-start) DIV 2) + start|
0 : result := peek;
out := TRUE|
-1 : endr := peek;
peek := ((endr-start) DIV 2) + start|
END;
ELSE
result := MAX(LONGCARD);
out := TRUE;
END;
UNTIL out;
QUIT:
RETURN result;
END TSearch;

PROCEDURE MakeStkIndex;
VAR
buffsize,
filesize,
recs,
lrec,
i : LONGCARD;
counter,
ibuffsize,
nread : CARDINAL;
cresult : INTEGER;
ch : CHAR;
delrecord : BYTE;

BEGIN
delrecord := 0FFH;
buffsize := SIZE(STOCK);
ibuffsize := SIZE(SNX);
filesize := Size(SFILE)-buffsize;
recs := filesize DIV buffsize;
lrec := recs * buffsize;
WrStr('Creating index file for ICSTOCK.00');
WrLn;
WrStr('Filesize of ICSTOCK.00: ');
WrLngCard(filesize,9);
WrLn;
WrStr('Records to process: ');
WrLngCard(recs,6);
WrLn;
GotoXY(35,11);
WrStr('Processing record');
counter := 1;
i := 0;
WHILE i <= lrec DO
Seek(SFILE,i);
GotoXY(38,13);
WrCard(counter,5);
nread := RdBin(SFILE,STOCK,VAL(CARDINAL,buffsize));
IF STOCK.istatus # delrecord THEN
SNX.item := STOCK.item;
SNX.desc := STOCK.idesc;
SNX.stdc := STOCK.istdcost;
SNX.lud := STOCK.isaldate;
SNX.lrd := STOCK.icrecdate;
SNX.ptdu := STOCK.ipqtyused;
SNX.ptds := STOCK.ipqtysold;
WrBin(SN,SNX,ibuffsize);
END;
INC(counter);
INC(i,buffsize);
END;
END MakeStkIndex;

PROCEDURE OpenStk;
BEGIN
SFILE := Open('C:\REPORTS\ICSTOCK.00');
END OpenStk;

PROCEDURE OpenStkNdx;
BEGIN
SN := Open('C:\REPORTS\ICSTOCK.NDX');
END OpenStkNdx;

PROCEDURE CloseStk;
BEGIN
Close(SFILE);
END CloseStk;
PROCEDURE CloseStkNdx;
BEGIN
Close(SN);
END CloseStkNdx;

END MCSTOCK.

  3 Responses to “Category : Modula II Source Code
Archive   : HISTRPT.ZIP
Filename : MCSTOCK.MOD

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/