%%%% ========================================================================
%%%% @MP-file{
%%%% author = "Ulrik Vieth",
%%%% version = "1.04",
%%%% date = "02 May 1995",
%%%% time = "11:24:17 MET",
%%%% filename = "closefrm.mp",
%%%% checksum = "08512 44 231 2198",
%%%% email = "
[email protected]",
%%%% codetable = "ISO/ASCII",
%%%% keywords = "MetaPost, data files, file closing",
%%%% supported = "yes",
%%%% abstract = "This file defines a `closefrom' macro
%%%% to complement the `readfrom' primitive.
%%%% It operates by repeatedly reading from
%%%% a file until reaching EOF, which has
%%%% the side-effect of closing the file.
%%%% (See do_read_from in mp.web for details!)
%%%%
%%%% This macro might be useful to avoid running
%%%% out of read files when using the MetaPost
%%%% graph package to process many data files
%%%% containing extra junk at the end, causing
%%%% data reading from the files to stop early
%%%% without closing the files.
%%%% ",
%%%% docstring = "The checksum field above contains a CRC-16
%%%% checksum as the first value, followed by
%%%% the equivalent of the standard UNIX wc
%%%% (word count) utility output of lines,
%%%% words, and characters. This is produced
%%%% by Robert Solovay's checksum utility.",
%%%% }
%%%% ========================================================================
% Read lines from file f (and throw away the contents) until reaching EOF.
vardef closefrom(expr f) =
save s_;
forever:
string s_;
s_ = readfrom f;
exitif s_=EOF;
endfor
enddef;