=== modified file 'data.awk' --- data.awk 2015-09-23 01:42:51 +0000 +++ data.awk 2015-09-17 07:09:55 +0000 @@ -56,7 +56,7 @@ m = match($0, ident_re) varname = substr($0, m, RLENGTH) V[varname] = substr($0, m+1+RLENGTH) - 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" next } @@ -102,44 +102,32 @@ continue loopvar = loop_stack[i, "var"] looprow = loop_stack[i, "row"] - if(varname == prefix"_index") { - found = looprow - return 1 - } - if(varname == prefix"_index0") { - found = looprow - 1 - return 1 - } - if(varname == prefix"_revindex") { - found = V[loopvar, "rows"] - looprow + 1 - return 1 - } - if(varname == prefix"_revindex0") { - found = V[loopvar, "rows"] - looprow - return 1 - } - if(varname == prefix"_first") { - found = looprow == 1 - return 1 - } - if(varname == prefix"_last") { - found = looprow == V[loopvar, "rows"] - return 1 - } - if(varname == prefix"_length") { - found = V[loopvar, "rows"] - return 1 - } + if(varname == prefix"_index") + return looprow + if(varname == prefix"_index0") + return looprow - 1 + if(varname == prefix"_revindex") + return V[loopvar, "rows"] - looprow + 1 + if(varname == prefix"_revindex0") + return V[loopvar, "rows"] - looprow + if(varname == prefix"_first") + return looprow == 1 + if(varname == prefix"_last") + return looprow == V[loopvar, "rows"] + if(varname == prefix"_length") + return V[loopvar, "rows"] split(V[loopvar, "fields"], names) for(n in names) { if(varname == (prefix names[n])) { split(V[loopvar, looprow], values) - found = values[n] - return 1 + return values[n] } } } if(!(varname in V)) { + if(DEBUG) { + print "variable not found: " varname >"/dev/stderr" + } return 0 } found = V[varname] @@ -149,14 +137,10 @@ function get(varname) { if(!find(varname)) { if(ENVIRON["DATA_AWK_EMPTY_GET"]) { - if(DEBUG) { - print "variable not found: " varname >"/dev/stderr" - } - found = "" - } else { - print "error: undefined variable '"varname"'" >"/dev/stderr" - exit 1 + return "" } + print "error: undefined variable '"varname"'" >"/dev/stderr" + exit 1 } if(DEBUG) { print "get →" varname "← = →"found"←" >"/dev/stderr" @@ -171,10 +155,9 @@ END { if(DEBUG) { print "--- loaded keys ---" >"/dev/stderr" - for(key in V) { - printf("%s\t→%s←\n", key, V[key]) >"/dev/stderr" + for(key in V) + printf("%s\t→%s←\t", key, V[key]) >"/dev/stderr" printf(">> %d →%s←\n", find(key), found) >"/dev/stderr" - } print "-------------------" >"/dev/stderr" } }