Reverse Index

<..reverse index..>
 \newcount\GetentriesN
 \GetentriesN=0
 \def\indexentry{\string\indexentry}
 \def\Ganchor{\ifnum \GetentriesN<10 0\fi
   \ifnum \GetentriesN<100 0\fi
   \ifnum \GetentriesN<1000 0\fi
   \the\GetentriesN}
 \def\Beforeentry{\let\getentries=\Getentries
    \let\Beforeentry=\beforeentry \Beforeentry}
 \def\Getentries#1#2{\endgroup
    \advance\GetentriesN by 1
    \let\parent=\empty
    \bparent#1|(<.par del.>\ifx \parent\empty
       \eparent#1|)<.par del.>\ifx \parent\empty
         \see#1|see|see<.par del.>%
         \ifx \isSee\empty <.no see entry.>%
         \else             <.yes see entry.>\fi
       \else
         \immediate\write\idx{\indexentry\the\split{%
            <.alt ind nun.>\string\erange{\csname \core|(\endcsname}
            \core<.alt ind nun.>\string\comNum}{#2}}%
       \fi
    \else
         \immediate\write\idx{\indexentry\the\split{%
            <.alt ind nun.>\string\brange{\Ganchor}
            \core<.alt ind nun.>\string\comNum}{#2}}%
         \expandafter\edef\csname \core|(\endcsname{\Ganchor}%
    \fi
 }
 -_-_-

<..no see entry..>
 \immediate\write\idx{\indexentry\the\split{%
            <.alt ind nun.>%
    #1<.alt ind nun.>\string\comNum}{#2}}%
 -_-_-

<..yes see entry..>
 \immediate\write\idx{\indexentry\the\split{%
    {\Ganchor}%
    \preSee\string\gobble|see{\isSee}}{#2}}%
 -_-_-

We want two references to the index numbers like in ‘\indexentry{\indNum{0006}...\indNum{0006}\comNum}{1}’ because the ‘\item \indNum{0006}...\indNum{0006}\comNum’ sometimes appear as ‘\item...\indNum{0006}\comNum’ with the first index being lost due to ‘@’ entries ‘\index{...@...}’.

<..alt ind nun..>
 \string\indNum{\Ganchor}%
 -_-_-