wok view sokojs/stuff/htm2slc.sh @ rev 24131

lxsession, lxsession-lxpolkit, lxappearance: misc fixes (thanks Saipul)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 23 10:55:42 2021 +0000 (2021-10-23)
parents
children 035e82f04c94
line source
1 #!/bin/sh
3 case "$0" in
4 *2txt*)
5 [ -z "$1" ] && echo "$0 file" && exit 1
6 sed '/^"\|<L>\|<Level/!d;s|.*<Level Id="|; |;s| *<L>||;s|</L>||;s| *"[,)].*||;s|^"||;s|".*||;s|_| |g;/^$/d' "$1" | awk 'BEGIN {n=1000;h=0}
7 { s[h++]=$0
8 if (/^;/) next
9 for (i=1;i<n && substr($0,i,1) == " ";i++);
10 if (i<n) n=i
11 } END { for (i=0;i<h;i++) if (substr(s[i],1,1) == ";") print s[i]; else print substr(s[i],n) }'
12 exit;;
13 esac
15 [ -z "$1" ] && echo "$0 set/" && exit 1
16 [ ! -s "$1/level0.htm" ] && echo "$1/level0.htm not found" && exit 2
18 cat <<EOT
19 <?xml version="1.0" encoding="utf-8"?>
20 <SokobanLevels xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="SokobanLev.xsd">
21 EOT
22 [ -s $1/description.txt ] && awk 'BEGIN { state=0 }
23 {
24 if (state == 0) { state++; print " <Title>" $0 "</Title>"; print " <Description>" }
25 else {
26 if (/[A-Za-z0-9]@[A-Za-z0-9]/) s=" <Email>" $0 "</Email>"
27 else if (/^http/) s=" <Url>" $0 "</Url>"
28 else if (!/^copyright/) { print; next }
29 else next
30 if (state++ == 1) print " </Description>"
31 print s
32 }
33 } END { if (state == 1) print " </Description>" }' $1/description.txt
34 copyright="$(grep -s ^copyright $1/description.txt | sed 's|^copyright |Copyright="|;s|$|" |')"
35 maxwidth="$(sed '/^"/!d;s| *"[,)].*||;s|^" *||' $1/level*.htm | awk 'BEGIN{w=0}{if(w<length($0)) w=length($0)}END{print w}')"
36 maxheight="$(for i in $1/level*.htm; do sed '/^"/!d;s| *"[,)].*||;s|^" *||;/^$/d' $i | wc -l; done | awk 'BEGIN{h=0}{if(h<$0) h=$0}END{print h}')"
37 echo " <LevelCollection ${copyright}MaxWidth=\"$maxwidth\" MaxHeight=\"$maxheight\">"
38 n=0
39 while [ -s "$1/level$n.htm" ]; do
40 i="$1/level$((n++)).htm"
41 id="$(sed '/^\/\/ /!d;/[0-9]x[0-9]*\+[0-9]*\+[0-9]/!d;s|^// ||;s| [0-9]*x[0-9]*.*||' $i)"
42 sed '/^"/!d;s| *"[,)].*||;s|^"||;s|_| |g;/^$/d' $i | awk -vx="${id:-$(basename $i .htm)}" '
43 BEGIN {n=1000;w=0;h=0} {
44 s[h]=$0
45 for (i=1;i<n && substr($0,i,1) == " ";i++);
46 if (i<n) n=i
47 if (w<length($0)) w=length($0)
48 h++
49 } END { print " <Level Id=\"" x "\" Width=\"" w-n+1 "\" Height=\"" h "\">"
50 for (i=0;i<h;i++) print " <L>" substr(s[i],n) "</L>"
51 print " </Level>" }'
52 done
53 cat <<EOT
54 </LevelCollection>
55 </SokobanLevels>
56 EOT