head	1.7;
access;
symbols
	core-8-5-9:1.4.2.2
	core-8-5-8:1.4
	macosx-cocoa-merge:1.4
	macosx-cocoa-premerge:1.4
	macosx-carbon-freeze:1.4
	core-8-5-7:1.4
	core-8-5-6:1.4
	core-8-6-b1:1.4
	core-8-6-a3:1.4
	core-8-5-5:1.4
	core-8-6-a2:1.4
	core-8-5-4:1.4
	core-8-5-3:1.4
	core-8-6-a1:1.4
	core-8-4-19:1.1.2.4
	core-8-5-branch:1.4.0.2
	core-8-5-2:1.4
	core-8-4-18:1.1.2.4
	core-8-5-1:1.4
	core-8-4-17:1.1.2.4
	core-8-5-0:1.4
	core-8-5-b3:1.4
	core-8-5-b2:1.3
	core-8-4-16:1.1.2.4
	core-8-5-b1:1.3
	core-stablilizer-merge:1.3
	core-stabilizer-branch:1.3.0.2
	core-stabilizer-merge:1.4
	core-8-4-15:1.1.2.4
	core-8-5-a6:1.3
	core-8-5-a5:1.3
	core-8-4-14:1.1.2.4
	core-8-5-a4:1.3
	core-8-4-13:1.1.2.4
	core-8-4-12:1.1.2.4
	core-8-4-11:1.1.2.4
	core-8-5-a3:1.3
	core-8-4-10:1.1.2.4
	core-8-4-9-branch:1.1.2.4.0.2
	core-8-5-a2:1.3
	core-8-4-9:1.1.2.4
	core-8-4-8:1.1.2.4
	core-8-4-branch:1.1.0.2;
locks; strict;
comment	@# @;


1.7
date	2010.02.26.10.26.31;	author dkf;	state Exp;
branches;
next	1.6;

1.6
date	2010.02.22.13.10.56;	author dkf;	state Exp;
branches;
next	1.5;

1.5
date	2010.02.19.13.41.49;	author dkf;	state Exp;
branches;
next	1.4;

1.4
date	2007.11.01.10.59.44;	author dkf;	state Exp;
branches
	1.4.2.1;
next	1.3;

1.3
date	2004.11.19.10.22.38;	author rmax;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2004.11.18.18.33.34;	author rmax;	state Exp;
branches;
next	1.1;

1.1
date	2004.11.18.00.43.19;	author rmax;	state Exp;
branches
	1.1.2.1;
next	;

1.1.2.1
date	2004.11.18.02.08.59;	author rmax;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2004.11.18.17.22.29;	author rmax;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2004.11.18.18.09.18;	author rmax;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2004.11.19.09.46.31;	author rmax;	state Exp;
branches;
next	;

1.3.2.1
date	2007.11.01.16.37.24;	author dgp;	state Exp;
branches;
next	;

1.4.2.1
date	2010.02.19.13.45.39;	author dkf;	state Exp;
branches;
next	1.4.2.2;

1.4.2.2
date	2010.02.22.13.11.32;	author dkf;	state Exp;
branches;
next	;


desc
@@


1.7
log
@Remap non-alphanumeric sequences in manpage filenames to single underscores.
@
text
@#!/bin/sh

########################################################################
### Parse Options
###

Gzip=:
SymOrLoc=""
Gz=""
Suffix=""

while true; do
    case $1 in
        -s | --symlinks  ) SymOrLoc="-s "      ;;
        -z | --compress  )     Gzip=$2;  shift ;;
	-e | --extension )       Gz=$2;  shift ;;
	-x | --suffix    )   Suffix=$2;  shift ;;
	-*) cat <<EOF
Unknown option "$1". Supported options:
    -s         Use symbolic links for manpages with multiple names.
    -z PROG    Use PROG to compress manual pages.
    -e EXT     Defines the extension added by -z PROG when compressing.
    -x SUFF    Defines an extra extension suffix to use.
Option names may not be combined getopt-style.
EOF
	    exit 1 ;;
	*)  break ;;
    esac
    shift
done
if test "$#" != 2; then
    echo "Usage: installManPages <options> file dir"
    exit 1
fi

########################################################################
### Parse Required Arguments
###

ManPage=$1
Dir=$2
if test -f $ManPage ; then : ; else
    echo "source manual page file must exist"
    exit 1
fi
if test -d $Dir ; then : ; else
    echo "target directory must exist"
    exit 1
fi
test -z "$SymOrLoc" && SymOrLoc="$Dir/"

########################################################################
### Extract Target Names from Manual Page
###

# A sed script to parse the alternative names out of a man page.
#
# Backslashes are trippled in the sed script, because it is in
# backticks which doesn't pass backslashes literally.
#
Names=`sed -n '
#                               Look for a line that starts with .SH NAME
    /^\.SH NAME/{
#                               Read next line
	n
#                               Remove all commas ...
	s/,//g
#                               ... and backslash-escaped spaces.
	s/\\\ //g
#                               Delete from \- to the end of line
	s/ \\\-.*//
#                               Convert all non-space non-alphanum sequences
#                               to single underscores.
	s/[^ A-Za-z0-9][^ A-Za-z0-9]*/_/g
#                               print the result and exit
	p;q
    }' $ManPage`

if test -z "$Names" ; then
    echo "warning: no target names found in $ManPage"
fi

########################################################################
### Remaining Set Up
###

case $ManPage in
    *.1) Section=1 ;;
    *.3) Section=3 ;;
    *.n) Section=n ;;
    *)	echo "unknown section for $ManPage"
	exit 2 ;;
esac

SrcDir=`dirname $ManPage`

########################################################################
### Process Page to Create Target Pages
###

First=""
for Target in $Names; do
    Target=$Target.$Section$Suffix
    rm -f $Dir/$Target $Dir/$Target.*
    if test -z "$First" ; then
	First=$Target
	sed -e "/man\.macros/r $SrcDir/man.macros" -e "/man\.macros/d" \
	    $ManPage > $Dir/$First
	chmod 444 $Dir/$First
	$Gzip $Dir/$First
    else
	ln $SymOrLoc$First$Gz $Dir/$Target$Gz
    fi
done

########################################################################
exit 0
@


1.6
log
@Added missing quoting
@
text
@d62 1
a62 3
#                               Look for a line, that starts with .SH NAME
#                               optionally allow NAME to be surrounded
#                               by quotes.
d72 3
@


1.5
log
@[Tcl Bug 2954638]: Correct behaviour of manual page installer. Also added
armouring to check that assumptions about the initial state are actually valid
(e.g., look for existing input file).
@
text
@d78 1
a78 1
if test -z $Names ; then
@


1.4
log
@Make documentation use the name that scripts use as much as possible.
[Bug 1640073]
@
text
@d3 9
a11 1
ZIP=:
d14 13
a26 4
        -s | --symlinks  )      S="-s ";;
        -z | --compress  )    ZIP=$2;  shift ;;
	-e | --extension )      Z=$2;  shift ;;
	-s | --suffix    ) SUFFIX=$2;  shift ;;
d36 19
a54 3
MANPAGE=$1
DIR=$2
test -z "$S" && S="$DIR/"
a57 11
#    /^\\.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/::/_/g       ;# Convert '::' to '_'
#	s/ \\\-.*//   ;# Delete from \- to the end of line
#	p             ;# print the result
#	q             ;# exit
#   }
#
d59 1
a59 1
# backticks which don't pass backslashes literally.
d61 6
a66 5
# Please keep the commented version above updated if you
# change anything to the script below.
NAMES=`sed -n '
    /^\\.SH NAME/{
	s/^.*$//
d68 1
d70 1
d72 1
a72 1
	s/::/_/g
d74 36
a109 16
	p
	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
d111 1
a111 2
	rm -f $DIR/$f $DIR/$f.*
	ln $S$FIRST$Z $DIR/$f$Z
d114 3
@


1.4.2.1
log
@[Tcl Bug 2954638]: Correct behaviour of manual page installer. Also added
armouring to check that assumptions about the initial state are actually valid
(e.g., look for existing input file).
@
text
@d3 1
a3 9
########################################################################
### Parse Options
###

Gzip=:
SymOrLoc=""
Gz=""
Suffix=""

d6 4
a9 13
        -s | --symlinks  ) SymOrLoc="-s "      ;;
        -z | --compress  )     Gzip=$2;  shift ;;
	-e | --extension )       Gz=$2;  shift ;;
	-x | --suffix    )   Suffix=$2;  shift ;;
	-*) cat <<EOF
Unknown option "$1". Supported options:
    -s         Use symbolic links for manpages with multiple names.
    -z PROG    Use PROG to compress manual pages.
    -e EXT     Defines the extension added by -z PROG when compressing.
    -x SUFF    Defines an extra extension suffix to use.
Option names may not be combined getopt-style.
EOF
	    exit 1 ;;
d19 3
a21 19
########################################################################
### Parse Required Arguments
###

ManPage=$1
Dir=$2
if test -f $ManPage ; then : ; else
    echo "source manual page file must exist"
    exit 1
fi
if test -d $Dir ; then : ; else
    echo "target directory must exist"
    exit 1
fi
test -z "$SymOrLoc" && SymOrLoc="$Dir/"

########################################################################
### Extract Target Names from Manual Page
###
d25 11
d37 1
a37 1
# backticks which doesn't pass backslashes literally.
d39 5
a43 6
Names=`sed -n '
#                               Look for a line, that starts with .SH NAME
#                               optionally allow NAME to be surrounded
#                               by quotes.
    /^\.SH NAME/{
#                               Read next line
a44 1
#                               Remove all commas ...
a45 1
#                               ... and backslash-escaped spaces.
d47 1
a47 1
#                               Delete from \- to the end of line
d49 16
a64 36
#                               print the result and exit
	p;q
    }' $ManPage`

if test -z $Names ; then
    echo "warning: no target names found in $ManPage"
fi

########################################################################
### Remaining Set Up
###

case $ManPage in
    *.1) Section=1 ;;
    *.3) Section=3 ;;
    *.n) Section=n ;;
    *)	echo "unknown section for $ManPage"
	exit 2 ;;
esac

SrcDir=`dirname $ManPage`

########################################################################
### Process Page to Create Target Pages
###

First=""
for Target in $Names; do
    Target=$Target.$Section$Suffix
    rm -f $Dir/$Target $Dir/$Target.*
    if test -z "$First" ; then
	First=$Target
	sed -e "/man\.macros/r $SrcDir/man.macros" -e "/man\.macros/d" \
	    $ManPage > $Dir/$First
	chmod 444 $Dir/$First
	$Gzip $Dir/$First
d66 2
a67 1
	ln $SymOrLoc$First$Gz $Dir/$Target$Gz
a69 3

########################################################################
exit 0
@


1.4.2.2
log
@Added missing quoting
@
text
@d78 1
a78 1
if test -z "$Names" ; then
@


1.3
log
@Classic sed doesn't support | in REs.
@
text
@d30 1
d47 1
@


1.3.2.1
log
@merge updates from HEAD
@
text
@a29 1
#       s/::/_/g       ;# Convert '::' to '_'
a45 1
	s/::/_/g
@


1.2
log
@some seds don't support comments :(
@
text
@d28 2
a29 1
#	s/,\|\\\ //g  ;# Remove all commas
d33 1
d44 2
a45 1
	s/,\|\\\ //g
@


1.1
log
@2004-11-18  Reinhard Max  <max@@suse.de>
        * unix/tcl.m4 (SC_CONFIG_MANPAGES): Applied an improved version of
        * unix/configure.in:                patch #996085, that introduces
        * unix/Makefile.in:                 --enable-man-suffix.

        * unix/installManPage:              added
        * unix/mkLinks:                     removed
@
text
@d23 15
a37 2
# Backslashes are trippled in the sed script, because it is in backticks
# which don't pass backslashes literally.
d39 6
a44 6
    /^\\.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
@


1.1.2.1
log
@2004-11-18  Reinhard Max  <max@@suse.de>

        * unix/tcl.m4 (SC_CONFIG_MANPAGES): Applied an improved version of
        * unix/configure.in:                patch #996085, that introduces
        * unix/Makefile.in:                 --enable-man-suffix.

        * unix/installManPage:              added
        * unix/mkLinks:                     removed
@
text
@@


1.1.2.2
log
@Some versions of sed appear to need semicolons in front of comments.
@
text
@d26 6
a31 6
    /^\\.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
@


1.1.2.3
log
@Arghh - some seds don't even support comments at all.
@
text
@d23 2
a24 15
# A sed script to 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/ \\\-.*//   ;# 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.
d26 6
a31 6
    /^\\.SH NAME/{
	s/^.*$//
	n
	s/,\|\\\ //g
	s/ \\\-.*//
	p
@


1.1.2.4
log
@Classic sed doesn't support | in REs.
@
text
@d28 1
a28 2
#	s/,//g        ;# Remove all commas ...
#	s/\\\ //g     ;# .. and backslash-escaped spaces.
a31 1
#   }
d42 1
a42 2
	s/,//g
	s/\\\ //g
@


