Skip to content

Commit

Permalink
CWEB — release 4.8.1, 2022-06-26.
Browse files Browse the repository at this point in the history
(1) Use iftex.sty to test TeX engine in use.

iftex.sty sets \ifpdf according to \pdfoutput.  This can be set _before_
'\input cwebmac'.

Note that you can _not_ use 'pdftex "\let\pdf+\pdfoutput=0\input ..."',
because \ifpdftex is always 'true' for PDFTeX.

(2) NOS has 'count \I' subentries. This helps to produce 'valid' PDF.

(3) HINT has infinite space, so we can also show TeX code for section 31.
  • Loading branch information
ascherer committed Jun 26, 2022
1 parent 837f017 commit 95545f0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 38 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,8 @@ tarfile: $(ALL) examples

tarball:
tar zcvhf /tmp/cweb.tgz $(ALL) examples

ctan:
git archive -o ~/cweb-4.8.1.zip --prefix=cweb/ cweb-4.8.1
make PDF=pdf usermanual
cd ..; zip -r ~/cweb-4.8.1.zip cweb/cwebman.pdf
71 changes: 35 additions & 36 deletions cwebmac.tex
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
% standard macros for CWEB listings (in addition to plain.tex)
% Version 4.8--- June 2022
% Version 4.9 --- June 2022
\ifx\renewenvironment\undefined\else\endinput\fi % LaTeX will use other macros
\xdef\fmtversion{\fmtversion+CWEB4.8}
\chardef\cwebversion=4 \chardef\cwebrevision=7
\newif\ifpdf
\ifx\pdf+\pdftrue\fi
\xdef\fmtversion{\fmtversion+CWEB4.9}
\chardef\cwebversion=4 \chardef\cwebrevision=9
\input iftex.sty % TeX engine tests
\ifx\pdf+\pdftrue\fi % for plain TeX in combination with dvipdfm
% Uncomment the following line if you want PDF goodies to be the default
%\ifx\pdf-\else\pdftrue\fi
\def\pdflinkcolor{0 0 1} % the RGB values for hyperlink color
\ifx\undefined\XeTeXrevision\else\pdftrue\fi % XeTeX produces PDF output
\newif\ifpdftex
\ifx\pdfoutput\undefined \pdftexfalse \else\ifnum\pdfoutput=0 \pdftexfalse
%\else \pdftextrue \pdfoutput=1 \input pdfcolor \let\setcolor\pdfsetcolor \fi\fi
\else \pdftextrue \pdfoutput=1 % changed in 3.69
\ifxetex\pdftrue\fi % XeTeX produces PDF output
\ifpdftex % pdfTeX produces PDF output if \pdfoutput>0
\def\Black{\pdfliteral{0 g 0 G}} % use rgb colors for direct PDF output too
\def\Blue{\pdfliteral{\pdflinkcolor\space rg \pdflinkcolor\space RG}}
\fi\fi
\newif\ifhint
\ifx\HINTversion\undefined \hintfalse \else \hinttrue \fi
\newif\ifacro \ifpdf\acrotrue\fi \ifpdftex\acrotrue\fi
\newif\ifacrohint \ifacro\acrohinttrue\fi \ifhint\acrohinttrue\fi
\fi
\newif\ifacrohint \ifpdf\acrohinttrue\fi \ifhint\acrohinttrue\fi

\let\:=\. % preserve a way to get the dot accent
% (all other accents will still work as usual)
Expand Down Expand Up @@ -135,17 +129,17 @@
\newtoks\toksA \newtoks\toksB \newtoks\toksC \newtoks\toksD
\newtoks\toksE \newtoks\toksF \newtoks\usersanitizer
\newcount\countA \countA=0 \newcount\countB \countB=0
\newcount\countC \countC=0
\newcount\countC \countC=0 \newcount\countD \countD=0
\newif\iftokprocessed \newif\ifTnum \newif\ifinstr
{\def\\{\global\let\spacechar= }\\ }

\ifacro % The following are pdf macros
\ifpdf % The following are pdf macros
\def\thewidth{\the\wd0 \space}
\def\theheight{\the\ht\strutbox\space}
\def\thedepth{\the\dp\strutbox\space}
\ifpdftex
\ifx\pdfannotlink\undefined\let\pdfannotlink\pdfstartlink\fi% for pdfTeX 0.14
\def\pdflink#1#2{\hbox{\pdfannotlink height\ht\strutbox depth\dp\strutbox
\def\pdflink#1#2{\hbox{\pdfannotlink height \theheight depth \thedepth
attr{/Border [0 0 0]} goto num #1 \Blue #1\Black\pdfendlink}} % changed 3.69
\else\def\pdflink#1#2{\setbox0=\hbox{\special{pdf: bc [ \pdflinkcolor ]}{#1}%
\special{pdf: ec}}\special{pdf: ann width \thewidth height \theheight
Expand Down Expand Up @@ -267,7 +261,7 @@
\let\pdflink=\HINTlink
\fi % End of HINT macros
% Common macros for \ifacro and \ifhint
% Common macros for \ifpdf and \ifhint
\ifacrohint
\def\pdfnote#1.{\setbox0=\hbox{\toksA={#1.}\toksB={}\maketoks}\the\toksA}
\def\firstsecno#1.{\setbox0=\hbox{\toksA={#1.}\toksB={}%
Expand All @@ -294,14 +288,14 @@
\def\maketoksdone{\edef\st{\global\noexpand\toksA={\the\toksB}}\st}
\fi % End of common macros
\def\pdfURL#1#2{\ifpdftex\pdfannotlink height\ht\strutbox depth\dp\strutbox
attr {/Border [0 0 0]} user { /Type /Action /Subtype /Link /A
\def\pdfURL#1#2{\ifpdf \ifpdftex\pdfannotlink height \theheight depth \thedepth
attr {/Border [0 0 0]} user { /Type /Annot /Subtype /Link /A
<< /S /URI /URI (#2) >>}\Blue #1\Black \pdfendlink % changed in 3.69
\else \ifpdf{\setbox0=\hbox{\special{pdf: bc [ \pdflinkcolor ]}{#1}%
\special{pdf: ec}}\special{pdf: ann width \thewidth\space height \theheight
\space depth \thedepth\space << /Border [0 0 0]
/Type /Action /Subtype /Link /A << /S /URI /URI (#2) >> >>}\box0\relax}%
\else #1 ({\tt#2})\fi\fi}
\else {\setbox0=\hbox{\special{pdf: bc [ \pdflinkcolor ]}{#1}%
\special{pdf: ec}}\special{pdf: ann width \thewidth height \theheight
depth \thedepth << /Border [0 0 0] /Type /Annot /Subtype /Link /A
<< /S /URI /URI (#2) >> >>}\box0\relax}\fi
\else #1 ({\tt#2})\fi}
{\catcode`\~=12 \gdef\TILDE/{~}} % ~ in a URL
{\catcode`\_=12 \gdef\UNDER/{_}} % _ in a URL
Expand All @@ -310,7 +304,7 @@
\sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50
\ifhint\HINTlabel\fi% Start page before section
\noindent{\let\*=\lapstar\bf\secstar.\quad}%
\ifacro \smash{\raise\baselineskip\hbox to0pt{\let\*=\empty
\ifpdf \smash{\raise\baselineskip\hbox to0pt{\let\*=\empty
\ifpdftex \pdfdest num \secstar fith%
\else \special{pdf: dest (\romannumeral\secstar)
[ @thispage /FitH @ypos ]}\fi}}\fi}
Expand Down Expand Up @@ -343,7 +337,7 @@
\outer\def\M#1{\MN{#1}\ifon\vfil\penalty-100\vfilneg % beginning of section
\vskip\intersecskip\startsection\ignorespaces}
\outer\def\N#1#2#3.{% beginning of starred section
\ifacro{\toksF={}\makeoutlinetoks#3\outlinedone\outlinedone}\fi
\ifpdf{\toksF={}\makeoutlinetoks#3\outlinedone\outlinedone}\fi
\gdepth=#1\gtitle={#3}\MN{#2}%
\ifon\ifnum#1<\secpagedepth \vfil\eject % force page break if depth is small
\else\vfil\penalty-100\vfilneg\vskip\intersecskip\fi\fi
Expand All @@ -352,10 +346,10 @@
\edef\gtitletoks{\expandafter\stripprefix\meaning\gtitletoks}%
\edef\next{\write\cont{\ZZ{\gtitletoks}{#1}{\secno}% write to contents file
{\noexpand\the\pageno}{\the\toksE}}}\next % \ZZ{title}{depth}{sec}{page}{ss}
\ifpdftex\expandafter\xdef\csname curr#1\endcsname{\secno}
\ifpdf \ifpdftex\expandafter\xdef\csname curr#1\endcsname{\secno}
\ifnum#1>0\countB=#1 \advance\countB by-1
\advancenumber{chunk\the\countB.\expnumber{curr\the\countB}}\fi\fi
\ifpdf\special{pdf: outline #1 << /Title (\the\toksE) /Dest
\else \special{pdf: outline #1 << /Title (\the\toksE) /Dest
[ @thispage /FitH @ypos ] >>}\fi
\ifon\startsection{\bf#3.\quad}\ignorespaces}
\def\MN#1{\par % common code for \M, \N
Expand Down Expand Up @@ -433,8 +427,8 @@
\def\title{\expandafter\uppercase\expandafter{\jobname}}
\def\topofcontents{\centerline{\titlefont\title}\vskip.7in
\vfill} % this material will start the table of contents page
\def\startpdf{\ifpdftex\pdfcatalog{/PageMode /UseOutlines}\else
\ifpdf{\special{pdf: docview << /PageMode /UseOutlines >>}}\fi\fi}
\def\startpdf{\ifpdf \ifpdftex\pdfcatalog{/PageMode /UseOutlines}
\else {\special{pdf: docview << /PageMode /UseOutlines >>}}\fi\fi}
\def\botofcontents{\vfill
\centerline{\covernote}} % this material will end the table of contents page
\def\covernote{}
Expand Down Expand Up @@ -495,7 +489,8 @@
\def\fin{\par\vfill\eject % this is done when we are ending the index
\ifpagesaved\null\vfill\eject\fi % output a null index column
\if L\lr\else\null\vfill\eject\fi % finish the current page
\ifpdftex \makebookmarks \fi % added in Version 3.68
\ifpdf \ifpdftex \makebookmarks % added in Version 3.68
\countsections \fi\fi % and in Version 4.9
\parfillskip 0pt plus 1fil
\def\grouptitle{NAMES OF THE SECTIONS}
\let\topsecno=\nullsec
Expand All @@ -508,10 +503,10 @@
\def\U{\note{Used in section}} % crossref for use of a section
\def\Us{\note{Used in sections}} % crossref for uses of a section
\def\I{\par\hangindent 2em}\let\*=*
\ifacro \def\outsecname{Names of the sections} \let\Xpdf\X
\ifpdf \def\outsecname{Names of the sections} \let\Xpdf\X
% \ifpdftex \makebookmarks \pdfdest name {NOS} fitb % in versions < 3.68
\ifpdftex \pdfdest name {NOS} fith % changed in version 3.69
\pdfoutline goto name {NOS} count -\secno {\outsecname}
\pdfoutline goto name {NOS} count -\the\countD {\outsecname}
\def\X##1:##2\X{\Xpdf##1:##2\X \firstsecno##1.%
{\toksF={}\makeoutlinetoks##2\outlinedone\outlinedone}%
\pdfoutline goto num \the\toksA \expandafter{\the\toksE}}
Expand All @@ -524,6 +519,10 @@
\fi\fi
\readsections}
\def\makebookmarks{\let\ZZ=\writebookmarkline \readcontents\relax}
\def\countsections{\message{Number of named sections:}
{\def\I{\global\advance\countD by 1}\def\X##1\X{\relax}
\def\Q##1.{\relax}\def\Qs##1.{\relax}\def\U##1.{\relax}\def\Us##1.{\relax}
\readsections\relax}\message{\the\countD}}
\def\expnumber#1{\expandafter\ifx\csname#1\endcsname\relax 0%
\else \csname#1\endcsname \fi} % Petr Olsak's macros from texinfo.tex
\def\advancenumber#1{\countA=\expnumber{#1}\relax \advance\countA by1
Expand Down Expand Up @@ -551,7 +550,7 @@
\ \ifhint
\HINTlink{#3}{\romannumeral#3}% No page numbers in HINT
\HINTcontents{#1}{#2}{#3}%
\else\ifacro\pdflink{#3}{\romannumeral#3}\else#3\fi
\else\ifpdf\pdflink{#3}{\romannumeral#3}\else#3\fi
\hbox to3em{\hss#4}\fi}}
\def\consetup#1{\ifcase#1 \bf % depth -1 (@**)
\or % depth 0 (@*)
Expand Down
13 changes: 11 additions & 2 deletions cwebman.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

\def\tangref{3} % where the main explanation of CTANGLing is given
\input cwebmac
\acrofalse\pdffalse\pdftexfalse\hintfalse\acrohintfalse
\pdffalse\acrohintfalse
\def\page{\box255 } \normalbottom
\parskip 0pt plus 1pt
\def\RA{\char'31 } % right arrow
Expand Down Expand Up @@ -1345,7 +1345,7 @@
\def\runninghead{APPENDIX A --- TRANSLATION BY {\tentt CWEAVE}}

Here is the corresponding excerpt from \.{common.tex}.
(Code for section 31 is omitted for space reasons.)
\ifhint\relax\else(Code for section 31 is omitted for space reasons.)\fi

\vskip6pt
\begingroup \def\tt{\eighttt} \baselineskip9pt
Expand Down Expand Up @@ -1418,6 +1418,15 @@
\4${}\}{}$\2\5
\&{while} ${}(\\{limit}\E\\{buffer}){}$;\par
\U27.\fi
!ifhint
\M{31}\B\X31:Move \PB{\\{buffer}} and \PB{\\{limit}} to \PB{\\{change\_buffer}}
and \PB{\\{change\_limit}}\X${}\E{}$\6
$\\{change\_limit}\K\\{change\_buffer}+(\&{ptrdiff\_t})(\\{limit}-%
\\{buffer});{}$\6
${}\\{strncpy}(\\{change\_buffer},\39\\{buffer},\39(\&{size\_t})(\\{limit}-%
\\{buffer}+\T{1})){}$;\par
\Us27\ET32.\fi
!fi
!endgroup
\endgroup
\vfil\eject
Expand Down

0 comments on commit 95545f0

Please sign in to comment.