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

f8fb31
#!/bin/bash
f8fb31
#
993f6a
# texinfo_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
993f6a
# function in coordination with texinfo_deleteEntry function, in order
e9dba2
# to keep cross reference information, inside the documentation
e9dba2
# manual, syncronized.
f8fb31
#
3b0984
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
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
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# 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
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
f8fb31
# ----------------------------------------------------------------------
f8fb31
# $Id$
f8fb31
# ----------------------------------------------------------------------
f8fb31
993f6a
function texinfo_deleteCrossReferences {
f8fb31
f8fb31
    local -a PATTERN
f8fb31
    local -a REPLACE
f8fb31
4191e8
    # Define documentation entry.
4191e8
    local MANUAL_ENTRY="$1"
4191e8
4191e8
    # Verify documentation entry. If documentation entry is empty,
4191e8
    # stop script execution with an error message.
4191e8
    if [[ $MANUAL_ENTRY == '' ]];then
4191e8
        cli_printMessage "`gettext "The first positional parameter cannot be empty."`" --as-error-line
f2c0f9
    fi
f2c0f9
f2c0f9
    # Build the node string using entry location.
d92dde
    local NODE="$(${FLAG_BACKEND}_getNode "$MANUAL_ENTRY")"
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.
5e989a
    local MANUAL_ENTRIES=$(cli_getFilesList ${MANUAL_BASEDIR_L10N} \
5e989a
        --pattern=".+\.${MANUAL_EXTENSION}")
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
f2c0f9
    # command to add a newline to the pattern space, the s command to
f2c0f9
    # make the pattern replacement using the `g' flag to make it
f2c0f9
    # global and finaly the command `b' to branch label named `a'.
d92dde
    sed -r -i ":a;N;s!${PATTERN[0]}!${REPLACE[0]}!g;ba" ${MANUAL_ENTRIES}
54ea1a
54ea1a
    # Update menu-related cross references. Menu-related cross
54ea1a
    # references hardly appear in more than one line, so there is no
4191e8
    # need to complicate much the replacement command.
d92dde
    sed -r -i "s!${PATTERN[1]}!${REPLACE[1]}!" ${MANUAL_ENTRIES}
f8fb31
f8fb31
}