\ProvidesFile{blx-bibtex.def}
[\abx@cptid]

\blx@warning@noline{%
  Using fall-back bibtex backend:\MessageBreak
  functionality may be reduced/unavailable%
}

% Initialisation of backend-related switches, variables, etc.
\newtoggle{blx@runbtx}

% No interface provided for this but can be set 'in emergency' by user
\def\blx@maxline{79}

% Rename write stream so use is clear
\let\blx@write\blx@bcfout

% Data file initialisation
\edef\blx@auxfile{\jobname}
\let\blx@aux\@mainaux
\newcommand*{\blxauxsuffix}{-blx}

\begingroup
\def\blx@tempa#1"#2{%
  #1\ifx#2\@empty\else
    \expandafter\blx@tempa
  \fi#2}
\edef\blx@ctrlfile{%
  \noexpand\blx@tempa
  \expandafter\blx@tempa\jobname"\@empty
  \space\noexpand\@empty}
\def\blx@tempa#1 #2{%
  #1\ifx#2\@empty\else
    \string_\expandafter\blx@tempa
  \fi#2}
\xdef\blx@ctrlfile{\blx@ctrlfile}
\endgroup

\def\blx@auxinit#1{%
  \blx@auxwrite\blx@aux
    {\def\do##1{,\blx@stripbib{##1}}}
    {\ifx\blx@aux\@mainaux
     \else
       \blx@msg@aux
     \fi
     \string\bibstyle{biblatex}\blx@nl
     \string\bibdata{%
       \blx@ctrlfile\blxauxsuffix
       \ifx#1\@empty
       \else
         \dolistloop#1%
       \fi}\blx@nl
     \string\citation{biblatex-control}}}

\def\blx@sig@bib{@Comment{$ biblatex control file $}}
\edef\blx@ver@bib{%
  @Comment{$ biblatex bcf format version \blx@bcfversion\space $}}

\let\blx@sig@aux\blx@sig@bbl
\let\blx@ver@aux\blx@ver@bbl

\edef\blx@msg@text{%
  \@percentchar\space Do not modify this file!\blx@nl
  \@percentchar\blx@nl
  \@percentchar\space This is an auxiliary file
  used by the 'biblatex' package.\blx@nl
  \@percentchar\space This file may safely be deleted.
  It will be recreated as\blx@nl
  \@percentchar\space required.\blx@nl}

\edef\blx@msg@aux{%
  \blx@sig@aux\blx@nl
  \blx@ver@aux\blx@nl
  \blx@msg@text
  \@percentchar\blx@nl\string\relax\blx@nl}
\edef\blx@msg@bib{%
  \blx@sig@bib\blx@nl
  \blx@ver@bib\blx@nl
  \blx@msg@text\blx@nl}

% User feedback

\renewrobustcmd*{\RequireBiber}[1][2]{%
  \ifnumgreater{#1}\blx@reqbiber
    {\numgdef\blx@reqbiber{#1}}
    {}%
    \blx@checkbackend{style}}
\@onlypreamble\RequireBiber
\let\blx@reqbiber\z@

\def\blx@checkbackend#1{%
  \ifnum\blx@reqbiber>2 %
     \blx@error
       {Biber backend is required by #1}
       {The selected style or one of the .bib files
        requires Biber.\MessageBreak It will
        not work at all with BibTeX.}%
   \fi}

\def\blx@check@logreq{%
  \begingroup
  \ltxrequest{biblatex}{{\iftoggle{blx@runltx}{1}{0}}}{%
    \provides[type=dynamic]{
      \def\do##1{\file{##1.aux}}
      \dolistloop\blx@list@inactive
      \file{\blx@ctrlfile\blxauxsuffix.bib}
    }
    \requires[type=dynamic]{
      \def\do##1{\file{##1.bbl}}
      \dolistloop\blx@list@inactive
    }
    \ifdef\blx@list@req@edit
      {\requires[type=editable]{
         \forlistloop\file\blx@list@req@edit
       }}
      {}
    \ifdef\blx@list@req@stat
      {\requires[type=static]{
         \forlistloop\file\blx@list@req@stat
       }}
      {}
  }%
  \def\do##1{%
    \ifinlist{##1}{\blx@list@active}
      {\blx@logreq@bibtex{1}{##1}}
      {\blx@logreq@bibtex{0}{##1}}}%
  \dolistloop\blx@list@inactive
  \endgroup}

\def\blx@logreq@bibtex#1#2{%
  \logrequest[package=biblatex,priority=5,active=#1]{%
    \generic{bibtex}
    \cmdline{%
      \iftoggle{blx@bibtex8}
        {\binary{bibtex8}
         \option{--wolfgang}
         \option{--min\string_crossrefs \blx@mincrossrefs}}
        {\binary{bibtex}
         \option{-min-crossrefs \blx@mincrossrefs}}%
      \infile{#2}
     }
     \input{
       \file{#2.aux}
     }
     \output{
       \file{#2.bbl}
     }
      \provides[type=dynamic]{
        \file{#2.bbl}
      }
      \requires[type=dynamic]{
        \file{#2.aux}
        \file{\blx@ctrlfile\blxauxsuffix.bib}
      }
      \requires[type=editable]{
        \ifcsdef{blx@list@bibfiles@#2}
          {\def\do{\file}
           \dolistcsloop{blx@list@bibfiles@#2}}
          {}
      }
      \requires[type=static]{
        \file{biblatex.bst}}
  }%
}

\def\blx@logreq@active#1{%
  \xifinlist{\blx@auxfile}{\blx@list@active}
    {}
    {\listxadd\blx@list@active{\blx@auxfile}}%
  \ifblank{#1}
    {}
    {\@latex@warning{#1}}%
  \blx@rerun@latex
  \blx@rerun@bibtex}

\def\blx@logreq@inactive{%
  \xifinlist{\blx@auxfile}{\blx@list@inactive}
    {}
    {\listxadd\blx@list@inactive{\blx@auxfile}}}

\def\blx@rerun@bibtex{%
  \global\toggletrue{blx@runbtx}%
  \global\let\blx@rerun@bibtex\relax}

% Only the toggle name changes here
\patchcmd{\blx@check@rerun}{blx@runbiber}{blx@runbtx}{}{}

\def\blx@warn@auxlist{%
  \begingroup
  \edef\blx@tempa{Please (re)run BibTeX on the file(s):}%
  \def\do##1{\appto\blx@tempa{\MessageBreak##1}}%
  \dolistloop\blx@list@active
  \blx@warning@noline{%
    \blx@tempa\MessageBreak
    and rerun LaTeX afterwards}%
  \endgroup}

\protected\def\blx@bibreq#1{%
  \blx@auxwrite\blx@aux{}{\string\citation{#1}}}

% bibtex doesn't parse ISO8601 dates so these overrides do nothing
\appto\blx@blxinit{%
  \def\iflabeldateera#1{\@secondoftwo}%
  \def\iflabelenddateera#1{\@secondoftwo}%
  \let\iflabeldatecirca\@secondoftwo
  \let\iflabelenddatecirca\@secondoftwo
  \let\iflabeldateuncertain\@secondoftwo
  \let\iflabelenddateuncertain\@secondoftwo}


% Alter message text
\patchcmd{\blx@bbl@warn}{Biber}{BibTeX}{}{}

%% Data input

\patchcmd{\blx@bblinput}{\blx@bblfile}{\blx@bblfile\blx@bblsecs}{}{}


\def\blx@bblfile{%
  \blx@secinit
  \begingroup
  \blx@bblstart
  \ifnum\c@refsection>\z@
    \edef\blx@auxfile{\jobname\the\c@refsection\blxauxsuffix}%
  \else
    \edef\blx@auxfile{\jobname}%
  \fi
  \blx@ifsigned{\blx@auxfile}{bbl}
    {\InputIfFileExists{\blx@auxfile.bbl}
       {\blx@info@noline{... file '\blx@auxfile.bbl' found}%
        \global\toggletrue{blx@bbldone}%
        \blx@generate@bbl@mdfivesum@found{\blx@auxfile.bbl}}
       {\blx@info@noline{... file '\blx@auxfile.bbl' not found}%
        \typeout{No file \blx@auxfile.bbl.}%
        \global\togglefalse{blx@bbldone}%
        \blx@generate@bbl@mdfivesum@notfound}}
    {}%
  \blx@bblend
  \endgroup
  % Check if Biber rerun was not carried out.
  % If so, ask for it again.
  \blx@check@bbl@rerun@mdfivesum
  \csnumgdef{blx@labelnumber@\the\c@refsection}{0}}

\def\blx@bblsecs{%
  \advance\c@refsection\@ne
  \ifnum\c@refsection>\c@blx@maxsection
  \else
    \blx@bblfile
    \expandafter\blx@bblsecs
  \fi}

\def\blx@refsection@ii{%
  \xdef\blx@auxfile{\jobname\the\c@refsection\blxauxsuffix}%
  \blx@regbibfiles\blx@auxfile\blx@bibfiles
  \blx@logreq@inactive
  \blx@ifsigned{\blx@auxfile}{aux}
    {\immediate\openout\blx@write\blx@auxfile.aux\relax
     \global\let\blx@aux\blx@write
     \blx@auxinit\blx@bibfiles}
    {}}

\def\blx@endrefsection{%
  \blx@endrefsegment
  \ifx\blx@aux\blx@write
    \immediate\closeout\blx@write
    \global\let\blx@aux\@mainaux
    \xdef\blx@auxfile{\jobname}%
  \fi
  \global\c@refsection\z@}

% xref support

% {<entrykey>}
\protected\def\blx@bbl@xref#1{%
  \ifcsdef{blx@refp@\the\c@refsection @\detokenize{#1}}
    {}
    {\listcsxadd{blx@refs@\the\c@refsection}{\detokenize{#1}}}%
  \listcsxadd{blx@refp@\the\c@refsection @\detokenize{#1}}{\abx@field@entrykey}%
  \csxdef{blx@refc@\the\c@refsection @\abx@field@entrykey}{\detokenize{#1}}}

\def\blx@addxref#1{%
  \blx@ifdata{#1}
    {\begingroup
     \def\do##1{%
       \csgappto{blx@data@\the\c@refsection @##1}{%
         \def\abx@field@xref{#1}}}%
     \dolistcsloop{blx@refp@\the\c@refsection @#1}%
     \endgroup}
    {}%
  \global\csundef{blx@refp@\the\c@refsection @#1}}

\def\blx@citation@xref#1{%
  \begingroup
  \edef\blx@tempa{blx@refp@\the\c@refsection @%
          \csname blx@refc@\the\c@refsection @#1\endcsname}%
  \ifcsdef\blx@tempa
    {\ifinlistcs{#1}\blx@tempa
       {}
       {\listcsxadd\blx@tempa{#1}}%
     \blx@tempcnta\z@
     \def\do##1{\advance\blx@tempcnta\@ne}%
     \dolistcsloop\blx@tempa}
    {\listcsxadd\blx@tempa{#1}%
     \blx@tempcnta\@ne}%
  \expandafter\endgroup\ifnum\blx@tempcnta<\blx@minxrefs\relax
  \else
    \expandafter\expandafter\expandafter\blx@citation@entry
    \expandafter\expandafter\expandafter{%
      \csname blx@refc@\the\c@refsection @#1\endcsname}\blx@msg@cundef
  \fi}

\def\blx@bblend{%
  \ifcsdef{blx@refs@\the\c@refsection}%
    {\begingroup
     \let\do\blx@addxref
     \dolistcsloop{blx@refs@\the\c@refsection}%
     \endgroup
     \global\csundef{blx@refs@\the\c@refsection}}
    {}%
  \iftoggle{blx@addset}
    {\blx@addset
     \global\togglefalse{blx@addset}}
    {}}


% set support

% We'll generate 'fake sets' for sorting.
% A fake set will be the copy of a normal set but with a crossref
% to the first set member, that way it inherits sorting info.

\def\blx@grabfirstcsvitem#1,#2\blx@grabfirstcsvitem@end{#1}

\def\blx@btx@fakesetentry#1#2#3#4{%
  \blx@nl
  @set{#1,\blx@nl
  \space\space fakeset  = {#2},\blx@nl
  \space\space entryset = {#3},\blx@nl
  \space\space crossref = {#4},\blx@nl
  }%
}

\def\blx@fakeset@prefix{blx@fakeset-}

\protected\def\blx@writefakeset@oo#1#2{%
  \begingroup
  \edef\blx@tempa{\endgroup
    \noexpand\blx@writefakeset
      {\expandonce{#1}}
      {\expandonce{#2}}}%
  \blx@tempa
}

\protected\def\blx@writefakeset#1#2{%
  \blx@auxwrite\blx@bcfout{}{%
    \blx@btx@fakesetentry
      {\blx@fakeset@prefix#1}
      {#1}
      {#2}
      {\blx@grabfirstcsvitem#2,\blx@grabfirstcsvitem@end}}}

\protected\def\blx@bbl@fakeset#1{%
  \csxdef{blx@isfakeset@\the\c@refsection @\abx@field@entrykey}{%
    \detokenize{#1}}%
  \global\cslet{blx@getfakeset@\the\c@refsection @#1}\abx@field@entrykey
}

% we can't rely on \inset in the .bbl (which should be in the child
% entry), so we produce setc manually from the @set parent
% but the bibliography may not be in a nice order to grab setc
% properly, so we need to save setc data in the .aux file
\appto\blx@secinit{%
  \cslet{blx@setclist@\the\c@refsection}\@empty
  \cslet{blx@fakesetplist@\the\c@refsection}\@empty}

\apptocmd{\blx@bbl@set@i}
  {\ifcsundef{blx@isfakeset@\the\c@refsection @\abx@field@entrykey}
     {\csxdef{blx@setc@\the\c@refsection @#1}{\abx@field@entrykey}%
      \listcsxadd{blx@setclist@\the\c@refsection}{\detokenize{#1}}}
     {}}
  {}
  {\blx@error
     {Failed to patch '\string\blx@bbl@set@i'}
     {Patching '\string\blx@bbl@set@i' failed for some reason.
      \MessageBreak
      Please report this bug}}

% {<section>}{<set child>}{<set parent>}
\protected\def\blx@aux@set@setc#1#2#3{%
  \csxdef{blx@setc@#1@#2}{#3}}

\protected\def\blx@aux@write@setc#1#2#3{%
  \blx@auxwrite\blx@aux{}{\string\blx@aux@set@setc{#1}{#2}{#3}}}

\def\blx@write@setc#1{%
  \ifcsundef{blx@setc@\the\c@refsection @#1}
    {}
    {\blx@aux@write@setc{\the\c@refsection}{#1}
       {\csuse{blx@setc@\the\c@refsection @#1}}}}

\appto\blx@bblend{%
  \forlistcsloop{\blx@write@setc}{blx@setclist@\the\c@refsection}}

% blx@setonly doesn't exist here, since it is defined in \inset,
% rely on the existence of setc instead.
% We also make sure to skip the actual @set entries and display
% the fake ones.
\patchcmd{\blx@bbl@endentry}
  {\nottoggle{blx@setonly}}
  {\ifentrytype{set}
    {\ifcsundef{blx@isfakeset@\the\c@refsection @\abx@field@entrykey}
       {\blx@writefakeset@oo{\abx@field@entrykey}{\abx@field@entryset}%
        \settoggle{blx@skipbib}{true}%
        \settoggle{blx@skipbiblist}{true}%
        \settoggle{blx@skiplab}{true}}
       {\listcsxadd{blx@fakesetplist@\the\c@refsection}{%
          \abx@field@entrykey}}}
    {}%
   \ifcsundef{blx@setc@\the\c@refsection @\abx@field@entrykey}}
  {}
  {\blx@error
     {Failed to patch '\string\blx@bbl@endentry'}
     {Patching '\string\blx@bbl@endentry' failed for some reason.
      \MessageBreak
      Please report this bug}}

% cite the fake set for our current set
% the \expandafter party essentially does
% \blx@citation@entry{\blx@fakeset@prefix#1}{\blx@msg@cundef}
% (just correctly \detokenize'd and all)
\def\blx@citation@set#1#2{%
  \blx@citation@entry{#1}{#2}%
  \ifcsundef{blx@isfakeset@\the\c@refsection @#1}
    {\begingroup
     \expandafter\def\expandafter\blx@tempa\expandafter{%
       \expandafter\detokenize\expandafter{\blx@fakeset@prefix#1}}%
     \expandafter\expandafter\expandafter\blx@citation@entry
     \expandafter\expandafter\expandafter{\blx@tempa}{\blx@msg@cundef}%
     \endgroup}
    {}%
  \begingroup
  \def\do##1{\blx@citation@entry{##1}\blx@msg@cundef}%
  \expandafter\expandafter\expandafter\docsvlist
  \expandafter\expandafter\expandafter{%
    \csname blx@setp@\the\c@refsection @#1\endcsname}%
  \endgroup}

\def\blx@citation@inset#1#2{%
  \blx@citation@entry{#1}{#2}%
  \expandafter\expandafter\expandafter\blx@citation@inset@i
  \expandafter\expandafter\expandafter{%
    \csname blx@setc@\the\c@refsection @#1\endcsname}\blx@msg@cundef}

\def\blx@citation@inset@i#1{%
  \ifcsdef{blx@setp@\the\c@refsection @#1}
    {\blx@citation@set{#1}}
    {\blx@citation@entry{#1}}}

\def\blx@appentrydatato#1#2{%
  \ifdef#2
    {\appto#1{%
       \def\noexpand#2{\expandonce#2}}}
    {}}

% if we have a fakeset, load the real @set to get the right entrykey
% if we have a real @set, load the fakeset for all entry data
% but make sure that the entrykey fits
% in any case copy over some label data from its first child
\def\blx@getdata#1{%
  \csuse{blx@data@\the\c@refsection @\blx@refcontext@context @#1}%
  \ifcsundef{blx@isfakeset@\the\c@refsection @#1}
    {}
    {\csuse{blx@data@\the\c@refsection @\blx@refcontext@context
             @\csuse{blx@isfakeset@\the\c@refsection @#1}}}%
  \ifcsundef{blx@getfakeset@\the\c@refsection @#1}
    {}
    {\let\blx@real@abx@field@entrykey\abx@field@entrykey
     \csuse{blx@data@\the\c@refsection @\blx@refcontext@context
            @\csuse{blx@getfakeset@\the\c@refsection @#1}}%
     \let\abx@field@entrykey\blx@real@abx@field@entrykey}%
  \ifcsundef{blx@setp@\the\c@refsection @\abx@field@entrykey}
    {}
    {\begingroup
     \expandafter\expandafter\expandafter\expandafter
     \expandafter\expandafter\expandafter\def
     \expandafter\expandafter\expandafter\expandafter
     \expandafter\expandafter\expandafter\blx@tempa
     \expandafter\expandafter\expandafter\expandafter
     \expandafter\expandafter\expandafter{%
       \expandafter\expandafter\expandafter\blx@grabfirstcsvitem
         \csname blx@setp@\the\c@refsection
           @\abx@field@entrykey\endcsname,\blx@grabfirstcsvitem@end}%
     \let\blx@tempb\@empty
     \blx@ifdata{\blx@tempa}
       {\blx@getdata{\blx@tempa}%
        \blx@appentrydatato\blx@tempb\abx@field@labelyear
        \blx@appentrydatato\blx@tempb\abx@field@labelendyear
        \blx@appentrydatato\blx@tempb\abx@field@labelmonth
        \blx@appentrydatato\blx@tempb\abx@field@labelendmonth
        \blx@appentrydatato\blx@tempb\abx@field@labelday
        \blx@appentrydatato\blx@tempb\abx@field@labelendday
        \blx@appentrydatato\blx@tempb\abx@field@labelprefix
        \blx@appentrydatato\blx@tempb\abx@field@labelalpha
        \blx@appentrydatato\blx@tempb\abx@field@extraalpha
        \blx@appentrydatato\blx@tempb\abx@field@extradate}
       {}%
     \edef\blx@tempb{\endgroup\blx@tempb}%
     \blx@tempb}%
  \blx@adjustyears
  \blx@getlabeldata
  \blx@aliasfields
  \blx@setcitecounter}


\def\blx@bblend@redosetlabelwidth@i#1{%
  \begingroup
  \blx@ifdata{#1}
    {\blx@getdata{#1}%
     \nottoggle{blx@skiplab}
       {\iftoggle{blx@labelnumber}
          {\ifdefempty\abx@field@localnumber
             {}
             {\ifundef\abx@field@shorthand
                {\blx@bbl@labelnumberwidth@numeric{}}
                {\blx@bbl@labelnumberwidth@shorthand{}}}}
          {}%
        \iftoggle{blx@labelalpha}
          {\blx@bbl@labelalpha}
          {}%
        \iftoggle{blx@labeltitle}
          {\blx@bbl@labeltitle}
          {}%
        \iftoggle{blx@labeltitleyear}
          {\blx@bbl@labeltitleyear}
          {}%
        \iftoggle{blx@labeldateparts}
          {\blx@bbl@labeldate}
          {}%
        \blx@bbl@labelname}
       {}}
    {}%
  \endgroup
}

\def\blx@bblend@redosetlabelwidth{%
  \forlistcsloop{\blx@bblend@redosetlabelwidth@i}
    {blx@fakesetplist@\the\c@refsection}}

\appto\blx@bblend{\blx@bblend@redosetlabelwidth}

% categories need the correct entry key for fake sets
\def\blx@addtocategory#1#2{%
  % If we are adding a set member to a category, make sure we also add the
  % set parent if it is cited. If it is cited, we should be using the set
  % parent in the category, not the set child member. blx@setc@... will
  % only exist if the set parent is also cited as it is only defined when a
  % member contains \inset which only happens when the set parent is cited.
  \ifcsdef{blx@setc@\the\c@refsection @#2}
    {\blx@auxwrite\@mainaux{}{\string\abx@aux@category{#1}{\csuse{blx@setc@\the\c@refsection @#2}}}%
     \abx@aux@category{#1}{\csuse{blx@setc@\the\c@refsection @#2}}}
    {}%
  \ifcsundef{blx@getfakeset@\the\c@refsection @#2}
    {}
    {\blx@auxwrite\@mainaux{}{\string\abx@aux@category{#1}{\csuse{blx@getfakeset@\the\c@refsection @#2}}}%
     \abx@aux@category{#1}{\csuse{blx@getfakeset@\the\c@refsection @#2}}}%
  \blx@auxwrite\@mainaux{}{\string\abx@aux@category{#1}{#2}}%
  \abx@aux@category{#1}{#2}}

% dynamic entry sets

\def\blx@btx@citeset#1#2{%
  \blx@nl
  @set{#1,\blx@nl
  \space\space entryset = {#2},\blx@nl
  }%
}

\protected\def\blx@setreq#1#2{%
  \blx@auxwrite\blx@bcfout{}{\blx@btx@citeset{#1}{#2}}%
  \blx@nocite@do{#1}}

% xref and @set
\def\blx@citation@i#1#2{%
  \ifbool{citerequest}
    {\ifcsdef{blx@setp@\the\c@refsection @#1}
       {\blx@citation@set{#1}{#2}}
       {\ifcsdef{blx@setc@\the\c@refsection @#1}
         {\blx@citation@inset{#1}{#2}}
         {\blx@citation@entry{#1}{#2}}}%
     \ifcsdef{blx@refc@\the\c@refsection @#1}%
       {\blx@citation@xref{#1}}
       {}}
    {}}

% refcontexts are out, but we can try to save labelprefix

% Luckily all refcontext names use \blx@refcontext@labelprefix, so if we
% don't modify that macro, we don't actually change the refcontext.
% Remember that \blx@refcontext@labelprefix contains a hash of the labelprefix
% and that \blx@refcontext@labelprefix@real contains the value.
% Effectively we always stay in \blx@sorting/global/global//global/global,
% and additionally carry around the labelprefix value
% in \blx@refcontext@labelprefix@real and pass it to the aux file.
% There are differences to the result obtained with Biber,
% but it should be good enough for very simple applications.
\blx@kv@defkey{blx@refcontext}{labelprefix}{%
  \xdef\blx@refcontext@labelprefix@real{#1}%
  \iftoggle{blx@defernumbers}
    {}%
    {\iftoggle{blx@labelnumber}
       {\blx@warning{%
          Option 'labelprefix' requires global\MessageBreak
          'defernumbers=true'}}
       {}}%
  \ifundef{\blx@bibtexwarn@labelprefix@used}
    {\blx@warning@noline{%
       The option 'labelprefix' is limited\MessageBreak
       when used with BibTeX.\MessageBreak
       Consider using Biber instead}%
     \global\let\blx@bibtexwarn@labelprefix@used\@empty}
    {}}

\def\blx@warn@bibtexrefcontext#1{%
  \blx@warning{%
    The refcontext option\MessageBreak
    '#1'\MessageBreak
    is not supported by the BibTeX backend.\MessageBreak
    Consider switching to Biber instead.\MessageBreak
    The option will be ignored}}

\def\blx@bibtexrefcontext@disable#1{%
  \blx@kv@defkey{blx@refcontext}{#1}{%
    \blx@warn@bibtexrefcontext{#1}}}

\forcsvlist{\blx@bibtexrefcontext@disable}{%
  nametemplates,sorting,sortingnamekeytemplatename,uniquenametemplatename,
  labelalphanametemplatename,namehashtemplatename}

\def\blx@assignrefcontext@disable#1{%
  \blx@warning{%
    BibTeX does not support refcontext assignments with\MessageBreak
    '\string\assignrefcontext#1'.\MessageBreak
    Consider using Biber instead.\MessageBreak
    Ignoring the refconext assignment}}

\def\blx@assignrefcontextkeyws[#1][#2]#3{%
  \blx@assignrefcontext@disable{keyws}}
\def\blx@assignrefcontextcats[#1][#2]#3{%
  \blx@assignrefcontext@disable{cats}}
\def\blx@assignrefcontextentries[#1][#2]#3{%
  \blx@assignrefcontext@disable{entries}}

\apptocmd{\blx@setdefaultrefcontext}
  {\csxdef{blx@assignedlabelprefix@\the\c@refsection @#1}{%
     \blx@refcontext@labelprefix@real}}
  {}
  {\blx@error
     {Failed to patch '\string\blx@setdefaultrefcontext'}
     {Patching '\string\blx@setdefaultrefcontext' failed for some reason.
      \MessageBreak
      Please report this bug}}

\def\abx@aux@defaultlabelprefix#1#2#3{%
  \csgdef{blx@assignedlabelprefix@#1@#2}{#3}}

\apptocmd{\blx@bbl@entry}
  {\ifcsundef{blx@assignedlabelprefix@\the\c@refsection @\thefield{entrykey}}
     {}
     {\blx@bbl@addfield{labelprefix}{%
        \csuse{blx@assignedlabelprefix@\the\c@refsection
          @\thefield{entrykey}}}}}
  {}
  {\blx@error
     {Failed to patch '\string\blx@bbl@entry'}
     {Patching '\string\blx@bbl@entry' failed for some reason.
      \MessageBreak
      Please report this bug}}

\blx@AtEndDocument{%
  % always add default labelprefix declarations to .aux
  \iftoggle{blx@bbldone}
    {\def\do#1{%
       \begingroup
       \def\do##1{%
         \blx@auxwrite\@mainaux{}{\string\abx@aux@defaultlabelprefix{#1}{##1}{%
           \csuse{blx@assignedlabelprefix@#1@##1}}}}%
       \dolistcsloop{blx@defaultrefcontexts@#1}%
       \endgroup}
     \dolistloop\blx@allrefsections}
    {}}


% Translate sorting schemes to BibTeX form
\def\blx@sorting@none{0}
\def\blx@sorting@nty{1}
\def\blx@sorting@nyt{2}
\def\blx@sorting@nyvt{3}
\def\blx@sorting@anyt{12}
\def\blx@sorting@anyvt{13}
\def\blx@sorting@ynt{21}
\def\blx@sorting@ydnt{22}
\def\blx@sorting@debug{99}

% Control file

\edef\blx@ctrl{%
  \blx@msg@bib
  @Control\string{biblatex-control,\blx@nl
  \space\space options = \string{%
    \blx@bcfversion:%
    \noexpand\iftoggle{blx@debug}{1}{0}:%
    \noexpand\iftoggle{blx@bibtex8}{1}{0}:%
    \noexpand\iftoggle{blx@sortcase}{1}{0}:%
    \noexpand\iftoggle{blx@useprefix}{1}{0}:%
    \noexpand\iftoggle{blx@useauthor}{1}{0}:%
    \noexpand\iftoggle{blx@useeditor}{1}{0}:%
    \noexpand\iftoggle{blx@usetranslator}{1}{0}:%
    \noexpand\iftoggle{blx@labelalpha}{1}{0}:%
    \noexpand\iftoggle{blx@labeldateparts}{1}{0}:%
    \noexpand\iftoggle{blx@singletitle}{1}{0}:%
    \noexpand\csuse{blx@sorting@\noexpand\blx@sorting}:%
    \noexpand\blx@maxcitenames:%
    \noexpand\blx@mincitenames:%
    \noexpand\blx@maxsortnames:%
    \noexpand\blx@minsortnames:%
    \noexpand\iftoggle{blx@nohashothers}{1}{0}:%
    \noexpand\iftoggle{blx@nosortothers}{1}{0}:%
    \noexpand\blx@maxalphanames:%
    \noexpand\blx@minalphanames:%
    \noexpand\blx@maxline:%
    \noexpand\detokenize\noexpand\expandafter{\noexpand\labelalphaothers}:%
    \noexpand\detokenize\noexpand\expandafter{\noexpand\blx@sortalphaothers}:%
    \noexpand\detokenize\noexpand\expandafter{\noexpand\blx@sorting}%
  \string},\blx@nl
  \string}%
}

\def\blx@ctrlwrite{%
  \ifcsundef{blx@sorting@\blx@sorting}
    {\blx@warning@noline{Sorting template '\blx@sorting'\MessageBreak
       not available with BibTeX backend.\MessageBreak
       Switch to Biber or select one of the default templates}}
    {}%
  \begingroup
  \blx@safe@actives
  \let\protect\string
  \edef\blx@sortalphaothers{\sortalphaothers}%
  \immediate\openout\blx@write\blx@ctrlfile\blxauxsuffix.bib\relax
  \blx@auxwrite\blx@write{}{\blx@ctrl}%
  \endgroup
  \AfterEndDocument{\immediate\closeout\blx@write}}


% {<string>}
% This mustn't be robust as it's likely to be used mainly in tests and so
% needs to be expandable
\renewcommand*\rangelen[1]{%
  \ifblank{#1}
    {0}%
    {\expandafter\blx@rangelen@range\romannumeral-`\q%
      #1\bibrangedash\bibrangedash&%
    }}

\def\blx@rangelen@range#1\bibrangedash#2\bibrangedash#3&{%
  \ifblank{#3}
    {\blx@rangelen@hyphen#1--&}
    {\blx@rangelen@check{#1}{#2}}%
}
\def\blx@rangelen@hyphen#1-#2-#3&{%
  \ifblank{#3}
    {1}% No range at all: assume one page
    {\blx@rangelen@check{#1}{#2}}%
}
\def\blx@rangelen@check#1#2{%
  \expandafter\blx@rangelen@check@aux
    \number\numexpr
      \blx@rangelen@check@int{#2}
      -
      \blx@rangelen@check@int{#1}
      + 1
    \relax
    &\stop
}
\def\blx@rangelen@check@aux#1&#2\stop{%
  \ifblank{#2}
    {#1}
    {-1}%
}
\def\blx@rangelen@check@int#1{%
  \ifblank{#1}
    {0&}
    {%
      \if\number\numexpr0#1-0#1\relax0
        #1
      \else
        0&
      \fi
    }%
}


% Disable some interfaces

\renewrobustcmd*{\DeclareSortingScheme}[3][]{}
\renewrobustcmd*{\DeclareExtradate}[1]{}

\def\blx@checkencoding{}

\AtBeginDocument{%
  \blx@checkencoding
  \if@filesw
    \blx@auxinit\blx@bibfiles
  \fi}

\endinput