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