Blame Scripts/Bash/Functions/Help/Texinfo/texinfo_deleteCrossReferences.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# texinfo_deleteCrossReferences.sh -- This function looks inside
878a2b
# texinfo source files, from section level on, and removes all cross
878a2b
# referece definitions related to a documentation entry. Use this
878a2b
# function in coordination with texinfo_deleteEntry function, in order
878a2b
# to keep cross reference information, inside the documentation
878a2b
# manual, syncronized.
878a2b
#
878a2b
# Copyright (C) 2009, 2010, 2011 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function texinfo_deleteCrossReferences {
878a2b
878a2b
    local -a PATTERN
878a2b
    local -a REPLACE
878a2b
878a2b
    # Define documentation entry.
878a2b
    local MANUAL_ENTRY="$1"
878a2b
878a2b
    # Verify documentation entry. If documentation entry is empty,
878a2b
    # stop script execution with an error message.
878a2b
    if [[ $MANUAL_ENTRY == '' ]];then
878a2b
        cli_printMessage "`gettext "The first positional parameter cannot be empty."`" --as-error-line
878a2b
    fi
878a2b
878a2b
    # Build the node string using entry location.
878a2b
    local NODE="$(texinfo_getEntryNode "$MANUAL_ENTRY")"
878a2b
878a2b
    # Define regular expression patterns for texinfo cross reference
878a2b
    # commands.
878a2b
    PATTERN[0]="@(pxref|xref|ref)\{(${NODE})\}"
878a2b
    REPLACE[0]='--- @strong{'`gettext "Removed"`'}(\1:\2) ---'
878a2b
878a2b
    # Define replacement string for missing entries. It is convenient
878a2b
    # to keep missing entries in documentation for documentation team
878a2b
    # to know. Removing the missing cross reference may intorudce
878a2b
    # confussion. Imagine that! you are spending lots of hours in an
878a2b
    # article and suddenly one of your cross refereces disappears with
878a2b
    # no visible reason, with the next working copy update you
878a2b
    # perform. That's frustrating. Instead, when centos-art.sh script
878a2b
    # finds a missing cross reference it removes the link and remark
878a2b
    # the issue for you to act on it.
878a2b
    PATTERN[1]="^(\* ${NODE}:(.*):(.*))$"
878a2b
    REPLACE[1]='\@comment --- '`gettext "Removed"`'(\1) ---'
878a2b
878a2b
    # Define list of entries to process.
878a2b
    local MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR_L10N} \
878a2b
        --pattern=".+\.${MANUAL_EXTENSION}")
878a2b
878a2b
    # Update node-related cross references. The node-related cross
878a2b
    # reference definition, long ones specially, could require more
878a2b
    # than one line to be set. By default, GNU sed does not matches 
878a2b
    # newline characters in the pattern space, so we need to make use
878a2b
    # of `label' feature and the `N' command in order to build a
878a2b
    # pattern space that includes the newline character in it. Here we
878a2b
    # use the `a' letter to name the label we use, followed by N
878a2b
    # command to add a newline to the pattern space, the s command to
878a2b
    # make the pattern replacement using the `g' flag to make it
878a2b
    # global and finaly the command `b' to branch label named `a'.
878a2b
    sed -r -i ":a;N;s!${PATTERN[0]}!${REPLACE[0]}!g;ba" ${MANUAL_ENTRIES}
878a2b
878a2b
    # Update menu-related cross references. Menu-related cross
878a2b
    # references hardly appear in more than one line, so there is no
878a2b
    # need to complicate much the replacement command.
878a2b
    sed -r -i "s!${PATTERN[1]}!${REPLACE[1]}!" ${MANUAL_ENTRIES}
878a2b
878a2b
}