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
            ;;
d92dde
    esac
d92dde
edaa9d
    # Define list of target documentation entries using find's regular
edaa9d
    # expression pattern as reference. This is required in order to
edaa9d
    # process non-existent documentation entries (e.g., when they are
edaa9d
    # created for first time). Otherwise, the list of documentation
edaa9d
    # entries will be empty an no entry would be processed.
edaa9d
    if [[ ${PATTERN} =~ '^/.+\.texinfo$' ]];then
edaa9d
edaa9d
        # When the pattern value is an absolute path to a
edaa9d
        # documentation entry, use that value as only documentation
edaa9d
        # entry in the list.
edaa9d
        MANUAL_ENTRIES=${PATTERN}
edaa9d
edaa9d
    else
edaa9d
edaa9d
        # When the pattern value is a regular expression, use
edaa9d
        # cli_getFilesList to build the list of documentation entries
edaa9d
        # using it.  Don't include manual or chapter definition files
edaa9d
        # in this list, it would create documentation entries for them
edaa9d
        # and that shouldn't happen.
5e989a
        MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR} \
edaa9d
            --pattern="$PATTERN" | egrep -v "/(${MANUAL_NAME}|chapter)")
edaa9d
    fi
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
edaa9d
}