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

878a2b
#!/bin/bash
878a2b
#
878a2b
# texinfo_updateStructureSection.sh -- This function looks for all
123ee8
# section entries (i.e., files holding section definitions) inside the
123ee8
# manual's base directory and updates menu, nodes and cross references
123ee8
# definitions for them all, one at a time.
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 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 texinfo_updateStructureSection {
878a2b
802774
    local PATTERN="${1}"
878a2b
123ee8
    # Define regular expression pattern used to build list of section
123ee8
    # entries when pattern points to manual's file name or it is not
123ee8
    # provided at all.
878a2b
    if [[ $PATTERN =~ "${MANUAL_NAME}\.${MANUAL_EXTENSION}$" ]] \
123ee8
        || [[ $PATTERN == '' ]]; then
123ee8
        PATTERN="/.+\.${MANUAL_EXTENSION}$"
878a2b
    fi
878a2b
802774
    local MANUAL_ENTRY=''
802774
    local MANUAL_ENTRIES=''
802774
    local ACTIONNAM_SECMENU=''
802774
    local ACTIONNAM_CROSREF=''
802774
878a2b
    # Define action to perform on menu, nodes and cross references
878a2b
    # definitions.
878a2b
    case "$2" in 
878a2b
878a2b
        --delete )
878a2b
878a2b
            # Remove menu and node definitions for sections inside
878a2b
            # manual, in order to reflect the changes.
123ee8
            ACTIONNAM_SECMENU='texinfo_updateSectionMenu --delete-entry'
878a2b
878a2b
            # Remove cross reference definitions inside manual
878a2b
            # structure.
123ee8
            ACTIONNAM_CROSREF='texinfo_deleteCrossReferences'
878a2b
            ;;
878a2b
878a2b
        --update | * )
878a2b
878a2b
            # Update menu and node definitions for sections inside
878a2b
            # manual, in order to reflect the changes.
123ee8
            ACTIONNAM_SECMENU='texinfo_updateSectionMenu --add-entry'
878a2b
123ee8
            # Restore cross reference definitions inside manual
878a2b
            # structure.  If a documentation entry has been removed by
878a2b
            # mistake and that mistake is later fixed by adding the
878a2b
            # removed documentation entry back into the manual
878a2b
            # structure, it is necessary to rebuild the missing cross
878a2b
            # reference information inside the manual structure in
123ee8
            # order to reactivate the removed cross references, as
878a2b
            # well.
123ee8
            ACTIONNAM_CROSREF='texinfo_restoreCrossReferences'
878a2b
            ;;
878a2b
878a2b
    esac
878a2b
878a2b
    # Define list of target entries using find's regular expression
878a2b
    # pattern as reference. Notice that, when we update section
878a2b
    # definition files, the files already exist in the working copy so
878a2b
    # the pattern can be its absolute path without any problem. If the
878a2b
    # pattern is built correctly, it will match the location and so be
878a2b
    # returned to build the list of entries to process. Notice also
878a2b
    # that, when updating, it is possible to use a regular expression
878a2b
    # to match more than one location and build the list of entries
878a2b
    # based on such matching.  In this last configuration, let you to
878a2b
    # update menu, nodes and cross references to many section
878a2b
    # definitions (i.e., all those section definition file that match
878a2b
    # the pattern you specified). 
878a2b
    MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR_L10N} \
123ee8
        --pattern="${PATTERN}" --mindepth="2" --maxdepth="2")
878a2b
878a2b
    # Verify list of target entries. Assuming is is empty,  define
878a2b
    # list of target documentation entries using pattern as reference
878a2b
    # instead.  When we delete a section entry from the working copy,
123ee8
    # using find to retrieve its path isn't possible because the
878a2b
    # section definition file is removed before executing find and by
878a2b
    # consequence no match is found.  This issue provokes no section
878a2b
    # entry to be removed from menu, nodes and cross references. In
878a2b
    # order to solve this, use the pattern value as list of target
878a2b
    # entries.  Notice that, in this case, the pattern value must be
878a2b
    # the absolute path to that documentation entry which doesn't
878a2b
    # exist and we want to update menu, nodes and cross references
878a2b
    # information for.
228c64
    if [[ $MANUAL_ENTRIES == '' ]] && [[ $PATTERN =~ '^/[[:alnum:]./_-]+$' ]];then
878a2b
        MANUAL_ENTRIES=${PATTERN}
878a2b
    fi
878a2b
c15d00
    # Verify list of target entries. Assuming it is still empty, there
c15d00
    # is nothing else to do here but printing an error message
878a2b
    # describing the fact that no section entry was found to process.
878a2b
    if [[ $MANUAL_ENTRIES == '' ]];then
54c0ab
        cli_printMessage "`gettext "There wasn't any section for processing found."`" --as-error-line
878a2b
    fi
878a2b
878a2b
    # Loop through target documentation entries in order to update the
878a2b
    # documentation structure (e.g., it is not enough with copying
878a2b
    # documentation entry files, it is also needed to update menu,
878a2b
    # nodes and related cross-references).
878a2b
    for MANUAL_ENTRY in ${MANUAL_ENTRIES};do
c15d00
123ee8
        # Define menu file based on manual entry. We use the menu file
123ee8
        # as reference to build the nodes files and update the menu
123ee8
        # file itself based on available section files.
123ee8
        local MENUFILE=$(dirname ${MANUAL_ENTRY} \
123ee8
            | sed -r 's,/$,,')-menu.${MANUAL_EXTENSION}
123ee8
2cac4b
        # Don't print action name here. Instead, make it integral part
2cac4b
        # of documentation entry creation process.
123ee8
        #cli_printMessage "${MANUAL_ENTRY}" --as-stdout-line
c15d00
123ee8
        ${ACTIONNAM_SECMENU}
878a2b
        texinfo_updateSectionNodes
878a2b
        texinfo_makeSeeAlso "${MANUAL_ENTRY}"
123ee8
        ${ACTIONNAM_CROSREF} "${MANUAL_ENTRY}"
c15d00
878a2b
    done
878a2b
878a2b
}