*--------------------------------------------------------------------------- && see http://www.e-bachmann.dk/computing/databases/xbase/fpt.html#FPT_STRUCT function FPT_Fix(FileName) local fd, FileSize, BlockLen, NextBlock, hdrOnDisk, hdr fd = fopen(FileName, F_READWRITE_UNBUFF) do case case fd < 0 wait window 'cannot open ' + FileName return FALSE otherwise FileSize = fseek(fd, 0, 2) =fseek(fd, 6, 0) BlockLen = fread(fd,2) BlockLen = CharToBinBE(BlockLen) =fseek(fd, 0, 0) hdrOnDisk = fread(fd, 4) NextBlock = ceiling(FileSize / BlockLen) hdr = BinToCharBE(NextBlock) do case case hdrOnDisk == hdr && all ok otherwise assert FALSE message 'about to repair' =fseek(fd, 0, 0) =fwrite(fd, hdr) endcase =fclose(fd) endcase endfunc *--------------------------------------------------------------------------- function CharToBinBE(s) && BigEndian local n n = ctobin(s) return n + iif(n<=0, 256^len(s)/2, -(256^len(s)/2)) endfunc *--------------------------------------------------------------------------- function BinToCharBE(n, nBytes) && BigEndian nBytes = iif(empty(nBytes), 4, nBytes) return bintoc(n + iif(n<=0, 256^nBytes/2, -(256^nBytes/2)), nBytes) endfunc *---------------------------------------------------------------------------