% Compatibility mode macros for CWEBx (in addition to cwebxmac.tex)
% File: cwebcmac.tex, Author: Marc van Leeuwen, Date: November 1994

% This file gives definitions to macros defined in cwebmac.tex that are
% undefined in cwebxmac.tex, in order to simulate the cwebmac macro
% environment as much as possible in compatibility mode of CWEBx.
% In addition \PB is defined so as to get decent behaviour of |...| when used
% inside math mode (which one should't do, but some do it anyway).

\ifx\documentstyle\undefined\else\endinput\fi % LaTeX will use other macros

\input cwebxmac % that's the standard stuff
\xdef\fmtversion{\fmtversion c}

\let\mc=\ninerm % medium caps
\let\sc=\eightrm % small caps (NOT a caps-and-small-caps font)
%\font\tenss=cmss10 \let\cmntfont\tenss % alternative comment font

\def\CEE/{\Cee}
\def\UNIX/{\caps{UNIX}}
\def\TEX/{\TeX}
\def\CPLUSPLUS/{\Cpp}
\def\9#1{}
\let\cmntfont\tenrm

\def\|#1{\leavevmode\hbox{$#1$}} % in case this is used directly
\def\ATP{\X\kern-.5em:Preprocessor definitions\X}
\let\ATH=\ATP % in case the user refers to \ATH directly
\def\PB#1{\ifmmode\hbox{#1}\else#1\fi} % make |...| safe in math mode

\def\DC{\kern.1em{::}\kern.1em} % symbol for ::
\def\PA{\mathbin{.*}} % symbol for .*
\def\MGA{\mathbin{\MG*}} % symbol for ->*

% Revert to Levy/Knuth representations of operators

\def\K{=\Penalty2} % assignment operator
\def\E{\Penalty7\equiv} % equality test
\newbox\MGbox % symbol for ->
\setbox\MGbox=\hbox{\kern-2pt\lower3pt\hbox{\teni\char'176}\kern1pt}
\def\MG{\copy\MGbox}

\secpagedepth=3 % page breaks will occur for depths -1, 0, and 1
\let\SHC\C % "// short comments" treated like "/* ordinary comments */"
\outer\def\N#1 #2. #3.				     % start of `@*' section
 {\global\gdepth=#1\global\advance\gdepth1 \global\gtitle={#3}\MN#2.%
  \ifon \ifnum#1<\secpagedepth \vfil\eject
	\else \vskip 0pt plus .5 \vsize \penalty-1000\vskip 0pt plus -.5 \vsize
	      \vskip\intersecskip
	\fi
  \fi
  \message{*\secno} % progress report
  \edef\next{\write\cont % to contents file
    {\ZZ{#3}{\number\gdepth}{\secno}{\noexpand\number\pageno}}}
  \next
  \ifon\startsection{\bf#3.\quad}%
 }

\def\contentsline#1#2#3#4% #1==title, #2=depth+1, #3=secno, #4=pageno
 {\ifnum#2=0 \smallbreak\fi
  \line{\consetup{#2}#1 \rm\leaders\hbox to .5em{.\hfil}\hfil
        \ #3\hbox to3em{\hss#4}%
       }%
 }
\def\consetup#1% #1=depth+1
 {\ifcase#1 \bf  % @**
  \or            % @*
  \or \hskip2em  % @*1
  \or \hskip4em  % @*2
  \or \hskip6em  % @*3
  \or \hskip8em  % @*4
  \or \hskip10em % @*5
  \else \hskip12em % depth >=6
  \fi
 }

\def\,{\relax\ifmmode\mskip\thinmuskip\else\thinspace\fi}
