#!/bin/sh
# Copyright 1991 by Norman Ramsey.  All rights reserved.
# See file COPYRIGHT for more information.
# $Id: noweb.nw,v 1.3 1997/09/13 20:29:56 nr Exp nr $
# $Name:  $
LIB=/usr/pkg/share/noweb
markup=$LIB/markup mntopt=-L status=0 tex=1 output=1
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
if [ $# -eq 0 ]; then echo "Usage: $0 [-L[fmt] -t -o] file [...]" 1>&2; exit 1; 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
    texname=`echo $source | sed '/\./s/\.[^.]*$//'`
    texname="$texname.tex"
    PATH="$PATH:$LIB" $markup $source | $LIB/finduses -noquote | $LIB/noidx -delay | 
    awk '{print}
    /^@defn [^ ]*$/ { print "@literal \\let\\nwnotused=\\nwoutput{}" }' |
    $LIB/totex -delay | cpif $texname || status=1
  fi
done
exit $status
