home *** CD-ROM | disk | FTP | other *** search
- {In the PC-DOS and generic MS-DOS implementations of Turbo Pascal version
- 3.00B, the function FileSize returns a value which is 1 less than the correct
- value. An obvious workaround would be simply to add 1 to the value returned
- by FileSize but that generates a secondary problem (demonstrated below) when
- you try to use BlockRead.
-
- This file contains two programs. The first program demonstrates the above
- mentioned secondary problem. The second program demonstrates a workaround for
- the problem which will work even when using BlockRead.
-
- At this writing, the first program, which demonstrates the problem, has been
- commented out. To see the problem demonstrated, delete the line immediately
- below this one.}
- (*
- program FileSizeError;
-
- type
- BufferType = array[1..128] of char;
-
- var
- f, t : file;
- ch : char;
-
- procedure open;
- begin
- assign(f, 'FILSIZ.FIX');
- reset(f);
- assign(t, 'OUT');
- rewrite(t);
- end; { open }
-
- procedure CopyFile(blocks : integer);
- var
- BlockResults : integer;
- buffer : BufferType;
- begin
- writeln('Copying ', blocks, ' blocks:');
- while blocks > 0 do
- begin
- BlockRead(f, buffer, 1); { gets I/O error on what should be the last read
- }
- Writeln(blocks:5);
- BlockWrite(t, buffer, 1);
- blocks := blocks - 1;
- end;
- close(f);
- close(t);
- end; { CopyFile }
-
- begin
- writeln('Demonstrating the problem . . .');
- open;
- CopyFile(FileSize(f) + 1);
- end.
- *)
-
-
- { In the following program DISTRICT OR MSC - add 1 to the file size when specifying the number of blocks to read
- - add optional paramter "RESULT" to blockread
- }
-
- program FileSizeFix;
-
- type
- BufferType = array[1..128] of char;
-
- var
- f, t : file;
- ch : char;
-
- procedure open;
- begin
- assign(f, 'FILSIZ.FIX');
- reset(f);
- assign(t, 'OUT');
- rewrite(t);
- end; { open }
-
- procedure CopyFile(blocks : integer);
- var
- BlockResults : integer;
- buffer : BufferType;
- begin
- writeln('Copying ', blocks, ' blocks:');
- while blocks > 0 do
- begin
- BlockRead(f, buffer, 1, BlockResults); { with new paramter }
- Writeln(blocks:5, BlockResults:5);
- BlockWrite(t, buffer, 1);
- blocks := blocks - 1;
- end;
- close(f);
- close(t);
- end; { CopyFile }
-
- begin
- writeln('Demonstrating the solution . . .');
- open;
- CopyFile(FileSize(f) + 1 ); { add one more block }
- end.