-
Notifications
You must be signed in to change notification settings - Fork 0
/
icontable.awk
executable file
·106 lines (90 loc) · 2.74 KB
/
icontable.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/gawk -f
## IconTable Script for viewing and extracting png-icons from Windows .ico files.
## Needed package "icoutils" installed as dependency.
## Change "browser" variable in BEGIN section from "yelp" to your favorite fast browser if you have it!
function extract(infile){
if(ENVIRON[TMPDIR]){tmproot=ENVIRON[TMPDIR]}else{tmproot="/tmp"}
system("rm -r "tmproot"/*_icotbl")
"mktemp -d --suffix=_icotbl"|getline tmpdir
extrcmd="icotool -x \""infile"\" -o \""tmpdir"\""
system(extrcmd)
close(extrcmd, "to")
}
function buildtable(name,folder){
cmd="find \""folder"\" -regextype sed -regex \".*/"name"_[0-9]*_.*\\.png\"";
while ((cmd|getline fnam)>0){
#print fnam
fattr=fnam;gsub(folder"/"name"_","",fattr);gsub(/.[^.]+$/,"",fattr)
ext=fnam;gsub(/[^\.]*\./,"",ext)
#print fattr
split(fattr,inf,FS)
nomer=inf[1]
#format[nomer][0]=0;delete format[nomer][0]
split(inf[2],format,"x")
imagefile[format[1]][format[2]][format[3]]=fnam
width[format[1]]=format[1]
height[format[2]]=format[2]
color[format[3]]=format[3]
sizeraw=format[1] format[2]
sizeraw=sizeraw+0
sizeraw_arr[sizeraw]=sizeraw
}
close(cmd)
asort(sizeraw_arr)
asort(width)
asort(height)
asort(color)
}
function buildfile(name,folder){
outfile=folder"/"name".html"
print "<html><head><title>"name".ico</title></head></head>"
print "<body style=\"margin:0;padding:0\">">outfile
print "<table border=1 width=\"100%\">">outfile
print "<tr><td colspan=\""length(color)*2"\" style=\"justify-content:center; align-items: center; text-align:center\"><font size=\"120%\">"name".ico</font></td></tr>">outfile
print "<tr>">outfile
for(c in color){
if(color[c]==32){display_color="XP"}else if(color[c]==24){display_color="True"}else if(color[c]==16){display_color="High"}else{display_color=2^color[c]}
print "<td colspan=2 style=\"justify-content:center; align-items: center; text-align:center\"><b>"display_color" color</b></td>">outfile
}
print "</tr>">outfile
for(i in sizeraw_arr){
polovina=length(sizeraw_arr[i])/2
w=substr(sizeraw_arr[i],1,polovina)
h=substr(sizeraw_arr[i],polovina+1,polovina)
print "<tr>">outfile
for(c in color){
print "<td>"w"x"h"</td><td><img width=\""w"\" height=\""h"\" src=\""imagefile[w][h][color[c]]"\"></td>">outfile
}
print "</tr>">outfile
}
print "</table></body>">outfile
}
function deltemp(){
dtemp="rm -r "tmpdir
system(dtemp)
close(dtemp)
}
function openfile(){
openhtml=browser" \""outfile"\" 2>/dev/null"
system(openhtml)
#close(openhtml,"to")
#deltemp()
}
BEGIN{
OFS=":"
FS="_"
#tmpdir="/home/joker/Документы/icons/tmp"
browser="/usr/bin/yelp"
}
END{
extract(ARGV[1])
iconame=ARGV[1];gsub(/.*\//,"",iconame);gsub(/.[^.]+$/,"",iconame)
buildtable(iconame,tmpdir)
buildfile(iconame,tmpdir)
openfile()
#dtemp="rm -r "tmpdir
system(dtemp)
#close(dtemp)
#print ARGV[1]
#print outfile
}