aat

git mirror of https://ccx.te2000.cz/bzr/aat
git clone https://ccx.te2000.cz/git/aat
Log | Files | Refs | README

commit 807a36200cf27322edc0d97853ec697ec2a2fb8d
parent 07797588c0a2ba7b9d71c1bcdb9fd64f8a75adef
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Wed,  9 Jul 2014 21:12:25 +0200

check for consistent field definitions
Diffstat:
Mbin/aat.awk | 28+++++++++++++++++++++++++---
Mdata.awk | 8++++++++
2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/bin/aat.awk b/bin/aat.awk @@ -74,9 +74,14 @@ function find_file(name) { } } - if(system("test -f " sh_escape(filename)) != 0) - { - die("could not find requested file: " sh_escape(filename) " (" name ") PWD: " PWD) + if(system("test -f " sh_escape(filename)) != 0) { + if("MAKE_CMD" in ENVIRON) { + if(system(ENVIRON["MAKE_CMD"] " " sh_escape(filename)) != 0) { + die("could not build requested file: " sh_escape(filename) " (" name ") PWD: " PWD) + } + } else { + die("could not find requested file: " sh_escape(filename) " (" name ") PWD: " PWD) + } } print_dep(filename) @@ -87,12 +92,23 @@ function macro_readinto(args, varname, fname) { sub(/[ \t].*$/, "", varname) sub(/^[^ \t]+[ \t]+/, "", fname) find_file(fname) + insert_comment("start @readinto "varname" "filename" {{{") tok_type=T_AWK while(getline <filename) { gsub(/["\\]/, "\\&", $0) token(varname " = \"" $0 "\\n\"\n") } close(filename) + insert_comment("}}} end @readinto "varname" "filename) +} + +function insert_comment(str, tok_type_prev) { + tok_type_prev = tok_type + sub(/^/, "# ", str) + gsub(/\n/, "\n# ", str) + tok_type=T_AWK + token(str "\n") + tok_type = tok_type_prev } function call_macro(name, args, file_old) { @@ -104,30 +120,36 @@ function call_macro(name, args, file_old) { # Macro to recursively parse another template if(name == "include"){ find_file(args) + insert_comment("start @include "filename" {{{") while(getline <filename) { parse_line($0) } close(filename) + insert_comment("}}} end @include "filename) } # Macro to insert another file as verbatim code else if(name == "awk"){ find_file(args) + insert_comment("start @awk "filename" {{{") tok_type=T_AWK while(getline <filename) { token($0 "\n") } close(filename) + insert_comment("}}} end @awk "filename) } # Macro to insert another file as text else if(name == "text"){ find_file(args) + insert_comment("start @text "filename" {{{") tok_type=T_TEXT while(getline <filename) { token($0 "\n") } close(filename) + insert_comment("}}} end @text "filename) } # Macro to insert source filename as a variable into produced code diff --git a/data.awk b/data.awk @@ -22,6 +22,14 @@ state == 2 { } state == 1 { + if((varname, "fields") in V) { + if(V[varname,"fields"] != $0) { + print "data.awk: differing field definition for '"varname"'" >"/dev/stderr" + print "previous: '"V[varname,"fields"]"'" >"/dev/stderr" + print "current: '"$0"'" >"/dev/stderr" + exit 1 + } + } V[varname,"fields"] = $0 state = 2 next