File: nsinstall-man.sh

package info (click to toggle)
aolserver4 4.5.1-15.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 11,772 kB
  • sloc: ansic: 45,120; tcl: 5,532; sh: 1,021; makefile: 380; pascal: 219; php: 13
file content (129 lines) | stat: -rwxr-xr-x 2,453 bytes parent folder | download | duplicates (5)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh

#
# nsinstall-man.sh --
#
#	Install a man or HTML page, making links to all functions/commands
#	documented in the file.  Modified from the Tcl source.
#
# $Id: nsinstall-man.sh,v 1.4 2006/04/28 13:47:45 jgdavidson Exp $
#

ECHO=:
LN=ln
RM="rm -f"
MD="mkdir -p"
SED=sed
CAT=cat
CHMOD=chmod
MODE=0444
GROFF=groff
HTM=""

while true; do
    case $1 in
        -v | --verbose)  	  ECHO=echo;;
        -s | --symlinks)  	  LN="$LN -s ";;
	-h | --html)		  HTM=".htm";;
	*)  break ;;
    esac
    shift
done
if test "$#" -ne 1 -a "$#" -ne 2; then
    echo "Usage: $0 <options> file ?dir?"
    exit 1
fi
if test "$#" -eq 2; then
    DIR=$2
else
    DIR=$AOLSERVER
fi
if test -z "$DIR"; then
    echo "Must specify output directory or set AOLSERVER environment variable."
    exit 1
fi
MANPAGE=$1
SECTION=`echo $MANPAGE | $SED 's/.*\(.\)$/\1/'`

#
# Search for man.macros in common locations.
#

MACROS=""
for d in \
	`dirname $MANPAGE` \
	$AOLSERVER/include \
	`dirname $0`/../include \
	../doc \
	./aolserver/doc
do
	f="$d/man.macros"
	if test -r $f; then
		MACROS=$f
		break
	fi
done
if test -z "$MACROS"; then
    echo "Can not locate required man.macros"
    exit 1
fi

#
# Parse the alternative names out of a man page.
#
#    /^\\.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/\\\ //g     ;# .. and backslash-escaped spaces.
#	s/ \\\-.*//   ;# Delete from \- to the end of line
#	p             ;# print the result
#	q             ;# exit
#   }
#
# Backslashes are trippled in the sed script, because it is in
# backticks which don't pass backslashes literally.
#
# Please keep the commented version above updated if you
# change anything to the script below.
NAMES=`$SED -n '
    /^\\.SH NAME/{
	s/^.*$//
	n
	s/,//g
	s/\\\ //g
	s/ \\\-.*//
	p
	q
    }' $MANPAGE`

#
# Create or link man pages for each name.
#

if test -z "$HTM"; then
    DIR=$DIR/man$SECTION
    MAN2HTM=$CAT
else
    DIR=$DIR
    MAN2HTM="$GROFF -Thtml -man"
fi

FIRST=""
$MD $DIR
for name in $NAMES
do
    tail=$name.$SECTION
    file=$DIR/$tail$HTM
    $RM $file
    if test -z "$FIRST"; then
	FIRST=$file
	$SED -e "/man\.macros/r $MACROS" -e "/man\.macros/d" $MANPAGE | \
		$MAN2HTM > $file
	$CHMOD $MODE $file
    	$ECHO "created: $file ($MODE)"
    else
	$LN $FIRST $file
    	$ECHO "linked: $file"
    fi
done