% BibTeX bibliography style based on the harvard.sty for use with
% the harvard bibtex family (agsm.bst, dcu.bst or kluwer.bst).
% version 0.99a for BibTeX versions 0.99a or later, LaTeX version 2.09.
%
%   This document is a modified version of harvard.sty to which it owes much of
%   its functionality.
%   The changes compared to the harvard style are:
%   (1) In addition to \cite{} and \citeasnoun{} there is now a new
%       command \shortcite{}. This command produces a <year> entry
%       only, without a author name. The year is given in parantheses
%       or brackets. The \shortcite command allows more than one
%       entry.
%   (2) The first entry of a multi author reference is abbreviated
%       with <et al>.
%   (3) The entries are either framed with brackets or parantheses.
%       A new definition at the beginning of the file can be
%       adapted easily for that purpose.
%
%   This latex style requires one of the harvard bibtex styles 
%   (agsm.bst, dcu.bst or kluwer.bst) or an
%   adapted style. The default \citationsstyle is agsm.
%-------------------------------------------------------------------------------
%   Created:
%   930416 as bibtex style for my dissertation                      Markus Flury
%   (changes 1,2,3)
%   
%   Changes:
%
%
%-------------------------------------------------------------------------------

\message{sssaj bibliography,}

%---change parantheses to brackets or vice versa or what ever---
\def\leftframe{(}
\def\rightframe{)}
%---------------------------------------------------------------

\def\@hiteml[#1]#2#3#4{\item[]\if@filesw%
      { \def\protect##1{\string ##1\space}\immediate%
\write\@auxout{\string\harvardcite{#4}{#2}{#1}{#3}}}\fi%
\protect\hspace*{-\labelwidth}\protect\hspace*{-\labelsep}\ignorespaces}

\def\@hitem#1#2#3{\item[]\if@filesw%
      { \def\protect##1{\string ##1\space}\immediate%
\write\@auxout{\string\harvardcite{#3}{#1}{#1}{#2}}}\fi%
\protect\hspace*{-\labelwidth}\protect\hspace*{-\labelsep}\ignorespaces}

\def\harvarditem{\@ifnextchar [{\@hiteml}{\@hitem}}

\def\harvardcite#1#2#3#4{
  \global\@namedef{bhf@#1}{#2}
  \global\@namedef{bha@#1}{#3}
  \global\@namedef{bhy@#1}{#4}\global\@namedef{b@#1}{\csname bha@#1\endcsname}
}

\def\cite{\@ifnextchar [{\@tempswatrue\@citex}{\@tempswafalse\@citex[]}}
\def\shortcite{\@ifnextchar [{\@tempswatrue\@shortcitex}{\@tempswafalse\@shortcitex[]}}
\def\citeasnoun{\@ifnextchar [{\@tempswatrue\@citexasnoun}
                           {\@tempswafalse\@citexasnoun[]}
}

\def\listcite{\@ifnextchar [{\@tempswatrue\@listcitex}{\@tempswafalse\@listcitex[]}}

\def\@enamedef#1{\expandafter\edef\csname #1\endcsname}

\def\@citex[#1]#2{\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi
  \def\@citea{}\@cite{\@for\@citeb:=#2\do
    {\@citea\def\@citea{\@hisep\penalty\@m\ }\@ifundefined
       {b@\@citeb}{{\bf ?}\@warning
       {Citation `\@citeb' on page \thepage \space undefined}}%
{{\csname b@\@citeb\endcsname\@hysep\csname bhy@\@citeb\endcsname}%
\global\@enamedef{b@\@citeb}{\csname bha@\@citeb\endcsname}}%
}}{#1}}

\def\@shortcitex[#1]#2{\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi
  \def\@shortcitea{}\@shortcite{\@for\@shortciteb:=#2\do
    {\@shortcitea\def\@shortcitea{\@hisep\penalty\@m\ }\@ifundefined
       {b@\@shortciteb}{{\bf ?}\@warning
       {Citation `\@shortciteb' on page \thepage \space undefined}}%
{{\csname bhy@\@shortciteb\endcsname}%
\global\@enamedef{}{}}%
}}{#1}}

\def\@citexasnoun[#1]#2{%
\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi%
\@citeasnoun{{\@ifundefined%
{b@#2}%
{{\bf ?}\@warning{Citation `#2' on page \thepage \space undefined}}%
{{\csname b@#2\endcsname\ \leftframe\csname bhy@#2\endcsname}%
\global\@namedef{b@#2}{\csname bha@#2\endcsname}}%
}}{#1}}

\def\@listcitex[#1]#2{\if@filesw\immediate\write\@auxout{\string\citation{#2}}\fi
  \def\@listcitea{}\@listcite{\@for\@listciteb:=#2\do
    {\@listcitea\def\@listcitea{\@hisep\penalty\@m\ }\@ifundefined
       {b@\@listciteb}{{\bf ?}\@warning
       {Citation `\@listciteb' on page \thepage \space undefined}}%
{{\csname b@\@listciteb\endcsname\@hysep\csname bhy@\@listciteb\endcsname}%
\global\@enamedef{b@\@listciteb}{\csname bha@\@listciteb\endcsname}}%
}}{#1}}


\gdef\hysep@agsm{\ }\gdef\hisep@agsm{,}%
\gdef\hysep@dcu{, }\gdef\hisep@dcu{;}%
\let\@hysep\hysep@agsm \let\@hisep\hisep@agsm
\def\citationstyle#1{%
\global\@namedef{@hysep}{\csname hysep@#1\endcsname}%
\global\@namedef{@hisep}{\csname hisep@#1\endcsname}}

%DEFAULT DEFINITIONS
\def\@cite#1#2{\leftframe{#1\if@tempswa , #2\fi}\rightframe}
\def\@shortcite#1#2{\leftframe{#1\if@tempswa , #2\fi}\rightframe}
\def\@citeasnoun#1#2{{#1\if@tempswa , #2\fi\rightframe}}
\def\@listcite#1#2{{#1\if@tempswa , #2\fi}}

% CHANGE \end{document} - to handle double definitions
\def\enddocument{\@checkend{document}\clearpage\begingroup
\if@filesw \immediate\closeout\@mainaux
\def\global\@namedef##1##2{}\def\newlabel{\@testdef r}%
\def\bibcite{\@testdef b}%
\def\harvardcite{\@testbibh}\@tempswafalse \makeatletter\input \jobname.aux
\if@tempswa \@warning{Label(s) may have changed.  Rerun to get
cross-references right}\fi\fi\endgroup\deadcycles\z@\@@end}

\def\@testbibh #1#2#3{
  \def\@tempa{#2}\expandafter
  \ifx \csname bhf@#1\endcsname \@tempa
     \def\@tempa{#3}\expandafter
     \ifx \csname bha@#1\endcsname \@tempa
     \else \@tempswatrue
     \fi
  \else
     \@tempswatrue
  \fi
}

