Blame Scripts/Bash/Functions/Manual/manual_removeCrossReferences.sh

f8fb31
#!/bin/bash
f8fb31
#
e9dba2
# manual_removeCrossReferences.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
e9dba2
# function in coordination with manual_removeEntry function, in order
e9dba2
# to keep cross reference information, inside the documentation
e9dba2
# manual, syncronized.
f8fb31
#
f8fb31
# Copyright (C) 2009, 2010 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
f8fb31
function manual_removeCrossReferences {
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" \
f8fb31
        | cut -d / -f10- \
f8fb31
        | tr '/' ' ' \
f8fb31
        | sed -r "s/(${MANUALS_FILE[7]}|\.texi)$//")
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
f8fb31
    # Sanitate all missing cross references, related to entry, in
f8fb31
    # section texinfo files. Missing cross references, related to
f8fb31
    # entry, in chapter texinfo files are already handled by
f8fb31
    # manual_updateMenu, and manual_updateNode functions. If we don't
f8fb31
    # sanitate missing cross refereces before info file is created,
f8fb31
    # errors are displayed since makeinfo don't produce info output
f8fb31
    # with broken cross refereces.
f8fb31
    sed -r -i \
f8fb31
        -e "s!${PATTERN[0]}!${REPLACE[0]}!Mg" \
f8fb31
        -e "s!${PATTERN[1]}!${REPLACE[1]}!g" \
f8fb31
        $(find ${MANUALS_DIR[2]} -mindepth 3 -name '*.texi')
f8fb31
f8fb31
}