1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#!/bin/sh
autostyle()
{
awk -v "template=$1" -v "root=$ROOT" '
BEGIN {
while((getline < template) > 0) {
if (parse_auto(RES, $0)) {
if (RES["action"] == "begin")
curr = RES["ID"]
else
reset_curr = 1
}
if (curr != "")
AUTO[curr] = AUTO[curr] var_subs($0) "\n"
if (reset_curr) {
curr = ""
reset_curr = 0
}
}
}
function var_subs(s)
{
gsub("[$]ROOT[$]", root, s)
return s
}
function parse_auto(RES, line ,tmp)
{
if (!(line ~ "<!--AUTO"))
return 0
sub(".*<!--AUTO[ \t]*", "", line)
sub("[ \t]*-->.*", "", line)
line = tolower(line)
tmp = line
sub("[ \t].*$", "", tmp)
RES["ID"] = tmp
tmp = line
sub("^[^ \t]*[ \t]*", "", tmp)
RES["action"] = tmp
return 1
}
{
if (parse_auto(RES, $0)) {
if (RES["action"] == "begin")
skip = 1
else if (RES["action"] == "end") {
printf("%s", AUTO[RES["ID"]])
skip = 0
}
next
}
}
(!skip) { print $0 }
'
}
for html in $*
do
case $html in
Autostyle.html) ;;
*)
mv $html $html.tmp
autostyle "Autostyle.html" < $html.tmp > $html
if test $? = 0
then
rm $html.tmp
else
echo "Failed on $html, keeping the original version."
mv $html.tmp $html
fi
esac
done
|