Hi Shivanand,
On Jan 9, 12:57pm, Shivanand Hiremath wrote:
> Subject: HELP: Pascal readln() problem on MPE
> I am facing the following strange behaviour of the pascal 'READLN()' and
> 'READ()' functions on the MPE.
>
...
I don't trust Pascal I/O and prefer to use the MPE intrinsics. Besides Pascal
I/O is pretty slow. I've changed your Pascal example to use intrinsics,
but I have not tested it!
> Following is the pascal program that I have written, to be executed on MPE:
> --------------------------------------------------------------------------
>
> program readGivenFile(input,output);
function FOPEN: integer; intrinsic;
function FREAD: integer; intrinsic
>
> procedure test;
> label
> 9999;
>
> var
> nextChar, ic : char;
> tcc,lc : integer; {* tcc => total chars count, lc => line count
*}
> inFile : text;
> inFileName : string[80];
fd : integer;
numBytes : integer;
buffer : packed array[1..500] of char; { something big enough }
> begin
> tcc := 0;
> lc := 1;
lc := 0;
>
> writeln('Enter the name of FILE to read: ');
> write(' ');
> readln(inFileName);
> writeln;
>
{reset(inFile, inFileName); {* open the file for reading *}
fd = fopen(inFileName, 1 {old}, 0 {read} );
### you don't test for failure, but I recommend testing the cond. code, eg
if ccode <> cce then { handle open failure whiich could be :
1) illegal filename, 2) non-existent file, 3) no read access
to file, etc. }
...
else
begin { fopen ok }
numBytes := fread(fd, buffer, -sizeof(buffer));
while ccode = cce do { not at eof yet...}
begin
{ probably want to trim trailing spaces }
while (numBytes > 0) and (buffer[numBytes] = ' ') do
numBytes := numBytes - 1;
tcc := tcc + numBtytes;
lc := lc + 1;
writeln('Number of chars in line ', lc, ' = ', tcc);
numBytes := fread(fd, buffer, -sizeof(buffer));
end; { while }
end; { fopen ok }
fclose(fd,0,0);
end;
>
> {* WHILE not(eof(inFile)) DO BEGIN *}
> while(true) do begin
> if eof(inFile) then
> goto 9999;
> if eoln(inFile) then begin
> readln(inFile);
> writeln;
> writeln('Number of chars in line ', lc, ' = ', tcc);
> writeln;
> lc := lc+1;
> tcc := 0;
> end {IF}
> Else begin
> read(inFile, nextChar);
> write(nextChar);
> tcc := tcc+1;
> end; {Else}
> end; {WHILE}
>
> 9999:
> close(inFile);
> end;
>
> BEGIN
> test;
> END.
--
|