summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
authorManuel Pégourié-Gonnard <mpg@elzevir.fr>2011-08-02 19:35:47 +0000
committerManuel Pégourié-Gonnard <mpg@elzevir.fr>2011-08-02 19:35:47 +0000
commitf2d6ed458a41ef939424ba4a5727efd53812544e (patch)
tree15ca260a6691c12ac0caf48a6b974d2faff6353d /Master/texmf-dist/tex
parentc3f47c95240cee16ee832b0424a5eaea71d3fff0 (diff)
bytefield 2011/06/19 v2.1
git-svn-id: svn://tug.org/texlive/trunk@23351 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/latex/bytefield/bytefield.sty113
1 files changed, 80 insertions, 33 deletions
diff --git a/Master/texmf-dist/tex/latex/bytefield/bytefield.sty b/Master/texmf-dist/tex/latex/bytefield/bytefield.sty
index e720839514f..319866f4b23 100644
--- a/Master/texmf-dist/tex/latex/bytefield/bytefield.sty
+++ b/Master/texmf-dist/tex/latex/bytefield/bytefield.sty
@@ -22,7 +22,7 @@
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{bytefield}
- [2011/02/09 v2.0a Network protocol diagrams]
+ [2011/06/19 v2.1 Network protocol diagrams]
\RequirePackage{calc}[1998/07/07]
\RequirePackage{keyval}
\def\bf@newdimen#1{\advance\count11 by 1
@@ -44,11 +44,10 @@
\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}[2][]{%
\bf@bytefieldsetup{#1}%
- \setcounter{bits@wide}{#2}%
+ \def\bits@wide{#2}%
\let\old@nl=\\%
\let\amp=&%
\catcode`\&=10
@@ -57,8 +56,9 @@
\setlength{\unitlength}{1pt}%
\global\counting@wordstrue
\begin{lrbox}{\entire@bytefield@picture}%
- \renewcommand{\\}{%
+ \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
@@ -76,12 +76,12 @@
\newlength{\units@tall}
\DeclareRobustCommand{\bitbox}[3][lrtb]{%
\setlength{\units@wide}{\bf@bitwidth * #2}%
- \parse@bitbox@arg{#1}%
+ \bf@parse@bitbox@arg{#1}%
\draw@bit@picture{\strip@pt\units@wide}{\strip@pt\bf@bitheight}{#3}}
\DeclareRobustCommand{\wordbox}[3][lrtb]{%
- \setlength{\units@wide}{\bf@bitwidth * \value{bits@wide}}%
+ \setlength{\units@wide}{\bf@bitwidth * \bits@wide}%
\setlength{\units@tall}{\bf@bitheight * #2}%
- \parse@bitbox@arg{#1}%
+ \bf@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)%
@@ -119,13 +119,13 @@
\newif\ifbitbox@bottom
\newif\ifbitbox@left
\newif\ifbitbox@right
-\def\parse@bitbox@arg#1{%
+\def\bf@parse@bitbox@arg#1{%
\bitbox@topfalse
\bitbox@bottomfalse
\bitbox@leftfalse
\bitbox@rightfalse
- \parse@bitbox@sides#1X}
-\def\parse@bitbox@sides#1{%
+ \bf@parse@bitbox@sides#1X}
+\def\bf@parse@bitbox@sides#1{%
\ifx#1X%
\else
\ifx#1t%
@@ -143,11 +143,11 @@
\fi
\fi
\fi
- \expandafter\parse@bitbox@sides
+ \expandafter\bf@parse@bitbox@sides
\fi}
\newlength{\units@high}
\DeclareRobustCommand{\skippedwords}[1][2ex]{%
- \setlength{\units@wide}{\bf@bitwidth * \value{bits@wide}}%
+ \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}%
@@ -163,56 +163,81 @@
\inc@bytefield@height{\unitlength * \real{\num@tall}}%
\global\counting@wordsfalse
\fi}
-\DeclareRobustCommand{\bitheader}[2][l]{%
- \parse@bitbox@arg{lrtb}%
- \setlength{\units@wide}{\bf@bitwidth * \value{bits@wide}}%
+\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}%
- \def\bit@endianness{#1}%
+ \bf@process@bitheader@opts{#1}%
\begin{picture}(\strip@pt\units@wide,\strip@pt\units@tall)%
(0,\strip@pt\units@high)
- \parse@range@list#2,X,
+ \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\parse@range@list#1,{%
+\def\bf@parse@range@list#1,{%
\ifx X#1
\else
- \parse@range#1-#1-#1\relax
- \expandafter\parse@range@list
+ \bf@parse@range#1-#1-#1\relax
+ \expandafter\bf@parse@range@list
\fi}
\newlength{\header@xpos}
\newcounter{header@val}
\newcounter{max@header@val}
-\def\parse@range#1-#2-#3\relax{%
+\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\bit@endianness b%
+ \if\bf@bit@endianness b%
\setlength{\header@xpos}{%
- \bf@bitwidth * (\value{bits@wide}-\value{header@val}-1)}
+ \bf@bitwidth * (\bits@wide - \value{header@val} + \bf@first@bit - 1)}%
\else
- \setlength{\header@xpos}{\bf@bitwidth * \value{header@val}}
+ \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{0pt}
-\def\bf@rightcurlyspace{0pt}
-\def\bf@leftlabelspace{0pt}
-\def\bf@rightlabelspace{0pt}
-\gdef\bf@leftcurlyspace{1ex}
-\gdef\bf@rightcurlyspace{1ex}
-\gdef\bf@leftlabelspace{0.5ex}
-\gdef\bf@rightlabelspace{0.5ex}
+\def\bf@leftcurlyspace{1ex}
+\def\bf@rightcurlyspace{1ex}
+\def\bf@leftlabelspace{0.5ex}
+\def\bf@rightlabelspace{0.5ex}
\let\bf@leftcurly=\{
\let\bf@rightcurly=\}
\newbox{\curly@box}
@@ -316,7 +341,7 @@
\global\wordlabell@end=\bytefield@height
\bf@newdimen\starting@point
\setlength{\starting@point}{%
- -\total@lbox@width - \bf@bitwidth*\value{bits@wide}}%
+ -\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}}%
@@ -426,6 +451,28 @@
\def\bf@leftcurlyshrinkage{#1}%
\def\bf@rightcurlyshrinkage{#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}}
\newcommand{\bf@bytefieldsetup}{\setkeys{bytefield}}
\let\bytefieldsetup=\bf@bytefieldsetup
\DeclareOption{compat1}{\bf@enter@compatibility@mode@i}