% This file is a LaTeX2e package.  One may select it in a LaTeX document by
% the command 
%
%	\usepackage{fwebinsert}
%

% The package sets things up so that one can include TeX output from FWEAVE
% into a LaTeX document.  

% J. A. Krommes, April 12, 1996

\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{fwebinsert}[1996/04/12]

\DeclareOption{FWEBstandalone}{\input{fwebmac.sty}\FWEBstandalonetrue}
\DeclareOption{FWEBinsert}{\input{fwebmac.sty}\FWEBstandalonefalse}

\ExecuteOptions{FWEBinsert} % Set up default.
\ProcessOptions

\makeatletter

% The optional argument to \fwebinput is zero or more letters from the list
% 0,1,2,3 (fweb levels), h (headers),  or c (table of contents).
\newcommand\fwebinput[2][]{\W@read{#1}{#2}}
\global\let\FWEBinput\fwebinput

\gdef\W@read#1#2{\begingroup% The entire file will be within a group.
	\toks0={#1}%
	\ifW@intoks{\toks0}0{\fweblevel{0}}{}%
	\ifW@intoks{\toks0}1{\fweblevel{1}}{}%
	\ifW@intoks{\toks0}2{\fweblevel{2}}{}%
	\ifW@intoks{\toks0}3{\fweblevel{3}}{}%
	\ifW@intoks{\toks0}h{\W@headerstrue}{\W@headersfalse}%
	\ifW@intoks{\toks0}c{}{\def\Wcon##1{}}%
	\def\jobname{#2}% For reading the aux file in \Wbegin.
	\input{#2.tex}% Read the TeX'd output from fweave.
	\endgroup
	}

\gdef\fweblevel#1{\def\W@ssmin{#1}}

\newif\ifW@inlist

\gdef\ifW@intoks#1#2#3#4{\let\W@tsttoken#2%
\expandafter\W@listcheck\the#1\relax
\ifW@inlist#3\else#4\fi}

\gdef\W@listcheck#1\relax{\W@inlistfalse
\def\test{#1}\ifx\test\empty
\else\W@tokscheck#1\relax\fi}

\gdef\W@tokscheck#1#2\relax{\if\W@tsttoken#1\W@inlisttrue\let\next\relax
\else\def\next{\W@listcheck#2\relax}\fi
\next}

\makeatother
