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

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