%\def\fileversion{1.2}
%\def\filedate{27 May 2007}
%\def\docdate{27 May 2007}
%\iffalse
% Doc-Source file to use with LaTeX2e
% Copyright (C) 2000 Nicola Talbot, all rights reserved.
%\fi
% \MakeShortVerb{\"}
% \newsavebox{\syntaxbox}
% \newenvironment{syntax}{\begin{lrbox}{\syntaxbox}\ttfamily}%
%{\end{lrbox}\vspace*{12pt}\par\noindent\fbox{\usebox{\syntaxbox}}\\}
%
% \title{\texttt{crkscrsh.cls v\fileversion}: \LaTeXe\ Class file 
% for typesetting cricket score sheets}
% \author{Nicola L.C. Talbot}
% \date{\docdate}
% \maketitle
%
% \tableofcontents\newpage
%
% \section{Introduction}\label{sec:intro}
% This is the documentation for the \LaTeXe\ class file \texttt{crkscrsh.cls},
% which is designed to typeset cricket score sheets.  It 
% requires a large amount of memory, so will not run on small installations
% of \TeX.  In order to reduce memory requirements, this class file
% is not of much use for anything other than printing the score sheet
% of a 90 or 40 limited overs cricket match (2 $\times$ 45-over or 2 $\times$ 20-over 
% innings), so there are no sectioning commands etc available.  The score sheet is typeset
% on A4 landscape with 10pt sans serif text, and there are no options
% to change the paper size or font size, however the following options 
% are available:\\
%\begin{tabular}{ll}
%\ttfamily final & Final version (default)\\
%\ttfamily draft & Draft version\\
%\ttfamily all & Display everything (default)\\
%\ttfamily nosummary & Don't display the bowling and batting summaries\\
% & (Useful if \TeX's capacities are exceeded)\\
%\ttfamily summaryonly & Only display the bowling and batting summaries\\
%\ttfamily 45 & 45-over innings (default)\\
%\ttfamily 20 & 20-over innings
%\end{tabular}
%
% The commands "\showall", "\nosummary" and "\summaryonly" are equivalent to
% the options "all", "nosummary" and "summaryonly", respectively.
%
% \section{Entering Information}
% This section describes the commands required to specify the relevant 
% information.
%
% \subsection{Global Commands}
% The following five commands may be used in the preamble:
%
% \DescribeMacro{\hometeam}
% The home team is specified by the command "\hometeam{"\meta{name}"}".
%
% \DescribeMacro{\awayteam}
% The away team is specified by the command "\awayteam{"\meta{name}"}".
%
% \DescribeMacro{\location}
% The location of the match is specified by the command 
% "\location{"\meta{place}"}".
%
% \DescribeMacro{\date}
% The date of the match is specified by the command
% "\date{"\meta{dd}"}{"\meta{mm}"}{"\meta{yy}"}", where
% the three arguments are numerical and specify the
% day, month and year.
%
% \DescribeMacro{\tosswonby}
% The team that won the toss is specified by
% "\tosswonby{"\meta{name}"}".
%
% \subsection{Commands Local to Each Innings}
%
% \vspace*{-12pt}
% \begin{syntax}"\begin{innings}{"\meta{team}"}"\end{syntax}\DescribeEnv{innings}
% The information about each innings are specified within
% an "innings" environment.  The "innings" environment takes
% one argument, \meta{team}, that specifies the batting team.
% For an example, see Section~\ref{ex:innings}.
% Within the "innings" environment, the following commands
% may be used:
%
% 
% \begin{syntax}"\newbowler{"\meta{name}"}{"\meta{label}"}"\end{syntax}\DescribeMacro{\newbowler}
% Each bowler should be specified with a separate
% "\newbowler" command.  The first argument,
% \meta{name}, is the bowler's name, and the
% second argument, \meta{label},
% is a unique identifier for this bowler.
%
% \begin{syntax}"\newbatsman["\meta{delay}"]{"\meta{hr}:\meta{min}"}{"\meta{name}"}"\end{syntax}
% \DescribeMacro{\newbatsman}
% Each batsman should be specified by the "\newbatsman" command,
% where \meta{hr}:\meta{min} specifies the time the batsman went
% to the crease, and \meta{name} is the name of the batsman.  
% Each batsman should be specified in order.  The optional
% argument \meta{delay} is the delay in minutes between the
% previous batsman leaving the crease, and the new batsman
% going out.  By default \meta{delay} is zero.  Apart
% from the first two batsman, a batsman should not be
% defined until the previous one is out.
%
% \begin{syntax}"\Over{"\meta{label}"}{"\meta{b}\ldots\meta{b}"}"\end{syntax}
% \DescribeMacro{\Over}
% The results of each over should be specified by the "\Over" command,
% where \meta{label} is the label of the bowler and
% \meta{b} is either the number of runs for that ball,
% a "." for a dot ball, "w" for a fall of wicket,
% "r" for a batsman retiring,
% or a "+" for a wide or no ball.
% \meta{b} may also be "s", to indicate if the batsmen
% have swapped due to runs being obtained from a bye,
% leg-bye, or if the batsman crossed before one was 
% caught out or stumped.  Note that this class file will only display
% the first 12 entries of an over\footnote{which should account for most bowler's
% capabilities, although it will appear very cramped.}, but any runs
% scored beyond the 12th ball will still be added to the total.  
% For examples see Section~\ref{sec:ex}.
%
% \begin{syntax}"\extra{"\meta{type}"}{"\meta{runs}"}"\end{syntax}
% \DescribeMacro{\extra}
% Any extras obtained during an over should be
% specified by the "\extra" command,
% where \meta{type} should be one of: "bye", "legbye",
% "wide" or "noball".  This command should come somewhere
% after the "\Over" command for that over, and before the
% "\Over" command for the following over.  It may appear 
% before or after "\howout" and "\newbatsman", although it
% makes sense to have it in chronological order.
% Examples are giving in Sections~\ref{ex:legbye} and~\ref{ex:noball}.
%
% \begin{syntax}"\howout["\meta{bowler}"]{"\meta{how out}"}"\end{syntax}
% \DescribeMacro{\howout}
% The "\howout" command specifies
% how the last batsman to be out was out.  This command should come
% after the over in which that batsman was out, and before the
% "\newbatsman" command, specifying the replacement batsman.
% The mandatory argument \meta{how out} specifies the text to
% appear in the ``How Out'' column of the sheet.  By default
% the bowler's name will be placed in the ``Bowler'' column,
% next to the ``How Out'' column, but sometimes this is inappropriate
% (e.g. for a run out), in which case the optional argument 
% \meta{bowler} can be used to override this.  Examples
% are given in Sections~\ref{ex:retired} and~\ref{ex:wickets}.
%
% \begin{syntax}"\InningsEndTime{"\meta{hrs}":"\meta{mins}"}"\end{syntax}
% \DescribeMacro{\InningsEndTime}
% The time the innings ended is specified by the command "\InningsEndTime",
% where \meta{hrs}:\meta{min} is the end time (24 hour clock).
%
% \section{Retrieving Totals}
% The total number of runs (including extras), total number of wickets and
% overs for each innings are stored in \TeX\ count registers of the
% form "\innings"\meta{n}"tot", "\innings"\meta{n}"wks" and
% "\innings"\meta{n}"overs", where \meta{n} is the lowercase romannumeral
% for the innings.  For example, the total number of runs scored
% in the first innings is stored in the register "\inningsitot",
% whereas the total number of runs scored in the second
% innings is stored in the register "\inningsiitot".  The total
% number of innings is stored in the register "\inningsN".
% Each innings also has a macro of the form "\innings"\meta{n}"name"
% that stores the name of the batting side for that innings (the
% name passed to the innings environment).  To access the value
% of a register, prefix it with "\the".  For example:
%\begin{verbatim}
%\begin{tabular}{lccc}
%Innings & Total & Wickets & Overs\\
%\inningsiname & \the\inningsitot & \the\inningsiwks & \the\inningsiovers\\
%\inningsiiname & \the\inningsiitot & \the\inningsiiwks & \the\inningsiiovers
%\end{tabular}
%\end{verbatim}
%
% \begin{syntax}"\SaveResults{"\meta{filename}"}"\end{syntax}
% \DescribeMacro{\SaveResults}
% Using the "\SaveResults" command, the above registers can be saved to a file
% which can then be "\input"'d
% into another document.  In addition, the following macro definitions are
% saved in \meta{filename}: "\HomeTeam", "\AwayTeam", "\MatchDate",
% "\MatchLocation", "\WonToss", "\InningsIResults", "\InningsIIResults"
% and "\MatchResult".  See Section~\ref{ex:save} for illustration on use.
%
% \section{Examples}
% \label{sec:ex}
%
% \subsection{Innings Example}\label{ex:innings}
% The following is an extract from one of Colney's innings:
%\begin{verbatim}
%\begin{innings}{Colney}           % Colney's innings
%\newbowler{Moore}{moore}          % Bowler A, given the label "moore"
%\newbowler{S. Brown}{brown}       % Bowler B, given the label "brown"
%\newbatsman{14:03}{G. Cawley}     % Batsman no 1.
%\newbatsman{14:03}{D. Whitworth}  % Batsman no 2.
%\Over{moore}{2....1}              % This is the first over bowled by "moore"
%                                  % 2 runs were scored off the first ball,
%                                  % and 1 run was scored off the last ball.
%\Over{brown}{....1.}              % This over was bowled by "brown",
%                                  % only 1 run was scored
%\end{verbatim}
%\hspace*{0.5in}\vdots
%\begin{verbatim}
%\InningsEndTime{16:36}            % Innings ended at 16:36.
%\end{innings}
%\end{verbatim}
%
% \subsection{Leg Bye Example}\label{ex:legbye}
% Now for an over where there has been a leg bye:
%\begin{verbatim}
%\Over{moore}{.s2124.}             % The first ball was a leg bye.  It's entered
%                                  % as a dot ball, as the run was not scored from 
%                                  % the bat, but since it has caused the batsmen
%                                  % to change over, "s" is required.
%\extra{legbye}{1}                 % This specifies the number of runs
%                                  % scored from the extra.
%\end{verbatim}
%
% \subsection{Example of Batsman Retiring}\label{ex:retired}
% In the following over, batsman number 1 retired out at the end of the over (the bowler
% "mears" should have been defined before this section of code):
%\begin{verbatim}
%\Over[1]{mears}{12..22r}          % "r" specifies that batsman no 1 retired. 
%                                  % (The number of wickets fallen is not advanced.)
%\howout[Out]{Retired}             % Bowler's name is not appropriate in this instance,
%                                  % so optional argument is needed to override it).
%\newbatsman{16:05}{M. Burrell}    % Need to specify the new batsman before
%                                  % the next over starts.
%\end{verbatim}
%
% \subsection{Example of Wickets Falling}\label{ex:wickets}
% In the following over, two wickets fell:
%\begin{verbatim}
%\Over[76]{mears}{.w1ws..}         % Batsman no 7 was the first to go,
%                                  % then batsman 6 was out. The batsmen had 
%                                  % swapped sides before batsman 6 was caught,
%                                  % so "s" is needed to reflect this.
%
%\howout{Bowled}                   % First state how batsman 7 was out.
%\newbatsman{16:20}{M. Robson}     % Declare the batsman to replace batsman 7
%
%\howout{Caught}                   % Now state how batsman no 6 was out.
%\newbatsman{16:21}{R. Foxall}     % Declare the batsman to replace batsman 6.
%\end{verbatim}
% (Note that if the batsman out was either number 10 or 11, the number should be grouped.
% For example: "\Over[{10}6]{mears}{.w1ws..}".)
%
% \subsection{Example of a No Ball and a Wide}\label{ex:noball}
% In the following over, there was a no ball and a wide.
%\begin{verbatim}
%\Over{brown}{+..2+.12}            % The first ball was a wide 
%                                  % (indicated by the first "+")
%                                  % the second "+" was a no ball.
%\extra{wide}{3}                   % Two runs were scored from the wide,
%                                  % plus one run for the wide itself, 
%                                  % which gives a total of 3.
%\extra{noball}{1}                 % No runs were scored off the no ball, 
%                                  % plus one run for the no ball itself, 
%                                  % which gives a total of 1.
%\end{verbatim}
%
% \subsection{Example Illustrating How to Save and Use Results}\label{ex:save}
% In this example, the match was defined in a file called "match1.tex", which
% looks something like:
%\begin{verbatim}
%\documentclass{crkscrsh}
%\hometeam{Colney Cricket Club}
%\awayteam{Holt}
%\location{Colney}
%\date{12}{08}{2000}
%\tosswonby{Colney}
%\begin{document}
%\begin{innings}{Colney}
%\end{verbatim}
% \vdots
%\begin{verbatim}
%\end{innings}
%\begin{innings}{Holt}
%\end{verbatim}
% \vdots
%\begin{verbatim}
%\end{innings}
%\SaveResults{match1res} % save the results to match1res.tex
%\end{verbatim}
%
% As noted in Section~\ref{sec:intro}, "crkscrsh.cls" does require
% a fair amount of memory, which is why it is a class file, and
% not a package.  So what if you want to use the information
% provided in "match1.tex"?  Firstly, the tables for
% each innings can be saved as EPS files as follows:
%\begin{verbatim}
%latex match1
%dvips -E -pp1 -o match1.1.eps match1
%dvips -E -pp2 -o match1.2.eps match1
%\end{verbatim}
%
% Now suppose you want to write a document (say "matchsummaries.tex")
% that includes a summary of the match defined in "match1.tex".
% The contents of "matchsummaries.tex" might look something like:
%\begin{verbatim}
% \input{match1res}The match between \HomeTeam\ and \AwayTeam\ on
% \MatchDate\ took place at \MatchLocation.  \WonToss\ won the
% toss, and \inningsiname\ batted first.  The score for the
% first innings was \InningsIResults.  The score for \inningsiiname's innings
% was \InningsIIResults.
% \MatchResult.
%\end{verbatim}
% Note that the macros "\inningsiiname" and "\InningsIIResults" will only
% be defined if at least two innings were specified in the original file
% (in this example "match1.tex").  The macro "\MatchResult" will only
% be defined if there were exactly two innings specified in the
% original file, and "\InningsIResults" will only be defined if there
% was at least one innings specified in the original file.
%
% \section{To Do}
% Currently there is no allowance for a previously retired batsman to return
% to the crease.  I will try to add in a new command to allow for this in 
% subsequent versions.
%
%\section{Contact Details}
%Dr Nicola Talbot\\
%School of Computing Sciences\\
%University of East Anglia\\
%Norwich. NR4 7TJ\\
%\url{http://theoval.cmp.uea.ac.uk/~nlct/}
%
% \StopEventually{}
%
%\iffalse
%    \begin{macrocode}
%<*driver>
\documentclass{ltxdoc}
\usepackage[colorlinks,bookmarks]{hyperref}
\OnlyDescription
\begin{document}\DocInput{crkscrsh.dtx}\end{document}
%</driver>
%    \end{macrocode}
%\fi
% \section{The Code}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{crkscrsh}[2007/05/27 Cricket Score Sheet (NLCT)]
%
\newif\ifsummaryonly
\newif\ifnosummary
\newif\ifshowall
\newcommand{\showall}{\showalltrue\nosummaryfalse\summaryonlyfalse}
\newcommand{\summaryonly}{\summaryonlytrue\nosummaryfalse\showallfalse}
\newcommand{\nosummary}{\nosummarytrue\summaryonlyfalse\showallfalse}
\newcount\maxovers

\DeclareOption{summaryonly}{\summaryonly}
\DeclareOption{nosummary}{\nosummary}
\DeclareOption{all}{\showall}
\DeclareOption{45}{\maxovers=45 \def\disovs{\@disovsxlv}}
\DeclareOption{20}{\maxovers=20 \def\disovs{\@disovsxx}}
\DeclareOption{draft}{\setlength{\overfullrule}{5pt}}
\DeclareOption{final}{\setlength{\overfullrule}{0pt}}
%
\ExecuteOptions{final,all,45}
\ProcessOptions
%
\RequirePackage{ifthen}
\input{size10.clo}
%
\RequirePackage[a4paper,landscape,margin=0.25in,nohead,nofoot]{geometry}

\setlength{\footskip}{0pt}
\setlength{\lineskip}{1\p@}
\setlength{\normallineskip}{1\p@}
\def\baselinestretch{}
\setlength{\parskip}{0\p@ \@plus \p@}
\setlength{\tabcolsep}{1.5\p@}
\setlength{\arrayrulewidth}{0.4\p@}
\setlength{\doublerulesep}{2\p@}

\def\@oddhead{}
\def\@evenhead{}
\def\@oddfoot{}
\def\@evenfoot{}

\newcount\bowN
\newcount\overN
\newcount\batsN
\newcount\fcg      % facing
\newcount\nfcg     % not facing
\newcount\@tmpctr
\newcount\@tmpctrII
\newcount\@ctr
\newcount\@runtot
\newcount\@extot
\newcount\@tot
\newcount\@ex@bye \newcount\@ex@legbye
\newcount\@ex@wide \newcount\@ex@noball
\newlength\@ovwd % width of over columns
\newlength\@btnmwd % width of batsman's name column

\def\@hmtm{}
\def\hometeam#1{\def\@hmtm{#1}}
\def\@awtm{}
\def\awayteam#1{\def\@awtm{#1}}
\def\@loc{}
\def\location#1{\def\@loc{#1}}
\def\@wontoss{}
\def\tosswonby#1{\def\@wontoss{#1}}
\renewcommand{\date}[3]{\renewcommand{\@date}{\underline{#1}/\underline{#2}/\underline{#3}}%
\def\MatchDate{#1/#2/#3}}
\def\MatchDate{\emph{Match date unspecified.}}
\date{\the\day}{\the\month}{\the\year}

\newcount\inningsN

\newenvironment{innings}[1]{\centering%
\fcg=1 \overN=0 \bowN=0 \batsN=0
\nfcg=2 \@runtot=0 \@extot=0 \@tot=0 \@ex@bye=0 \@ex@legbye=0
\@ex@wide=0 \@ex@noball=0 \@wickets=0
\def\@innings{#1}%
\global\advance\inningsN by 1\relax
% initialise
\InningsEndTime{24:00}%
}%
{%
\ifnum\overN>\maxovers
\ClassError{crkscrsh}{Too many overs in innings \the\inningsN}{You have specified \the\maxovers-over
innings, but have entered \the\overN \space overs.  The additional overs will still count towards
the run and wicket totals, but will not be displayed.} \fi
\printsheet\@innings
\expandafter\global\expandafter\newcount\csname innings\romannumeral\inningsN tot\endcsname
\expandafter\global\expandafter\newcount\csname innings\romannumeral\inningsN wks\endcsname
\expandafter\global\expandafter\newcount\csname innings\romannumeral\inningsN overs\endcsname
%
\expandafter\global\csname innings\romannumeral\inningsN tot\endcsname=\@tot
\expandafter\global\csname innings\romannumeral\inningsN wks\endcsname=\@wickets
\expandafter\global\csname innings\romannumeral\inningsN overs\endcsname=\overN
%
\expandafter\xdef\csname innings\romannumeral\inningsN name\endcsname{\@innings}
\expandafter\xdef\csname innings\romannumeral\inningsN res\endcsname{%
\expandafter\the\csname innings\romannumeral\inningsN tot\endcsname \space
\expandafter\ifnum\csname innings\romannumeral\inningsN wks\endcsname<10
for \expandafter\the\csname innings\romannumeral\inningsN wks\endcsname
\else
all out
\fi}\par}

\newwrite\@resfd

\newcommand\SaveResults[1]{%
\openout\@resfd=#1\relax
\write\@resfd{\protect\iffalse Output from \jobname\protect\fi}
\write\@resfd{\protect\def\protect\HomeTeam{\@hmtm}}
\write\@resfd{\protect\def\protect\AwayTeam{\@awtm}}
\write\@resfd{\protect\def\protect\MatchDate{\MatchDate}}
\write\@resfd{\protect\def\protect\MatchLocation{\@loc}}
\write\@resfd{\protect\def\protect\WonToss{\@wontoss}}
\write\@resfd{\protect\newcount \protect\inningsN \space \protect\inningsN = \the\inningsN}
% Havn't quite worked out how to do this in a loop.
% Nothing I've tried seems to work properly.
% This does up to a maximum of 4 innings
\ifcase\inningsN
\or
\write\@resfd{\protect\newcount\protect\inningsitot \protect\inningsitot=\the\inningsitot}
\write\@resfd{\protect\newcount\protect\inningsiwks \protect\inningsiwks=\the\inningsiwks}
\write\@resfd{\protect\newcount\protect\inningsiovers \protect\inningsiovers=\the\inningsiovers}
\write\@resfd{\protect\def\protect\inningsiname{\inningsiname}}
\write\@resfd{\protect\def\protect\InningsIResults{\inningsires}}
\or
% Determine match result (limited overs match, so no draw)
\ifnum\inningsitot=\inningsiitot
\def\MatchResult{Match tied} % Match tied.
\else
\ifnum\inningsitot>\inningsiitot
% Side batting first won.
\ifnum\inningsiwks<\inningsiiwks
\@tmpctr=\inningsiiwks
\advance\@tmpctr by -\inningsiwks
\edef\MatchResult{\inningsiname \space won by \the\@tmpctr \space \ifnum\@tmpctr>1 wickets\else wicket\fi}
\else
\@tmpctr=\inningsitot
\advance\@tmpctr by -\inningsiitot
\edef\MatchResult{\inningsiname \space won by \the\@tmpctr \space \ifnum\@tmpctr>1 runs\else run\fi}
\fi
\else
% Side batting second won.
\ifnum\inningsiiwks<\inningsiwks
\@tmpctr=\inningsiwks
\advance\@tmpctr by -\inningsiiwks
\edef\MatchResult{\inningsiiname \space won by \the\@tmpctr \space \ifnum\@tmpctr>1 wickets\else wicket\fi}
\else
\@tmpctr=\inningsiitot
\advance\@tmpctr by -\inningsitot
\edef\MatchResult{\inningsiiname \space won by \the\@tmpctr \space \ifnum\@tmpctr>1 runs\else run\fi}
\fi
\fi
\fi
\write\@resfd{\protect\newcount\protect\inningsitot \protect\inningsitot=\the\inningsitot}
\write\@resfd{\protect\newcount\protect\inningsiwks \protect\inningsiwks=\the\inningsiwks}
\write\@resfd{\protect\newcount\protect\inningsiovers \protect\inningsiovers=\the\inningsiovers}
\write\@resfd{\protect\def\protect\inningsiname{\inningsiname}}
\write\@resfd{\protect\newcount\protect\inningsiitot \protect\inningsiitot=\the\inningsiitot}
\write\@resfd{\protect\newcount\protect\inningsiiwks \protect\inningsiiwks=\the\inningsiiwks}
\write\@resfd{\protect\newcount\protect\inningsiiovers \protect\inningsiiovers=\the\inningsiiovers}
\write\@resfd{\protect\def\protect\inningsiiname{\inningsiiname}}
\write\@resfd{\protect\def\protect\InningsIResults{\inningsires}}
\write\@resfd{\protect\def\protect\InningsIIResults{\inningsiires}}
\write\@resfd{\protect\def\protect\MatchResult{\MatchResult}}
\or
\write\@resfd{\protect\newcount\protect\inningsitot \protect\inningsitot=\the\inningsitot}
\write\@resfd{\protect\newcount\protect\inningsiwks \protect\inningsiwks=\the\inningsiwks}
\write\@resfd{\protect\newcount\protect\inningsiovers \protect\inningsiovers=\the\inningsiovers}
\write\@resfd{\protect\def\protect\inningsiname{\inningsiname}}
\write\@resfd{\protect\newcount\protect\inningsiitot \protect\inningsiitot=\the\inningsiitot}
\write\@resfd{\protect\newcount\protect\inningsiiwks \protect\inningsiiwks=\the\inningsiiwks}
\write\@resfd{\protect\newcount\protect\inningsiiovers \protect\inningsiiovers=\the\inningsiiovers}
\write\@resfd{\protect\def\protect\inningsiiname{\inningsiiname}}
\write\@resfd{\protect\newcount\protect\inningsiiitot \protect\inningsiiitot=\the\inningsiiitot}
\write\@resfd{\protect\newcount\protect\inningsiiiwks \protect\inningsiiiwks=\the\inningsiiiwks}
\write\@resfd{\protect\newcount\protect\inningsiiiovers \protect\inningsiiiovers=\the\inningsiiiovers}
\write\@resfd{\protect\def\protect\inningsiiiname{\inningsiiiname}}
\write\@resfd{\protect\def\protect\InningsIResults{\inningsires}}
\write\@resfd{\protect\def\protect\InningsIIResults{\inningsiires}}
\write\@resfd{\protect\def\protect\InningsIIIResults{\inningsiiires}}
\else
\write\@resfd{\protect\newcount\protect\inningsitot \protect\inningsitot=\the\inningsitot}
\write\@resfd{\protect\newcount\protect\inningsiwks \protect\inningsiwks=\the\inningsiwks}
\write\@resfd{\protect\newcount\protect\inningsiovers \protect\inningsiovers=\the\inningsiovers}
\write\@resfd{\protect\def\protect\inningsiname{\inningsiname}}
\write\@resfd{\protect\newcount\protect\inningsiitot \protect\inningsiitot=\the\inningsiitot}
\write\@resfd{\protect\newcount\protect\inningsiiwks \protect\inningsiiwks=\the\inningsiiwks}
\write\@resfd{\protect\newcount\protect\inningsiiovers \protect\inningsiiovers=\the\inningsiiovers}
\write\@resfd{\protect\def\protect\inningsiiname{\inningsiiname}}
\write\@resfd{\protect\newcount\protect\inningsiiitot \protect\inningsiiitot=\the\inningsiiitot}
\write\@resfd{\protect\newcount\protect\inningsiiiwks \protect\inningsiiiwks=\the\inningsiiiwks}
\write\@resfd{\protect\newcount\protect\inningsiiiovers \protect\inningsiiiovers=\the\inningsiiiovers}
\write\@resfd{\protect\def\protect\inningsiiiname{\inningsiiiname}}
\write\@resfd{\protect\newcount\protect\inningsivtot \protect\inningsivtot=\the\inningsivtot}
\write\@resfd{\protect\newcount\protect\inningsivwks \protect\inningsivwks=\the\inningsivwks}
\write\@resfd{\protect\newcount\protect\inningsivovers \protect\inningsivovers=\the\inningsivovers}
\write\@resfd{\protect\def\protect\inningsivname{\inningsivname}}
\write\@resfd{\protect\def\protect\InningsIResults{\inningsires}}
\write\@resfd{\protect\def\protect\InningsIIResults{\inningsiires}}
\write\@resfd{\protect\def\protect\InningsIIIResults{\inningsiiires}}
\write\@resfd{\protect\def\protect\InningsIVResults{\inningsivres}}
\fi
\closeout\@resfd
}

\newcommand{\printsheet}[1]{%
\ifshowall
\newpage\noindent
\disovs{#1}\\[-1pt]
\ingstats
\else
\ifsummaryonly
\noindent Innings for #1:\\
\ingstats\par
\else
\ifnosummary
\newpage\noindent\disovs{#1}\par
\fi
\fi
\fi
}

\def\overtot#1{\makebox[0.15in]{\csname @ov\romannumeral#1tot\endcsname}}
\def\overwks#1{\csname @ov\romannumeral#1wks\endcsname}
\def\overbw#1{\csname @ov\romannumeral#1bw\endcsname}
\def\standof#1{%
\ifnum#1=1\relax
\csname @fowiscr\endcsname
\else
\expandafter\ifx\csname @fow\romannumeral#1scr\endcsname\relax
\relax
\else
\@ctr=#1\relax
\advance\@ctr by -1\relax
\@tmpctrII=\csname @fow\romannumeral\@ctr scr\endcsname
\@tmpctr=\csname @fow\romannumeral#1scr\endcsname
\advance\@tmpctr by -\@tmpctrII
\the\@tmpctr
\fi
\fi
}

\newcommand{\@disovsxlv}[1]{\noindent\scriptsize
\@ovwd=11.4pt\relax
\@btnmwd=1.18in\relax
\begin{tabular}{|c|l|l|l|l|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
\hline
\multicolumn{50}{|l|}{\normalsize\makebox[2.25in][l]{\rule{0pt}{12pt}\@hmtm} verses 
\makebox[2.25in]{\@awtm} %
at \makebox[2.0in]{\@loc} date \makebox[1in][l]{\@date}
\makebox[1.25in][r]{\@wontoss} won toss}\\\hline
\multicolumn{3}{|c|}{\makebox[0.75in]{\normalsize\rule[-2pt]{0pt}{11pt} Innings of}} & 
\multicolumn{2}{c|}{\makebox[0.522in]{OVERS}} & 
1 & 2 &  3 &  4 &
5 & 6 & 7 &  8 &
9 & 10 & 11 & 12 &
13 & 14 & 15 & 16 &
17 & 18 & 19 & 20 &
21 & 22 & 23 & 24 &
25 & 26 & 27 & 28 &
29 & 30 & 31 & 32 &
33 & 34 & 35 & 36 & 
37 & 38 & 39 & 40 & 
41 & 42 & 43 & 44 & 45\\\cline{6-50}
\multicolumn{3}{|c|}{\rule[-2pt]{0pt}{10pt}} &  
\multicolumn{2}{c|}{TOTAL} & 
\overtot1 &
\overtot2 & 
\overtot3 & 
\overtot4 & 
\overtot5 & 
\overtot6 & 
\overtot7 & 
\overtot8 & 
\overtot9 & 
\overtot{10} & 
\overtot{11} & 
\overtot{12} & 
\overtot{13} & 
\overtot{14} & 
\overtot{15} & 
\overtot{16} &
\overtot{17} & 
\overtot{18} & 
\overtot{19} & 
\overtot{20} & 
\overtot{21} & 
\overtot{22} & 
\overtot{23} & 
\overtot{24} & 
\overtot{25} & 
\overtot{26} & 
\overtot{27} & 
\overtot{28} & 
\overtot{29} & 
\overtot{30} &
\overtot{31} &
\overtot{32} &
\overtot{33} &
\overtot{34} &
\overtot{35} &
\overtot{36} &
\overtot{37} &
\overtot{38} &
\overtot{39} &
\overtot{40} &
\overtot{41} &
\overtot{42} &
\overtot{43} &
\overtot{44} &
\overtot{45}\\\cline{6-50}
\multicolumn{3}{|c|}{\normalsize #1} &  
\multicolumn{2}{c|}{WKTS} &
\overwks1 &
\overwks2 & 
\overwks3 & 
\overwks4 & 
\overwks5 & 
\overwks6 & 
\overwks7 & 
\overwks8 & 
\overwks9 & 
\overwks{10} & 
\overwks{11} & 
\overwks{12} & 
\overwks{13} & 
\overwks{14} & 
\overwks{15} & 
\overwks{16} &
\overwks{17} & 
\overwks{18} & 
\overwks{19} & 
\overwks{20} & 
\overwks{21} & 
\overwks{22} & 
\overwks{23} & 
\overwks{24} & 
\overwks{25} & 
\overwks{26} & 
\overwks{27} & 
\overwks{28} & 
\overwks{29} & 
\overwks{30} &
\overwks{31} &
\overwks{32} &
\overwks{33} &
\overwks{34} &
\overwks{35} &
\overwks{36} &
\overwks{37} &
\overwks{38} &
\overwks{39} &
\overwks{40} &
\overwks{41} &
\overwks{42} &
\overwks{43} &
\overwks{44} &
\overwks{45}\\\cline{6-50}
\multicolumn{3}{|c|}{\rule[-2pt]{0pt}{10pt}} &  
\multicolumn{2}{c|}{BOWLER} &
\overbw{1} &
\overbw{2} & 
\overbw{3} & 
\overbw{4} & 
\overbw{5} & 
\overbw{6} & 
\overbw{7} & 
\overbw{8} & 
\overbw{9} & 
\overbw{10} & 
\overbw{11} & 
\overbw{12} & 
\overbw{13} & 
\overbw{14} & 
\overbw{15} & 
\overbw{16} &
\overbw{17} & 
\overbw{18} & 
\overbw{19} & 
\overbw{20} & 
\overbw{21} & 
\overbw{22} & 
\overbw{23} & 
\overbw{24} & 
\overbw{25} & 
\overbw{26} & 
\overbw{27} & 
\overbw{28} & 
\overbw{29} & 
\overbw{30} &
\overbw{31} &
\overbw{32} &
\overbw{33} &
\overbw{34} &
\overbw{35} &
\overbw{36} &
\overbw{37} &
\overbw{38} &
\overbw{39} &
\overbw{40} &
\overbw{41} &
\overbw{42} &
\overbw{43} &
\overbw{44} &
\overbw{45}\\\hline
\message{.}\dispbatsxlv1
\message{.}\dispbatsxlv2
\message{.}\dispbatsxlv3
\message{.}\dispbatsxlv4
\message{.}\dispbatsxlv5
\message{.}\dispbatsxlv6
\message{.}\dispbatsxlv7
\message{.}\dispbatsxlv8
\message{.}\dispbatsxlv9
\message{.}\dispbatsxlv{10}
\message{.}\dispbatsxlv{11}
\multicolumn{1}{|l}{} & \multicolumn{7}{l|}{\rule[-3pt]{0pt}{12pt}\normalsize Fall of Wickets} &
\multicolumn{2}{c|}{1} &
\multicolumn{2}{c|}{2} &
\multicolumn{2}{c|}{3} &
\multicolumn{2}{c|}{4} &
\multicolumn{2}{c|}{5} &
\multicolumn{2}{c|}{6} &
\multicolumn{2}{c|}{7} &
\multicolumn{2}{c|}{8} &
\multicolumn{2}{c|}{9} &
\multicolumn{2}{c|}{10} &
\multicolumn{2}{c|}{\footnotesize\smash{\begin{tabular}[t]{c}E\\[-3pt]X\\[-3pt]T\\[-3pt]R\\[-3pt]A\\[-3pt]S\end{tabular}}} &
\multicolumn{12}{l|}{\ Byes} &
\multicolumn{2}{c|}{\the\@ex@bye} &
\multicolumn{5}{l|}{Runs from the bat} & 
\the\@runtot\\\cline{1-28}\cline{31-50}
\multicolumn{1}{|l}{} & \multicolumn{7}{l|}{\rule[-3pt]{0pt}{12pt}\normalsize Batsman} &
\multicolumn{2}{c|}{\csname @fow\romannumeral1bts\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral2bts\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral3bts\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral4bts\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral5bts\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral6bts\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral7bts\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral8bts\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral9bts\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral10bts\endcsname} &
\multicolumn{2}{c|}{} &
\multicolumn{12}{l|}{\ Leg Byes} &
\multicolumn{2}{c|}{\the\@ex@legbye} &
\multicolumn{5}{l|}{Total Extras} & 
\the\@extot\\\cline{1-28}\cline{31-50}
\multicolumn{1}{|l}{} & \multicolumn{7}{l|}{\rule[-3pt]{0pt}{12pt}\normalsize Score} &
\multicolumn{2}{c|}{\csname @fow\romannumeral1scr\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral2scr\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral3scr\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral4scr\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral5scr\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral6scr\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral7scr\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral8scr\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral9scr\endcsname} &
\multicolumn{2}{c|}{\csname @fow\romannumeral10scr\endcsname} &
\multicolumn{2}{c|}{} &
\multicolumn{12}{l|}{\ Wides} &
\multicolumn{2}{c|}{\the\@ex@wide} &
\multicolumn{5}{l|}{\bfseries Total} & 
\bfseries \the\@tot\\\cline{1-28}\cline{31-50}
\multicolumn{1}{|l}{} & \multicolumn{7}{l|}{\rule[-3pt]{0pt}{12pt}\normalsize Stand of} &
\multicolumn{2}{c|}{\standof1} &
\multicolumn{2}{c|}{\standof2} &
\multicolumn{2}{c|}{\standof3} &
\multicolumn{2}{c|}{\standof4} &
\multicolumn{2}{c|}{\standof5} &
\multicolumn{2}{c|}{\standof6} &
\multicolumn{2}{c|}{\standof7} &
\multicolumn{2}{c|}{\standof8} &
\multicolumn{2}{c|}{\standof9} &
\multicolumn{2}{c|}{\standof{10}} &
\multicolumn{2}{c|}{\standof{11}} &
\multicolumn{12}{l|}{\ No Balls} &
\multicolumn{2}{c|}{\the\@ex@noball} &
\multicolumn{6}{c|}{For \makebox[0.2in]{\the\@wickets} Wkts \makebox[0.2in]{\the\overN} Overs}\\\hline
\end{tabular}
}

\newcommand{\@disovsxx}[1]{\noindent\scriptsize
\@ovwd=0.15in\relax
\advance\@ovwd by \tabcolsep
\multiply\@ovwd by 2\relax
\advance\@ovwd by \arrayrulewidth
\@btnmwd=1.3in\relax
\begin{tabular}{|c|l|l|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
\hline
\multicolumn{26}{|l|}{\normalsize\makebox[2.25in][l]{\rule{0pt}{12pt}\@hmtm} verses 
\makebox[2.25in]{\@awtm} %
at \makebox[2.0in]{\@loc} date \makebox[1in][l]{\@date}
\makebox[1.25in][r]{\@wontoss} won toss}\\\hline
\multicolumn{2}{|c|}{\makebox[0.75in]{\normalsize\rule[-2pt]{0pt}{11pt} Innings of}} & 
\multicolumn{1}{c|}{\makebox[0.522in]{OVERS}} & 
1 & 2 &  3 &  4 &
5 & 6 & 7 &  8 &
9 & 10 & 11 & 12 &
13 & 14 & 15 & 16 &
17 & 18 & 19 & 20 & \multicolumn{3}{c|}{} \\\cline{4-23}
\multicolumn{2}{|c|}{\rule[-2pt]{0pt}{10pt}} &  
\multicolumn{1}{c|}{TOTAL} & 
\overtot1 &
\overtot2 & 
\overtot3 & 
\overtot4 & 
\overtot5 & 
\overtot6 & 
\overtot7 & 
\overtot8 & 
\overtot9 & 
\overtot{10} & 
\overtot{11} & 
\overtot{12} & 
\overtot{13} & 
\overtot{14} & 
\overtot{15} & 
\overtot{16} &
\overtot{17} & 
\overtot{18} & 
\overtot{19} & 
\overtot{20} & \multicolumn{3}{c|}{}\\\cline{4-26}
\multicolumn{2}{|c|}{\makebox[0.7in]{\normalsize #1}} &  
\multicolumn{1}{c|}{WKTS} &
\overwks1 &
\overwks2 & 
\overwks3 & 
\overwks4 & 
\overwks5 & 
\overwks6 & 
\overwks7 & 
\overwks8 & 
\overwks9 & 
\overwks{10} & 
\overwks{11} & 
\overwks{12} & 
\overwks{13} & 
\overwks{14} & 
\overwks{15} & 
\overwks{16} &
\overwks{17} & 
\overwks{18} & 
\overwks{19} & 
\overwks{20} & \makebox[22pt]{Time} & \makebox[22pt]{Balls} &\\\cline{4-23}
\multicolumn{2}{|c|}{\rule[-2pt]{0pt}{10pt}} &  
\multicolumn{1}{c|}{BOWLER} &
\overbw{1} &
\overbw{2} & 
\overbw{3} & 
\overbw{4} & 
\overbw{5} & 
\overbw{6} & 
\overbw{7} & 
\overbw{8} & 
\overbw{9} & 
\overbw{10} & 
\overbw{11} & 
\overbw{12} & 
\overbw{13} & 
\overbw{14} & 
\overbw{15} & 
\overbw{16} &
\overbw{17} & 
\overbw{18} & 
\overbw{19} & 
\overbw{20} & In & Faced & Runs\\\hline
\message{.}\dispbatsxx1
\message{.}\dispbatsxx2
\message{.}\dispbatsxx3
\message{.}\dispbatsxx4
\message{.}\dispbatsxx5
\message{.}\dispbatsxx6
\message{.}\dispbatsxx7
\message{.}\dispbatsxx8
\message{.}\dispbatsxx9
\message{.}\dispbatsxx{10}
\message{.}\dispbatsxx{11}
\multicolumn{1}{|l}{} & \multicolumn{4}{l|}{\rule[-3pt]{0pt}{12pt}\normalsize Fall of Wickets} &
1 &
2 &
3 &
4 &
5 &
6 &
7 &
8 &
9 &
10 &
\footnotesize\smash{\begin{tabular}[t]{c}E\\[-3pt]X\\[-3pt]T\\[-3pt]R\\[-3pt]A\\[-3pt]S\end{tabular}} &
\multicolumn{4}{l|}{\ Byes} &
\the\@ex@bye &
\multicolumn{4}{l|}{Runs from the bat} & 
\the\@runtot\\\cline{1-15}\cline{17-26}
\multicolumn{1}{|l}{} & \multicolumn{4}{l|}{\rule[-3pt]{0pt}{12pt}\normalsize Batsman} &
\csname @fow\romannumeral1bts\endcsname &
\csname @fow\romannumeral2bts\endcsname &
\csname @fow\romannumeral3bts\endcsname &
\csname @fow\romannumeral4bts\endcsname &
\csname @fow\romannumeral5bts\endcsname &
\csname @fow\romannumeral6bts\endcsname &
\csname @fow\romannumeral7bts\endcsname &
\csname @fow\romannumeral8bts\endcsname &
\csname @fow\romannumeral9bts\endcsname &
\csname @fow\romannumeral10bts\endcsname &
 &
\multicolumn{4}{l|}{\ Leg Byes} &
\the\@ex@legbye &
\multicolumn{4}{l|}{Total Extras} & 
\the\@extot\\\cline{1-15}\cline{17-26}
\multicolumn{1}{|l}{} & \multicolumn{4}{l|}{\rule[-3pt]{0pt}{12pt}\normalsize Score} &
\csname @fow\romannumeral1scr\endcsname &
\csname @fow\romannumeral2scr\endcsname &
\csname @fow\romannumeral3scr\endcsname &
\csname @fow\romannumeral4scr\endcsname &
\csname @fow\romannumeral5scr\endcsname &
\csname @fow\romannumeral6scr\endcsname &
\csname @fow\romannumeral7scr\endcsname &
\csname @fow\romannumeral8scr\endcsname &
\csname @fow\romannumeral9scr\endcsname &
\csname @fow\romannumeral10scr\endcsname &
 &
\multicolumn{4}{l|}{\ Wides} &
\the\@ex@wide &
\multicolumn{4}{l|}{\bfseries Total} & 
\bfseries \the\@tot\\\cline{1-15}\cline{17-26}
\multicolumn{1}{|l}{} & \multicolumn{4}{l|}{\rule[-3pt]{0pt}{12pt}\normalsize Stand of} &
\standof1 &
\standof2 &
\standof3 &
\standof4 &
\standof5 &
\standof6 &
\standof7 &
\standof8 &
\standof9 &
\standof{10} &
\standof{11} &
\multicolumn{4}{l|}{\ No Balls} &
\the\@ex@noball &
\multicolumn{5}{c|}{For \makebox[0.2in]{\the\@wickets} Wkts \makebox[0.2in]{\the\overN} Overs}\\\hline
\end{tabular}
}

\newcount\@crk@modctr
\def\modulo#1#2{%
\@crk@modctr=#1\relax
\divide \@crk@modctr by #2\relax
\multiply \@crk@modctr by #2\relax
\advance #1 by -\@crk@modctr}

\newcount\@numer \newcount\@denom \newcount\@rmndr
\def\decfrac#1#2{%
\@numer=#1\relax
\@denom=#2\relax
\multiply\@numer by 100\relax
\ifnum\@denom=0\relax
--%
\else
\divide\@numer by \@denom
\@rmndr=\@numer
\divide\@rmndr by 100\relax
\ifnum\@rmndr<10\relax\phantom{0}\fi\the\@rmndr%
\@rmndr=\@numer
\modulo{\@rmndr}{100}%
\ifnum\@rmndr=0\relax
\phantom{.00}%
\else
.%
\ifnum\@rmndr<10\relax 0\the\@rmndr
\else
\@denom=\@rmndr
\modulo{\@rmndr}{10}%
\ifnum\@rmndr=0\relax
\divide\@denom by 10\relax
\the\@denom\phantom{0}%
\else
\the\@denom
\fi
\fi
\fi
\fi
}

\def\strikerate#1{%
\decfrac{\csname @bts\romannumeral#1rn\endcsname}{\csname @bts\romannumeral#1bf\endcsname}}

\def\@batsum#1{%
\smash{\normalsize #1} & 
\smash{\normalsize \csname @batsman\romannumeral#1\endcsname} &
\smash{\normalsize \csname @howout@\romannumeral#1\endcsname} &
\smash{\normalsize \csname @outbow@\romannumeral#1\endcsname} & 
\smash{\normalsize \expandafter\ifnum\csname @bts\romannumeral#1rn\endcsname>-1 
\expandafter\the\csname @bts\romannumeral#1rn\endcsname\fi} & 
\smash{\normalsize \expandafter\ifnum\csname @bts\romannumeral#1bf\endcsname>-1 
\expandafter\the\csname @bts\romannumeral#1bf\endcsname\fi} &
\smash{\normalsize \expandafter\ifnum\csname @bts\romannumeral#1bf\endcsname>-1 
\expandafter\the\csname @bts\romannumeral#1IV\endcsname\fi} &
\smash{\normalsize \expandafter\ifnum\csname @bts\romannumeral#1bf\endcsname>-1 
\expandafter\the\csname @bts\romannumeral#1VI\endcsname\fi} &
\smash{\normalsize \expandafter\ifnum\csname @bts\romannumeral#1bf\endcsname>0
\strikerate{#1}\fi}
}

\def\@battots{%
\multicolumn{4}{l|}{\smash{\normalsize\bfseries Total}} &
\smash{\normalsize \the\@runtot} &
\smash{\normalsize
\@tmpctr=0\relax
\@ctr=1\relax
\whiledo{\@ctr < \batsN \TE@or \@ctr=\batsN}{%
\advance\@tmpctr by \csname @bts\romannumeral\@ctr bf\endcsname
\advance\@ctr by 1\relax}% 
\the\@tmpctr}\relax &
\smash{\normalsize
\@tmpctr=0\relax
\@ctr=1\relax
\whiledo{\@ctr < \batsN \TE@or \@ctr=\batsN}{%
\advance\@tmpctr by \csname @bts\romannumeral\@ctr IV\endcsname
\advance\@ctr by 1\relax}% 
\the\@tmpctr} &
\smash{\normalsize
\@tmpctr=0\relax
\@ctr=1\relax
\whiledo{\@ctr < \batsN \TE@or \@ctr=\batsN}{%
\advance\@tmpctr by \csname @bts\romannumeral\@ctr VI\endcsname
\advance\@ctr by 1\relax}% 
\the\@tmpctr}\relax &
\smash{\normalsize
\@tmpctr=0\relax
\@ctr=1\relax
\whiledo{\@ctr < \batsN \TE@or \@ctr=\batsN}{%
\advance\@tmpctr by \csname @bts\romannumeral\@ctr bf\endcsname
\advance\@ctr by 1\relax}% 
\decfrac{\@runtot}{\@tmpctr}}%
}

\def\ingstats{%
\tiny
\begin{tabular}[t]{|c|l|l|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|l|l|l|c|c|c|c|c|}
\ifsummaryonly \hline \fi
\multicolumn{2}{|l|}{\rule{0pt}{9pt}\makebox[1.1in][l]{\normalsize Bowling Summary}} & 
\normalsize Overs &
\makebox[10pt]{\normalsize 1} & \makebox[10pt]{\normalsize 2} & 
\makebox[10pt]{\normalsize 3} & \makebox[10pt]{\normalsize 4} &
\makebox[10pt]{\normalsize 5} & \makebox[10pt]{\normalsize 6} & 
\makebox[10pt]{\normalsize 7} & \makebox[10pt]{\normalsize 8} & 
\makebox[10pt]{\normalsize 9} & \makebox[10pt]{\normalsize 10} & 
\makebox[10pt]{\normalsize 11} & \makebox[10pt]{\normalsize 12} &
\begin{tabular}{@{}c@{}}No\\Balls\end{tabular} &
Wide & Ovrs & Mdns & Runs & Wkts & Avge &
\multicolumn{2}{l|}{\normalsize Batting Summary} & \smash{\makebox[0.8in]{\normalsize How Out}} & 
\smash{\makebox[0.8in]{\normalsize Bowler}} & 
\smash{\normalsize Runs} & \smash{\normalsize Balls Faced} & 
\smash{\makebox[0.3in]{\normalsize 4's}} & \smash{\makebox[0.3in]{\normalsize 6's}} & 
\smash{\normalsize Strike Rate}\\\hline
\@bowsumi1 & & & & & & & & &\\\cline{3-15}
\@bowsumii1 & \@batsum1 \\\cline{3-15}\cline{23-31}
\@bowsumiii1 & & & & & & & & & \\\cline{1-22}
\@bowsumi2 & \@batsum2 \\\cline{3-15}\cline{23-31}
\@bowsumii2 & & & & & & & & & \\\cline{3-15}
\@bowsumiii2 & \@batsum3 \\\cline{1-31}
\@bowsumi3 & & & & & & & & & \\\cline{3-15}
\@bowsumii3 & \@batsum4 \\\cline{3-15}\cline{23-31}
\@bowsumiii3 & & & & & & & & & \\\cline{1-22}
\@bowsumi4 & \@batsum5 \\\cline{3-15}\cline{23-31}
\@bowsumii4 & & & & & & & & & \\\cline{3-15}
\@bowsumiii4 & \@batsum6 \\\cline{1-31}
\@bowsumi5 & & & & & & & & & \\\cline{3-15}
\@bowsumii5 & \@batsum7 \\\cline{3-15}\cline{23-31}
\@bowsumiii5 & & & & & & & & & \\\cline{1-22}
\@bowsumi6 & \@batsum8 \\\cline{3-15}\cline{23-31}
\@bowsumii6 & & & & & & & & & \\\cline{3-15}
\@bowsumiii6 & \@batsum9 \\\cline{1-31}
\@bowsumi7 & & & & & & & & & \\\cline{3-15}
\@bowsumii7 & \@batsum{10} \\\cline{3-15}\cline{23-31}
\@bowsumiii7 & & & & & & & & & \\\cline{1-22}
\@bowsumi8 & \@batsum{11} \\\cline{3-15}\cline{23-31}
\@bowsumii8 & \multicolumn{4}{l|}{} & & & & & \\\cline{3-15}
\@bowsumiii8 & \@battots \\\hline
\end{tabular}}

\def\bownam#1{\normalsize \csname @bw\romannumeral#1\endcsname}

\def\@bowsumi#1{%
 & & Mdns & 
\csname @bw\romannumeral#1@ov\romannumeral1mdn\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral2mdn\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral3mdn\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral4mdn\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral5mdn\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral6mdn\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral7mdn\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral8mdn\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral9mdn\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral10mdn\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral11mdn\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral12mdn\endcsname &
& & & & & &
}

\def\@bowsumii#1{%
\smash{\normalsize \@Alph{#1}} & \smash{\bownam#1} & Runs &
\csname @bw\romannumeral#1@ov\romannumeral1rns\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral2rns\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral3rns\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral4rns\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral5rns\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral6rns\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral7rns\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral8rns\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral9rns\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral10rns\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral11rns\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral12rns\endcsname &
\smash{\ifnum\bowN<#1\relax \else\normalsize\expandafter\the\csname @bw\romannumeral#1noball\endcsname\fi} &
\smash{\ifnum\bowN<#1\relax \else\normalsize\expandafter\the\csname @bw\romannumeral#1wide\endcsname\fi} &
\smash{\ifnum\bowN<#1\relax \else\normalsize\expandafter\the\csname @bw\romannumeral#1@ovbw\endcsname\fi} &
\smash{\normalsize
\ifnum\bowN<#1\relax
\else
\@tmpctr=\csname @bw\romannumeral#1@ovbw\endcsname\relax
\csname @bw\romannumeral#1@ov\romannumeral\@tmpctr mdn\endcsname\fi} &
\smash{\normalsize
\ifnum\bowN<#1\relax
\else
\@tmpctr=\csname @bw\romannumeral#1@ovbw\endcsname\relax
\csname @bw\romannumeral#1@ov\romannumeral\@tmpctr rns\endcsname\fi} &
\smash{\normalsize
\ifnum\bowN<#1\relax
\else
\@tmpctr=\csname @bw\romannumeral#1@ovbw\endcsname\relax
\csname @bw\romannumeral#1@ov\romannumeral\@tmpctr wks\endcsname\fi} & 
\smash{\normalsize
\ifnum\bowN<#1\relax 
\else
\@tmpctr=\csname @bw\romannumeral#1@ovbw\endcsname\relax
\expandafter\ifnum\csname @bw\romannumeral#1@ov\romannumeral\@tmpctr wks\endcsname=0\relax
\makebox[22.77785pt]{--}%
\else
\decfrac{\csname @bw\romannumeral#1@ov\romannumeral\@tmpctr rns\endcsname}{\csname @bw\romannumeral#1@ov\romannumeral\@tmpctr wks\endcsname}%
\fi \fi}
}

\def\@bowsumiii#1{%
 & & Wkts &
\csname @bw\romannumeral#1@ov\romannumeral1wks\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral2wks\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral3wks\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral4wks\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral5wks\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral6wks\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral7wks\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral8wks\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral9wks\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral10wks\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral11wks\endcsname &
\csname @bw\romannumeral#1@ov\romannumeral12wks\endcsname &
 & & & & & &
}

\newcount\@btsirn \@btsirn=-1
\newcount\@btsiirn \@btsiirn=-1
\newcount\@btsiiirn \@btsiiirn=-1
\newcount\@btsivrn \@btsivrn=-1
\newcount\@btsvrn \@btsvrn=-1
\newcount\@btsvirn \@btsvirn=-1
\newcount\@btsviirn \@btsviirn=-1
\newcount\@btsviiirn \@btsviiirn=-1
\newcount\@btsixrn \@btsixrn=-1
\newcount\@btsxrn \@btsxrn=-1
\newcount\@btsxirn \@btsxirn=-1

\newcount\@btsibf \@btsibf=-1
\newcount\@btsiibf \@btsiibf=-1
\newcount\@btsiiibf \@btsiiibf=-1
\newcount\@btsivbf \@btsivbf=-1
\newcount\@btsvbf \@btsvbf=-1
\newcount\@btsvibf \@btsvibf=-1
\newcount\@btsviibf \@btsviibf=-1
\newcount\@btsviiibf \@btsviiibf=-1
\newcount\@btsixbf \@btsixbf=-1
\newcount\@btsxbf \@btsxbf=-1
\newcount\@btsxibf \@btsxibf=-1

\newcount\@btsiIV \@btsiIV=-1
\newcount\@btsiiIV \@btsiiIV=-1
\newcount\@btsiiiIV \@btsiiiIV=-1
\newcount\@btsivIV \@btsivIV=-1
\newcount\@btsvIV \@btsvIV=-1
\newcount\@btsviIV \@btsviIV=-1
\newcount\@btsviiIV \@btsviiIV=-1
\newcount\@btsviiiIV \@btsviiiIV=-1
\newcount\@btsixIV \@btsixIV=-1
\newcount\@btsxIV \@btsxIV=-1
\newcount\@btsxiIV \@btsxiIV=-1

\newcount\@btsiVI \@btsiVI=-1
\newcount\@btsiiVI \@btsiiVI=-1
\newcount\@btsiiiVI \@btsiiiIV=-1
\newcount\@btsivVI \@btsivVI=-1
\newcount\@btsvVI \@btsvVI=-1
\newcount\@btsviVI \@btsviVI=-1
\newcount\@btsviiVI \@btsviiVI=-1
\newcount\@btsviiiVI \@btsviiiVI=-1
\newcount\@btsixVI \@btsixVI=-1
\newcount\@btsxVI \@btsxVI=-1
\newcount\@btsxiVI \@btsxiVI=-1

\def\dspovsItoXX#1{%
\DspOv{1}{#1} &
\DspOv{2}{#1} &
\DspOv{3}{#1} &
\DspOv{4}{#1} &
\DspOv{5}{#1} &
\DspOv{6}{#1} &
\DspOv{7}{#1} &
\DspOv{8}{#1} &
\DspOv{9}{#1} &
\DspOv{10}{#1} &
\DspOv{11}{#1} &
\DspOv{12}{#1} &
\DspOv{13}{#1} &
\DspOv{14}{#1} &
\DspOv{15}{#1} &
\DspOv{16}{#1} &
\DspOv{17}{#1} &
\DspOv{18}{#1} &
\DspOv{19}{#1} &
\DspOv{20}{#1}}

\def\dspovsXXItoXLV#1{%
 &
\DspOv{21}{#1} &
\DspOv{22}{#1} &
\DspOv{23}{#1} &
\DspOv{24}{#1} &
\DspOv{25}{#1} &
\DspOv{26}{#1} &
\DspOv{27}{#1} &
\DspOv{28}{#1} &
\DspOv{29}{#1} &
\DspOv{30}{#1} &
\DspOv{31}{#1} &
\DspOv{32}{#1} &
\DspOv{33}{#1} &
\DspOv{34}{#1} &
\DspOv{35}{#1} &
\DspOv{36}{#1} &
\DspOv{37}{#1} &
\DspOv{38}{#1} &
\DspOv{39}{#1} &
\DspOv{40}{#1} &
\DspOv{41}{#1} &
\DspOv{42}{#1} &
\DspOv{43}{#1} &
\DspOv{44}{#1} &
\DspOv{45}{#1}}

\def\dispbatsxlv#1{%
\normalsize#1 & 
\multicolumn{4}{l|}{\rule[-6pt]{0pt}{18pt}\makebox[\@btnmwd][l]{\normalsize\csname @batsman\romannumeral#1\endcsname}} &
\dspovsItoXX{#1} \dspovsXXItoXLV{#1} \\\cline{2-5}
 &\tiny \rule[-2pt]{0pt}{8pt}In 
\ifnum#1>\batsN 
\relax
\else 
\expandafter\showtime\csname @batsmanin@\romannumeral#1\endcsname
\fi &
\multicolumn{2}{l|}{\tiny Out 
\ifnum#1>\batsN
\relax
\else
\expandafter\ifnum\csname @batsmanout@\romannumeral#1\endcsname>0
\expandafter\showtime\csname @batsmanout@\romannumeral#1\endcsname
\fi
\fi} &
\tiny Time In
\ifnum#1>\batsN
\relax
\else
\expandafter\ifnum\csname @batsmanout@\romannumeral#1\endcsname>0
\timein{#1}
\fi
\fi &
 & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & \\\hline
}

\def\dispbatsxx#1{%
\normalsize#1 & 
\multicolumn{2}{l|}{\rule[-6pt]{0pt}{18pt}\makebox[\@btnmwd][l]{\normalsize\csname @batsman\romannumeral#1\endcsname}} &
\dspovsItoXX{#1} & 
\ifnum#1>\batsN
\relax
\else
\normalsize\expandafter\ifnum\csname @batsmanout@\romannumeral#1\endcsname>0
\smash{\timein{#1}}
\fi
\fi 
&
\smash{\expandafter\ifnum\csname @bts\romannumeral#1bf\endcsname>-1 
\normalsize\expandafter\the\csname @bts\romannumeral#1bf\endcsname\fi}&
\smash{\expandafter\ifnum\csname @bts\romannumeral#1rn\endcsname>-1 
\normalsize\expandafter\the\csname @bts\romannumeral#1rn\endcsname\fi}\\\cline{2-3}
 &\tiny \rule[-2pt]{0pt}{8pt}\qquad In 
\ifnum#1>\batsN 
\relax
\else 
\expandafter\showtime\csname @batsmanin@\romannumeral#1\endcsname
\fi &
\tiny \qquad Out 
\ifnum#1>\batsN
\relax
\else
\expandafter\ifnum\csname @batsmanout@\romannumeral#1\endcsname>0
\expandafter\showtime\csname @batsmanout@\romannumeral#1\endcsname
\fi
\fi &
 & & & & & & & & & & & & & & & & & & & & & & \\\hline
}

\newcommand{\newbowler}[2]{%
\advance\bowN by 1
% bowler's label
\expandafter\def\csname @bw\romannumeral\bowN\endcsname{#1}
% bowler's index
\expandafter\edef\csname @bw@#2\endcsname{\the\bowN}
% number of overs bowled by this person
\expandafter\newcount\csname @bw\romannumeral\bowN @ovbw\endcsname
% number of no balls bowled by this person
\expandafter\newcount\csname @bw\romannumeral\bowN noball\endcsname
% number of wide bowled by this person
\expandafter\newcount\csname @bw\romannumeral\bowN wide\endcsname
}

\newcommand{\howout}[2][\relax]{%
\ifx#1\relax
\@tmpctr=\csname @bw@\@crbw\endcsname
\edef\@outbow{\csname @bw\romannumeral\@tmpctr\endcsname}
\else
\def\@outbow{#1}
\fi
\def\@howout{#2}}

\newcount\@wkct
\newcommand{\newbatsman}[3][0]{%
\advance\batsN by 1
\expandafter\hrstomin#2\to\@tmpctr
\expandafter\def\csname @batsman\romannumeral\batsN\endcsname{#3}
\expandafter\edef\csname @batsmanin@\romannumeral\batsN\endcsname{\the\@tmpctr}
\expandafter\def\csname @batsmanout@\romannumeral\batsN\endcsname{0}
\expandafter\def\csname @btsmn@\romannumeral\batsN @outinov\endcsname{45}
\expandafter\def\csname @howout@\romannumeral\batsN\endcsname{NOT}
\expandafter\def\csname @outbow@\romannumeral\batsN\endcsname{OUT}
\ifnum\batsN>2
\expandafter\edef\csname @btsmn@\romannumeral\batsN @inov\endcsname{\the\overN}
\advance\@tmpctr by -#1
\ifnum\@wkct<\@wktsthisov
\advance\@wkct by 1
\@tmpctrII=\csname @batsmout\romannumeral\@wkct\endcsname
\relax
\expandafter\edef\csname @batsmanout@\romannumeral\@tmpctrII\endcsname{%
\the\@tmpctr}
\expandafter\edef\csname @btsmn@\romannumeral\@tmpctrII @outinov\endcsname{%
\the\overN}
\expandafter\edef\csname @howout@\romannumeral\@tmpctrII\endcsname{%
\@howout}
\expandafter\edef\csname @outbow@\romannumeral\@tmpctrII\endcsname{%
\@outbow}
\else
\ClassError{crkscrsh}{Too many batsman on crease!}{%
You have specified a new batsman when there was no corresponding
wicket taken in the last over}
\fi
\else
\csname @bts\romannumeral\batsN bf\endcsname=0\relax
\csname @bts\romannumeral\batsN rn\endcsname=0\relax
\csname @bts\romannumeral\batsN IV\endcsname=0\relax
\csname @bts\romannumeral\batsN VI\endcsname=0\relax
\expandafter\def\csname @btsmn@\romannumeral\batsN @inov\endcsname{1}
\fi
\def\@howout{}\def\@outbow{}
}

\newcommand{\InningsEndTime}[1]{%
\ifnum\fcg>0
\expandafter\hrstomin#1\to\@tmpctr
\expandafter\edef\csname @batsmanout@\romannumeral\fcg\endcsname{\the\@tmpctr}
\fi
\ifnum\nfcg>0
\expandafter\hrstomin#1\to\@tmpctr
\expandafter\edef\csname @batsmanout@\romannumeral\nfcg\endcsname{\the\@tmpctr}
\fi
}

\def\hrstomin#1:#2\to#3{%
#3=#1
\multiply#3 by 60
\advance#3 by #2}

\newcount\@hrs \newcount\@mins
\def\gethrsmins#1:#2\end{%
\@hrs=#1 \@mins=#2}

% takes time as mins, prints as hr:min
\def\showtime#1{%
\@hrs=#1
\divide\@hrs by 60
\@mins=#1
\modulo{\@mins}{60}
\ifnum\@hrs<10 0\fi\the\@hrs:%
\ifnum\@mins<10 0\fi\the\@mins
}

\def\timein#1{%
\ifnum#1>\batsN
\relax
\else
% \@tmpctr = time in
\@tmpctr=\csname @batsmanin@\romannumeral#1\endcsname
% \@tmpctrII = time out
\@tmpctrII=\csname @batsmanout@\romannumeral#1\endcsname
\advance\@tmpctrII by -\@tmpctr
\the\@tmpctrII
\fi}

\def\addthisball#1#2#3{%
\expandafter\addto\csname @ov@bat@\romannumeral#2\endcsname\item{#1}
\expandafter\addto\csname @ov@bat@\romannumeral#3\endcsname\item{x}
\@tmpctr=#2
\advance\@tmpctr by 1
\@tmpctrII=\@tmpctr
\advance\@tmpctrII by 3
\ifnum\@tmpctrII>11 \@tmpctrII=11 \fi
\@ctr=\@tmpctr\relax
\whiledo{\@ctr < \@tmpctrII \TE@or \@ctr = \@tmpctrII}{%
\ifnum\@ctr=#2
\relax
\else
\ifnum\@ctr=#3
\relax
\else
\expandafter\addto\csname @ov@bat@\romannumeral\@ctr\endcsname\item{x}
\fi
\fi
\advance\@ctr by 1\relax
}\relax
}


\def\getball#1{%
\ifx#1\end
\let\next=\relax
\else
\ifthenelse{\equal{#1}{s}}{%
\swap{\fcg}{\nfcg}
}{%
\advance\@ball by 1
\ifthenelse{\equal{#1}{r} \or \equal{#1}{w}}{}{\addthisball{#1}{\fcg}{\nfcg}}
%
\ifthenelse{\equal{#1}{w} \or \equal{#1}{r}}{%
\ifthenelse{\equal{#1}{w}}{%
\advance\@wickets by 1
\expandafter\edef\csname @fow\romannumeral\@wickets scr\endcsname{\the\@tot}}%
{}
\advance\@wktsthisov by 1
\edef\@tmp{\csname @batsmout\romannumeral\@wktsthisov\endcsname}
\ifnum\@tmp=0
\ClassError{crkscrsh}{Inconsistency in fall of wickets}{%
You need to specify which batsman was out in \protect\Over}
\else
\expandafter\advance\csname @bts\romannumeral\fcg bf\endcsname by 1
\ifnum\@tmp=\fcg % facing batsman was out
\ifthenelse{\equal{#1}{w}}{%
\addthisball{#1}{\fcg}{\nfcg}
\expandafter\edef\csname @fow\romannumeral\@wickets bts\endcsname{\the\fcg}}{}
\advance\@batsmanN by 1
\fcg=\@batsmanN
\csname @bts\romannumeral\@batsmanN bf\endcsname=0
\csname @bts\romannumeral\@batsmanN rn\endcsname=0
\csname @bts\romannumeral\@batsmanN IV\endcsname=0
\csname @bts\romannumeral\@batsmanN VI\endcsname=0
\else
\ifnum\@tmp=\nfcg % non-facing batsman out
\ifthenelse{\equal{#1}{w}}{%
\addthisball{#1}{\nfcg}{\fcg}
\expandafter\edef\csname @fow\romannumeral\@wickets bts\endcsname{\the\nfcg}}{}
\advance\@batsmanN by 1
\nfcg=\@batsmanN
\csname @bts\romannumeral\@batsmanN bf\endcsname=0
\csname @bts\romannumeral\@batsmanN rn\endcsname=0
\csname @bts\romannumeral\@batsmanN IV\endcsname=0
\csname @bts\romannumeral\@batsmanN VI\endcsname=0
\else
\ClassError{crkscrsh}{Batsman \@tmp \space is not in the crease at fall of wicket}{}
\fi
\fi
\fi
}{%
\ifthenelse{\equal{#1}{.}}{%
% dot ball
\expandafter\advance\csname @bts\romannumeral\fcg bf\endcsname by 1
}{%
\ifthenelse{\equal{#1}{+}}{}{%
% Run(s) scored
\advance\@runs by #1
\expandafter\advance\csname @bts\romannumeral\fcg rn\endcsname by #1
\expandafter\advance\csname @bts\romannumeral\fcg bf\endcsname by 1
\ifnum#1=4\relax
\expandafter\advance\csname @bts\romannumeral\fcg IV\endcsname by 1
\else
\ifnum#1=6\relax
\expandafter\advance\csname @bts\romannumeral\fcg VI\endcsname by 1
\fi
\fi
\ifodd#1
\swap{\fcg}{\nfcg}
\fi
}}}}
\let\next=\getball
\fi
\next}

\def\getbatsmani#1{%
\ifx#1\end
\let\next=\relax
\else
\advance\@wktsthisov by 1
\expandafter\def\csname @batsmout\romannumeral\@wktsthisov\endcsname{#1}
\let\next=\getbatsmani
\fi
\next
}

\newcount\@wktsthisov
\def\getbatsmenout#1{%
\@wktsthisov=0
\@ctr=1\relax
\whiledo{\@ctr < 12}{%
\expandafter\def\csname @batsmout\romannumeral\@ctr\endcsname{0}\relax
\advance\@ctr by 1\relax}
\ifx#1\relax
\else
\getbatsmani#1\end
\fi
}

\newcount\@wickets \newcount\@runs \newcount\@ball \newcount\@batsmanN
\newcount\@mdns \newcount\@wks \newcount\@rns
\def\@crbw{} % current bowler
\newcommand{\Over}[3][\relax]{%
\advance\overN by 1
\def\@crbw{#2}
\getbatsmenout{#1}
\@batsmanN=\batsN
\expandafter\edef\csname @ov\romannumeral\overN bw\endcsname{%
\expandafter\@Alph\csname @bw@#2\endcsname}
\@runs=0 \@ball=0
\@ctr=1\relax
\whiledo{\@ctr < 12}{%
\expandafter\def\csname @ov@bat@\romannumeral\@ctr\endcsname{}
\advance\@ctr by 1\relax
}\relax
\@wktsthisov=0
\getball#3\end
\@ctr=1\relax
\whiledo{\@ctr < 12}{%
\expandafter\edef\csname @ov\romannumeral\overN @bat@\romannumeral\@ctr\endcsname{\csname @ov@bat@\romannumeral\@ctr\endcsname}
\advance\@ctr by 1\relax
}
%
\@ctr=\csname @bw@\@crbw\endcsname\relax
\expandafter\advance\csname @bw\romannumeral\@ctr @ovbw\endcsname by 1\relax
\@tmpctr=\csname @bw\romannumeral\@ctr @ovbw\endcsname
%
\@tmpctrII=\@tmpctr
\advance\@tmpctrII by -1
\ifnum\@tmpctr=1
\@mdns=0\relax
\else
\@mdns=\csname @bw\romannumeral\@ctr @ov\romannumeral\@tmpctrII mdn\endcsname
\fi
\ifnum\@runs=0
\advance\@mdns by 1\relax
\fi
\expandafter\edef\csname @bw\romannumeral\@ctr @ov\romannumeral\@tmpctr mdn\endcsname{\the\@mdns}
%
\ifnum\@tmpctr=1
\@wks=0\relax
\else
\@wks=\csname @bw\romannumeral\@ctr @ov\romannumeral\@tmpctrII wks\endcsname
\fi
\advance\@wks by \@wktsthisov\relax
\expandafter\edef\csname @bw\romannumeral\@ctr @ov\romannumeral\@tmpctr wks\endcsname{\the\@wks}
%
\ifnum\@tmpctr=1
\@rns=0\relax
\else
\@rns=\csname @bw\romannumeral\@ctr @ov\romannumeral\@tmpctrII rns\endcsname
\fi
\advance\@rns by \@runs\relax
\expandafter\edef\csname @bw\romannumeral\@ctr @ov\romannumeral\@tmpctr rns\endcsname{\the\@rns}
%
%
\advance\@runtot by \@runs
\advance\@tot by \@runs
\expandafter\edef\csname @ov\romannumeral\overN wks\endcsname{%
\the\@wickets}
\expandafter\edef\csname @ov\romannumeral\overN tot\endcsname{%
\the\@tot}
%
\swap{\fcg}{\nfcg}
\@wkct=0
}

\toksdef\ta=0 \toksdef\tb=2
\long\def\append#1\to#2{\ta={#1}\tb=\expandafter{#2}%
\edef#2{\the\tb\the\ta}}

\def\addto#1\item#2{\append#2\to#1}

\newcommand{\extra}[2]{%
\advance\@extot by #2
\advance\@tot by #2
\expandafter\edef\csname @ov\romannumeral\overN tot\endcsname{%
\the\@tot}
\expandafter\ifx\csname @ex@#1\endcsname\relax
\ClassError{crkscrsh}{Unknown extra name}{The first argument
to \protect\extra \space must be one of: bye, legbye,
wide or noball}
\else
\expandafter\advance\csname @ex@#1\endcsname by #2
\ifthenelse{\equal{#1}{noball} \or \equal{#1}{wide}}{%
\@ctr=\csname @bw@\@crbw\endcsname\relax
\expandafter\advance\csname @bw\romannumeral\@ctr#1\endcsname by 1
}{}
\fi
}

\def\getballfordisp#1{%
\ifx#1\end%
\let\next=\relax%
\else
\advance\@ball by 1\relax
\ifthenelse{\equal{#1}{x}}{%
\expandafter\def\csname @tmpball\romannumeral\@ball\endcsname{\phantom{x}}}%
{\expandafter\def\csname @tmpball\romannumeral\@ball\endcsname{#1}}%
\let\next=\getballfordisp%
\fi
\next}

\newcommand{\dspball}[1]{\csname @tmpball\romannumeral#1\endcsname}

\newcommand{\VIballover}{%
\begin{tabular}[t]{@{}cc@{}}%
\dspball1 & \dspball4 \\
\dspball2 & \dspball5 \\
\dspball3 & \dspball6
\end{tabular}}

\newcommand{\IXballover}{%
\ifnum\maxovers=45\relax \setlength{\tabcolsep}{0.1pt}\fi%
\begin{tabular}[t]{@{}ccc@{}}%
\dspball1 & \dspball4 & \dspball7\\
\dspball2 & \dspball5 & \dspball8\\
\dspball3 & \dspball6 & \dspball9
\end{tabular}}

\newcommand{\XIIballover}{%
\ifnum\maxovers=45\relax \setlength{\tabcolsep}{-1pt}\relax
\else \setlength{\tabcolsep}{0.1pt}\relax \fi
\begin{tabular}[t]{@{}cccc@{}}
\dspball1 & \dspball4 & \dspball7 & \dspball{10}\\
\dspball2 & \dspball5 & \dspball8 & \dspball{11}\\
\dspball3 & \dspball6 & \dspball9 & \dspball{12}
\end{tabular}}

\newcommand{\dspov}[1]{%
\ifx#1\relax
\else
\@ball=0\relax
\expandafter\getballfordisp#1\end%
\makebox[\@ovwd]{\smash{%
\ifnum\@ball>9\relax
\XIIballover
\else
\ifnum\@ball>6\relax
\IXballover
\else
\VIballover
\fi\fi}}%
\fi%
}

\newif\ifinrange
\def\checkinrange#1<=#2<=#3\end{%
\inrangefalse
\expandafter\ifnum#1=#2
\inrangetrue
\fi
\expandafter\ifnum#3=#2
\inrangetrue
\fi
\expandafter\ifnum#1<#2
\expandafter\ifnum#3>#2
\inrangetrue
\fi
\fi
}
            
% #1->over, #2->batsman
\newcommand{\DspOv}[2]{%
\checkinrange1<=#2<=\batsN\end
\ifinrange
\@tmpctr=#1\relax
\advance\@tmpctr by -1\relax
\@tmpctrII=\csname @btsmn@\romannumeral#2@outinov\endcsname \relax
%
\ifnum\@tmpctrII=\@tmpctr\relax
\makebox[\@ovwd]{\smash{\raisebox{-4pt}{$\left.\left.\rule{0pt}{10pt}\right\rangle\!\!\right\rangle$}}}%
\else
\@tmpctr=\csname @btsmn@\romannumeral#2@inov\endcsname\relax
\checkinrange\@tmpctr<=#1<=\@tmpctrII\end
\ifinrange
\raisebox{5pt}{\expandafter\dspov\csname @ov\romannumeral#1@bat@\romannumeral#2\endcsname}%
\fi
\fi
\fi
}

\newcount\@swapctr
\newcommand{\swap}[2]{%
\@swapctr=#1
#1=#2
#2=\@swapctr}
%    \end{macrocode}
%\Finale
%\endinput
                                                                                            
\AtBeginDocument{\sffamily\raggedbottom}
