% \iffalse meta-comment
%%
%% Copyright (C) 2012 by Simon Sigurdhsson <sigurdhsson@gmail.com>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status `unmaintained'.
%% 
%% This work consists of the files chscite.dtx and chscite.ins
%% and the derived filebase chscite.sty.
%% 
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{chscite.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{chscite}
%<*package>
    [2012/12/16 v2.9999 Chalmers bibliography style]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{chscite}[2012/12/16]
\AtBeginDocument{%
	\OnlyDescription%
%	\CodelineIndex%
%	\EnableCrossrefs%
	\RecordChanges%
}
\AtEndDocument{%
	\PrintChanges%
	\PrintIndex%
}
\begin{document}
  \DocInput{chscite.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v1.0}{2011/06/05}{Initial version}
% \changes{v2.0}{2011/06/06}{Added language options}
% \changes{v2.0c}{2011/06/22}{Improved translations}
% \changes{v2.9}{2011/09/16}{Polyglossia compatibility}
% \changes{v2.9}{2011/09/16}{Various bugfixes}
% \changes{v2.9}{2011/09/16}{Improved documentation}
% \changes{v2.99}{2011/09/16}{Fixed critical \texttt{.dtx} bug}
%
% \GetFileInfo{chscite.dtx}
%
% \DoNotIndex{\newcommand,\newenvironment,\ ,\null,\ifthenelse,\def,\equal}
% 
% \GetFileInfo{chscite.dtx}
% \title{The \textsf{chscite} package\thanks{This document
%   corresponds to \textsf{chscite}~\fileversion~(converges to 3, a
%   completely arbitrary number), dated \filedate.}}
% \author{Simon Sigurdhsson \\ \texttt{sigurdhsson@gmail.com}\footnote{This package is currently unmaintained. If you'd like to maintain it, please get in touch and I'll transfer the Github repository to you.}}
%
% \maketitle
% \tableofcontents
%
% \section{Introduction}
%
% This package, heavily based on the \textsf{harvard} package for 
% Harvard-style citations, provides a citation suite for students at Chalmers
% University of Technology that follows given recommendations. The package
% is aimed at the swedish audience, with additional support for english
% enabled by default.
%
% \section{Usage}
% This section assumes general knowledge of \textsc{Bib}\TeX{}, and in
% particular that the user knows how to create \textsc{Bib}\TeX{} databases,
% include these in \LaTeX{} documents and run the |bibtex| binary.
%
% \subsection{Options}
% The package is invoked as |\usepacakge|\oarg{language}|{chscite}|, where
% \meta{language} can be either |english| (the default) or |swedish|. The
% language option controls the language of various internal strings used by
% the \textsc{Bib}\TeX{} style |chscite.bst|.
%
% \subsection{Commands}
% The package itself contains relatively few user-exposed commands. These can
% be used to cite references in a few different ways. For more information on
% these commands, refer to the \textsf{harvard} package manual.
%
% \subsubsection{Full citations}
% \DescribeMacro{\nocite}
% The \cs{nocite}\marg{reference} command includes a reference in the
% bibliography without printing anything. This is useful for references that
% aren't actually referenced in text.
%
% \DescribeMacro{\cite}
% The familiar \cs{cite}\oarg{suffix}\marg{reference} command works as for
% standard \textsc{Bib}\TeX{} styles, except it now uses the Harvard 
% convention for citing references. Sample output: \textbf{(Lamport 1986)}.
%
% \DescribeMacro{\citeaffixed}
% The \cs{citeaffixed}\oarg{suffix}\marg{reference}\marg{prefix} command works
% the same way as \cs{cite}, but prefixes the output with \meta{prefix}.
% Sample output: \textbf{(i.e.~Lamport 1986)}.
%
% \DescribeMacro{\citeasnoun}
% The \cs{citeasnoun}\oarg{suffix}\marg{reference} command cites a reference
% as a noun. Sample output: \textbf{Lamport (1986)}.
%
% \DescribeMacro{\possessivecite}
% The \cs{possessivecite}\oarg{suffix}\marg{reference} command cites a 
% reference as in the possessive manner.
% Sample output: \textbf{Lamport's (1986)}.
%
% \subsubsection{Partial citations}
% \DescribeMacro{\citename}
% The \cs{citename}\marg{reference} command simply prints the author name(s)
% of the given reference.
%
% \DescribeMacro{\citeyear}
% The \cs{citeyear}\marg{reference} command simply prints the year
% of the given reference.
%
% \subsection{Using \texttt{@misc} for web sources}
% In this package, the \texttt{@misc} \textsc{Bib}\TeX{} style has been crafted
% to typeset web sources correctly as per Chalmers recommendations. Proper use,
% apart from usual \textsc{Bib}\TeX{} syntax, includes using the \texttt{note}
% field to specify retreival date and the \texttt{howpublished} field for web
% page title:
% \iffalse
%<*example>
% \fi
\begin{verbatim}
@misc{google,
	author = {Johnson, S.},
	year = 2007,
	title = {Exploiting the mobile channel},
	howpublished = {m.Net Corporation},
	url = {http://www.mnetcorporation.com/article-exploiting-the-mobile-channel},
	note = {2008-04-18}
}
\end{verbatim}
% \iffalse
%</example>
% \fi
%
% \subsection{Using the \texttt{@patent} entry type}
% The \texttt{@patent} included in this package is a custom alternative to
% \texttt{@techreport} especially made for referencing patents. Required fields
% are \texttt{author}, \texttt{year}, \texttt{title} and \texttt{number} (the
% patent number). There are no optional fields: 
% \iffalse
%<*example>
% \fi
\begin{verbatim}
@patent{volvo,
	author = {{Volvo Lastvagnar}},
	year = 2006,
	title = {Information based controlling of chassis height of a vehicle},
	number = {SE0403224}
}
\end{verbatim}
% \iffalse
%</example>
% \fi
%
% \section{Known issues}
% The |chscite.bst| \textsc{Bib}\TeX{} style does not support cross references
% at the moment. This is a planned improvement.
%
% \PrintChanges
%
% \StopEventually{}
%
% \section{Implementation}
%
% \subsection{\LaTeX{} package file \texttt{chscite.sty}}
%
% \iffalse
%<*package>
% \fi
%
%    \begin{macrocode}
\RequirePackage{ifthen}
\@ifundefined{url}{\RequirePackage{url}}{}
%    \end{macrocode}
%
% \begin{macro}{\chsurl}
%    \begin{macrocode}
\newcommand{\chsurl}[1]{\url{#1}}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%% Kristoffer H. Rose <kris@diku.dk> 1995/03/01:
%%   do not expand macros in citations: put definitions on .aux file instead.
{\catcode`\:=12 \catcode`\-=12 \catcode`\>=12 \catcode`\<=12 %
 \gdef\codeof#1{\expandafter\codeof@\meaning#1<-:}%
 \gdef\codeof@#1:->#2<-:{#2}}
%    \end{macrocode}
%
% \begin{macro}{\chspreambletext}
%    \begin{macrocode}
\def\chspreambletext{\catcode`\#=12 \chspreambletext@}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\chspreambletext@}
%    \begin{macrocode}
\def\chspreambletext@#1{\def\next{#1}\catcode`\#=6 %
  \immediate\write\@auxout{\string\chspreambledefs{%
      \string\AtBeginDocument{\codeof\next}}}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\chspreambledefs}
%    \begin{macrocode}
\def\chspreambledefs#1{#1\gdef\chspreambledefs##1{}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\chsitem}
%    \begin{macrocode}
\newcommand{\chsitem}[4][\null]{\item[]%
\if@filesw{ \def\protect##1{\string ##1\space}%
\ifthenelse{\equal{#1}{\null}}
  {\def\next{{#4}{#2}{#2}{#3}}}
  {\def\next{{#4}{#2}{#1}{#3}}}
\immediate\write\@auxout{\string\chscite\codeof\next}%
}\fi%
\protect\hspace*{-\labelwidth}\protect\hspace*{-\labelsep}\ignorespaces%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\chscite}
%    \begin{macrocode}
\newcommand{\chscite}[4]{
  \global\@namedef{CHS@fn@#1}{#2}
  \global\@namedef{CHS@an@#1}{#3}
  \global\@namedef{CHS@yr@#1}{#4}
  \global\@namedef{CHS@df@#1}{\csname CHS@fn@#1\endcsname}
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\CHS@citetoaux}
%    \begin{macrocode}
\newcommand{\CHS@citetoaux}[1]{%
  \if@filesw\immediate\write\@auxout{\string\citation{#1}}\fi%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\CHS@checkdef}
%    \begin{macrocode}
\newcommand{\CHS@checkdef}[2]{\@ifundefined{CHS@df@#1}%
  {\textbf{?}\@warning{Citation '#1' on page \thepage \space undefined}}%
  {#2}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\CHS@dolist}
%    \begin{macrocode}
\newcommand{\CHS@dolist}[2]{\def\@citea{\null}\@for\@citeb:=#1\do%
{\@citea\def\@citea{,\penalty\@m\ }\CHS@checkdef{\@citeb}%
{#2{\@citeb}\null\penalty\@m\ %
\CHS@year{\@citeb}\CHS@setd{\@citeb}}}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@enamedef}
%    \begin{macrocode}
\def\@enamedef#1{\expandafter\def\csname #1\expandafter\endcsname\expandafter}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\CHS@name}
%    \begin{macrocode}
\newcommand{\CHS@name}[1]{\csname CHS@df@#1\endcsname}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\CHS@fname}
%    \begin{macrocode}
\newcommand{\CHS@fname}[1]{\csname CHS@fn@#1\endcsname}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\CHS@aname}
%    \begin{macrocode}
\newcommand{\CHS@aname}[1]{\csname CHS@an@#1\endcsname}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\CHS@year}
%    \begin{macrocode}
\newcommand{\CHS@year}[1]{\csname CHS@yr@#1\endcsname}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\CHS@setd}
%    \begin{macrocode}
\newcommand{\CHS@setd}[1]{%
\global\@enamedef{CHS@df@#1}{\csname CHS@an@#1\endcsname}%
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\CHS@df@}
%    \begin{macrocode}
%% Berwin A. Turlach <berwin@alphasun.anu.edu.au>
\global\@namedef{CHS@df@*}{\csname CHS@fn@*\endcsname}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\nocite}
% Cite a reference without printing anything.
%    \begin{macrocode}
\renewcommand{\nocite}[1]{\CHS@citetoaux{#1}%
\@for\@citeb:=#1\do%
{\CHS@checkdef{\@citeb}{}}}%
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\cite}
% \begin{macro}{\CHS@dcite}
% \begin{macro}{\CHS@acite}
% \begin{macro}{\CHS@fcite}
% Cite a reference in the traditional manner.
%    \begin{macrocode}
\renewcommand{\cite}{\@ifstar{\@ifstar{\CHS@acite}{\CHS@fcite}}{\CHS@dcite}}
\newcommand{\CHS@dcite}[2][\null]{\CHS@citetoaux{#2}%
{(\CHS@dolist{#2}{\CHS@name}\ifthenelse{\equal{#1}{\null}}%
  {}{, #1})}%
}
\newcommand{\CHS@acite}[2][\null]{\CHS@citetoaux{#2}%
{(\CHS@dolist{#2}{\CHS@aname}\ifthenelse{\equal{#1}{\null}}%
  {}{, #1})}%
}
\newcommand{\CHS@fcite}[2][\null]{\CHS@citetoaux{#2}%
{(\CHS@dolist{#2}{\CHS@fname}\ifthenelse{\equal{#1}{\null}}%
  {}{, #1})}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\citeaffixed}
% \begin{macro}{\CHS@fciteaff}
% \begin{macro}{\CHS@aciteaff}
% \begin{macro}{\CHS@dciteaff}
% Cite a reference with affixed text.
%    \begin{macrocode}
\newcommand{\citeaffixed}{\@ifstar{\@ifstar{\CHS@aciteaff}{\CHS@fciteaff}}%
{\CHS@dciteaff}%
}
\newcommand{\CHS@fciteaff}[3][\null]{\CHS@citetoaux{#2}%
{(#3\ \CHS@dolist{#2}{\CHS@fname}\ifthenelse{\equal{#1}{\null}}%
    {}{, #1})}%
}
\newcommand{\CHS@aciteaff}[3][\null]{\CHS@citetoaux{#2}%
{(#3\ \CHS@dolist{#2}{\CHS@aname}\ifthenelse{\equal{#1}{\null}}%
    {}{, #1})}%
}
\newcommand{\CHS@dciteaff}[3][\null]{\CHS@citetoaux{#2}%
{(#3\ \CHS@dolist{#2}{\CHS@name}\ifthenelse{\equal{#1}{\null}}%
    {}{, #1})}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\citeasnoun}
% \begin{macro}{\CHS@fciteasn}
% \begin{macro}{\CHS@aciteasn}
% \begin{macro}{\CHS@dciteasn}
% Cite a reference as a noun.
%    \begin{macrocode}
\newcommand{\citeasnoun}{\@ifstar{\@ifstar{\CHS@aciteasn}{\CHS@fciteasn}}%
{\CHS@dciteasn}%
}
\newcommand{\CHS@fciteasn}[2][\null]{\CHS@citetoaux{#2}\CHS@checkdef{#2}{%
{\CHS@fname{#2}\ (\CHS@year{#2}\ifthenelse{\equal{#1}{\null}}
    {}{, #1})}\CHS@setd{#2}}%
}
\newcommand{\CHS@aciteasn}[2][\null]{\CHS@citetoaux{#2}\CHS@checkdef{#2}{%
{\CHS@aname{#2}\ (\CHS@year{#2}\ifthenelse{\equal{#1}{\null}}
    {}{, #1})}\CHS@setd{#2}}%
}
\newcommand{\CHS@dciteasn}[2][\null]{\CHS@citetoaux{#2}\CHS@checkdef{#2}{%
{\CHS@name{#2}\ (\CHS@year{#2}\ifthenelse{\equal{#1}{\null}}
    {}{, #1})}\CHS@setd{#2}}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\possessivecite}
% \begin{macro}{\CHS@fcitepos}
% \begin{macro}{\CHS@acitepos}
% \begin{macro}{\CHS@dcitepos}
% Cite a reference in the possessive.
%    \begin{macrocode}
\newcommand{\possessivecite}{\@ifstar{\@ifstar{\CHS@acitepos}{\CHS@fcitepos}}%
{\CHS@dcitepos}%
}
\newcommand{\CHS@fcitepos}[2][\null]{\CHS@citetoaux{#2}\CHS@checkdef{#2}{%
{\CHS@fname{#2}s (\CHS@year{#2}\ifthenelse{\equal{#1}{\null}}
    {}{, #1})}\CHS@setd{#2}}%
}
\newcommand{\CHS@acitepos}[2][\null]{\CHS@citetoaux{#2}\CHS@checkdef{#2}{%
{\CHS@aname{#2}s (\CHS@year{#2}\ifthenelse{\equal{#1}{\null}}
    {}{, #1})}\CHS@setd{#2}}%
}
\newcommand{\CHS@dcitepos}[2][\null]{\CHS@citetoaux{#2}\CHS@checkdef{#2}{%
{\CHS@name{#2}s (\CHS@year{#2}\ifthenelse{\equal{#1}{\null}}
    {}{, #1})}\CHS@setd{#2}}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\citename}
% \begin{macro}{\CHS@fcitenam}
% \begin{macro}{\CHS@acitenam}
% \begin{macro}{\CHS@dcitenam}
% Print the name(s) of the author(s) of a specific reference.
%    \begin{macrocode}
\newcommand{\citename}{\@ifstar{\@ifstar{\CHS@acitenam}\CHS@fcitenam}%
{\CHS@dcitenam}%
}
\newcommand{\CHS@fcitenam}[2][\null]{\CHS@citetoaux{#2}\CHS@checkdef{#2}{%
{\CHS@fname{#2}\ifthenelse{\equal{#1}{\null}}
    {}{\ (#1)}}}%
}
\newcommand{\CHS@acitenam}[2][\null]{\CHS@citetoaux{#2}\CHS@checkdef{#2}{%
{\CHS@aname{#2}\ifthenelse{\equal{#1}{\null}}
    {}{\ (#1)}}}%
}
\newcommand{\CHS@dcitenam}[2][\null]{\CHS@citetoaux{#2}\CHS@checkdef{#2}{%
{\CHS@name{#2}\ifthenelse{\equal{#1}{\null}}
    {}{\ (#1)}}}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\citeyear}
% \begin{macro}{\CHS@citeyr}
% \begin{macro}{\CHS@citeyrnb}
% Print the year of a specific reference.
%    \begin{macrocode}
\newcommand{\citeyear}{\@ifstar{\CHS@citeyrnb}{\CHS@citeyr}}
\newcommand{\CHS@citeyrnb}[2][\null]{\CHS@citetoaux{#2}%
{\def\@citea{\null}\@for\@citeb:=#2\do%
{\@citea\def\@citea{,\penalty\@m\ }\CHS@checkdef{\@citeb}%
{\CHS@year{\@citeb}}}\ifthenelse{\equal{#1}{\null}}%
{}{, #1}}%
}
\newcommand{\CHS@citeyr}[2][\null]{\CHS@citetoaux{#2}%
{(\def\@citea{\null}\@for\@citeb:=#2\do%
{\@citea\def\@citea{,\penalty\@m\ }\CHS@checkdef{\@citeb}%
{\CHS@year{\@citeb}}}\ifthenelse{\equal{#1}{\null}}%
{}{, #1})}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \changes{v2.9}{2011/09/16}{Removed \cs{CHS@hisep}}
% \changes{v2.9}{2011/09/16}{Removed \cs{CHS@hysep}}
% \changes{v2.9}{2011/09/16}{Removed \cs{chsleft}}
% \changes{v2.9}{2011/09/16}{Removed \cs{chsright}}
% \changes{v2.9}{2011/09/16}{Removed \cs{chsyearleft}}
% \changes{v2.9}{2011/09/16}{Removed \cs{chsyearright}}
% \changes{v2.9}{2011/09/16}{Removed \cs{CHS@checkcitations}}
%
%
% \begin{macro}{\chsWand}
% \begin{macro}{\chsWjanuary}
% \begin{macro}{\chsWfebruary}
% \begin{macro}{\chsWmarch}
% \begin{macro}{\chsWapril}
% \begin{macro}{\chsWmay}
% \begin{macro}{\chsWjune}
% \begin{macro}{\chsWjuly}
% \begin{macro}{\chsWaugust}
% \begin{macro}{\chsWseptember}
% \begin{macro}{\chsWoctober}
% \begin{macro}{\chsWnovember}
% \begin{macro}{\chsWdecember}
% \begin{macro}{\chsWprinting}
% \begin{macro}{\chsWphdthesis}
% \begin{macro}{\chsWmscthesis}
% \begin{macro}{\chsWinstitution}
% \begin{macro}{\chsWin}
% \begin{macro}{\chsPage}
% \begin{macro}{\chsPages}
% \begin{macro}{\chsEdition}
% \begin{macro}{\chsNumero}
% \begin{macro}{\chsVolume}
% \begin{macro}{\chsWst}
% \begin{macro}{\chsWnd}
% \begin{macro}{\chsWrd}
% \begin{macro}{\chsWth}
% \begin{macro}{\chsWeditor}
% \changes{v2.0e}{2011/06/23}{Fixed editor translation}
% \begin{macro}{\chsWelectronic}
% \begin{macro}{\chsWtechreport}
% Various translatable terms
%    \begin{macrocode}
\newcommand{\chsWand}{}%
\newcommand{\chsWjanuary}{}%
\newcommand{\chsWfebruary}{}%
\newcommand{\chsWmarch}{}%
\newcommand{\chsWapril}{}%
\newcommand{\chsWmay}{}%
\newcommand{\chsWjune}{}%
\newcommand{\chsWjuly}{}%
\newcommand{\chsWaugust}{}%
\newcommand{\chsWseptember}{}%
\newcommand{\chsWoctober}{}%
\newcommand{\chsWnovember}{}%
\newcommand{\chsWdecember}{}%
\newcommand{\chsWprinting}{}%
\newcommand{\chsWphdthesis}{}%
\newcommand{\chsWmscthesis}{}%
\newcommand{\chsWinstitution}{}%
\newcommand{\chsWin}{}%
\newcommand{\chsPage}{}%
\newcommand{\chsPages}{}%
\newcommand{\chsEdition}{}%
\newcommand{\chsNumero}{}%
\newcommand{\chsVolume}{}%
\newcommand{\chsWst}{}%
\newcommand{\chsWnd}{}%
\newcommand{\chsWrd}{}%
\newcommand{\chsWth}{}%
\newcommand{\chsWeditor}{}%
\newcommand{\chsWelectronic}{}%
\newcommand{\chsWtechreport}{}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% Set up swedish translations if |swedish| option is given.
% \changes{v2.0b}{2011/06/12}{Fixed a critical bug in |swedish| option}
%    \begin{macrocode}
\DeclareOption{swedish}{%
\renewcommand{\chsWand}{och}%
\renewcommand{\chsWjanuary}{januari}%
\renewcommand{\chsWfebruary}{februari}%
\renewcommand{\chsWmarch}{mars}%
\renewcommand{\chsWapril}{april}%
\renewcommand{\chsWmay}{maj}%
\renewcommand{\chsWjune}{juni}%
\renewcommand{\chsWjuly}{juli}%
\renewcommand{\chsWaugust}{augusti}%
\renewcommand{\chsWseptember}{september}%
\renewcommand{\chsWoctober}{oktober}%
\renewcommand{\chsWnovember}{november}%
\renewcommand{\chsWdecember}{december}%
\renewcommand{\chsWprinting}{Under tryckning}%
\renewcommand{\chsWphdthesis}{Doktorsavhandling}%
\renewcommand{\chsWmscthesis}{Examensarbete}%
\renewcommand{\chsWinstitution}{inom}%
\renewcommand{\chsWin}{I}%
\renewcommand{\chsPage}{s.}%
\renewcommand{\chsPages}{ss.}%
\renewcommand{\chsEdition}{upplagan}%
\renewcommand{\chsNumero}{nr}%
\renewcommand{\chsVolume}{vol.}%
\renewcommand{\chsWst}{:a}%
\renewcommand{\chsWnd}{:a}%
\renewcommand{\chsWrd}{:e}%
\renewcommand{\chsWth}{:e}%
\renewcommand{\chsWeditor}{red.}%
\renewcommand{\chsWelectronic}{Elektronisk}%
\renewcommand{\chsWtechreport}{Teknisk rapport}%
}
%    \end{macrocode}
%
% Set up english translations if |english| option is given.
%    \begin{macrocode}
\DeclareOption{english}{%
\renewcommand{\chsWand}{and}%
\renewcommand{\chsWjanuary}{January}%
\renewcommand{\chsWfebruary}{February}%
\renewcommand{\chsWmarch}{March}%
\renewcommand{\chsWapril}{April}%
\renewcommand{\chsWmay}{May}%
\renewcommand{\chsWjune}{June}%
\renewcommand{\chsWjuly}{July}%
\renewcommand{\chsWaugust}{August}%
\renewcommand{\chsWseptember}{September}%
\renewcommand{\chsWoctober}{October}%
\renewcommand{\chsWnovember}{November}%
\renewcommand{\chsWdecember}{December}%
\renewcommand{\chsWprinting}{Unpublished}%
\renewcommand{\chsWphdthesis}{Ph.D.~thesis}%
\renewcommand{\chsWmscthesis}{Master's~thesis}%
\renewcommand{\chsWinstitution}{at}%
\renewcommand{\chsWin}{In}%
\renewcommand{\chsPage}{p.}%
\renewcommand{\chsPages}{pp.}%
\renewcommand{\chsEdition}{edition}%
\renewcommand{\chsNumero}{no.}%
\renewcommand{\chsVolume}{vol.}%
\renewcommand{\chsWst}{st}%
\renewcommand{\chsWnd}{nd}%
\renewcommand{\chsWrd}{rd}%
\renewcommand{\chsWth}{th}%
\renewcommand{\chsWeditor}{ed.}%
\renewcommand{\chsWelectronic}{Electronic}%
\renewcommand{\chsWtechreport}{Technical report}%
}
%    \end{macrocode}
%
% Execute default options, process given options and choose the correct 
% bibliography style.
%    \begin{macrocode}
\ExecuteOptions{english}
\ProcessOptions*
\bibliographystyle{chscite}
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
%
% \subsection{\textsc{Bib}\TeX{} style file \texttt{chscite.bst}}
% \changes{v1.0b}{2011/06/06}{Fixed bug concerning editors in \texttt{.bst} file}
% \changes{v2.0c}{2011/06/22}{Cleaned up \texttt{.bst} file}
% \changes{v2.0d}{2011/06/23}{Improved handling of editions}
% \changes{v2.999}{2012/05/13}{Added \texttt{@patent} and \texttt{@misc} entries}
% \changes{v2.9999}{2012/12/05}{Added \texttt{@techreport} style}
%
% \iffalse
%<*bibstyle>
% \fi
%
%    \begin{macrocode}
ENTRY
  {
    address
    author
    booktitle
    chapter
    edition
    editor
    howpublished
    institution
    journal
    key
    month
    note
    number
    organization
    pages
    publisher
    school
    series
    title
    type
    URL
    volume
    year
  }
  { field.used }
  { extra.label sort.label list.year }

INTEGERS { output.state before.all mid.sentence after.sentence after.block }

FUNCTION {init.state.consts}
{
  #0 'before.all :=
  #1 'mid.sentence :=
  #2 'after.sentence :=
  #3 'after.block :=
}

STRINGS { s t f }

FUNCTION {item.check}
{
  't :=
  empty$
  { "empty " t * " in " * cite$ * warning$ }
  { skip$ }
  if$
}

FUNCTION {new.block}
{
  output.state before.all =
  'skip$
  { after.block 'output.state := }
  if$
}

FUNCTION {lastint}
{
  #-1 #1 substring$ chr.to.int$ "0" chr.to.int$ -
}

FUNCTION {format.number.th}
{
  duplicate$ duplicate$
  #1 =
  { pop$ pop$ "\chsWst{}" }
  {
    #2 =
    { pop$ "\chsWnd{}" }
    {
      #3 =
      { "\chsWrd{}" }
      { "\chsWth{}" }
      if$
    }
    if$
  }
  if$
}

FUNCTION {not}
{
  { #0 }
  { #1 }
  if$
}

FUNCTION {and}
{
  'skip$
  { pop$ #0 }
  if$
}

FUNCTION {or}
{
  { pop$ #1 }
  'skip$
  if$
}

FUNCTION {field.or.null}
{
  duplicate$ empty$
  { pop$ "" }
  'skip$
  if$
}

FUNCTION {emphasize}
{
  duplicate$ empty$
  { pop$ "" }
  { "\emph{" swap$ * "}" * }
  if$
}

FUNCTION {write.url}
{
  URL empty$
  'skip$
  { " \chsurl{" URL * "}" add.period$ * write$ newline$ }
  if$
}

FUNCTION {fin.entry}
{
  add.period$
  write$
  type$ "misc" =
    'skip$
    'write.url
  if$
  newline$
}

INTEGERS { nameptr namesleft numnames }

FUNCTION {format.names}
{
  's :=
  'f :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
  #3 numnames >
  {
    { namesleft #0 > }
    {
      s nameptr f format.name$ 't :=
      nameptr #1 >
	    {
	      namesleft #1 >
	      { ", " * t * }
	      {
	        t "others" =
		      { " et~al." * }
		      { " \chsWand{}\ " * t * }
	        if$
	      }
	      if$
	    }
	    't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
    while$
  }
  { s nameptr f format.name$ " et~al." * }
  if$
}

FUNCTION {format.authors}
{
  author empty$
  { "" }
  { "{vv~}{ll}{, jj}{, f.}" author format.names }
  if$
}

FUNCTION {n.dashify}
{
  't :=
  ""
  { t empty$ not }
  {
    t #1 #1 substring$ "-" =
	  {
	    t #1 #2 substring$ "--" = not
	    {
	      "--" *
	      t #2 global.max$ substring$ 't :=
	    }
	    {
	      { t #1 #1 substring$ "-" = }
		    {
		      "-" *
		      t #2 global.max$ substring$ 't :=
		    }
	      while$
	    }
	    if$
	  }
	  {
	    t #1 #1 substring$ *
	    t #2 global.max$ substring$ 't :=
	  }
    if$
  }
  while$
}

FUNCTION {format.btitle}
{
  title "." * emphasize
}

FUNCTION {tie.or.space.connect}
{
  duplicate$ text.length$ #3 <
  { "~" }
  { " " }
  if$
  swap$ * *
}

FUNCTION {either.or.check}
{
  empty$
  'pop$
  { "can't use both " swap$ * " fields in " * cite$ * warning$ }
  if$
}

FUNCTION {format.editors}
{
  editor empty$
  { "" }
  { "\chsWeditor{}" "{vv~}{ll}{, jj}{, f.}" editor format.names tie.or.space.connect }
  if$
}

FUNCTION {format.book.editors}
{
  editor empty$
  { "" }
  { "\chsWeditor{}" "{vv~}{ll}{, jj}{, f.}" editor format.names tie.or.space.connect }
  if$
}

FUNCTION {format.edition}
{
  edition edition lastint format.number.th *
}

INTEGERS { multiresult }

FUNCTION {multi.page.check}
{
  't :=
  #0 'multiresult :=
  {
    multiresult not
    t empty$ not
    and
  }
  {
    t #1 #1 substring$
    duplicate$ "-" =
    swap$ duplicate$ "," =
    swap$ "+" =
    or or
	  { #1 'multiresult := }
	  { t #2 global.max$ substring$ 't := }
    if$
  }
  while$
  multiresult
}

FUNCTION {format.pages}
{
  pages empty$
  { "" }
  {
    ","
    pages multi.page.check
	  { "\chsPages{}" pages n.dashify tie.or.space.connect }
	  { "\chsPage{}" pages tie.or.space.connect }
    if$
    tie.or.space.connect
  }
  if$
}

INTEGERS { len }

FUNCTION {chop.word}
{
  's :=
  'len :=
  s #1 len substring$ =
  { s len #1 + global.max$ substring$ }
  's
  if$
}

INTEGERS { ind tsslen }

STRINGS { tss ret rss istr }

FUNCTION {replace.substring}
{
  'rss :=
  'tss :=
  'istr :=
  "" 'ret :=
  tss text.length$ 'tsslen :=
  #1 'ind :=
  { istr ind tsslen substring$ "" = not }
  {
    istr ind tsslen substring$ tss =
    {
      ret rss * 'ret :=
      ind tsslen + 'ind :=
    }
    {
      ret istr ind #1 substring$ * 'ret :=
      ind #1 + 'ind :=
    }
    if$
  }
  while$
  ret
}

FUNCTION {format.lab.names.abbr}
{
  's :=
  s num.names$ 'numnames :=
  numnames #1 >
  {
    numnames #3 >
	  { s #1 "{vv~}{ll}" format.name$ " et~al." * }
	  {
	    s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
      { s #1 "{vv~}{ll}" format.name$ " et~al." * }
	    {
	      s #1 "{vv~}{ll}" format.name$ " \chsWand{}\ " *
        s #2 "{vv~}{ll}" format.name$ * 
      }
      if$
    }
    if$
  }
  { s #1 "{vv~}{ll}" format.name$ }
  if$
}

FUNCTION {format.lab.names.full}
{
  's :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
  { namesleft #0 > }
  {
    s nameptr "{vv~}{ll}" format.name$ 't :=
    nameptr #1 >
	  {
	    namesleft #1 >
	    { ", " * t * }
	    {
	      t "others" =
		    { " et~al." * }
		    { " \chsWand{}\ " * t * }
	      if$
	    }
	    if$
	  }
	  't
    if$
    nameptr #1 + 'nameptr :=
    namesleft #1 - 'namesleft :=
  }
  while$
}

INTEGERS { author.field editor.field organization.field title.field key.field }

FUNCTION {init.field.constants}
{
  #0 'author.field :=
  #1 'editor.field :=
  #2 'organization.field :=
  #3 'title.field :=
  #4 'key.field :=
}

FUNCTION {make.list.label}
{
  author.field field.used =
  { format.authors }
  {
    editor.field field.used =
    { format.editors }
    {
      organization.field field.used =
      { "The " #4 organization chop.word #3 text.prefix$ }
      {
        title.field field.used =
        { format.btitle }
        {
          key.field field.used =
          { key #3 text.prefix$ }
          { "Internal error :001 on " cite$ * " label" * warning$ }
          if$
        }
        if$
      }
      if$
    }
    if$
  }
  if$
}

FUNCTION {make.full.label}
{
  author.field field.used =
  { author format.lab.names.full }
  {
    editor.field field.used =
    { editor format.lab.names.full }
    {
      organization.field field.used =
      { "The " #4 organization chop.word #3 text.prefix$ }
      {
        title.field field.used =
        { format.btitle }
        {
          key.field field.used =
          { key #3 text.prefix$ }
          { "Internal error :001 on " cite$ * " label" * warning$ }
          if$
        }
        if$
      }
      if$
    }
    if$
  }
  if$
}

FUNCTION {make.abbr.label}
{     
	author.field field.used =
	{ author format.lab.names.abbr }
	{
	  editor.field field.used =
	  { editor format.lab.names.abbr }
	  {
	    organization.field field.used =
	    { "The " #4 organization chop.word #3 text.prefix$ }
	    {
	      title.field field.used =
	      { format.btitle }
	      {
	        key.field field.used =
	        { key #3 text.prefix$ }
	        { "Internal error :001 on " cite$ * " label" * warning$ }
	        if$
	      }
	      if$
	    }
	    if$
	  }
	  if$
	}
	if$
}

FUNCTION {output.bibitem}
{
  newline$
  "\chsitem{" write$
  make.abbr.label write$
  "}{" write$
  list.year write$
  "}{" write$
  cite$ write$
  "}" write$
  newline$
  ""
  before.all 'output.state :=
}

FUNCTION {journal.or.series}
{
  journal missing$
	{ series }
	{ journal }
	if$
}

FUNCTION {publisher.or.school}
{
  publisher missing$
	{ school }
	{ publisher }
	if$
}

%% STYLES
FUNCTION {article}
{ output.bibitem
  make.list.label "(" tie.or.space.connect list.year * ")" *
  author "author" item.check
  title missing$
    'skip$
    { title tie.or.space.connect }
  if$
	type$ "inproceedings" =
	type$ "conference" =
	or not
	month missing$
	or
		'skip$
		{ ";" month year tie.or.space.connect tie.or.space.connect }
	if$
	journal missing$
		'skip$
		{ add.period$ journal.or.series emphasize tie.or.space.connect 
		  volume missing$
			{ cite$ " has journal/series with no volume!" * warning$ }
			{ "," "\chsVolume{}" tie.or.space.connect volume tie.or.space.connect * }
			if$
		  number missing$
			'skip$
			{ "," "\chsNumero{}" number tie.or.space.connect tie.or.space.connect * }
			if$
		}
		if$
		pages missing$
			'skip$
			{ format.pages * }
		if$
		add.period$ *
  
  fin.entry
}

FUNCTION {book}
{ output.bibitem
  make.list.label "(" tie.or.space.connect list.year * ")" *
  author "author" item.check
	chapter missing$
		'skip$
		{ chapter add.period$ "\chsWin{}" tie.or.space.connect tie.or.space.connect }
	if$
  title missing$
    'skip$
    { title emphasize tie.or.space.connect }
  if$
	editor missing$
		'skip$
		{ "," format.book.editors tie.or.space.connect }
	if$
	pages missing$
	journal missing$
	not or
		'skip$
		{ format.pages * }
	if$
	add.period$
  edition missing$
		'skip$
		{ edition empty$
			'skip$
			{ format.edition "\chsEdition{}" add.period$ tie.or.space.connect tie.or.space.connect }
			if$
		}
	if$
	URL missing$
	  'skip$
	  { "[\chsWelectronic]" tie.or.space.connect }
	if$
 	publisher missing$
	school missing$
	and
		'skip$
		{ address missing$
			{ cite$ " has publisher with no address!" * warning$ }
			{ address ":" * publisher.or.school tie.or.space.connect add.period$ tie.or.space.connect }
			if$
		}
	if$
		series missing$
		journal missing$ 
		and
			'skip$
			{ volume missing$
				{ cite$ " has journal/series with no volume!" * warning$ }
				{ "(" journal.or.series ":" * * volume tie.or.space.connect
					series missing$
					'skip$
					{ format.pages * }
					if$
					")" add.period$ * tie.or.space.connect * }
				if$
			}
		if$
  
	type$ "mastersthesis" =
	type$ "phdthesis" =
	or
	'skip$
  { write$ fin.entry }
	if$
}

FUNCTION {booklet} { book }

FUNCTION {inbook} { book }

FUNCTION {incollection} { book }

FUNCTION {inproceedings}
{ output.bibitem
  make.list.label "(" tie.or.space.connect list.year * ")" *
  author "author" item.check
	booktitle missing$
		{ title emphasize tie.or.space.connect }
		{ title add.period$ "\chsWin{}" tie.or.space.connect booktitle emphasize tie.or.space.connect tie.or.space.connect }
	if$	
	month missing$
		'skip$
		{ booktitle missing$
				{ add.period$ }
				{ ";" * }
			if$
			month "~" year * * tie.or.space.connect
		}
	if$
	address missing$
		'skip$
		{ "," address tie.or.space.connect add.period$ * }
	if$
	pages missing$
		'skip$
		{ format.pages add.period$ tie.or.space.connect }
	if$ 
	write$
  
  fin.entry
}

FUNCTION {conference} { inproceedings }

FUNCTION {manual}
{ cite$ ": @manual cite style not implemented!" * warning$ }

FUNCTION {mastersthesis}
{ book
	"(\chsWmscthesis{}" tie.or.space.connect
	note missing$
		'skip$
		{ "\chsWinstitution{}" note tie.or.space.connect tie.or.space.connect }
	if$
	")" add.period$ * write$
	fin.entry
}

FUNCTION {phdthesis}
{ book
	"(\chsWphdthesis{}" tie.or.space.connect
	note missing$
		'skip$
		{ "\chsWinstitution{}" note tie.or.space.connect tie.or.space.connect }
	if$
	")" add.period$ * write$
	fin.entry
}

FUNCTION {proceedings} { inproceedings }

FUNCTION {unpublished}
{ output.bibitem
  make.list.label "(" tie.or.space.connect list.year * ")" *
  author "author" item.check
	chapter missing$
		'skip$
		{ chapter add.period$ "\chsWin{}" tie.or.space.connect tie.or.space.connect tie.or.space.connect }
	if$
  title missing$
    'skip$
    { title emphasize tie.or.space.connect }
  if$
	editor missing$
		'skip$
		{ "," format.book.editors tie.or.space.connect * }
	if$
	pages missing$
	journal missing$
	not or
		'skip$
		{ format.pages * }
	if$
	add.period$ 
	URL missing$
	  { "\chsWprinting{}" tie.or.space.connect add.period$ }
	  { "[\chsWelectronic]" tie.or.space.connect }
	if$
 	publisher missing$
		'skip$
		{ address missing$
			{ cite$ " has publisher with no address!" * warning$ }
			{ address ":" * publisher.or.school tie.or.space.connect add.period$ tie.or.space.connect }
			if$
		}
	if$
	write$
  
  fin.entry
}

FUNCTION {misc}
{ output.bibitem
  make.list.label "(" tie.or.space.connect list.year * ")" *
  author "author" item.check
  title missing$
    'skip$
    { title tie.or.space.connect add.period$ }
  if$
  howpublished missing$
    'skip$
    { howpublished emphasize tie.or.space.connect add.period$ }
  if$
  URL missing$
    'skip$
    { " \chsurl{" URL "}" * * tie.or.space.connect add.period$ }
  if$
  note missing$
    'skip$
    { "(" note ")" * * tie.or.space.connect add.period$ }
  if$
  write$
  fin.entry
}

FUNCTION {techreport}
{ output.bibitem
  make.list.label "(" tie.or.space.connect list.year * ")" *
  author "author" item.check
  title missing$
    { cite$ " has no title!" * warning$ }
    { title emphasize tie.or.space.connect add.period$ }
  if$
  URL missing$
    'skip$
    { "[\chsWelectronic]" tie.or.space.connect }
  if$
  institution missing$
    { cite$ " has no institution!" * warning$ }
    { address missing$
        { cite$ " has institution with no address!" * warning$ }
        { address ":" * tie.or.space.connect }
      if$
      institution tie.or.space.connect add.period$
      number missing$
        { cite$ " has institution with no number!" * warning$ }
        { "(\chsWtechreport{}:" number tie.or.space.connect ")" * tie.or.space.connect }
      if$
    }
    if$
  add.period$
  write$
  fin.entry
}

FUNCTION {patent}
{ output.bibitem
  make.list.label "(" tie.or.space.connect list.year * ")" *
  author "author" item.check
    title missing$
      'skip$
      { title emphasize tie.or.space.connect add.period$ }
    if$
    number missing$
      'skip$
      { number tie.or.space.connect add.period$ }
    if$
  write$
  fin.entry
}

FUNCTION {default.type} { misc }

MACRO {jan} {"\chsWjanuary{}"}
MACRO {feb} {"\chsWfebruary{}"}
MACRO {mar} {"\chsWmarch{}"}
MACRO {apr} {"\chsWapril{}"}
MACRO {may} {"\chsWmay{}"}
MACRO {jun} {"\chsWjune{}"}
MACRO {jul} {"\chsWjuly{}"}
MACRO {aug} {"\chsWaugust{}"}
MACRO {sep} {"\chsWseptember{}"}
MACRO {oct} {"\chsWoctober{}"}
MACRO {nov} {"\chsWnovember{}"}
MACRO {dec} {"\chsWdecember{}"}

MACRO {acmcs} {"ACM Computing Surveys"}
MACRO {acta} {"Acta Informatica"}
MACRO {cacm} {"Communications of the ACM"}
MACRO {ibmjrd} {"IBM Journal of Research and Development"}
MACRO {ibmsj} {"IBM Systems Journal"}
MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
MACRO {ieeetc} {"IEEE Transactions on Computers"}
MACRO {ieeetcad} {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
MACRO {ipl} {"Information Processing Letters"}
MACRO {jacm} {"Journal of the ACM"}
MACRO {jcss} {"Journal of Computer and System Sciences"}
MACRO {scp} {"Science of Computer Programming"}
MACRO {sicomp} {"SIAM Journal on Computing"}
MACRO {tocs} {"ACM Transactions on Computer Systems"}
MACRO {tods} {"ACM Transactions on Database Systems"}
MACRO {tog} {"ACM Transactions on Graphics"}
MACRO {toms} {"ACM Transactions on Mathematical Software"}
MACRO {toois} {"ACM Transactions on Office Information Systems"}
MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
MACRO {tcs} {"Theoretical Computer Science"}

READ

EXECUTE {init.field.constants}

FUNCTION {sortify}
{
  purify$
  "l" change.case$
}

FUNCTION {sortify.names}
{
  " \chsWand{}\ " " " replace.substring
  " et~al." " zzz" replace.substring
  sortify
}

FUNCTION {author.key.label}
{
  author empty$
  {
    key empty$
	  { title.field 'field.used := }
	  { key.field 'field.used := }
    if$
  }
  { author.field 'field.used := }
  if$
}

FUNCTION {author.editor.key.label}
{
  author empty$
  {
    editor empty$
	  {
	    key empty$
	    { title.field 'field.used := }
	    { key.field 'field.used := }
	    if$
  	}
	  { editor.field 'field.used := }
    if$
  }
  { author.field 'field.used := }
  if$
}

FUNCTION {author.key.organization.label}
{
  author empty$
  {
    key empty$
	  {
	    organization empty$
	    { title.field 'field.used := }
	    { organization.field 'field.used := }
	    if$
	  }
	  { key.field 'field.used := }
    if$
  }
  { author.field 'field.used := }
  if$
}

FUNCTION {editor.key.organization.label}
{
  editor empty$
  {
    key empty$
	  {
	    organization empty$
	    { title.field 'field.used := }
	    { organization.field 'field.used := }
	    if$
	  }
	  { key.field 'field.used := }
    if$
  }
  { editor.field 'field.used := }
  if$
}

FUNCTION {sort.format.title}
{
  't :=
  "A " #2
    "An " #3
      "The " #4 t chop.word
    chop.word
  chop.word
  sortify
  #1 global.max$ substring$
}

FUNCTION {calc.label}
{
  make.abbr.label
  title.field field.used =
  { sort.format.title }
  { sortify.names }
  if$
  year field.or.null purify$ #-1 #4 substring$ sortify *
  'sort.label :=
}

FUNCTION {preliminaries}
{
  type$ "book" =
  type$ "inbook" =
  or
  'author.editor.key.label
  {
    type$ "proceedings" =
	  'editor.key.organization.label
	  {
	    type$ "manual" =
	    'author.key.organization.label
	    'author.key.label
	    if$
	  }
    if$
  }
  if$
}

FUNCTION {first.presort}
{
  calc.label
  sort.label
  title.field field.used =
  { skip$ }
  { "    " * make.list.label sortify.names * "    " * title field.or.null sort.format.title * }
  if$
  #1 entry.max$ substring$
  'sort.key$ :=
}

ITERATE {preliminaries}

ITERATE {first.presort}

SORT

STRINGS { last.sort.label next.extra last.full.label }

INTEGERS { last.extra.num }

FUNCTION {initialize.confusion}
{
  #0 int.to.chr$ 'last.sort.label :=
  #0 int.to.chr$ 'last.full.label :=
}

FUNCTION {confusion.pass}
{
  last.sort.label sort.label =
  'skip$
  {
    sort.label 'last.sort.label :=
    make.full.label sortify.names 'last.full.label :=
  }
  if$
}

EXECUTE {initialize.confusion}

ITERATE {confusion.pass}

EXECUTE {initialize.confusion}

REVERSE {confusion.pass}

FUNCTION {initialize.last.extra.num}
{
  #0 int.to.chr$ 'last.sort.label :=
  "" 'next.extra :=
  #0 'last.extra.num :=
}

FUNCTION {forward.pass}
{
  last.sort.label sort.label =
  {
    last.extra.num #1 + 'last.extra.num :=
    last.extra.num int.to.chr$ 'extra.label :=
  }
  {
    "a" chr.to.int$ 'last.extra.num :=
    "" 'extra.label :=
    sort.label 'last.sort.label :=
  }
  if$
}

FUNCTION {reverse.pass}
{
  next.extra "b" =
  { "a" 'extra.label := }
  'skip$
  if$
  year empty$
  { "n.d." extra.label * 'list.year := }
  { year extra.label * 'list.year := }
  if$
  extra.label 'next.extra :=
}

ITERATE {first.presort}

SORT

EXECUTE {initialize.last.extra.num}

ITERATE {forward.pass}

REVERSE {reverse.pass}

FUNCTION {second.presort}
{
  make.list.label
  title.field field.used =
  { sort.format.title }
  { sortify.names }
  if$
  "    " * list.year field.or.null sortify * "    " *
  title.field field.used =
  'skip$
  { title field.or.null sort.format.title * }
  if$
  #1 entry.max$ substring$
  'sort.key$ :=
}

ITERATE {second.presort}

SORT

FUNCTION {begin.bib}
{
  preamble$ empty$
  'skip$
  {
    "\chspreambledefs{%" write$ newline$
    preamble$ write$ "}" write$ newline$
    "\chspreambletext{%" write$ newline$
    preamble$ write$ "}" write$ newline$
  }
  if$
  "\begin{thebibliography}{xx}" write$ newline$
}

EXECUTE {begin.bib}

EXECUTE {init.state.consts}

ITERATE {call.type$}

FUNCTION {end.bib}
{
  newline$
  "\end{thebibliography}" write$ newline$
}

EXECUTE {end.bib}
%    \end{macrocode}
%
% \iffalse
%</bibstyle>
% \fi
%
% \Finale
\endinput
