wok-6.x view sokojs/stuff/slc2htm.sh @ rev 24813
updated libnetfilter_queue and libnetfilter_queue-dev (1.0.3 -> 1.0.5)
author | Hans-G?nter Theisgen |
---|---|
date | Tue Mar 22 17:30:17 2022 +0100 (2022-03-22) |
parents | db9d9cb3c164 |
children |
line source
1 #!/bin/sh
3 swap() {
4 awk 'BEGIN { n=0 } { l[n++]=$0 } END {
5 for (i = 0; i < length(l[0]); i++) {
6 for (j = 0; j < n; j++) printf "%s", substr(l[j],i+1,1)
7 print ""
8 }}'
9 }
11 filter() {
12 sed 's| _| |;s|_ | |;s|^_| |;s|_$| |'
13 }
15 check() {
16 grep -Eq ' _|_ |^_|_$'
17 }
19 [ -z "$1" ] && echo "Usage: $0 set1.slc ..." && exit 1
20 [ ! -s "main.htm" ] && echo "$PWD/main.htm not found" && exit 2
22 while [ "$1" ]; do
23 file="$1"
24 set="$(basename $1 .slc)"
25 shift
26 [ -d "$set" ] && continue
27 echo "$set"
28 grep -q "<option>$set</option>" main.htm || sed -i "s|</select>|<option>$set</option>\");\n document.write(\"&|" main.htm
29 mkdir "$set"
30 comment=""; state=""; level=0
31 while read line; do
32 case "$line" in
33 *\<Url\>*) echo "$line" | sed 's|.*<Url>||;s|</Url>.*||' >> "$set/description.txt" ;;
34 *\<Email\>*) echo "$line" | sed 's|.*<Email>||;s|</Email>.*||' >> "$set/description.txt" ;;
35 *\<Title\>*) echo "$line" | sed 's|.*<Title>||;s|</Title>.*||' >> "$set/description.txt" ;;
36 *\<Description\>) state="Description"; continue ;;
37 *\</Description\>) state="" ;;
38 *\<LevelCollection*)
39 maxwidth="$(echo "$line" | sed 's|.*MaxWidth="||;s|".*||')"
40 col=16; [ $maxwidth -gt $col ] && col=$maxwidth
41 maxheight="$(echo "$line" | sed 's|.*MaxHeight="||;s|".*||')"
42 row=16; [ $maxheight -gt $row ] && row=$maxheight
43 echo "$line" | sed '/Copyright=/!d;s|.*Copyright="|copyright |;s|".*||' >> "$set/description.txt" ;;
44 *\<Level*) state="Level"
45 id="$(echo "$line" | sed 's|.*Id="||;s|".*||')"
46 width="$(echo "$line" | sed 's|.*Width="||;s|".*||')"
47 fmt=" "
48 fmt="${fmt:0:$((($col-$width)/2))}%-$(($col-($col-$width)/2))s"
49 height="$(echo "$line" | sed 's|.*Height="||;s|".*||')"
50 height=$((($row-$height)/2))
51 l=0
52 echo -n "" > $set/tmp0
53 while [ $height -gt $l ]; do
54 printf "$fmt\n" "" >> "$set/tmp0"
55 l=$(($l+1))
56 done
57 cat > "$set/level$level.htm" <<EOT
58 <html>
59 <head>
60 </head>
61 <body>
62 <form action="">
63 <script type="text/javascript">
64 <!--
65 if (parent.frames[0] == null) { document.location = "../sokojs.htm" }
66 l = new Array(
67 // $id ${maxwidth}x$maxheight+$((($col-$width)/2))+$height
68 EOT
69 continue ;;
70 *\</Level\>) state=""
71 while [ $row -gt $l ]; do
72 printf "$fmt\n" "" >> "$set/tmp0"
73 l=$(($l+1))
74 done
75 while swap < $set/tmp0 | check || check < $set/tmp0 ; do
76 swap < $set/tmp0 | filter | swap | filter > $set/tmp1
77 mv -f $set/tmp1 $set/tmp0
78 done
79 x=$(($(sed '/[@+]/{s|[@+].*||;q}' $set/tmp0 |\
80 wc -cl | sed 's|^|-|;s|......$|+&|')))
81 sed 's|.*|"&",|;$s|,$|);|' $set/tmp0 >> "$set/level$level.htm"
82 cat >> "$set/level$level.htm" <<EOT
84 Row=$row
85 Col=$col
86 for (x = 0; x < Row; x++)
87 for (y = 0; y < Col; y++)
88 document.write("<INPUT TYPE=\"button\" value=\"",
89 ' _#*$.'.indexOf(l[x].substring(y, y + 1).replace('+','.').replace('@','_')), "\">")
90 document.write("<INPUT TYPE=\"button\" value=\"$x\">",
91 "<INPUT TYPE=\"button\" value=\"$level\"><\/FORM>")
93 document.write("<FORM ACTION=\"\">")
94 document.write("<INPUT TYPE=\"button\" value=\""+Row+"\">",
95 "<INPUT TYPE=\"button\" value=\""+Col+"\">",
96 "<INPUT TYPE=\"button\" value=\"$set\">",
97 "<INPUT TYPE=\"button\" value=\"COUNT\"><\/FORM>")
98 parent.frames[1].location = "../main.htm"
99 //-->
100 </script></form>
101 </body>
102 </html>
103 EOT
104 rm -f $set/tmp*
105 level=$(($level+1))
106 continue ;;
107 esac
108 case "$state" in
109 Description)
110 echo "$line" >> "$set/description.txt" ;;
111 Level)
112 printf "$fmt\n" "$(echo "$line" | sed 's|.*<L>||;s|</L>||;:a;s|\([#.+@$\*]_*\) |\1_|;ta')" >> "$set/tmp0"
113 l=$(($l+1))
114 esac
115 done < "$file"
116 sed -i "s|COUNT|$(($level-1))|" "$set"/level*.htm
117 done