|
|
4c79b5 |
#!/bin/bash
|
|
|
4c79b5 |
#
|
|
|
4de5d4 |
# manual_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 |
#
|
|
|
9f5f2e |
# Copyright (C) 2009-2011 Alain Reguera Delgado
|
|
|
4c79b5 |
#
|
|
|
7cd8e9 |
# This program is free software; you can redistribute it and/or
|
|
|
7cd8e9 |
# modify it under the terms of the GNU General Public License as
|
|
|
7cd8e9 |
# published by the Free Software Foundation; either version 2 of the
|
|
|
7cd8e9 |
# License, or (at your option) any later version.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# This program is distributed in the hope that it will be useful, but
|
|
|
4c79b5 |
# 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
|
|
|
4c79b5 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
4c79b5 |
# USA.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
418249 |
# $Id$
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
4c79b5 |
|
|
|
4de5d4 |
function manual_updateMenu {
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Specify which action to do inside chapter's menu.
|
|
|
4c79b5 |
local ACTION="$1"
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Build the menu line related to the entry being processed
|
|
|
4c79b5 |
# currently.
|
|
|
4c79b5 |
local MENULINE=$(echo "$ENTRY" \
|
|
|
5285d6 |
| cut -d / -f8- \
|
|
|
4c79b5 |
| tr '/' ' ' \
|
|
|
5285d6 |
| sed -r "s/(chapter-intro\.texi|\.texi)$//")
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Give format to menu line using texinfo style.
|
|
|
4c79b5 |
MENULINE="* $MENULINE::"
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Define chapter's menu. Remove `@menu', `@end menu', and empty lines
|
|
|
4c79b5 |
# from output.
|
|
|
5285d6 |
local MENU=$(cat $MANUAL_DIR_CHAPTER/chapter-menu.texi \
|
|
|
4c79b5 |
| egrep -v '^[[:space:]]*$' | egrep -v '^@(end )?menu')
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Re-defined chapter's menu based on action.
|
|
|
4c79b5 |
case $ACTION in
|
|
|
4c79b5 |
'remove-entry' )
|
|
|
4c79b5 |
# Remove menu line from chapter's menu.
|
|
|
4c79b5 |
MENU=$(echo "$MENU" | egrep -v "$MENULINE")
|
|
|
4c79b5 |
;;
|
|
|
4c79b5 |
'update-entry' | * )
|
|
|
4c79b5 |
# Add menu line to chapter's menu. This is the default
|
|
|
4de5d4 |
# behaivour if no argument is passed to manual_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.
|
|
|
5285d6 |
echo "$MENU" > $MANUAL_DIR_CHAPTER/chapter-menu.texi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|