[mod.computers.vax] Reading files with long lines in Pascal

KARNEY%PPC.MFENET@NMFECC.ARPA.UUCP (02/19/87)

I'm trying to read a text file in Pascal.  The text file may not have 
a maximum record length defined.  Since the default record length is 133,
and since I want to read files with longer lines I use something like
    program foo(input,output);
    var f:text;
    begin
      open(f,'tst.txt',history:=readonly,record_length:=501);
    end.
so allowing me to handle line with up to 501 characters.  This works fine
most of the time.  E.g.,
    $ create tst.txt
    foobar
    ^Z
    $ r foo
is OK.  But if the same file is created by EDT, I get
    %PAS-F-RECLENINC, RECORD_LENGTH specified is inconsistent with this file
even though DIRECTORY/FULL shows no differences in record structure.

What's going on?  How do I reliably read text files with long lines?  What
I need is some way of specifying a record_length only for those files with
no maximum record length defined.  I suppose I could do:
      open(f,'tst.txt',history:=readonly,record_length:=501,error:=continue);
      if status(f)>0 then
        open(f,'tst.txt',history:=readonly,error:=continue);
But is there a more elegant solution?

                    Charles Karney
                    Karney%PPC.MFENET@NMFECC.ARPA

carl@CITHEX.CALTECH.EDU.UUCP (02/19/87)

>  I'm trying to read a text file in Pascal.  The text  file  may  not  have  a
>  maximum  record length defined.  Since the default record length is 133, and
>  since I want to read files with longer lines I use something like
>      program foo(input,output);
>      var f:text;
>      begin
>        open(f,'tst.txt',history:=readonly,recordlength:=501);
>      end.
>  so allowing me to handle line with up to 501 characters.   This  works  fine
>  most of the time.  E.g.,
>          $ create tst.txt
>          foobar
>          ^Z
>          $ r foo
>  is OK.  But if the same file is created by EDT, I get
>      %PAS-F-RECLENINC, RECORDLENGTH specified is inconsistent with this file
>  even though DIRECTORY/FULL shows no differences in record structure.
>
>  What's going on?  How do I reliably read text files with long lines?  What I
>  need  is  some way of specifying a recordlength only for those files with no
>  maximum record length defined.  I suppose I could do:

As you've surmised, the problem is that CREATE doesn't specify a maximum
record size, while EDT does (by default, 255).  You can determine this by
using ANALYZE/RMS/FDL.

>      
>     open(f,'tst.txt',history:=readonly,recordlength:=501,error:=continue);
>     if status(f)>0 then
>       open(f,'tst.txt',history:=readonly,error:=continue);
>  But is there a more elegant solution?

There is, to the best of my knowledge, no more elegant solution.  You could,
of course, use calls to RMS to find out what the maximum record size limit
for the file is, but that would actually increase the amount of code in
your executable (assuming that you link with a shareable image instead of
with an object library), and what you were trying to do would be a bit less
clear.