%% %% This is file `bytefield.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% bytefield.dtx (with options: `package') %% %% This is a generated file. %% %% Copyright (C) 2008 by Scott Pakin %% %% This file may be distributed and/or modified under the conditions of %% the LaTeX Project Public License, either version 1.3a 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.3c or later is part of all distributions of LaTeX version %% 2006/05/20 or later. %% \NeedsTeXFormat{LaTeX2e}[1999/12/01] \ProvidesPackage{bytefield} [2005/07/31 v1.2a Network protocol diagrams] \RequirePackage{calc}[1998/07/07] \def\bf@newdimen#1{\advance\count11 by 1 \ch@ck1\insc@unt\dimen% Check room \allocationnumber=\count11 \dimendef#1=\allocationnumber \wlog{\string#1=\string\dimen\the\allocationnumber\space (locally)}} \newlength{\bytefield@height} \newif\ifcounting@words \newlength{\bytefield@height@increment} \DeclareRobustCommand{\inc@bytefield@height}[1]{% \setlength{\bytefield@height@increment}{#1}% \global\advance\bytefield@height by \bytefield@height@increment} \newcounter{bits@wide} \newsavebox{\entire@bytefield@picture} \newenvironment{bytefield}[1]{% \setcounter{bits@wide}{#1}% \let\old@nl=\\% \let\amp=&% \catcode`\&=10 \openup -1pt \setlength{\bytefield@height}{0pt}% \setlength{\unitlength}{1pt}% \counting@wordstrue \begin{lrbox}{\entire@bytefield@picture}% \renewcommand{\\}{% \amp\show@wordlabelr\cr% \ignorespaces\counting@wordstrue\make@lspace\amp}% \vbox\bgroup\ialign\bgroup##\amp##\amp##\cr\amp% }{% \amp\show@wordlabelr\cr\egroup\egroup% \end{lrbox}% \usebox{\entire@bytefield@picture}} \newlength{\bitwidth} \AtBeginDocument{\settowidth{\bitwidth}{\tiny 99i}} \newlength{\byteheight} \AtBeginDocument{\setlength{\byteheight}{4ex}} \newlength{\units@wide} \newlength{\units@tall} \DeclareRobustCommand{\bitbox}[3][lrtb]{% \setlength{\units@wide}{\bitwidth * #2}% \parse@bitbox@arg{#1}% \draw@bit@picture{\strip@pt\units@wide}{\strip@pt\byteheight}{#3}} \DeclareRobustCommand{\wordbox}[3][lrtb]{% \setlength{\units@wide}{\bitwidth * \value{bits@wide}}% \setlength{\units@tall}{\byteheight * #2}% \parse@bitbox@arg{#1}% \draw@bit@picture{\strip@pt\units@wide}{\strip@pt\units@tall}{#3}} \DeclareRobustCommand{\draw@bit@picture}[3]{% \begin{picture}(#1,#2)% \put(0,0){\makebox(#1,#2){\parbox[c]{#1\unitlength}{% \bf@newdimen\height \bf@newdimen\depth \bf@newdimen\totalheight \bf@newdimen\width \height=#2\unitlength \depth=0pt% \totalheight=#2\unitlength \width=#1\unitlength \def\widthunits{#1}% \def\heightunits{#2}% \centering #3}}}% \ifbitbox@top \put(0,#2){\line(1,0){#1}} \fi \ifbitbox@bottom \put(0,0){\line(1,0){#1}} \fi \ifbitbox@left \put(0,0){\line(0,1){#2}} \fi \ifbitbox@right \put(#1,0){\line(0,1){#2}} \fi \end{picture}% \ifcounting@words \inc@bytefield@height{\unitlength * \real{#2}}% \counting@wordsfalse \fi \ignorespaces} \newif\ifbitbox@top \newif\ifbitbox@bottom \newif\ifbitbox@left \newif\ifbitbox@right \def\parse@bitbox@arg#1{% \bitbox@topfalse \bitbox@bottomfalse \bitbox@leftfalse \bitbox@rightfalse \parse@bitbox@sides#1X} \def\parse@bitbox@sides#1{% \ifx#1X% \else \ifx#1t% \bitbox@toptrue \else \ifx#1b% \bitbox@bottomtrue \else \ifx#1l% \bitbox@lefttrue \else \ifx#1r% \bitbox@righttrue \fi \fi \fi \fi \expandafter\parse@bitbox@sides \fi} \newlength{\units@high} \DeclareRobustCommand{\skippedwords}[1][2ex]{% \setlength{\units@wide}{\bitwidth * \value{bits@wide}}% \setlength{\units@high}{1pt * \ratio{\units@wide}{6.0pt}}% \setlength{\units@tall}{#1 + \units@high}% \edef\num@wide{\strip@pt\units@wide}% \edef\num@tall{\strip@pt\units@tall}% \edef\num@high{\strip@pt\units@high}% \begin{picture}(\num@wide,\num@tall) \put(0,\num@tall){\line(6,-1){\num@wide}} \put(\num@wide,0){\line(-6,1){\num@wide}} \put(0,0){\line(0,1){\num@high}} \put(\num@wide,\num@tall){\line(0,-1){\num@high}} \end{picture}% \ifcounting@words \inc@bytefield@height{\unitlength * \real{\num@tall}}% \counting@wordsfalse \fi} \DeclareRobustCommand{\bitheader}[2][l]{% \parse@bitbox@arg{lrtb}% \setlength{\units@wide}{\bitwidth * \value{bits@wide}}% \setlength{\units@tall}{\heightof{\tiny 9}}% \setlength{\units@high}{\units@tall * -1}% \def\bit@endianness{#1}% \begin{picture}(\strip@pt\units@wide,\strip@pt\units@tall)% (0,\strip@pt\units@high) \parse@range@list#2,X, \end{picture}% \ifcounting@words \inc@bytefield@height{\unitlength * \real{\strip@pt\units@tall}}% \counting@wordsfalse \fi \ignorespaces} \def\parse@range@list#1,{% \ifx X#1 \else \parse@range#1-#1-#1\relax \expandafter\parse@range@list \fi} \newlength{\header@xpos} \newcounter{header@val} \newcounter{max@header@val} \def\parse@range#1-#2-#3\relax{% \setcounter{header@val}{#1} \setcounter{max@header@val}{#2 + 1} \loop \ifnum\value{header@val}<\value{max@header@val}% \if\bit@endianness b% \setlength{\header@xpos}{% \bitwidth * (\value{bits@wide}-\value{header@val}-1)} \else \setlength{\header@xpos}{\bitwidth * \value{header@val}} \fi \put(\strip@pt\header@xpos,0){% \makebox(\strip@pt\bitwidth,\strip@pt\units@tall){% \tiny \theheader@val}} \addtocounter{header@val}{1} \repeat} \newlength{\curlyshrinkage} \setlength{\curlyshrinkage}{5pt} \newlength{\curlyspace} \AtBeginDocument{\setlength{\curlyspace}{1ex}} \newlength{\labelspace} \AtBeginDocument{\setlength{\labelspace}{0.5ex}} \newbox{\curly@box} \def\store@rcurly#1#2{% \begingroup \bf@newdimen\curly@height% \setlength{\curly@height}{#2 - \curlyshrinkage}% \bf@newdimen\half@curly@height% \setlength{\half@curly@height}{0.5\curly@height}% \bf@newdimen\curly@shift% \setlength{\curly@shift}{\half@curly@height + 0.5\curlyshrinkage}% \global\sbox{#1}{\raisebox{\curly@shift}{% $\xdef\old@axis{\the\fontdimen22\textfont2}$% $\fontdimen22\textfont2=0pt% \left.\vrule height\half@curly@height width 0pt depth\half@curly@height\right\}$% $\fontdimen22\textfont2=\old@axis$}}% \endgroup } \def\store@lcurly#1#2{% \begingroup \bf@newdimen\curly@height% \setlength{\curly@height}{#2 - \curlyshrinkage}% \bf@newdimen\half@curly@height% \setlength{\half@curly@height}{0.5\curly@height}% \bf@newdimen\curly@shift% \setlength{\curly@shift}{\half@curly@height + 0.5\curlyshrinkage}% \global\sbox{#1}{\raisebox{\curly@shift}{% $\xdef\old@axis{\the\fontdimen22\textfont2}$% $\fontdimen22\textfont2=0pt% \left\{\vrule height\half@curly@height width 0pt depth\half@curly@height\right.$% $\fontdimen22\textfont2=\old@axis$}}% \endgroup } \def\show@wordlabelr{} \newlength{\wordlabelr@start} \newlength{\wordlabelr@end} \newenvironment{wordgroupr}[1]{% \global\wordlabelr@start=\bytefield@height \gdef\wordlabelr@text{#1}% \ignorespaces% }{% \global\wordlabelr@end=\bytefield@height \gdef\show@wordlabelr{% \sbox{\word@label@box}{% \begin{tabular}[b]{@{}l@{}}\wordlabelr@text\end{tabular}}% \settowidth{\label@box@width}{\usebox{\word@label@box}}% \setlength{\label@box@height}{\wordlabelr@end-\wordlabelr@start}% \store@rcurly{\curly@box}{\label@box@height}% \bf@newdimen\total@box@width% \setlength{\total@box@width}{% \curlyspace + \widthof{\usebox{\curly@box}} + \labelspace + \label@box@width}% \begin{picture}(\strip@pt\total@box@width,0) \put(0,0){% \hspace*{\curlyspace}% \usebox{\curly@box}% \hspace*{\labelspace}% \makebox(\strip@pt\label@box@width,\strip@pt\label@box@height){% \usebox{\word@label@box}}} \end{picture}% \gdef\show@wordlabelr{}}% \ignorespaces} \newlength{\wordlabell@start} \newlength{\wordlabell@end} \newlength{\total@lbox@width} \gdef\make@lspace{} \newenvironment{wordgroupl}[1]{% \global\wordlabell@start=\bytefield@height \gdef\wordlabell@text{#1}% \sbox{\word@label@box}{% \begin{tabular}[b]{@{}l@{}}\wordlabell@text\end{tabular}}% \settowidth{\label@box@width}{\usebox{\word@label@box}}% \store@lcurly{\curly@box}{5cm}% \setlength{\total@lbox@width}{% \curlyspace + \widthof{\usebox{\curly@box}} + \labelspace + \label@box@width}% \global\total@lbox@width=\total@lbox@width \gdef\make@lspace{% \hspace*{\total@lbox@width}% \gdef\make@lspace{}}% \ignorespaces% }{% \global\wordlabell@end=\bytefield@height \bf@newdimen\starting@point \setlength{\starting@point}{% -\total@lbox@width - \bitwidth*\value{bits@wide}}% \sbox{\word@label@box}{% \begin{tabular}[b]{@{}l@{}}\wordlabell@text\end{tabular}}% \settowidth{\label@box@width}{\usebox{\word@label@box}}% \setlength{\label@box@height}{\wordlabell@end-\wordlabell@start}% \store@lcurly{\curly@box}{\label@box@height}% \begin{picture}(0,0) \put(\strip@pt\starting@point,0){% \makebox(\strip@pt\label@box@width,\strip@pt\label@box@height){% \usebox{\word@label@box}}% \hspace*{\labelspace}% \usebox{\curly@box}% \hspace*{\curlyspace}} \end{picture}% \ignorespaces} \newlength{\label@box@width} \newlength{\label@box@height} \newsavebox{\word@label@box} \endinput %% %% End of file `bytefield.sty'.