summaryrefslogtreecommitdiff
path: root/macros/generic/misc/zip.tex
blob: c1139b3cc41a2d1f6b2740a3aef15288f415c3ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
% zip.tex
% 
% J. Daniel Smith
% 24 May 1990
%
% Modified from a STY file snarfed from someplace else.  But I don't
% remember where the original code came from...  OOPS!!!
%
% Make a barcode for a ZIP code!
%
% Example usage is below.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\catcode`@=11    % letter
%
% Dimensions of bars to be used in the barcode
\newdimen\b@rwidth \newdimen\b@rlong \newdimen\b@rshort \newdimen\b@rsep
\b@rwidth=0.02true in \b@rlong=0.125true in \b@rshort=0.05true in
\b@rsep=0.0275true in
\def\sb@r{\vrule height\b@rshort width\b@rwidth depth0pt \kern\b@rsep}
\def\lb@r{\vrule height\b@rlong width\b@rwidth depth0pt \kern\b@rsep}

% The barcodes for each digit
\def\zerob@r{\lb@r\lb@r\sb@r\sb@r\sb@r}
\def\oneb@r{\sb@r\sb@r\sb@r\lb@r\lb@r}
\def\twob@r{\sb@r\sb@r\lb@r\sb@r\lb@r}
\def\threeb@r{\sb@r\sb@r\lb@r\lb@r\sb@r}
\def\fourb@r{\sb@r\lb@r\sb@r\sb@r\lb@r}
\def\fiveb@r{\sb@r\lb@r\sb@r\lb@r\sb@r}
\def\sixb@r{\sb@r\lb@r\lb@r\sb@r\sb@r}
\def\sevenb@r{\lb@r\sb@r\sb@r\sb@r\lb@r}
\def\eightb@r{\lb@r\sb@r\sb@r\lb@r\sb@r}
\def\nineb@r{\lb@r\sb@r\lb@r\sb@r\sb@r}

\newcount\zipb@rm
\newcount\zipb@rn
\chardef\ten=10

%Almost like using \ifcase... except `-' is ignored.
\def\zipb@r@@@#1#2{\expandafter\def\csname zipb@r@@#1\endcsname%
                   {#2\advance\zipb@rn#1\relax}}

\newbox\zipbarcode
\zipb@r@@@0{\global\setbox\zipbarcode\hbox{\box\zipbarcode\zerob@r}}
\zipb@r@@@1{\global\setbox\zipbarcode\hbox{\box\zipbarcode\oneb@r}}
\zipb@r@@@2{\global\setbox\zipbarcode\hbox{\box\zipbarcode\twob@r}}
\zipb@r@@@3{\global\setbox\zipbarcode\hbox{\box\zipbarcode\threeb@r}}
\zipb@r@@@4{\global\setbox\zipbarcode\hbox{\box\zipbarcode\fourb@r}}
\zipb@r@@@5{\global\setbox\zipbarcode\hbox{\box\zipbarcode\fiveb@r}}
\zipb@r@@@6{\global\setbox\zipbarcode\hbox{\box\zipbarcode\sixb@r}}
\zipb@r@@@7{\global\setbox\zipbarcode\hbox{\box\zipbarcode\sevenb@r}}
\zipb@r@@@8{\global\setbox\zipbarcode\hbox{\box\zipbarcode\eightb@r}}
\zipb@r@@@9{\global\setbox\zipbarcode\hbox{\box\zipbarcode\nineb@r}}

\def\zipb@r@@#1{\csname zipb@r@@#1\endcsname}

\def\zipb@r@#1{\ifx#1\null
                 \let\next\relax
 	       \else
  		 \zipb@r@@{#1}#1%
  	          \let\next\zipb@r@
 	       \fi
 	       \next}

\def\zipbar#1{\setbox\zipbarcode=\null
 \hbox{ % put numbers in an \hbox
   \global\setbox\zipbarcode\hbox{\box\zipbarcode\lb@r} % start with long bar
   \zipb@rn\z@\zipb@r@#1\null
   \zipb@rm\zipb@rn \divide\zipb@rm\ten \multiply\zipb@rm\ten
   \advance\zipb@rm-\zipb@rn
   \ifnum\zipb@rm<0
    \advance\zipb@rm\ten
   \fi
   \zipb@r@@{\the\zipb@rm} % last digit, so that the sum is divisible by ten
   \global\setbox\zipbarcode\hbox{\box\zipbarcode\lb@r}% end with a long bar
   } % end of \hbox
}

\catcode`@=12  % disable private sequences
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%\zipbar{1234567890}
%
%\zipbar{48837}
%
%\zipbar{78653--0102}
%\bye
\endinput