\ProvidesPackage{ktv-buildnum}[2003/10/10 v1.5  KTV, Build Number]
\def\bld@ext{.ktvnum}
\def\bld@ext@old{.xka}
\def\builnumfile{\jobname}
\AtBeginDocument{
  \newwrite\bld@ostream
  \newcount\buildnum
  \IfFileExists{\builnumfile\bld@ext}%
    {\@@input\builnumfile\bld@ext\relax}%
    {\buildnum=0}
  \IfFileExists{\builnumfile\bld@ext@old}
    {%\begingroup
      \newcount\tmp@cnt \tmp@cnt=\buildnum
      \@@input\builnumfile\bld@ext@old\relax
      \ifnum\tmp@cnt>\buildnum        
        \global\buildnum=\tmp@cnt
      \fi
    %\endgroup
    }{}  
  \advance\buildnum1 %
  \immediate\openout\bld@ostream\builnumfile\bld@ext %
  \immediate\write\bld@ostream{\string\buildnum=\the\buildnum}%
  \immediate\closeout\bld@ostream{}%
}
\endinput
% END OF FILE