commit 288f43b43a24f6a80a7d26a033d6c096877bf98b
parent dbf657d3701537f19713a4d4769a39393aacd1d7
Author: Jan Pobrislo <ccx@wpr.cz>
Date: Tue, 15 Sep 2015 22:54:55 +0200
read whole file instead of lazy input which seeks
Diffstat:
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/bin/query_awk b/bin/query_awk
@@ -1,5 +1,2 @@
#!/bin/zsh
-i=$1:a
-query=$0:A:h:h/query.pl
-cd || exit $?
-exec $query $input
+exec $0:A:h:h/query.pl "$@"
diff --git a/query.pl b/query.pl
@@ -155,7 +155,13 @@ out_default_aux([]) --> [].
parse_file(InFile) :-
- ( phrase_from_file(query_awk(Awk), InFile)
+ ( open(InFile, read, Fd), read_stream_to_codes(Fd, Codes)
+ -> true
+ ; throw(read_error(InFile))
+ ),
+ (
+ % phrase_from_file(query_awk(Awk), InFile)
+ phrase(query_awk(Awk), Codes)
-> true
; throw(parsing_failed(InFile))
),
@@ -180,6 +186,8 @@ main(Args) :-
% (phrase(out_awk(Awk), Out) -> true ; throw(formatting_failed(Awk))),
% format('~s', [Out]).
+prolog:message(read_error(File)) -->
+ ['Unable to read file: ~w'-[File]].
prolog:message(parsing_failed(File)) -->
['Unable to parse AWK/query file: ~w'-[File]].
prolog:message(formatting_failed(File,_)) -->
diff --git a/query.test b/query.test
@@ -489,3 +489,11 @@ printf "%s", "hostname=" ((find("hostname")?found:"localhost")) "\n"
# END: bar/inherit/example/data.aat
>>>2
>>>= 0
+
+./querytest tests/query21
+<<<
+ if(DEBUG) printf "got scalar: %s ⇒ %s (%d)\n", varname, V[varname], m >"/dev/stderr"
+>>>
+ if(DEBUG) printf "got scalar: %s ⇒ %s (%d)\n", varname, V[varname], m >"/dev/stderr"
+>>>2
+>>>= 0