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:
"David F. McKenna" <[log in to unmask]>
Reply To:
David F. McKenna
Date:
Thu, 9 Jan 1997 14:24:26 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (197 lines)
I haven't looked at the code generated, nor have I ever used READ/WRITE
> 80 characters(then only playing around!), but a 'READ' actually
creates an indirect Get code that looks like
        From READLN (F,X);
        To     BEGIN
                  x := f^; GET (F);
                END;
The hp Pascal GET command (Pascal command) may have a limitation to 254
characters.  As far as the handbook(Pascal standards) that I have
length(min or max) is not specified for the GET command.
**** But I agree with Stan - Do not use Pascal I/O

>-----Original Message-----
>From:  Shivanand Hiremath [SMTP:[log in to unmask]]
>Sent:  Thursday, January 09, 1997 4:57 AM
>To:    [log in to unmask]
>Subject:       HELP: Pascal readln() problem on MPE
>
>I am facing the following  strange  behaviour of the pascal  'READLN()'
> and
>'READ()' functions on the MPE.
>
>Problem description:
>--------------------
>
>There is a file whose  record size is greater than 255 bytes.  This
>file can
>be of either fixed length or variable  length  record type.  Now a few
>lines
>of text is added to this  file.  Some of  these  lines  have  more
>than 254
>characters in them.
>
>Also there is a Pascal  program  which I have  written,  that is
>supposed to
>open the above  mentioned  file for input and display  the  contents of
>that
>file line by line  (ie.  record by  record)  and also the  total
>number  of
>characters in each line.
>
>Now I am observing some strange or unexpected behaviour of this small
>pascal
>program under the following instances of input file:
>
>    1.  If a line in the input file has less than 254  characters,
>then the
>        behavior is correct and as expected.
>
>    2.  If a line in the input file has more than 254  characters,
>then the
>        call to the pascal readln() function senses an end of line
>character
>        after 254th  character  and is ignoring  the rest of the
>characters
>        from 255 till the end of that  record.  The  next  call to
>readln()
>        reads (at the most 254 chars) FROM THE BEGINNING OF THE NEXT
>RECORD.
>
>        Even the behavior of the pascal function read() is the same as
>above.
>        If there  are more than 254  characters  in a line of  record,
>then
>        after the 254th call to the read()  function  the eoln() is
>becoming
>        true.
>
>Any explaination for this strange behavior?
>
>
>Following is the pascal program that I have written, to be executed on
>MPE:
>------------------------------------------------------------------------
>--
>
>program readGivenFile(input,output);
>
>    procedure test;
>        label
>            9999;
>
>        var
>            nextChar, ic : char;
>            tcc,lc : integer; {* tcc => total chars count, lc => line
>count *}
>            inFile : text;
>            inFileName : string[80];
>    begin
>        tcc := 0;
>        lc := 1;
>
>        writeln('Enter the name of FILE to read: ');
>          write('                                ');
>        readln(inFileName);
>        writeln;
>
>        reset(inFile, inFileName); {* open the file for reading *}
>
>        {* 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.
>
>
>
>Also I have coded the above pascal  program into an  equivalent  'C'
>program
>and ran it on MPE.  This equivalent C program is working perfectly fine
>with
>the results as expected!!
>
>Following  is the equivalent 'C' code of the above program.
>-----------------------------------------------------------
>This  'C'  program  was also  executed  on the  MPE.  This  program
>behaves
>correctly and gives the expected results.
>
>
>#include <stdio.h>
>
>main(argc, argv)
>int argc;
>char* argv[];
>{
>    int tcc,lc,nextChar,ic;
>    FILE *fp;
>
>    if(argc != 2)
>    {
>        printf("Usage: %s <fileName>\n", argv[0]);
>        exit(1);
>    }
>
>    if ( (fp = fopen(argv[1],"r")) == NULL )
>    {
>        perror("fopen");
>        exit(1);
>    }
>
>    tcc=0;
>    lc=1;
>
>    while(1)
>    {
>        if( (nextChar = getc(fp)) == EOF)
>            break;
>        else
>            fprintf(stdout,"%c",nextChar);
>
>        if(nextChar == '\n')
>        {
>            fprintf(stdout,"Number of chars in line %d = %d\n\n",
>lc,tcc);
>            lc++;
>            tcc=0;
>        }
>        else
>            tcc++;
>    }
>
>    fclose(fp);
>}
>
>
>Can anyone  explain for this behavior or suggest some solution or
>workaround
>for this Pascal problem on MPE ??
>
>---
>
>Shivanand C. Hiremath
>HP-ISO, Bangalore, India.
>Email: <[log in to unmask]>,

ATOM RSS1 RSS2