|
| 1 | +#!/usr/bin/gawk -f |
| 2 | + |
| 3 | +## |
| 4 | + |
| 5 | + |
| 6 | +@load "filefuncs" |
| 7 | +@load "gd" |
| 8 | +@load "readfile" |
| 9 | +@load "readdir" |
| 10 | +@include "arraytree" |
| 11 | + |
| 12 | +function find( path, names, names_ar, |
| 13 | + IMG_X, IMG_Y){ |
| 14 | +split(names,names_ar) |
| 15 | +for(n in names_ar){ |
| 16 | +names_n[names_ar[n]]=names_ar[n] |
| 17 | +} |
| 18 | + |
| 19 | +fs=FS |
| 20 | +FS="/" |
| 21 | +while((getline < path)>0){ |
| 22 | + |
| 23 | +#print path " " $2 " " $3 |
| 24 | + |
| 25 | +fname=gensub(/\.[^.]*$/,"",1,$2) |
| 26 | + |
| 27 | +if($3=="d" && $2!~/^\.+$/){ |
| 28 | +find(path"/"$2,names) |
| 29 | + |
| 30 | +}else{ |
| 31 | +if($3~/(f|l)/ && fname in names_n){ |
| 32 | +IMG_DST=gdImageCreateFromFile(path"/"$2) |
| 33 | +IMG_X=gdImageSX(IMG_DST) |
| 34 | +IMG_Y=gdImageSY(IMG_DST) |
| 35 | +if(IMG_DST && IMG_X==IMG_Y){ |
| 36 | + |
| 37 | +icons[fname][IMG_X]=gensub(/^\//,"",1,gensub(pwd,"",1,path))"/"$2 |
| 38 | +#print "icons["fname"]["IMG_X"]="icons[fname][IMG_X] |
| 39 | +#print "icons["name"]["IMG_X"]=" gensub(/^\//,"",1,gensub(pwd,"",1,path))"/"$2 |
| 40 | +#print gensub(/^\//,"",1,gensub(pwd,"",1,path))"/"$2,IMG_X " x " IMG_Y,rel |
| 41 | +gdImageDestroy(IMG_DST) |
| 42 | +} |
| 43 | +} |
| 44 | +} |
| 45 | + |
| 46 | +} |
| 47 | +FS=fs |
| 48 | + |
| 49 | +} |
| 50 | + |
| 51 | + |
| 52 | +function tbl( names, sizes, names_a,sizes_a){ |
| 53 | + |
| 54 | +split(names,names_a) |
| 55 | +split(sizes,sizes_a) |
| 56 | + |
| 57 | +for(n in names_a){ |
| 58 | +#print names_a[n] |
| 59 | +if(names_a[n]){names_n[names_a[n]]=names_a[n]} |
| 60 | + |
| 61 | +find(pwd,names) |
| 62 | + |
| 63 | +#find(pwd,names_n[names_a[n]]) |
| 64 | +for(s in sizes_a){ |
| 65 | +sizes_n[sizes_a[s]]=sizes_a[s] |
| 66 | +#print "icons["n"]["sizes_a[s]"]" |
| 67 | +#printf names_a[n] " " sizes_a[s] " " |
| 68 | +} |
| 69 | +#print "" |
| 70 | +} |
| 71 | + |
| 72 | +if(length(names_n)>1 && names in names_n){delete names_n[names]} |
| 73 | + |
| 74 | +print "*Built by [MDTable.awk](https://github.com/nestoris/scripts-for-Icon-theming/blob/main/icontable.awk)*\n" > outfile |
| 75 | +if(!ARGV[5]){printf "| " > outfile} |
| 76 | +for(s in sizes_a){ |
| 77 | +printf "|**"sizes_a[s]"x"sizes_a[s]"**" > outfile |
| 78 | +} |
| 79 | +print "|" > outfile |
| 80 | +if(!ARGV[5]){printf "|-" > outfile} |
| 81 | +for(s in sizes_a){ |
| 82 | +printf "|-" > outfile |
| 83 | +} |
| 84 | +print "|" > outfile |
| 85 | + |
| 86 | +##печатаем строки |
| 87 | +for(n in names_a){ |
| 88 | +if(names_a[n]~/^$/){delete names_a[n]} |
| 89 | +#printf "|**"toupper(substr(names_a[n],1,1)) substr(names_a[n],2)"**" |
| 90 | +if(!ARGV[5]){printf "|**"names_a[n]"**" > outfile} |
| 91 | +for(s in sizes_a){ |
| 92 | +#print "<<<"n">>>" |
| 93 | +#print sizes_a[s] |
| 94 | +#print icons[names_a[n]][sizes_a[s]] |
| 95 | +printf "|%s", "" > outfile |
| 96 | + |
| 97 | +} |
| 98 | +print "|" > outfile |
| 99 | + |
| 100 | +} |
| 101 | + |
| 102 | +fs=FS |
| 103 | +FS="/" |
| 104 | + |
| 105 | + |
| 106 | +FS=fs |
| 107 | + |
| 108 | +} |
| 109 | + |
| 110 | +function r_descript(file, out){ # read names and descriptions of icons |
| 111 | + |
| 112 | +fs=FS |
| 113 | +FS=" " |
| 114 | +while((getline<file)>0){ |
| 115 | +#print $1 |
| 116 | +#arr[$1]=$2 |
| 117 | +out=out (out?" ":"") $1 |
| 118 | +} |
| 119 | +FS=fs |
| 120 | +return out |
| 121 | +} |
| 122 | + |
| 123 | +function checkargs(arg1,arg2,arg3 ,status, statdata){ |
| 124 | +status=stat(arg1,statdata) |
| 125 | +if(statdata["type"]!="directory"){hq_a[1]=1} |
| 126 | + |
| 127 | +status=stat(arg2,statdata) |
| 128 | +if(statdata["type"]=="directory"){hq_a[2]=2} |
| 129 | + |
| 130 | +status=stat(arg3,statdata) |
| 131 | +if(statdata["type"]=="directory"){hq_a[3]=3} |
| 132 | + |
| 133 | +helpquit(hq_a) |
| 134 | +} |
| 135 | + |
| 136 | +function helpquit(hq_a, m, msg){ |
| 137 | + |
| 138 | +for(m in hq_a){ |
| 139 | +if(m==1){print "First argument must be a directory"} |
| 140 | +if(m==2){print "Second argument cannot be a directory"} |
| 141 | +if(m==3){print "Second argument cannot be a directory"} |
| 142 | + |
| 143 | +#msg=msg msg?"\n":"" (m==1?"First argument must be a directory":m==2?"Second argument cannot be a folder":m==3?"Second argument cannot be a folder":"") |
| 144 | + |
| 145 | +} |
| 146 | + |
| 147 | +if(length(hq_a)>0){ |
| 148 | +("ps -p " PROCINFO["pid"] " -o comm=") | getline CMDNAME |
| 149 | +print "Syntax:\n\t" CMDNAME " <PATH> <NAME_LIST_FILE> <SIZE_LIST_FILE> [OUTPUT_FILE]" |
| 150 | +exit -1 |
| 151 | +} |
| 152 | +} |
| 153 | + |
| 154 | +BEGIN{ |
| 155 | +checkargs(ARGV[1],ARGV[2],ARGV[3]) |
| 156 | +print ARGV[1] |
| 157 | +#if(isarray(hq_a)){print "aaa"}else{print "ddd"} |
| 158 | +if(!ARGV[1]){ |
| 159 | +#delete ARGV |
| 160 | +helpquit() |
| 161 | +} |
| 162 | +pwd=ARGV[1]?ARGV[1]:ENVIRON["PWD"] |
| 163 | +#pwd="/home/joker/Документы/GitHub/Win98SE/SE98" |
| 164 | +#pwd="/home/joker/Документы/GitHub/Win98SE" |
| 165 | +names_f=ARGV[2]?ARGV[2]:"names" |
| 166 | +sizes_f=ARGV[3]?ARGV[3]:"sizes" |
| 167 | +outfile=ARGV[4]?ARGV[4]:"/dev/stdout" |
| 168 | + |
| 169 | +#nmz=readfile(names_f) |
| 170 | +nmz=r_descript(names_f) |
| 171 | + |
| 172 | +gsub("\n"," ",nmz) |
| 173 | +gsub(/[ ]+/," ",nmz) |
| 174 | +szz=readfile(sizes_f) |
| 175 | +gsub("\n"," ",szz) |
| 176 | + |
| 177 | +#print nmz |
| 178 | +tbl(nmz,szz) |
| 179 | +#tbl("computer folder catfish","48 32") |
| 180 | +#arraytree(icons,"icons") |
| 181 | + |
| 182 | +#find(".","computer.png",pwd) |
| 183 | +#find(pwd,"computer") |
| 184 | + |
| 185 | +} |
0 commit comments