fixes
This commit is contained in:
@@ -64,6 +64,21 @@ available by loading the
|
||||
:- use_module(library(readutil),
|
||||
[read_line_to_codes/2]).
|
||||
|
||||
re_open(S, Mode, S) :-
|
||||
is_stream(S),
|
||||
!,
|
||||
current_stream(_, Mode, S).
|
||||
re_open(F, Mode, S) :-
|
||||
open(F, Mode, S).
|
||||
|
||||
re_open(S, Mode, S, Props) :-
|
||||
is_stream(S),
|
||||
!,
|
||||
current_stream(_, Mode, S),
|
||||
maplist( set_stream(S), Props).
|
||||
re_open(F, Mode, S, Props) :-
|
||||
open(F, Mode, S, Props).
|
||||
|
||||
/**
|
||||
@pred search_for(+ _Char_,+ _Line_)
|
||||
Search for a character _Char_ in the list of codes _Line_.
|
||||
@@ -454,8 +469,8 @@ process(StreamInp, Command) :-
|
||||
the output stream is accessible through `filter_output`.
|
||||
*/
|
||||
file_filter(Inp, Out, Command) :-
|
||||
open(Inp, read, StreamInp, [alias(filter_input)]),
|
||||
open(Out, write, StreamOut),
|
||||
re_open(Inp, read, StreamInp, [alias(filter_input)]),
|
||||
re_open(Out, write, StreamOut),
|
||||
filter(StreamInp, StreamOut, Command),
|
||||
close(StreamInp),
|
||||
close(StreamOut).
|
||||
@@ -467,8 +482,8 @@ Same as file_filter/3, but before starting the filter execute
|
||||
_Arguments_.
|
||||
*/
|
||||
file_filter_with_initialization(Inp, Out, Command, FormatString, Parameters) :-
|
||||
open(Inp, read, StreamInp, [alias(filter_input)]),
|
||||
open(Out, write, StreamOut, [alias(filter_output)]),
|
||||
re_open(Inp, read, StreamInp, [alias(filter_input)]),
|
||||
re_open(Out, write, StreamOut, [alias(filter_output)]),
|
||||
format(StreamOut, FormatString, Parameters),
|
||||
filter(StreamInp, StreamOut, Command),
|
||||
close(StreamInp),
|
||||
@@ -483,8 +498,8 @@ _StartGoal_, and call _ENdGoal_ as an epilog.
|
||||
The input stream are always accessible through `filter_output` and `filter_input`.
|
||||
*/
|
||||
file_filter_with_start_end(Inp, Out, Command, StartGoal, EndGoal) :-
|
||||
open(Inp, read, StreamInp, [alias(filter_input)]),
|
||||
open(Out, write, StreamOut, [alias(filter_output)]),
|
||||
re_open(Inp, read, StreamInp, [alias(filter_input)]),
|
||||
re_open(Out, write, StreamOut, [alias(filter_output)]),
|
||||
call( StartGoal, StreamInp, StreamOut ),
|
||||
filter(StreamInp, StreamOut, Command),
|
||||
call( EndGoal, StreamInp, StreamOut ),
|
||||
@@ -495,22 +510,22 @@ file_filter_with_start_end(Inp, Out, Command, StartGoal, EndGoal) :-
|
||||
/**
|
||||
* @pred file_select(+ _FileIn_, + _Goal_) is meta
|
||||
*
|
||||
* @param _FileIn_ File to process
|
||||
* @param _FileIn_ File or Stream to process
|
||||
* @param _Goal_ to be metacalled, receives FileIn as
|
||||
* extra arguments
|
||||
*
|
||||
* @return bindings to arguments of _Goal_.
|
||||
|
||||
For every line _LineIn_ in file _FileIn_, execute
|
||||
`call(`Goal,LineIn)`.
|
||||
|
||||
The input stream is accessible through the alias `filter_input`, and
|
||||
the output stream is accessible through `filter_output`.
|
||||
*
|
||||
* @brief For every line _LineIn_ in file _FileIn_, execute
|
||||
* `call(`Goal,LineIn)`.
|
||||
*
|
||||
* The input stream is accessible through the alias `filter_input`, and
|
||||
* the output stream is accessible through `filter_output`.
|
||||
*/
|
||||
file_select(Inp, Command) :-
|
||||
( retract(alias(F)) -> true ; F = '' ),
|
||||
atom_concat(filter_input, F, Alias),
|
||||
open(Inp, read, StreamInp, [Alias]),
|
||||
re_open(Inp, read, StreamInp, [Alias]),
|
||||
atom_concat('_', F, NF),
|
||||
assert( alias(NF) ),
|
||||
repeat,
|
||||
|
Reference in New Issue
Block a user