Blame Scripts/Functions/Help/Texinfo/texinfo_updateStructureSection.sh

edaa9d
#!/bin/bash
edaa9d
#
edaa9d
# texinfo_updateStructureSection.sh -- This function looks for all
c212d0
# section entry files inside manual's base directory and updates menu,
c212d0
# nodes and cross references definitions for them all, one at a time.
edaa9d
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
edaa9d
#
edaa9d
# This program is free software; you can redistribute it and/or modify
edaa9d
# it under the terms of the GNU General Public License as published by
edaa9d
# the Free Software Foundation; either version 2 of the License, or (at
edaa9d
# your option) any later version.
edaa9d
#
edaa9d
# This program is distributed in the hope that it will be useful, but
edaa9d
# WITHOUT ANY WARRANTY; without even the implied warranty of
edaa9d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
edaa9d
# General Public License for more details.
edaa9d
#
edaa9d
# You should have received a copy of the GNU General Public License
edaa9d
# along with this program; if not, write to the Free Software
edaa9d
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
edaa9d
#
edaa9d
# ----------------------------------------------------------------------
edaa9d
# $Id$
edaa9d
# ----------------------------------------------------------------------
edaa9d
edaa9d
function texinfo_updateStructureSection {
edaa9d
31416c
    # Print action message. These actions might consume some time to
31416c
    # finish. The more section entries the regular expression pattern
31416c
    # matches, the more time it will take to finish.
31416c
    cli_printMessage "`gettext "Updating section menus, nodes and cross references"`" --as-banner-line
bff0d9
edaa9d
    local PATTERN=''
edaa9d
    local MANUAL_ENTRIES=''
d92dde
    local ACTIONNAM_SECMENU=''
d92dde
    local ACTIONNAM_CROSREF=''
edaa9d
bff0d9
    # Define regular expression pattern used to build the list of
bff0d9
    # section entries that will be processed.
d92dde
    if [[ "$1" != '' ]];then
edaa9d
        PATTERN="$1"
edaa9d
    else
c212d0
        PATTERN="${MANUAL_ENTRY}"
c212d0
    fi
bff0d9
c212d0
    # Verify the pattern value considering both the chapter and
c212d0
    # section names. This is required when no chapter or section name
c212d0
    # is provided to `centos-art.sh' script, as non-option argument in
c212d0
    # the command-line (e.g., `centos-art help --update-structure').
c212d0
    if [[ $PATTERN =~ "${MANUAL_NAME}\.${MANUAL_EXTENSION}$" ]] \
c212d0
        || [[ $PATTERN =~ "chapter\.${MANUAL_EXTENSION}$" ]];then
c212d0
        PATTERN="$(dirname ${MANUAL_ENTRY})/.+\.${MANUAL_EXTENSION}"
edaa9d
    fi
edaa9d
bff0d9
    # Define action to perform on menu, nodes and cross references
bff0d9
    # definitions.
d92dde
    case "$2" in 
d92dde
d92dde
        --delete )
d92dde
d92dde
            # Remove menu and node definitions for sections inside
d92dde
            # manual, in order to reflect the changes.
d92dde
            ACTIONNAM_SECMENU='updateSectionMenu --delete-entry'
d92dde
d92dde
            # Remove cross reference definitions inside manual
d92dde
            # structure.
d92dde
            ACTIONNAM_CROSREF='deleteCrossReferences'
d92dde
            ;;
d92dde
d92dde
        --update | * )
d92dde
d92dde
            # Update menu and node definitions for sections inside
d92dde
            # manual, in order to reflect the changes.
d92dde
            ACTIONNAM_SECMENU='updateSectionMenu --add-entry'
d92dde
d92dde
            # Resotre cross reference definitions inside manual
d92dde
            # structure.  If a documentation entry has been removed by
d92dde
            # mistake and that mistake is later fixed by adding the
d92dde
            # removed documentation entry back into the manual
d92dde
            # structure, it is necessary to rebuild the missing cross
d92dde
            # reference information inside the manual structure in
d92dde
            # order to reactivate the removed cross refereces, as
d92dde
            # well.
d92dde
            ACTIONNAM_CROSREF='restoreCrossReferences'
d92dde
            ;;
edaa9d
e7414c
    esac
edaa9d
115094
    # Define list of target entries using find's regular expression
115094
    # pattern as reference. Notice that, when we update section
115094
    # definition files, the files already exist in the working copy so
115094
    # the pattern can be its absolute path without any problem. If the
115094
    # pattern is built correctly, it will match the location and so be
115094
    # returned to build the list of entries to process. Notice also
115094
    # that, when updating, it is possible to use a regular expression
115094
    # to match more than one location and build the list of entries
115094
    # based on such matching.  In this last configuration, let you to
115094
    # update menu, nodes and cross references to many section
115094
    # definitions (i.e., all those section definition file that match
115094
    # the pattern you specified). 
115094
    MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR_L10N} \
bff0d9
        --pattern="${PATTERN}" | egrep -v "/(${MANUAL_NAME}|chapter)")
115094
115094
    # Verify list of target entries. Assuming is is empty,  define
115094
    # list of target documentation entries using pattern as reference
115094
    # instead.  When we delete a section entry from the working copy,
115094
    # using find to retrive its path isn't possible because the
115094
    # section definition file is removed before executing find and by
115094
    # consequence no match is found.  This issue provokes no section
115094
    # entry to be removed from menu, nodes and cross references. In
115094
    # order to solve this, use the pattern value as list of target
115094
    # entries.  Notice that, in this case, the pattern value must be
115094
    # the absolute path to that documentation entry which doesn't
115094
    # exist and we want to update menu, nodes and cross references
115094
    # information for.
31416c
    if [[ $MANUAL_ENTRIES == '' ]] && [[ $PATTERN =~ '^[[:alnum:]./_-]+$' ]];then
bff0d9
        MANUAL_ENTRIES=${PATTERN}
115094
    fi
115094
31416c
    # Verify list of target entries. Assumming it is still empty,
31416c
    # there is nothing else to do here but printing an error message
31416c
    # describing the fact that no section entry was found to process.
bff0d9
    if [[ $MANUAL_ENTRIES == '' ]];then
bff0d9
        cli_printMessage "`gettext "No section entry found to process."`" --as-error-line
bff0d9
    fi
edaa9d
31416c
    # Loop through target documentation entries in order to update the
c212d0
    # documentation structure (e.g., it is not enough with copying
edaa9d
    # documentation entry files, it is also needed to update menu,
edaa9d
    # nodes and related cross-references).
edaa9d
    for MANUAL_ENTRY in ${MANUAL_ENTRIES};do
31416c
        cli_printMessage "${MANUAL_ENTRY}" --as-response-line
d92dde
        ${FLAG_BACKEND}_${ACTIONNAM_SECMENU}
4e0284
        ${FLAG_BACKEND}_updateSectionNodes
bff0d9
        ${FLAG_BACKEND}_makeSeeAlso "${MANUAL_ENTRY}"
31416c
        ${FLAG_BACKEND}_${ACTIONNAM_CROSREF} "${MANUAL_ENTRY}"
edaa9d
    done
e7414c
edaa9d
}