%%%%%%%%%%%%%%%%%%%%%%%%%%% bhs.sty %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% bhs.sty
% Scanner for the encoding used in the machine-readable
% Biblia Hebraica Stuttgardiana
% to install it, include it as a LaTeX style option "bhs"
% with Plain TeX, say "\input bhs.sty"
% to activate it, say "\setcode {bhs}
% 09.03.95
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (c) Klaus Lagally
%     Institut fuer Informatik
%     Universitaet Stuttgart
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ifx \bhsatcode \undefined \else \expandafter \endinput
\fi % load only once

\chardef \bhsatcode = \catcode`\@  \catcode`\@ = 11

\a@ident {bhs.sty} {3.03} {09.03.95}

\input bhslabel.sty	% process BHS labels

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% dynamic definitions for BHS Hebrew coding
{\catcode `\ =9 \catcode `\^^M=9 \catcode `\^^I=9
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gdef \setbhs@codes {% activate and change some codes
\globaldefs=1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def \sc@A {a}   \def \sc@B {b}   \def \sc@C {S}   \def \sc@D {d}
\def \sc@E {e}   \def \sc@F {A}   \def \sc@G {g}   \def \sc@H {H}
\def \sc@I {i}   \def \sc@J {t}   \def \sc@K {k}   \def \sc@L {l}
\def \sc@M {m}   \def \sc@N {n}   \def \sc@O {O}   \def \sc@P {p}
\def \sc@Q {q}   \def \sc@R {r}   \def \sc@S {s}   \def \sc@T {t}
\def \sc@U {u}   \def \sc@V {D}   \def \sc@W {W}   \def \sc@X {X}
\def \sc@Y {y}   \def \sc@Z {z}   \def \sc@@ {QQ}
\a@digits = {0123456789}     	\a@paren  = {[]}
\a@first = {)+(##&$":.,*0123456789}	
\globaldefs=0 }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}% end of dynamic definitions for BHS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \bhs@beg #1#2{% start BHS scanner
  \def \next {\bhs@word #1#2}%
\ifx #1>\let \next \sc@endscan \else			% finished
\ifx #2>\def \next {\bhs@testpara #1#2}\else
\ifx #2?\def \next {\bhs@testpara #1#2}\else
\ifx #1W\def \next {\bhs@begW #2}\else
\fi\fi\fi\fi \next }

\def \bhs@word #1#2{% transform input into internal notation
     \def \next {\bhs@word #2}%
\ifx #1>\let \next \sc@endscan \else			% finished
\ifx #1]\let \next \bhs@word \else
\ifx #10\def \next {\bhs@zero #2}\else
\ifx #17\def \next {\bhs@seven #2}\else
	\test@in@set #1\a@digits
\ifin@list \let \next \bhs@word \else
%
\ifx #1?\def \next {\bhs@query #2}\else
\ifx #1:\def \next {\bhs@colon #2}\else
\ifx #1O\def \next {\bhs@O #2}\else
\ifx #1W\def \next {\bhs@W #2}\else
\ifx #1|\def \sc@char {|}\sc@put \else
\ifx #1#2\def \next {\bhs@word #1|#2}\else
%
\ifx #1.\sc@put \else
\ifx #1'\def \sc@char {'}\sc@put \else
\ifx #1)\def \sc@char {QQ}\sc@put \else
\ifx #1+\def \sc@char {V}\sc@put \else
%
\ifx #1(\def \sc@char {P}\sc@put \else
\ifx #1##\def \sc@char {\nxp \a@S }\sc@put \else
\ifx #1&\def \sc@char {\nxp \a@s }\sc@put \else
\ifx #1$\def \sc@char {x}\sc@put \else
%
\ifx #1"\def \sc@char {\nxp \a@E }\sc@put \else
\ifx #1-\def \sc@char {B}\sc@put \else
\ifx #1*\def \sc@char {*}\sc@put \else
\ifcat \nxp #1a\edef \sc@char {\csname sc@#1\endcsname }%
   	\sc@put
\fi\fi\fi\fi
\fi\fi\fi\fi 
\fi\fi\fi\fi 
%
\fi\fi\fi\fi\fi\fi 
\fi\fi\fi\fi\fi 
\next }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \bhs@colon #1{% shwa or chatef
\let \next \bhs@word
\ifx #1A\def \sc@char {\nxp \a@A }\else
\ifx #1F\def \sc@char {\nxp \a@O }\else
\ifx #1E\def \sc@char {\nxp \a@I }\else
\def \sc@char {\nxp \a@j }\def \next {\bhs@word #1}%
\fi\fi\fi \sc@put \next }

\def \bhs@O #1#2{% cholem or cholem waw
\def \next {\bhs@word #2}\test@in@set #1\a@digits
\ifin@list \def \next {\bhs@word #1#2O}\else
\ifx #1W\def \sc@char {O}\else
	\def \sc@char {\nxp \a@o }\def \next {\bhs@word #1#2}%
\fi \sc@put \fi \next }

\def \bhs@W #1{% waw or shureq
\def \sc@char {w}\def \next {\bhs@word #1}%
\ifx #1.\def \sc@char {U}\let \next \bhs@word
\fi \sc@put \next }

\def \bhs@begW #1{% initial waw
\def \sc@char {w}\def \next {\bhs@word #1}%
\ifx #1.\def \sc@char {ww}\let \next \bhs@word
\fi \sc@put \next }

\def \bhs@seven #1{% meteg
\let \next \bhs@word 
\ifx #15\def \sc@char {|}\sc@put \else
	\test@in@set #1\a@digits
\ifin@list \else \def \next {\bhs@word #1}%
\fi\fi \next }

\def \bhs@zero #1{% sop pasuq and pasuq
\let \next \bhs@word 
\ifx #10\def \sc@char {:}\sc@put \else
\ifx #15\let \next \bhs@pasuq \else
	\test@in@set #1\a@digits
\ifin@list \else \def \next {\bhs@word #1}%
\fi\fi\fi \next }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\gdef \sv@cholem #1{% short o: cholem breve; local version for BHS
\def \next {\syl@con #1}% 
\ifx #1|\def \next {\syl@con }\add@madda 	% meteg 
\fi 
%\ifx #1\a@s \ch@lemtrue \else
\ifx #1a\ch@lemtrue \else
\ifx #1A\ch@lemtrue \else
\ifx #1Q\ch@lemtrue \else
\if \the\last@con \a@s \else
\ifx #1x\else        
	\add@wasla				% ldot
%\fi
\fi\fi\fi\fi\fi \put@syl \next }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \bhs@testpara #1#2{% single initial P ?
\ifx #1P\def \next {\bhs@para #1#2}%
\else \def \next {\bhs@word #1#2}%
\fi \next }

\def \bhs@para P#1>>{% prepare paragraph mark
\sc@back \bhspara #1>>}

\def \a@c@bhspara {% small paragraph mark
\putwordb@x {\small \heb@font \space \char '164 \space }\test@token }

\def \bhs@pasuq #1>>{% prepare verse division
\sc@back \pasuq #1>>}

\def \a@c@pasuq {% verse division
\putwordb@x {\small $\,|\,$}\test@token }

\def \bhs@query #1>>{% new line, push back the rest
\sc@back \|#1>>}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \a@bhs {bhs}        \def \a@BHS {BHS}
\let \bhs@setcode \setcode

\def \set@bhs {% substitute BHS scanner
\let \sc@beg \bhs@beg 	\let \sc@word \bhs@word  
\let \sc@back \sc@@back	\let \sc@endscan \sc@@endscan
\let \a@scan \a@@scan   \setbhs@codes	
\message {input coding set to BHS conventions}}

\def \setcode #1{\def \next {#1}% switch input coding
\ifx \next \a@bhs \set@bhs \else
\ifx \next \a@BHS \set@bhs \else
	\bhs@setcode {#1}
\fi\fi }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\message {scanner for code BHS installed.}

\catcode `\@ = \bhsatcode
\endinput
%%%%%%%%%%%%%%%%%%%%%%%% EOF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

