wok rev 24567

sokojs: add shrink.sh
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Feb 26 15:02:05 2022 +0000 (2022-02-26)
parents b53e18d1978e
children 4495814243a2
files sokojs/stuff/htm2slc.sh sokojs/stuff/shrink.sh sokojs/stuff/slc2htm.sh sokojs/stuff/unshrink.sh
line diff
     1.1 --- a/sokojs/stuff/htm2slc.sh	Sat Feb 26 07:43:46 2022 +0100
     1.2 +++ b/sokojs/stuff/htm2slc.sh	Sat Feb 26 15:02:05 2022 +0000
     1.3 @@ -2,7 +2,7 @@
     1.4  
     1.5  case "$0" in
     1.6  *2txt*)
     1.7 -  [ -z "$1" ] && echo "$0 file" && exit 1
     1.8 +  [ -z "$1" ] && echo "Usage: $0 file" && exit 1
     1.9    sed '/^"\|<L>\|<Level/!d;s|.*<Level Id="|; |;s| *<L>||;s|</L>||;s| *"[,)].*||;s|^"||;s|".*||;s|_| |g;/^$/d' "$1" | awk 'BEGIN {n=1000;h=0}
    1.10  { s[h++]=$0
    1.11    if (/^;/) next
    1.12 @@ -12,7 +12,7 @@
    1.13    exit;;
    1.14  esac
    1.15  
    1.16 -[ -z "$1" ] && echo "$0 set/" && exit 1
    1.17 +[ -z "$1" ] && echo "Usage: $0 set/" && exit 1
    1.18  [ ! -s "$1/level0.htm" ] && echo "$1/level0.htm not found" && exit 2
    1.19  
    1.20  cat <<EOT
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/sokojs/stuff/shrink.sh	Sat Feb 26 15:02:05 2022 +0000
     2.3 @@ -0,0 +1,49 @@
     2.4 +#!/bin/sh
     2.5 +
     2.6 +[ -z "$1" ] && echo "Usage: $0 level-files..." && exit 1
     2.7 +case "$0" in
     2.8 +*unshrink*)
     2.9 +	sed -i 's|.*//!||' $@ ;;
    2.10 +*)	for file in $@ ; do awk 'BEGIN { begin=9999; end=9999; tab=" " }
    2.11 +function scan(s) {
    2.12 +  i=2
    2.13 +  for (b=0;;i++) {
    2.14 +    c=substr(s,i,1)
    2.15 +    if (c != " ") break
    2.16 +    b++
    2.17 +  }
    2.18 +  if (c != "\"") line[row++]=s
    2.19 +  else if (row == 0) print "//!" s
    2.20 +  else line2[cut++]=s
    2.21 +  for (e=0;;i++) {
    2.22 +    c=substr(s,i,1)
    2.23 +    if (c == "\"") break
    2.24 +    if (c == " ") e++; else e=0
    2.25 +  }
    2.26 +  if (b < begin) begin=b
    2.27 +  if (e < end && line[row-1]==s) end=e
    2.28 +  col=i-2
    2.29 +}
    2.30 +function flush() {
    2.31 +  for (i=0;i<row;i++) {
    2.32 +    if (i == row-1) tail="\"); //!"; else tail="\",  //!"
    2.33 +    print "\"" tab substr(line[i],begin+2,length(line[i])-end-begin-3) tail line[i]
    2.34 +  }
    2.35 +  for (i=0;i<cut;i++) print "//!" line2[i]
    2.36 +}
    2.37 +{ if (/^"/) {
    2.38 +    scan($0); n++
    2.39 +    if (/");/) flush()
    2.40 +  } 
    2.41 +  else if (/^Row/) print "Row=" row " //!" $0
    2.42 +  else if (/^Col/) print "Col=" col-begin-end+length(tab) " //!" $0
    2.43 +  else if (/[0-9]\\">",$/) {
    2.44 +    s=$0; sub(/.*value=\\"/,"",s); sub(/\\">.*/,"",s)
    2.45 +    l=length(line[0])-3; n-=cut+row; begin-=length(tab)
    2.46 +    n=s - (l*n) - begin - ((begin+end)*(int(s/l)-n))
    2.47 +    print "document.write(\"<INPUT TYPE=\\\"button\\\" value=\\\"" n "\\\">\", //!" $0
    2.48 +  }
    2.49 +  else print }' < $file > $file.$$
    2.50 +		mv -f $file.$$ $file
    2.51 +	done ;;
    2.52 +esac
     3.1 --- a/sokojs/stuff/slc2htm.sh	Sat Feb 26 07:43:46 2022 +0100
     3.2 +++ b/sokojs/stuff/slc2htm.sh	Sat Feb 26 15:02:05 2022 +0000
     3.3 @@ -16,7 +16,7 @@
     3.4      grep -Eq ' _|_ |^_|_$'
     3.5  }
     3.6  
     3.7 -[ -z "$1" ] && echo "$0 set1.slc ..." && exit 1
     3.8 +[ -z "$1" ] && echo "Usage: $0 set1.slc ..." && exit 1
     3.9  [ ! -s "main.htm" ] && echo "$PWD/main.htm not found" && exit 2
    3.10  
    3.11  while [ "$1" ]; do
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/sokojs/stuff/unshrink.sh	Sat Feb 26 15:02:05 2022 +0000
     4.3 @@ -0,0 +1,1 @@
     4.4 +shrink.sh
     4.5 \ No newline at end of file