#!/bin/sh
# --------------------------------------------------------------------------
# Copyright 1992-1993 by Forschungszentrum Informatik (FZI)
#
# You can use and distribute this software under the terms of the license
# version 1 you should have received along with this software.
# If not or if you want additional information, write to
# Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
# D-76131 Karlsruhe, Germany.
# ------------------------------------------------------------------------
# 'mkinstallman - 21:10:93 - Dietmar Thebald, Ingolf Mertens, Walter Zimmer'

 self=mkinstallman
usage='srcdir targetdir old_ext new_ext'

# mkinstallman is used for installing the OBST manpages.  Each call
# moves the manpages from $srcdir to $targetdir.  If the old and new
# extensions of the manpages differ, the manpage will be renamed and
# occurences of the old extensions inside manpage (typically in ".so
# ..." include statements) are replaced by the new extension.

[ $# -le 1 ]  && { echo >&2 "usage: $self $usage"; exit 1; }

   srcdir="$1"
targetdir="$2"
  old_ext="$3"
  new_ext="$4"
 old_sect="`echo $old_ext | sed 's|^\.||'`"
 new_sect="`echo $new_ext | sed 's|^\.||'`"
 new_suff="`echo $targetdir | sed 's|.*man\(.*\)|\1|'`"

umask 022

cd "$srcdir"
for f in *$old_ext
do
   cmd="s|$old_ext\$|$new_ext|"
   target="$targetdir/`echo $f | sed $cmd`"
   echo "$f --> $target"

   sed -e "s|^\([ ]*\.so[ ]*man\)[^/]*\(/.*\)$old_ext|\1$new_suff\2$new_ext|"\
       -e "s|^\(\.TH .* \)$old_sect |\1$new_sect |"\
       "$f"\
     > "$target"
done
