Blame Scripts/Functions/Help/Backends/Texinfo/texinfo_updateMenu.sh

4c79b5
#!/bin/bash
4c79b5
#
1afa3c
# texinfo_updateMenu.sh -- This function updates menu lines inside
4c79b5
# texinfo chapters.  If this function is called with the
4c79b5
# 'remove-entry' string as first argument, then the menu line related
4c79b5
# to the entry being processed is removed. If this function is called
4c79b5
# with the 'update-entry' string as first argument, then the menu line
4c79b5
# related to the entry being processed is added to the menu. If no
4c79b5
# argument is passed to this function, the 'update-entry' action is
4c79b5
# assumed.
4c79b5
#
2d3646
# 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
1afa3c
function texinfo_updateMenu {
4c79b5
4c79b5
    # Specify which action to do inside chapter's menu.
4c79b5
    local ACTION="$1"
4c79b5
4da029
    # Build the menu node related to the entry being processed
4c79b5
    # currently.
96fb67
    local MENUNODE=$(echo "$MANUAL_ENTRY" | cut -d / -f9- | tr '/' ' ' \
e124a8
        | sed "s/\.${FLAG_BACKEND}$//")
e124a8
4c79b5
    # Give format to menu line using texinfo style.
4da029
    local MENULINE="* ${MANUAL_CHAPTER_NAME} $MENUNODE::" 
4c79b5
4c79b5
    # Define chapter's menu. Remove `@menu', `@end menu', and empty lines
4c79b5
    # from output.
66b6ae
    local MENU=$(cat $MANUAL_CHAPTER_DIR/chapter-menu.${FLAG_BACKEND} \
4c79b5
        | egrep -v '^[[:space:]]*$' | egrep -v '^@(end )?menu') 
4c79b5
4c79b5
    # Re-defined chapter's menu based on action.
4c79b5
    case $ACTION in
e124a8
4c79b5
        'remove-entry' )
4c79b5
            # Remove menu line from chapter's menu.
4c79b5
            MENU=$(echo "$MENU"  | egrep -v "$MENULINE")
4c79b5
            ;;
e124a8
4c79b5
        'update-entry' | * )
4c79b5
            # Add menu line to chapter's menu. This is the default
1afa3c
            # behaivour if no argument is passed to texinfo_updateMenu
4c79b5
            # function.
4c79b5
            MENU="$MENU
4c79b5
            $MENULINE"
4c79b5
            ;;
4c79b5
    esac
4c79b5
4c79b5
    # Organize menu alphabetically, remove empty and duplicated lines.
4c79b5
    # At this point, empty line may occur the first time the menu is
4c79b5
    # created, don't let them to scape.
4c79b5
    MENU=$(echo "$MENU" | egrep -v '^[[:space:]]*$' | sort | uniq )
4c79b5
4c79b5
    # Rebuild chapter's menu structure adding '@menu' and '@end menu'
4c79b5
    # lines back in menu.
4c79b5
    MENU="@menu
4c79b5
    $MENU
4c79b5
    @end menu"
4c79b5
4c79b5
    # Remove opening spaces/tabs from final menu structure.
4c79b5
    MENU=$(echo "$MENU" | sed -r 's!^[[:space:]]+!!g')
4c79b5
4c79b5
    # Dump final menu structure back into chapter's menu file.
66b6ae
    echo "$MENU" > $MANUAL_CHAPTER_DIR/chapter-menu.${FLAG_BACKEND}
4c79b5
4c79b5
}