home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cweb28.zip / cwebmac.tex < prev    next >
Text File  |  1992-10-03  |  12KB  |  266 lines

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