fileset

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

commit bf09029e9c7786d70c38eb074a8a427c7d1005fb
parent 1a1a254caef26c966c63635a542dd2fd5e6c801d
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Mon, 21 Dec 2015 22:07:36 +0100

custom condition / checks
Diffstat:
MREADME | 5+++++
Mbin/fileset.awk | 73+++++++++++++++++++++++++++++++++++++++++++++++++------------------------
2 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/README b/README @@ -94,6 +94,11 @@ Flags taken by the rfdlhcLHC commands: "f" - when removing existing file, do it forcibly (rm -f) "p" - create parent directories if they don't exist (mkdir -p) +?<flags><tab><command> + TODO + flags: + "i" - redirect stdin from the file for the command + Commandline utilities: fileset [file [file ...]] diff --git a/bin/fileset.awk b/bin/fileset.awk @@ -10,6 +10,7 @@ BEGIN { } func_num=0 + has_cond="" } function escaped(str) { @@ -49,6 +50,22 @@ function print_e(str) { # print end block print indent str } +function print_cond(statement, suffix) { # TODO + if(has_cond == "") { + print_b("if ! $check_only; then") + print_d("{ "statement"\n}"suffix) + print_e("fi") + } else { + if(suffix) { + funcs["do_" has_cond] = "{ "statement"\n}"suffix + } else { + funcs["do_" has_cond] = statement + } + print_d("req " has_cond) + has_cond = "" + } +} + function print_rsfilter(str) { if ("RSFILTER" in ENVIRON) { print str >>ENVIRON["RSFILTER"] @@ -156,24 +173,28 @@ function process_statement() { } # cat, copy, content; eats rest of statement and puts it into the file - if(cchar ~ /[cC]/) { + if(cchar ~ /[bBcC]/) { shellfunc("f 1", crest) - content = get_argument(cchar == "C") - - # unless disabled with the N flag, append newline at the end of - # last line, if not already present - printf_fmt = crest ~ /n/ || (crest !~ /N/ && content !~ /\n$/) ? \ - "%s\\n" : "%s" + content = get_argument(cchar ~ "BC") func_name = "fn" func_num++ - funcs[func_name] = "\tprintf '"printf_fmt"' "quoted(content) - if(crest ~ /a/) { - print_b("if ! $check_only; then") - print_i(func_name " >>" fname) - print_e("fi") + if(cchar ~ /[bB]/) { + funcs[func_name] = "\tbase64 <<<"quoted(content) } else { + # unless disabled with the N flag, append newline at the end of + # last line, if not already present + printf_fmt = crest ~ /n/ || (crest !~ /N/ && content !~ /\n$/) ? \ + "%s\\n" : "%s" + funcs[func_name] = "\tprintf '"printf_fmt"' "quoted(content) + } + + if(crest ~ /a/) { + print_cond(func_name, ">>"fname) + } else if(has_cond == "") { print_i("c " func_name) + } else { + print_cond("c "func_name) } continue } @@ -211,31 +232,35 @@ function process_statement() { print_d("rm "fname".tmp.$$") # use file as Input } else if(crest ~ /i/) { - print_b("if ! $check_only; then") - print_d("{ "statement"\n} <"fname) - print_e("fi") + print_cond(statement, "<"fname) # use file as Output } else if(crest ~ /o/) { shellfunc("req type_or_missing f", crest) - print_b("if ! $check_only; then") - print_d("{ "statement"\n} >"fname) - print_e("fi") + print_cond(statement, ">"fname) # Append to file } else if(crest ~ /a/) { shellfunc("req type_or_missing f", crest) - print_b("if ! $check_only; then") - print_d("{ "statement"\n} >>"fname) - print_e("fi") + print_cond(statement, ">>"fname) # do nothing special with file } else { - print_b("if ! $check_only; then") - print_d("{ "statement"\n}") - print_e("fi") + print_cond(statement) } statement = "" continue } + # shell condition + if(cchar == "?") { + has_cond = func_num++ + if(crest ~ /i/) { + funcs["cond_" has_cond] = ( \ + "{ "statement"\n} <"fname \ + ) + } else { + funcs["cond_" has_cond] = statement + } + } + # if none above matched printf "unrecognised statement: %s\n", cchar crest statement >"/dev/stderr" statement = ""