more fixes to messages
improve lineutils git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2117 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
@@ -2,11 +2,21 @@
|
||||
[search_for/3,
|
||||
scan_natural/3,
|
||||
scan_integer/3,
|
||||
split/3
|
||||
split/3,
|
||||
glue/3,
|
||||
filter/3,
|
||||
copy_line/2,
|
||||
file_filter/3
|
||||
]).
|
||||
|
||||
:- meta_predicate filter(+,+,:).
|
||||
|
||||
:- use_module(library(lists),
|
||||
[member/2]).
|
||||
[member/2,
|
||||
append/3]).
|
||||
|
||||
:- use_module(library(readutil),
|
||||
[read_line_to_codes/2]).
|
||||
|
||||
|
||||
search_for(C) --> [C], !.
|
||||
@@ -27,15 +37,55 @@ scan_natural(N0,N) -->
|
||||
get_natural(N1,N).
|
||||
scan_natural(N,N) --> [].
|
||||
|
||||
split(String, SplitCodes, [S|Strings]) :-
|
||||
split(SplitCodes, S, Strings, String, []).
|
||||
split(String, SplitCodes, Strings) :-
|
||||
split_at_blank(SplitCodes, Strings, String, []).
|
||||
|
||||
split(SplitCodes, [], [New|Set]) -->
|
||||
split_at_blank(SplitCodes, More) -->
|
||||
[C],
|
||||
{ member(C, SplitCodes) }, !,
|
||||
split(SplitCodes, New, Set).
|
||||
split_at_blank(SplitCodes, More).
|
||||
split_at_blank(SplitCodes, [[C|New]| More]) -->
|
||||
[C], !,
|
||||
split(SplitCodes, New, More).
|
||||
split_at_blank(_, []) --> [].
|
||||
|
||||
split(SplitCodes, [], More) -->
|
||||
[C],
|
||||
{ member(C, SplitCodes) }, !,
|
||||
split_at_blank(SplitCodes, More).
|
||||
split(SplitCodes, [C|New], Set) -->
|
||||
[C], !,
|
||||
split(SplitCodes, New, Set).
|
||||
split(_, [], []) --> [].
|
||||
|
||||
glue([], _, []).
|
||||
glue([H|T], [B|_], Merged) :-
|
||||
append(H, [B|Rest], Merged),
|
||||
glue(T, [B], Rest).
|
||||
|
||||
copy_line(StreamInp, StreamOut) :-
|
||||
read_line_to_codes(StreamInp, Line),
|
||||
format(StreamOut, '~s~n', [Line]).
|
||||
|
||||
filter(StreamInp, StreamOut, Command) :-
|
||||
repeat,
|
||||
read_line_to_codes(StreamInp, Line),
|
||||
(
|
||||
Line == end_of_file
|
||||
->
|
||||
true
|
||||
;
|
||||
call(Command, Line, NewLine),
|
||||
format(StreamOut, '~s~n', [NewLine]),
|
||||
fail
|
||||
).
|
||||
|
||||
|
||||
file_filter(Inp, Out, Command) :-
|
||||
open(Inp, read, StreamInp),
|
||||
open(Out, write, StreamOut),
|
||||
filter(StreamInp, StreamOut, Command),
|
||||
close(StreamInp),
|
||||
close(StreamOut).
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user