Blame Scripts/Functions/Help/help_renameCrossReferences.sh

9f4d86
#!/bin/bash
9f4d86
#
0211a4
# 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
#
9f4d86
# Copyright (C) 2009-2011 Alain Reguera Delgado
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
fa95b1
# the Free Software Foundation; either version 2 of the License, or
fa95b1
# (at your option) any later version.
fa95b1
#
9f4d86
# This program is distributed in the hope that it will be useful, but
9f4d86
# 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
9f4d86
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
9f4d86
# USA.
9f4d86
# ----------------------------------------------------------------------
9f4d86
# $Id$
9f4d86
# ----------------------------------------------------------------------
9f4d86
0211a4
function help_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" \
9f4d86
        | cut -d / -f8- \
9f4d86
        | tr '/' ' ' \
9f4d86
        | sed -r \
9f4d86
            -e "s/(chapter-intro\.texi|\.texi)$//" \
9f4d86
            -e 's! !( |\\n)!g')
9f4d86
9f4d86
    # Define node replacement for target documentation entry.
9f4d86
    NODE_DST=$(echo "$FLAG_TO" \
9f4d86
        | cut -d / -f8- \
9f4d86
        | tr '/' ' ' \
9f4d86
        | sed -r \
9f4d86
            -e "s/(chapter-intro\.texi|\.texi)$//")
9f4d86
9f4d86
    # Sanitate node replacement for target documentation entry to make
9f4d86
    # use of regular expression positional markers, so the word
9f4d86
    # separator character found by node pattern could be used.
9f4d86
    for NODE in $NODE_DST;do
9f4d86
        if [[ $COUNT -eq 1 ]];then 
9f4d86
            NODE_DST="${NODE}\\${COUNT}"
9f4d86
        else
9f4d86
            NODE_DST="${NODE_DST}$(echo "${NODE}\\${COUNT}")"
9f4d86
        fi
9f4d86
        COUNT=$(($COUNT + 1))
9f4d86
    done
9f4d86
9f4d86
    # Remove last positional marker from node replacement.
9f4d86
    NODE_DST=$(echo $NODE_DST | sed -r 's!\\[[:digit:]]$!!')
9f4d86
9f4d86
    # Define list of entries to process.
759d18
    ENTRIES=$(cli_getFilesList "${MANUAL_BASEDIR}" '.*\.texi')
9f4d86
9f4d86
    # Set action preamble.
467208
    cli_printActionPreamble "$ENTRIES" '' ''
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
9f4d86
    # commented. So, restore target documentation entries.
0211a4
    help_restoreCrossReferences "${FLAG_TO}"
9f4d86
9f4d86
}