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
e7414c
    # Define manual entries based on pattern.
e7414c
    if [[ -a $PATTERN ]];then
e7414c
e7414c
        # Define list of target documentation entries using find's
e7414c
        # regular expression pattern as reference. Notice that, when
e7414c
        # wer update section definition files, the files already exist
e7414c
        # in the working copy so the pattern can be its absolute path
e7414c
        # without any problem. If the pattern is built correctly, it
e7414c
        # will match the location and so be returned to build the list
e7414c
        # of entries to process. Notice also that, when updating, it
e7414c
        # is possible to use a regular expression to match more than
e7414c
        # one location and build the list of entries based on such
e7414c
        # matching.  In this last configuration, let you to update
e7414c
        # menu, nodes and cross references to many section definitions
e7414c
        # (i.e., all those section definition file that match the
e7414c
        # pattern you specified). 
e7414c
        MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR_L10N} \
e7414c
            --pattern="$PATTERN" | egrep -v "/(${MANUAL_NAME}|chapter)")
e7414c
e7414c
    else
e7414c
    
e7414c
        # Define list of target documentation entries using pattern as
e7414c
        # reference. When we delete a section entry from the working
e7414c
        # copy, using find to retrive its path isn't useful because
e7414c
        # the section definition file has been already removed from
e7414c
        # the working copy and even the regex pattern be correctly
e7414c
        # formed, the file doesn't exist and by consequence no match
e7414c
        # is found.  This issue provokes no section entry to be
e7414c
        # removed from menu, nodes and cross references. In order to
e7414c
        # solve this, use the pattern value as list of target entries.
e7414c
        # Notice that, in this case, the pattern value must be the
e7414c
        # absolute path of that section entry removed we want to
e7414c
        # update menu, nodes and cross references information for.
e7414c
        MANUAL_ENTRIES=$PATTERN
e7414c
e7414c
    fi
e7414c
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
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
}