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

878a2b
#!/bin/bash
878a2b
#
878a2b
# texinfo_renameCrossReferences.sh -- This function renames menu,
878a2b
# nodes and cross references related to chapters and sections that
878a2b
# have been renamed previously.
878a2b
#
878a2b
# Copyright (C) 2009, 2010, 2011 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_renameCrossReferences {
878a2b
878a2b
    local -a PATTERN
878a2b
    local -a REPLACE
878a2b
878a2b
    # Build source and target node definitions.
878a2b
    local NODE_SRC="$(texinfo_getEntryNode "$MANUAL_ENTRY_SRC")"
878a2b
    local NODE_DST="$(texinfo_getEntryNode "$MANUAL_ENTRY_DST")"
878a2b
878a2b
    # Define regular expression pattern and its replacement for node
878a2b
    # definitions that have been previously removed.
878a2b
    PATTERN[0]="--- @strong\{`gettext "Removed"`\}\((pxref|xref|ref):\<${NODE_SRC}\>(.*)\) ---"
878a2b
    REPLACE[0]="\@\1{${NODE_DST}\2}"
878a2b
878a2b
    # Define regular expression pattern and its replacement for menu
878a2b
    # definitions that have been previously removed.
878a2b
    PATTERN[1]="^@comment --- `gettext "Removed"`\(\* \<${NODE_SRC}\>(.*)\) ---$"
878a2b
    REPLACE[1]="* ${NODE_DST}\1"
878a2b
878a2b
    # Define list of entries to process. This is, all the texinfo
878a2b
    # source files the documentation manual is made of.
878a2b
    local MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR_L10N} \
878a2b
        --pattern=".+\.${MANUAL_EXTENSION}")
878a2b
878a2b
    # Update node cross references. The node-related cross reference
878a2b
    # definition, long ones specially, could require more than one
878a2b
    # line to be set. By default, GNU sed does not matches newline
878a2b
    # characters in the pattern space, so we need to make use of
878a2b
    # `label' feature and the `N' command in order to build a pattern
878a2b
    # space that includes the newline character in it. Here we use the
878a2b
    # `a' letter to name the label we use, followed by N command to
878a2b
    # add a newline to the pattern space, the s command to make the
878a2b
    # pattern replacement using the `g' flag to make it global and
878a2b
    # finaly the command `b' to branch label named `a'.
878a2b
    #
878a2b
    # Inside the pattern space, the `\<' and `\>' are used to restrict
878a2b
    # the match pattern to a word boundary. The word boundary
878a2b
    # restriction applied here is required to avoid undesired
878a2b
    # replacements when we replace singular words with their plurals.
878a2b
    # For example, if we need to change the node `Manual' to its
878a2b
    # plular (i.e., `Manuals'), and no boundary restriction is used in
878a2b
    # the pattern space to do that, we might end up having nodes like
878a2b
    # `Manualsssss' which probably doesn't exist. This is because this
878a2b
    # sed command might be applied to the same file more than once;
878a2b
    # and each time it is applied, a new `Manuals' replaces the
878a2b
    # previous `Manuals' replacement to form `Manualss', `Manualsss',
878a2b
    # and so on for each interaction. Using word boundaries
878a2b
    # restrictions prevent such issue from happening.
878a2b
    sed -r -i ":a;N;s!${PATTERN[0]}!${REPLACE[0]}!g;ba" ${MANUAL_ENTRIES}
878a2b
878a2b
    # Update menu cross references. Menu cross reference definitions
878a2b
    # hardly appear in more than one line, so there is no need to
878a2b
    # complicate the replacement command.
878a2b
    sed -r -i "s!${PATTERN[1]}!${REPLACE[1]}!" ${MANUAL_ENTRIES}
878a2b
878a2b
}