#!/bin/sh

#************************************************************ 
#
# Component       CNF  
#
# Synopsis        shell script (useful for module location setting
#
#
# Copyright 2001 Sun Microsystems, Inc. All rights reserved.
#
#
#************************************************************
#
# #ident "@(#)nhadm 1.7 02/01/31 SMI"
#
#************************************************************

FILENAME=`basename $0`
if [ -f "$PWD/$0.pl" ]
then
    LIBNAME=$PWD
    NHADM_DUMP=$PWD
else
    LIBNAME=`dirname $0`/../lib/adm/
    NHADM_DUMP=`dirname $0`/../lib/dump/
fi
export NHADM_DUMP
ARGS=""

if [ "$1" = "--err" ] || [ "$1" = "-z" ]
then
    #
    # generation of documentation about error messages
    #

    # default -> HTML
    command=""
    if [ "$2" = "html" ] || [ "$2" = "" ]
    then
	command="/usr/perl5/bin/pod2html --title \"NHAS 2.0 Administration Tool: Error messages\""
    fi
    if [ "$2" = "text" ]
    then
        command="/usr/perl5/bin/pod2text"
    fi

    if [ "$command" = "" ]
    then
        echo "$2: invalid format. Supported documentation format: html, text"
        exit 1
    fi

    # generate documentation by removing comments before pod directives
    # and calling pod2html
    list="$LIBNAME/*.pl $LIBNAME/*.pm"
    awk 'BEGIN { FS="#" ; start=0 } \
     /^#=item/ { if (start == 0) print "" ; start=1 } \
     /^#=head1/ { if (start == 0) print "" ; start=1 } \
     /^#=over/ { if (start == 0) print "" ; start=1 } \
     /^#=back/ { if (start == 0) print "" ; start=1 } \
     /^#=cut/    {start = 0 ; print "=cut" } \
     { if (start == 1) print  $2} \
     END { print "" }' $list \
     | eval $command
     exit 0
fi

HELP=no
while [ "$1" != "" ]
do
    ARGS="$ARGS $1"
    if [ "$1" = "-h" ] || [ "$1" = "--help" ]
    then
        # display the help specific to the shell script
        # if root (same rule than the perl script)
	USERNAME=`/usr/bin/id`
	ROOT=`/usr/bin/echo $USERNAME | /usr/bin/grep "uid=[0-9]*(root)"`
	if [ "$ROOT" != "" ]
	then
	    HELP=yes
	fi
    fi
    shift 1
done
/usr/bin/perl -w -I$LIBNAME $LIBNAME/$FILENAME.pl $ARGS
if [ $HELP = "yes" ]
then
    echo ""
    echo "    special argument: error list"
    echo "      -z | --err [ html | text ]"
    echo "        produce a list of all errors with their description"
    echo "        in html or text format (default is html)"
fi
