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

updated sc-im (-> 0.8.4)
author Hans-G?nter Theisgen
date Thu Aug 22 14:48:42 2024 +0100 (2 months ago)
parents 8db826af003e
children
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
8 [ -s "$file" ] || continue
9 grep -q '//!' "$file" && continue
10 awk 'BEGIN { begin=9999; end=9999; tab=" " }
11 function scan(s) {
12 i=2
13 for (b=0;;i++) {
14 c=substr(s,i,1)
15 if (c != " ") break
16 b++
17 }
18 if (c != "\"") line[row++]=s
19 else if (row == 0) print "//!" s
20 else line2[cut++]=s
21 for (e=0;;i++) {
22 c=substr(s,i,1)
23 if (c == "\"") break
24 if (c == " ") e++; else e=0
25 }
26 if (b < begin) begin=b
27 if (e < end && line[row-1]==s) end=e
28 col=i-2
29 }
30 function flush() {
31 for (i=0;i<row;i++) {
32 l=length(line[i])-end-begin-3
33 if (i == row-1) { tail="\"); //!"
34 if (end==0) l--
35 } else tail="\", //!"
36 print "\"" tab substr(line[i],begin+2,l) tail line[i]
37 }
38 for (i=0;i<cut;i++) print "//!" line2[i]
39 }
40 { if (/^"/) {
41 scan($0); n++
42 if (/");/) flush()
43 }
44 else if (/^Row/) print "Row=" row " //!" $0
45 else if (/^Col/) print "Col=" col-begin-end+length(tab) " //!" $0
46 else if (/\\"[0-9]*\\">",$/ && n != 0) {
47 s=$0; sub(/.*value=\\"/,"",s); sub(/\\">.*/,"",s)
48 l=length(line[0])-3; n-=cut+row; begin-=length(tab)
49 n=s - (l*n) - begin - ((begin+end)*(int(s/l)-n))
50 print "document.write(\"<INPUT TYPE=\\\"button\\\" value=\\\"" n "\\\">\", //!" $0
51 n=0
52 }
53 else print }' < $file | sed 's|"")|")|' > $file.$$
54 mv -f $file.$$ $file
55 done ;;
56 esac