wok-6.x view sokojs/stuff/shrink.sh @ 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
children 4495814243a2
line source
1 #!/bin/sh
3 [ -z "$1" ] && echo "Usage: $0 level-files..." && exit 1
4 case "$0" in
5 *unshrink*)
6 sed -i 's|.*//!||' $@ ;;
7 *) for file in $@ ; do awk 'BEGIN { begin=9999; end=9999; tab=" " }
8 function scan(s) {
9 i=2
10 for (b=0;;i++) {
11 c=substr(s,i,1)
12 if (c != " ") break
13 b++
14 }
15 if (c != "\"") line[row++]=s
16 else if (row == 0) print "//!" s
17 else line2[cut++]=s
18 for (e=0;;i++) {
19 c=substr(s,i,1)
20 if (c == "\"") break
21 if (c == " ") e++; else e=0
22 }
23 if (b < begin) begin=b
24 if (e < end && line[row-1]==s) end=e
25 col=i-2
26 }
27 function flush() {
28 for (i=0;i<row;i++) {
29 if (i == row-1) tail="\"); //!"; else tail="\", //!"
30 print "\"" tab substr(line[i],begin+2,length(line[i])-end-begin-3) tail line[i]
31 }
32 for (i=0;i<cut;i++) print "//!" line2[i]
33 }
34 { if (/^"/) {
35 scan($0); n++
36 if (/");/) flush()
37 }
38 else if (/^Row/) print "Row=" row " //!" $0
39 else if (/^Col/) print "Col=" col-begin-end+length(tab) " //!" $0
40 else if (/[0-9]\\">",$/) {
41 s=$0; sub(/.*value=\\"/,"",s); sub(/\\">.*/,"",s)
42 l=length(line[0])-3; n-=cut+row; begin-=length(tab)
43 n=s - (l*n) - begin - ((begin+end)*(int(s/l)-n))
44 print "document.write(\"<INPUT TYPE=\\\"button\\\" value=\\\"" n "\\\">\", //!" $0
45 }
46 else print }' < $file > $file.$$
47 mv -f $file.$$ $file
48 done ;;
49 esac