wok-current diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sokojs/stuff/slc2htm.sh	Sat Oct 16 16:30:13 2021 +0000
     1.3 @@ -0,0 +1,103 @@
     1.4 +#!/bin/sh
     1.5 +
     1.6 +[ -z "$1" ] && echo "$0 set1.slc ..." && exit 1
     1.7 +[ ! -s "main.htm" ] && echo "$PWD/main.htm not found" && exit 2
     1.8 +
     1.9 +while [ "$1" ]; do
    1.10 +	file="$1"
    1.11 +	set="$(basename $1 .slc)"
    1.12 +	shift
    1.13 +	[ -d "$set" ] && continue
    1.14 +	echo "$set"
    1.15 +	grep -q "<option>$set</option>" main.htm || sed -i "s|</select>|<option>$set</option>\");\n    document.write(\"&|" main.htm
    1.16 +	mkdir "$set"
    1.17 +	comment=""; state=""; level=0
    1.18 +	while read line; do
    1.19 +		case "$line" in
    1.20 +		*\<Url\>*) echo "$line" | sed 's|.*<Url>||;s|</Url>.*||' >> "$set/description.txt" ;;
    1.21 +		*\<Title\>*) echo "$line" | sed 's|.*<Title>||;s|</Title>.*||' >> "$set/description.txt" ;;
    1.22 +		*\<Description\>) state="Description"; continue ;;
    1.23 +		*\</Description\>) state="" ;;
    1.24 +		*\<LevelCollection*)
    1.25 +                        maxwidth="$(echo "$line" | sed 's|.*MaxWidth="||;s|".*||')"
    1.26 +			col=16; [ $maxwidth -gt $col ] && col=$maxwidth
    1.27 +                        maxheight="$(echo "$line" | sed 's|.*MaxHeight="||;s|".*||')"
    1.28 +			row=16; [ $maxheight -gt $row ] && row=$maxheight
    1.29 +                        echo "$line" | sed '/Copyright=/!d;s|.*Copyright="|copyright |;s|".*||' >> "$set/description.txt" ;;
    1.30 +		*\<Level*) state="Level"
    1.31 +                        id="$(echo "$line" | sed 's|.*Id="||;s|".*||')"
    1.32 +                        width="$(echo "$line" | sed 's|.*Width="||;s|".*||')"
    1.33 +			fmt="                                               "
    1.34 +			fmt="${fmt:0:$((($col-$width)/2))}%-$(($col-($col-$width)/2))s"
    1.35 +                        height="$(echo "$line" | sed 's|.*Height="||;s|".*||')"
    1.36 +			height=$((($row-$height)/2))
    1.37 +			l=0
    1.38 +			cat > "$set/level$level.htm" <<EOT
    1.39 +<html>
    1.40 +<head>
    1.41 +</head>
    1.42 +<body>
    1.43 +<form action="">
    1.44 +<script type="text/javascript">
    1.45 +<!--
    1.46 +if (parent.frames[0] == null) { document.location = "../sokojs.htm"  }
    1.47 +l = new Array(
    1.48 +EOT
    1.49 +			prev=""
    1.50 +			continue ;;
    1.51 +		*\</Level\>) state=""
    1.52 +			while [ $row -gt $l ]; do
    1.53 +				printf "\"$fmt\",\n" "$prev" >> "$set/level$level.htm"
    1.54 +				prev=""
    1.55 +				l=$(($l+1))
    1.56 +			done
    1.57 +			cat >> "$set/level$level.htm" <<EOT
    1.58 +$(printf "\"$fmt\"" "$prev"));
    1.59 +
    1.60 +Row=$row
    1.61 +Col=$col
    1.62 +for  (x = 0; x < Row; x++)
    1.63 +  for  (y = 0; y < Col; y++)
    1.64 +    document.write("<INPUT TYPE=\"button\" value=\"",
    1.65 +      ' _#*$.'.indexOf(l[x].substring(y, y + 1)), "\">")
    1.66 +document.write("<INPUT TYPE=\"button\" value=\"$x\">",
    1.67 +               "<INPUT TYPE=\"button\" value=\"$level\"><\/FORM>")
    1.68 +
    1.69 +document.write("<FORM ACTION=\"\">")
    1.70 +document.write("<INPUT TYPE=\"button\" value=\""+Row+"\">",
    1.71 +               "<INPUT TYPE=\"button\" value=\""+Col+"\">",
    1.72 +               "<INPUT TYPE=\"button\" value=\"$set\">",
    1.73 +               "<INPUT TYPE=\"button\" value=\"COUNT\"><\/FORM>")
    1.74 +parent.frames[1].location = "../main.htm"
    1.75 +parent.frames[2].location = "../level.htm"
    1.76 +//-->
    1.77 +</script></form>
    1.78 +</body>
    1.79 +</html>
    1.80 +EOT
    1.81 +			level=$(($level+1))
    1.82 +			continue ;;
    1.83 +		esac
    1.84 +		case "$state" in
    1.85 +		Description)
    1.86 +			echo "$line" >> "$set/description.txt" ;;
    1.87 +		Level)
    1.88 +			[ "$prev" ] && printf "\"$fmt\",$comment\n" "$prev" >> "$set/level$level.htm" ||
    1.89 +			echo "// $id ${maxwidth}x$maxheight+$((($col-$width)/2))+$height" >> "$set/level$level.htm"
    1.90 +			while [ $height -gt 0 ]; do
    1.91 +				printf "\"$fmt\",\n" "" >> "$set/level$level.htm"
    1.92 +				height=$(($height-1))
    1.93 +				l=$(($l+1))
    1.94 +			done
    1.95 +			prev="$(echo "$line" | sed 's|.*<L>||;s|</L>||;:a;s|\([#.+@$\*]_*\) |\1_|;ta')"
    1.96 +			comment=""
    1.97 +			if echo "$prev" | grep -Eq '@|\+'; then
    1.98 +				x=$(($(echo "$prev" | sed 's|[@+].*||' | wc -c)+($l*$col)+($col-$width)/2-1))
    1.99 +				comment=" // $(printf "\"$fmt\"," "$prev") $x"
   1.100 +				prev="$(echo "$prev" | sed 's|\+|.|;s|@|_|')"
   1.101 +			fi
   1.102 +			l=$(($l+1))
   1.103 +		esac
   1.104 +	done < "$file"
   1.105 +	sed -i "s|COUNT|$(($level-1))|" "$set"/level*.htm
   1.106 +done