Blame Automation/Modules/Help/Texinfo/texinfo_renameCrossReferences.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# texinfo_renameCrossReferences.sh -- This function renames menu,
Alain Reguera Delgado 8f60cb
# nodes and cross references related to chapters and sections that
Alain Reguera Delgado 8f60cb
# have been renamed previously.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function texinfo_renameCrossReferences {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local -a PATTERN
Alain Reguera Delgado 8f60cb
    local -a REPLACE
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Build source and target node definitions.
Alain Reguera Delgado 8f60cb
    local NODE_SRC="$(texinfo_getEntryNode "$MANUAL_ENTRY_SRC")"
Alain Reguera Delgado 8f60cb
    local NODE_DST="$(texinfo_getEntryNode "$MANUAL_ENTRY_DST")"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define regular expression pattern and its replacement for node
Alain Reguera Delgado 8f60cb
    # definitions that have been previously removed.
Alain Reguera Delgado 8f60cb
    PATTERN[0]="--- @strong\{`gettext "Removed"`\}\((pxref|xref|ref):\<${NODE_SRC}\>(.*)\) ---"
Alain Reguera Delgado 8f60cb
    REPLACE[0]="\@\1{${NODE_DST}\2}"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define regular expression pattern and its replacement for menu
Alain Reguera Delgado 8f60cb
    # definitions that have been previously removed.
Alain Reguera Delgado 8f60cb
    PATTERN[1]="^@comment --- `gettext "Removed"`\(\* \<${NODE_SRC}\>(.*)\) ---$"
Alain Reguera Delgado 8f60cb
    REPLACE[1]="* ${NODE_DST}\1"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define list of entries to process. This is, all the texinfo
Alain Reguera Delgado 8f60cb
    # source files the documentation manual is made of.
Alain Reguera Delgado 8f60cb
    local MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR_L10N} \
Alain Reguera Delgado 8f60cb
        --pattern="^.+\.${MANUAL_EXTENSION}$" \
Alain Reguera Delgado 8f60cb
            | egrep -v "(${MANUAL_NAME}|chapter)-(menu|nodes|index)")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Update node cross references. The node-related cross reference
Alain Reguera Delgado 8f60cb
    # definition, long ones specially, could require more than one
Alain Reguera Delgado 8f60cb
    # line to be set. By default, GNU sed does not matches newline
Alain Reguera Delgado 8f60cb
    # characters in the pattern space, so we need to make use of
Alain Reguera Delgado 8f60cb
    # `label' feature and the `N' command in order to build a pattern
Alain Reguera Delgado 8f60cb
    # space that includes the newline character in it. Here we use the
Alain Reguera Delgado 8f60cb
    # `a' letter to name the label we use, followed by N command to
Alain Reguera Delgado 8f60cb
    # add a newline to the pattern space, the s command to make the
Alain Reguera Delgado 8f60cb
    # pattern replacement using the `g' flag to make it global and
Alain Reguera Delgado 8f60cb
    # finally the command `b' to branch label named `a'.
Alain Reguera Delgado 8f60cb
    #
Alain Reguera Delgado 8f60cb
    # Inside the pattern space, the `\<' and `\>' are used to restrict
Alain Reguera Delgado 8f60cb
    # the match pattern to a word boundary. The word boundary
Alain Reguera Delgado 8f60cb
    # restriction applied here is required to avoid undesired
Alain Reguera Delgado 8f60cb
    # replacements when we replace singular words with their plurals.
Alain Reguera Delgado 8f60cb
    # For example, if we need to change the node `Manual' to its
Alain Reguera Delgado 8f60cb
    # plural (i.e., `Manuals'), and no boundary restriction is used in
Alain Reguera Delgado 8f60cb
    # the pattern space to do that, we might end up having nodes like
Alain Reguera Delgado 8f60cb
    # `Manualsssss' which probably doesn't exist. This is because this
Alain Reguera Delgado 8f60cb
    # sed command might be applied to the same file more than once;
Alain Reguera Delgado 8f60cb
    # and each time it is applied, a new `Manuals' replaces the
Alain Reguera Delgado 8f60cb
    # previous `Manuals' replacement to form `Manualss', `Manualsss',
Alain Reguera Delgado 8f60cb
    # and so on for each interaction. Using word boundaries
Alain Reguera Delgado 8f60cb
    # restrictions prevent such issue from happening.
Alain Reguera Delgado 8f60cb
    sed -r -i ":a;N;s!${PATTERN[0]}!${REPLACE[0]}!g;ba" ${MANUAL_ENTRIES}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Update menu cross references. Menu cross reference definitions
Alain Reguera Delgado 8f60cb
    # hardly appear in more than one line, so there is no need to
Alain Reguera Delgado 8f60cb
    # complicate the replacement command.
Alain Reguera Delgado 8f60cb
    sed -r -i "s!${PATTERN[1]}!${REPLACE[1]}!" ${MANUAL_ENTRIES}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}