HP3000-L Archives

January 1997, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Jeff Vance <[log in to unmask]>
Reply To:
Jeff Vance <[log in to unmask]>
Date:
Thu, 9 Jan 1997 13:00:57 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (102 lines)
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.

--

ATOM RSS1 RSS2