%% %% 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) 2000-2021 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} [2021/08/17 v2.7 Network protocol diagrams] \RequirePackage{calc}[1998/07/07] \RequirePackage{keyval} \def\bf@newdimen#1{\advance\count11 by 1 \ch@ck1\insc@unt\dimen \allocationnumber=\count11 \dimendef#1=\allocationnumber \wlog{\string#1=\string\dimen\the\allocationnumber\space (locally)}% } \AtBeginDocument{% \expandafter\ifx\csname e@alloc\endcsname\relax \expandafter\ifx\csname locdimen\endcsname\relax \else \let\bf@newdimen=\locdimen \fi \else \let\bf@newdimen=\newdimen \fi } \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 } \newsavebox{\entire@bytefield@picture} \newenvironment{bytefield}[2][]{% \bf@bytefieldsetup{#1}% \renewcommand{\baselinestretch}{}% \selectfont \def\bits@wide{#2}% \let\old@nl=\\% \let\amp=&% \catcode`\&=10 \openup -1pt \setlength{\bytefield@height}{0pt}% \setlength{\unitlength}{1pt}% \global\counting@wordstrue \begin{lrbox}{\entire@bytefield@picture}% \renewcommand{\\}[1][0pt]{% \unskip \vspace{##1}% \amp\show@wordlabelr\cr \ignorespaces\global\counting@wordstrue\make@lspace\amp}% \vbox\bgroup\ialign\bgroup##\amp##\amp##\cr\amp }{% \unskip \amp\show@wordlabelr\cr\egroup\egroup \end{lrbox}% \usebox{\entire@bytefield@picture}% } \newcommand*{\bf@bitformatting}{\tiny} \newcommand*{\bf@boxformatting}{\centering} \newlength{\bf@bitwidth} \settowidth{\bf@bitwidth}{\bf@bitformatting{99i}} \newlength{\bf@bitheight} \setlength{\bf@bitheight}{4ex} \newlength{\units@wide} \newlength{\units@tall} \newcommand*{\bf@call@box@cmd}[1]{% \def\bf@call@box@func{#1}% \bf@call@box@cmd@i } \newcommand*{\bf@call@box@cmd@i}[2][lrtb]{% \def\bf@call@box@arg@i{#1}% \def\bf@call@box@arg@ii{#2}% \bf@call@box@cmd@ii } \newcommand*{\bf@call@box@cmd@ii}[2][]{% \def\bf@call@box@arg@iii{#1}% \def\bf@call@box@arg@iv{#2}% \bf@call@box@func } \DeclareRobustCommand{\bitbox}{\bf@call@box@cmd{\bf@bitbox}} \def\bf@bitbox{% \bgroup \expandafter\bf@parse@bitbox@arg\expandafter{\bf@call@box@arg@i}% \setlength{\units@wide}{\bf@bitwidth * \bf@call@box@arg@ii}% \expandafter\bf@bytefieldsetup\expandafter{\bf@call@box@arg@iii}% \@ifundefined{bf@bgcolor}{% }{% \rlap{% \draw@bit@picture{\strip@pt\units@wide}{\strip@pt\bf@bitheight}{% \color{\bf@bgcolor}% \rule{\width}{\height}% }% }% }% \draw@bit@picture{\strip@pt\units@wide}{\strip@pt\bf@bitheight}{% \bf@call@box@arg@iv }% \egroup \ignorespaces } \DeclareRobustCommand{\wordbox}{\bf@call@box@cmd{\bf@wordbox}} \def\bf@wordbox{% \bgroup \expandafter\bf@parse@bitbox@arg\expandafter{\bf@call@box@arg@i}% \setlength{\units@wide}{\bf@bitwidth * \bits@wide}% \setlength{\units@tall}{\bf@bitheight * \bf@call@box@arg@ii}% \expandafter\bf@bytefieldsetup\expandafter{\bf@call@box@arg@iii}% \@ifundefined{bf@bgcolor}{% }{% \rlap{% \draw@bit@picture{\strip@pt\units@wide}{\strip@pt\units@tall}{% \color{\bf@bgcolor}% \rule{\width}{\height}% }% }% }% \draw@bit@picture{\strip@pt\units@wide}{\strip@pt\units@tall}{% \bf@call@box@arg@iv }% \@ifundefined{bf@per@word}{}{\bf@invoke@per@word{\bf@call@box@arg@ii}}% \egroup \ignorespaces } \DeclareRobustCommand{\draw@bit@picture}[3]{% \begin{picture}(#1,#2)% \put(0,0){\makebox(#1,#2){\parbox{#1\unitlength}{% \bf@set@user@dimens{#1}{#2}% \bf@boxformatting{#3\par}}}}% \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}}% \global\counting@wordsfalse \fi } \newcommand{\bf@invoke@per@word}[1]{% \begin{picture}(0,0)% \@tempcnta=0 \@tempdima=#1\bf@bitheight \bf@set@user@dimens{\strip@pt\units@wide}{\strip@pt\units@tall}% \loop \advance\@tempdima by -\bf@bitheight \bgroup \put(-\strip@pt\units@wide, \strip@pt\@tempdima){% \expandafter\bf@per@word\expandafter{\the\@tempcnta}{#1}% }% \egroup \advance\@tempcnta by 1\relax \ifnum#1>\@tempcnta \repeat \end{picture}% } \newcommand{\bf@set@user@dimens}[2]{% \bf@newdimen\width \bf@newdimen\height \bf@newdimen\depth \bf@newdimen\totalheight \width=#1\unitlength \height=#2\unitlength \depth=0pt% \totalheight=#2\unitlength \def\widthunits{#1}% \def\heightunits{#2}% } \DeclareRobustCommand{\bitboxes}{% \@ifstar {\bf@call@box@cmd{\bf@bitboxes@star}}% {\bf@call@box@cmd{\bf@bitboxes@no@star}}% } \def\bf@relax{\relax} \def\bf@bitboxes@no@star{% \expandafter\bf@bitboxes@no@star@i\bf@call@box@arg@iv\relax \ignorespaces } \def\bf@bitboxes@no@star@i#1{% \def\bf@call@box@arg@iv{#1}% \ifx\bf@call@box@arg@iv\bf@relax \let\next=\relax \else \bf@bitbox \let\next=\bf@bitboxes@no@star@i \fi \next } \def\bf@bitboxes@star{% \edef\bf@bitboxes@sides{\bf@call@box@arg@i}% \expandafter\bf@bitboxes@star@i\bf@call@box@arg@iv\relax\relax \ignorespaces } \def\bf@bitboxes@star@i#1#2{% \def\bf@call@box@arg@iv{#1}% \def\bf@bitboxes@arg@ii{#2}% \ifx\bf@bitboxes@arg@ii\bf@relax \bf@bitbox \let\next=\relax \else \edef\bf@call@box@arg@i{\bf@bitboxes@sides R}% \bf@bitbox \def\next{\bf@bitboxes@star@ii{#2}}% \fi \next } \def\bf@bitboxes@star@ii#1#2{% \def\bf@call@box@arg@iv{#1}% \def\bf@bitboxes@arg@ii{#2}% \ifx\bf@bitboxes@arg@ii\bf@relax \edef\bf@call@box@arg@i{\bf@bitboxes@sides L}% \else \edef\bf@call@box@arg@i{\bf@bitboxes@sides LR}% \fi \ifx\bf@call@box@arg@iv\bf@relax \let\next=\relax \else \bf@bitbox \def\next{\bf@bitboxes@star@ii{#2}}% \fi \next } \newif\ifbitbox@top \newif\ifbitbox@bottom \newif\ifbitbox@left \newif\ifbitbox@right \def\bf@parse@bitbox@arg#1{% \bitbox@topfalse \bitbox@bottomfalse \bitbox@leftfalse \bitbox@rightfalse \bf@parse@bitbox@sides#1X% } \def\bf@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 \else \ifx#1T% \bitbox@topfalse \else \ifx#1B% \bitbox@bottomfalse \else \ifx#1L% \bitbox@leftfalse \else \ifx#1R% \bitbox@rightfalse \else \PackageWarning{bytefield}{Unrecognized box side `#1'}% \fi \fi \fi \fi \fi \fi \fi \fi \expandafter\bf@parse@bitbox@sides \fi } \newlength{\units@high} \DeclareRobustCommand{\skippedwords}[1][2ex]{% \setlength{\units@wide}{\bf@bitwidth * \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}}% \global\counting@wordsfalse \fi } \newcommand*{\bf@bit@endianness}{l} \newcommand*{\bf@first@bit}{0} \DeclareRobustCommand{\bitheader}[2][]{% \bf@parse@bitbox@arg{lrtb}% \setlength{\units@wide}{\bf@bitwidth * \bits@wide}% \setlength{\units@tall}{\heightof{\bf@bitformatting{1234567890}}}% \setlength{\units@high}{\units@tall * -1}% \bf@process@bitheader@opts{#1}% \begin{picture}(\strip@pt\units@wide,\strip@pt\units@tall)% (0,\strip@pt\units@high) \bf@parse@range@list#2,X, \end{picture}% \ifcounting@words \inc@bytefield@height{\unitlength * \real{\strip@pt\units@tall}}% \global\counting@wordsfalse \fi \ignorespaces } \def\bf@parse@range@list#1,{% \ifx X#1 \else \bf@parse@range#1-#1-#1\relax \expandafter\bf@parse@range@list \fi } \newlength{\header@xpos} \newcounter{header@val} \newcounter{max@header@val} \def\bf@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\bf@bit@endianness b% \setlength{\header@xpos}{% \bf@bitwidth * (\bits@wide - \value{header@val} + \bf@first@bit - 1)}% \else \setlength{\header@xpos}{\bf@bitwidth * (\value{header@val} - \bf@first@bit)}% \fi \put(\strip@pt\header@xpos,0){% \makebox(\strip@pt\bf@bitwidth,\strip@pt\units@tall){% \bf@bitformatting{\theheader@val}}} \addtocounter{header@val}{1} \repeat } \newcommand*{\bf@process@bitheader@opts}{% \let\KV@bytefield@l=\KV@bitheader@l \let\KV@bytefield@b=\KV@bitheader@b \let\KV@bytefield@l@default=\KV@bitheader@l@default \let\KV@bytefield@b@default=\KV@bitheader@b@default \setkeys{bytefield}% } \define@key{bitheader}{l}[true]{% \expandafter\ifx\csname curlyshrinkage\endcsname\relax \PackageWarning{bytefield}{% The "l" argument to \protect\bitheader\space is deprecated.\MessageBreak Instead, please use "endianness=little", which can\MessageBreak even be declared globally for the entire document.\MessageBreak This warning occurred}% \fi \def\bf@bit@endianness{l}% } \define@key{bitheader}{b}[true]{% \expandafter\ifx\csname curlyshrinkage\endcsname\relax \PackageWarning{bytefield}{% The "b" argument to \protect\bitheader\space is deprecated.\MessageBreak Instead, please use "endianness=big", which can\MessageBreak even be declared globally for the entire document.\MessageBreak This warning occurred}% \fi \def\bf@bit@endianness{b}% } \def\bf@leftcurlyshrinkage{5pt} \def\bf@rightcurlyshrinkage{5pt} \def\bf@leftcurlyspace{1ex} \def\bf@rightcurlyspace{1ex} \def\bf@leftlabelspace{0.5ex} \def\bf@rightlabelspace{0.5ex} \let\bf@leftcurly=\{ \let\bf@rightcurly=\} \let\bf@leftcurlystyle=\relax \let\bf@rightcurlystyle=\relax \newbox{\curly@box} \def\store@rcurly#1#2{% \begingroup \bf@newdimen\curly@height \setlength{\curly@height}{#2 - \bf@rightcurlyshrinkage}% \bf@newdimen\half@curly@height \setlength{\half@curly@height}{0.5\curly@height}% \bf@newdimen\curly@shift \setlength{\curly@shift}{\bf@rightcurlyshrinkage}% \setlength{\curly@shift}{\half@curly@height + 0.5\curly@shift}% \addtolength{\curly@shift}{-\fontdimen22\textfont2}% \global\sbox{#1}{\raisebox{\curly@shift}{% \bf@rightcurlystyle{% $\left. \vrule height\half@curly@height width 0pt depth\half@curly@height\right\bf@rightcurly$% }% }}% \endgroup } \def\store@lcurly#1#2{% \begingroup \bf@newdimen\curly@height \setlength{\curly@height}{#2 - \bf@leftcurlyshrinkage}% \bf@newdimen\half@curly@height \setlength{\half@curly@height}{0.5\curly@height}% \bf@newdimen\curly@shift \setlength{\curly@shift}{\bf@leftcurlyshrinkage}% \setlength{\curly@shift}{\half@curly@height + 0.5\curly@shift}% \addtolength{\curly@shift}{-\fontdimen22\textfont2}% \global\sbox{#1}{\raisebox{\curly@shift}{% \bf@leftcurlystyle{% $\left\bf@leftcurly \vrule height\half@curly@height width 0pt depth\half@curly@height\right.$% }% }}% \endgroup } \def\show@wordlabelr{} \newlength{\wordlabelr@start} \newlength{\wordlabelr@end} \newenvironment{rightwordgroup}[2][]{% \endgroup \global\wordlabelr@start=\bytefield@height \gdef\wordlabelr@params{#1}% \gdef\wordlabelr@text{#2}% \ignorespaces }{% \begingroup \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}% \expandafter\bf@bytefieldsetup\expandafter{\wordlabelr@params}% \store@rcurly{\curly@box}{\label@box@height}% \bf@newdimen\total@box@width \setlength{\total@box@width}{% \bf@rightcurlyspace + \widthof{\usebox{\curly@box}} + \bf@rightlabelspace + \label@box@width }% \begin{picture}(\strip@pt\total@box@width,0) \put(0,0){% \hspace*{\bf@rightcurlyspace}% \usebox{\curly@box}% \hspace*{\bf@rightlabelspace}% \makebox(\strip@pt\label@box@width,\strip@pt\label@box@height){% \usebox{\word@label@box}% }% }% \end{picture}% \gdef\show@wordlabelr{}}% \def\@currenvir{rightwordgroup}% \ignorespacesafterend } \newlength{\wordlabell@start} \newlength{\wordlabell@end} \newlength{\total@lbox@width} \gdef\make@lspace{} \newenvironment{leftwordgroup}[2][]{% \global\wordlabell@start=\bytefield@height \gdef\wordlabell@params{#1}% \gdef\wordlabell@text{#2}% \bf@bytefieldsetup{#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}{% \bf@leftcurlyspace + \widthof{\usebox{\curly@box}} + \bf@leftlabelspace + \label@box@width}% \global\total@lbox@width=\total@lbox@width \gdef\make@lspace{% \hspace*{\total@lbox@width}% \gdef\make@lspace{}% }% \endgroup \ignorespaces }{% \begingroup \global\wordlabell@end=\bytefield@height \bf@newdimen\starting@point \setlength{\starting@point}{% -\total@lbox@width - \bf@bitwidth*\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}% \expandafter\bf@bytefieldsetup\expandafter{\wordlabell@params}% \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*{\bf@leftlabelspace}% \usebox{\curly@box}% \hspace*{\bf@leftcurlyspace}} \end{picture}% \def\@currenvir{leftwordgroup}% \ignorespacesafterend } \newlength{\label@box@width} \newlength{\label@box@height} \newsavebox{\word@label@box} \newcommand{\bf@enter@compatibility@mode@i}{% \PackageInfo{bytefield}{Entering version 1 compatibility mode}% \newlength{\bitwidth}% \newlength{\byteheight}% \newlength{\curlyspace}% \newlength{\labelspace}% \newlength{\curlyshrinkage}% \settowidth{\bitwidth}{\tiny 99i}% \setlength{\byteheight}{4ex}% \setlength{\curlyspace}{1ex}% \setlength{\labelspace}{0.5ex}% \setlength{\curlyshrinkage}{5pt}% \let\newbytefield=\bytefield \let\endnewbytefield=\endbytefield \renewenvironment{bytefield}[1]{% \begin{newbytefield}[% bitwidth=\bitwidth, bitheight=\byteheight, curlyspace=\curlyspace, labelspace=\labelspace, curlyshrinkage=\curlyshrinkage]{##1}% }{% \end{newbytefield}% } \def\wordgroupr{\begin{rightwordgroup}} \def\endwordgroupr{\end{rightwordgroup}} \def\wordgroupl{\begin{leftwordgroup}} \def\endwordgroupl{\end{leftwordgroup}} \renewcommand{\bytefieldsetup}[1]{% \PackageError{bytefield}{% The \protect\bytefieldsetup\space macro is not available in\MessageBreak version 1 compatibility mode% }{% Remove [compat1] from the \protect\usepackage{bytefield} line to make \protect\bytefieldsetup\MessageBreak available to this document.\space\space (The document may also need to be modified to use\MessageBreak the new bytefield interface.) }% }% } \newcommand{\wordgroupr}{% \PackageError{bytefield}{% Macros \protect\wordgroupr, \protect\wordgroupl, \protect\endwordgroupr, \MessageBreak and \protect\endwordgroupl\space no longer exist% }{% Starting with version 2.0, bytefield uses \protect\begin{wordgroupr}... \MessageBreak \protect\end{wordgroupr} and \protect\begin{wordgroupl}...% \protect\end{wordgroupl}\MessageBreak to specify word groups and a new \protect\bytefieldsetup\space macro to \MessageBreak change bytefield's various formatting parameters.% }% } \let\endwordgroupr=\wordgroupr \let\wordgroupl=\wordgroupr \let\endwordgroupl=\wordgroupr \define@key{bytefield}{bitwidth}{% \def\bf@bw@arg{#1}% \def\bf@auto{auto}% \ifx\bf@bw@arg\bf@auto \settowidth{\bf@bitwidth}{\bf@bitformatting{99i}}% \else \setlength{\bf@bitwidth}{#1}% \fi } \define@key{bytefield}{bitheight}{\setlength{\bf@bitheight}{#1}} \define@key{bytefield}{bitformatting}{\def\bf@bitformatting{#1}} \define@key{bytefield}{boxformatting}{\def\bf@boxformatting{#1}} \define@key{bytefield}{leftcurly}{\def\bf@leftcurly{#1}} \define@key{bytefield}{rightcurly}{\def\bf@rightcurly{#1}} \define@key{bytefield}{leftcurlyspace}{\def\bf@leftcurlyspace{#1}} \define@key{bytefield}{rightcurlyspace}{\def\bf@rightcurlyspace{#1}} \define@key{bytefield}{curlyspace}{% \def\bf@leftcurlyspace{#1}% \def\bf@rightcurlyspace{#1}% } \define@key{bytefield}{leftlabelspace}{\def\bf@leftlabelspace{#1}} \define@key{bytefield}{rightlabelspace}{\def\bf@rightlabelspace{#1}} \define@key{bytefield}{labelspace}{% \def\bf@leftlabelspace{#1}% \def\bf@rightlabelspace{#1}% } \define@key{bytefield}{leftcurlyshrinkage}{\def\bf@leftcurlyshrinkage{#1}} \define@key{bytefield}{rightcurlyshrinkage}{\def\bf@rightcurlyshrinkage{#1}} \define@key{bytefield}{curlyshrinkage}{% \def\bf@leftcurlyshrinkage{#1}% \def\bf@rightcurlyshrinkage{#1}% } \define@key{bytefield}{leftcurlystyle}{\def\bf@leftcurlystyle{#1}} \define@key{bytefield}{rightcurlystyle}{\def\bf@rightcurlystyle{#1}} \define@key{bytefield}{curlystyle}{% \def\bf@leftcurlystyle{#1}% \def\bf@rightcurlystyle{#1}% } \define@key{bytefield}{endianness}{\bf@parse@endianness{#1}} \newcommand{\bf@parse@endianness}[1]{% \def\bf@little{little}% \def\bf@big{big}% \def\bf@arg{#1}% \ifx\bf@arg\bf@little \def\bf@bit@endianness{l}% \else \ifx\bf@arg\bf@big \def\bf@bit@endianness{b}% \else \PackageError{bytefield}{% Invalid argument "#1" to the endianness option% }{% The endianness option must be set to either "little" or "big".\MessageBreak Please specify either endianness=little or endianness=big. }% \fi \fi } \define@key{bytefield}{lsb}{\def\bf@first@bit{#1}} \define@key{bytefield}{bgcolor}{\def\bf@bgcolor{#1}} \define@key{bytefield}{perword}{\def\bf@per@word{#1}} \newcommand{\bf@bytefieldsetup}{\setkeys{bytefield}} \let\bytefieldsetup=\bf@bytefieldsetup \DeclareOption{compat1}{\bf@enter@compatibility@mode@i} \def\bf@package@options{} \DeclareOption*{% \edef\next{% \noexpand\g@addto@macro\noexpand\bf@package@options{,\CurrentOption}% }% \next } \ProcessOptions\relax \expandafter\bf@bytefieldsetup\expandafter{\bf@package@options} \endinput %% %% End of file `bytefield.sty'.