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

878a2b
#!/bin/bash
878a2b
#
878a2b
# texinfo_updateSectionMenu.sh -- This function updates the section's
878a2b
# menu definition file of a chapter.  If this function is called with
878a2b
# the '--delete-entry' string as first argument, the menu line related
878a2b
# to the entry being processed is removed. Otherwise, if this function
878a2b
# is called with the '--add-entry' string as first argument, the menu
878a2b
# line related to the entry being processed is added to menu's bottom.
878a2b
# If no argument is passed to this function, the '--add-entry' action
878a2b
# is assumed.
878a2b
#
e6bbbf
# Copyright (C) 2009-2013 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_updateSectionMenu {
878a2b
878a2b
    # Specify which action to do with documentation entry inside the
878a2b
    # chapter menu.
878a2b
    local ACTION="$1"
878a2b
878a2b
    # Define section order. Through this property you can customize
878a2b
    # the section order inside the manual.  Possible arguments to this
878a2b
    # option are `ordered', `reversed', `created'.  From these three
878a2b
    # values `created' is used by default (i.e., new menu entries are
878a2b
    # added to menu's bottom as last entry.).  Notice that, once
878a2b
    # you've sorted the menu using `ordered' or `reversed' values, it
878a2b
    # is hard to sort the list back to former creation orders. Go
878a2b
    # sorted or not sorted at all.
878a2b
    local MANUAL_SECTION_ORDER=$(cli_getConfigValue "${MANUAL_CONFIG_FILE}" "main" "manual_section_order")
878a2b
    if [[ ! $MANUAL_SECTION_ORDER =~ '^(created|ordered|reversed)$' ]];then
878a2b
        MANUAL_SECTION_ORDER='created'
878a2b
    fi
878a2b
878a2b
    # Build node information used inside chapter menu.
878a2b
    local MENUNODE=$(texinfo_getEntryNode "$MANUAL_ENTRY")
878a2b
878a2b
    # Define menu entry using texinfo style and node information as
878a2b
    # reference.
878a2b
    local MENULINE="* ${MENUNODE}::" 
878a2b
123ee8
    # Retrieve list of menu entries from chapter menu and exclude
878a2b
    # `@menu', `@end menu' and empty lines from output.
123ee8
    local MENU=$(cat  ${MENUFILE} \
878a2b
        | egrep -v '^[[:space:]]*$' | egrep -v '^@(end )?menu')
878a2b
878a2b
    # Re-defined chapter menu entries based on action provided to this
878a2b
    # function as first positional parameter.
878a2b
    case $ACTION in
878a2b
878a2b
        --delete-entry )
878a2b
            # Remove menu entry from chapter menu.
878a2b
            MENU="$(echo "$MENU" | egrep -v "$MENULINE")"
878a2b
            ;;
878a2b
878a2b
        --add-entry | * )
878a2b
            # Add menu entry to chapter menu list as last entry.
878a2b
            MENU="$(echo "$MENU" | egrep -v "$MENULINE" )
878a2b
                ${MENULINE}"
878a2b
            ;;
878a2b
878a2b
    esac
878a2b
878a2b
    # Remove opening spaces/tabs and empty lines from final menu
878a2b
    # entries.
878a2b
    MENU=$(echo "$MENU" | sed -r 's!^[[:space:]]+!!g' \
878a2b
        | egrep -v '^[[:space:]]*$')
878a2b
878a2b
    # Sort menu entries based on section order property.
878a2b
    case $MANUAL_SECTION_ORDER in
878a2b
878a2b
        'ordered' )
878a2b
            MENU="$(echo "$MENU" | sort )"
878a2b
            ;;
878a2b
878a2b
        'reversed' )
878a2b
            MENU="$(echo "$MENU" | sort -r )"
878a2b
            ;;
878a2b
878a2b
    esac
878a2b
878a2b
    # Rebuild list of chapter menu entries including '@menu' and '@end
878a2b
    # menu' lines back into chapter menu.
878a2b
    MENU="@menu
878a2b
    $MENU
878a2b
    @end menu"
878a2b
878a2b
    # Remove opening spaces/tabs and empty lines from final menu
878a2b
    # structure.
878a2b
    MENU=$(echo "$MENU" | sed -r 's!^[[:space:]]+!!g' \
878a2b
        | egrep -v '^[[:space:]]*$')
878a2b
878a2b
    # Dump chapter menu entries back into chapter's menu definition
878a2b
    # file.
123ee8
    echo "$MENU" > ${MENUFILE}
878a2b
878a2b
}