|
|
4c79b5 |
#!/bin/bash
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# help_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 |
#
|
|
|
4c79b5 |
# Copyright (C) 2009-2010 Alain Reguera Delgado
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
# This program is free software; you can redistribute it and/or modify
|
|
|
4c79b5 |
# it under the terms of the GNU General Public License as published by
|
|
|
4c79b5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
|
4c79b5 |
# (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 |
# ----------------------------------------------------------------------
|
|
|
4c79b5 |
# $Id: help_updateMenu.sh 44 2010-09-17 05:58:18Z al $
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function help_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" \
|
|
|
4c79b5 |
| cut -d / -f10- \
|
|
|
4c79b5 |
| tr '/' ' ' \
|
|
|
4c79b5 |
| sed -r "s/(${MANUALS_FILE[7]}|\.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.
|
|
|
4c79b5 |
local MENU=$(cat $ENTRYCHAPTER/${MANUALS_FILE[8]} \
|
|
|
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
|
|
|
4c79b5 |
# behaivour if no argument is passed to help_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.
|
|
|
4c79b5 |
echo "$MENU" > $ENTRYCHAPTER/${MANUALS_FILE[8]}
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|