. "$KEYSLIB"/keyfunc.sh
defhelp <<HELP
-KEEPER [INDICES ...]
+[-pt] KEEPER [INDICES ...]
Typeset cards for a set of keeper secrets.
-This program writes a PostScript file to standard output which will contain
-key nubs from the keeper set KEEPER, specifically the keys with the given
-INDICES. Elements of the list are either simple integers or ranges
-[LOW]-[HIGH]; if LOW is omitted, it means 0, and if HIGH is omitted, it means
-the highest possible index. If no INDICES are given then all secret keys are
-written.
+This program creates a set of printable cards containing key nubs from the
+keeper set KEEPER, specifically the keys with the given INDICES. Elements of
+the list are either simple integers or ranges [LOW]-[HIGH]; if LOW is
+omitted, it means 0, and if HIGH is omitted, it means the highest possible
+index. If no INDICES are given then all secret keys are written.
The public keys are found in $KEYS/keeper/KEEPER/I.pub;
key nubs are read from the safe place where \`keys new-keeper' left
them.
+
+If the \`-p' option is given, then the output is a PostScript file which
+can be printed immediately. If the \`-t' option is given, then the output
+is a \`tar' archive containing a TeX source file and images, which must
+be processed using \`latex' and \`dvips'. The default is \`-t'.
HELP
+## Read options.
+mode=tar
+while getopts "pt" opt; do
+ case "$opt" in
+ p) mode=ps ;;
+ t) mode=tar ;;
+ *) usage_err ;;
+ esac
+done
+shift $(( $OPTIND - 1 ))
+
## Parse the command line.
case $# in 0) usage_err ;; esac
keeper=$1; shift
mktmp
umask 077
exec 3>$tmp/$keeper.tex
-cat >&3 <<'EOF'
-\documentclass[a4paper, landscape, 12pt]{article}
-\usepackage[utf8]{inputenc}
-\usepackage[T1]{fontenc}
-EOF
-if kpsewhich mdwfonts.sty >/dev/null; then
- cat >&3 <<'EOF'
-\usepackage[palatino, helvetica, courier, maths = cmr]{mdwfonts}
-EOF
-fi
-cat >&3 <<'EOF'
-\usepackage{graphicx}
-
-%% Report errors with enough context that we can debug them.
-\errorcontextlines=999
-
-%% Basic layout for the cards. We use the paragraph filling machinery, but
-%% don't actually need most of the trimmings.
-\parindent=0pt
-\parfillskip=0pt
-\pagestyle{empty}
-
-%% Page layout: try to use most of the page. The document class will already
-%% have set up the paper size, but we do the rest here.
-\hoffset=-1in \voffset=-1in
-\oddsidemargin=20mm
-\textwidth=\paperwidth \advance\textwidth by -2\oddsidemargin
-\topmargin=20mm
-\headheight=0pt \headsep=0pt
-\textheight=\paperheight \advance\textheight by -2\topmargin
-\AtBeginDocument{\special{papersize=\the\paperwidth,\the\paperheight}}
-
-%% Parameters for the cards and guide rules.
-\newdimen\cardwd \cardwd=82mm
-\newdimen\cardht \cardht=49mm
-\newdimen\guidelen \guidelen=10mm
-\newdimen\rulewd \rulewd=0.6pt
-
-%% Typesetting the secret as text. The macro \snarf TOKEN T0 T1 ... T7
-%% gathers T0 T1 ... T7 into a single argument and passes them to TOKEN, as
-%% long as T0 is not \relax. We use this to process the secret text in a
-%% continuation-passing style.
-\def\snarf#1#2{%
- \ifx#2\relax\let\next\empty%
- \else\def\next{\snarfdo#1#2}%
- \fi%
- \next%
-}
-\def\snarfdo#1#2#3#4#5#6#7#8#9{#1{#2#3#4#5#6#7#8#9}}
-
-%% Print the left and right halves of the line, with a separator. Use boxes
-%% for the lines so that TeX will work out the width of the enclosing vbox
-%% for us. The basic usage is \line TEXT \relax ... \relax, with eight
-%% \relax tokens: this is enough to complete both \snarf calls.
-\def\line{\snarf\lineleft}
-\def\lineleft#1{\hbox\bgroup#1 \snarf\lineright}
-\def\lineright#1{#1\egroup\line}
-
-%% Typeset a card containing a secret. Usage is \card{INDEX}{SECRET}.
-\def\card#1#2{%
- %%
- %% Make sure we're setting a paragraph.
- \leavevmode%
- %%
- %% Initial material: a stretchy space on the left.
- \hbox{}\nobreak\hfil%
- %%
- %% An alignment for the guide markers surrounding the actual card.
- \vbox{\halign{&##\cr%
- %%
- %% Top left guides.
- \vrule width \guidelen height \rulewd depth 0pt%
- \vrule width \rulewd depth 0pt height \guidelen%
- &%
- %%
- %% Top centre gap.
- \hfil%
- &%
- %%
- %% Top right guides.
- \vrule width \rulewd depth 0pt height \guidelen%
- \vrule width \guidelen height \rulewd depth 0pt%
- \cr%
- %%
- %% Left gap.
- &%
- %%
- %% The actual card.
- \vbox to \cardht{%
- %%
- %% We actually do more or less sensible typesetting. TeX will set the
- %% box width from the hsize, and we should leave a small margin all
- %% around.
- \parfillskip=0pt plus 1fil%
- \leftskip=1em \rightskip=1em%
- \hsize=\cardwd%
- %%
- %% The heading.
- \hrule height 0pt \prevdepth = 0pt%
- \medskip%
- {\large\bfseries\textsf{\keeper} secret #1/\total}%
- %%
- %% The QR-code and the text of the secret.
- \vfil%
- $%
- \vcenter{\hbox{\includegraphics[scale = 2.4]{#1.eps}}}%
- \hfil%
- \vcenter{\ttfamily%
- \line#2%
- \relax\relax\relax\relax\relax\relax\relax\relax%
- }%
- $%
- %%
- %% And we're done.
- \vfil%
- }%
- &%
- %%
- %% Right gap.
- \cr%
- %%
- %% Bottom left guides.
- \vrule width \guidelen depth \rulewd height 0pt%
- \vrule width \rulewd depth \guidelen height 0pt%
- &%
- %% Bottom centre gap.
- \hfil%
- &%
- %% Bottom right guides.
- \vrule width \rulewd depth \guidelen height 0pt%
- \vrule width \guidelen depth \rulewd height 0pt%
- \cr%
- %%
- %% Leave a small vertical space at the bottom to separate lines of cards.
- \strut \cr%
- }}%
- %%
- %% End material: a stretchy space to match the one at the start, and then
- %% allow a break.
- \nobreak\hfil\hbox{}%
- \penalty0%
-}
-EOF
+cat >&3 $ETC/keeper-cards.tex
## Write the basic configuration stuff.
cat >&3 <<EOF
\end{document}
EOF
exec 3>&-
-if ! (cd $tmp
- exec </dev/null >tex.out 2>&1
- latex $keeper.tex && dvips -o$keeper.ps $keeper.dvi); then
- echo >&2 "$quis: document formatting failed"
- sed >&2 's/^/| /' $tmp/tex.out
- exit 1
-fi
-cat $tmp/$keeper.ps
+
+case $mode in
+ ps)
+ if ! (cd $tmp
+ exec </dev/null >tex.out 2>&1
+ latex $keeper.tex && dvips -o$keeper.ps $keeper.dvi); then
+ echo >&2 "$quis: document formatting failed"
+ sed >&2 's/^/| /' $tmp/tex.out
+ exit 1
+ fi
+ cat $tmp/$keeper.ps
+ ;;
+ tar)
+ (cd $tmp; tar cf - $keeper.tex *.eps)
+ ;;
+esac
###----- That's all, folks --------------------------------------------------