From ced51aa57c06445dfac130ae975a612dff820b8b Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Fri, 10 Oct 2014 01:27:51 +0200 Subject: awink: clean up a bit, funcitonalize --- scripts/awink | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'scripts/awink') diff --git a/scripts/awink b/scripts/awink index d0ad890..1456c8b 100755 --- a/scripts/awink +++ b/scripts/awink @@ -1,17 +1,28 @@ #!/usr/bin/env bash -if ! [[ -n "$1" || -n "$2" ]]; then - printf "%s\n" "awink " - exit 2 -fi +## +# arguments: +# $1 In file +# $2 Out file +build() { + gawk '{ + if (NF == 2 && $1 == "%include") { + while ((getline line < $2) > 0) { + print line; + } + close($2); + } else { + print; + } + }' "$1" > "$2" +} -gawk '{ - if (NF == 2 && $1 == "%include") { - while ((getline line < $2) > 0) { - print line; - } - close($2); - } else { - print; - } -}' "$1" > "$2" +main() { + if [[ "$#" != 2 ]]; then + printf "%s\n" "awink " + exit 2 + fi + + build "$1" "$2" +} +main "$@" -- cgit v1.2.3-70-g09d2