#! /bin/sh

w="${1}";	# label
d="${2}";	# src dir
l="${3}";	# src files list
h=
v=
r () {
for i in ${1}
do
	grep -l "\<${w}\>" ${d}${i}>/dev/null 2>&1||continue
	for n in $(grep -n "\<${w}\>" ${d}${i}|grep -v "\<${w}:\|;-\|;.;*${w}\|%${w}"|cut -d: -f1)
	do
	    [ -z "${n}" ]&&break
	    [ "${v}" = "${i}" ]||{ export h=xxx;v=${i};echo -n "\n<li><a href=\"file://localhost${d}${i}\">${i}</a><ul><li>\n"; }
	    echo -n "${n} "
	done
	[ -z "${h}" ]||echo '\n</li></ul></li>\n';h=
done
}

echo -e "$(r "${l}")"

# bash doesnt proagate vari values outside <while> loop !!!
#	grep -n "\<${w}\>" ${d}${i}|grep -v "\<${w}:\|;-"|cut -d: -f1|while read n
