home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / dev / c / cweb / macros / cwebmac.tex next >
Encoding:
Text File  |  1994-09-19  |  15.0 KB  |  332 lines

  1. % standard macros for CWEB listings (in addition to plain.tex)
  2. % Version 3.1 --- September 1994
  3. \ifx\documentstyle\undefined\else\endinput\fi % LaTeX will use other macros
  4. \xdef\fmtversion{\fmtversion+CWEB3.1}
  5.  
  6. \let\:=\. % preserve a way to get the dot accent
  7.  % (all other accents will still work as usual)
  8.  
  9. \parskip 0pt % no stretch between paragraphs
  10. \parindent 1em % for paragraphs and for the first line of C text
  11.  
  12. \font\ninerm=cmr9
  13. \let\mc=\ninerm % medium caps
  14. \def\CEE/{{\mc C\spacefactor1000}}
  15. \def\UNIX/{{\mc U\kern-.05emNIX\spacefactor1000}}
  16. \def\TEX/{\TeX}
  17. \def\CPLUSPLUS/{{\mc C\PP\spacefactor1000}}
  18. \def\Cee{\CEE/} % for backward compatibility
  19. \def\9#1{}
  20. \font\eightrm=cmr8
  21. \let\sc=\eightrm % small caps (NOT a caps-and-small-caps font)
  22. \let\mainfont=\tenrm
  23. \let\cmntfont\tenrm
  24. %\font\tenss=cmss10 \let\cmntfont\tenss % alternative comment font
  25. \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
  26. \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
  27. \font\tentex=cmtex10 % TeX extended character set (used in strings)
  28. \fontdimen7\tentex=0pt % no double space after sentences
  29.  
  30. \def\\#1{\leavevmode\hbox{\it#1\/\kern.05em}} % italic type for identifiers
  31. \def\|#1{\leavevmode\hbox{$#1$}} % one-letter identifiers look better this way
  32. \def\{\leavevmode\hbox{\bf
  33.   \def\_{\kern.04em\vbox{\hrule width.3em height .6pt}\kern.08em}%
  34.   #1\/\kern.05em}} % boldface type for reserved words
  35. \def\.#1{\leavevmode\hbox{\tentex % typewriter type for strings
  36.   \let\\=\BS % backslash in a string
  37.   \let\{=\LB % left brace in a string
  38.   \let\}=\RB % right brace in a string
  39.   \let\~=\TL % tilde in a string
  40.   \let\ =\SP % space in a string
  41.   \let\_=\UL % underline in a string
  42.   \let\&=\AM % ampersand in a string
  43.   \let\^=\CF % circumflex in a string
  44.   #1\kern.05em}}
  45. \def\){\discretionary{\hbox{\tentex\BS}}{}{}}
  46. \def\AT{@} % at sign for control text (not needed in versions >= 2.9)
  47. \def\ATL{\par\noindent\bgroup\catcode`\_=12 \postATL} % print @l in limbo
  48. \def\postATL#1 #2 {\bf letter \\{\uppercase{\char"#1}}
  49.    tangles as \tentex "#2"\egroup\par}
  50. \def\noATL#1 #2 {}
  51. \def\noatl{\let\ATL=\noATL} % suppress output from @l
  52. \def\ATH{\X\kern-.5em:Preprocessor definitions\X}
  53. \let\PB=\relax % hook for program brackets |...| in TeX part or section name
  54.  
  55. \chardef\AM=`\& % ampersand character in a string
  56. \chardef\BS=`\\ % backslash in a string
  57. \chardef\LB=`\{ % left brace in a string
  58. \chardef\RB=`\} % right brace in a string
  59. \def\SP{{\tt\char`\ }} % (visible) space in a string
  60. \chardef\TL=`\~ % tilde in a string
  61. \chardef\UL=`\_ % underline character in a string
  62. \chardef\CF=`\^ % circumflex character in a string
  63.  
  64. \newbox\PPbox % symbol for ++
  65. \setbox\PPbox=\hbox{\kern.5pt\raise1pt\hbox{\sevenrm+\kern-1pt+}\kern.5pt}
  66. \def\PP{\copy\PPbox}
  67. \newbox\MMbox \setbox\MMbox=\hbox{\kern.5pt\raise1pt\hbox{\sevensy\char0
  68.  \kern-1pt\char0}\kern.5pt}
  69. \def\MM{\copy\MMbox}
  70. \newbox\MGbox % symbol for ->
  71. \setbox\MGbox=\hbox{\kern-2pt\lower3pt\hbox{\teni\char'176}\kern1pt}
  72. \def\MG{\copy\MGbox}
  73. \def\MRL#1{\mathrel{\let\K==#1}}
  74. %\def\MRL#1{\KK#1}\def\KK#1#2{\buildrel\;#1\over{#2}}
  75. \let\GG=\gg
  76. \let\LL=\ll
  77. \let\NULL=\Lambda
  78. \mathchardef\AND="2026 % bitwise and; also \& (unary operator)
  79. \let\OR=\mid % bitwise or
  80. \let\XOR=\oplus % bitwise exclusive or
  81. \def\CM{{\sim}} % bitwise complement
  82. \newbox\MODbox \setbox\MODbox=\hbox{\eightrm\%}
  83. \def\MOD{\mathbin{\copy\MODbox}}
  84. \def\DC{\kern.1em{::}\kern.1em} % symbol for ::
  85. \def\PA{\mathbin{.*}} % symbol for .*
  86. \def\MGA{\mathbin{\MG*}} % symbol for ->*
  87. \def\this{\&{this}}
  88.  
  89. \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
  90. \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
  91.  
  92. \newcount\ind % current indentation in ems
  93. \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
  94. \def\2{\global\advance\ind by-1} % indent one less notch
  95. \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
  96. \def\4{\copy\bak} % backspace one notch
  97. \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
  98. \def\6{\ifmmode\else\par % forced break
  99.   \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
  100. \def\7{\Y\6} % forced break and a little extra space
  101. \def\8{\hskip-\ind em\hskip 2em} % no indentation
  102.  
  103. \newcount\gdepth % depth of current major group, plus one
  104. \newcount\secpagedepth
  105. \secpagedepth=3 % page breaks will occur for depths -1, 0, and 1
  106. \newtoks\gtitle % title of current major group
  107. \newskip\intersecskip \intersecskip=12pt minus 3pt % space between sections
  108. \let\yskip=\smallskip
  109. \def\?{\mathrel?}
  110. \def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt\eightrm#1~#2.\par}}
  111. \def\lapstar{\rlap{*}}
  112. \def\stsec{\rightskip=0pt % get out of C mode (cf. \B)
  113.   \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50
  114.   \noindent{\let\*=\lapstar\bf\secstar.\quad}}
  115. \let\startsection=\stsec
  116. \def\defin#1{\global\advance\ind by 2 \1\&{#1 } } % begin `define' or `format'
  117. \def\A{\note{See also section}} % xref for doubly defined section name
  118. \def\As{\note{See also sections}} % xref for multiply defined section name
  119. \def\B{\rightskip=0pt plus 100pt minus 10pt % go into C mode
  120.   \sfcode`;=3000
  121.   \pretolerance 10000
  122.   \hyphenpenalty 1000 % so strings can be broken (discretionary \ is inserted)
  123.   \exhyphenpenalty 10000
  124.   \global\ind=2 \1\ \unskip}
  125. \def\C#1{\5\5\quad$/\ast\,${\cmntfont #1}$\,\ast/$}
  126. \let\SHC\C % "// short comments" treated like "/* ordinary comments */"
  127. %\def\C#1{\5\5\quad$\triangleright\,${\cmntfont#1}$\,\triangleleft$}
  128. %\def\SHC#1{\5\5\quad$\diamond\,${\cmntfont#1}}
  129. \def\D{\defin{\#define}} % macro definition
  130. \let\E=\equiv % equivalence sign
  131. \def\ET{ and~} % conjunction between two section numbers
  132. \def\ETs{, and~} % conjunction between the last two of several section numbers
  133. \def\F{\defin{format}} % format definition
  134. \let\G=\ge % greater than or equal sign
  135. % \H is long Hungarian umlaut accent
  136. \let\I=\ne % unequal sign
  137. \def\J{\.{@\&}} % TANGLE's join operation
  138. \let\K== % assignment operator
  139. %\let\K=\leftarrow % "honest" alternative to standard assignment operator
  140. % \L is Polish letter suppressed-L
  141. \outer\def\M#1{\MN{#1}\ifon\vfil\penalty-100\vfilneg % beginning of section
  142.   \vskip\intersecskip\startsection\ignorespaces}
  143. \outer\def\N#1#2#3.{\gdepth=#1\gtitle={#3}\MN{#2}% beginning of starred section
  144.   \ifon\ifnum#1<\secpagedepth \vfil\eject % force page break if depth is small
  145.     \else\vfil\penalty-100\vfilneg\vskip\intersecskip\fi\fi
  146.   \message{*\secno} % progress report
  147.   \edef\next{\write\cont{\ZZ{#3}{#1}{\secno}% write to contents file
  148.                    {\noexpand\the\pageno}}}\next % \ZZ{title}{depth}{sec}{page}
  149.   \ifon\startsection{\bf#3.\quad}\ignorespaces}
  150. \def\MN#1{\par % common code for \M, \N
  151.   {\xdef\secstar{#1}\let\*=\empty\xdef\secno{#1}}% remove \* from section name
  152.   \ifx\secno\secstar \onmaybe \else\ontrue \fi
  153.   \mark{{{\tensy x}\secno}{\the\gdepth}{\the\gtitle}}}
  154. % each \mark is {section reference or null}{depth plus 1}{group title}
  155. % \O is Scandinavian letter O-with-slash
  156. % \P is paragraph sign
  157. \def\Q{\note{This code is cited in section}} % xref for mention of a section
  158. \def\Qs{\note{This code is cited in sections}} % xref for mentions of a section
  159. \let\R=\lnot % logical not
  160. % \S is section sign
  161. \def\T#1{\leavevmode % octal, hex or decimal constant
  162.   \hbox{$\def\?{\kern.2em}%
  163.     \def\$##1{\egroup_{\,\rm##1}\bgroup}% suffix to constant
  164.     \def\_{\cdot 10^{\aftergroup}}% power of ten (via dirty trick)
  165.     \let\~=\oct \let\^=\hex {#1}$}}
  166. \def\U{\note{This code is used in section}} % xref for use of a section
  167. \def\Us{\note{This code is used in sections}} % xref for uses of a section
  168. \let\V=\lor % logical or
  169. \let\W=\land % logical and
  170. \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % section name
  171.   \XX$\langle\,${#2\eightrm\kern.5em#1}$\,\rangle$\XX}
  172. \def\Y{\par\yskip}
  173. \let\Z=\le
  174. \let\ZZ=\let % now you can \write the control sequence \ZZ
  175. \let\*=*
  176.  
  177. %\def\oct{\hbox{\rm\char'23\kern-.2em\it\aftergroup\?\aftergroup}} % WEB style
  178. %\def\hex{\hbox{\rm\char"7D\tt\aftergroup}} % WEB style
  179. \def\oct{\hbox{$^\circ$\kern-.1em\it\aftergroup\?\aftergroup}}% CWEB style
  180. \def\hex{\hbox{$^{\scriptscriptstyle\#}$\tt\aftergroup}} % CWEB style
  181. \def\vb#1{\leavevmode\hbox{\kern2pt\vrule\vtop{\vbox{\hrule
  182.         \hbox{\strut\kern2pt\.{#1}\kern2pt}}
  183.       \hrule}\vrule\kern2pt}} % verbatim string
  184.  
  185. \def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue
  186. \newif\ifon \newif\iftitle \newif\ifpagesaved
  187.  
  188. \def\lheader{\mainfont\the\pageno\eightrm\qquad\grouptitle\hfill\title\qquad
  189.   \mainfont\topsecno} % top line on left-hand pages
  190. \def\rheader{\mainfont\topsecno\eightrm\qquad\title\hfill\grouptitle
  191.   \qquad\mainfont\the\pageno} % top line on right-hand pages
  192. \def\grouptitle{\let\i=I\let\j=J\uppercase\expandafter{\expandafter
  193.                         \takethree\topmark}}
  194. \def\topsecno{\expandafter\takeone\topmark}
  195. \def\takeone#1#2#3{#1}
  196. \def\taketwo#1#2#3{#2}
  197. \def\takethree#1#2#3{#3}
  198. \def\nullsec{\eightrm\kern-2em} % the \kern-2em cancels \qquad in headers
  199.  
  200. \let\page=\pagebody \raggedbottom
  201. % \def\page{\box255 }\normalbottom % faster, but loses plain TeX footnotes
  202. \def\normaloutput#1#2#3{\shipout\vbox{
  203.   \ifodd\pageno\hoffset=\pageshift\fi
  204.   \vbox to\fullpageheight{
  205.   \iftitle\global\titlefalse
  206.   \else\hbox to\pagewidth{\vbox to10pt{}\ifodd\pageno #3\else#2\fi}\fi
  207.   \vfill#1}} % parameter #1 is the page itself
  208.   \global\advance\pageno by1}
  209.  
  210. \gtitle={\.{CWEB} output} % this running head is reset by starred sections
  211. \mark{\noexpand\nullsec0{\the\gtitle}}
  212. \def\title{\expandafter\uppercase\expandafter{\jobname}}
  213. \def\topofcontents{\centerline{\titlefont\title}\vskip.7in
  214.   \vfill} % this material will start the table of contents page
  215. \def\botofcontents{\vfill
  216.   \centerline{\covernote}} % this material will end the table of contents page
  217. \def\covernote{}
  218. \def\contentspagenumber{0} % default page number for table of contents
  219. \newdimen\pagewidth \pagewidth=6.5in % the width of each page
  220. \newdimen\pageheight \pageheight=8.7in % the height of each page
  221. \newdimen\fullpageheight \fullpageheight=9in % page height including headlines
  222. \newdimen\pageshift \pageshift=0in % shift righthand pages wrt lefthand ones
  223. \def\magnify#1{\mag=#1\pagewidth=6.5truein\pageheight=8.7truein
  224.   \fullpageheight=9truein\setpage}
  225. \def\setpage{\hsize\pagewidth\vsize\pageheight} % use after changing page size
  226. \def\contentsfile{\jobname.toc} % file that gets table of contents info
  227. \def\readcontents{\input \contentsfile}
  228. \def\readindex{\input \jobname.idx}
  229. \def\readsections{\input \jobname.scn}
  230.  
  231. \newwrite\cont
  232. \output{\setbox0=\page % the first page is garbage
  233.   \openout\cont=\contentsfile
  234.        \write\cont{\catcode `\noexpand\@=11\relax}   % \makeatletter
  235.   \global\output{\normaloutput\page\lheader\rheader}}
  236. \setpage
  237. \vbox to \vsize{} % the first \topmark won't be null
  238.  
  239. \def\ch{\note{The following sections were changed by the change file:}
  240.   \let\*=\relax}
  241. \newbox\sbox % saved box preceding the index
  242. \newbox\lbox % lefthand column in the index
  243. \def\inx{\par\vskip6pt plus 1fil % we are beginning the index
  244.   \def\page{\box255 } \normalbottom
  245.   \write\cont{} % ensure that the contents file isn't empty
  246.        \write\cont{\catcode `\noexpand\@=12\relax}   % \makeatother
  247.   \closeout\cont % the contents information has been fully gathered
  248.   \output{\ifpagesaved\normaloutput{\box\sbox}\lheader\rheader\fi
  249.     \global\setbox\sbox=\page \global\pagesavedtrue}
  250.   \pagesavedfalse \eject % eject the page-so-far and predecessors
  251.   \setbox\sbox\vbox{\unvbox\sbox} % take it out of its box
  252.   \vsize=\pageheight \advance\vsize by -\ht\sbox % the remaining height
  253.   \hsize=.5\pagewidth \advance\hsize by -10pt
  254.     % column width for the index (20pt between cols)
  255.   \parfillskip 0pt plus .6\hsize % try to avoid almost empty lines
  256.   \def\lr{L} % this tells whether the left or right column is next
  257.   \output{\if L\lr\global\setbox\lbox=\page \gdef\lr{R}
  258.     \else\normaloutput{\vbox to\pageheight{\box\sbox\vss
  259.         \hbox to\pagewidth{\box\lbox\hfil\page}}}\lheader\rheader
  260.     \global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
  261.   \message{Index:}
  262.   \parskip 0pt plus .5pt
  263.   \outer\def\I##1, {\par\hangindent2em\noindent##1:\kern1em} % index entry
  264.   \def\[##1]{$\underline{##1}$} % underlined index item
  265.   \rm \rightskip0pt plus 2.5em \tolerance 10000 \let\*=\lapstar
  266.   \hyphenpenalty 10000 \parindent0pt
  267.   \readindex}
  268. \def\fin{\par\vfill\eject % this is done when we are ending the index
  269.   \ifpagesaved\null\vfill\eject\fi % output a null index column
  270.   \if L\lr\else\null\vfill\eject\fi % finish the current page
  271.   \parfillskip 0pt plus 1fil
  272.   \def\grouptitle{NAMES OF THE SECTIONS}
  273.   \let\topsecno=\nullsec
  274.   \message{Section names:}
  275.   \output={\normaloutput\page\lheader\rheader}
  276.   \setpage
  277.   \def\note##1##2.{\quad{\eightrm##1~##2.}}
  278.   \def\Q{\note{Cited in section}} % crossref for mention of a section
  279.   \def\Qs{\note{Cited in sections}} % crossref for mentions of a section
  280.   \def\U{\note{Used in section}} % crossref for use of a section
  281.   \def\Us{\note{Used in sections}} % crossref for uses of a section
  282.   \def\I{\par\hangindent 2em}\let\*=*
  283.   \readsections}
  284. \def\con{\par\vfill\eject % finish the section names
  285. % \ifodd\pageno\else\titletrue\null\vfill\eject\fi % for duplex printers
  286.   \rightskip 0pt \hyphenpenalty 50 \tolerance 200
  287.   \setpage \output={\normaloutput\page\lheader\rheader}
  288.   \titletrue % prepare to output the table of contents
  289.   \pageno=\contentspagenumber
  290.   \def\grouptitle{TABLE OF CONTENTS}
  291.   \message{Table of contents:}
  292.   \topofcontents
  293.   \line{\hfil Section\hbox to3em{\hss Page}}
  294.   \let\ZZ=\contentsline
  295.   \readcontents\relax % read the contents info
  296.   \botofcontents \end} % print the contents page(s) and terminate
  297. \def\contentsline#1#2#3#4{\ifnum#2=0 \smallbreak\fi
  298.     \line{\consetup{#2}#1
  299.       \rm\leaders\hbox to .5em{.\hfil}\hfil\ #3\hbox to3em{\hss#4}}}
  300. \def\consetup#1{\ifcase#1 \bf % depth -1 (@**)
  301.   \or % depth 0 (@*)
  302.   \or \hskip2em % depth 1 (@*1)
  303.   \or \hskip4em % depth 2 (@*2)
  304.   \or \hskip6em % depth 3 (@*3)
  305.   \or \hskip8em % depth 4 (@*4)
  306.   \or \hskip10em % depth 5 (@*5)
  307.   \else \hskip12em \fi} % depth 6 or more
  308. \def\noinx{\let\inx=\end} % no indexes or table of contents
  309. \def\nosecs{\let\FIN=\fin \def\fin{\let\parfillskip=\end \FIN}}
  310.     % no index of section names or table of contents
  311. \def\nocon{\let\con=\end} % no table of contents
  312. \def\today{\ifcase\month\or
  313.   January\or February\or March\or April\or May\or June\or
  314.   July\or August\or September\or October\or November\or December\fi
  315.   \space\number\day, \number\year}
  316. \newcount\twodigits
  317. \def\hours{\twodigits=\time \divide\twodigits by 60 \printtwodigits
  318.   \multiply\twodigits by-60 \advance\twodigits by\time :\printtwodigits}
  319. \def\gobbleone1{}
  320. \def\printtwodigits{\advance\twodigits100
  321.   \expandafter\gobbleone\number\twodigits
  322.   \advance\twodigits-100 }
  323. \def\TeX{{\ifmmode\it\fi
  324.    \leavevmode\hbox{T\kern-.1667em\lower.424ex\hbox{E}\hskip-.125em X}}}
  325. \def\,{\relax\ifmmode\mskip\thinmuskip\else\thinspace\fi}
  326. \def\datethis{\def\startsection{\leftline{\sc\today\ at \hours}\bigskip
  327.   \let\startsection=\stsec\stsec}}
  328.   % say `\datethis' in limbo, to get your listing timestamped before section 1
  329. \def\datecontentspage{%
  330.   \def\topofcontents{\leftline{\sc\today\ at \hours}\bigskip
  331.    \centerline{\titlefont\title}\vfill}} % timestamps the contents page
  332.