#!/bin/sh

#	$1	image
#	$2	template
#	$3	[target_dir/][prefix]	target_dir must exist; '/' mandatory.

extract(){
	echo -n extracting "$4	" bytes at "$3" >&2
	(dd bs="$3" skip=1 count=0 && dd count=1 bs="$4") <"$1" >"$2" 2>/dev/null
	echo \. >&2
}

jigdo-file list-template -t "$2"\
|while read t o s m r
do	if [ "$t" = need-file ]
	then	extract "$1" "$3$m$r" "$o" "$s"
	fi
done
