Blame Automation/centos-art.sh-help/Texinfo/texinfo_deleteCrossReferences.sh

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