2 %% This is file `bytefield.sty',
3 %% generated with the docstrip utility.
5 %% The original source files were:
7 %% bytefield.dtx (with options: `package')
9 %% This is a generated file.
11 %% Copyright (C) 2005 by Scott Pakin <scott+bf@pakin.org>
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
18 %% http://www.latex-project.org/lppl.txt
20 %% and version 1.3a or later is part of all distributions of LaTeX version
21 %% 2004/10/11 or later.
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}%
46 \setlength{\bytefield@height}{0pt}%
47 \setlength{\unitlength}{1pt}%
49 \begin{lrbox}{\entire@bytefield@picture}%
51 \amp\show@wordlabelr\cr%
52 \ignorespaces\counting@wordstrue\make@lspace\amp}%
53 \vbox\bgroup\ialign\bgroup##\amp##\amp##\cr\amp%
55 \amp\show@wordlabelr\cr\egroup\egroup%
57 \usebox{\entire@bytefield@picture}}
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}{%
78 \bf@newdimen\totalheight
82 \totalheight=#2\unitlength
88 \put(0,#2){\line(1,0){#1}}
91 \put(0,0){\line(1,0){#1}}
94 \put(0,0){\line(0,1){#2}}
97 \put(#1,0){\line(0,1){#2}}
101 \inc@bytefield@height{\unitlength * \real{#2}}%
106 \newif\ifbitbox@bottom
108 \newif\ifbitbox@right
109 \def\parse@bitbox@arg#1{%
114 \parse@bitbox@sides#1X}
115 \def\parse@bitbox@sides#1{%
133 \expandafter\parse@bitbox@sides
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}}
150 \inc@bytefield@height{\unitlength * \real{\num@tall}}%
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,
164 \inc@bytefield@height{\unitlength * \real{\strip@pt\units@tall}}%
168 \def\parse@range@list#1,{%
171 \parse@range#1-#1-#1\relax
172 \expandafter\parse@range@list
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}
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)}
186 \setlength{\header@xpos}{\bitwidth * \value{header@val}}
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}
193 \newlength{\curlyshrinkage}
194 \setlength{\curlyshrinkage}{5pt}
195 \newlength{\curlyspace}
196 \AtBeginDocument{\setlength{\curlyspace}{1ex}}
197 \newlength{\labelspace}
198 \AtBeginDocument{\setlength{\labelspace}{0.5ex}}
200 \def\store@rcurly#1#2{%
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
213 depth\half@curly@height\right\}$%
214 $\fontdimen22\textfont2=\old@axis$}}%
217 \def\store@lcurly#1#2{%
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
230 depth\half@curly@height\right.$%
231 $\fontdimen22\textfont2=\old@axis$}}%
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}%
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}{%
252 \widthof{\usebox{\curly@box}} +
255 \begin{picture}(\strip@pt\total@box@width,0)
257 \hspace*{\curlyspace}%
259 \hspace*{\labelspace}%
260 \makebox(\strip@pt\label@box@width,\strip@pt\label@box@height){%
261 \usebox{\word@label@box}}}
263 \gdef\show@wordlabelr{}}%
265 \newlength{\wordlabell@start}
266 \newlength{\wordlabell@end}
267 \newlength{\total@lbox@width}
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}{%
278 \widthof{\usebox{\curly@box}} +
281 \global\total@lbox@width=\total@lbox@width
283 \hspace*{\total@lbox@width}%
284 \gdef\make@lspace{}}%
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}%
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}%
302 \hspace*{\curlyspace}}
305 \newlength{\label@box@width}
306 \newlength{\label@box@height}
307 \newsavebox{\word@label@box}
310 %% End of file `bytefield.sty'.