blob: 95a2b746f197246217315609bf2d702dd7f2fab2 (
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
|
%%
%% This is file `fifo-stack.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% fifo-stack.dtx (with options: `package')
%%
%% Copyright (C) 2014 Stephen Gaito (PerceptiSys Ltd)
%%
%% This work may be distributed and/or modified under the conditions of the LaTeX
%% Project Public License, either version 1.3 of this license or (at your
%% option) any later version.
%%
%% The latest version of this license is in http://www.latex-project.org/lppl.txt
%% and version 1.3 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 Stephen Gaito.
%%
%% The released source can be found at:
%% https://github.com/diSimplex/latexFifoStack/tree/master/texStyle
%%
%% The development source can be found at:
%% https://github.com/stephengaito/latexFifoStack/tree/master/texStyle
%%
%% This work consists of the files fifo-stack.dtx, and fifo-stack.ins.
%%
%% The command:
%% pdflatex fifo-stack.ins
%% followed by:
%% pdflatex fifo-stack.dtx
%% will produce the derived files: fifo-stack.sty, fifo-stack-test.tex,
%% and fifo-stack.pdf.
%%
%% The command:
%% pdflatex fifo-stack-test.tex
%% will regression test the fifo-stack package. Output will be found in
%% fifo-stack-test.lgout. If pdflatex completes with no errors, then all
%% regression tests passed.
%%
\ProvidesPackage{fifo-stack}[2014/03/24 v1.0 Multi-FIFO/stack system]
\RequirePackage{ifthen}
\newcount\tmp@fifo@stack@top
\newcount\tmp@fifo@stack@bottom
\newcount\tmp@fifo@stack@size
\global\def\fifo@stack@pointer#1{%
\ifnum#1<0
@\expandafter\romannumeral\numexpr -1*#1 \relax
\else
\expandafter\romannumeral\numexpr #1+1 \relax
\fi
}
\newcommand\FSCreate[2]{%
\expandafter\gdef\csname #1@fifo@stack@count@top\endcsname{0}%
\expandafter\gdef\csname #1@fifo@stack@count@bottom\endcsname{1}%
\expandafter\gdef\csname #1@fifo@stack@count@size\endcsname{0}%
\expandafter\do@fifo@stack@top@macro%
\csname #1@fifo@stack@count@top\endcsname{#1}{#2}%
\expandafter\do@fifo@stack@bottom@macro%
\csname #1@fifo@stack@count@bottom\endcsname{#1}{#2}%
}
\newcommand\do@fifo@stack@top@macro[3]{%
\expandafter\newcommand\expandafter*%
\csname fifo@stack@top@#2\endcsname{%
\expandafter\ifx\csname #2@\fifo@stack@pointer#1\endcsname\relax
#3%
\else
\csname #2@\fifo@stack@pointer#1\endcsname
\fi
}%
}
\newcommand\do@fifo@stack@bottom@macro[3]{%
\expandafter\newcommand\expandafter*%
\csname fifo@stack@bottom@#2\endcsname{%
\expandafter\ifx\csname #2@\fifo@stack@pointer#1\endcsname\relax
#3%
\else
\csname #2@\fifo@stack@pointer#1\endcsname
\fi
}%
}
\newcommand{\FSClear}[1]{%
\whiledo{0 < \FSSize{#1}}{\FSPop{#1}}
}
\newcommand{\FSDestroy}[1]{%
\FSClear{#1}
\expandafter\global\expandafter\let
\csname #1@fifo@stack@count@top\endcsname=
\fifo@stack@never@defined\relax
\expandafter\global\expandafter\let
\csname #1@fifo@stack@count@bottom\endcsname=
\fifo@stack@never@defined\relax
\expandafter\global\expandafter\let
\csname #1@fifo@stack@count@size\endcsname=
\fifo@stack@never@defined\relax
\expandafter\global\expandafter\let
\csname fifo@stack@top@#1\endcsname=
\fifo@stack@never@defined\relax
\expandafter\global\expandafter\let
\csname fifo@stack@bottom@#1\endcsname=
\fifo@stack@never@defined\relax
}
\newcommand\FSTop[1]{%
\ifx\csname #1@fifo@stack@count@top\endcsname\relax
\PackageError{fifo-stack}{Undefined FIFO/stack #1}%
{You should first create the FIFO/stack with \FSCreate}%
\else
\csname fifo@stack@top@#1\endcsname
\fi
}
\newcommand\FSPush[2]{%
\ifx\csname #1@fifo@stack@count@top\endcsname\relax
\PackageError{fifo-stack}{Undefined FIFO/stack #1}%
{You should first create the FIFO/stack with \FSCreate}%
\else
\edef\fifo@stack@newtop{#2}%
\tmp@fifo@stack@top\csname #1@fifo@stack@count@top\endcsname\relax
\global\advance\tmp@fifo@stack@top by 1\relax
\expandafter\xdef\csname #1@fifo@stack@count@top\endcsname
{\the\tmp@fifo@stack@top}%
\tmp@fifo@stack@size\csname #1@fifo@stack@count@size\endcsname\relax
\global\advance\tmp@fifo@stack@size by 1\relax
\expandafter\xdef\csname #1@fifo@stack@count@size\endcsname
{\the\tmp@fifo@stack@size}%
\expandafter\xdef\csname #1@\fifo@stack@pointer\tmp@fifo@stack@top\endcsname
{\fifo@stack@newtop}%
\fi
}
\newcommand\FSPop[1]{%
\ifx\csname #1@fifo@stack@count@top\endcsname\relax
\PackageError{fifo-stack}{Undefined FIFO/stack #1}%
{You should first create the FIFO/stack with \FSCreate}%
\else
\tmp@fifo@stack@top\csname #1@fifo@stack@count@top\endcsname\relax
\tmp@fifo@stack@bottom\csname #1@fifo@stack@count@bottom\endcsname\relax
\ifnum\tmp@fifo@stack@top<\tmp@fifo@stack@bottom\relax\else
\expandafter\global\expandafter\let
\csname #1@\fifo@stack@pointer\tmp@fifo@stack@top\endcsname=
\fifo@stack@never@defined\relax
\advance\tmp@fifo@stack@top by -1\relax
\expandafter\xdef\csname #1@fifo@stack@count@top\endcsname
{\the\tmp@fifo@stack@top}%
\tmp@fifo@stack@size\csname #1@fifo@stack@count@size\endcsname\relax
\global\advance\tmp@fifo@stack@size by -1\relax
\expandafter\xdef\csname #1@fifo@stack@count@size\endcsname
{\the\tmp@fifo@stack@size}%
\fi
\fi
}
\newcommand\FSShowTop[1]{%
{\edef\fifo@stack@top{\FSTop{#1}}%
\typeout{The top of #1: \fifo@stack@top}}}
\newcommand\FSBottom[1]{%
\ifx\csname #1@fifo@stack@count@bottom\endcsname\relax
\PackageError{fifo-stack}{Undefined FIFO/stack #1}%
{You should first create the FIFO/stack with \FSCreate}%
\else
\csname fifo@stack@bottom@#1\endcsname
\fi
}
\newcommand\FSUnshift[2]{%
\ifx\csname #1@fifo@stack@count@bottom\endcsname\relax
\PackageError{fifo-stack}{Undefined FIFO/stack #1}%
{You should first create the FIFO/stack with \FSCreate}%
\else
\edef\fifo@stack@newBottom{#2}%
\tmp@fifo@stack@bottom\csname #1@fifo@stack@count@bottom\endcsname\relax
\global\advance\tmp@fifo@stack@bottom by -1\relax
\expandafter\xdef\csname #1@fifo@stack@count@bottom\endcsname
{\the\tmp@fifo@stack@bottom}%
\tmp@fifo@stack@size\csname #1@fifo@stack@count@size\endcsname\relax
\global\advance\tmp@fifo@stack@size by 1\relax
\expandafter\xdef\csname #1@fifo@stack@count@size\endcsname
{\the\tmp@fifo@stack@size}%
\expandafter\xdef\csname #1@\fifo@stack@pointer\tmp@fifo@stack@bottom\endcsname
{\fifo@stack@newBottom}%
\fi
}
\newcommand\FSShift[1]{%
\ifx\csname #1@fifo@stack@count@bottom\endcsname\relax
\PackageError{fifo-stack}{Undefined FIFO/stack #1}%
{You should first create the FIFO/stack with \FSCreate}%
\else
\tmp@fifo@stack@top\csname #1@fifo@stack@count@top\endcsname\relax
\tmp@fifo@stack@bottom\csname #1@fifo@stack@count@bottom\endcsname\relax
\ifnum\tmp@fifo@stack@top<\tmp@fifo@stack@bottom\relax\else
\expandafter\global\expandafter\let
\csname #1@\fifo@stack@pointer\tmp@fifo@stack@bottom\endcsname=
\fifo@stack@never@defined\relax
\advance\tmp@fifo@stack@bottom by 1\relax
\expandafter\xdef\csname #1@fifo@stack@count@bottom\endcsname
{\the\tmp@fifo@stack@bottom}%
\tmp@fifo@stack@size\csname #1@fifo@stack@count@size\endcsname\relax
\global\advance\tmp@fifo@stack@size by -1\relax
\expandafter\xdef\csname #1@fifo@stack@count@size\endcsname
{\the\tmp@fifo@stack@size}%
\fi
\fi
}
\newcommand\FSShowBottom[1]{%
{\edef\fifo@stack@bottom{\FSBottom{#1}}%
\typeout{The bottom of #1: \fifo@stack@bottom}}}
\newcommand\FSSize[1]{\csname #1@fifo@stack@count@size\endcsname}
\endinput
%%
%% End of file `fifo-stack.sty'.
|