Debian Codegraph @

texmf-dist/source/latex/oberdiek/flags.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: flags.dtx
4 % Version: 2016/05/16 v0.5
5 % Info: Setting/clearing of flags in bit fields
6 %
7 % Copyright (C)
8 % 2007 Heiko Oberdiek
9 % 2016-2019 Oberdiek Package Support Group
10 % https://github.com/ho-tex/oberdiek/issues
11 %
12 % This work may be distributed and/or modified under the
13 % conditions of the LaTeX Project Public License, either
14 % version 1.3c of this license or (at your option) any later
15 % version. This version of this license is in
16 % https://www.latex-project.org/lppl/lppl-1-3c.txt
17 % and the latest version of this license is in
18 % https://www.latex-project.org/lppl.txt
19 % and version 1.3 or later is part of all distributions of
20 % LaTeX version 2005/12/01 or later.
21 %
22 % This work has the LPPL maintenance status "maintained".
23 %
24 % The Current Maintainers of this work are
25 % Heiko Oberdiek and the Oberdiek Package Support Group
26 % https://github.com/ho-tex/oberdiek/issues
27 %
28 % This work consists of the main source file flags.dtx
29 % and the derived files
30 % flags.sty, flags.pdf, flags.ins, flags.drv.
31 %
32 % Distribution:
33 % CTAN:macros/latex/contrib/oberdiek/flags.dtx
34 % CTAN:macros/latex/contrib/oberdiek/flags.pdf
35 %
36 % Unpacking:
37 % (a) If flags.ins is present:
38 % tex flags.ins
39 % (b) Without flags.ins:
40 % tex flags.dtx
41 % (c) If you insist on using LaTeX
42 % latex \let\install=y\input{flags.dtx}
43 % (quote the arguments according to the demands of your shell)
44 %
45 % Documentation:
46 % (a) If flags.drv is present:
47 % latex flags.drv
48 % (b) Without flags.drv:
49 % latex flags.dtx; ...
50 % The class ltxdoc loads the configuration file ltxdoc.cfg
51 % if available. Here you can specify further options, e.g.
52 % use A4 as paper format:
53 % \PassOptionsToClass{a4paper}{article}
54 %
55 % Program calls to get the documentation (example):
56 % pdflatex flags.dtx
57 % makeindex -s gind.ist flags.idx
58 % pdflatex flags.dtx
59 % makeindex -s gind.ist flags.idx
60 % pdflatex flags.dtx
61 %
62 % Installation:
63 % TDS:tex/latex/oberdiek/flags.sty
64 % TDS:doc/latex/oberdiek/flags.pdf
65 % TDS:source/latex/oberdiek/flags.dtx
66 %
67 %<*ignore>
68 \begingroup
69 \catcode123=1 %
70 \catcode125=2 %
71 \def\x{LaTeX2e}%
72 \expandafter\endgroup
73 \ifcase 0\ifx\install y1\fi\expandafter
74 \ifx\csname processbatchFile\endcsname\relax\else1\fi
75 \ifx\fmtname\x\else 1\fi\relax
76 \else\csname fi\endcsname
77 %</ignore>
78 %<*install>
79 \input docstrip.tex
80 \Msg{************************************************************************}
81 \Msg{* Installation}
82 \Msg{* Package: flags 2016/05/16 v0.5 Setting/clearing of flags in bit fields (HO)}
83 \Msg{************************************************************************}
84
85 \keepsilent
86 \askforoverwritefalse
87
88 \let\MetaPrefix\relax
89 \preamble
90
91 This is a generated file.
92
93 Project: flags
94 Version: 2016/05/16 v0.5
95
96 Copyright (C)
97 2007 Heiko Oberdiek
98 2016-2019 Oberdiek Package Support Group
99
100 This work may be distributed and/or modified under the
101 conditions of the LaTeX Project Public License, either
102 version 1.3c of this license or (at your option) any later
103 version. This version of this license is in
104 https://www.latex-project.org/lppl/lppl-1-3c.txt
105 and the latest version of this license is in
106 https://www.latex-project.org/lppl.txt
107 and version 1.3 or later is part of all distributions of
108 LaTeX version 2005/12/01 or later.
109
110 This work has the LPPL maintenance status "maintained".
111
112 The Current Maintainers of this work are
113 Heiko Oberdiek and the Oberdiek Package Support Group
114 https://github.com/ho-tex/oberdiek/issues
115
116
117 This work consists of the main source file flags.dtx
118 and the derived files
119 flags.sty, flags.pdf, flags.ins, flags.drv.
120
121 \endpreamble
122 \let\MetaPrefix\DoubleperCent
123
124 \generate{%
125 \file{flags.ins}{\from{flags.dtx}{install}}%
126 \file{flags.drv}{\from{flags.dtx}{driver}}%
127 \usedir{tex/latex/oberdiek}%
128 \file{flags.sty}{\from{flags.dtx}{package}}%
129 }
130
131 \catcode32=13\relax% active space
132 \let =\space%
133 \Msg{************************************************************************}
134 \Msg{*}
135 \Msg{* To finish the installation you have to move the following}
136 \Msg{* file into a directory searched by TeX:}
137 \Msg{*}
138 \Msg{* flags.sty}
139 \Msg{*}
140 \Msg{* To produce the documentation run the file `flags.drv'}
141 \Msg{* through LaTeX.}
142 \Msg{*}
143 \Msg{* Happy TeXing!}
144 \Msg{*}
145 \Msg{************************************************************************}
146
147 \endbatchfile
148 %</install>
149 %<*ignore>
150 \fi
151 %</ignore>
152 %<*driver>
153 \NeedsTeXFormat{LaTeX2e}
154 \ProvidesFile{flags.drv}%
155 [2016/05/16 v0.5 Setting/clearing of flags in bit fields (HO)]%
156 \documentclass{ltxdoc}
157 \usepackage{holtxdoc}[2011/11/22]
158 \begin{document}
159 \DocInput{flags.dtx}%
160 \end{document}
161 %</driver>
162 % \fi
163 %
164 %
165 %
166 % \GetFileInfo{flags.drv}
167 %
168 % \title{The \xpackage{flags} package}
169 % \date{2016/05/16 v0.5}
170 % \author{Heiko Oberdiek\thanks
171 % {Please report any issues at \url{https://github.com/ho-tex/oberdiek/issues}}}
172 %
173 % \maketitle
174 %
175 % \begin{abstract}
176 % Package \xpackage{flags} allows the setting and clearing
177 % of flags in bit fields and converts the bit field into a
178 % decimal number. Currently the bit field is limited to 31 bits.
179 % \end{abstract}
180 %
181 % \tableofcontents
182 %
183 % \section{Documentation}
184 %
185 % A new powerful package \xpackage{bitset} is written by me
186 % and supersedes this package:
187 % \begin{itemize}
188 % \item The bit range is not restricted to 31 bits, only index
189 % numbers are objected to \TeX's number limit.
190 % \item Many more operations are available.
191 % \item No dependency of \eTeX.
192 % \end{itemize}
193 % Therefore I consider this package as obsolete and
194 % have stopped the development of this package.
195 %
196 % \subsection{User interface}
197 %
198 % Flag positions are one-based, thus the flag position must be
199 % a positive integer. Currently supported range: |1..31|
200 %
201 % \begin{declcs}{resetflags} \M{fname}
202 % \end{declcs}
203 % The bit field \meta{fname} is cleared.
204 % Currently is is also used for initialization,
205 % because a \cs{newflags} macro is not implemented.
206 %
207 % \begin{declcs}{setflag} \M{fname} \M{position}
208 % \end{declcs}
209 % The flag at bit position \meta{position} is set in the
210 % bit field \meta{fname}.
211 %
212 % \begin{declcs}{clearflag} \M{fname} \M{position}
213 % \end{declcs}
214 % The flag at bit position \meta{position} is cleared in the
215 % bit field \meta{fname}.
216 %
217 % \begin{declcs}{printflags} \M{fname}
218 % \end{declcs}
219 % The bit field \meta{fname} is converted to a decimal number.
220 % The macro is expandible.
221 %
222 % \begin{declcs}{extractflag} \M{fname} \M{position}
223 % \end{declcs}
224 % Extracts the flag setting at bit position \meta{position}.
225 % \cs{extractflag} expands to |1| if the flag is set and |0| otherwise.
226 %
227 % \begin{declcs}{queryflag} \M{fname} \M{position}
228 % \M{set part} \M{clear part}
229 % \end{declcs}
230 % It is a wrapper for \cs{extractflag}. \meta{set part} is called if
231 % \cs{extractflag} returns |1|. Otherwise \meta{clear part} is executed.
232 %
233 % \paragraph{Example.} See package \xpackage{bookmark}.
234 % It uses package \xpackage{flags} for its font style options.
235 %
236 % \subsection{Requirements}
237 %
238 % \begin{itemize}
239 % \item \eTeX\ (\cs{numexpr})
240 % \end{itemize}
241 %
242 % \subsection{ToDo}
243 %
244 % \begin{itemize}
245 % \raggedright
246 % \item Named positions.
247 % \item Setting positions by a key-value interface.
248 % \item Support for more than 31 bits while maintaining expandibility of
249 % \cs{printflags}.
250 % \item Eventually \cs{newflags}, \cs{newflagstype}.
251 % \end{itemize}
252 %
253 %
254 % \StopEventually{
255 % }
256 %
257 % \section{Implementation}
258 %
259 % \begin{macrocode}
260 %<*package>
261 \NeedsTeXFormat{LaTeX2e}
262 \ProvidesPackage{flags}%
263 [2016/05/16 v0.5 Setting/clearing of flags in bit fields (HO)]%
264 % \end{macrocode}
265 %
266 % \begin{macrocode}
267 \begingroup\expandafter\expandafter\expandafter\endgroup
268 \expandafter\ifx\csname numexpr\endcsname\relax
269 \PackageError{flags}{%
270 Missing e-TeX, package loading aborted%
271 }{%
272 This packages makes heavy use of \string\numexpr.%
273 }%
274 \expandafter\endinput
275 \fi
276 % \end{macrocode}
277 %
278 % \begin{macro}{\resetflags}
279 % \begin{macrocode}
280 \newcommand*{\resetflags}[1]{%
281 \expandafter\let\csname flags@#1\endcsname\@empty
282 }
283 % \end{macrocode}
284 % \end{macro}
285 %
286 % \begin{macro}{\printflags}
287 % Macro \cs{printflags} converts the bit field into a decimal
288 % number.
289 % \begin{macrocode}
290 \newcommand*{\printflags}[1]{%
291 \expandafter\@printflags\csname flags@#1\endcsname
292 }
293 \def\@printflags#1{%
294 \expandafter\@firstofone\expandafter{%
295 \number\numexpr
296 \ifx#1\@empty
297 0%
298 \else
299 \expandafter\@@printflags#1%
300 \fi
301 }%
302 }
303 \def\@@printflags#1#2\fi{%
304 \fi
305 #1%
306 \ifx\\#2\\%
307 \else
308 +2*\numexpr\expandafter\@@printflags#2%
309 \fi
310 }
311 % \end{macrocode}
312 % \end{macro}
313 %
314 % \begin{macro}{\setflag}
315 % \begin{macrocode}
316 \newcommand*{\setflag}[2]{%
317 \ifnum#2>\z@
318 \expandafter\@setflag\csname flags@#1\expandafter\endcsname
319 \expandafter{\romannumeral\number\numexpr#2-1\relax000}%
320 \else
321 \PackageError{flags}{Position must be a positive number}\@ehc
322 \fi
323 }
324 \def\@setflag#1#2{%
325 \ifx#1\relax
326 \let#1\@empty
327 \fi
328 \edef#1{%
329 \expandafter\@@setflag\expandafter{#1}{#2}%
330 }%
331 }
332 \def\@@setflag#1#2{%
333 \ifx\\#1\\%
334 \FLAGS@zero#2\relax
335 1%
336 \else
337 \ifx\\#2\\%
338 1\@gobble#1%
339 \else
340 \@@@setflag#1|#2%
341 \fi
342 \fi
343 }
344 \def\@@@setflag#1#2|#3#4\fi\fi{%
345 \fi\fi
346 #1%
347 \@@setflag{#2}{#4}%
348 }
349 % \end{macrocode}
350 % \end{macro}
351 %
352 % \begin{macro}{\clearflag}
353 % \begin{macrocode}
354 \newcommand*{\clearflag}[2]{%
355 \ifnum#2>\z@
356 \expandafter\@clearflag\csname flags@#1\expandafter\endcsname
357 \expandafter{\romannumeral\number\numexpr#2-1\relax000}%
358 \else
359 \PackageError{flags}{Position must be a positive number}\@ehc
360 \fi
361 }
362 \def\@clearflag#1#2{%
363 \ifx#1\relax
364 \let#1\@empty
365 \fi
366 \edef#1{%
367 \expandafter\@@clearflag\expandafter{#1}{#2}%
368 }%
369 }
370 \def\@@clearflag#1#2{%
371 \ifx\\#1\\%
372 \else
373 \ifx\\#2\\%
374 0\@gobble#1%
375 \else
376 \@@@clearflag#1|#2%
377 \fi
378 \fi
379 }
380 \def\@@@clearflag#1#2|#3#4\fi\fi{%
381 \fi\fi
382 #1%
383 \@@clearflag{#2}{#4}%
384 }
385 % \end{macrocode}
386 % \end{macro}
387 %
388 % \begin{macrocode}
389 \def\FLAGS@zero#1{%
390 \ifx#1\relax
391 \else
392 0%
393 \expandafter\FLAGS@zero
394 \fi
395 }
396 % \end{macrocode}
397 %
398 % \begin{macro}{\queryflag}
399 % \begin{macrocode}
400 \newcommand*{\queryflag}[2]{%
401 \ifnum\extractflag{#1}{#2}=\@ne
402 \expandafter\@firstoftwo
403 \else
404 \expandafter\@secondoftwo
405 \fi
406 }
407 % \end{macrocode}
408 % \end{macro}
409 %
410 % \begin{macro}{\extractflag}
411 % \begin{macrocode}
412 \newcommand*{\extractflag}[1]{%
413 \expandafter\@extractflag\csname flags@#1\endcsname
414 }
415 \def\@extractflag#1#2{%
416 \ifx#1\@undefined
417 0%
418 \else
419 \ifx#1\relax
420 0%
421 \else
422 \ifx#1\@empty
423 0%
424 \else
425 \expandafter\expandafter\expandafter\@@extractflag
426 \expandafter\expandafter\expandafter{%
427 \expandafter#1\expandafter
428 }\expandafter{%
429 \romannumeral\number\numexpr#2-1\relax000%
430 }%
431 \fi
432 \fi
433 \fi
434 }
435 \def\@@extractflag#1#2{%
436 \ifx\\#1\\%
437 0%
438 \else
439 \ifx\\#2\\%
440 \@car#1\@nil
441 \else
442 \@@@extractflag#1|#2%
443 \fi
444 \fi
445 }
446 \def\@@@extractflag#1#2|#3#4\fi\fi{%
447 \fi\fi
448 \@@extractflag{#2}{#4}%
449 }
450 % \end{macrocode}
451 % \end{macro}
452 %
453 % \begin{macrocode}
454 %</package>
455 % \end{macrocode}
456 %
457 % \section{Installation}
458 %
459 % \subsection{Download}
460 %
461 % \paragraph{Package.} This package is available on
462 % CTAN\footnote{\CTANpkg{flags}}:
463 % \begin{description}
464 % \item[\CTAN{macros/latex/contrib/oberdiek/flags.dtx}] The source file.
465 % \item[\CTAN{macros/latex/contrib/oberdiek/flags.pdf}] Documentation.
466 % \end{description}
467 %
468 %
469 % \paragraph{Bundle.} All the packages of the bundle `oberdiek'
470 % are also available in a TDS compliant ZIP archive. There
471 % the packages are already unpacked and the documentation files
472 % are generated. The files and directories obey the TDS standard.
473 % \begin{description}
474 % \item[\CTANinstall{install/macros/latex/contrib/oberdiek.tds.zip}]
475 % \end{description}
476 % \emph{TDS} refers to the standard ``A Directory Structure
477 % for \TeX\ Files'' (\CTANpkg{tds}). Directories
478 % with \xfile{texmf} in their name are usually organized this way.
479 %
480 % \subsection{Bundle installation}
481 %
482 % \paragraph{Unpacking.} Unpack the \xfile{oberdiek.tds.zip} in the
483 % TDS tree (also known as \xfile{texmf} tree) of your choice.
484 % Example (linux):
485 % \begin{quote}
486 % |unzip oberdiek.tds.zip -d ~/texmf|
487 % \end{quote}
488 %
489 % \subsection{Package installation}
490 %
491 % \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
492 % \docstrip\ archive. The files are extracted by running the
493 % \xfile{.dtx} through \plainTeX:
494 % \begin{quote}
495 % \verb|tex flags.dtx|
496 % \end{quote}
497 %
498 % \paragraph{TDS.} Now the different files must be moved into
499 % the different directories in your installation TDS tree
500 % (also known as \xfile{texmf} tree):
501 % \begin{quote}
502 % \def\t{^^A
503 % \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}}
504 % flags.sty & tex/latex/oberdiek/flags.sty\\
505 % flags.pdf & doc/latex/oberdiek/flags.pdf\\
506 % flags.dtx & source/latex/oberdiek/flags.dtx\\
507 % \end{tabular}^^A
508 % }^^A
509 % \sbox0{\t}^^A
510 % \ifdim\wd0>\linewidth
511 % \begingroup
512 % \advance\linewidth by\leftmargin
513 % \advance\linewidth by\rightmargin
514 % \edef\x{\endgroup
515 % \def\noexpand\lw{\the\linewidth}^^A
516 % }\x
517 % \def\lwbox{^^A
518 % \leavevmode
519 % \hbox to \linewidth{^^A
520 % \kern-\leftmargin\relax
521 % \hss
522 % \usebox0
523 % \hss
524 % \kern-\rightmargin\relax
525 % }^^A
526 % }^^A
527 % \ifdim\wd0>\lw
528 % \sbox0{\small\t}^^A
529 % \ifdim\wd0>\linewidth
530 % \ifdim\wd0>\lw
531 % \sbox0{\footnotesize\t}^^A
532 % \ifdim\wd0>\linewidth
533 % \ifdim\wd0>\lw
534 % \sbox0{\scriptsize\t}^^A
535 % \ifdim\wd0>\linewidth
536 % \ifdim\wd0>\lw
537 % \sbox0{\tiny\t}^^A
538 % \ifdim\wd0>\linewidth
539 % \lwbox
540 % \else
541 % \usebox0
542 % \fi
543 % \else
544 % \lwbox
545 % \fi
546 % \else
547 % \usebox0
548 % \fi
549 % \else
550 % \lwbox
551 % \fi
552 % \else
553 % \usebox0
554 % \fi
555 % \else
556 % \lwbox
557 % \fi
558 % \else
559 % \usebox0
560 % \fi
561 % \else
562 % \lwbox
563 % \fi
564 % \else
565 % \usebox0
566 % \fi
567 % \end{quote}
568 % If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
569 % TDS installing feature, then some files can already be in the right
570 % place, see the documentation of \docstrip.
571 %
572 % \subsection{Refresh file name databases}
573 %
574 % If your \TeX~distribution
575 % (\TeX\,Live, \mikTeX, \dots) relies on file name databases, you must refresh
576 % these. For example, \TeX\,Live\ users run \verb|texhash| or
577 % \verb|mktexlsr|.
578 %
579 % \subsection{Some details for the interested}
580 %
581 % \paragraph{Unpacking with \LaTeX.}
582 % The \xfile{.dtx} chooses its action depending on the format:
583 % \begin{description}
584 % \item[\plainTeX:] Run \docstrip\ and extract the files.
585 % \item[\LaTeX:] Generate the documentation.
586 % \end{description}
587 % If you insist on using \LaTeX\ for \docstrip\ (really,
588 % \docstrip\ does not need \LaTeX), then inform the autodetect routine
589 % about your intention:
590 % \begin{quote}
591 % \verb|latex \let\install=y\input{flags.dtx}|
592 % \end{quote}
593 % Do not forget to quote the argument according to the demands
594 % of your shell.
595 %
596 % \paragraph{Generating the documentation.}
597 % You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
598 % the documentation. The process can be configured by the
599 % configuration file \xfile{ltxdoc.cfg}. For instance, put this
600 % line into this file, if you want to have A4 as paper format:
601 % \begin{quote}
602 % \verb|\PassOptionsToClass{a4paper}{article}|
603 % \end{quote}
604 % An example follows how to generate the
605 % documentation with pdf\LaTeX:
606 % \begin{quote}
607 %\begin{verbatim}
608 %pdflatex flags.dtx
609 %makeindex -s gind.ist flags.idx
610 %pdflatex flags.dtx
611 %makeindex -s gind.ist flags.idx
612 %pdflatex flags.dtx
613 %\end{verbatim}
614 % \end{quote}
615 %
616 % \begin{History}
617 % \begin{Version}{2007/02/18 v0.1}
618 % \item
619 % First version.
620 % \end{Version}
621 % \begin{Version}{2007/03/07 v0.2}
622 % \item
623 % Raise an error if \eTeX\ is not detected.
624 % \end{Version}
625 % \begin{Version}{2007/03/31 v0.3}
626 % \item
627 % \cs{queryflag} and \cs{extractflag} added.
628 % \item
629 % Raise an error if position is not positive in case of
630 % \cs{setflag} and \cs{clearflag}.
631 % \end{Version}
632 % \begin{Version}{2007/09/30 v0.4}
633 % \item
634 % Package is deprecated because of new more powerful
635 % package \xpackage{bitset}.
636 % \end{Version}
637 % \begin{Version}{2016/05/16 v0.5}
638 % \item
639 % Documentation updates.
640 % \end{Version}
641 % \end{History}
642 %
643 % \PrintIndex
644 %
645 % \Finale
646 \endinput