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

4c79b5
#!/bin/bash
4c79b5
#
60a25c
# texinfo_updateSectionMenu.sh -- This function updates the section's
60a25c
# menu definition file of a chapter.  If this function is called with
d92dde
# the '--delete-entry' string as first argument, the menu line related
60a25c
# to the entry being processed is removed. Otherwise, if this function
d92dde
# is called with the '--add-entry' string as first argument, the menu
60a25c
# line related to the entry being processed is added to menu's bottom.
d92dde
# If no argument is passed to this function, the '--add-entry' action
60a25c
# is assumed.
4c79b5
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
60a25c
function texinfo_updateSectionMenu {
4c79b5
edaa9d
    # Specify which action to do with documentation entry inside the
edaa9d
    # chapter menu.
4c79b5
    local ACTION="$1"
4c79b5
59df1a
    # Define section order. Through this property you can customize
59df1a
    # the section order inside the manual.  Possible arguments to this
59df1a
    # option are `ordered', `reversed', `created'.  From these three
59df1a
    # values `created' is used by default (i.e., new menu entries are
59df1a
    # added to menu's bottom as last entry.).  Notice that, once
59df1a
    # you've sorted the menu using `ordered' or `reversed' values, it
59df1a
    # is hard to sort the list back to former creation orders. Go
59df1a
    # sorted or not sorted at all.
59df1a
    local MANUAL_SECTION_ORDER=$(cli_getConfigValue "${MANUAL_CONFIG_FILE}" "main" "manual_section_order")
59df1a
    if [[ ! $MANUAL_SECTION_ORDER =~ '^(created|ordered|reversed)$' ]];then
59df1a
        MANUAL_SECTION_ORDER='created'
59df1a
    fi
59df1a
edaa9d
    # Build node information used inside chapter menu.
ef43e2
    local MENUNODE=$(texinfo_getEntryNode "$MANUAL_ENTRY")
e124a8
edaa9d
    # Define menu entry using texinfo style and node information as
edaa9d
    # reference.
d92dde
    local MENULINE="* ${MENUNODE}::" 
4c79b5
edaa9d
    # Retrive list of menu entries from chapter menu and exclude
edaa9d
    # `@menu', `@end menu' and empty lines from output.
3cc2c7
    local MENU=$(cat $(dirname ${MANUAL_ENTRY})/chapter-menu.${MANUAL_EXTENSION} \
272536
        | egrep -v '^[[:space:]]*$' | egrep -v '^@(end )?menu')
4c79b5
edaa9d
    # Re-defined chapter menu entries based on action provided to this
edaa9d
    # function as first positional parameter.
4c79b5
    case $ACTION in
e124a8
d92dde
        --delete-entry )
edaa9d
            # Remove menu entry from chapter menu.
3cc2c7
            MENU="$(echo "$MENU" | egrep -v "$MENULINE")"
4c79b5
            ;;
e124a8
d92dde
        --add-entry | * )
edaa9d
            # Add menu entry to chapter menu list as last entry.
3cc2c7
            MENU="$(echo "$MENU" | egrep -v "$MENULINE" )
3cc2c7
                ${MENULINE}"
4c79b5
            ;;
edaa9d
4c79b5
    esac
4c79b5
6819ed
    # Remove opening spaces/tabs and empty lines from final menu
6819ed
    # entries.
6819ed
    MENU=$(echo "$MENU" | sed -r 's!^[[:space:]]+!!g' \
6819ed
        | egrep -v '^[[:space:]]*$')
6819ed
59df1a
    # Sort menu entries based on section order property.
59df1a
    case $MANUAL_SECTION_ORDER in
6819ed
6819ed
        'ordered' )
6819ed
            MENU="$(echo "$MENU" | sort )"
6819ed
            ;;
6819ed
6819ed
        'reversed' )
6819ed
            MENU="$(echo "$MENU" | sort -r )"
6819ed
            ;;
6819ed
6819ed
    esac
6819ed
edaa9d
    # Rebuild list of chapter menu entries including '@menu' and '@end
edaa9d
    # menu' lines back into chapter menu.
4c79b5
    MENU="@menu
4c79b5
    $MENU
4c79b5
    @end menu"
4c79b5
d92dde
    # Remove opening spaces/tabs and empty lines from final menu
d92dde
    # structure.
d92dde
    MENU=$(echo "$MENU" | sed -r 's!^[[:space:]]+!!g' \
d92dde
        | egrep -v '^[[:space:]]*$')
4c79b5
edaa9d
    # Dump chapter menu entries back into chapter's menu definition
edaa9d
    # file.
3cc2c7
    echo "$MENU" > $(dirname ${MANUAL_ENTRY})/chapter-menu.${MANUAL_EXTENSION}
4c79b5
4c79b5
}