\section{Weaving a {\tt noweb} file into a \TeX file} The copyright applies both to the {\tt noweb} source and to the generated shell script. <>= # Copyright 1991-1997 by Norman Ramsey. All rights reserved. # See file /sys/src/cmd/noweb/COPYRIGHT for more information. # $Id: noweave.nw,v 1.6 1998/08/17 00:10:34 nr Exp nr $ # # Translated from sh to rc by Russ Cox # bugs -> rsc@plan9.bell-labs.com @ Here's the organization of the source: <>= #!/bin/rc <> rfork en <> <> <> { <> status='' } | { args=(`{echo $noindex $delay $shortxref}) eval $backend $args } exit $status <>= if(! ~ $verbose '') echo $backend $noindex $delay $shortxref >[1=2] @ The first item of initialization is to locate the {\tt noweb} library. <>= LIB=/sys/lib/noweb @ We need to add the {\tt noweb} bin directories to the union mount on {\tt /bin . <>= bind -b $LIB/bin/$objtype /bin bind -b $LIB/bin/rc /bin @ We continue with initialization. We use strings throughout rather than {\tt rc} lists, since we're just going to echo it anyway, and it makes keeping the filterlist easy. <>= markup=markup backend=totex wrapper='' delay='' args='' markopts='' noweboptions='' autodefs='' verbose='' shortxref='' noquote=-noquote docanchor='' noindex=-noindex filterlist=() # following supported by change in totex back end noquote='' @ I make two passes over the arguments so as not to require that options be given in a certain order <>= saveargs=($*) arg='' while(! ~ $#* 0) { switch($1) { <> case - arg=$arg^' '$1 case -* echo $0': unrecognized option '$1 >[1=2] <> exit usage case * arg=$arg^' '$1 } shift } <> if(~ $wrapper '') wrapper=latex *=$saveargs shift while(! ~ $#* 0) { switch($1) { <> } shift } <>= if(~ $noweboptions '') noweboptions=$newopt if not noweboptions=$noweboptions','$newopt <>= case -latex if(! ~ $wrapper none) wrapper=latex case -tex wrapper=tex case -html if(! ~ $wrapper none) wrapper=html backend='tohtml -localindex' noquote='' docanchor='-docanchor 10' case -latex+html if(! ~ $wrapper none) wrapper=latex backend='tohtml -localindex -raw' noquote='' docanchor='-docanchor 10' case -ascii wrapper=none backend=toascii case -troff backend=toroff case -n wrapper=none case -backend backend=$2 shift case -markup markup=$2 shift @ Note some versions of echo break on [[echo "-n..."]], echoing nothing at all. The leading space is claimed to prevent this problem. <