summaryrefslogtreecommitdiff
path: root/web/noweb/src/shell/noweb.nw
blob: 1f258cb7550eecb6ce65368f873c13d2866ac3a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
\section{Generating all outputs from a {\tt noweb} file}
The copyright applies both to the {\tt noweb} source and to the
generated shell script.
<<copyright notice>>=
# Copyright 1991 by Norman Ramsey.  All rights reserved.
# See file COPYRIGHT for more information.
@
Here's the organization of the source:
<<noweb>>=
#!/bin/sh
<<copyright notice>>
# $Id: noweb.nw,v 1.3 1997/09/13 20:29:56 nr Exp $
# $Name:  $
LIB=|LIBDIR|
markup=$LIB/markup mntopt=-L status=0 tex=1 output=1
<<consume options, setting [[tex]], [[output]], [[mntopt]], and [[markup]]>>
if [ $# -eq 0 ]; then <<complain of no args and exit>>; fi

for source do
  if [ -n "$output" ]; then 
    PATH="$PATH:$LIB" $markup -t "$source" | $LIB/mnt -t8 "$mntopt" -all || status=1
  fi
  if [ -n "$tex" ]; then
    <<write {\TeX} output>> || status=1
  fi
done
exit $status
@
{\tt noweb} could be modified to follow two Knuth-like and {\tt nuweb}-like conventions:
\begin{itemize}
\item
Treat multiple white space within chunk names as single blanks, and
ignore leading and trailing whitespace.
\item
Permit chunk names to be abbreviated by writing an initial subsequence
of the name followed by ``[[...]]''.
\end{itemize}
The modification is simple; just add these two programs to the
pipeline.
([[disambiguate]] is an Icon program found in the [[icon]] directory
of the [[noweb]] distribution.)
<<compress multiple blanks in uses and defns>>=
sed -e '/^@[ud][se][ef][ n]/s/[ 	][ 	]*/ /g' \
    -e '/^@[ud][se][ef][ n]/s/ $//'
<<disambiguate uses and defns ending in three dots>>=
$LIB/disambiguate
@ 
When writing {\TeX} output, I call [[$markup]] a second time to expand tabs.
%% timings on nuweb
% markup 0.4u 0.1s
% noxref 3.9u 1.0s
% nawk   6.5u 0.2s
<<write {\TeX} output>>=
texname=`echo "$source" | sed '/\./s/\.[^.]*$//'`
texname="$texname.tex"
PATH="$PATH:$LIB" $markup "$source" | $LIB/finduses -noquote | $LIB/noidx -delay | 
nawk '{print}
/^@defn [^ ]*$/ { print "@literal \\let\\nwnotused=\\nwoutput{}" }' |
$LIB/totex -delay | cpif $texname
<<consume options, setting [[tex]], [[output]], [[mntopt]], and [[markup]]>>=
while [ $# -gt 0 ]; do
  case $1 in
    -to|-ot) tex= output= ; shift ;;
    -t)  tex=             ; shift ;;
    -o)  output=          ; shift ;;
    -L*) mntopt="$1"      ; shift ;;
    -markup) markup="$2"  ; shift; shift ;;
    -*)  echo "Unrecognized option $1" 1>&2; exit 1 ;;
    *) break ;;
  esac
done
<<complain of no args and exit>>=
echo "Usage: $0 [-L[fmt] -t -o] file [...]" 1>&2; exit 1
@