home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / dev / misc / cweb / macros / cwebmac.tex (.txt) < prev    next >
LaTeX Document  |  1993-12-21  |  15KB  |  316 lines

  1. % standard macros for CWEB listings (in addition to plain.tex)
  2. % Version 3.0 --- June 1993
  3. \ifx\documentstyle\undefined\else\endinput\fi % LaTeX will use other macros
  4. \xdef\fmtversion{\fmtversion+CWEB3.0}
  5. \let\:=\. % preserve a way to get the dot accent
  6.  % (all other accents will still work as usual)
  7. \parskip 0pt % no stretch between paragraphs
  8. \parindent 1em % for paragraphs and for the first line of C text
  9. \font\ninerm=cmr9
  10. \let\mc=\ninerm % medium caps
  11. \def\CEE/{{\mc C\spacefactor1000}}
  12. \def\UNIX/{{\mc U\kern-.05emNIX\spacefactor1000}}
  13. \def\TEX/{\TeX}
  14. \def\CPLUSPLUS/{{\mc C\PP\spacefactor1000}}
  15. \def\Cee{\CEE/} % for backward compatibility
  16. \def\9#1{}
  17. \font\eightrm=cmr8
  18. \let\sc=\eightrm % small caps (NOT a caps-and-small-caps font)
  19. \let\mainfont=\tenrm
  20. \let\cmntfont\tenrm
  21. %\font\tenss=cmss10 \let\cmntfont\tenss % alternative comment font
  22. \font\titlefont=cmr7 scaled\magstep4 % title on the contents page
  23. \font\ttitlefont=cmtt10 scaled\magstep2 % typewriter type in title
  24. \font\tentex=cmtex10 % TeX extended character set (used in strings)
  25. \fontdimen7\tentex=0pt % no double space after sentences
  26. \def\\#1{\leavevmode\hbox{\it#1\/\kern.05em}} % italic type for identifiers
  27. \def\|#1{\leavevmode\hbox{$#1$}} % one-letter identifiers look better this way
  28. \def\{\leavevmode\hbox{\bf
  29.   \def\_{\kern.04em\vbox{\hrule width.3em height .6pt}\kern.08em}%
  30.   #1\/\kern.05em}} % boldface type for reserved words
  31. \def\.#1{\leavevmode\hbox{\tentex % typewriter type for strings
  32.   \let\\=\BS % backslash in a string
  33.   \let\{=\LB % left brace in a string
  34.   \let\}=\RB % right brace in a string
  35.   \let\~=\TL % tilde in a string
  36.   \let\ =\SP % space in a string
  37.   \let\_=\UL % underline in a string
  38.   \let\&=\AM % ampersand in a string
  39.   \let\^=\CF % circumflex in a string
  40.   #1\kern.05em}}
  41. \def\){\discretionary{\hbox{\tentex\BS}}{}{}}
  42. \def\AT{@} % at sign for control text (not needed in versions >= 2.9)
  43. \def\ATL{\par\noindent\bgroup\catcode`\_=12 \postATL} % print @l in limbo
  44. \def\postATL#1 #2 {\bf letter \\{\uppercase{\char"#1}}
  45.    tangles as \tentex "#2"\egroup\par}
  46. \def\noATL#1 #2 {}
  47. \def\noatl{\let\ATL=\noATL} % suppress output from @l
  48. \def\ATH{\X\kern-.5em:Preprocessor definitions\X}
  49. \let\PB=\relax % hook for program brackets |...| in TeX part or section name
  50. \chardef\AM=`\& % ampersand character in a string
  51. \chardef\BS=`\\ % backslash in a string
  52. \chardef\LB=`\{ % left brace in a string
  53. \chardef\RB=`\} % right brace in a string
  54. \def\SP{{\tt\char`\ }} % (visible) space in a string
  55. \chardef\TL=`\~ % tilde in a string
  56. \chardef\UL=`\_ % underline character in a string
  57. \chardef\CF=`\^ % circumflex character in a string
  58. \newbox\PPbox % symbol for ++
  59. \setbox\PPbox=\hbox{\kern.5pt\raise1pt\hbox{\sevenrm+\kern-1pt+}\kern.5pt}
  60. \def\PP{\copy\PPbox}
  61. \newbox\MMbox \setbox\MMbox=\hbox{\kern.5pt\raise1pt\hbox{\sevensy\char0
  62.  \kern-1pt\char0}\kern.5pt}
  63. \def\MM{\copy\MMbox}
  64. \newbox\MGbox % symbol for ->
  65. \setbox\MGbox=\hbox{\kern-2pt\lower3pt\hbox{\teni\char'176}\kern1pt}
  66. \def\MG{\copy\MGbox}
  67. \def\MRL#1{\mathrel{\let\K==#1}}
  68. %\def\MRL#1{\KK#1}\def\KK#1#2{\buildrel\;#1\over{#2}}
  69. \let\GG=\gg
  70. \let\LL=\ll
  71. \let\NULL=\Lambda
  72. \mathchardef\AND="2026 % bitwise and; also \& (unary operator)
  73. \let\OR=\mid % bitwise or
  74. \let\XOR=\oplus % bitwise exclusive or
  75. \def\CM{{\sim}} % bitwise complement
  76. \newbox\MODbox \setbox\MODbox=\hbox{\eightrm\%}
  77. \def\MOD{\mathbin{\copy\MODbox}}
  78. \def\DC{\kern.1em{::}\kern.1em} % symbol for ::
  79. \def\PA{\mathbin{.*}} % symbol for .*
  80. \def\MGA{\mathbin{\MG*}} % symbol for ->*
  81. \def\this{\&{this}}
  82. \newbox\bak \setbox\bak=\hbox to -1em{} % backspace one em
  83. \newbox\bakk\setbox\bakk=\hbox to -2em{} % backspace two ems
  84. \newcount\ind % current indentation in ems
  85. \def\1{\global\advance\ind by1\hangindent\ind em} % indent one more notch
  86. \def\2{\global\advance\ind by-1} % indent one less notch
  87. \def\3#1{\hfil\penalty#10\hfilneg} % optional break within a statement
  88. \def\4{\copy\bak} % backspace one notch
  89. \def\5{\hfil\penalty-1\hfilneg\kern2.5em\copy\bakk\ignorespaces}% optional break
  90. \def\6{\ifmmode\else\par % forced break
  91.   \hangindent\ind em\noindent\kern\ind em\copy\bakk\ignorespaces\fi}
  92. \def\7{\Y\6} % forced break and a little extra space
  93. \def\8{\hskip-\ind em\hskip 2em} % no indentation
  94. \newcount\gdepth % depth of current major group, plus one
  95. \newcount\secpagedepth
  96. \secpagedepth=3 % page breaks will occur for depths -1, 0, and 1
  97. \newtoks\gtitle % title of current major group
  98. \newskip\intersecskip \intersecskip=12pt minus 3pt % space between sections
  99. \let\yskip=\smallskip
  100. \def\?{\mathrel?}
  101. \def\note#1#2.{\Y\noindent{\hangindent2em\baselineskip10pt\eightrm#1~#2.\par}}
  102. \def\lapstar{\rlap{*}}
  103. \def\stsec{\rightskip=0pt % get out of C mode (cf. \B)
  104.   \sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50
  105.   \noindent{\let\*=\lapstar\bf\secstar.\quad}}
  106. \let\startsection=\stsec
  107. \def\defin#1{\global\advance\ind by 2 \1\&{#1 } } % begin `define' or `format'
  108. \def\A{\note{See also section}} % xref for doubly defined section name
  109. \def\As{\note{See also sections}} % xref for multiply defined section name
  110. \def\B{\rightskip=0pt plus 100pt minus 10pt % go into C mode
  111.   \sfcode`;=3000
  112.   \pretolerance 10000
  113.   \hyphenpenalty 9999 % so strings can be broken (discretionary \ is inserted)
  114.   \exhyphenpenalty 10000
  115.   \global\ind=2 \1\ \unskip}
  116. \def\C#1{\5\5\quad$/\ast\,${\cmntfont #1}$\,\ast/$}
  117. \let\SHC\C % "// short comments" treated like "/* ordinary comments */"
  118. %\def\C#1{\5\5\quad$\triangleright\,${\cmntfont#1}$\,\triangleleft$}
  119. %\def\SHC#1{\5\5\quad$\diamond\,${\cmntfont#1}}
  120. \def\D{\defin{\#define}} % macro definition
  121. \let\E=\equiv % equivalence sign
  122. \def\ET{ and~} % conjunction between two section numbers
  123. \def\ETs{, and~} % conjunction between the last two of several section numbers
  124. \def\F{\defin{format}} % format definition
  125. \let\G=\ge % greater than or equal sign
  126. % \H is long Hungarian umlaut accent
  127. \let\I=\ne % unequal sign
  128. \def\J{\.{@\&}} % TANGLE's join operation
  129. \let\K== % assignment operator
  130. %\let\K=\leftarrow % "honest" alternative to standard assignment operator
  131. % \L is Polish letter suppressed-L
  132. \outer\def\M#1{\MN{#1}\ifon\vfil\penalty-100\vfilneg % beginning of section
  133.   \vskip\intersecskip\startsection\ignorespaces}
  134. \outer\def\N#1#2#3.{\gdepth=#1\gtitle={#3}\MN{#2}% beginning of starred section
  135.   \ifon\ifnum#1<\secpagedepth \vfil\eject % force page break if depth is small
  136.     \else\vfil\penalty-100\vfilneg\vskip\intersecskip\fi\fi
  137.   \message{*\secno} % progress report
  138.   \edef\next{\write\cont{\ZZ{#3}{#1}{\secno}% write to contents file
  139.                    {\noexpand\the\pageno}}}\next % \ZZ{title}{depth}{sec}{page}
  140.   \ifon\startsection{\bf#3.\quad}\ignorespaces}
  141. \def\MN#1{\par % common code for \M, \N
  142.   {\xdef\secstar{#1}\let\*=\empty\xdef\secno{#1}}% remove \* from section name
  143.   \ifx\secno\secstar \onmaybe \else\ontrue \fi
  144.   \mark{{{\tensy x}\secno}{\the\gdepth}{\the\gtitle}}}
  145. % each \mark is {section reference or null}{depth plus 1}{group title}
  146. % \O is Scandinavian letter O-with-slash
  147. % \P is paragraph sign
  148. \def\Q{\note{This code is cited in section}} % xref for mention of a section
  149. \def\Qs{\note{This code is cited in sections}} % xref for mentions of a section
  150. \let\R=\lnot % logical not
  151. % \S is section sign
  152. \def\T#1{\leavevmode % octal, hex or decimal constant
  153.   \hbox{$\def\?{\kern.2em}%
  154.     \def\$##1{\egroup_{\,\rm##1}\bgroup}% suffix to constant
  155.     \def\_{\cdot 10^{\aftergroup}}% power of ten (via dirty trick)
  156.     \let\~=\oct \let\^=\hex {#1}$}}
  157. \def\U{\note{This code is used in section}} % xref for use of a section
  158. \def\Us{\note{This code is used in sections}} % xref for uses of a section
  159. \let\V=\lor % logical or
  160. \let\W=\land % logical and
  161. \def\X#1:#2\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi % section name
  162.   \XX$\langle\,${#2\eightrm\kern.5em#1}$\,\rangle$\XX}
  163. \def\Y{\par\yskip}
  164. \let\Z=\le
  165. \let\ZZ=\let % now you can \write the control sequence \ZZ
  166. \let\*=*
  167. %\def\oct{\hbox{\rm\char'23\kern-.2em\it\aftergroup\?\aftergroup}} % WEB style
  168. %\def\hex{\hbox{\rm\char"7D\tt\aftergroup}} % WEB style
  169. \def\oct{\hbox{$^\circ$\kern-.1em\it\aftergroup\?\aftergroup}}% CWEB style
  170. \def\hex{\hbox{$^{\scriptscriptstyle\#}$\tt\aftergroup}} % CWEB style
  171. \def\vb#1{\leavevmode\