SPL to HP C/XL Migration Guide (30231-90001)

9- 6
Alternatively, the HP C/XL fread function can be used to read
fixed-length binary data into a structure, such as an array or struct.
Since fread does not recognize file record boundaries, you need to be
sure the sizes you supply add up correctly.
The conventional means of performing I/O in HP C/XL is to view data files
as a "stream" of text (ASCII characters) in variable-length records.
The functions contained in the HP C/XL library provide a rich set of
formatted I/O operations, greatly simplifying the multiple steps which
are necessary in SPL. Consideration of fixed-length record operations is
required only to read files created in this manner by other programs, or
to create files for programs that expect to read fixed-length records.
Writing Records into a File in Sequential Order
SPL uses the FWRITE intrinsic to write all or part of a record in a
sequential file with fixed- or variable-length records. A logical
record pointer points to the next record to be written. When any part
of a record is written, the pointer advances to the next record.
The HP C/XL functions provide many choices for output. You may use
fputs, fwrite, or write to emulate the SPL record structure. Or you may
use the printf and fprintf to write formatted, variable-length text
records. With the latter two, you must identify the end of each record
to HP C/XL by writing a '\n' (linefeed) character. The '\n' is not
actually stored in the file.
Updating a File
SPL uses the MPE V intrinsic FUPDATE to replace the record last accessed
in the file by any intrinsic. This is commonly used to update part of a
record that has been located by some identifying data in the same record.
The records cannot be variable-length.
HP C/XL has no direct equivalent of the FUPDATE intrinsic. You will have
to emulate it by using the HP C/XL function ftell to give you the record
start byte
before
you read it. Then you can reposition the file with
the fseek function and rewrite the record with fputs, fwrite, or write.
You can even write records with fprintf and the rest as long as you
remember to write a '\n' character, signaling end-of-record to HP C/XL .