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

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