wok view sokojs/stuff/shrink.sh @ rev 24570

sokojs: add shrink.sh (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Feb 26 21:49:28 2022 +0000 (2022-02-26)
parents 36a1e6790d10
children 33b1bc3e872a
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 l=length(line[i])-end-begin-3
30 if (i == row-1) { tail="\"); //!"
31 if (end==0) l--
32 } else tail="\", //!"
33 print "\"" tab substr(line[i],begin+2,l) tail line[i]
34 }
35 for (i=0;i<cut;i++) print "//!" line2[i]
36 }
37 { if (/^"/) {
38 scan($0); n++
39 if (/");/) flush()
40 }
41 else if (/^Row/) print "Row=" row " //!" $0
42 else if (/^Col/) print "Col=" col-begin-end+length(tab) " //!" $0
43 else if (/\\"[0-9]*\\">",$/ && n != 0) {
44 s=$0; sub(/.*value=\\"/,"",s); sub(/\\">.*/,"",s)
45 l=length(line[0])-3; n-=cut+row; begin-=length(tab)
46 n=s - (l*n) - begin - ((begin+end)*(int(s/l)-n))
47 print "document.write(\"<INPUT TYPE=\\\"button\\\" value=\\\"" n "\\\">\", //!" $0
48 n=0
49 }
50 else print }' < $file | sed 's|"")|")|' > $file.$$
51 mv -f $file.$$ $file
52 done ;;
53 esac