Blame Scripts/Bash/centos-art/Functions/Manual/manual_deleteCrossReferences.sh

f8fb31
#!/bin/bash
f8fb31
#
742c46
# manual_deleteCrossReferences.sh -- This function looks inside
e9dba2
# texinfo source files, from section level on, and removes all cross
e9dba2
# referece definitions related to a documentation entry. Use this
742c46
# function in coordination with manual_deleteEntry function, in order
e9dba2
# to keep cross reference information, inside the documentation
e9dba2
# manual, syncronized.
f8fb31
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
f8fb31
# 
f8fb31
# This program is free software; you can redistribute it and/or
f8fb31
# modify it under the terms of the GNU General Public License as
f8fb31
# published by the Free Software Foundation; either version 2 of the
f8fb31
# License, or (at your option) any later version.
f8fb31
# 
f8fb31
# This program is distributed in the hope that it will be useful, but
f8fb31
# WITHOUT ANY WARRANTY; without even the implied warranty of
f8fb31
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f8fb31
# General Public License for more details.
f8fb31
#
f8fb31
# You should have received a copy of the GNU General Public License
f8fb31
# along with this program; if not, write to the Free Software
f8fb31
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
f8fb31
# USA.
f8fb31
# 
f8fb31
# ----------------------------------------------------------------------
f8fb31
# $Id$
f8fb31
# ----------------------------------------------------------------------
f8fb31
742c46
function manual_deleteCrossReferences {
f8fb31
f8fb31
    local -a PATTERN
f8fb31
    local -a REPLACE
f8fb31
f8fb31
    # Build the node string using global entry (ENTRY) variable being
f8fb31
    # processed currently.
f8fb31
    local NODE=$(echo "$ENTRY" \
5285d6
        | cut -d / -f8- \
f8fb31
        | tr '/' ' ' \
54ea1a
        | sed -r \
54ea1a
            -e "s/(chapter-intro\.texi|\.texi)$//" \
54ea1a
            -e 's! !( |\\n)!g')
f8fb31
f8fb31
    # Define regular expression patterns for texinfo cross reference
f8fb31
    # commands.
f8fb31
    PATTERN[0]="@(pxref|xref|ref)\{(${NODE})\}"
f8fb31
    PATTERN[1]="^(\* ${NODE}:(.*)?:(.*)?)$"
f8fb31
f8fb31
    # Define replacement string for missing entries. It is convenient
f8fb31
    # to keep missing entries in documentation for documentation team
f8fb31
    # to know. Removing the missing cross reference may intorudce
f8fb31
    # confussion. Imagine that! you are spending lots of hours in an
f8fb31
    # article and suddenly one of your cross refereces disappears with
f8fb31
    # no visible reason, with the next working copy update you
f8fb31
    # perform. That's frustrating. Instead, when centos-art.sh script
f8fb31
    # finds a missing cross reference it removes the link and remark
f8fb31
    # the issue for you to act on it.
f8fb31
    REPLACE[0]='--- @strong{'`gettext "Removed"`'}(\1:\2) ---'
f8fb31
    REPLACE[1]='@comment --- '`gettext "Removed"`'(\1) ---'
f8fb31
54ea1a
    # Define list of entries to process.
5285d6
    local ENTRIES=$(cli_getFilesList "${MANUAL_DIR}" '.*\.texi')
54ea1a
54ea1a
    # Set action preamble.
54ea1a
    cli_printActionPreamble "$ENTRIES"
54ea1a
54ea1a
    # Update node-related cross references. The node-related cross
54ea1a
    # reference definition, long ones specially, could require more
54ea1a
    # than one line to be set. By default, GNU sed does not matches 
54ea1a
    # newline characters in the pattern space, so we need to make use
54ea1a
    # of `label' feature and the `N' command in order to build a
54ea1a
    # pattern space that includes the newline character in it. Here we
54ea1a
    # use the `a' letter to name the label we use, followed by N
54ea1a
    # command to expand the pattern space, the s command to make the
54ea1a
    # pattern replacement using the `g' flag to make it global and
54ea1a
    # finaly the command `b' to branch label named `a'.
54ea1a
    sed -r -i ":a;N;s!${PATTERN[0]}!${REPLACE[0]}!g;ba" ${ENTRIES}
54ea1a
54ea1a
    # Update menu-related cross references. Menu-related cross
54ea1a
    # references hardly appear in more than one line, so there is no
54ea1a
    # need to complicate the replacement command.
54ea1a
    sed -r -i "s!${PATTERN[1]}!${REPLACE[1]}!" ${ENTRIES}
f8fb31
f8fb31
}