%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    Tages-Termin-Kalender erstellen    % 
%    von Andreas Schrell                %
%        Windhoevel 2                   %
%        5600 Wuppertal 2               %
%        Tel. 0202/666889               %
%    E-Mail: ma107 at dhafeu11.bitnet   %
%    Version 1.0 vom 9.10.1991          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentstyle{article}

%
%    Wochentag zu einem Datum ermitteln
%
\makeatletter
\newcount\@tag \newcount\@monat \newcount\@jahr
\newcount\@ja \newcount\@jb \newcount\@ha
\newcount\@hb \newcount\@hc \newcount\@b \newcount\@f
\newcount\Tag \newcount\Monat \newcount\Jahr \newcount\WT
\newcount\Woche \newcount\JT \newcount\RT \newcount\MAXT
\newcount\WTM

\def\Wochentag #1.#2.#3.{\@tag=#1\@monat=#2\@jahr=#3
\Tag#1\Monat#2\Jahr#3
\ifnum\@jahr<100\advance\@jahr by 1900\else\fi
\ifnum\@monat<3                         % if monat<3
 \advance\@monat by 10                  %   monat:=monat+10
 \advance\@jahr by -1                   %   jahr:=jahr-1
\else                                   % else
 \advance\@monat by -2                  %   monat:=monat-2
\fi                                     % fi
\@ja=\@jahr\divide\@ja by 100           % ja:=jahr/100
\@jb=-\@ja\multiply\@jb by 100
\advance \@jb by \@jahr                 % jb:=jahr-ja*100
\@ha=\@monat\multiply\@ha by 13
\advance\@ha by -1                      % ha:=13*monat-1
\divide\@ha by 5                        % ha:=ha/5
\@hb=\@jb\divide\@hb by 4               % hb:=jb/4
\@hc=\@ja\divide\@hc by 4               % hc:=ja/4
\@b=\@ha\advance\@b by \@hb
\advance\@b by \@hc                     % b:=ha+hb+hc
\@f=\@b\advance\@f by \@jb
\advance\@f by \@tag                    % f:=b+jb+tag
\multiply \@ja by 2
\advance\@f by -\@ja                    % f:=f-2*ja
\maketag}

\newif\ifFeiertag
\newif\ifMK \MKfalse
\def\FTT #1 #2 #3 {\ifnum\Monat=#2 \ifnum\Tag=#1
 \Feiertagtrue\def\Feiertagname{#3}%
\fi\fi}
\def\FTM #1 #2 #3 {\ifnum\Monat=#2 \ifnum\WTC=#1
 \Feiertagtrue\def\Feiertagname{#3}%
\fi\fi}
\def\testFeiertage{\Feiertagfalse
 \ifMK\let\FT\FTM\else\let\FT\FTT\fi
 \FT 1 1 Neujahr
 \FT 1 5 Maifeiertag
 \FT 3 10 {Tag der deutschen Einheit}
 \FT 1 11 Allerheiligen
 \FT 25 12 1.~Weihnachtstag
 \FT 26 12 2.~Weihnachtstag
\ifnum\Jahr=1991
 \FT 20 11 Bu\ss-~und~Bettag
\fi
\ifnum\Jahr=1992
 \FT 17 4 Karfreitag
 \FT 19 4 Ostern
 \FT 20 4 Ostern
 \FT 28 5 Himmelfahrt
 \FT 7 6 Pfingsten
 \FT 8 6 Pfingsten
 \FT 18 6 Fronleichnam
 \FT 18 11 Bu\ss-~und~Bettag
\fi
\ifnum\Jahr=1993
 \FT 9 4 Karfreitag
 \FT 11 4 Ostern
 \FT 12 4 Ostern
 \FT 20 5 Himmelfahrt
 \FT 30 5 Pfingsten
 \FT 31 5 Pfingsten
 \FT 10 6 Fronleichnam
 \FT 17 11 Bu\ss-~und~Bettag
\fi
\ifnum\Jahr=1994
 \FT 1 4 Karfreitag
 \FT 3 4 Ostern
 \FT 4 4 Ostern
 \FT 12 5 Himmelfahrt
 \FT 22 5 Pfingsten
 \FT 23 5 Pfingsten
 \FT 2 6 Fronleichnam
 \FT 16 11 Bu\ss-~und~Bettag
\fi
}

\def\MAXTberechnen{
 \MAXT=
 \ifcase\Monat
   -1\or 31\or 28\or 31\or 30\or 31\or 30\or 31\or 31\or
   30\or 31\or 30\or 31\else \ddt \fi\relax
 \ifnum\Monat=2
   \@ha=\Jahr \divide\@ha by 4 \multiply \@ha by 4
   \ifnum\@ha=\Jahr \advance \MAXT by 1\fi
   \@ha=\Jahr \divide\@ha by 100 \multiply \@ha by 100
   \ifnum\@ha=\Jahr \advance \MAXT by -1\fi
   \@ha=\Jahr \divide\@ha by 400 \multiply \@ha by 400
   \ifnum\@ha=\Jahr \advance \MAXT by 1\fi
 \fi\relax}

\def\maketag{\@ha=\@f
\divide\@ha by 7
\multiply\@ha by 7
\advance\@f by -\@ha                    % f:= f mod 7
\WT=\@f
\edef\Tagname{\ifcase\@f
           Sonntag\or Montag\or Dienstag\or Mittwoch\or Donnerstag\or
           Freitag\or Samstag\else ????????\fi}
\edef\Monatname{\ifcase\Monat \ddt\or
                Januar\or Februar\or M\"arz\or April\or Mai\or Juni\or
                Juli\or August\or September\or Oktober\or November\or
                Dezember\else ????????\fi}}

\def\nexttag{\advance\@f by 1
 \advance\JT by 1 \advance\RT by -1
 \advance\Tag by 1
 \ifnum\Tag>\MAXT
   \Tag=1
   \advance\Monat by 1
   \ifnum\Monat>12 \Monat=1 \advance\Jahr by 1 \fi
   \MAXTberechnen
 \fi\relax
 \maketag
 \ifnum\WT=1\advance\Woche by 1\fi\relax
 \ifnum\Tag=1 \WTM=\WT\fi}

\newcount\Malc \newcount\WTC

\newbox\Monatsbox

\def\Monatskalender{\maketag\MKtrue
 \WTC=\WTM \ifnum\WTC=0\relax\WTC=7\fi
 \global\Malc=\WTC
\setbox\Monatsbox=\vbox{\hsize=4cm\small
 \noindent\setbox0\hbox{00}\underline{\strut
 \hbox to \wd0{\hss Mo\hss}\ \ \hbox to \wd0{\hss Di\hss}\ \
 \hbox to \wd0{\hss Mi\hss}\ \ \hbox to \wd0{\hss Do\hss}\ \
 \hbox to \wd0{\hss Fr\hss}\ \ \hbox to \wd0{\hss Sa\hss}\ \
 \hbox to \wd0{\hss\bf So\hss}}\vskip 1mm
 \noindent
 \loop
 \ifnum\WTC>1\relax
   \advance\WTC by -1
   \phantom{00}\ \
 \repeat
 \WTC=1
 \loop
   {\testFeiertage
   \ifFeiertag\global\let\FTF\it\else\global\let\FTF\relax\fi}%
 \ifnum\WTC<\MAXT\relax
   {\ifnum\Malc=7\bf\fi\FTF
    \ifnum\WTC<10\relax\phantom{0}\fi
    \ifnum\Tag=\WTC\underline{\the\WTC}\else\the\WTC\fi}%
   {\ifnum\Malc=7\relax \\ \global\Malc=0\else\ \ \fi}%
   \global\advance\Malc by 1
   \advance\WTC by 1
 \repeat{\ifnum\Malc=7\bf\fi\FTF
   \ifnum\Tag=\WTC\underline{\the\WTC}\else\the\WTC\fi}\par}\MKfalse}

\arrayrulewidth=0.00333in
\tabcolsep=2pt \doublerulesep=0pt
\fboxrule=\arrayrulewidth
\fboxsep=-\fboxrule
\pagestyle{empty}
\oddsidemargin=-1cm
\topmargin=-1cm
\advance\vsize by 1cm
\headheight=0pt
\headsep=0pt

\def\Initialisierung{\newbox\BoxA
 \setbox\BoxA\hbox{\begin{tabular*}{12cm}%
 {|l|@{\extracolsep{\fill}}l@{\extracolsep{0pt}}*{6}{|c}|}
 \hline
 \vrule height11pt width0pt
 Uhr & T\"atigkeit & P & T & S & Pri & Zeit & ok \\
 \hline\hline
 \phantom{0}\lower1pt\hbox{7:}\phantom{00}
 & \hbox to 7cm{\hss} & & & & & & \\ \hline
 \phantom{0}\lower1pt\hbox{8:} & & & & & & & \\ \hline
 \phantom{0}\lower1pt\hbox{9:} & & & & & & & \\ \hline
 \lower1pt\hbox{10:} &  & & & & & & \\ \hline
 \lower1pt\hbox{11:} &  & & & & & & \\ \hline
 \lower1pt\hbox{12:} &  & & & & & & \\ \hline
 \lower1pt\hbox{13:} &  & & & & & & \\ \hline
 \lower1pt\hbox{14:} &  & & & & & & \\ \hline
 \lower1pt\hbox{15:} &  & & & & & & \\ \hline
 \lower1pt\hbox{16:} &  & & & & & & \\ \hline
 \lower1pt\hbox{17:} &  & & & & & & \\ \hline
 \lower1pt\hbox{18:} &  & & & & & & \\ \hline
 \lower1pt\hbox{19:} &  & & & & & & \\ \hline
 \lower1pt\hbox{20:} &  & & & & & & \\ \hline
 \lower1pt\hbox{21:} &  & & & & & & \\ \hline
 \lower1pt\hbox{22:} &  & & & & & & \\ \hline \hline
 \multicolumn{2}{|l|}{} & & & & & & \\ \hline
 \multicolumn{2}{|l|}{} & & & & & & \\ \hline
 \multicolumn{2}{|l|}{} & & & & & & \\ \hline
 \multicolumn{2}{|l|}{} & & & & & & \\ \hline
 \multicolumn{2}{|l|}{} & & & & & & \\ \hline
 \multicolumn{2}{|l|}{} & & & & & & \\ \hline
 \multicolumn{2}{|l|}{} & & & & & & \\ \hline
 \multicolumn{2}{|l|}{} & & & & & & \\ \hline
 \multicolumn{2}{|l|}{} & & & & & & \\ \hline
 \multicolumn{2}{|l|}{} & & & & & & \\ \hline
 \multicolumn{2}{|l|}{} & & & & & & \\ \hline
 \end{tabular*}}}

\def\Tageskalender{\Monatskalender
 \testFeiertage
 \vbox{\ifFeiertag\vglue-7mm\fi
 \ifFeiertag\hbox{\framebox{\vbox to 7mm{\vss\hbox to 12cm{\hss
 \bf\Feiertagname\hss}\vss}}}\nointerlineskip\fi
 \hbox{%
 \framebox{\vbox to 7mm{\vss\hbox to 4cm{\hss
 \Large\bf\vrule height13pt width0pt\Tagname\hss}\vss}}%
 \framebox{\vbox to 7mm{\vss\hbox to 8cm{\hss
 \Large\bf\vrule height13pt width0pt\relax \the\Tag.
           \Monatname\ (\the\Monat)\ \ \the\Jahr\hss}\vss}}}%
 \nointerlineskip
 \hbox{\bf
 \framebox{\vbox to 7mm{\vss
       \hbox to 4cm{\hss\vrule height12pt width0pt
       \the\Woche. Woche\hss}\vss}}%
 \framebox{\vbox to 7mm{\vss\hbox to 4cm{\hss\vrule height12pt width0pt
       \the\JT. Tag\hss}\vss}}%
 \framebox{\vbox to 7mm{\vss\hbox to 4cm{\hss\vrule height12pt width0pt
       \the\RT\ Resttage
           \hss}\vss}}}%
 \vskip 3mm
 \copy\BoxA
 \vskip 3mm
 \hbox{\vbox{\hbox{%
 \framebox{\vbox to 2cm{\hbox to 7cm{\ Gedenktage:
 \vrule height11pt width0pt\strut\hss}
 \hrule height 0.00333in\vss
 \hrule height 0.00333in\vss
 \hrule height 0.00333in\vss
 \hrule height 0.00333in\vss
}}}%
 \offinterlineskip
 \hbox{%
 \framebox{\vbox to 2cm{\hbox to 7cm{\ Notizen:
 \vrule height11pt width0pt\strut\hss}
 \hrule height 0.00333in\vss
 \hrule height 0.00333in\vss
 \hrule height 0.00333in\vss
 \hrule height 0.00333in\vss
}}}}%
 \framebox{\vbox to 4cm{\vss
       \hbox to 5cm{\hss\vbox{\hsize=4cm
       \hbox{\bf\Monatname\ \the\Jahr}\vskip 4mm
       \copy\Monatsbox\par}\hss}\vss}}}}%
}


%%%%%%%%%%%%%%%%
% Es geht los: %
%%%%%%%%%%%%%%%%

\message{Anfangsdatum (xx.xx.xxxx): }
\read-1 to \AFD

\newcount\AT
\message{Anzahl der Tage (eine Seite pro Tag!): }
\read-1 to \AZT
\AT=\AZT

\newcount\startt \newcount\startm
\newif\ifweiter

\expandafter\Wochentag \AFD.

\startt=\Tag\startm=\Monat
\Tag=1\Monat=1\JT=1\Woche=1
\Wochentag 1.1.\the\Jahr.
\MAXTberechnen

\RT=364
\@ha=\Jahr \divide\@ha by 4 \multiply \@ha by 4
\ifnum\@ha=\Jahr \advance \RT by 1\fi
\@ha=\Jahr \divide\@ha by 100 \multiply \@ha by 100
\ifnum\@ha=\Jahr \advance \RT by -1\fi
\@ha=\Jahr \divide\@ha by 400 \multiply \@ha by 400
\ifnum\@ha=\Jahr \advance \RT by 1\fi

\message{Ich berechne die Daten des ersten Tages. }
\message{Bitte etwas Geduld. }
\loop
{\global\weitertrue
 \ifnum\Monat=\startm
   \ifnum\Tag=\startt
     \global\weiterfalse
   \fi
  \fi}%
\ifweiter %\fi
 \nexttag
\repeat

\Initialisierung

\makeatother

\begin{document}

\loop
\ifnum\AT>0 %\fi
 \advance\AT by -1
 \message{(\Tagname, \the\Tag. \Monatname\space \the\Jahr,
 noch zu setzen: \the\AT\space\ifnum\AT=1 Tag\else Tage\fi) ........ }
 \Tageskalender\clearpage
 \nexttag
\repeat

\end{document}
