X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/1818107e8198734df843841a51bca3713bd37596..7f9f8b0729bcbe8da67957d56ea2dace7fd12bad:/doc/sod.sty diff --git a/doc/sod.sty b/doc/sod.sty index 56fc726..0452348 100644 --- a/doc/sod.sty +++ b/doc/sod.sty @@ -7,7 +7,7 @@ %%%----- Licensing notice --------------------------------------------------- %%% -%%% This file is part of the Sensble Object Design, an object system for C. +%%% This file is part of the Sensible Object Design, an object system for C. %%% %%% SOD is free software; you can redistribute it and/or modify %%% it under the terms of the GNU General Public License as published by @@ -28,6 +28,8 @@ %% More reference types. \defxref{p}{part} +\def\instead#1#2{#1} + %% Other languages with special typesetting. \def\Cplusplus{C\kern-\p@++} \def\Csharp{C\#} @@ -57,15 +59,28 @@ %% Listings don't need to be small. \let\listingsize\relax +%% Notes for later. +\def\fixme#1{\leavevmode\marginpar{FIXME}\index{FIXME}[FIXME: #1]} + +%% Diagram settings. +\tikzset{ + every picture/.style={>=stealth, thick}, + lit/.style={font=\sffamily} +} + %% Metavariables are italics without decoration. \def\syntleft{\normalfont\itshape} \let\syntright\empty %% Literal code is in sans face. -\let\codeface\sffamily -\def\code#1{\ifmmode\hbox\fi{\normalfont\codeface\/#1\/}} +\def\codeface{\upshape\sffamily} +\DeclareRobustCommand\code[1]{% + \ifmmode\hbox\else\leavevmode\fi% + {\normalfont\codeface\/#1\/}% +} \def\ulitleft{\normalfont\codeface} \let\ulitright\empty +\def\lit@i#1#2#3{\ifmmode\leavevmode\hbox\fi{#1{#3\/}#2}} %% Conditionally enter maths mode. Can't use \ensuremath here because we %% aren't necessarily sure where the maths will actually end. @@ -76,7 +91,7 @@ \atdef <#1>{\synt{#1}\@scripts} \atdef "#1"{\lit*{#1}\@scripts} \atdef `#1'{\lit{#1}\@scripts} -\atdef |#1|{\textsf{#1}\@scripts} +\atdef |#1|{\lit*{#1}\@scripts} %% A handy abbreviation; `\\' itself is too good to steal. \atdef \\{\textbackslash} @@ -113,17 +128,44 @@ \atdef !{\m@maybe|\@scripts} \def\returns{\m@maybe\longrightarrow\m@maybe@end\hspace{0.5em}\ignorespaces} \atdef >{\leavevmode\unskip\hspace{0.5em}\returns} -\atdef -#1{\if>#1{\ensuremath\rightarrow}\fi} +\atdef -#1{\if>#1\hbox{--\raisebox{.4pt}{>}}\penalty200\relax\fi} %% Comment setting. -\atdef ;#1\\{\normalfont\itshape;#1\\} +\def\comment#1{\mbox{\normalfont\itshape\/#1\/}} +\atdef /*#1*/{/*\comment{#1}*/} +\def\@semis{\@ifnextchar;{;\@semis}\@semicomment} +\def\@semicomment#1\\{\comment{#1}\\} +\atdef ;#1\\{;\@semis} %% Environment for setting programs. Newlines are explicit, because %% otherwise I need comments in weird places to make the vertical spacing %% come out properly. You can write `\obeylines' if you really want to. -\def\prog{\codeface\quote\tabbing} +\def\@prog{\let\prog@@cr\@tabcr\let\@tabcr\@progcr\codeface\tabbing} +\def\prog{\quote\@prog} \def\endprog{\endtabbing\endquote} +\let\nprog\@prog +\let\endnprog\endtabbing \def\ind{\quad\=\+\kill} +\def\@progcr{\futurelet\@tempa\@progcr@i} +{\def\:{\gdef\@progcr@sp}\: {\@progcr}} +\atdef~{\textasciitilde} +\def\@progcr@i{% + \ifx\@tempa\@sptoken\let\next@\@progcr@sp\else + \if1\ifx\@tempa[1\else + \ifx\@tempa*1\else + 0\fi\fi + \let\next@\prog@@cr\else + \if1\ifx\@tempa+1\else + \ifx\@tempa-1\else + 0\fi\fi + \let\next@\@progcr@ii\else + \let\next@\@progcr@a\fi\fi\fi + \next@} +\def\@progcr@a{\prog@@cr*{}\ignorespaces} +\def\@progcr@ii#1{\csname @progcr@#1\endcsname\ignorespaces} +\@namedef{@progcr@+}{\prog@@cr[\medskipamount]} +\@namedef{@progcr@-}{\prog@@cr*[\jot]} +\def\macsl{\`\textbackslash\hskip\leftmargin} %% Put a chunk of text in a box. \newenvironment{boxy}[1][\q@]{% @@ -141,65 +183,217 @@ } %% Lisp documentation machinery. -\def\definedescribecategory#1#2{\@namedef{cat!#1}{#2}} -\def\describecategoryname#1{% - \expandafter\let\expandafter\@tempa\csname cat!#1\endcsname% - \ifx\@tempa\relax#1\else\@tempa\fi} +\def\definedescribecategory#1{% + \@ifnextchar[{\def@desc{#1}}{\def@desc{#1}[plain]}} +\def\def@desc#1[#2]#3{\@namedef{cat!#1}##1{#3}\@namedef{catsw!#1}{#2}} +\def\describecategoryname{\@ifnextchar[\@descname@i{\@descname@i[]}} +\def\@descname@i[#1]#2{% + \expandafter\let\expandafter\@tempa\csname cat!#2\endcsname% + \expandafter\let\expandafter\@tempb\csname modcat/#1\endcsname% + \ifx\@tempa\relax\@tempb{#2}\else\@tempa\@tempb\fi} +\def\@mod@dispatch#1#2{\csname #1/#2\endcsname} +\def\@desc@dispatch#1#2{% + \csname #1/% + \expandafter\ifx\csname catsw!#2\endcsname\relax plain% + \else \csname catsw!#2\endcsname \fi% + \endcsname% +} + \definedescribecategory{sym}{symbol} -\definedescribecategory{fun}{function} -\definedescribecategory{gf}{generic function} +\definedescribecategory{fun}{#1{function}} +\definedescribecategory{gf}{generic #1{function}} +\definedescribecategory{msg}{message} \definedescribecategory{var}{variable} +\definedescribecategory{modvar}{module variable} \definedescribecategory{const}{constant} -\definedescribecategory{meth}{primary method} -\definedescribecategory{ar-meth}{around method} -\definedescribecategory{be-meth}{before method} -\definedescribecategory{af-meth}{after method} +\definedescribecategory{meth}[method]{primary #1{method}} +\definedescribecategory{ar-meth}[method]{\code{:around} #1{method}} +\definedescribecategory{be-meth}[method]{\code{:before} #1{method}} +\definedescribecategory{af-meth}[method]{\code{:after} #1{method}} \definedescribecategory{cls}{class} +\definedescribecategory{rst}{restart} \definedescribecategory{ty}{type} -\definedescribecategory{mac}{macro} -\definedescribecategory{lmac}{local macro} +\definedescribecategory{type}{type} +\definedescribecategory{mac}{#1{macro}} +\definedescribecategory{lmac}{local #1{macro}} \definedescribecategory{parse}{parser spec} \definedescribecategory{parseform}{parser form} \definedescribecategory{opt}{option handler} \definedescribecategory{optmac}{option macro} +\definedescribecategory{plug}{pluggable parser} \def\nlret{\\\hspace{4em}\returns} +\@namedef{modcat/}#1{#1} +\@namedef{modlabel/}#1{#1} +\@namedef{modindex/}#1{#1@\noexpand\code{#1}} + +\@namedef{modcat/setf}#1{\code{setf}-#1} +\@namedef{modlabel/setf}#1{setf/#1} +\@namedef{modindex/setf}#1{#1@\noexpand\code{#1}} + +\@namedef{modcat/muffs}#1{#1} +\@namedef{modlabel/muffs}#1{*#1*} +\@namedef{modindex/muffs}#1{#1@\noexpand\code{*#1*}} + +\@namedef{modcat/kwd}#1{#1} +\@namedef{modlabel/kwd}#1{:#1} +\@namedef{modindex/kwd}#1{#1@\noexpand\code{:#1}} + +\@namedef{descargs/plain}#1{#1{}} +\@namedef{desclabel/plain}#1#2#3{#1:\@mod@dispatch{modlabel}{#2}{#3}} +\@namedef{descindex/plain}#1#2#3{% + \@mod@dispatch{modindex}{#2}{#3}!% + \protect\describecategoryname[#2]{#1}% +} + +\@namedef{descargs/method}#1#2{#1{{#2}}} +\@namedef{desclabel/method}#1#2#3#4% + {#1:\@mod@dispatch{modlabel}{#2}{#3}(#4)} +\@namedef{descindex/method}#1#2#3#4{% + \@mod@dispatch{modindex}{#2}{#3}!% + \protect\describecategoryname[#2]{#1}% + \protect\fmtspecs{ specialized at }{#4}% +} + \def\q@{\q@} -\def\parse@dhd#1{\@ifnextchar[{\parse@dhd@a{#1}}{\parse@dhd@c{#1}}} -\def\parse@dhd@a#1[#2]{#1{#2}} -\def\parse@dhd@c#1#2#3{\parse@dhd@cc{#1}{#2}{#3}#3 \q@} -\def\parse@dhd@cc#1#2#3#4 #5\q@{#1{#4}{#2}{#3}} +\def\@setf{setf} + +\def\fmtspecs#1#2{% + \if!#2!\else\count@\z@\toks@{}#1\@fmtspecs@i#2,\q@,\fi} +\def\@fmtspecs@i#1,{% + \def\@tempa{#1}% + \ifx\@tempa\q@% + \ifcase\count@(no args?!)% + \or% nothin' doin + \or \space and % + \else, and % + \fi% + \the\toks@% + \else% + \ifnum\count@>\@ne, \fi% + \the\toks@% + \toks@{\code{#1}}\advance\count@\@ne% + \expandafter\@fmtspecs@i% + \fi% +} + +%% \parse@dhd{NEXT}[MOD]{CAT}{...}...[NAME]{SYNOPSIS} +%% call NEXT{MOD}{CAT}{{...}...}{NAME}{SYNOPSIS} +%% #1 #2 #3 #4 #5 +\def\@setf{setf} +\def\@starstar{**} +\def\parse@dhd#1{% {NEXT} + \@ifnextchar[{\parse@dhd@a{#1}}{\parse@dhd@c{#1}}} +\def\parse@dhd@a#1[#2]#3{% {NEXT}[MOD]{CAT} + \@desc@dispatch{descargs}{#3}{\parse@dhd@ab{#1}{#2}{#3}}} +\def\parse@dhd@ab#1#2#3#4{% {NEXT}{MOD}{CAT}{{...}...} + \@ifnextchar[{\parse@dhd@ac{#1}{#2}{#3}{#4}}{\parse@dhd@ad{#1}{#2}{#3}{#4}}} +\def\parse@dhd@ac#1#2#3#4[#5]#6{% {NEXT}{MOD}{CAT}{{...}...}[NAME]{SYNOPSIS} + #1{#2}{#3}{#4}{#5}{#6}} +\def\parse@dhd@ad#1#2#3#4#5{% {NEXT}{MOD}{CAT}{{...}...}{NAME [ARGS...]} + \parse@dhd@ae{#1}{#2}{#3}{#4}{#5}#5 \q@} +\def\parse@dhd@ae#1#2#3#4#5#6 #7\q@{% + % {NEXT}{MOD}{CAT}{{...}...}{SYNSOPSIS}NAME [ARGS...]\q@ + #1{#2}{#3}{#4}{#6}{#5}} + +\def\parse@dhd@c#1#2{% {NEXT}{CAT} + \@desc@dispatch{descargs}{#2}{\parse@dhd@cb{#1}{#2}}} +\def\parse@dhd@cb#1#2#3{% {NEXT}{CAT}{{...}...} + \@ifnextchar[{\parse@dhd@cc{#1}{#2}{#3}}{\parse@dhd@cd{#1}{#2}{#3}}} +\def\parse@dhd@cc#1#2#3[#4]#5{% {NEXT}{CAT}{{...}...}[NAME]{SYNOPSIS} + #1{}{#2}{#3}{#4}{#5}} +\def\parse@dhd@cd#1#2#3#4{% {NEXT}{CAT}{{...}...}{SYNOPSIS} + \parse@dhd@ce{#1}{#2}{#3}{#4}#4 \q@} +\def\parse@dhd@ce#1#2#3#4#5 #6\q@{% + % {NEXT}{CAT}{{...}...}{SYNOPSIS}NAME [ARGS...]\q@ + \def\temp@{#5}% + \ifx\@setf\temp@\def\next@{\parse@dhd@csetf{#1}{#2}{#3}{#4}#6 \q@}% + \else\def\temp@##1##2*##3\q@{\def\temp@{##1##3}}\temp@#5*\q@% + \ifx\temp@\@starstar\def\next@{\parse@dhd@cmuffs{#1}{#2}{#3}{#4}#5}% + \else\def\temp@##1##2\q@{\def\temp@{##1}}\temp@#5\q@% + \if:\temp@\def\next@{\parse@dhd@ckwd{#1}{#2}{#3}{#4}#5\q@}% + \else\def\next@{#1{}{#2}{#3}{#5}{#4}}\fi\fi\fi% + \next@% +} +\def\parse@dhd@csetf#1#2#3#4(#5 #6\q@{% + % {NEXT}{CAT}{{...}...}{SYNOPSIS}(NAME [ARGS...])\q@ + #1{setf}{#2}{#3}{#5}{#4}} +\def\parse@dhd@cmuffs#1#2#3#4*#5*{% + % {NEXT}{CAT}{{...}...}{SYNOPSIS}*NAME* + #1{muffs}{#2}{#3}{#5}{#4}} +\def\parse@dhd@ckwd#1#2#3#4:#5\q@{% + % {NEXT}{CAT}{{...}...}{SYNOPSIS}:NAME\q@ + #1{kwd}{#2}{#3}{#5}{#4}} \newif\if@dheadfirst \def\dhead{\parse@dhd\dhead@} -\def\dhead@#1#2#3{% - \if@dheadfirst\global\@dheadfirstfalse\else\relax\\[\smallskipamount]\fi% - {\let\protect\@empty\def\@uscore{_\@gobble}\message{#2:#1}% - \def\@uscore{-\@gobble}\edef\@tempa{\noexpand\label{#2:#1}}\@tempa}% - \rlap{\rightline{\normalfont\bfseries[\describecategoryname{#2}]}}% - #3% +\def\dhead@#1#2#3#4#5{% {MOD}{CAT}{{...}...}{NAME}{SYNOPSIS} + \if@dheadfirst\global\@dheadfirstfalse\else\relax\\*[\smallskipamount]\fi% + \phantomsection% + {\let\protect\@empty\let\@uscore\relax% + \edef\temp@{\@desc@dispatch{desclabel}{#2}{#2}{#1}{#4}#3}% + \def\@uscore{_\@gobble}\expandafter\message\expandafter{\temp@}% + \def\@uscore{-\@gobble}\expandafter\label\expandafter{\temp@}}% + {\begingroup\lccode`\~=`\_\lowercase{\endgroup\def~{_}}% + \protected@edef\@tempa##1{% + \noexpand\index{\@desc@dispatch{descindex}{#2}{#2}{#1}{#4}#3##1}}% + \toks@\expandafter{\@tempa{|)}}% + \toks\tw@\expandafter{\after@desc}% + \xdef\after@desc{\the\toks\tw@\the\toks@}% + \@tempa{|(}}% + \rlap{\hb@xt@\linewidth{\hfil\normalfont\bfseries + [\describecategoryname[#1]{#2}]}}% + #5% } \def\desc@begin#1{% + \let\saved@after@desc\after@desc% + \gdef\after@desc{}% \normalfont% \if@nobreak\else\par\goodbreak\fi% \global\@dheadfirsttrue% \begingroup% - \codeface% \let\@endparenv\relax% \clubpenalty\@M \widowpenalty\@M \interlinepenalty50% - \tabbing#1\endtabbing% + \@prog#1\endtabbing% \endgroup% \penalty\@M\@afterheading% \list{}{\rightmargin\z@\topsep\z@}\item% } -\let\desc@end\endlist +\def\desc@end{\endlist\after@desc\global\let\after@desc\saved@after@desc} + +\def\@ifnextchar@preserve#1#2#3{% + \let\want@= #1\def\@tempa{#2}\def\@tempb{#3}% + \futurelet\nch@\@ifnch@p% +} +\def\@ifnch@p{% + \ifx\want@\nch@\expandafter\@tempa\else\expandafter\@tempb\fi} \@namedef{describe*}#1{\desc@begin{#1}} \expandafter\let\csname enddescribe*\endcsname\desc@end \def\describe{\parse@dhd\desc@} -\def\desc@#1#2#3{\desc@begin{\dhead@{#1}{#2}{#3}}} +\def\desc@#1#2#3#4#5{\desc@begin{\dhead@{#1}{#2}{#3}{#4}{#5}}} \let\enddescribe\desc@end +\def\descref{\@ifstar% + {\descref@i{}\@gobble{}}% + {\descref@i{ (}{\noexpand\autopageref}{)}}} +\def\descref@i#1#2#3#4#5{\@ifnextchar@preserve[% + {\descref@ii{#1}{#2}{#3}{#4}{#5}}% + {\descref@iii{#1}{#2}{#3}{#4}{#5}{}}} +\def\descref@ii#1#2#3#4#5[#6]{\descref@iii{#1}{#2}{#3}{#4}{#5}{ #6}} +\def\descref@iii#1#2#3#4#5#6{% + \begingroup% + \let\protect\@empty% + \def\@uscore{-\@gobble}% + \edef\@tempa##1{% + \endgroup% + \noexpand\hyperref[#4:#5]% + ##1% + #2{#4:#5}% + }% + \@tempa{{\code{#5}}#6#1}#3% +} + %%%----- That's all, folks -------------------------------------------------- \endinput