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

878a2b
#!/bin/bash
878a2b
#
878a2b
# texinfo_updateChapterMenu.sh -- This function updates chapter menu.
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_updateChapterMenu {
878a2b
878a2b
    local ACTION=$1
878a2b
    local MENUCHAPTERS=''
878a2b
a79a46
    # Print action name.
a79a46
    cli_printMessage "${MANUAL_BASEFILE}-menu.${MANUAL_EXTENSION}" --as-creating-line
a79a46
878a2b
    # Build menu of chapters. The Index node is not included as other
878a2b
    # nodes are. The Index node is defined inside the master texinfo
878a2b
    # file (repository.texinfo) as an included file. To create the final
878a2b
    # .info file correctly, the Index line in the menu should remain,
878a2b
    # even no other node exist.
878a2b
    if [[ -f ${MANUAL_BASEFILE}-menu.${MANUAL_EXTENSION} ]];then
878a2b
        MENUCHAPTERS=$(cat ${MANUAL_BASEFILE}-menu.${MANUAL_EXTENSION} \
878a2b
            | egrep -v "^@(end )?menu$" \
878a2b
            | egrep -v '^\* (Licenses|Index)::$')
878a2b
    fi
878a2b
878a2b
    # Re-defined menu of chapters based on action.
878a2b
    case $ACTION in
878a2b
878a2b
        --delete-entry )
878a2b
            # Remove chapter from menu.
878a2b
            MENUCHAPTERS=$(echo "${MENUCHAPTERS}" \
878a2b
                | egrep -v '^\* '"${MANUAL_CHAPTER_NAME}"'::[[:print:]]*$')
878a2b
            ;;
878a2b
878a2b
        --add-entry | * )
878a2b
            # Update chapter menu using texinfo format. Be sure the
878a2b
            # chapter node itself is not included here, that would
878a2b
            # duplicate it inside the menu definition file which end
878a2b
            # up being a definition error. Take care the way you quote
878a2b
            # egrep's pattern, prevent to end up using the syntax
878a2b
            # `$"..."' which has security risks.
878a2b
            MENUCHAPTERS="$(echo "${MENUCHAPTERS}" \
878a2b
                | egrep -v '\* '"${MANUAL_CHAPTER_NAME}"'::[[:print:]]*$')
878a2b
                * ${MANUAL_CHAPTER_NAME}::"
878a2b
            ;;
878a2b
    esac
878a2b
878a2b
    # Remove opening spaces/tabs and empty line from the menu of
878a2b
    # chapters. Empty lines may occur the first time the menu of
878a2b
    # chapters is created.
878a2b
    MENUCHAPTERS=$(echo "${MENUCHAPTERS}" | sed -r 's!^[[:space:]]+!!' \
878a2b
        | egrep -v '^[[:space:]]*$')
878a2b
878a2b
    # Organize menu of chapters alphabetically and verify that no
878a2b
    # duplicated line be included on the list. Notice that organizing
123ee8
    # menu this way suppresses the idea of putting the last chapter
878a2b
    # created at the end of the list. 
878a2b
    #MENUCHAPTERS=$(echo "${MENUCHAPTERS}" | sort | uniq)
878a2b
878a2b
    # Give format to final menu output.
878a2b
    MENUCHAPTERS="@menu
878a2b
    ${MENUCHAPTERS}
878a2b
    * Licenses::
878a2b
    * Index::
878a2b
    @end menu"
878a2b
878a2b
    # Remove opening space/tabs from menu's final definition.
878a2b
    MENUCHAPTERS=$(echo "${MENUCHAPTERS}" | sed -r 's!^[[:space:]]+!!' \
878a2b
        | egrep -v '^[[:space:]]*$')
878a2b
878a2b
    # Dump organized menu of chapters into file.
878a2b
    echo "${MENUCHAPTERS}" > ${MANUAL_BASEFILE}-menu.${MANUAL_EXTENSION}
878a2b
878a2b
}