HP Pascal/iX Programmer's Guide (31502-90023)
3- 18
readln(infile); {and advance to the next line.}
writeln(linepos(outfile)); {Also, print the number of characters
written to outfile,}
writeln(outfile); {and start a new line of outfile.}
END {IF} {If the current line of infile has not ended,}
ELSE BEGIN
read(in,c); {read the next character of infile,}
write(out,c); {and write it to outfile.}
END;
END; {WHILE}
END.
The preceding program copies the textfile infile to the
textfile outfile, writing the values of linepos(infile) and
linepos(outfile) to the standard textfile output whenever
eoln(infile) is
true
.
Except for the
position
function, every sequential I/O procedure and
sequential file function applies to textfiles (see "Sequential
Input/Output" ). Sequential files work the same way, except that for
textfiles, read (like readln) sometimes performs implicit data
conversion, and write (like writeln) can format the output value. See
the
HP Pascal/iX Reference Manual
or the
HP Pascal/HP-UX Reference
Manual
, depending on your implementation, for information on implicit
data conversion and formatting output values.
Direct Input/Output
Direct input/output
is input/output that is performed with direct files;
that is, files whose current position indices can be manipulated directly
by the program. Direct input and output come from read-write files
opened by the procedure open (they cannot be textfiles). Your program
can use the same direct file for input and output.
Table 3-8 summarizes the characteristics of the predefined direct I/O
procedures. (The I/O procedures in Table 3-3 also work on direct
access files.)
Table 3-8. Characteristics of Direct I/O Procedures
------------------------------------------------------------------------------------------------
|||||
| Procedure |
Readdir
|
Writedir
|
Seek
|
|||||
------------------------------------------------------------------------------------------------
|| |
| State that | Read-write |
| file must be in | |
|| |
------------------------------------------------------------------------------------------------
|||||
| Assigns | Specified | Specified | Not applicable |
| value of | component | variable | |
|||||
------------------------------------------------------------------------------------------------
|||||
| To | Specified | Specified | Not applicable |
| | variable | component | |
|||||
------------------------------------------------------------------------------------------------
|| ||
| Advances current | To component following specified component | To specified |
| position index | | component |
|| ||
------------------------------------------------------------------------------------------------
||| |
| After call, | No | Yes |
| buffer is | | |
| undefined | | |
||| |
------------------------------------------------------------------------------------------------