summaryrefslogtreecommitdiffstats
path: root/unix/installManPage
blob: 8045423bb90a410a50533ff36e21742f0f916e67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh

ZIP=:
while true; do
    case $1 in
        -s | --symlinks  )      S="-s ";;
        -z | --compress  )    ZIP=$2;  shift ;;
	-e | --extension )      Z=$2;  shift ;;
	-s | --suffix    ) SUFFIX=$2;  shift ;;
	*)  break ;;
    esac
    shift
done
if test "$#" != 2; then
    echo "Usage: installManPages <options> file dir"
    exit 1
fi

MANPAGE=$1
DIR=$2
test -z "$S" && S="$DIR/"

# Backslashes are trippled in the sed script, because it is in backticks
# which don't pass backslashes literally.
NAMES=`sed -n '
    /^\\.SH NAME/{    ;# Look for a line, that starts with .SH NAME
	s/^.*$//      ;# Delete the content of this line from the buffer
	n             ;# Read next line
	s/,\|\\\ //g  ;# Remove all commas
	s/ \\\-.*//   ;# Delete from \- to the end of line
	p             ;# print the result
	q
    }' $MANPAGE`

SECTION=`echo $MANPAGE | sed 's/.*\(.\)$/\1/'`
SRCDIR=`dirname $MANPAGE`
FIRST=""
for f in $NAMES; do
    f=$f.$SECTION$SUFFIX
    if test -z "$FIRST" ; then
	FIRST=$f
	rm -f $DIR/$FIRST $DIR/$FIRST.*
	sed -e "/man\.macros/r $SRCDIR/man.macros" -e "/man\.macros/d" \
	    $MANPAGE > $DIR/$FIRST
	chmod 444 $DIR/$FIRST
	$ZIP $DIR/$FIRST
    else
	rm -f $DIR/$f $DIR/$f.*
	ln $S$FIRST$Z $DIR/$f$Z
    fi
done