#!/bin/csh -f

# Set Variables 
# "man_dir" to the path name of the LEDA manual directory
# "awk_cmd" to your awk command (must be compatible with GNU gawk)

set man_dir = /KM/usr/naeher/leda/man
set awk_cmd = gawk


if (! -d $man_dir) then
echo    ""
echo -n "Cannot find LEDA manual directory,"
echo    " change variable 'man_dir' in '$0' \!"
echo    ""
exit 1
endif

if ("$1" == "-l") then
set less = 0
shift
else
set less = 1

if ("$1" == "-t") then
set textedit = 1
shift
else
set textedit = 0
endif
endif


if ($1 == "") then
clear
echo "Lman - print LEDA manual pages"
echo " "
echo "Syntax: "
echo " "
echo "    lman   T   [op]"
echo " "
echo "Arguments: "
echo " "
echo "    T   :  name of a LEDA data type"
echo " "
echo "    op  :  name of an operation of data type T or one of the section names"
echo "           definition, declaration, creation, operations, or implementation"
echo " "
echo "Usage: "
echo " "
echo "    lman  T        prints the manual page for data type T (piped through less)."
echo " "
echo "    lman  T  op    prints the manual entry for operation T::op or section"
echo "                   op of the manual page for T (if op is a section name)."
echo " "
echo " "
exit 1
endif

set tex_file = $man_dir/$1.tex
set awk_script = $man_dir/AWK


if (-f $tex_file) then
  if ($2 != "") then
    while ($2 != "")
      $awk_cmd -f $awk_script $tex_file $2 
      shift
    end
  else
   if ($less == 1) then
    $awk_cmd -f $awk_script $tex_file | less -+M -+m -e -n -P"LEDA Manual ($1)"
   else
    if ($textedit == 1) then
     $awk_cmd -f $awk_script $tex_file | sed s/_//g > /tmp/lman$$
     textedit -read_only /tmp/lman$$
     rm -f /tmp/lman$$
    else
     $awk_cmd -f $awk_script $tex_file
    endif
   endif
  endif
else
   echo "$0": LEDA data type \"$1\" not found
   exit 1
endif

exit 0
