Jump to content

User:Scsbot/formtools/formsetup

From Wiktionary, the free dictionary
tag=$1
file=$2

tf=tf$$

rm="/bin/rm -f"

td=td$tag

xmlsed -t $file > $tf

forms="`grep '/form$' $tf`"
nf=`echo "$forms" | wc -l`

if test $nf -lt 1
then
	echo "unexpected (no forms)" >&2
	exit 1
fi

mkdir $td || exit 1

for x in `echo "$forms" | column 1`
do
	formname="`xmlsed -x $file \\#$x/@name`"
	formid="`xmlsed -x $file \\#$x/@id`"

	echo "$x	$formid	$formname" >> $td/.toc

	mkdir $td/$x

	xmlsed -x $file \#$x/@action > $td/$x/.action
	xmlsed -x $file \#$x/@method > $td/$x/.method

	pat=`echo $x | sed 's/\./\\\\./g'`

	for y in `grep "^$pat\\..*input$" $tf | column 1`
	do	name="`xmlsed -x $file \\#$y/@name`"
		type="`xmlsed -x $file \\#$y/@type`"
		value="`xmlsed -x $file \\#$y/@value`"

		echo "$value" > $td/$x/$name

		echo "$name	$type" >> $td/$x/.toc
	done

	for y in `grep "^$pat\\..*/textarea$" $tf | column 1`
	do	name="`xmlsed -x $file \\#$y/@name`"
		type=".textarea"

		xmlsed -x $file \#$y > $td/$x/$name

		echo "$name	$type" >> $td/$x/.toc
	done
done

$rm $tf

exit 0