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