%%
%% This is file `statistik.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% statistik.dtx  (with options: `package')
%% 
%% statistik.sty  -- Statistiken ^^fcber Kapitel erstellen
%% Copyright (C) 2003 Michael Niedermair
%% 
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation; either version 2 of the License, or
%% (at your option) any later version.
%% 
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%% 
%% You should have received a copy of the GNU General Public License
%% along with this program; if not, write to the Free Software
%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{statistik}
  [2003/04/05 v0.03 Statistiken ^^fcber Kapitel erstellen (mgn)]
\RequirePackage{keyval}
\newcommand{\stafilename}{\jobname-info.tex}
\newcommand{\staenconding}{latin1}
\newcommand{\staxmlencoding}{ISO-8859-1}
\newcommand{\staheader}{}
\newcommand{\stafoot}{}
\newcommand{\stabody}[3]{%
#1 #2 #3 ^^J%
}
\newcommand{\statabline}{}
\newcommand{\stabegincommand}{}
\define@key{Sta}{encoding}[latin1]{\renewcommand{\staenconding}{#1}}
\define@key{Sta}{xmlencoding}[ISO-8859-1]{%
  \renewcommand{\staxmlenconding}{#1}}
\define@key{Sta}{textable}[true]{%
  \renewcommand{\stafilename}{\jobname-info.tex}
  \renewcommand{\staheader}{%
    \string\documentclass{article}^^J%
    \string\usepackage[\staenconding]\string{inputenc\string}^^J%
    \string\usepackage[ngerman]{babel}^^J%
    \string\begin{document}^^J%
    \string\begin{tabular}{|c|l|c|}\string\hline^^J%
    Nummer & Titel & Seiten \string\\\string\hline\string\hline%
  }
  \renewcommand{\statabline}{}
  \renewcommand{\stafoot}{%
    \string\hline^^J%
    \string\end{tabular}^^J%
    \string\end{document}^^J%
  }
  \renewcommand{\stabody}[3]{%
    ##1 & ##2\space & ##3 \string\\\statabline%
  }
  \renewcommand{\stabegincommand}{%
    \AtBeginDocument{%
      \WrtStatistik{\staheader}%
      \AtEndDocument{%
        \clearpage\ShowPagesOfThisChapter{}%
        \WrtStatistik{\stafoot}%
      }%
    }
  }
}
\define@key{Sta}{table}[true]{%
  \renewcommand{\stafilename}{\jobname-info.tex}
  \renewcommand{\staheader}{%
    \string\begin{tabular}{|c|l|c|}\string\hline^^J%
    Nummer & Titel & Seiten \string\\\string\hline\string\hline%
  }
  \renewcommand{\statabline}{}
  \renewcommand{\stafoot}{%
    \string\hline^^J%
    \string\end{tabular}^^J%
  }
  \renewcommand{\stabody}[3]{%
    ##1 & ##2\space & ##3 \string\\\statabline%
  }
  \renewcommand{\stabegincommand}{%
    \AtBeginDocument{%
      \WrtStatistik{\staheader}%
      \AtEndDocument{%
        \clearpage\ShowPagesOfThisChapter{}%
        \WrtStatistik{\stafoot}%
      }%
    }
  }
}
\define@key{Sta}{csv}[true]{%
  \renewcommand{\stafilename}{\jobname-info.csv}
  \renewcommand{\staheader}{}
  \renewcommand{\stafoot}{}
  \renewcommand{\stabody}[3]{##1;##2;##3}
  \renewcommand{\statabline}{}
  \renewcommand{\stabegincommand}{%
    \AtEndDocument{\clearpage\ShowPagesOfThisChapter{}}
  }
}
\define@key{Sta}{xml}[true]{%
  \renewcommand{\stafilename}{\jobname-info.xml}
  \renewcommand{\staheader}{%
    <?xml version= "1.0" encoding="\staxmlencoding" ?>^^J<dokument>}
  \renewcommand{\stafoot}{</dokument>}
  \renewcommand{\stabody}[3]{%
    <kapitel><nr>##1</nr><titel>##2</titel><seiten>##3</seiten></kapitel>}
  \renewcommand{\statabline}{}
  \renewcommand{\stabegincommand}{%
    \AtBeginDocument{%
      \WrtStatistik{\staheader}%
      \AtEndDocument{\clearpage\ShowPagesOfThisChapter{}%
        \WrtStatistik{\stafoot}%
      }%
    }%
  }
}
\def\ProcessOptionsWithKV#1{%
  \let\@tempc\relax
  \let\Sta@tempa\@empty
  \@for\CurrentOption:=\@classoptionslist\do{%
    \@ifundefined{KV@#1@\CurrentOption}%
    {}%
    {\edef\Sta@tempa{\Sta@tempa,\CurrentOption,}}%
  }%
  \edef\Sta@tempa{%
    \noexpand\setkeys{#1}{%
      \Sta@tempa\@ptionlist{\@currname.\@currext}%
    }%
  }%
  \Sta@tempa
}
\ProcessOptionsWithKV{Sta}
\AtEndOfPackage{%
  \let\@unprocessedoptions\relax
}
\newwrite\Statistik
\immediate
\openout\Statistik=\stafilename
\stabegincommand
\newcommand*{\WrtStatistik}{\immediate\write\Statistik}
\newcounter{lastchapterfirstpage}\setcounter{lastchapterfirstpage}{-1}
\newcounter{lastchapterpages}
\newcommand*{\Orig@Chapter}{}
\let\Orig@Chapter=\chapter
\newcommand*\TitleOfLastChapter{}
\newcommand*\XTitleOfLastChapter{}
\newcommand*{\ShowPagesOfThisChapter}[2][\thechapter]{%
  \ifnum \value{lastchapterfirstpage}>-1
  \setcounter{lastchapterpages}{\value{page}}%
  \addtocounter{lastchapterpages}{-\value{lastchapterfirstpage}}%
  \WrtStatistik{\stabody{#1}{\XTitleOfLastChapter}{\thelastchapterpages}}%
  \fi
  \renewcommand*{\TitleOfLastChapter}{#2}%
  \expandafter\edef\expandafter\XTitleOfLastChapter\expandafter{%
    \expandafter\strip@prefix\meaning\TitleOfLastChapter}%
}
\newcommand*{\St@schapter}[1]{%
  \ShowPagesOfThisChapter{#1}%
  \setcounter{lastchapterfirstpage}{\value{page}}%
  \Orig@Chapter*{#1}}
\newcommand*{\St@chapter}[2][]{%
  \ShowPagesOfThisChapter{#1}% oder #2 f^^fcr den langen Titel
  \setcounter{lastchapterfirstpage}{\value{page}}%
  \Orig@Chapter[{#1}]{#2}}
\renewcommand*{\chapter}{%
  \if@twoside\cleardoublepage\else\clearpage\fi
  \secdef\St@chapter\St@schapter
}
\endinput
%%
%% End of file `statistik.sty'.
