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

edaa9d
#!/bin/bash
edaa9d
#
edaa9d
# texinfo_updateStructureSection.sh -- This function looks for all
d92dde
# documentation entry (section) files inside manual's base directory
d92dde
# and updates menu, nodes and cross references definitions for them
d92dde
# all, one at a time.
edaa9d
#
edaa9d
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
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
edaa9d
    local PATTERN=''
edaa9d
    local MANUAL_ENTRY=''
edaa9d
    local MANUAL_ENTRIES=''
d92dde
    local ACTIONNAM_SECMENU=''
d92dde
    local ACTIONNAM_CROSREF=''
edaa9d
edaa9d
    # Define find's regular expression pattern.
d92dde
    if [[ "$1" != '' ]];then
edaa9d
        PATTERN="$1"
edaa9d
    else
edaa9d
        PATTERN=".+\.${MANUAL_EXTENSION}"
edaa9d
    fi
edaa9d
d92dde
    # Define action to perform on 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} \
115094
        --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.
115094
    if [[ $MANUAL_ENTRIES == '' ]];then
115094
        MANUAL_ENTRIES=$PATTERN
115094
    fi
115094
edaa9d
    # Print action message.
edaa9d
    cli_printMessage "`gettext "Updating section menus, nodes and cross references."`" --as-response-line
edaa9d
edaa9d
    # Loop through target documentation entries in order to update
edaa9d
    # the 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
d92dde
        ${FLAG_BACKEND}_${ACTIONNAM_SECMENU}
4e0284
        ${FLAG_BACKEND}_updateSectionNodes
d92dde
        ${FLAG_BACKEND}_${ACTIONNAM_CROSREF} ${MANUAL_ENTRY}
edaa9d
    done
e7414c
edaa9d
}