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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
#!/bin/sh
clean_id()
{
tr "\r\n" "~" | sed '
s/~*$//;
s/|/\&pipe;/g;
s/&/\&/g;
s/</\</g;
s/>/\>/g;
s/"/\"/g;
s/'\''/\'/g;
s/~\+/<br>/g;
'
echo ""
}
genpage()
{
local dir scripts name desc
dir="$1"
scripts="$2"
name=`cat $dir/ID.name`
desc=`cat $dir/ID.desc`
./tags < "$dir/ex.html" | awk -v "fn_ref=../packages/XREF" -v "scripts=$scripts" -v "name=$name" -v "desc=$desc" '
BEGIN {
while((getline < fn_ref) > 0) {
REF[$2] = $3
}
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
print "<html>"
print "<head>"
print " <title> pcb-rnd rosetta", name, "</title>"
print " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=us-ascii\">"
print "</head>"
print "<body>"
print "<!-- ******* DO NOT EDIT THIS FILE, it is generated by rosetta_genpages.sh ******* -->"
print "<-- back to the <a href=\"../index.html\">index of Rosetta examples</a>"
print "<h1>" name "</h1>"
print desc
print "<H2> Example implementations </H2>"
v = split(scripts, S, "[\r\n]+")
for(n = 1; n <= v; n++) {
lang=S[n]
sub("^ex[.]", "", lang)
if (n != 1)
print " | "
print "<a href=\"" S[n] "\">" lang "</a>"
}
print "<h2> Explanation, step by step </h2>"
}
/^<ref>/ {
gsub("</?ref>", "", $0)
name=$0
gsub("[ \t]*", "", name)
if (name in REF) {
link_begin="<a href=\"../" REF[name] "\">"
link_end = "</a>"
}
else {
link_begin=""
link_end=""
}
print "<i>" link_begin $0 link_end "</i>"
next
}
{ print $0 }
END {
print "</body>"
print "</html>"
}
' > "$dir/index.html"
}
gen_index()
{
awk -v "template=$1" '
BEGIN {
FS="[|]"
q = "\""
LANGS["rb"] = "ruby"
LANGS["pl"] = "perl"
LANGS["py"] = "python"
LANGS["stt"] = "stutter"
LANGS["scm"] = "scheme"
}
($1 == "scripts") {
s = $3
gsub("ex[.]", "", s)
v = split(s, S, " ")
s = ""
for(n = 1; n <= v; n++) {
if (S[n] in LANGS)
s = s " " LANGS[S[n]]
else
s = s " " S[n]
}
DATA[$2, $1] = s
next
}
($1 == "name") {
if (names == "")
names = $2
else
names = names "|" $2
}
{
# DATA[script, name] = "hello world"
DATA[$2, $1] = $3
}
function generate(cmd ,N,n,v,name,level) {
if (cmd == "index") {
print "<table border=1 cellspacing=0 cellpadding=15>"
print "<tr><th>lvl<th>example <th> languages <th> description"
v = split(names, N, "[|]")
for(n = 1; n <= v; n++) {
name = N[n]
level = name
sub("_.*", "", level)
if (level ~ "[^0-9]")
level = "n/a"
print "<tr>"
print " <td>" level
print " <td><a href=" q name "/index.html" q ">" DATA[name, "name"] "</a>"
print " <td>" DATA[name, "scripts"]
print " <td>" DATA[name, "desc"]
}
print "</table>"
}
else
print "Do not know how to generate " cmd > "/dev/stderr"
}
END {
FS=""
while((getline < template) > 0) {
if (match($0, "<rosetta[ \t][^>]*>")) {
print substr($0, 1, RSTART-1)
cmd=substr($0, RSTART+8, RLENGTH-9)
sub("^[ \t]*", "", cmd)
generate(cmd)
print substr($0, RSTART+RLENGTH)
}
else
print $0
}
}
'
}
for n in ../rosetta/*
do
if test -d "$n"
then
bn=`basename $n`
scripts=`cd $n && ls ex.* | grep -v ".pyc$\|.html$" `
genpage "$n" "$scripts"
echo -n "desc|$bn|"
clean_id < $n/ID.desc
echo -n "name|$bn|"
clean_id < $n/ID.name
echo -n "scripts|$bn|"
echo $scripts
fi
done | gen_index ../rosetta/index.templ.html > ../rosetta/index.html
|