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
#
e6bbbf
# Copyright (C) 2009-2013 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
654704
    # Retrive documentation entries passed to `centos-art.sh' script
654704
    # as non-option arguments and store them in array variables in
654704
    # order to describe their parts (e.g., manual name, chapter name
654704
    # and section name) that way.  Documentation entries passed as
654704
    # non-opiton arguments must be written either in
654704
    # `MANUAL:PART:CHAPTER:SECTION' or `path/to/dir' formats in order
654704
    # to be processed correctly here. Empty spaces are not permitted.
654704
    # To separate words, use the minus sign (e.g., hello-world) or
654704
    # cammel case (e.g., HelloWorld).
654704
    for MANUAL_DOCENTRY in $@;do
878a2b
654704
        if [[ ${MANUAL_DOCENTRY} =~ '^[[:alpha:]][[:alnum:]-]+:([[:alnum:]-]*:){2}[[:alnum:]/]*' ]];then
878a2b
654704
            # When `MANUAL:PART:CHAPTER:SECTION' is used as format to
654704
            # documentation entry, you can specify the manual, chapter
654704
            # and section where documentation actions will take place
654704
            # on.
878a2b
654704
            # Manual self name.
654704
            MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
3b9515
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS=":" } { print $1 }') -f \
654704
                | tr '[:upper:]' '[:lower:]')
878a2b
654704
            # Manual self directory name.
654704
            MANUAL_DIRN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
3b9515
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS=":" } { print $1 }') -d )
878a2b
654704
            # Manual part name.
654704
            MANUAL_PART[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
3b9515
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS=":" } { print $2 }') -d )
878a2b
654704
            # Manual chapter name.
654704
            MANUAL_CHAP[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
3b9515
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS=":" } { print $3 }') -d )
878a2b
654704
            # Manual section name.
654704
            MANUAL_SECT[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
3b9515
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS=":" } { print $4 }' | tr '/' '-') -f )
3b9515
3b9515
        elif [[ ${MANUAL_DOCENTRY} =~ "^(trunk|branches|tags)?(/)?($(ls ${TCAR_WORKDIR} \
3b9515
            | tr '[[:space:]]' '|' | sed 's/|$//'))" ]];then
3b9515
3b9515
            # When we use the `path/to/dir' as format to reach
3b9515
            # documentation entries, you cannot specify the manual
3b9515
            # chapter or section where documentation actions will take
3b9515
            # place on. Instead, they are predefined for you here. Use
3b9515
            # this format to quickly document directories inside your
3b9515
            # working copy.
3b9515
            #
3b9515
            # When we use the `path/to/dir' format to reach
3b9515
            # documentation entries, there is a distinction between
3b9515
            # Subversion and Git version control system we need to be
3b9515
            # aware of.  This is the directory structure layout used
3b9515
            # in the repository.  In Subversion, we use a trunk/,
3b9515
            # branches/, tags/ layout as first level in the repository
3b9515
            # directory structure but, in Git, we don't need such
3b9515
            # special layout in the repository's first directory
3b9515
            # level. The script must be able to understand both
3b9515
            # directory structures.
878a2b
654704
            # Manual's self name.
654704
            MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]='tcar-fs'
878a2b
654704
            # Manual's self directory name.
3b9515
            MANUAL_DIRN[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
3b9515
                ${MANUAL_SLFN[${MANUAL_DOCENTRY_COUNT}]} -d)
878a2b
654704
            # Manual's chapter name.
654704
            MANUAL_CHAP[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
654704
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS="/" }; { if ( NF >= 1 ) print $1 }' ) -d )
878a2b
654704
            # Manual's section name.
654704
            MANUAL_SECT[${MANUAL_DOCENTRY_COUNT}]=$(cli_getRepoName \
654704
                $(echo "${MANUAL_DOCENTRY}" | gawk 'BEGIN { FS="/" }; { if ( NF >= 2 ) print $0 }' \
654704
                | cut -d/ -f2- | tr '/' '-') -f )
878a2b
654704
        else
878a2b
654704
            cli_printMessage "`gettext "The documentation entry provided isn't supported."`" --as-error-line
878a2b
654704
        fi
878a2b
654704
        # Increment counting of non-option arguments.
654704
        MANUAL_DOCENTRY_COUNT=$(($MANUAL_DOCENTRY_COUNT + 1))
878a2b
654704
    done
878a2b
878a2b
}