#!/bin/sh

###############################################################################
##                                                                           ##
##    This is the "tags" utility of "Build'n'Play" (BnP).                    ##
##                                                                           ##
##    (A tool for extracting the available subtarget tags                    ##
##    from an installation script <target>.bnp.)                             ##
##                                                                           ##
##    Copyright (c) 1998 by Steffen Beyer. All rights reserved.              ##
##                                                                           ##
##    This program is free software; you can redistribute it                 ##
##    and/or modify it under the same terms as Perl, i.e., either            ##
##    the "Artistic License" or the "GNU General Public License".            ##
##                                                                           ##
###############################################################################

###############################################################################
##                                                                           ##
##    This version of "tags" was developed with support from O'Reilly        ##
##    Verlag and was first published on the CD-ROM accompanying the book     ##
##    "Programmieren mit Perl-Modulen" (O'Reilly Verlag 1999).               ##
##                                                                           ##
##    Diese Version von "tags" entstand mit Unterstuetzung des O'Reilly      ##
##    Verlag und wurde erstmalig auf der CD-ROM zum Buch "Programmieren      ##
##    mit Perl-Modulen" (O'Reilly Verlag 1999) veroeffentlicht.              ##
##                                                                           ##
###############################################################################

self="`basename \"$0\"`"

if [ $# -ne 1 ]
then
    echo
    echo "Usage: $self <target>.bnp"
    echo
    echo "This utility extracts the available subtarget"
    echo "tags from an installation script <target>.bnp"
    echo
    exit 1
fi

path="`dirname \"$1\"`"
name="`basename \"$1\" .bnp`"

if [ "x$path" = "x." ]
then
    file="$name.bnp"
else
    file="$path/$name.bnp"
fi

if [ ! -f "$file" ]
then
    echo "$self: Can't find file '$file'!" >&2
    exit 1
fi

if [ "x$PAGER" = "x" ]
then
    PAGER=more
fi

(
    for item in `egrep 'begin_(lazy_)?section *\(' "$file" | \
       sed -e \
       's|^.*begin_lazy_section *(||; \
        s|^.*begin_section *(||; s|).*$||; s|  *||g; s|,,*| |g'`
    do
        tag="`echo \"$item\" | \
            sed -ne \"s|^[\\\"']||p\" | \
            sed -ne \"s|[\\\"']$||p\"`"
        if [ "x$tag" != "x" ]
        then
            echo "build $name.$tag"
        fi
    done
) | sort -u | $PAGER

##
## EOF
##

