Blame Scripts/Functions/Help/help_renameCrossReferences.sh

9f4d86
#!/bin/bash
9f4d86
#
2a0af5
# help_renameCrossReferences.sh -- This function replaces a node
9f4d86
# pattern with a node replacement and updates cross-reference
9f4d86
# definitions to reflect the changes.
9f4d86
#
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
9f4d86
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9f4d86
# General Public License for more details.
9f4d86
#
9f4d86
# You should have received a copy of the GNU General Public License
9f4d86
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
9f4d86
# ----------------------------------------------------------------------
9f4d86
# $Id$
9f4d86
# ----------------------------------------------------------------------
9f4d86
2a0af5
function help_renameCrossReferences {
9f4d86
9fa13b
    local MANUAL_ENTRY_SRC=$(${FUNCNAM}_getEntry "$1")
9fa13b
    local MANUAL_ENTRY_DST=$(${FUNCNAM}_getEntry "$2")
9f4d86
9f4d86
    # Define node pattern for source documenation entry.
9fa13b
    local NODE_SRC=$(${FUNCNAM}_getNode "$MANUAL_ENTRY_SRC")
9f4d86
9f4d86
    # Define node replacement for target documentation entry.
9fa13b
    local NODE_DST=$(${FUNCNAM}_getNode "$MANUAL_ENTRY_DST")
9f4d86
9f4d86
    # Define list of entries to process.
9fa13b
    local MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR} \
9fa13b
        --pattern=".*\.${MANUAL_EXTENSION}")
9f4d86
9f4d86
    # Update node-related cross-references. The node-related cross
9f4d86
    # reference definition, long ones specially, could require more
9f4d86
    # than one line to be set. By default, GNU sed does not matches 
9f4d86
    # newline characters in the pattern space, so we need to make use
9f4d86
    # of `label' feature and the `N' command in order to build a
9f4d86
    # pattern space that includes the newline character in it. Here we
9f4d86
    # use the `a' letter to name the label we use, followed by N
9f4d86
    # command to add a newline to the pattern space, the s command to
9f4d86
    # make the pattern replacement using the `g' flag to make it
9f4d86
    # global and finaly the command `b' to branch label named `a'.
974695
    #
974695
    # Inside the pattern space, the `\<' and `\>' are used to restrict
974695
    # the match pattern to a word boundary. The word boundary
974695
    # restriction applied here is required to avoid undesired
974695
    # replacements when we replace singular words with their plurals.
974695
    # For example, if we need to change the word `Manual' to its
974695
    # plular (i.e., `Manuals'), and no boundary restriction is used in
974695
    # the pattern space to do that, we might end up having words like
974695
    # `Manualsssss'. This is because this sed command might be applied
974695
    # to the same file many times; and each time it is applied a new
974695
    # `Manuals' replaces the previous `Manuals' replacement to form
974695
    # `Manualss', `Manualsss', and so on for each interaction.
974695
    sed -r -i ":a;N;s!\<${NODE_SRC}\>!${NODE_DST}!g;ba" ${MANUAL_ENTRIES}
9f4d86
9f4d86
    # At this point, source documentation entry has been renamed from
9f4d86
    # source to target documentation entry, but they are still
658f2b
    # commented. So, uncomment them restoring target documentation
658f2b
    # entries.
9fa13b
    ${FUNCNAM}_restoreCrossReferences "${MANUAL_ENTRY_DST}"
9f4d86
9f4d86
}