Reading variable-length records from a file 
Author Message
 Reading variable-length records from a file

What is the best method for reading variable-length records from a file, using Ada (generic Ada, or GNAT)?  I have some files, from
a VMS system, that I want to read on a Win2K system.  The files have the VMS standard "implied carriage control", which means that
each "record" (or line; it's a text file) has a two-byte count value, followed by "count" bytes (characters).

 -Brian



Wed, 28 Jan 2004 02:37:23 GMT  
 Reading variable-length records from a file

Quote:

> What is the best method for reading variable-length records from a file, using Ada (generic Ada, or GNAT)?  I have some files, from
> a VMS system, that I want to read on a Win2K system.  The files have the VMS standard "implied carriage control", which means that
> each "record" (or line; it's a text file) has a two-byte count value, followed by "count" bytes (characters).

And a fill byte if needed to even the count.


Wed, 28 Jan 2004 03:04:52 GMT  
 Reading variable-length records from a file

Quote:

> What is the best method for reading variable-length records from a file, using Ada (generic Ada, or GNAT)?  I have some files, from
> a VMS system, that I want to read on a Win2K system.  The files have the VMS standard "implied carriage control", which means that
> each "record" (or line; it's a text file) has a two-byte count value, followed by "count" bytes (characters).

>  -Brian

An ugly way to do it would be to write a "VMS_get_line" procedure to...
 - read the two characters to generate the line length (c2'pos*256+c1'pos)
 - read that many characters (and Pad as Larry mentioned)
and call that in lieu of Text_IO.Get_Line.

(or are you looking for a plug replacement so you can use Integer_IO... that would be harder)

  --Mark
PS: I could make a snide comment about it being easier to do in C, but that would be flame bait.



Wed, 28 Jan 2004 05:28:09 GMT  
 Reading variable-length records from a file

Quote:
> What is the best method for reading variable-length records from a file, using Ada (generic Ada, or GNAT)?  I have some files, from
> a VMS system, that I want to read on a Win2K system.  The files have the VMS standard "implied carriage control", which means that
> each "record" (or line; it's a text file) has a two-byte count value, followed by "count" bytes (characters).

How do you move the file from VMS to Windows?

If you use FTP, simply specify "ASCII mode" instead of "IMAGE mode"
during the transfer and you will get a plain Windows text file.

If you share the file system (NFS, Samba), make sure that the file
is created with the "stream" or "stream_lf" attribute (use FDL options).

Otherwise, if you can't modify the way the file is created, you can
convert it on VMS using the following DCL procedure. This changes
the physical content while preserving the logical one. After conversion,
the file remains a valid text file on VMS but is also Windows-compliant.

$ convert/fdl=sys$input: 'infile' 'outfile'
        file
          organization sequential
        record
          block_span yes
          carriage_control carriage_return
          format stream
$

We work in an heterogeneous environment (VMS + UNIX + Windows) and
we share all Ada source files (text files) on the same file system
without problem.

-Thierry
____________________________________________________________________________


CANAL+ Technologies, 34 place Raoul Dautry, 75906 Paris Cedex 15, France
Tel: +33 1 71 71 54 30   Fax: +33 1 71 71 52 08   Mobile: +33 6 03 00 65 75
____________________________________________________________________________



Fri, 30 Jan 2004 16:14:38 GMT  
 Reading variable-length records from a file
Unfortunately, the files were ZIPped up and sent to me; I don't have a VMS system to perform the conversion.  Therefore, I want to
write an Ada program to convert the files for me.  I could have written a C program to do this in the time it took for me to write
the original post, but I want to "get both lobes around the Ada paradigm", and do it in Ada.  So far, the only suggestion on
actually doing the conversion in Ada was to read two characters, multiply the first by 256, add them together, and then read that
number of characters from the file.  GROSS!  There has to be a better way!

 -Brian

Quote:

> > What is the best method for reading variable-length records from a file, using Ada (generic Ada, or GNAT)?  I have some files,
from
> > a VMS system, that I want to read on a Win2K system.  The files have the VMS standard "implied carriage control", which means
that
> > each "record" (or line; it's a text file) has a two-byte count value, followed by "count" bytes (characters).

> How do you move the file from VMS to Windows?

> If you use FTP, simply specify "ASCII mode" instead of "IMAGE mode"
> during the transfer and you will get a plain Windows text file.

> If you share the file system (NFS, Samba), make sure that the file
> is created with the "stream" or "stream_lf" attribute (use FDL options).

> Otherwise, if you can't modify the way the file is created, you can
> convert it on VMS using the following DCL procedure. This changes
> the physical content while preserving the logical one. After conversion,
> the file remains a valid text file on VMS but is also Windows-compliant.

> $ convert/fdl=sys$input: 'infile' 'outfile'
>         file
>           organization sequential
>         record
>           block_span yes
>           carriage_control carriage_return
>           format stream
> $

> We work in an heterogeneous environment (VMS + UNIX + Windows) and
> we share all Ada source files (text files) on the same file system
> without problem.

> -Thierry
> ____________________________________________________________________________


> CANAL+ Technologies, 34 place Raoul Dautry, 75906 Paris Cedex 15, France
> Tel: +33 1 71 71 54 30   Fax: +33 1 71 71 52 08   Mobile: +33 6 03 00 65 75
> ____________________________________________________________________________



Sat, 31 Jan 2004 01:39:35 GMT  
 Reading variable-length records from a file
Quote:
> Unfortunately, the files were ZIPped up and sent to me;

  Do you mean with pkzip?  If so, I'd expect pkzip options to convert.

Quote:
> program to convert the files for me.  I could have written a C program to
> do this in the time it took for me to write the original post,
> ...
> the only suggestion on actually doing the conversion in Ada was to read
> two characters, multiply the first by 256, add them together, and then
> read that number of characters from the file.  GROSS!  There has to be a
> better way!

  For those of us too dense to see the better way, could you please
show (the important parts of) the C code you would use?  Perhaps there's
a clever trick that could also be used in Ada.


Sat, 31 Jan 2004 02:29:47 GMT  
 Reading variable-length records from a file

Quote:

> Unfortunately, the files were ZIPped up and sent to me; I don't have a VMS system to perform the conversion.  Therefore, I want to

Does ZIP have a notion of text files ?  It sounds like they were
ZIPped as binary.

Quote:
> write an Ada program to convert the files for me.  I could have written a C program to do this in the time it took for me to write
> the original post, but I want to "get both lobes around the Ada paradigm", and do it in Ada.  So far, the only suggestion on
> actually doing the conversion in Ada was to read two characters, multiply the first by 256, add them together, and then read that
> number of characters from the file.  GROSS!  There has to be a better way!

Plus one if needed to make it an even number.


Sat, 31 Jan 2004 02:51:28 GMT  
 Reading variable-length records from a file
Larry Kilgallen:

Quote:
>Does ZIP have a notion of text files ?

Yes. Anyway you can force the unzipping as a text,
on the target system.
________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: Do not answer to sender address, visit the Web site!
    Ne rpondez pas l'expditeur, visitez le site ouaibe!

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp



Sat, 31 Jan 2004 05:29:31 GMT  
 Reading variable-length records from a file

Quote:
> Larry Kilgallen:

>>Does ZIP have a notion of text files ?

> Yes. Anyway you can force the unzipping as a text,
> on the target system.

For the case at hand, though, the decision must be made when the
zipping is done, on the sending system.  No user interaction is
required as the file on the VMS system clearly indicates its
format.


Sat, 31 Jan 2004 06:41:27 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. How to read a binary file with variable length record

2. Attempting to read variable length records as raw data

3. Variable length records (How to define/read)

4. Reading variable length records...

5. Getting true length of a variable length record - IBM Mainframe

6. Finding Variable-Length Record Length

7. processing variable length records in text file

8. Import dos file variable record length

9. How to access files with variable length records?

10. How to access files with variable length records?

11. Sorting a file with variable length records.

12. Accessing variable-length records files in C-ISAM standard

 

 
Powered by phpBB® Forum Software