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\startluacode
28 local format, gsub, find, match = string.format, string.gsub, string.find, string.match
29 local setmetatableindex = table.setmetatableindex
30
31 local list = { }
32 local size = { }
33 local comp = { }
34 local nope = setmetatableindex("number")
35
36 local omit = {
37 "char%-def%.lua",
38 "mult%-def%.lua", "mult%-..%.mkii", "mult%-m..%.mkii",
39 }
40 local skip = {
41 "prag%-.*%.tex", "docs%-.*.tex", "list%-.*%.tex", "test%-.*%.tex", "demo%-.*%.tex",
42 "opti%-.*%.tex", "chrt%-.*%.tex", ".*%-old", ".*%-obs", ".*%-tst", "supp%-.*%.tex",
43 "colo%-pan.tex", ".*test.*"
44 }
45 local types = {
46 "tex", "mkii", "mkiv", "mkvi", "lua", "mkxl", "mklx", "lmt"
47 }
48 local patterns = {
49 "^([a-z][a-z][a-z][a-z])%-[a-z0-9%-]+%.[a-z]+",
50 "^([xms])%-[a-z0-9%-]+%.[a-z]+",
51 }
52
53 local function collect(list,suffix,n)
54 local path = document.arguments.basepath or file.dirname(resolvers.find_file("context.mkiv"),".")
55 local pattern = path .. "/*." .. suffix .. "$"
56 local texfiles = dir.glob(pattern)
57 for i=1,#texfiles do
58 local name = texfiles[i]
59 local base = file.basename(name)
60 for p=1,#patterns do
61 local category = match(base,patterns[p])
62 if category and lfs.isfile(name) then
63 local okay = true
64 for s=1,#skip do
65 if find(base,skip[s]) then
66 okay = false
67 break
68 end
69 end
70 if okay then
71 local lm = list[category]
72 local sm = size[category]
73 local cm = comp[category]
74 if not lm then
75 lm = setmetatableindex("number")
76 sm = setmetatableindex("number")
77 cm = setmetatableindex("number")
78 list[category] = lm
79 size[category] = sm
80 comp[category] = cm
81 end
82 lm[n] = lm[n] + 1
83 local done = true
84 for o=1,#omit do
85 if find(base,omit[o]) then
86 done = false
87 break
88 end
89 end
90 local data = io.loaddata(name)
91 if data then
92 if suffix == "lua" or suffix == "lmt" then
93 data = gsub(data,"%-%-%[%[.-%]%]%-%-","")
94 data = gsub(data,"%-%-.-[\n\r]","")
95 else
96 data = gsub(data,"%%.-[\n\r]","")
97 end
98 data = gsub(data,"%s","")
99 else
100 logs.report("error","unknown file %a",name)
101 data = ""
102 end
103 sm[n+#types] = sm[n+#types] + #data
104 if done then
105 sm[n] = sm[n] + #data
106 else
107 cm[n] = cm[n] + 1
108 end
109 end
110 end
111 end
112 end
113 end
114
115 local function prepare(what)
116 if next(list) then
117
118 else
119 for i=1,#types do
120 collect(list,types[i],i)
121 end
122 end
123 local max, what = 0, (what == "size" and size) or list
124 for k, v in table.sortedpairs(what) do
125 for i=1,7 do if v[i] > max then max = v[i] end end
126 end
127 return max, what, function(n) return (max == 0 and 0) or (n == 0 and 0) or n/max end
128 end
129
130 local f_norm = string.formatters["%0.3f"]
131
132 function document.context_state_1(what)
133 local max, what, norm = prepare(what)
134 context.starttabulate { "|Tl|T|T|T|T|T|T|T|T|" }
135 context.NC()
136 context("category")
137 context.NC()
138 for i=1,#types do
139 local n, m = 0, 0
140 for k, v in next, list do
141 local nn = what[k][i]
142 local mm = what[k][i+#types]
143 n = n + nn
144 m = m + (mm or nn)
145 end
146 context.Top(types[i],norm(max),n,m)
147 context.NC()
148 end
149
150 context.NR()
151 context.HL()
152 for k, v in table.sortedpairs(what) do
153 local c = what == size and comp[k] or nope
154 context.NC()
155 context(k)
156 context.NC()
157 for i=1,#types do
158 context.Bar(types[i],v[i],c[i],f_norm(norm(v[i])))
159 context.NC()
160 end
161 context.NR()
162 end
163 context.stoptabulate()
164 end
165
166 function document.context_state_2(what)
167 local max, what, norm = prepare(what)
168 for k, v in table.sortedpairs(what) do
169 local c = (what == size and comp[k]) or nope
170 context.StartUp(k)
171 for i=1,#types do
172 context.Up(types[i],f_norm(norm(v[i])))
173 end
174 context.StopUp()
175 end
176 end
177
178\stopluacode
179
180\definecolor[bar:tex] [middlegreen]
181\definecolor[bar:mkii][middleblue]
182\definecolor[bar:mkiv][middlered]
183\definecolor[bar:mkvi][middleyellow]
184\definecolor[bar:mkxl][middlemagenta]
185\definecolor[bar:mklx][middlecyan]
186\definecolor[bar:lua] [middlegray]
187\definecolor[bar:lmt] [middleorange]
188
189\newcount\UpCounter
190
191\starttexdefinition Top #what#fraction#total#bigones
192 \hbox to 7em{\hss#total}
193 \enspace
194 \hbox to 4em{{{\bf#what}\ifnum#total=#bigones\else\ifnum#bigones>0#bigones\rlap{}\fi\fi\hss}}
195\stoptexdefinition
196
197\starttexdefinition Bar #color#size#nobigones#fraction
198 \ifcase#size\else
199 \hbox to 7em{\hss\ifcase#nobigones\else\llap{}\fi#size}
200 \enspace
201 \blackrule[color=bar:#color,width=#fraction\dimexpr 20em\relax,height=.8\strutht]
202
203
204 \fi
205\stoptexdefinition
206
207\starttexdefinition StartUp #name
208 \def\UpName{#name}
209 \dontleavehmode\framed[frame=off,align={middle,low},height=18em]\bgroup
210\stoptexdefinition
211
212\starttexdefinition StopUp
213 \par\nointerlineskip\blackrule[height=1pt,width=7em,depth=0pt,color=darkgray]
214 \par\tttf\strut\UpName\par
215 \egroup
216 \ifnum\UpCounter=17
217 \par \UpCounter\zerocount
218 \else
219 \kern1em \advance\UpCounter\plusone
220 \fi
221\stoptexdefinition
222
223\starttexdefinition Up #color#width
224
225 \scratchdimen#width\dimexpr 40em\relax
226 \ifdim\scratchdimen=\zeropoint
227 \kern1em
228 \else\ifdim\scratchdimen>13em
229 \blackrule[color=bar:#color,height=15em,width=1em]
230 \hskip1.1em
231 \blackrule[color=white,height=14em,width=1.2em]
232 \hskip1.1em
233 \blackrule[color=bar:#color,height=13em,width=1em]
234 \else
235 \ifdim\scratchdimen<\onepoint \scratchdimen\onepoint \fi
236 \blackrule[color=bar:#color,height=\scratchdimen,width=1em]
237 \fi\fi
238\stoptexdefinition
239
240\starttexdefinition Show #title#how#what
241 \startTEXpage[offset=1em,width=fit]
242 \hbox{\tttf\strut\currentdate#title}
243 \blank[line]
244 \ctxlua{document.context_state_\number#how("#what")}
245 \stopTEXpage
246\stoptexdefinition
247
248
249
250\starttext
251 \Show
252 {The number of files used in ConTeXt (base modules and styles).}
253 {1}{number}
254 \Show
255 {The size of (core) files used in ConTeXt ( : large data files excluded; : large data files included; comment and spaces removed)}
256 {1}{size}
257 \Show
258 {The relative number of files used in ConTeXt (tex, mkii, mkiv, mkvi, mkxl, mklx, lua, lmt).}
259 {2}{number}
260 \Show
261 {The relative size of files used in ConTeXt (tex, mkii, mkiv, mkvi, mkxl, mklx, lua, lmt).}
262 {2}{size}
263\stoptext
264 |