commit 2b20f6163358b6ceeaef55392fb42685c2709bbf
parent 94be808397255ea657ba68f79bb070150acadf6b
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date: Tue, 1 Mar 2016 15:39:40 +0100
untested hexdump mode
Diffstat:
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/README b/README
@@ -76,6 +76,9 @@ B<flags><tab><content>
create regular file with content specified as base64,
additional flags as with "b"
+X<flags><tab><content>
+ create regular file with content specified as hexdump as produced by xxd
+
!<flags><tab><command>
run shell command on file, depending on the flags:
"i" - redirect stdin from the file for the command
diff --git a/bin/fileset.awk b/bin/fileset.awk
@@ -172,16 +172,19 @@ function process_statement() {
continue
}
- # cat, copy, content; eats rest of statement and puts it into the file
- # binary, base64; decodes the arguments and changes file content
- if(cchar ~ /[bBcC]/) {
+ # Cat, Copy, Content; eats rest of statement and puts it into the file
+ # Binary, Base64; decodes the arguments and changes file content
+ # heXdump; decodes the arguments and replaces file content
+ if(cchar ~ /[bBcCX]/) {
shellfunc("f 1", crest)
- content = get_argument(cchar ~ /[BC]/)
+ content = get_argument(cchar ~ /[BCX]/)
func_name = "fn" func_num++
if(cchar ~ /[bB]/) {
funcs[func_name] = "\tbase64 <<<"quoted(content)
+ if(cchar ~ /[X]/) {
+ funcs[func_name] = "\txxd -r <<<"quoted(content)
} else {
# unless disabled with the N flag, append newline at the end of
# last line, if not already present
diff --git a/bin/fslist b/bin/fslist
@@ -43,7 +43,11 @@ if (($+commands[file])) && (($+commands[base64])); then
: ${print_b:=1}
else
: ${print_b:=0}
+ if (($+commands[file])) && (($+commands[xxd])); then
+ : ${print_x:=1}
+ fi
fi
+: ${print_x:=0}
fnames=( )
for arg in "${@:-$ROOT}"; do
@@ -90,8 +94,13 @@ for fname in $fnames; do
statement $'l\t'$s[link] $'\t'
elif [[ $t == f ]]; then
if (($print_c)); then
- if (($print_b)) && [[ $(file -bi $fname) != text/* ]]; then
- statement B$'\t'"$(base64 <$fname)" $'\n'
+ if (($s[size])) && (($print_b + $print_x)) && \
+ [[ $(file -bi $fname) != text/* ]]; then
+ if (($print_x)); then
+ statement X$'\t'"$(xxd $fname)" $'\n'
+ else
+ statement B$'\t'"$(base64 <$fname)" $'\n'
+ fi
else
IFS= read -r -d '' content <$fname
flags=''