% \iffalse meta-comment
%
% Copyright (C) 1993 by LaTeX3 project.  All rights reserved.
% For additional copyright information see further down in this file.
% 
% This file is part of the LaTeX2e system (PRELIMINARY TEST RELEASE)
% ------------------------------------------------------------------
% 
%  This system is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% 
% 
% IMPORTANT NOTICE:
% 
% For error reports in case of UNCHANGED versions see readme files.
% 
% Please do not request updates from us directly.  Distribution is
% done through Mail-Servers and TeX organizations.
% 
% You are not allowed to change this file.
% 
% You are allowed to distribute this file under the condition that
% it is distributed together with all files mentioned in 00readme.l2e.
% 
% If you receive only some of these files from someone, complain!
% 
% You are NOT ALLOWED to distribute this file alone.  You are NOT
% ALLOWED to take money for the distribution or use of either this
% file or a changed version, except for a nominal charge for copying
% etc.
% \fi
%%% ====================================================================
%%%  @LaTeX-file{
%%%     author          = "David Carlisle",
%%%     version         = "1.05",
%%%     date            = "01 December 1993",
%%%     time            = "12:29:54 GMT",
%%%     filename        = "latexbug.tex",
%%%     checksum        = "12187 266 843 6786",
%%%     email           = "carlisle@cs.man.ac.uk (Internet)",
%%%     codetable       = "ISO/ASCII",
%%%     keywords        = "LaTeX, bugs, reporting",
%%%     supported       = "yes",
%%%     docstring       = "
%%%
%%%     LaTeX bug report generator.
%%%     %%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%%     Processing this file with LaTeX should produce
%%%     a file latexbug.msg in the current directory.
%%%
%%%     latexbug.msg may be used as a template for submitting bug
%%%     reports concerning files in the standard LaTeX distribution.
%%%
%%%     Any bug report should be accompanied by a small LaTeX test file
%%%     that shows the bug, and the log that LaTeX produces on the
%%%     test file.
%%%
%%%     Please check before submitting a bug report that your format is
%%%     not more than one year old. New LaTeX releases occur at 6
%%%     monthly intervals, and so your bug may be fixed in a later
%%%     release.
%%%
%%%     Completed bug report forms, together with a LaTeX test file, and
%%%     a corresponding log file should be submitted to:
%%%     latex-bugs@rus.uni-stuttgart.de
%%%
%%%  }
%%% ====================================================================

\ifcat{=

\catcode`\{=1 \let\bgroup{
\catcode`\}=2 \let\egroup}
\catcode`\#=6 
\catcode`\^=7
\catcode`\@=11

\newlinechar`\^^J
\def\m@ne{-1 }
\countdef\count@255

\def\fmtname{INITEX}
\def\fmtversion{9999/00/00}
\def\space{ }
\def\@spaces{\space\space\space\space}
\let\@@end\end

\chardef\msg15
\immediate\openout\msg=\jobname.msg

\expandafter\edef\csname newif\endcsname#1#2{%
  \let\noexpand\ifinteractive
    \expandafter\noexpand\csname iffalse\endcsname}

\def\typeout{\immediate\write17}

\def\two@digits#1{\ifnum#1<10 0\fi\number#1}

\def\wmsg#1#{\bgroup\@wmsg}

\else
%%
%% @ is a letter
%%
\catcode`\@=11

%%
%% Output stream to produce the bug report template.
%%
\newwrite\msg
\immediate\openout\msg=\jobname.msg


%%
%% Check that LaTeX2e is being used.
%%
\ifx\undefined\newcommand
 \newlinechar`\^^J%
 \immediate\write17{^^J%
    You must use LaTeX2e to generate the bug report!^^J^^J%
    If there is a bug in the installation procedure,^^J%
    and you can not create LaTeX2e, you may use initex^^J%
    to generate the report}%

 \let\relax\end
\else
\def\@tempa{LaTeX2e}\ifx\@tempa\fmtname\else
 \immediate\write17{^^J%
  Older Versions of LaTeX are no longer supported.^^J%
  You must use LaTeX2e to generate the bug report!^^J^^J%
  If there is a bug in the installation procedure,^^J%
  and you can not create LaTeX2e, you may use initex^^J%
  to generate the report}%
 \let\relax\@@end
\fi\fi

%%
%% \wmsg writes to the terminal, and the .msg file
%% \wmsg* just writes to the .msg file
%% \typeout just writes to the terminal
%%

\def\wmsg{\bgroup\@ifstar{\interactivefalse\@wmsg}\@wmsg}

\fi

\relax


\def\@wmsg#1{%
  \ifinteractive\immediate\write17{#1}\fi
  \immediate\write\msg{#1}%
  \egroup}


%%
%% if \interactivefalse just make a blank template.
%%
\newif\ifinteractive
\interactivetrue


%%
%% Opening Banner.
%%
\typeout{^^J%
============================================================^^J%
^^J%
LaTeX2e bug report generator^^J%
==========================^^J%
Processing this file with LaTeX will produce a template \jobname.msg^^J%
for submitting bug reports for the LaTeX distribution.^^J%
^^J%
\ifinteractive
If you choose the interactive option, you will be prompted to answer^^J%
several questions. Otherwise a blank template will be created for^^J%
you to fill in using your editor.^^J%
\else
INITEX should only be used for reporting bugs with the LaTeX2e^^J%
installation procedure. If you have a working copy of LaTeX2e,^^J%
please use that to generate the report.
\fi}

\ifinteractive
\message{Interactive session (y/n) ? }
\read\m@ne to \answer

%%
%% Allow anything begining with `y' or `Y' for yes.
%%
\edef\answer{\uccode`\expandafter\@car\answer\@nil}
\ifnum \answer=`Y \else\interactivefalse\fi
\else
\def\answer{`\N}
\fi

%%
%% Header in the msg file.
%%
\wmsg*{^^J%
 LaTeX2e bug report.^^J%
\ifnum \answer=`Y Generated \else Template generated \fi
 by latexbug.tex on \number\year/\two@digits\month/\two@digits\day^^J%
 ============================================================}

%%%
%%% For testing for blank lines.
%%%
\def\xpar{\par}

\ifinteractive
%%
%% if interactive, \wread reads a line (verbatim) and write it to the
%% .msg file, until a blank line is entered.
%%
  \typeout{^^J%
    The answer to each question may take several lines.^^J%
    (Each line will be prompted by =>.)^^J%
    Typing a blank line terminates the current answer.}
  \def\wread{{\catcode`\^^I=12
  \let\do\@makeother\dospecials
  \message{=> }\read\m@ne to \answer
  \ifx\answer\xpar\else
    \immediate\write\msg{\answer}
    \expandafter\wread
  \fi}}
\else
%%
%% If non-interactive, \wread just writes a blank line to the .msg file,
%% and \wmsg does not write to the terminal.
%%
  \def\wread{\wmsg{}}
\fi

%%
%% Test which format is being used. These fields are completed
%% automatically even if the blank template is being produced.
%%
\wmsg{^^J%
Format:^^J%
\fmtname\space <\fmtversion>}

%%
%% Test the age of the current format.
%%
\def\getage#1/#2/#3\@nil{%
  \count@\year
  \advance\count@-#1\relax
  \multiply\count@ by 12\relax
  \advance\count@\month
  \advance\count@-#2\relax}
%
\expandafter\getage\fmtversion\@nil
%%
%% \count@ should now be the age of the format in months.
%%
\ifnum\count@>12
\def\oldformat{^^J%
   ! Your LaTeX installation is more than one year old.^^J%
   ! Please consider updating LaTeX before submitting this report.^^J%
   ! At least check a current latex.bug file, to see if the bug^^J%
   ! has been fixed in the current release.^^J%
   !}
%%
%% Put the message in a macro to improve the look of the error mesage.
%%

\errhelp{If you still wish to complete the form, just type return.}
\errmessage{\oldformat}
\fi

%%
%% Two macros that vary their definitions betwen LaTeX installations.
%%
\wmsg*{^^J%
Current Directory Syntax:^^J%
\meaning\@currdir}

\wmsg*{^^J%
Input Path:^^J%
\meaning\input@path}


%%
%% Now just use \wmsg and \wread for each of the fields in the form.
%%
\wmsg{^^J%
Your Name:}
\wread

\wmsg{^^J%
Your Address (preferably email):}
\wread

\wmsg{^^J%
Brief description of bug:}
\wread

\wmsg{^^J%
List of classes, packages and options (with dates/version numbers)^^J%
used in the test file:}
\wread


%%
%% Closing Banner.
%%
\typeout{^^J%
============================================================}

\ifinteractive
 \typeout{^^J%
   You may wish to make further changes to the bug report file^^J%
   \jobname.msg^^J%
   Using your editor.}
\else
 \typeout{^^J%
   A template for submitting bug reports has been left in the file:^^J%
   \jobname.msg^^J%
   Please use your editor to complete the file before submitting^^J%
   your report.}
\fi

\let\ifinteractivetrue\iftrue
\wmsg{^^J%
============================================================^^J%
^^J%
  If you have access to email, please send^^J%
  \@spaces1) \jobname.msg,^^J%
  \@spaces2) a small LaTeX file demonstrating the bug,^^J%
  \@spaces3) the log file LaTeX produces from your test file,^^J%
  to: \space latex-bugs@rus.uni-stuttgart.de^^J%
^^J%
^^J%
============================================================}

%%
%% Close the .msg output stream.
%%
\immediate\closeout\msg

%%
%% This is the TeX primitive \end command.
%%
\@@end
