%%
%% This is file `bibleref-xidx.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% bibleref.dtx  (with options: `bibleref-xidx.sty,package')
%% 
%%  bibleref.dtx
%%  Copyright 2011 Nicola Talbot
%% 
%%  This work may be distributed and/or modified under the
%%  conditions of the LaTeX Project Public License, either version 1.3
%%  of this license of (at your option) any later version.
%%  The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%%  and version 1.3 or later is part of all distributions of LaTeX
%%  version 2005/12/01 or later.
%% 
%%  This work has the LPPL maintenance status `maintained'.
%% 
%%  The Current Maintainer of this work is Nicola Talbot.
%% 
%%  This work consists of the files bibleref.dtx and bibleref.ins and the derived files bibleref-xidx.sty, bibleref.sty, sample-categories.tex, sample-indextools.tex, sample-xidx.tex, sample.tex, sample.ist.
%% 
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bibleref-xidx}[2011/01/19 v1.0 (NLCT) Extended indexing support for bibleref]
\newif\if@br@indexchapters
\@br@indexchapterstrue
\newif\if@br@indexverses
\@br@indexversestrue
\DeclareOption{verses}{\@br@indexchapterstrue\@br@indexversestrue}
\DeclareOption{noverses}{\@br@indexversesfalse}
\DeclareOption{chapters}{\@br@indexchaptersfalse}
\DeclareOption{nochapters}{\@br@indexchaptersfalse\@br@indexversesfalse}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{bibleref}}
\ProcessOptions
\RequirePackage{bibleref}
\def\@bibleverse(#1:{%
  \def\@bv@chidxsort{}%
  \def\@bv@chidxentry{}%
  \@br@chsty{#1}%
  \@@bibleverse
}
\def\@bibleverser-(#1:{%
  \def\@bv@chidxsort{}%
  \def\@bv@chidxentry{}%
  \@br@chsty{#1}%
  \@@bibleverse
}
\def\@@bibleverse#1){%
  \def\@bv@tmp{#1}%
  \ifx\@bv@tmp\@empty
    \@bvx@dochindex
  \else
    \BRchvsep
    \@br@vrsty{#1}%
  \fi
  \new@ifnextchar(%
    {\BRchsep\@bibleverse}%
    {\new@ifnextchar-%
       {\protect\BRvrsep\@bibleverser}%
       {\@end@@bibleverse}%
    }%
}
\newcommand*{\@brx@dochsep}{%
  \@bvx@chdo{\protect\BRvsep}%
}
\renewcommand*{\@br@chsty}[1]{%
  \let\@brx@chsep\@empty
  \@for\@brx@thisch:=#1\do{%
    \@bvx@dochindex
    \@brx@chsep
    \expandafter\@@br@chsty\@brx@thisch-\@nil\end
    \let\@brx@chsep\@brx@dochsep
  }%
}
\newcommand*{\@brx@dovssep}{%
  \@bvx@vsdo{\protect\BRvsep}%
}
\renewcommand*{\@br@vrsty}[1]{%
  \let\@brx@vssep\@empty
  \@for\@brx@thisvs:=#1\do{%
    \def\@bv@vsidxentry{}%
    \def\@bv@vsidxsort{}%
    \@brx@vssep
    \expandafter\@@br@vrsty\@brx@thisvs-\@nil\end
    \let\@brx@vssep\@brx@dovssep
    \@bvx@dovsindex
  }%
}
\def\@@br@vrsty#1-#2\end{%
  \ifx\@nil#2\relax
    \@do@verse{#1}%
  \else
    \@do@verserange{#1}#2%
  \fi
}
\renewcommand{\@do@verse}[1]{%
  \@nodo@verse{#1}%
  \expandafter\@bvx@vsdo\expandafter{\@br@tmp}%
  \@bv@addtovsidxsort{-000}%
}
\def\@@br@chsty#1-#2\end{%
  \ifx\@nil#2\relax
    \@do@chapter{#1}%
  \else
    \@do@chapterrange{#1}#2%
  \fi
}
\newcommand{\@do@chapter}[1]{%
  \@nodo@chapter{#1}%
  \@bvx@chdo{\protect\BRchapterstyle{#1}}%
  \@bv@addtochidxsort{-000}%
}
\renewcommand*{\@nodo@chapter}[1]{%
  \ifnum0#1<10\relax
    \@bv@setchidxsort{00#1}%
  \else
    \ifnum0#1<100\relax
      \@bv@setchidxsort{0#1}%
    \else
      \@bv@setchidxsort{#1}%
    \fi
  \fi
}
\def\@do@chapterrange#1#2-\@nil{%
  \@nodo@chapter{#1}%
  \@bvx@chdo{\protect\BRchapterstyle{#1}}%
  \@bv@addtochidxsort{-}%
  \@bvx@chadddo{\protect\BRvrsep}%
  \@nodo@chapter{#2}%
  \@bvx@chadddo{\protect\BRchapterstyle{#2}}%
}
\renewcommand*{\@nodo@verse}[1]{%
  \br@stripverse{#1}%
  \ifnum\@br@versenum<10\relax
    \@bv@addtovsidxsort{00#1}%
  \else
    \ifnum\@br@versenum<100\relax
      \@bv@addtovsidxsort{0#1}%
    \else
      \@bv@addtovsidxsort{#1}%
    \fi
  \fi
  \ifx\@br@versesuffix\@empty
    \protected@edef\@br@tmp{%
       \protect\BRversestyle{\@br@versenum}%
    }%
  \else
    \protected@edef\@br@tmp{%
       \protect\BRversestyle{\@br@versenum}%
       \protect\BRversesuffixstyle{\@br@versesuffix}%
    }%
  \fi
}
\def\@do@verserange#1#2-\@nil{%
  \@nodo@verse{#1}%
  \expandafter\@bvx@vsdo\expandafter{\@br@tmp}%
  \@bv@addtovsidxsort{-}%
  \@bvx@vsadddo{\protect\BRvrsep}%
  \@nodo@verse{#2}%
  \expandafter\@bvx@vsadddo\expandafter{\@br@tmp}%
}
\newcommand*{\@bv@setvsidxsort}[1]{%
\if@bv@idx
  \protected@edef\@bv@vsidxsort{#1}%
\fi
}
\newcommand*{\@bv@addtovsidxsort}[1]{%
\if@bv@idx
  \@bv@tmpa={#1}%
  \@bv@tmpb=\expandafter{\@bv@vsidxsort}%
  \protected@edef\@bv@vsidxsort{\the\@bv@tmpb\the\@bv@tmpa}%
\fi
}
\newcommand*{\@bv@setvsidx}[1]{%
\if@bv@idx
  \def\@bv@vsidxentry{#1}%
\fi
}
\newcommand*{\@bv@addtovsidx}[1]{%
\if@bv@idx
  \@bv@tmpa={#1}%
  \@bv@tmpb=\expandafter{\@bv@vsidxentry}%
  \protected@edef\@bv@vsidxentry{\the\@bv@tmpb\the\@bv@tmpa}%
\fi
}
\newcommand*{\@bv@setchidx}[1]{%
\if@bv@idx
  \def\@bv@chidxentry{#1}%
\fi
}
\newcommand*{\@bv@addtochidx}[1]{%
\if@bv@idx
  \@bv@tmpa={#1}%
  \@bv@tmpb=\expandafter{\@bv@chidxentry}%
  \protected@edef\@bv@chidxentry{\the\@bv@tmpb\the\@bv@tmpa}%
\fi
}
\newcommand*{\@bv@setchidxsort}[1]{%
\if@bv@idx
  \protected@edef\@bv@chidxsort{#1}%
\fi
}
\newcommand*{\@bvx@chdo}[1]{#1\@bv@setchidx{#1}}
\newcommand*{\@bvx@vsdo}[1]{#1\@bv@setvsidx{#1}}
\newcommand*{\@bvx@chadddo}[1]{#1\@bv@addtochidx{#1}}
\newcommand*{\@bvx@vsadddo}[1]{#1\@bv@addtovsidx{#1}}
\let\@bv@org@bible@verse\@bible@verse
\renewcommand*{\@bible@verse}{%
  \def\@bv@chidxentry{}%
  \@bv@org@bible@verse
}
\renewcommand*{\@end@@bibleverse}{%
  \ifx\@bv@chidxentry\@empty
    \@bvx@dobkindex
  \else
    \if@br@indexchapters
    \else
       \@bvx@dobkindex
    \fi
  \fi
  \@bv@idxfalse
  \@bv@restore
}
\newcommand*{\@bvx@dochindex}{%
\if@br@indexchapters
  \ifx\@bv@chidxentry\@empty
  \else
    \if@bv@idx
      \expandafter\@do@bibleref@map\@@bv@idxsort\relax
      \@do@biblerefindex
        {\@@bv@idxsort\relax @\@bv@mainidxentry
           !\@bv@chidxsort @\@bv@chidxentry
           |\@bv@idxpgformat}%
    \fi
  \fi
\fi
}
\newcommand*{\@bvx@dovsindex}{%
\if@br@indexverses
  \ifx\@bv@vsidxentry\@empty
  \else
    \if@bv@idx
      \expandafter\@do@bibleref@map\@@bv@idxsort\relax
      \@do@biblerefindex
        {\@@bv@idxsort\relax @\@bv@mainidxentry
           !\@bv@chidxsort @\@bv@chidxentry
           !\@bv@vsidxsort @\@bv@vsidxentry
           |\@bv@idxpgformat}%
    \fi
  \fi
\else
  \@bvx@dochindex
\fi
}

\newcommand*{\@bvx@dobkindex}{%
  \if@bv@idx
    \expandafter\@do@bibleref@map\@@bv@idxsort\relax
    \@do@biblerefindex
      {\@@bv@idxsort\relax @\@bv@mainidxentry|\@bv@idxpgformat}%
  \fi
}
\endinput
%%
%% End of file `bibleref-xidx.sty'.
