Re: file-seek in Gambit.
Marc Feeley <feeley <at> IRO.UMontreal.CA>
2005-01-07 21:05:45 GMT
> I can't seem to find a way to seek in and get the position in files
> using Gambit (4beta11). Wouldn't this be a handy feature?
Yes, I have been planing this for a while and have just completed the
implementation and documentation. Here it is:
<at> deffn procedure input-port-byte-position <at> var{port} <at> r{[} <at> var{position} <at> r{[} <at> var{whence} <at> r{]} <at> r{]}
<at> deffnx procedure output-port-byte-position <at> var{port} <at> r{[} <at> var{position} <at> r{[} <at> var{whence} <at> r{]} <at> r{]}
When called with a single argument these procedures return the byte
position where the next I/O operation would take place in the file
attached to the given <at> var{port} (relative to the beginning of the
file). When called with two or three arguments, the byte position for
subsequent I/O operations on the given <at> var{port} is changed to
<at> var{position}, which must be an exact integer. When <at> var{whence} is
omitted or is 0, the <at> var{position} is relative to the beginning of
the file. When <at> var{whence} is 1, the <at> var{position} is relative to
the current byte position of the file. When <at> var{whence} is 2, the
<at> var{position} is relative to the end of the file. The return value
is the new byte position. On most operating systems the byte position
for reading and writing of a given bidirectional port are the same.
When <at> code{input-port-byte-position} is called to change the byte
position of an input-port, all input buffers will be flushed so that
the next byte read will be the one at the given position.
When <at> code{output-port-byte-position} is called to change the byte
position of an output-port, there is an implicit call to
<at> code{force-output} before the position is changed.
(Continue reading)