%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% calender.sty:
% 2005/11/28/ tsakurai@rimath.saitama-u.ac.jp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{calender}[2005/11/28]
\RequirePackage{color}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagestyle{empty}
\topmargin =-1in
\oddsidemargin =-1in
\evensidemargin=-1in
\headheight=0pt
\headsep=0pt
\topskip=0pt
\parindent=0pt
\splittopskip=0pt
\unitlength=1mm
%
\def\bye{\begin{document}\end{document}}
{\catcode`\p=12\catcode`\t=12\gdef\rmPT#1pt{#1}}
\def\val#1{\expandafter\rmPT\the#1}
\long\def\xy(#1,#2)#3{{\everypar{}\baselineskip0pt\lineskip0pt
  \evald{\dimen1}{#1}\evald{\dimen2}{#2}%
  \hbox to0pt{\kern\dimen1\vbox to0pt{\kern\dimen2{#3}\vss}\hss}}}
\long\def\base(#1,#2)#3{\xy(#1,#2){\smash{\kern0pt#3}}}
{\catcode`\@=11\global\let\lw=\@wholewidth}\lw=.75bp
\def\HLine(#1,#2)(#3,#4){{% #4 �� dummy parameter
  \eval\leftx{#1}\evald\hsize{#3-(#1)}%
  \ifdim\hsize<0pt\hsize=-\hsize\def\leftx{#3}\fi\advance\hsize\lw
  \base(\leftx,#2){\kern-.5\lw\vrule width\hsize height.5\lw depth.5\lw}}}
\def\VLine(#1,#2)(#3,#4){{% #3 �� dummy parameter
  \eval\topy{#2}\evald\vsize{#4-(#2)}%
  \ifdim\vsize<0pt\vsize=-\vsize\def\topy{#4}\fi\advance\vsize\lw
  \xy(#1,\topy){\kern-.5\lw\rlap{\kern-.5\lw\vrule width\lw height\vsize}}}}
\def\forxx#1\do#2{\def\body{#2}\expandafter\bodyfor#1,\relax,}
\def\bodyfor#1,{\ifx\relax#1\else\def\xx{#1}\body\expandafter\bodyfor\fi}
\def\hboxto#1#2{{\evald\hsize{#1}\leavevmode\hbox to\hsize{#2\hss}}}
\def\ptop#1#2{{\evald\hsize{#1}\leavevmode\parbox[t]{\hsize}{#2}}}
%
\newtoks\expr
\newskip\xAA
\newskip\stacktop
\def\pushback#1#2{#1\expandafter{\the#1#2}}
\def\scan#1{%
  \ifx#1\relax\else
    \ifx#1(\pushback\expr{\Op\(,}\else
    \ifx#1)\pushback\expr{,\Op\)}\else
    \ifx#1+\pushback\expr{,\Op\+,}\else
    \ifx#1-\pushback\expr{,\Op\-,}\else
    \ifx#1*\pushback\expr{,\Op\*,}\else 
    \ifx#1/\pushback\expr{,\Op\/,}\else
           \pushback\expr{#1}\relax
    \fi\fi\fi\fi\fi\fi
    \expandafter\scan
  \fi}
\def\eval#1#2{\expr{}\scan(#2)\relax\evalx{\expr}\ratio#1{\xAA}{\unitlength}}
\def\xval#1#2{\eval\tempxx{#2}\xdef#1{\tempxx}}
\def\evalc#1#2{\expr{}\scan(#2)\relax\evalx{\expr}\edef#1{\the\xAA}}
\def\evald#1#2{\expr{}\scan(#2)\relax\evalx{\expr}#1=\xAA}
\def\evalx#1{{%
  \def\({\pushOp{\putA}\pushOp{\putA}}%
  \def\){\popOp\popOp}%
  \def\+{\popOp\popOp\pushOp{\addA}\pushOp{\putA}}%
  \def\-{\popOp\popOp\pushOp{\subA}\pushOp{\putA}}%
  \def\*{\popOp\pushOp{\mulbyA}}%
  \def\/{\popOp\pushOp{\divbyA}}%
  \def\pushOp##1{\begingroup\aftergroup##1}%
  \def\popOp{\global\xAA=\stacktop\endgroup}%
  \def\putA{\stacktop=\xAA}%
  \def\addA{\advance\stacktop+\xAA}%
  \def\subA{\advance\stacktop-\xAA}%
  \def\mulbyA{\ratio\rr{\xAA}{\unitlength}\stacktop=\rr\stacktop}%
  \def\divbyA{\ratio\rr{\stacktop}{\xAA}\stacktop=\rr\unitlength}%
  \forxx\the#1\do{%
    \expandafter\ifx\expandafter\Op\xx\relax\else
    \ifx\xx\empty\stacktop=0pt\else
      \afterassignment\gobbletorelax\stacktop=\xx\unitlength\relax
    \fi\fi
  }\global\xAA=\stacktop}}
\def\gobbletorelax#1\relax{}
\def\ratio#1#2#3{{% #1<-(#2/#3)
  \dimendef\RA22\dimendef\RB23\relax
  \gdef\rtmp{}\RA=#2\relax\RB=#3\relax
  \ifdim\RB<0pt\RB=-\RB\RA=-\RA\relax\fi
  \ifdim\RA<0pt\RA=-\RA\gdef\rtmp{-}\fi
  \dimen1=\RA\divide\dimen1\RB
  \xdef\rtmp{\rtmp\number\dimen1.}%
  \count1=6\loop\ifnum\count1>0\advance\count1-1
    \multiply\dimen1\RB\advance\RA-\dimen1
    \RA=10\RA\dimen1=\RA\divide\dimen1\RB
    \xdef\rtmp{\rtmp\number\dimen1}%
  \repeat}\edef#1{\rtmp}}
%%EOF of teikei.sty

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newtoks\Month
\newcount\NumDays
\newcount\FirstDay

\def\cal(#1,#2){
  \if*#1\else\year=#1\fi
  \if*#2
    \calx(\year,1--12)%
  \else\ifnum12<#23
    \calx(\year,#2--#2)%
  \else
    \calx(\year,#2)%
  \fi\fi
  \relax}

\def\calx(#1,#2--#3){%
  \year=#1\month=#2
  \loop\ifnum\month>#3\relax\else
    \typeout{\the\year/\the\month}
    \PrintMonth
    \advance\month+1
  \repeat
  \relax}

\def\PrintMonth{{
\ifcase\month\or
 \Month{January}   \NumDays=31\or
 \Month{February}  \NumDays=28\or
 \Month{March}     \NumDays=31\or
 \Month{April}     \NumDays=30\or
 \Month{May}       \NumDays=31\or
 \Month{June}      \NumDays=30\or
 \Month{July}      \NumDays=31\or
 \Month{August}    \NumDays=31\or
 \Month{September} \NumDays=30\or
 \Month{October}   \NumDays=31\or
 \Month{November}  \NumDays=30\or
 \Month{December}  \NumDays=31\or
 \relax\fi
\def\mod##1{{\count0=\count255\divide\count0by##1\multiply\count0by##1
             \global\advance\count255-\count0}\ignorespaces}
\ifnum\month=2\relax
  \count255=\year
  \mod{400}\ifnum\count255=0\advance\NumDays+1\fi
  \mod{100}\ifnum\count255=0\advance\NumDays-1\fi
  \mod{  4}\ifnum\count255=0\advance\NumDays+1\fi
\fi

\ifnum\month<3\advance\year-1\advance\month+12\fi
\count255=\year
{\divide\year by   4\global\advance\count255+\year}
{\divide\year by 100\global\advance\count255-\year}
{\divide\year by 400\global\advance\count255+\year}
{\multiply\month26\advance\month+16\divide\month by10
                    \global\advance\count255+\month}
\advance\count255+1\mod7
\FirstDay=\count255
\ifnum\month>12\advance\year+1\advance\month-12\relax\fi

\count255=\FirstDay\advance\count255+\NumDays
\advance\count255+6\divide\count255by7
\xdef\nrows{\the\count255}%
%\edef\nrows{5}%

%<<
\hsize=190mm
\vsize=260mm
\def\lx{10mm}
\def\ty{40mm}
\def\hh{10mm}

\ifnum\nrows=6\voffset=-10mm\fi
\base(\lx,\ty-\hh-4mm){\Huge\sf\ \the\Month\ \ \the\year}
\HLine(\lx,\ty-\hh)(\lx+\hsize,*)
\edef\x{\lx}
\count255=8
\loop\ifnum\count255>0\advance\count255-1
  \VLine(\x,\ty-\hh)(\x,\ty+\nrows*\vsize/6)
  \eval\x{\x+\hsize/7}%
\repeat

\count255=\nrows
\advance\count255+1
\edef\y{\ty}
\loop\ifnum\count255>0\advance\count255-1
  \HLine(\lx,\y)(\lx+\hsize,*)
  \eval\y{\y+\vsize/6}%
\repeat

\base(\lx,\ty-2.5mm){\huge\sf
  \color[rgb]{1,0,0}%
  \hboxto{\hsize/7}{~Sun \hss}%
  \color[rgb]{0,0,0}%
  \hboxto{\hsize/7}{~Mon \hss}%
  \hboxto{\hsize/7}{~Tue \hss}%
  \hboxto{\hsize/7}{~Wed \hss}%
  \hboxto{\hsize/7}{~Thu \hss}%
  \hboxto{\hsize/7}{~Fri \hss}%
  \color[rgb]{0,0,1}%
  \hboxto{\hsize/7}{~Sat \hss}%
  \color[rgb]{0,0,0}%
  \relax}
\base(\lx,\ty+9mm){\parbox[t]{\hsize}{\leavevmode
  \Huge\sf\evald\baselineskip{\vsize/6}%
  \hboxto{\FirstDay*\hsize/7}{\hss}\hskip0pt plus1sp minus1sp 
  \count0=0
  \loop\ifnum\count0<\NumDays
    \advance\count0+1
    \hboxto{\hsize/7}{%
      \count255=\FirstDay\advance\count255+\count0\mod7
      \ifnum\count255=1\relax\color[rgb]{1,0,0}\fi
      \ifnum\count255=0\relax\color[rgb]{0,0,1}\fi
      ~\the\count0\hss
    }\hskip0pt plus1sp minus1sp
  \repeat
  \relax}}
\newpage}}
\csname @begindocumenthook\endcsname
\endinput
%%EOF
