allow a file filter with initialization.

This commit is contained in:
Vitor Santos Costa 2010-04-18 21:48:00 +01:00
parent 7593a9ec78
commit 7e389a5b87
2 changed files with 23 additions and 4 deletions

View File

@ -9113,14 +9113,24 @@ For every line @var{LineIn} in stream @var{StreamInp}, execute
stream @var{StreamOut}.
@item file_filter(+@var{FileIn}, +@var{FileOut}, +@var{Goal})
@findex filter/3
@snindex filter/3
@cnindex filter/3
@findex file_filter/3
@snindex file_filter/3
@cnindex file_filter/3
For every line @var{LineIn} in file @var{FileIn}, execute
@code{call(Goal,LineIn,LineOut)}, and output @var{LineOut} to file
@var{FileOut}.
@item file_filter(+@var{FileIn}, +@var{FileOut}, +@var{Goal},
+@var{FormatCommand}, +@var{Arguments})
@findex file_filter_with_init/5
@snindex file_filter_with_init/5
@cnindex file_filter_with_init/5
Same as @code{file_filter/3}, but before starting the filter execute
@code{format/3} on the output stream, using @var{FormatCommand} and
@var{Arguments}.
@end table

View File

@ -11,10 +11,11 @@
copy_line/2,
filter/3,
file_filter/3,
file_filter_with_init/5,
process/2
]).
:- meta_predicate filter(+,+,:), file_filter(+,+,:), process(+,:).
:- meta_predicate filter(+,+,:), file_filter(+,+,:), file_filter_with_init(+,+,:,+,:), process(+,:).
:- use_module(library(lists),
[member/2,
@ -137,4 +138,12 @@ file_filter(Inp, Out, Command) :-
close(StreamInp),
close(StreamOut).
file_filter_with_init(Inp, Out, Command, FormatString, Parameters) :-
open(Inp, read, StreamInp),
open(Out, write, StreamOut),
format(StreamOut, FormatString, Parameters),
filter(StreamInp, StreamOut, Command),
close(StreamInp),
close(StreamOut).