#!/bin/sh
#ident "%W%" %G%
 
#-----------------------------------------------------------------------
# Copyright (C) 1994 Kubota Graphics Corp.
# 
# Permission to use, copy, modify, and distribute this material for
# any purpose and without fee is hereby granted, provided that the
# above copyright notice and this permission notice appear in all
# copies, and that the name of Kubota Graphics not be used in
# advertising or publicity pertaining to this material.  Kubota
# Graphics Corporation MAKES NO REPRESENTATIONS ABOUT THE ACCURACY
# OR SUITABILITY OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED
# "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE AND KUBOTA GRAPHICS CORPORATION DISCLAIMS ALL WARRANTIES,
# EXPRESS OR IMPLIED.
#-----------------------------------------------------------------------

#
# This script copies every .3d file from SRC_ROOT to
# INSTALL_ROOT/usr/kits/KWS/dore/man and rename the new file functioname.3d,
# where "functioname" is the Dore function name.
#
# To figure out what the function name is, it looks for the ".TH" string
# in the original troff manpage file. Every manpage file must have a
# unique .TH entry, or else this script will fail.
#

INSTALL_PATH=$INSTALL_ROOT/usr/share/man/man3
SCP_PATH=$INSTALL_ROOT/../data/scps

if [ -z "$SRC_ROOT" ]; then
   echo SRC_ROOT not set
   exit
fi

if [ -z "$INSTALL_ROOT" ]; then
   echo INSTALL_ROOT not set
   exit
fi

if [ -s $SRC_ROOT/*.3d ]; then
    if [ ! -d $INSTALL_PATH ]; then                             
        echo "Creating directory $INSTALL_PATH" 
        mkdir -p $INSTALL_PATH
	chmod 755 $INSTALL_PATH
    fi           

    if [ ! -d $INSTALL_PATH/dore/man3 ]; then                             
        mkdir -p $INSTALL_PATH/dore/man3
    fi           

    echo "Creating man page files"
    for fname1 in $SRC_ROOT/*.3d; do
        fname2=`awk '/^\.TH/ {print $2}' $fname1`
        cp $fname1 $INSTALL_PATH/dore/man3/$fname2.3d
    done

    echo "Creating whatis file"
    catman -M $INSTALL_PATH/dore -w
    mv $INSTALL_PATH/dore/whatis $INSTALL_PATH/../.KWSDOREMN.whatis

    echo "Installing man page files"
    mv $INSTALL_PATH/dore/man3/* $INSTALL_PATH
    rm -rf $INSTALL_PATH/dore
else
    echo No files with .3d extension in $SRC_ROOT 
fi

echo "Installing scp file"
if [ -s $SRC_ROOT/adoremn.scp ]; then
	if [ ! -d $SCP_PATH ]; then
        	echo "Creating directory $SCP_PATH" 
		mkdir -p $SCP_PATH
		chmod 755 $SCP_PATH
	fi
	cp $SRC_ROOT/adoremn.scp $SCP_PATH/KWSDOREMNxxx.scp
else
    echo "No scp file"
fi

