commit d0dcbf0a7470719f9f41394be363160b4cc376b8
parent 02f124b476873b8466cb873e790d01343296bdcd
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date: Tue, 29 Oct 2013 10:19:34 +0100
fix output when query did not match, skip comments
Diffstat:
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/bin/aat.awk b/bin/aat.awk
@@ -17,7 +17,7 @@ function token(content) {
if(!content) return
# concatenate tokens of same type if the previous one doesn't end in newline
if((!tok_finished[tok_n]) && tok_n && tok_type == tok_types[tok_n]) {
- if(DEBUG) printf "concat \"%s\" \"%s\"\n", tok_contents[tok_n], content
+ if(DEBUG) printf "concat \"%s\" \"%s\"\n", tok_contents[tok_n], content >"/dev/stderr"
tok_contents[tok_n] = tok_contents[tok_n] content
} else {
tok_types[++tok_n] = tok_type
diff --git a/bin/query.awk b/bin/query.awk
@@ -47,7 +47,7 @@ function parse_line(line) {
while(length(line)) {
if(DEBUG) printf "%d: →%s←\n", in_string, line >"/dev/stderr"
if(in_string) {
- if(match(line, /^(\\[^"]|[^"\\])+/)) {
+ if(match(line, /^(\\.|[^"\\])+/)) {
out(substr(line, 1, RLENGTH))
line = substr(line, RLENGTH+1)
}
@@ -65,6 +65,9 @@ function parse_line(line) {
if(DEBUG) printf "%d: →%s←\n", in_string, line >"/dev/stderr"
exit 1
}
+ } else if(match(line, /^#/)) {
+ out(line)
+ line = ""
} else if(match(line, /[<"]/)) {
out(substr(line, 1, RSTART-1))
line = substr(line, RSTART)
@@ -74,13 +77,17 @@ function parse_line(line) {
out("\"")
} else {
if(DEBUG) printf "q: →%s← →%s←\n", last_out, line >"/dev/stderr"
- if(match(last_out, /[\n\t([ ]$/) && match(line, /^<([a-zA-Z0-9._]|'[^']*')*>/)) {
+ if(match(last_out, /[\n\t([ ]$/) && \
+ match(line, /^<([a-zA-Z0-9._<>]|'[^']*')*>/)) {
expand_remaining = substr(line, 2, RLENGTH-2)
line = substr(line, RLENGTH+1)
out(expand_query())
} else if(match(line, /^<[^<"]*/)) {
- out(substr(line, 1, RSTART-1))
- line = substr(line, RSTART)
+ if(DEBUG) printf("SKIP: →%s← →%s← →%s←\n", last_out, \
+ substr(line, 1, RLENGTH), substr(line, RLENGTH+1) \
+ ) >"/dev/stderr"
+ out(substr(line, 1, RLENGTH))
+ line = substr(line, RLENGTH+1)
} else {
out(line)
line = ""