remove bee2-selectmap/.svn
[fleet.git] / doc / bytefield.sty
1 %%
2 %% This is file `bytefield.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% bytefield.dtx  (with options: `package')
8 %% 
9 %% This is a generated file.
10 %% 
11 %% Copyright (C) 2005 by Scott Pakin <scott+bf@pakin.org>
12 %% 
13 %% This file may be distributed and/or modified under the conditions of
14 %% the LaTeX Project Public License, either version 1.3a of this license
15 %% or (at your option) any later version.  The latest version of this
16 %% license is in:
17 %% 
18 %%    http://www.latex-project.org/lppl.txt
19 %% 
20 %% and version 1.3a or later is part of all distributions of LaTeX version
21 %% 2004/10/11 or later.
22 %% 
23 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
24 \ProvidesPackage{bytefield}
25     [2005/07/31 v1.2a Network protocol diagrams]
26 \RequirePackage{calc}[1998/07/07]
27 \def\bf@newdimen#1{\advance\count11 by 1
28   \ch@ck1\insc@unt\dimen% Check room
29   \allocationnumber=\count11
30   \dimendef#1=\allocationnumber
31   \wlog{\string#1=\string\dimen\the\allocationnumber\space (locally)}}
32 \newlength{\bytefield@height}
33 \newif\ifcounting@words
34 \newlength{\bytefield@height@increment}
35 \DeclareRobustCommand{\inc@bytefield@height}[1]{%
36   \setlength{\bytefield@height@increment}{#1}%
37   \global\advance\bytefield@height by \bytefield@height@increment}
38 \newcounter{bits@wide}
39 \newsavebox{\entire@bytefield@picture}
40 \newenvironment{bytefield}[1]{%
41   \setcounter{bits@wide}{#1}%
42   \let\old@nl=\\%
43   \let\amp=&%
44   \catcode`\&=10
45   \openup -1pt
46   \setlength{\bytefield@height}{0pt}%
47   \setlength{\unitlength}{1pt}%
48   \counting@wordstrue
49   \begin{lrbox}{\entire@bytefield@picture}%
50   \renewcommand{\\}{%
51     \amp\show@wordlabelr\cr%
52     \ignorespaces\counting@wordstrue\make@lspace\amp}%
53   \vbox\bgroup\ialign\bgroup##\amp##\amp##\cr\amp%
54 }{%
55   \amp\show@wordlabelr\cr\egroup\egroup%
56   \end{lrbox}%
57   \usebox{\entire@bytefield@picture}}
58 \newlength{\bitwidth}
59 \AtBeginDocument{\settowidth{\bitwidth}{\tiny 99i}}
60 \newlength{\byteheight}
61 \AtBeginDocument{\setlength{\byteheight}{4ex}}
62 \newlength{\units@wide}
63 \newlength{\units@tall}
64 \DeclareRobustCommand{\bitbox}[3][lrtb]{%
65   \setlength{\units@wide}{\bitwidth * #2}%
66   \parse@bitbox@arg{#1}%
67   \draw@bit@picture{\strip@pt\units@wide}{\strip@pt\byteheight}{#3}}
68 \DeclareRobustCommand{\wordbox}[3][lrtb]{%
69   \setlength{\units@wide}{\bitwidth * \value{bits@wide}}%
70   \setlength{\units@tall}{\byteheight * #2}%
71   \parse@bitbox@arg{#1}%
72   \draw@bit@picture{\strip@pt\units@wide}{\strip@pt\units@tall}{#3}}
73 \DeclareRobustCommand{\draw@bit@picture}[3]{%
74   \begin{picture}(#1,#2)%
75     \put(0,0){\makebox(#1,#2){\parbox[c]{#1\unitlength}{%
76       \bf@newdimen\height
77       \bf@newdimen\depth
78       \bf@newdimen\totalheight
79       \bf@newdimen\width
80       \height=#2\unitlength
81       \depth=0pt%
82       \totalheight=#2\unitlength
83       \width=#1\unitlength
84       \def\widthunits{#1}%
85       \def\heightunits{#2}%
86       \centering #3}}}%
87     \ifbitbox@top
88       \put(0,#2){\line(1,0){#1}}
89     \fi
90     \ifbitbox@bottom
91       \put(0,0){\line(1,0){#1}}
92     \fi
93     \ifbitbox@left
94       \put(0,0){\line(0,1){#2}}
95     \fi
96     \ifbitbox@right
97       \put(#1,0){\line(0,1){#2}}
98     \fi
99   \end{picture}%
100   \ifcounting@words
101     \inc@bytefield@height{\unitlength * \real{#2}}%
102     \counting@wordsfalse
103   \fi
104   \ignorespaces}
105 \newif\ifbitbox@top
106 \newif\ifbitbox@bottom
107 \newif\ifbitbox@left
108 \newif\ifbitbox@right
109 \def\parse@bitbox@arg#1{%
110   \bitbox@topfalse
111   \bitbox@bottomfalse
112   \bitbox@leftfalse
113   \bitbox@rightfalse
114   \parse@bitbox@sides#1X}
115 \def\parse@bitbox@sides#1{%
116   \ifx#1X%
117   \else
118     \ifx#1t%
119       \bitbox@toptrue
120     \else
121       \ifx#1b%
122         \bitbox@bottomtrue
123       \else
124         \ifx#1l%
125           \bitbox@lefttrue
126         \else
127           \ifx#1r%
128             \bitbox@righttrue
129           \fi
130         \fi
131       \fi
132     \fi
133     \expandafter\parse@bitbox@sides
134   \fi}
135 \newlength{\units@high}
136 \DeclareRobustCommand{\skippedwords}[1][2ex]{%
137   \setlength{\units@wide}{\bitwidth * \value{bits@wide}}%
138   \setlength{\units@high}{1pt * \ratio{\units@wide}{6.0pt}}%
139   \setlength{\units@tall}{#1 + \units@high}%
140   \edef\num@wide{\strip@pt\units@wide}%
141   \edef\num@tall{\strip@pt\units@tall}%
142   \edef\num@high{\strip@pt\units@high}%
143   \begin{picture}(\num@wide,\num@tall)
144     \put(0,\num@tall){\line(6,-1){\num@wide}}
145     \put(\num@wide,0){\line(-6,1){\num@wide}}
146     \put(0,0){\line(0,1){\num@high}}
147     \put(\num@wide,\num@tall){\line(0,-1){\num@high}}
148   \end{picture}%
149   \ifcounting@words
150     \inc@bytefield@height{\unitlength * \real{\num@tall}}%
151     \counting@wordsfalse
152   \fi}
153 \DeclareRobustCommand{\bitheader}[2][l]{%
154   \parse@bitbox@arg{lrtb}%
155   \setlength{\units@wide}{\bitwidth * \value{bits@wide}}%
156   \setlength{\units@tall}{\heightof{\tiny 9}}%
157   \setlength{\units@high}{\units@tall * -1}%
158   \def\bit@endianness{#1}%
159   \begin{picture}(\strip@pt\units@wide,\strip@pt\units@tall)%
160                  (0,\strip@pt\units@high)
161     \parse@range@list#2,X,
162   \end{picture}%
163   \ifcounting@words
164     \inc@bytefield@height{\unitlength * \real{\strip@pt\units@tall}}%
165     \counting@wordsfalse
166   \fi
167   \ignorespaces}
168 \def\parse@range@list#1,{%
169   \ifx X#1
170   \else
171     \parse@range#1-#1-#1\relax
172     \expandafter\parse@range@list
173   \fi}
174 \newlength{\header@xpos}
175 \newcounter{header@val}
176 \newcounter{max@header@val}
177 \def\parse@range#1-#2-#3\relax{%
178   \setcounter{header@val}{#1}
179   \setcounter{max@header@val}{#2 + 1}
180   \loop
181     \ifnum\value{header@val}<\value{max@header@val}%
182       \if\bit@endianness b%
183         \setlength{\header@xpos}{%
184           \bitwidth * (\value{bits@wide}-\value{header@val}-1)}
185       \else
186         \setlength{\header@xpos}{\bitwidth * \value{header@val}}
187       \fi
188       \put(\strip@pt\header@xpos,0){%
189         \makebox(\strip@pt\bitwidth,\strip@pt\units@tall){%
190           \tiny \theheader@val}}
191       \addtocounter{header@val}{1}
192   \repeat}
193 \newlength{\curlyshrinkage}
194 \setlength{\curlyshrinkage}{5pt}
195 \newlength{\curlyspace}
196 \AtBeginDocument{\setlength{\curlyspace}{1ex}}
197 \newlength{\labelspace}
198 \AtBeginDocument{\setlength{\labelspace}{0.5ex}}
199 \newbox{\curly@box}
200 \def\store@rcurly#1#2{%
201   \begingroup
202     \bf@newdimen\curly@height%
203     \setlength{\curly@height}{#2 - \curlyshrinkage}%
204     \bf@newdimen\half@curly@height%
205     \setlength{\half@curly@height}{0.5\curly@height}%
206     \bf@newdimen\curly@shift%
207     \setlength{\curly@shift}{\half@curly@height + 0.5\curlyshrinkage}%
208     \global\sbox{#1}{\raisebox{\curly@shift}{%
209       $\xdef\old@axis{\the\fontdimen22\textfont2}$%
210       $\fontdimen22\textfont2=0pt%
211        \left.\vrule height\half@curly@height
212                     width 0pt
213                     depth\half@curly@height\right\}$%
214       $\fontdimen22\textfont2=\old@axis$}}%
215   \endgroup
216 }
217 \def\store@lcurly#1#2{%
218   \begingroup
219     \bf@newdimen\curly@height%
220     \setlength{\curly@height}{#2 - \curlyshrinkage}%
221     \bf@newdimen\half@curly@height%
222     \setlength{\half@curly@height}{0.5\curly@height}%
223     \bf@newdimen\curly@shift%
224     \setlength{\curly@shift}{\half@curly@height + 0.5\curlyshrinkage}%
225     \global\sbox{#1}{\raisebox{\curly@shift}{%
226       $\xdef\old@axis{\the\fontdimen22\textfont2}$%
227       $\fontdimen22\textfont2=0pt%
228        \left\{\vrule height\half@curly@height
229                      width 0pt
230                      depth\half@curly@height\right.$%
231       $\fontdimen22\textfont2=\old@axis$}}%
232   \endgroup
233 }
234 \def\show@wordlabelr{}
235 \newlength{\wordlabelr@start}
236 \newlength{\wordlabelr@end}
237 \newenvironment{wordgroupr}[1]{%
238   \global\wordlabelr@start=\bytefield@height
239   \gdef\wordlabelr@text{#1}%
240   \ignorespaces%
241 }{%
242   \global\wordlabelr@end=\bytefield@height
243   \gdef\show@wordlabelr{%
244     \sbox{\word@label@box}{%
245       \begin{tabular}[b]{@{}l@{}}\wordlabelr@text\end{tabular}}%
246     \settowidth{\label@box@width}{\usebox{\word@label@box}}%
247     \setlength{\label@box@height}{\wordlabelr@end-\wordlabelr@start}%
248     \store@rcurly{\curly@box}{\label@box@height}%
249     \bf@newdimen\total@box@width%
250     \setlength{\total@box@width}{%
251       \curlyspace +
252       \widthof{\usebox{\curly@box}} +
253       \labelspace +
254       \label@box@width}%
255     \begin{picture}(\strip@pt\total@box@width,0)
256       \put(0,0){%
257         \hspace*{\curlyspace}%
258         \usebox{\curly@box}%
259         \hspace*{\labelspace}%
260         \makebox(\strip@pt\label@box@width,\strip@pt\label@box@height){%
261           \usebox{\word@label@box}}}
262     \end{picture}%
263     \gdef\show@wordlabelr{}}%
264   \ignorespaces}
265 \newlength{\wordlabell@start}
266 \newlength{\wordlabell@end}
267 \newlength{\total@lbox@width}
268 \gdef\make@lspace{}
269 \newenvironment{wordgroupl}[1]{%
270   \global\wordlabell@start=\bytefield@height
271   \gdef\wordlabell@text{#1}%
272   \sbox{\word@label@box}{%
273     \begin{tabular}[b]{@{}l@{}}\wordlabell@text\end{tabular}}%
274   \settowidth{\label@box@width}{\usebox{\word@label@box}}%
275   \store@lcurly{\curly@box}{5cm}%
276   \setlength{\total@lbox@width}{%
277     \curlyspace +
278     \widthof{\usebox{\curly@box}} +
279     \labelspace +
280     \label@box@width}%
281   \global\total@lbox@width=\total@lbox@width
282   \gdef\make@lspace{%
283     \hspace*{\total@lbox@width}%
284     \gdef\make@lspace{}}%
285   \ignorespaces%
286 }{%
287   \global\wordlabell@end=\bytefield@height
288   \bf@newdimen\starting@point
289   \setlength{\starting@point}{%
290     -\total@lbox@width - \bitwidth*\value{bits@wide}}%
291   \sbox{\word@label@box}{%
292     \begin{tabular}[b]{@{}l@{}}\wordlabell@text\end{tabular}}%
293   \settowidth{\label@box@width}{\usebox{\word@label@box}}%
294   \setlength{\label@box@height}{\wordlabell@end-\wordlabell@start}%
295   \store@lcurly{\curly@box}{\label@box@height}%
296   \begin{picture}(0,0)
297     \put(\strip@pt\starting@point,0){%
298       \makebox(\strip@pt\label@box@width,\strip@pt\label@box@height){%
299         \usebox{\word@label@box}}%
300       \hspace*{\labelspace}%
301       \usebox{\curly@box}%
302       \hspace*{\curlyspace}}
303   \end{picture}%
304   \ignorespaces}
305 \newlength{\label@box@width}
306 \newlength{\label@box@height}
307 \newsavebox{\word@label@box}
308 \endinput
309 %%
310 %% End of file `bytefield.sty'.