=== removed file 'bin/query.awk' --- bin/query.awk 2013-10-13 15:13:47 +0000 +++ bin/query.awk 1970-01-01 00:00:00 +0000 @@ -1,92 +0,0 @@ -#!/bin/awk -f -BEGIN { - in_string = 0 -} - -function out(str) { - printf "%s", str - last_out = str -} - -# called for expanding {< >} -# global variable expand_remaining used as input -function expand_query( expanded) { - expanded = "" - while(match(expand_remaining, "['<>]")) { - if(RSTART > 1) - expanded = expanded "\"" substr(expand_remaining, 1, RSTART-1) "\"" - char = substr(expand_remaining, RSTART, 1) - expand_remaining = substr(expand_remaining, RSTART+1) - if(char == ">") - return "get("expanded")" - else if(char == "<") { - expanded = expanded expand_query() - } else if(char == "'") { - if(match(expand_remaining, "'")) { - expanded = expanded substr(expand_remaining, 1, RSTART-1) - expand_remaining = substr(expand_remaining, RSTART+1) - } else { - expanded = expand_remaining - expand_remaining = "" - } - } else { - print "ERROR: internal error in expand_query()" >"/dev/stderr" - exit 1 - } - } - if(expand_remaining) { - expanded = "\"" expand_remaining "\"" - expand_remaining = "" - } - return "get("expanded")" -} - -function parse_line(line) { - while(length(line)) { - if(DEBUG) printf "%d: \"%s\"\n", in_string, line >"/dev/stderr" - if(in_string) { - if(match(line, /^\(\\[^"]\|[^"\\]\)/)) { - out(substr(line, 1, RLENGTH)) - line = substr(line, RLENGTH+1) - } - if(match(line, /^"/)) { - out("\"") - line = substr(line, 2) - in_string = 0 - } else if(match(line, /^\\$/)) { - out("\\") - line = "" - } else if(!line) { - # is this valid? - } else { - print "string parsing error" >"/dev/stderr" - exit 1 - } - } else if(match(line, /[<"]/)) { - out(substr(line, 1, RSTART-1)) - line = substr(line, RSTART) - if(match(line, /^"/)) { - line = substr(line, 2) - in_string = 1 - } else { - 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) - } else { - out(line) - line = "" - } - } - } else { - out(line) - line = "" - } - } - out("\n") -} - -{ parse_line($0) }