#! /bin/csh -f
#
# Silly program that creates a first other manual page from the inline
# help file
#
# see also the help2man program https://www.gnu.org/software/help2man/
#
set version="1.3  16-mar-2020 PJT"

if ($#argv == 0) then
  echo "Usage: $0 [-section] name"
  echo "Version: $version"
  echo ""
  echo "Creates a barebone Unix man page on stdout from a NEMO inline help file help=h."
  echo "You probably want to edit this file after creation."
  echo "Using a different section, one can also generate a template for"
  echo "other than level 1 man pages from existing programs"
  echo "See also https://www.gnu.org/software/help2man/"
  exit 0
endif

set section=1
foreach a ($*)
  switch ($a)
  case "-*":
    set section=`echo $a | tr -d -`
    breaksw
  default:
    set name=$a
    breaksw
  endsw
end

set lname=$name
set uname=`echo $name | tr '[a-z]' '[A-Z]'`
set ddmmmyyyy=`date '+%d %h %Y'`
set ddmmyy=`date '+%d-%h-%y'`

echo '.\" This man pages created with '$0
echo '.\" Remove these comment lines when editing for the final version'
echo ".TH $uname ${section}NEMO "'"'"$ddmmmyyyy"'"'
echo ".SH NAME"
if ($section == 1) then
  echo "$lname \- `$lname help=uq`"
else
  echo "$lname \- "
endif
echo ".SH SYNOPSIS"
if ($section == 1) then
  echo "\fB$lname\fP [parameter=value]"
endif
echo ".SH DESCRIPTION"
echo "No description available. This manual page was created by mkman"
if ($section == 1) then
  echo ".SH PARAMETERS"
  echo "The following parameters are recognized in any order if the keyword"
  echo "is also given:"
  $lname help=h | awk '{ printf(".TP 20\n\\fB%s=\\fP\n%s %s %s %s %s %s %s %s\n",$1,$3,$4,$5,$6,$7,$8,$9,$10)}'
endif
echo ".SH EXAMPLES"
echo ".SH SEE ALSO"
echo ".SH FILES"
echo ".SH AUTHOR"
echo "mkman"
echo ".SH UPDATE HISTORY"
echo ".nf"
echo ".ta +1.0i +4.0i"
echo "$ddmmyy	V0.0 Created by mkman	NEMO/$USER"
echo ".fi"
