%%
%% This is file `makebst.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% makebst.dtx  (with options: `program,optlist,ds24')
%% =============================================
%% IMPORTANT NOTICE:
%% This is a generated file.
%% 
%% It is subject to the same copyright conditions (see below)
%% as in the original file: makebst.dtx.
%% It may not be distributed without makebst.dtx.
%% 
%% Full documentation can be obtained by LaTeXing that original file.
%% Only a few abbreviated comments remain here to describe the usage.
%% =============================================
%% Copyright 1993-1999 Patrick W Daly
%% Max-Planck-Institut f\"ur Aeronomie
%% Max-Planck-Str. 2
%% D-37191 Katlenburg-Lindau
%% Germany
%% E-mail: daly@linmp.mpg.de
%%
%% 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 any later version.
%%
%% This is a contributed file to the LaTeX2e system.
%% -------------------------------------------------
\def\ProvidesFile#1 [#2 #3 #4]{\def\filename{#1}%
  \def\fileversion{#3}\def\filedate{#2}}
 \ProvidesFile{makebst}
    [1999/02/24 3.2 (PWD)]
 % This file is to be run under TeX (or even LaTeX)
 % It interactively asks questions about the bibliographic style file
 % that you want to produce. When it is finished, it writes a docstrip
 % driver file that produces that .bst file from the generic .mbs that
 % you specified; optionally, it will call the docstrip run immediately.
 % For details, read the documentation in the source file makebst.dtx.
 %--------------------------------------------------------------------
\newwrite\outfile
\newread\ttyin
\newread\infile
\newwrite\ttyout
\def\mes{\immediate\write\ttyout}
\def\wr#1{\immediate\write\outfile{#1}}
\newlinechar=`\^^J
\def\MBswitch{\catcode`\{=12 \catcode`\}=12
              \catcode`\(=1 \catcode`\)=2\relax}
\def\defpar{\par}
\def\remblk#1 @@{#1}
\def\ask#1#2{\mes{#2}\read\ttyin to #1\ifx#1\defpar\def#1{}\else
   \edef#1{\expandafter\remblk#1@@}\fi}
\def\groot#1.#2@@{#1}
\def\getroot#1{\expandafter\groot#1.@@}
\def\gext#1.#2.#3@@{#2}
\def\getext#1{\expandafter\gext#1..@@}
\def\MBaskfile#1(#2.#3)#4#5{%
\loop
  \def\ans{#2.#3}
\if!#2!
 \if!#3!\ask{#5}{#1}\fi
  \ask{#5}{#1 (default extension=#3)}\else
  \ask{#5}{#1 (default=\ans)}
\fi
  \ifx#5\empty \edef#5{\ans}\fi
  \edef\froot{\getroot#5}
  \edef\fext{\getext#5}
  \ifx\fext\empty \def\fext{#3}\fi
  \edef#5{\froot.\fext}
\if#4i
  \def\temp{Cannot find file `#5'}
  \openin\infile#5\relax
  \ifeof\infile \def\ans{}\fi \closein\infile
\else
 \def\temp{There is no default}
 \ifx\froot\empty \def\ans{}\fi
\fi
  \ifx\ans\empty \mes{*** \temp}
\repeat}
{\catcode`\%=12
 \gdef\pc{%}
 \gdef\pcpc{%% }
}
\def\spsp{\space\space}
\newcount\hours
\newcount\minutes
\def\SetTime{\hours=\time
        \global\divide\hours by 60
        \minutes=\hours
        \multiply\minutes by 60
        \advance\minutes by-\time
        \global\multiply\minutes by-1 }
\SetTime
\def\now{\number\hours:\ifnum\minutes<10 0\fi\number\minutes}
\def\today{\number\year/\ifnum\month<10 0\fi\number\month
   /\ifnum\day<10 0\fi\number\day}
\def\Now{\today\space at \now}
\def\optdef#1#2#3#4{\expandafter\def\csname opt@#1\endcsname{#2}%
  \expandafter\def\csname txt@#1\endcsname{#3}%
  \edef\optlist{#1,\optlist}%
  \mes{(#1) #3\space #4}}

\def\optlist{?,}

\def\nxtopt#1,#2@@{#1} \def\rstopt#1,#2@@{#2}

\newif\ifsw
\def\getans{\ask{\ans}{\spsp Select:}
  \expandafter\ifx\csname opt@\ans\endcsname\relax \def\ans{*}\fi
  \expandafter\ifx\csname opt@\ans\endcsname\relax
     \edef\ans{\expandafter\nxtopt\optlist@@}\fi
  \swtrue \loop
    \edef\temp{\expandafter\nxtopt\optlist@@}%
    \edef\optlist{\expandafter\rstopt\optlist@@}%
    \if\temp?\swfalse\else
      \if\temp\ans\wropt\ans
          \else\wrxopt\temp
      \fi
      \expandafter\let\csname opt@\temp\endcsname\relax
    \fi
  \ifsw \repeat
  \def\optlist{?,}%
  \wr{\pc--------------------}%
  }
\def\wropt#1{\edef\tempx{\csname opt@#1\endcsname}\if!\tempx!
  \wr{\spsp\spsp\pc: (def) \csname txt@#1\endcsname}\else
  \wr{\spsp\sep\csname opt@#1\endcsname\pc: \csname txt@#1\endcsname}
    \def\sep{,}\fi
  \mes{\spsp You have selected: \csname txt@#1\endcsname}}
\def\wrxopt#1{\edef\tempx{\csname opt@#1\endcsname}\if!\tempx!
  \wr{\pc\spsp\pc(def) \csname txt@#1\endcsname}\else
  \wr{\pc\spsp\sep\csname opt@#1\endcsname\pc: \csname txt@#1\endcsname}
    \def\sep{,}\fi}
\mes{***********************************^^J%
     * This is Make Bibliography Style *^^J%
     ***********************************^^J%
     It makes up a docstrip batch job to produce^^J%
     a customized .bst file for running with BibTeX}

\ask{\yn}{Do you want a description of the usage? (NO)}

\if!\yn!\else\if\yn n\else\if\yn N\else
\mes{In the interactive dialogue that follows,^^J%
     you will be presented with a series of menus.^^J%
     In each case, one answer is the default, marked as (*),^^J%
     and a mere carriage-return is sufficient to select it.^^J%
     (If there is no * choice, then the default is the last choice.)^^J%
     For the other choices, a letter is indicated^^J%
     in brackets for selecting that option. If you select^^J%
     a letter not in the list, default is taken.^^J^^J%
     The final output is a file containing a batch job^^J%
     which may be (La)TeXed to produce the desired BibTeX^^J%
     bibliography style file. The batch job may be edited^^J%
     to make minor changes, rather than running this program^^J%
     once again.}
\fi\fi\fi
\MBaskfile{^^JEnter the name of the MASTER file}(merlin.mbs)i\mfile
\let\mroot=\froot
\let\mext=\fext
\edef\temp{\mroot.opt}
\openin\infile\temp\relax
\let\mnext=\mext
\ifeof\infile\else
  \ask{\yn}{** Warning: a file `\temp' also exists^^J
       \spsp Shall I read it for the menu information? (NO)^^J
       \spsp (Answer `yes' only if you really know what you are doing)}
\if\yn y\def\mnext{opt}\else\if\yn Y\def\mnext{opt}\fi\fi
\mes{Menu information read from `\mroot.\mnext'}
\fi
\closein\infile
\MBaskfile{^^JName of the final OUTPUT .bst file?}(.bst)o\ofile
\let\oroot=\froot
\let\oext=\fext
\ask{\ans}{^^JGive a comment line to include in the style file.^^J%
           Something like for which journals it is applicable.}
\immediate\openout\outfile\oroot.dbj
\wr{\pcpc Driver file to produce \oroot.\oext\space from \mroot.\mext}
\wr{\pcpc Generated with \filename, version \fileversion\space (\filedate)}
\wr{\pcpc Produced on \Now}
\wr{\pcpc}
\wr{\string\input\space docstrip}
\wr{}
\wr{\string\preamble}
\wr{----------------------------------------}
\wr{*** \ans\space ***}
\wr{}
\wr{\string\endpreamble}
\wr{}
\wr{\string\postamble}
\wr{End of customized bst file}
\wr{\string\endpostamble}
\wr{}
\wr{\string\keepsilent}
\wr{}
\wr{\string\askforoverwritefalse}
\begingroup\MBswitch
\wr(\string\def\string\MBopts{\string\from{\mroot.\mext}{\pc)
\endgroup
\def\sep{}

\edef\temp{\mroot.\mnext}
\let\endoptions=\endinput
\input\temp
\begingroup\MBswitch
\wr(\spsp}})
\endgroup
\wr{\string\generate{\string\file{\oroot.\oext}{\string\MBopts}}}
\wr{\string\endbatchfile}

\immediate\closeout\outfile
\mes{^^JFinished!!^^J%
     Batch job written to file `\oroot.dbj'}
\def\ofile{\oroot.dbj}
\ask{\yn}{Shall I now run this batch job? (NO)}
\def\temp{\relax}
\if!\yn!\else\if\yn n\else\if\yn N\else
\def\temp{\input\ofile}\fi\fi\fi
{\catcode`\@=11 \ifx\@@end\undefined\else
  \global\let\end=\@@end\fi}
\temp
\end
%% <<<<< End of generated file <<<<<<
%%
%% End of file `makebst.tex'.
