Blame Automation/Modules/Help/Texinfo/texinfo_updateStructureSection.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# texinfo_updateStructureSection.sh -- This function looks for all
Alain Reguera Delgado 8f60cb
# section entries (i.e., files holding section definitions) inside the
Alain Reguera Delgado 8f60cb
# manual's base directory and updates menu, nodes and cross references
Alain Reguera Delgado 8f60cb
# definitions for them all, one at a time.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function texinfo_updateStructureSection {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local PATTERN="${1}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define regular expression pattern used to build list of section
Alain Reguera Delgado 8f60cb
    # entries when pattern points to manual's file name or it is not
Alain Reguera Delgado 8f60cb
    # provided at all.
Alain Reguera Delgado 8f60cb
    if [[ $PATTERN =~ "${MANUAL_NAME}\.${MANUAL_EXTENSION}$" ]] \
Alain Reguera Delgado 8f60cb
        || [[ $PATTERN == '' ]]; then
Alain Reguera Delgado 8f60cb
        PATTERN="/.+\.${MANUAL_EXTENSION}$"
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local MANUAL_ENTRY=''
Alain Reguera Delgado 8f60cb
    local MANUAL_ENTRIES=''
Alain Reguera Delgado 8f60cb
    local ACTIONNAM_SECMENU=''
Alain Reguera Delgado 8f60cb
    local ACTIONNAM_CROSREF=''
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define action to perform on menu, nodes and cross references
Alain Reguera Delgado 8f60cb
    # definitions.
Alain Reguera Delgado 8f60cb
    case "$2" in 
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        --delete )
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Remove menu and node definitions for sections inside
Alain Reguera Delgado 8f60cb
            # manual, in order to reflect the changes.
Alain Reguera Delgado 8f60cb
            ACTIONNAM_SECMENU='texinfo_updateSectionMenu --delete-entry'
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Remove cross reference definitions inside manual
Alain Reguera Delgado 8f60cb
            # structure.
Alain Reguera Delgado 8f60cb
            ACTIONNAM_CROSREF='texinfo_deleteCrossReferences'
Alain Reguera Delgado 8f60cb
            ;;
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        --update | * )
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Update menu and node definitions for sections inside
Alain Reguera Delgado 8f60cb
            # manual, in order to reflect the changes.
Alain Reguera Delgado 8f60cb
            ACTIONNAM_SECMENU='texinfo_updateSectionMenu --add-entry'
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
            # Restore cross reference definitions inside manual
Alain Reguera Delgado 8f60cb
            # structure.  If a documentation entry has been removed by
Alain Reguera Delgado 8f60cb
            # mistake and that mistake is later fixed by adding the
Alain Reguera Delgado 8f60cb
            # removed documentation entry back into the manual
Alain Reguera Delgado 8f60cb
            # structure, it is necessary to rebuild the missing cross
Alain Reguera Delgado 8f60cb
            # reference information inside the manual structure in
Alain Reguera Delgado 8f60cb
            # order to reactivate the removed cross references, as
Alain Reguera Delgado 8f60cb
            # well.
Alain Reguera Delgado 8f60cb
            ACTIONNAM_CROSREF='texinfo_restoreCrossReferences'
Alain Reguera Delgado 8f60cb
            ;;
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    esac
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define list of target entries using find's regular expression
Alain Reguera Delgado 8f60cb
    # pattern as reference. Notice that, when we update section
Alain Reguera Delgado 8f60cb
    # definition files, the files already exist in the working copy so
Alain Reguera Delgado 8f60cb
    # the pattern can be its absolute path without any problem. If the
Alain Reguera Delgado 8f60cb
    # pattern is built correctly, it will match the location and so be
Alain Reguera Delgado 8f60cb
    # returned to build the list of entries to process. Notice also
Alain Reguera Delgado 8f60cb
    # that, when updating, it is possible to use a regular expression
Alain Reguera Delgado 8f60cb
    # to match more than one location and build the list of entries
Alain Reguera Delgado 8f60cb
    # based on such matching.  In this last configuration, let you to
Alain Reguera Delgado 8f60cb
    # update menu, nodes and cross references to many section
Alain Reguera Delgado 8f60cb
    # definitions (i.e., all those section definition file that match
Alain Reguera Delgado 8f60cb
    # the pattern you specified). 
Alain Reguera Delgado 8f60cb
    MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR_L10N} \
Alain Reguera Delgado 8f60cb
        --pattern="${PATTERN}" --mindepth="2" --maxdepth="2")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify list of target entries. Assuming is is empty,  define
Alain Reguera Delgado 8f60cb
    # list of target documentation entries using pattern as reference
Alain Reguera Delgado 8f60cb
    # instead.  When we delete a section entry from the working copy,
Alain Reguera Delgado 8f60cb
    # using find to retrieve its path isn't possible because the
Alain Reguera Delgado 8f60cb
    # section definition file is removed before executing find and by
Alain Reguera Delgado 8f60cb
    # consequence no match is found.  This issue provokes no section
Alain Reguera Delgado 8f60cb
    # entry to be removed from menu, nodes and cross references. In
Alain Reguera Delgado 8f60cb
    # order to solve this, use the pattern value as list of target
Alain Reguera Delgado 8f60cb
    # entries.  Notice that, in this case, the pattern value must be
Alain Reguera Delgado 8f60cb
    # the absolute path to that documentation entry which doesn't
Alain Reguera Delgado 8f60cb
    # exist and we want to update menu, nodes and cross references
Alain Reguera Delgado 8f60cb
    # information for.
Alain Reguera Delgado 8f60cb
    if [[ $MANUAL_ENTRIES == '' ]] && [[ $PATTERN =~ '^/[[:alnum:]./_-]+$' ]];then
Alain Reguera Delgado 8f60cb
        MANUAL_ENTRIES=${PATTERN}
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify list of target entries. Assuming it is still empty, there
Alain Reguera Delgado 8f60cb
    # is nothing else to do here but printing an error message
Alain Reguera Delgado 8f60cb
    # describing the fact that no section entry was found to process.
Alain Reguera Delgado 8f60cb
    if [[ $MANUAL_ENTRIES == '' ]];then
Alain Reguera Delgado 8f60cb
        cli_printMessage "`gettext "There wasn't any section for processing found."`" --as-error-line
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Loop through target documentation entries in order to update the
Alain Reguera Delgado 8f60cb
    # documentation structure (e.g., it is not enough with copying
Alain Reguera Delgado 8f60cb
    # documentation entry files, it is also needed to update menu,
Alain Reguera Delgado 8f60cb
    # nodes and related cross-references).
Alain Reguera Delgado 8f60cb
    for MANUAL_ENTRY in ${MANUAL_ENTRIES};do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define menu file based on manual entry. We use the menu file
Alain Reguera Delgado 8f60cb
        # as reference to build the nodes files and update the menu
Alain Reguera Delgado 8f60cb
        # file itself based on available section files.
Alain Reguera Delgado 8f60cb
        local MENUFILE=$(dirname ${MANUAL_ENTRY} \
Alain Reguera Delgado 8f60cb
            | sed -r 's,/$,,')-menu.${MANUAL_EXTENSION}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Don't print action name here. Instead, make it integral part
Alain Reguera Delgado 8f60cb
        # of documentation entry creation process.
Alain Reguera Delgado 8f60cb
        #cli_printMessage "${MANUAL_ENTRY}" --as-stdout-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        ${ACTIONNAM_SECMENU}
Alain Reguera Delgado 8f60cb
        texinfo_updateSectionNodes
Alain Reguera Delgado 8f60cb
        texinfo_makeSeeAlso "${MANUAL_ENTRY}"
Alain Reguera Delgado 8f60cb
        ${ACTIONNAM_CROSREF} "${MANUAL_ENTRY}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}