wok-current annotate sokojs/stuff/slc2htm.sh @ rev 24127

sokojs: get slc levels
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 16 16:30:13 2021 +0000 (2021-10-16)
parents
children 787a1807d2bb
rev   line source
pascal@24127 1 #!/bin/sh
pascal@24127 2
pascal@24127 3 [ -z "$1" ] && echo "$0 set1.slc ..." && exit 1
pascal@24127 4 [ ! -s "main.htm" ] && echo "$PWD/main.htm not found" && exit 2
pascal@24127 5
pascal@24127 6 while [ "$1" ]; do
pascal@24127 7 file="$1"
pascal@24127 8 set="$(basename $1 .slc)"
pascal@24127 9 shift
pascal@24127 10 [ -d "$set" ] && continue
pascal@24127 11 echo "$set"
pascal@24127 12 grep -q "<option>$set</option>" main.htm || sed -i "s|</select>|<option>$set</option>\");\n document.write(\"&|" main.htm
pascal@24127 13 mkdir "$set"
pascal@24127 14 comment=""; state=""; level=0
pascal@24127 15 while read line; do
pascal@24127 16 case "$line" in
pascal@24127 17 *\<Url\>*) echo "$line" | sed 's|.*<Url>||;s|</Url>.*||' >> "$set/description.txt" ;;
pascal@24127 18 *\<Title\>*) echo "$line" | sed 's|.*<Title>||;s|</Title>.*||' >> "$set/description.txt" ;;
pascal@24127 19 *\<Description\>) state="Description"; continue ;;
pascal@24127 20 *\</Description\>) state="" ;;
pascal@24127 21 *\<LevelCollection*)
pascal@24127 22 maxwidth="$(echo "$line" | sed 's|.*MaxWidth="||;s|".*||')"
pascal@24127 23 col=16; [ $maxwidth -gt $col ] && col=$maxwidth
pascal@24127 24 maxheight="$(echo "$line" | sed 's|.*MaxHeight="||;s|".*||')"
pascal@24127 25 row=16; [ $maxheight -gt $row ] && row=$maxheight
pascal@24127 26 echo "$line" | sed '/Copyright=/!d;s|.*Copyright="|copyright |;s|".*||' >> "$set/description.txt" ;;
pascal@24127 27 *\<Level*) state="Level"
pascal@24127 28 id="$(echo "$line" | sed 's|.*Id="||;s|".*||')"
pascal@24127 29 width="$(echo "$line" | sed 's|.*Width="||;s|".*||')"
pascal@24127 30 fmt=" "
pascal@24127 31 fmt="${fmt:0:$((($col-$width)/2))}%-$(($col-($col-$width)/2))s"
pascal@24127 32 height="$(echo "$line" | sed 's|.*Height="||;s|".*||')"
pascal@24127 33 height=$((($row-$height)/2))
pascal@24127 34 l=0
pascal@24127 35 cat > "$set/level$level.htm" <<EOT
pascal@24127 36 <html>
pascal@24127 37 <head>
pascal@24127 38 </head>
pascal@24127 39 <body>
pascal@24127 40 <form action="">
pascal@24127 41 <script type="text/javascript">
pascal@24127 42 <!--
pascal@24127 43 if (parent.frames[0] == null) { document.location = "../sokojs.htm" }
pascal@24127 44 l = new Array(
pascal@24127 45 EOT
pascal@24127 46 prev=""
pascal@24127 47 continue ;;
pascal@24127 48 *\</Level\>) state=""
pascal@24127 49 while [ $row -gt $l ]; do
pascal@24127 50 printf "\"$fmt\",\n" "$prev" >> "$set/level$level.htm"
pascal@24127 51 prev=""
pascal@24127 52 l=$(($l+1))
pascal@24127 53 done
pascal@24127 54 cat >> "$set/level$level.htm" <<EOT
pascal@24127 55 $(printf "\"$fmt\"" "$prev"));
pascal@24127 56
pascal@24127 57 Row=$row
pascal@24127 58 Col=$col
pascal@24127 59 for (x = 0; x < Row; x++)
pascal@24127 60 for (y = 0; y < Col; y++)
pascal@24127 61 document.write("<INPUT TYPE=\"button\" value=\"",
pascal@24127 62 ' _#*$.'.indexOf(l[x].substring(y, y + 1)), "\">")
pascal@24127 63 document.write("<INPUT TYPE=\"button\" value=\"$x\">",
pascal@24127 64 "<INPUT TYPE=\"button\" value=\"$level\"><\/FORM>")
pascal@24127 65
pascal@24127 66 document.write("<FORM ACTION=\"\">")
pascal@24127 67 document.write("<INPUT TYPE=\"button\" value=\""+Row+"\">",
pascal@24127 68 "<INPUT TYPE=\"button\" value=\""+Col+"\">",
pascal@24127 69 "<INPUT TYPE=\"button\" value=\"$set\">",
pascal@24127 70 "<INPUT TYPE=\"button\" value=\"COUNT\"><\/FORM>")
pascal@24127 71 parent.frames[1].location = "../main.htm"
pascal@24127 72 parent.frames[2].location = "../level.htm"
pascal@24127 73 //-->
pascal@24127 74 </script></form>
pascal@24127 75 </body>
pascal@24127 76 </html>
pascal@24127 77 EOT
pascal@24127 78 level=$(($level+1))
pascal@24127 79 continue ;;
pascal@24127 80 esac
pascal@24127 81 case "$state" in
pascal@24127 82 Description)
pascal@24127 83 echo "$line" >> "$set/description.txt" ;;
pascal@24127 84 Level)
pascal@24127 85 [ "$prev" ] && printf "\"$fmt\",$comment\n" "$prev" >> "$set/level$level.htm" ||
pascal@24127 86 echo "// $id ${maxwidth}x$maxheight+$((($col-$width)/2))+$height" >> "$set/level$level.htm"
pascal@24127 87 while [ $height -gt 0 ]; do
pascal@24127 88 printf "\"$fmt\",\n" "" >> "$set/level$level.htm"
pascal@24127 89 height=$(($height-1))
pascal@24127 90 l=$(($l+1))
pascal@24127 91 done
pascal@24127 92 prev="$(echo "$line" | sed 's|.*<L>||;s|</L>||;:a;s|\([#.+@$\*]_*\) |\1_|;ta')"
pascal@24127 93 comment=""
pascal@24127 94 if echo "$prev" | grep -Eq '@|\+'; then
pascal@24127 95 x=$(($(echo "$prev" | sed 's|[@+].*||' | wc -c)+($l*$col)+($col-$width)/2-1))
pascal@24127 96 comment=" // $(printf "\"$fmt\"," "$prev") $x"
pascal@24127 97 prev="$(echo "$prev" | sed 's|\+|.|;s|@|_|')"
pascal@24127 98 fi
pascal@24127 99 l=$(($l+1))
pascal@24127 100 esac
pascal@24127 101 done < "$file"
pascal@24127 102 sed -i "s|COUNT|$(($level-1))|" "$set"/level*.htm
pascal@24127 103 done