This program reports how many records are in use in an MSORT file. It opens the file as text, counts the deleted record entries and subtracts them from the high-water mark.
00010 REM &REM&00020 PRINT 'CS'; INPUT "MSORT file to check:",MFN$! Get MSORT file name00025 LET T=0 ! Initialize deleted records to 000030 OPEN(1,OPT="TEXT")MFN$ ! Open MSORT file00040 READ RECORD(1,IND=25,SIZ=4)A$ ! Get start block of deleted key00050 IF DEC(A$) = 0 ! If start block is 0 then LET T=0; ! number of delete records is 0 GOTO 130 ! Go determine # of records used FI00060 LET P=(DEC(A$)-1) * 1024 ! then pointer is block -1 * block size00070 READ RECORD(1,IND=P,SIZ=6)B$ ! get # of bytes in block and next ! block pointer00080 LET B=DEC(B$(1,2)) ! Calc # of bytes in this block00090 LET B=B-6 ! Subtract size of this pointer00100 LET B=B/4, ! Divide by size of each entry which ! yields # of delete records for THIS ! block T=T+B ! T = total delete records in file00110 IF B$(3,4)=DIM(6,$00$) ! Check for more deleted blocks GOTO 130 ! If none then get out of loop00120 P=(DEC(B$(3,4))-1)*1024; ! get next deleted key block GOTO 70 ! and continue00130 READ RECORD(1,IND=33,SIZ=4)C$ ! Get "high water mark" for file ! (Max # of records EVER written)00140 LET U=DEC(C$)-T ! Get number of used records in file00150 PRINT "NUMBER OF USED RECORDS: ",! Display result UNotes
The high-water mark is the largest number of records ever written to the file, so deleted records have to be subtracted to get the number in use.