%% letter.bst
%% Copyright 1999 Christophe Geuzaine
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or (at your option) any later version.
%
% BibTeX bibliography style `letter.bst'
% 'directory' database: all fields
% 
% Christophe.Geuzaine@advalvas.be
%
% Last modified 04/05/1999
% 
% The parts you may want to customize are labeled with "CUSTOM"
%

INTEGERS { nameptr namesleft numnames numaux len }
STRINGS { s t u v }

% ------------------------------------------------------------ 
%  E N T R I E S
% ------------------------------------------------------------ 

ENTRY
  { name
    address
    p.address
    r.address
    w.title
    w.name
    w.address
  }
  {}
  {}


% ------------------------------------------------------------ 
%  F O R M A T S 
% ------------------------------------------------------------ 

FUNCTION {format.names}
{ 's :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { 
% CUSTOM uncomment one of the following lines to have the behaviour on the right
      s nameptr "{ff }{vv }{ll}{, jj}"  format.name$ 't := % Christophe de Geuzaine, jr
%     s nameptr "{f. }{vv }{ll}{, jj}"  format.name$ 't := % C. de Geuzaine, jr
%     s nameptr "{vv }{ll}{ f.}{, jj}"  format.name$ 't := % de Geuzaine C., jr
%     s nameptr "{vv }{ll}{, ff}{, jj}" format.name$ 't := % de Geuzaine, Christophe, jr

      nameptr #1 >
	{ namesleft #1 >
	    { ", " * t * }
	    { " {\dirandf} " * t * }
	  if$
	}
	't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

FUNCTION {format.name}
{ name empty$
    { "" }
    { name format.names }
  if$
}

FUNCTION {format.address}
{ address empty$
    { "" }
    { " \dirnext " address * }
  if$
}

FUNCTION {format.p.address}
{ p.address empty$
    { "" }
    { " \dirnext " p.address * }
  if$
}

FUNCTION {format.r.address}
{ r.address empty$
    { "" }
    { " \dirnext " r.address * }
  if$
}

FUNCTION {format.w.title}
{ w.title empty$
    { "" }
    { " \dirnext " w.title * }
  if$
}

FUNCTION {format.w.name}
{ w.name empty$
    { "" }
    { " \dirnext " w.name * }
  if$
}

FUNCTION {format.w.address}
{ w.address empty$
    { "" }
    { " \dirnext " w.address * }
  if$
}

% ------------------------------------------------------------ 
%  P E R S O N   E N T R Y  
% ------------------------------------------------------------ 

FUNCTION { person }
{ 
  "\diritem{" write$
  format.name write$
  "}{" write$
  "d." cite$ * write$
  "}" write$

  newline$

  "\diritem{" write$
  "\dirbegin " write$
  format.name write$
  format.p.address write$
  "\dirend " write$
  "}{" write$
  "p." cite$ * write$
  "}" write$

  newline$

  "\diritem{" write$
  "\dirbegin " write$
  format.name write$
  format.r.address write$
  "\dirend " write$
  "}{" write$
  "r." cite$ * write$
  "}" write$

  newline$

  "\diritem{" write$
  "\dirbegin " write$
  format.name write$
  format.w.title write$
  format.w.name write$
  format.w.address write$
  "\dirend " write$
  "}{" write$
  "w." cite$ * write$
  "}" write$

  newline$
}

% ------------------------------------------------------------ 
%  C O M P A N Y   E N T R Y  
% ------------------------------------------------------------ 


FUNCTION { company }
{ 
  "\diritem{" write$
  name write$
  "}{" write$
  "d." cite$ * write$
  "}" write$

  newline$

  "\diritem{" write$
  "\dirbegin " write$
  name write$
  format.address write$
  "\dirend " write$
  "}{" write$
  "p." cite$ * write$
  "}" write$

  newline$

  "\diritem{" write$
  "\dirbegin " write$
  name write$
  format.address write$
  "\dirend " write$
  "}{" write$
  "r." cite$ * write$
  "}" write$

  newline$

  "\diritem{" write$
  "\dirbegin " write$
  name write$
  format.address write$
  "\dirend " write$
  "}{" write$
  "w." cite$ * write$
  "}" write$

  newline$
}

% ------------------------------------------------------------ 
%  P L A C E   E N T R Y  
% ------------------------------------------------------------ 

FUNCTION { place }
{ 
  "\diritem{" write$
  name write$
  "}{" write$
  "d." cite$ * write$
  "}" write$

  newline$

  "\diritem{" write$
  "\dirbegin " write$
  name write$
  format.address write$
  "\dirend " write$
  "}{" write$
  "p." cite$ * write$
  "}" write$

  newline$

  "\diritem{" write$
  "\dirbegin " write$
  name write$
  format.address write$
  "\dirend " write$
  "}{" write$
  "r." cite$ * write$
  "}" write$

  newline$

  "\diritem{" write$
  "\dirbegin " write$
  name write$
  format.address write$
  "\dirend " write$
  "}{" write$
  "w." cite$ * write$
  "}" write$

  newline$
}

% ------------------------------------------------------------ 
%  M A I N 
% ------------------------------------------------------------ 

READ
ITERATE {call.type$}

