fileset

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

commit 0a3ede80aa047c34fda23a907888c16a1b16408d
parent 5fe2703c9df556e8dfed96ba6765fb288a647e48
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Thu, 26 Sep 2013 21:34:34 +0200

fixed die function, made fsapply wrapper
Diffstat:
Mbin/fileset.awk | 20+++++++++++++-------
Abin/fsapply | 18++++++++++++++++++
Mbin/fslist | 11++++++++++-
3 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/bin/fileset.awk b/bin/fileset.awk @@ -7,21 +7,25 @@ BEGIN { # header print "#!/bin/sh" print "export fname dirname" - print "die() { printf '%s\n' \"$*\"; exit 1 }" + print_b("die() {") + print_i("printf '%s\\n' \"$*\"") + print_i("exit 1") + print_e("}") } function escaped(str) { gsub(/\\/, "\\\\", str) -# gsub(/\n/, "\\n", str) - gsub(/([\\"`$])/, "\\\\&", str) + # gsub(/\n/, "\\n", str) + gsub(/([\\\t"`${}\[\]])/, "\\\\&", str) return str } function quoted(str) { if(str ~ /^[a-zA-Z0-9_./]+$/) return str - else - return "\"" escaped(str) "\"" + gsub(/'/, "'\\''", str) + return "'" str "'" + # return "\"" escaped(str) "\"" } function print_i(str) { # print with indent @@ -198,9 +202,11 @@ function process_statement() { cmd_mknod("test -f "fname, "file") # unless disabled with the N flag, append newline at the end of # last line, if not already present - printf_fmt = (crest !~ /N/ && statement !~ /\n$/) ? \ - "%s\n" : "%s" + printf_fmt = crest ~ /n/ || (crest !~ /N/ && statement !~ /\n$/) ? \ + "%s\\n" : "%s" printf_redir = (crest ~ /a/ ? ">>" : ">") fname + # print_i("content="quoted(statement)) + # print_d("printf "printf_redir" '"printf_fmt"' \"$content\"") print_d("printf "printf_redir" '"printf_fmt"' "quoted(statement)) statement = "" continue diff --git a/bin/fsapply b/bin/fsapply @@ -0,0 +1,18 @@ +#!/bin/sh +if getopts x o; then + opt=-$o + shift +else + opt="" +fi +if ! [[ -d $1 ]]; then + printf '%s\n' >&2 "supply directory argument (got '$1')" + exit 2 +fi +cd "$1" || exit $? +shift +if [[ -n "$opt" ]]; then + fileset.awk | sh $opt +else + fileset.awk | sh +fi diff --git a/bin/fslist b/bin/fslist @@ -33,7 +33,12 @@ statement_end() { } for arg in "${@:-$PWD}"; do - for fname in $arg:a/**/*; do + if [[ -d $arg ]]; then + fnames=( $arg:a/**/* ) + else + fnames=( $arg:a ) + fi + for fname in $fnames; do zstat -LH s $fname || continue ftype=$(( [##16] $s[mode] >> 12 )) fmode=$(( [##8] $s[mode] & 8#7777 )) @@ -64,6 +69,10 @@ for arg in "${@:-$PWD}"; do flags='' if [[ $content == *$'\n' ]]; then content=${content%$'\n'} + if [[ $content == *$'\n' ]]; then + # force appending newline + flags+=n + fi else flags+=N fi