summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/regstats/regstats.sty
blob: 1d585979964743bf7ff9ec1d6d0f008986450907 (plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
%%
%% This is file `regstats.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% regstats.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Project: regstats
%% Version: 2012/01/07 v1.0h
%% 
%% Copyright (C) 2011 - 2012 by
%%     H.-Martin M"unch <Martin dot Muench at Uni-Bonn dot de>
%% 
%% The usual disclaimer applies:
%% If it doesn't work right that's your problem.
%% (Nevertheless, send an e-mail to the maintainer
%%  when you find an error in this package.)
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. This version of this license is in
%%    http://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is H.-Martin Muench.
%% 
%% This work consists of the main source file regstats.dtx,
%% the README, and the derived files
%%    regstats.sty, regstats.pdf,
%%    regstats.ins, regstats.drv,
%%    regstats-example.tex, regstats-example.pdf,
%%    regstats-example.log.
%% 
\NeedsTeXFormat{LaTeX2e}[2011/06/27]
\ProvidesPackage{regstats}[2012/01/07 v1.0h
              Counting used registers (HMM)]

%% Allows to count the number of used registers
%% (counter, dimen, skip, muskip, box, token, input, output,
%%  math families, languages, insertions)
%% and compare these to the maximum available number of such registers.

\RequirePackage{kvoptions}[2010/12/23]% v3.10
\RequirePackage{atveryend}[2011/06/30]% v1.8
\RequirePackage{ltxcmds}[2011/04/18]%   v1.20

%% regstats may work with earlier versions of LaTeX and these
%% packages, but this was not tested. Please consider updating
%% your LaTeX and packages to the most recent version
%% (if they are not already the most recent version).

\SetupKeyvalOptions{family=regstats,prefix=regstats@}
\DeclareBoolOption{proof}% \regstats@proof
\DeclareBoolOption{left}
\DeclareBoolOption{timer}

\ProcessKeyvalOptions*

\ifregstats@proof
  \PackageInfo{regstats}{%
    This package will use one of each kind of register itself!%
    \MessageBreak%
    (And other packages used by this package\MessageBreak%
    probably use additional resources,\MessageBreak%
    if those packages are not used anyway.)\MessageBreak%
   }
\else
  \PackageInfo{regstats}{%
    This package will not use registers itself,\MessageBreak%
    but packages used by this package\MessageBreak%
    (and packages loaded by those packages)\MessageBreak%
    use additional resources,\MessageBreak%
    if those packages are not used anyway.\MessageBreak%
   }
\fi

\ifregstats@timer
  \RequirePackage{intcalc}[2007/09/27]%  v1.1
  \RequirePackage{ifluatex}[2010/03/01]% v1.3
  \RequirePackage{ifpdf}[2011/01/30]%    v2.3
\fi

\newcommand{\regst@ts@timer}{%
  \message{^^J}
  \ifluatex
    \@tempcnta=%
      \directlua{
        if starttime then
          tex.sprint((os.clock()-starttime)*65536)
        else
          tex.sprint(0)
        end
       }\relax
    \ifnum \the\@tempcnta = 0
      \PackageError{regstats}{Did you forget to start the timer?}{%
        Before \string\documentclass\space you need to say%
        \MessageBreak%
        \string\directlua{starttime = os.clock()} \MessageBreak%
       }
    \fi
  \else
    \ifpdf
      \@tempcnta=\the\pdfelapsedtime\relax
    \else
      \PackageError{regstats}{Option timer only works with pdf(la)tex%
        \MessageBreak%
        and with lua(la)tex}{%
        Neither appear to be used here. Announced compilation time %
        will be zero.
       }
      \@tempcnta=0\relax
    \fi
  \fi
  \edef\regstatselapsedtime{\the\@tempcnta}
  \divide \@tempcnta by 65536% scaledseconds -> seconds
  \edef\regstatsseconds{\the\@tempcnta}
  \ifnum \regstatsseconds > 59
    \edef\regstatsseconds{\intcalcMod{\the\@tempcnta}{60}}
    \divide \@tempcnta by 60% seconds -> minutes
  \else
    \@tempcnta=0\relax% minutes = 0
  \fi
  \ifnum \regstatsseconds < 10
    \message{Time elapsed for the last compiler run:^^J%
      about \the\@tempcnta:0\regstatsseconds\space%
      (m:ss; \regstatselapsedtime /65536 s).^^J}
  \else
    \message{Time elapsed for the last compiler run:^^J%
      about \the\@tempcnta:\regstatsseconds \space%
      (m:ss; \regstatselapsedtime /65536 s).^^J}
  \fi
  }

\ifregstats@timer
\else
\renewcommand{\regst@ts@timer}{\relax}
\fi

\let\regst@ts@statistics\AtVeryVeryEnd%

\@ifl@t@r\fmtversion{2011/06/27}% or possibly even newer
{\@ifpackagelater{atveryend}{2011/06/29}%
 {% 2011/06/30, v1.8, or even more recent: OK
 }{% else: older package version, no \AtVeryVeryEnd
   \let\regst@ts@statistics\ltx@firstofone%
 }
}{% else: older fmtversion: OK
}

\AtBeginDocument{%
 \AtEndDocument{%
  \BeforeClearDocument{%
   \AfterLastShipout{%
    \AtVeryEndDocument{%
     \AtEndAfterFileList{%
      \ltx@ifclassloaded{seminar}{% no \AtVeryVeryEnd
        \let\regst@ts@statistics\ltx@firstofone%
       }{% else
         \ltx@ifpackageloaded{slidesec}{% no \AtVeryVeryEnd
           \let\regst@ts@statistics\ltx@firstofone%
          }{% else: OK
          }%
       }%
      \regst@ts@statistics{%
        \ltx@ifpackageloaded{etex}{%
          \PackageInfo{regstats}{e-TeX-package found.}
        }{% else
          \PackageWarning{regstats}{Could not find the e-TeX-package.%
            \MessageBreak%
            That can mean that e-TeX was disabled or\MessageBreak%
            that your distribution of TeX does not contain e-TeX%
            \MessageBreak%
            or that you simply forgot to say \string\usepackage{etex}%
            \MessageBreak%
            in the preamble of \jobname.tex.\MessageBreak%
            The number of available counter, dimen, skip,\MessageBreak%
            muskip, box, and toks registers as well as the\MessageBreak%
            number of insertions would be larger when using%
            \MessageBreak%
            the e-TeX-package.%
           }
        }
        \def\regstats@lft{}%
        \newcommand{\regstats@regstat}[5]{%
          \@tempcnta=#1 \relax
          \ifnum \the\@tempcnta = 0
            \@tempcnta=2 \relax
          \fi
          \ifnum \the\@tempcnta > 1
            \gdef\regstats@pl{#3}
          \else
            \gdef\regstats@pl{#2}
          \fi
          \ltx@ifpackageloaded{etex}{\edef\regstats@max{#5}}{%
            \edef\regstats@max{#4}}
          \ifregstats@left
            \@tempcnta=\regstats@max \relax
            \advance\@tempcnta by -#1%
            \ifnum \the\@tempcnta > 0
              \edef\regstats@lft{, left: \the\@tempcnta}
            \else
              \ifnum \the\@tempcnta = 0
                \edef\regstats@lft{, left: \the\@tempcnta !!!}
              \else% \the\@tempcnta < 0
                \edef\regstats@lft{, left: \the\@tempcnta **********}
              \fi
            \fi
          \fi
         }
        \ifregstats@proof
          \PackageWarning{regstats}{%
            Package regstats loaded with option 'proof'.\MessageBreak%
            This package itself will now use\MessageBreak%
             one of each register for testing!\MessageBreak%
            }%
          \def\regstats@proof{1}
          \newcounter{regstatscount}
          \edef\regstats@counter{\the\allocationnumber}
          \edef\regstats@test{\the\count10}
          \ifx\regstats@counter\regstats@test
          \else
            \message{Discrepancy when counting count registers.^^J}
            \def\regstats@proof{0}
          \fi
          \newdimen{\regstatsdimen}
          \edef\regstats@dimen{\the\allocationnumber}
          \edef\regstats@test{\the\count11}
          \ifx\regstats@dimen\regstats@test
          \else
            \message{Discrepancy when counting dimen registers.^^J}
            \def\regstats@proof{0}
          \fi
          \newskip\regstatsskip
          \edef\regstats@skip{\the\allocationnumber}
          \edef\regstats@test{\the\count12}
          \ifx\regstats@skip\regstats@test
          \else
            \message{Discrepancy when counting skip registers.^^J}
            \def\regstats@proof{0}
          \fi
          \newmuskip\regstatsmuskip
          \edef\regstats@muskip{\the\allocationnumber}
          \edef\regstats@test{\the\count13}
          \ifx\regstats@muskip\regstats@test
          \else
            \message{Discrepancy when counting muskip registers.^^J}
            \def\regstats@proof{0}
          \fi
          \newbox\regstatsbox
          \edef\regstats@box{\the\allocationnumber}
          \edef\regstats@test{\the\count14}
          \ifx\regstats@box\regstats@test
          \else
            \message{Discrepancy when counting box registers.^^J}
            \def\regstats@proof{0}
          \fi
          \newtoks\regstatstoks
          \edef\regstats@toks{\the\allocationnumber}
          \edef\regstats@test{\the\count15}
          \ifx\regstats@toks\regstats@test
          \else
            \message{Discrepancy when counting toks registers.^^J}
            \def\regstats@proof{0}
          \fi
          \newread\regstatsread
          \edef\regstats@read{\the\allocationnumber}
          \edef\regstats@test{\the\count16}
          \ifx\regstats@read\regstats@test
          \else
            \message{Discrepancy when counting read registers.^^J}
            \def\regstats@proof{0}
          \fi
          \newwrite\regstatswrite
          \edef\regstats@write{\the\allocationnumber}
          \edef\regstats@test{\the\count17}
          \ifx\regstats@write\regstats@test
          \else
            \message{Discrepancy when counting write registers.^^J}
            \def\regstats@proof{0}
          \fi
          \newfam\regstatsfam
          \edef\regstats@fam{\the\allocationnumber}
          \edef\regstats@test{\the\count18}
          \ifx\regstats@fam\regstats@test
          \else
            \message{Discrepancy when counting fam registers.^^J}
            \def\regstats@proof{0}
          \fi
          \newlanguage\regstatslanguage
          \edef\regstats@language{\the\allocationnumber}
          \edef\regstats@test{\the\count19}
          \ifx\regstats@language\regstats@test
          \else
            \message{Discrepancy when counting language registers.^^J}
            \def\regstats@proof{0}
          \fi
          \newinsert\regstatsinsert
          \edef\regstats@insert{\the\allocationnumber}
          \edef\regstats@test{\the\count20}
          \ifx\regstats@insert\regstats@test
          \else
            \message{Discrepancy when counting insert registers.^^J}
            \def\regstats@proof{0}
          \fi
        \edef\regstats@test{0}
        \ifx\regstats@proof\regstats@test
          \message{Regstats test for register numbers failed.^^J}
          \message{Therefore option 'proof' is necessary to get the %
                   right numbers.^^J}
        \fi
      \else
        \edef\regstats@counter{\the\count10}
        \edef\regstats@dimen{\the\count11}
        \edef\regstats@skip{\the\count12}
        \edef\regstats@muskip{\the\count13}
        \edef\regstats@box{\the\count14}
        \edef\regstats@toks{\the\count15}
        \edef\regstats@read{\the\count16}
        \edef\regstats@write{\the\count17}
        \edef\regstats@fam{\the\count18}
        \edef\regstats@language{\the\count19}
        \edef\regstats@insert{\the\count20}
      \fi
      \@tempcnta = 233 \relax
      \advance\@tempcnta by -\regstats@insert%
      \advance\@tempcnta by +1%
      \edef\regstats@insert{\the\@tempcnta}
      \message{^^J}
      \message{Here is how much of TeX's registers you used^^J}%
      \message{\space (numbers of available registers are estimated!):^^J}%
      \regstats@regstat{\regstats@counter}{}{s}{233}{32767}
      \message{ \regstats@counter\space  counter register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@dimen}{}{s}{233}{32767}
      \message{ \regstats@dimen\space    dimen   register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@skip}{}{s}{233}{32767}
      \message{ \regstats@skip\space     skip    register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@muskip}{}{s}{255}{32767}
      \message{ \regstats@muskip\space   muskip  register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@box}{}{s}{233}{32767}
      \message{ \regstats@box\space      box     register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@toks}{}{s}{255}{32767}
      \message{ \regstats@toks\space     toks    register\regstats@pl\space      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@read}{}{s}{15}{15}
      \message{ \regstats@read\space     input stream\regstats@pl\space (read)   out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@write}{}{s}{15}{15}
      \message{ \regstats@write\space    output stream\regstats@pl\space (write) out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@fam}{y}{ies}{15}{15}
      \message{ \regstats@fam\space      math famil\regstats@pl\space (fam)      out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@language}{}{s}{255}{255}
      \message{ \regstats@language\space language code\regstats@pl\space         out of \regstats@max \regstats@lft ^^J}
      \regstats@regstat{\regstats@insert}{}{s}{101}{124}
      \message{ \regstats@insert\space   insertion\regstats@pl\space             out of \regstats@max \regstats@lft ^^J}
      \regst@ts@timer
      }%
     }%
    }%
   }%
  }%
 }%
}

\endinput
%%
%% End of file `regstats.sty'.