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

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