\ProvidesFile{biblatex-gost.def}
[2013/04/03\space v0.8\space biblatex-gost styles]

% these declarations should be here, not in lbx, to be initialized for all languages
\NewBibliographyString{
  involumes,
  geneditor,
  geneditors,
  bygeneditor,
  bygeneditortr,
  bygeneditorco,
  bygeneditoran,
  bygeneditorin,
  bygeneditorfo,
  bygeneditoraf,
  bygeneditortrco,
  bygeneditortran,
  bygeneditortrin,
  bygeneditortrfo,
  bygeneditortraf,
  bygeneditorcoin,
  bygeneditorcofo,
  bygeneditorcoaf,
  bygeneditoranin,
  bygeneditoranfo,
  bygeneditoranaf,
  bygeneditortrcoin,
  bygeneditortrcofo,
  bygeneditortrcoaf,
  bygeneditortranin,
  bygeneditortranfo,
  bygeneditortranaf,
  bycompilertr,
  bycompilerco,
  bycompileran,
  bycompilerin,
  bycompilerfo,
  bycompileraf,
  bycompilertrco,
  bycompilertran,
  bycompilertrin,
  bycompilertrfo,
  bycompilertraf,
  bycompilercoin,
  bycompilercofo,
  bycompilercoaf,
  bycompileranin,
  bycompileranfo,
  bycompileranaf,
  bycompilertrcoin,
  bycompilertrcofo,
  bycompilertrcoaf,
  bycompilertranin,
  bycompilertranfo,
  bycompilertranaf,
  gecompiler,
  gecompilers,
  bygecompiler,
  bygecompilertr,
  bygecompilerco,
  bygecompileran,
  bygecompilerin,
  bygecompilerfo,
  bygecompileraf,
  bygecompilertrco,
  bygecompilertran,
  bygecompilertrin,
  bygecompilertrfo,
  bygecompilertraf,
  bygecompilercoin,
  bygecompilercofo,
  bygecompilercoaf,
  bygecompileranin,
  bygecompileranfo,
  bygecompileranaf,
  bygecompilertrcoin,
  bygecompilertrcofo,
  bygecompilertrcoaf,
  bygecompilertranin,
  bygecompilertranfo,
  bygecompilertranaf,
  books,
  parts,
  issues,
  mediavideorecording,
  mediasoundrecording,
  mediagraphic,
  mediacartographic,
  mediakit,
  mediamotionpicture,
  mediamicroform,
  mediamultimedia,
  mediamusic,
  mediaobject,
  mediamanuscript,
  mediatext,
  mediabraille,
  mediaeresource,
  langpolish,
  frompolish,
  updated,
  systemreq,
  countryru,countryussr,patentru,patentussr,patreqru,patrequssr,invcert,
  requested,published,priority,
  docthesis,phdautoref,docautoref,
}
\DeclareLanguageMapping{russian}{russian-gost}
%
%   Sorting Schemes
%
\DeclareSortingScheme{nty}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \name{sortname}
    \name{author}
    \name{editor}
    \name{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{sortvolume}
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{book}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{part}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{issue}
    \literal{0000}
  }
}

\DeclareSortingScheme{nyvt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \name{sortname}
    \name{author}
    \name{editor}
    \name{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{sortvolume}
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{book}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{part}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{issue}
    \literal{0000}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
}

\DeclareSortingScheme{ynt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
  }
  \sort{
    \field{sortyear}
    \field{year}
    \literal{9999}
  }
  \sort{
    \name{sortname}
    \name{author}
    \name{editor}
    \name{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
}

\DeclareSortingScheme{ydnt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
  }
  \sort[direction=descending]{
    \field[strside=left,strwidth=4]{sortyear}
    \field[strside=left,strwidth=4]{year}
    \literal{9999}
  }
  \sort{
    \name{sortname}
    \name{author}
    \name{editor}
    \name{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
}

\DeclareSortingScheme{nyt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \name{sortname}
    \name{author}
    \name{editor}
    \name{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortvolume}
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{book}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{part}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{issue}
    \literal{0000}
  }
}

\DeclareSortingScheme{ntvy}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \name{sortname}
    \name{author}
    \name{editor}
    \name{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortvolume}
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{book}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{part}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{issue}
    \literal{0000}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
}

\DeclareSortingScheme{anyt}{
  \sort{
    \field{presort}
  }
  \sort{
    \field{labelalpha}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
}

\DeclareSortingScheme{anyvt}{
  \sort{
    \field{presort}
  }
  \sort{
    \field{labelalpha}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{book}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{part}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{issue}
    \literal{0000}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
}

\DeclareBibliographyOption{movenames}[true]{%
  \gdef\blx@opt@movenames{#1}%
  \ifstrequal{#1}{true}
    {\DeclareStyleSourcemap{
      \maps[datatype=bibtex]{
        \map[overwrite]{
          \step[fieldsource=author,
            match=\regexp{(.+\s+and\s+){3,}},
            final]
          \step[fieldsource=options,
            match=\regexp{(.+)},
            replace=\regexp{useauthor=false,$1}]
          \step[fieldsource=options,
            match=\regexp{^$},
            replace=\regexp{useauthor=false}]
        }
        \map{
          \step[fieldsource=author,
            match=\regexp{(.+\s+and\s+){3,}},
            final]
          \step[fieldset=options, fieldvalue={useauthor=false}]
        }
        \map[overwrite]{
          \step[fieldsource=editor,
            match=\regexp{(.+\s+and\s+){3,}},
            final]
          \step[fieldsource=options,
            match=\regexp{(.+)},
            replace=\regexp{useeditor=false,$1}]
          \step[fieldsource=options,
            match=\regexp{^$},
            replace=\regexp{useeditor=false}]
        }
        \map{
          \step[fieldsource=editor,
            match=\regexp{(.+\s+and\s+){3,}},
            final]
          \step[fieldset=options, fieldvalue={useeditor=false}]
        }
        \map[overwrite]{
          \pertype{patent}
          \step[fieldsource=options, final]
          \step[fieldset=options, fieldvalue={useauthor=false,}]
          \step[fieldset=options, origfieldval, append]
        }
        \map{
          \pertype{patent}
          \step[fieldset=options, fieldvalue={useauthor=false}]
        }
      }
     }
    }
   {\DeclareStyleSourcemap{
      \maps[datatype=bibtex]{
        \map[overwrite]{
          \pertype{patent}
          \step[fieldsource=options, final]
          \step[fieldset=options, fieldvalue={useauthor=false,}]
          \step[fieldset=options, origfieldval, append]
        }
        \map{
          \pertype{patent}
          \step[fieldset=options, fieldvalue={useauthor=false}]
        }
      }
    }
   }
}

\DeclareSortExclusion{inbook,incollection,inproceeding,bookinbook,suppbook,suppcollection,inreference}
  {editor,volume,maintitle}

\DeclareLabelname{%
  \field{shortauthor}
  \field{author}
  \field{shorteditor}
  \field{editor}
  \field{translator}
}

\DeclareLabeltitle[book,collection,reference,proceedings]{%
  \field{shorttitle}
  \field{maintitle}
  \field{title}}

\DeclareDataInheritance{*}{*}{%
  \noinherit{heading}}
\DeclareDataInheritance{periodical}{article}{%
  \noinherit{endyear}\noinherit{endmonth}\noinherit{endday}}
\DeclareDataInheritance{mvbook,mvcollection,mvproceedings}
  {book,collection,inbook,incollection,inproceedings}{%
  \noinherit{endyear}\noinherit{endmonth}\noinherit{endday}}
\DeclareDataInheritance{mvbook,mvcollection,mvproceedings,mvreference}
  {book,collection,proceedings,reference}{%
  \inherit{shorttitle}{shorttitle}}

\DeclareDataInheritance{book}{inbook,bookinbook,suppbook}{%
  \inherit{translator}{booktranslator}
  \inherit{introduction}{bookintroduction}
  \inherit{commentator}{bookcommentator}
  \inherit{annotator}{bookannotator}
  \inherit{foreword}{bookforeword}
  \inherit{afterword}{bookafterword}
  \inherit{origlanguage}{bookoriglanguage}
  \inherit{credits}{bookcredits}
  \noinherit{pagetotal}}
\DeclareDataInheritance{collection,reference}{incollection,inreference,suppcollection}{%
  \inherit{translator}{booktranslator}
  \inherit{introduction}{bookintroduction}
  \inherit{commentator}{bookcommentator}
  \inherit{annotator}{bookannotator}
  \inherit{foreword}{bookforeword}
  \inherit{afterword}{bookafterword}
  \inherit{origlanguage}{bookoriglanguage}
  \inherit{credits}{bookcredits}
  \noinherit{pagetotal}}
\DeclareDataInheritance{proceedings}{inproceedings}{%
  \inherit{translator}{booktranslator}
  \inherit{introduction}{bookintroduction}
  \inherit{commentator}{bookcommentator}
  \inherit{annotator}{bookannotator}
  \inherit{foreword}{bookforeword}
  \inherit{afterword}{bookafterword}
  \inherit{origlanguage}{bookoriglanguage}
  \inherit{credits}{bookcredits}
  \noinherit{pagetotal}}

