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

9f4d86
#!/bin/bash
9f4d86
#
1afa3c
# texinfo_renameCrossReferences.sh -- This function replaces a node
9f4d86
# pattern with a node replacement and updates cross-reference
9f4d86
# definitions to reflect the changes.
9f4d86
#
2d3646
# Copyright (C) 2009, 2010, 2011 The CentOS Project
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
1afa3c
function texinfo_renameCrossReferences {
9f4d86
9f4d86
    local NODE=''
9f4d86
    local COUNT=1
9f4d86
    local ENTRIES=''
9f4d86
    local NODE_SRC=''
9f4d86
    local NODE_DST=''
9f4d86
9f4d86
    # Define node pattern for source documenation entry.
9f4d86
    NODE_SRC=$(echo "$ENTRY" \
91f787
        | cut -d / -f8- \
9f4d86
        | tr '/' ' ' \
9f4d86
        | sed -r \
658f2b
            -e "s/(chapter-intro\.texi|\.texi)$//")
9f4d86
9f4d86
    # Define node replacement for target documentation entry.
658f2b
    NODE_DST=$(echo "$ENTRY_DST" \
91f787
        | cut -d / -f8- \
9f4d86
        | tr '/' ' ' \
9f4d86
        | sed -r \
9f4d86
            -e "s/(chapter-intro\.texi|\.texi)$//")
9f4d86
9f4d86
    # Define list of entries to process.
f025ec
    ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR} --pattern='.*\.texi')
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'.
9f4d86
    sed -r -i ":a;N;s!${NODE_SRC}!${NODE_DST}!g;ba" ${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.
1afa3c
    texinfo_restoreCrossReferences "${ENTRY_DST}"
9f4d86
9f4d86
}