Blame Scripts/Bash/Functions/Help/help_getEntries.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# help_getEntries.sh -- This function interpretes non-option
878a2b
# arguments passed to `help' functionality through the command-line
878a2b
# and redefines array variables related to documentation entries.
878a2b
#
878a2b
# Copyright (C) 2009, 2010, 2011 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function help_getEntries {
878a2b
878a2b
    # Initialize manual's documentation entry as an empty value local
878a2b
    # to this function.
878a2b
    local MANUAL_DOCENTRY=''
878a2b
878a2b
    # Redefine positional parameters using ARGUMENTS. At this point,
878a2b
    # option arguments have been removed from ARGUMENTS variable and
878a2b
    # only non-option arguments remain in it. 
878a2b
    eval set -- "$ARGUMENTS"
878a2b
878a2b
    if [[ $@ == '' ]];then
878a2b
878a2b
        # Define default documentation entry. This happens when
878a2b
        # non-option arguments aren't provided to centos-art.sh
878a2b
        # script.  Default documentation entry defined here points to
878a2b
        # manual's main definition file, so only the manual's self
878a2b
        # name and manual's directory name need to be defined here.
878a2b
        MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]='tcar-fs'
878a2b
        MANUAL_DIRN[${MANUAL_DOCENTRY_COUNT}]='Tcar-fs'
878a2b
        MANUAL_DOCENTRY_COUNT=$(($MANUAL_DOCENTRY_COUNT + 1))
878a2b
878a2b
    else
878a2b
878a2b
        # Retrive documentation entries passed to `centos-art.sh'
878a2b
        # script as non-option arguments and store them in array
878a2b
        # variables in order to describe their parts (e.g., manual
878a2b
        # name, chapter name and section name) that way.
878a2b
        # Documentation entries passed as non-opiton arguments must be
878a2b
        # written either in `MANUAL:PART:CHAPTER:SECTION' or
878a2b
        # `path/to/dir' formats in order to be processed correctly
878a2b
        # here. Empty spaces are not permitted. To separate words, use
878a2b
        # the minus sign (e.g., hello-world) or cammel case (e.g.,
878a2b
        # HelloWorld).
878a2b
        for MANUAL_DOCENTRY in $@;do
878a2b
878a2b
            if [[ ${MANUAL_DOCENTRY} =~ '^([A-Za-z0-9-]+)(:[A-Za-z0-9-]*){0,3}$' ]];then
878a2b
878a2b
                # When `MANUAL:PART:CHAPTER:SECTION' is used as format
878a2b
                # to documentation entry, you can specify the manual,
878a2b
                # chapter and section where documentation actions will
878a2b
                # take place on.
878a2b
878a2b
                # Manual self name.
878a2b
                MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
878a2b
                    $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN{ FS=":" } { print $1 }') -f \
878a2b
                    | tr '[:upper:]' '[:lower:]')
878a2b
878a2b
                # Manual self directory name.
878a2b
                MANUAL_DIRN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
878a2b
                    $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN{ FS=":" } { print $1 }') -d )
878a2b
878a2b
                # Manual part name.
878a2b
                MANUAL_PART[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
878a2b
                    $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN{ FS=":" } { print $2 }') -d )
878a2b
878a2b
                # Manual chapter name.
878a2b
                MANUAL_CHAP[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
878a2b
                    $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN{ FS=":" } { print $3 }') -d )
878a2b
878a2b
                # Manual section name.
878a2b
                MANUAL_SECT[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
878a2b
                    $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN{ FS=":" } { print $4 }') -f )
878a2b
878a2b
            elif [[ ${MANUAL_DOCENTRY} =~ '^(trunk|branches|tags)' ]];then
878a2b
878a2b
                # When `path/to/dir' is used as format to
878a2b
                # documentation entry, you cannot specify the manual
878a2b
                # chapter or section where documentation actions will
878a2b
                # take place on. Instead, they are predefined for you
878a2b
                # here. Use this format to document directories inside
878a2b
                # your working copy.
878a2b
878a2b
                # Manual's self name.
878a2b
                MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]='tcar-fs'
878a2b
878a2b
                # Manual's self directory name.
878a2b
                MANUAL_DIRN[${MANUAL_DOCENTRY_COUNT}]='Tcar-fs'
878a2b
878a2b
                # Manual's chapter name.
878a2b
                MANUAL_CHAP[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
878a2b
                    $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS="/" }; { if ( NF >= 1 ) print $1 }' ) -d )
878a2b
878a2b
                # Manual's section name.
878a2b
                MANUAL_SECT[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
878a2b
                    $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS="/" }; { if ( NF >= 2 ) print $0 }' \
878a2b
                    | cut -d/ -f2- | tr '/' '-') -f )
878a2b
878a2b
            else
878a2b
                cli_printMessage "`gettext "The documentation entry provided isn't supported."`" --as-error-line
878a2b
            fi
878a2b
878a2b
            # Increment counting of non-option arguments.
878a2b
            MANUAL_DOCENTRY_COUNT=$(($MANUAL_DOCENTRY_COUNT + 1))
878a2b
878a2b
        done
878a2b
878a2b
    fi
878a2b
878a2b
}