#!/bin/rc
# 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
rfork en
LIB=/sys/lib/noweb
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=''
nl='
'
using_index=''
using_xref=''
bind -b $LIB/bin/$cputype /bin
bind -b $LIB/bin/rc /bin
saveargs=($*)
arg=''
while(! ~ $#* 0) {
switch($1) {
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
case -filter
shift
case -x
using_xref=1
case -index
noindex=''
using_index=1
case -indexfrom
shift
noindex=''
using_index=1
case -autodefs
newfilter='autodefs.'^$2
if(test -r $newfilter) {
filterlist=($filterlist $newfilter)
}
if not {
echo $0^': don''t know how to find definitions for '^$2
exit defns
}
shift
case -showautodefs
foundautodefs=no
for(i in $LIB/autodefs.*) {
if(test -r $i) {
echo 'Supports -autodefs '^$i | sed 's!$LIB/autodefs\.!!' >[1=2]
foundautodefs=yes
}
}
if(~ $foundautodefs no)
echo 'Does not support -autodefs' >[1=2]
exit complain
case -option
newopt=$2
shift
if(~ $newopt shortxref)
shortxref=-shortxref
if(~ $newopt longxref)
shortxref=-longxref
if(~ $noweboptions '')
noweboptions=$newopt
if not
noweboptions=$noweboptions','$newopt
# case -nodelay
# delay=''
case -delay
delay=-delay
wrapper=none
case -t*
markopts=$markopts' '$1
case -v
echo 'RCS id $Id: noweave.nw,v 1.6 1998/08/17 00:10:34 nr Exp nr $' >[1=2]
verbose=1
case -
arg=$arg^' '$1
case -*
echo $0': unrecognized option '$1 >[1=2]
echo 'Usage: '$0' [options] [files]' >[1=2]
echo 'Options recognized are:' >[1=2]
echo '-latex Emit LaTeX with headers and trailers (default).' >[1=2]
echo '-tex Emit plain TeX with headers and trailers.' >[1=2]
echo '-html Emit HTML with headers and trailers.' >[1=2]
echo '-latex+html Assume LaTeX in documentation, but use HTML in code.' >[1=2]
# echo '-ascii Emit ASCII.' >[1=2]
echo '-troff Emit troff (actually GNU groff).' >[1=2]
echo ' -n Don''t use any header or trailer.' >[1=2]
echo '-markup frontend Parse input with frontend (e.g., numarkup).' >[1=2]
echo '-x Use the default cross-referencer (needs LaTeX or HTML).' >[1=2]
echo '-index Create index using identifiers defined in input files.' >[1=2]
echo '-indexfrom defs Create index of identifers listed in file defs.' >[1=2]
echo '-filter cmd Filter through ''cmd'' before weaving; cmd could prettyprint' >[1=2]
echo ' or perform other functions.' >[1=2]
echo '-autodefs lang Source is in language ''lang''; find definitions automatically.' >[1=2]
echo '-showautodefs List languages that can be used with -autodefs' >[1=2]
echo '-option opt Add \noweboptions{opt} to header (latex only)' >[1=2]
echo '-delay Delay markup until after first documentation chunk.' >[1=2]
echo '-tk Expand tab stops every k columns' >[1=2]
echo '-t Copy tabs to the output' >[1=2]
echo '-v Print pipeline and RCS info on standard error' >[1=2]
exit usage
case *
arg=$arg^' '$1
}
shift
}
if(! ~ $using_xref '' && ! ~ $using_index '') {
echo $0': you may not use -x with -index or -indexfrom (drop the -x)' >[1=2]
exit -x-index
}
if(~ $wrapper '')
wrapper=latex
*=$saveargs
shift
while(! ~ $#* 0) {
switch($1) {
case -filter
newfilter=$2
shift
filterlist=($filterlist $newfilter)
case -x
newfilter='noidx '^$docanchor^' '^$delay
filterlist=($filterlist $newfilter)
case -index
newfilter='finduses '^$noquote
filterlist=($filterlist $newfilter)
newfilter='noidx '^$docanchor^' '^$delay
filterlist=($filterlist $newfilter)
case -indexfrom
newfilter='finduses '^$noquote^' '^$2
filterlist=($filterlist $newfilter)
newfilter='noidx '^$docanchor^' '^$delay
filterlist=($filterlist $newfilter)
shift
}
shift
}
header=''
# whatis wrapper
# whatis arg
switch($wrapper) {
case none
;
case latex
header='@header '^$wrapper^' '^$noweboptions
trailer='@trailer '^$wrapper
case *
header='@header '^$wrapper^$arg
}
if(~ $#filterlist 0)
filterlist=cat
pipeline='| '^$filterlist
pipeline=$"pipeline
markopts=($markopts $arg)
backargs=`{echo $noindex $delay $shortxref}
markup=`{echo $markup^' '^$"markopts^' '^$pipeline | sed 's/(\| *cat *)+(\||$)//'}
if(! ~ $verbose '')
{
echo bind -b $LIB/bin/$cputype /bin
echo bind -b $LIB/bin/rc /bin
ifs=$nl {tab=`{unicode 9}} # noweb will kill the tabs
if(! ~ $header '' || ! ~ $trailer '') {
echo '{'
{
if(! ~ $header '')
echo echo $header
echo $markup | sed 's/ *\| */ |\n'^$tab^'/'
if(! ~ $trailer '')
echo echo $trailer
} |sed 's/^/'^$tab^'/'
echo '} | '^$backend $backargs
}
if not {
echo $markup '|' | sed 's/ *\| */ |\n /'
echo $backend $backargs
}
} >[1=2]
{
if(! ~ $header '')
echo $header
eval $markup
if(! ~ $trailer '')
echo $trailer
if not
status=''
} | {
eval $backend $backargs
}
|